From 5d8ba0d259ce2fcbdad2da21c6122d91d253ca7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=96=E5=81=A5=E6=AD=A3?= Date: Sun, 14 Jul 2024 13:22:47 +0800 Subject: [PATCH] Fixed: Ignore the lateral movement --- lua/readermode/init.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/readermode/init.lua b/lua/readermode/init.lua index 6545e9f..3272322 100644 --- a/lua/readermode/init.lua +++ b/lua/readermode/init.lua @@ -18,17 +18,29 @@ function M.setup(opts) vim.api.nvim_create_user_command("ReaderMode", require("readermode").toggle, {}) vim.keymap.set({ "n" }, M.opts.keymap, M.toggle, { desc = M.opts.desc }) + local last_line = M.getCurrentLineNumber() + -- Define Autocommand w/ new Autogroup vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { group = vim.api.nvim_create_augroup("ReaderMode", { clear = true }), callback = function() if M.opts.enabled then - M.center() + local current_line = M.getCurrentLineNumber() + if current_line ~= last_line then + M.center() + else + end + last_line = current_line end end, }) end +---@return number +function M.getCurrentLineNumber() + return vim.api.nvim_win_get_cursor(0)[1] +end + ---@return nil function M.toggle() M.opts.enabled = not M.opts.enabled