fix: prevent incorrect unindent on <CR> using nvim_input('<Ignore>')

main
borja (aider) 2 months ago
parent 3f3ec3df1a
commit 12bae73dfd

@ -190,8 +190,6 @@ local function setup_buffer_keymaps()
-- Use string.match with %S to check for any non-whitespace character -- Use string.match with %S to check for any non-whitespace character
local has_content = details.content and string.match(details.content, "%S") local has_content = details.content and string.match(details.content, "%S")
-- Debugging removed
if details.is_todo and has_content then if details.is_todo and has_content then
-- Case 1: Non-empty TODO line -- Case 1: Non-empty TODO line
-- Create a new TODO line below with same indent/marker -- 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 local cursor_col_bytes = #new_line_content
vim.api.nvim_win_set_cursor(0, { lnum + 1, cursor_col_bytes }) vim.api.nvim_win_set_cursor(0, { lnum + 1, cursor_col_bytes })
-- Action handled, do not fall through to default behavior. -- Tell Neovim to ignore the original <CR> press
-- No return value needed as it's not an expr mapping anymore. vim.api.nvim_input('<Ignore>')
return -- Action handled
elseif details.is_todo and not has_content then elseif details.is_todo and not has_content then
-- Case 2: Empty TODO line (e.g., "- [ ]") - Implement Outdenting -- 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 local cursor_col_bytes = #new_line_content
vim.api.nvim_win_set_cursor(0, { lnum, cursor_col_bytes }) vim.api.nvim_win_set_cursor(0, { lnum, cursor_col_bytes })
-- Action handled, do not fall through. -- Tell Neovim to ignore the original <CR> press
vim.api.nvim_input('<Ignore>')
return -- Action handled
else else
-- Line is not indented, terminate the list -- 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 -- Replace the line with an empty string
vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, { "" }) vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, { "" })
-- Now, manually insert a newline below using the API -- 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 -- Move cursor to the new empty line
vim.api.nvim_win_set_cursor(0, { lnum + 1, 0 }) vim.api.nvim_win_set_cursor(0, { lnum + 1, 0 })
-- Action handled, do not fall through. -- Tell Neovim to ignore the original <CR> press
vim.api.nvim_input('<Ignore>')
return -- Action handled
end end
else else
-- Case 3: Not a TODO line -- Case 3: Not a TODO line
-- Do nothing. Neovim will automatically handle the Enter key press -- 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('<Ignore>').
return -- Explicitly return nothing to be clear return -- Explicitly return nothing to be clear
end end
end end
@ -320,7 +320,7 @@ local function setup_buffer_keymaps()
-- Set up buffer-local keymaps -- Set up buffer-local keymaps
-- Use buffer = 0 to target the current buffer -- Use buffer = 0 to target the current buffer
vim.keymap.set("n", "<leader>t", function() end, { desc = "+TODOs", buffer = 0 }) -- Placeholder vim.keymap.set("n", "<leader>t", function() end, { desc = "+TODOs", buffer = 0 }) -- Placeholder
-- Removed expr = true from <CR> mapping -- Keep <CR> mapping without expr = true
vim.keymap.set("i", "<CR>", press_enter, { desc = "Todoer: Handle Enter", buffer = 0 }) vim.keymap.set("i", "<CR>", press_enter, { desc = "Todoer: Handle Enter", buffer = 0 })
-- Keep expr = true for Tab/S-Tab for now, until they are refactored -- Keep expr = true for Tab/S-Tab for now, until they are refactored
vim.keymap.set("i", "<TAB>", press_tab, { desc = "Todoer: Handle Tab", expr = true, buffer = 0 }) vim.keymap.set("i", "<TAB>", press_tab, { desc = "Todoer: Handle Tab", expr = true, buffer = 0 })

Loading…
Cancel
Save