From 4833c0b69b4c7037025563c769a235e16d5ef425 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Sun, 20 Oct 2024 14:50:21 -0600 Subject: [PATCH] fix(autocommands): Restore default column retention behavior (Issue #16) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- lua/typewriter/autocommands.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/typewriter/autocommands.lua b/lua/typewriter/autocommands.lua index 058e751..b57a93c 100644 --- a/lua/typewriter/autocommands.lua +++ b/lua/typewriter/autocommands.lua @@ -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() @@ -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, })