|
|
|
@ -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("<CR>", 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("<CR>", 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("<CR>", 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", "<leader>t", function() end, { desc = "+TODOs", buffer = 0 }) -- Placeholder
|
|
|
|
|
vim.keymap.set("i", "<CR>", press_enter, { desc = "Todoer: Handle Enter", expr = true, buffer = 0 })
|
|
|
|
|
-- Removed expr = true from <CR> mapping
|
|
|
|
|
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
|
|
|
|
|
vim.keymap.set("i", "<TAB>", press_tab, { desc = "Todoer: Handle Tab", expr = true, buffer = 0 })
|
|
|
|
|
vim.keymap.set("i", "<S-Tab>", press_shift_tab, { desc = "Todoer: Handle Shift-Tab", expr = true, buffer = 0 })
|
|
|
|
|
vim.keymap.set("n", "<leader>tt", toggle_todo, { desc = "Todoer: Toggle TODO", buffer = 0 })
|
|
|
|
|