From 12bae73dfd4129a666e5bffc6c9640d8789b347d Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Wed, 30 Apr 2025 13:43:29 +0200 Subject: [PATCH] fix: prevent incorrect unindent on using nvim_input('') --- lua/todoer/init.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lua/todoer/init.lua b/lua/todoer/init.lua index 7d969e0..9f1c2d9 100644 --- a/lua/todoer/init.lua +++ b/lua/todoer/init.lua @@ -190,8 +190,6 @@ local function setup_buffer_keymaps() -- Use string.match with %S to check for any non-whitespace character local has_content = details.content and string.match(details.content, "%S") - -- Debugging removed - if details.is_todo and has_content then -- Case 1: Non-empty TODO line -- Create a new TODO line below with same indent/marker @@ -205,8 +203,9 @@ local function setup_buffer_keymaps() local cursor_col_bytes = #new_line_content vim.api.nvim_win_set_cursor(0, { lnum + 1, cursor_col_bytes }) - -- Action handled, do not fall through to default behavior. - -- No return value needed as it's not an expr mapping anymore. + -- Tell Neovim to ignore the original press + vim.api.nvim_input('') + return -- Action handled elseif details.is_todo and not has_content then -- Case 2: Empty TODO line (e.g., "- [ ]") - Implement Outdenting @@ -241,13 +240,12 @@ local function setup_buffer_keymaps() local cursor_col_bytes = #new_line_content vim.api.nvim_win_set_cursor(0, { lnum, cursor_col_bytes }) - -- Action handled, do not fall through. + -- Tell Neovim to ignore the original press + vim.api.nvim_input('') + return -- Action handled else -- Line is not indented, terminate the list - -- ===== DEBUGGING START ===== - vim.notify(string.format("[Todoer Debug] Terminating list on line %d. Setting line to empty string.", lnum), vim.log.levels.WARN) - -- ===== DEBUGGING END ===== -- Replace the line with an empty string vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, { "" }) -- Now, manually insert a newline below using the API @@ -255,13 +253,15 @@ local function setup_buffer_keymaps() -- Move cursor to the new empty line vim.api.nvim_win_set_cursor(0, { lnum + 1, 0 }) - -- Action handled, do not fall through. + -- Tell Neovim to ignore the original press + vim.api.nvim_input('') + return -- Action handled end else -- Case 3: Not a TODO line -- Do nothing. Neovim will automatically handle the Enter key press - -- because this function didn't modify the buffer or explicitly handle it. + -- because this function didn't modify the buffer or call nvim_input(''). return -- Explicitly return nothing to be clear end end @@ -320,7 +320,7 @@ local function setup_buffer_keymaps() -- Set up buffer-local keymaps -- Use buffer = 0 to target the current buffer vim.keymap.set("n", "t", function() end, { desc = "+TODOs", buffer = 0 }) -- Placeholder - -- Removed expr = true from mapping + -- Keep mapping without expr = true vim.keymap.set("i", "", press_enter, { desc = "Todoer: Handle Enter", buffer = 0 }) -- Keep expr = true for Tab/S-Tab for now, until they are refactored vim.keymap.set("i", "", press_tab, { desc = "Todoer: Handle Tab", expr = true, buffer = 0 })