fix: support all list markers for tab indentation

main
borja (aider) 2 months ago
parent 16615aeb43
commit 3f3ec3df1a

@ -245,6 +245,9 @@ local function setup_buffer_keymaps()
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
@ -266,11 +269,10 @@ local function setup_buffer_keymaps()
-- indent line if tab is pressed when line is a todo (Will be refactored in Step 4) -- indent line if tab is pressed when line is a todo (Will be refactored in Step 4)
local function press_tab() local function press_tab()
local current_line = vim.api.nvim_get_current_line() local current_line = vim.api.nvim_get_current_line()
-- Check if current line matches the patterns (Only checks '-' marker currently) -- Updated pattern to match -, *, + markers
-- TODO: Update pattern to match *, + as well local pattern = "^%s*[%-%*%+]%s+%[[ x]%]"
local pattern = "^%s*%- %[[ x]%]"
if string.match(current_line, pattern) then if string.match(current_line, pattern) then
-- print("tab pressed, allegedly") -- Removed print -- Still using feedkeys for now, will be refactored later
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-t>", true, false, true), "i", false) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-t>", true, false, true), "i", false)
return "" -- Action handled by feedkeys return "" -- Action handled by feedkeys
else else
@ -282,11 +284,10 @@ local function setup_buffer_keymaps()
-- indent line if shift tab is pressed when line is a todo (Will be refactored in Step 4) -- indent line if shift tab is pressed when line is a todo (Will be refactored in Step 4)
local function press_shift_tab() local function press_shift_tab()
local current_line = vim.api.nvim_get_current_line() local current_line = vim.api.nvim_get_current_line()
-- Check if current line matches the patterns (Only checks '-' marker currently) -- Updated pattern to match -, *, + markers
-- TODO: Update pattern to match *, + as well local pattern = "^%s*[%-%*%+]%s+%[[ x]%]"
local pattern = "^%s*%- %[[ x]%]"
if string.match(current_line, pattern) then if string.match(current_line, pattern) then
-- print("shift tab pressed, allegedly") -- Removed print -- Still using feedkeys for now, will be refactored later
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-d>", true, false, true), "i", false) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-d>", true, false, true), "i", false)
return "" -- Action handled by feedkeys return "" -- Action handled by feedkeys
else else
@ -302,6 +303,7 @@ local function setup_buffer_keymaps()
-- 1: Prefix (indentation, marker '-', '*', '+', or '#', and whitespace) -- 1: Prefix (indentation, marker '-', '*', '+', or '#', and whitespace)
-- 2: State (' ' or 'x') -- 2: State (' ' or 'x')
-- 3: Rest of the line (after ']') -- 3: Rest of the line (after ']')
-- Adjusted pattern slightly to ensure it captures # correctly too if needed
local prefix, state, rest = string.match(line, "^([%s]*[%-#%*%+]%s*)%[([ x])%](.*)") local prefix, state, rest = string.match(line, "^([%s]*[%-#%*%+]%s*)%[([ x])%](.*)")
if prefix then -- Check if the pattern matched (i.e., it's a toggleable line) if prefix then -- Check if the pattern matched (i.e., it's a toggleable line)

Loading…
Cancel
Save