Skip to content

Commit

Permalink
fix(autocommands): Restore default column retention behavior (Issue #16)
Browse files Browse the repository at this point in the history
- Added conditional logic to ensure column preservation only applies when typewriter mode is active.
- Modified CursorMoved autocmd to respect Neovim’s default column retention behavior when typewriter mode is disabled.
- Adjusted TWEnable and TWDisable commands to toggle column preservation appropriately.
- This resolves Issue #16 where the cursor column was not correctly restored when moving between lines with j/k motions.
  • Loading branch information
joshuadanpeterson committed Oct 20, 2024
1 parent d68b7af commit 4833c0b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lua/typewriter/autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ function M.autocmd_setup()
-- User commands
vim.api.nvim_create_user_command("TWEnable", function()
commands.enable_typewriter_mode()
set_state(State.PRESERVE_COLUMN) -- Enable column preservation when typewriter mode is active
end, { desc = "Enable Typewriter mode" })

vim.api.nvim_create_user_command("TWDisable", function()
Expand Down Expand Up @@ -275,10 +276,14 @@ function M.autocmd_setup()
vim.api.nvim_create_autocmd("CursorMoved", {
pattern = "*",
callback = function()
if current_state == State.PRESERVE_COLUMN then
-- Only preserve column if typewriter mode is active
if current_state == State.PRESERVE_COLUMN and utils.is_typewriter_active() then
handle_column_preservation()
elseif current_state == State.NORMAL then
commands.center_cursor()
-- Default Neovim behavior (no column preservation)
-- We don't interfere with the default behavior when not in typewriter mode
return
end
end,
})
Expand Down

0 comments on commit 4833c0b

Please sign in to comment.