From e7f6d63fdeb10f9dbe968e860f00b694469b72ac Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Wed, 30 Apr 2025 11:22:12 +0200 Subject: [PATCH] fix: prevent E565 error on by removing expr=true --- lua/todoer/init.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lua/todoer/init.lua b/lua/todoer/init.lua index e44c104..2d0815a 100644 --- a/lua/todoer/init.lua +++ b/lua/todoer/init.lua @@ -115,8 +115,8 @@ local function setup_buffer_keymaps() local function press_enter() local details, lnum = get_current_line_details() if not details then - -- Fallback if getting details fails for some reason - return vim.api.nvim_replace_termcodes("", true, false, true) + -- Getting details failed, do nothing and let Neovim handle Enter. + return end -- Check if the line is a TODO item and if it has content after the marker @@ -136,8 +136,8 @@ 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, return empty string because mapping is expr=true - return "" + -- Action handled, do not fall through to default behavior. + -- No return value needed as it's not an expr mapping anymore. elseif details.is_todo and not has_content then -- Case 2: Empty TODO line (e.g., "- [ ]") - Implement Outdenting @@ -172,20 +172,25 @@ 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 - return "" + -- Action handled, do not fall through. + else -- Line is not indented, terminate the list -- Replace the line with an empty string vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, { "" }) - -- Let Neovim handle inserting a newline below the now-empty line - return vim.api.nvim_replace_termcodes("", true, false, true) + -- Now, manually insert a newline below using the API + vim.api.nvim_buf_set_lines(0, lnum, lnum, false, { "" }) + -- Move cursor to the new empty line + vim.api.nvim_win_set_cursor(0, { lnum + 1, 0 }) + + -- Action handled, do not fall through. end else -- Case 3: Not a TODO line - -- Let Neovim handle the Enter key press normally - return vim.api.nvim_replace_termcodes("", true, false, true) + -- Do nothing. Neovim will automatically handle the Enter key press + -- because this function didn't modify the buffer or explicitly handle it. + return -- Explicitly return nothing to be clear end end @@ -243,9 +248,10 @@ local function setup_buffer_keymaps() -- Set up buffer-local keymaps -- Use buffer = 0 to target the current buffer - -- Note: Setting expr = true for Tab/S-Tab allows returning keys for default behavior vim.keymap.set("n", "t", function() end, { desc = "+TODOs", buffer = 0 }) -- Placeholder - vim.keymap.set("i", "", press_enter, { desc = "Todoer: Handle Enter", expr = true, buffer = 0 }) + -- Removed expr = true from mapping + 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 }) vim.keymap.set("i", "", press_shift_tab, { desc = "Todoer: Handle Shift-Tab", expr = true, buffer = 0 }) vim.keymap.set("n", "tt", toggle_todo, { desc = "Todoer: Toggle TODO", buffer = 0 })