Skip to content

Commit

Permalink
Fixed: Ignore the lateral movement
Browse files Browse the repository at this point in the history
  • Loading branch information
肖健正 committed Jul 14, 2024
1 parent 5815627 commit 5d8ba0d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lua/readermode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d8ba0d

Please sign in to comment.