From d75ccc32eb662cbb48f3b4e83b40c9a198545967 Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Wed, 30 Apr 2025 16:06:01 +0200 Subject: [PATCH] feat: add debug logging for tab indentation issues --- lua/todoer/init.lua | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lua/todoer/init.lua b/lua/todoer/init.lua index 97aac04..b6054da 100644 --- a/lua/todoer/init.lua +++ b/lua/todoer/init.lua @@ -77,6 +77,19 @@ local function get_indent_string() return et and string.rep(" ", sw) or "\t" end +-- Debug helper to print line details +local function debug_line(msg, details) + print(string.format( + "[DEBUG] %s:\n indent: '%s' (len=%d)\n marker: '%s'\n content: '%s'\n is_todo: %s", + msg, + details.indent, + #details.indent, + details.marker or "nil", + details.content, + details.is_todo + )) +end + -- Helper: Gets details for the current line including cursor position local function get_current_line_details_with_cursor() local cursor_pos = vim.api.nvim_win_get_cursor(0) @@ -275,14 +288,23 @@ local function setup_buffer_keymaps() -- Handle tab indentation for TODO lines local function press_tab() - local details = get_line_details(vim.api.nvim_win_get_cursor(0)[1]) + local lnum = vim.api.nvim_win_get_cursor(0)[1] + local details = get_line_details(lnum) + + print("\n[DEBUG TAB] Line "..lnum.." before:") + debug_line("Original", details) + if not details or not details.is_todo then + print("[DEBUG TAB] Not a TODO line, using default Tab") return vim.api.nvim_replace_termcodes("", true, false, true) end local indent_str = get_indent_string() local new_line = details.indent .. indent_str .. (details.marker or "-") .. " [ ] " .. details.content + + print("[DEBUG TAB] New line will be:", new_line) + print("[DEBUG TAB] Indent string:", "'"..indent_str.."' (length="..#indent_str..")") vim.api.nvim_set_current_line(new_line) -- Calculate new cursor column (preserve relative position) @@ -295,8 +317,14 @@ local function setup_buffer_keymaps() -- Handle shift-tab outdentation for TODO lines local function press_shift_tab() - local details = get_line_details(vim.api.nvim_win_get_cursor(0)[1]) + local lnum = vim.api.nvim_win_get_cursor(0)[1] + local details = get_line_details(lnum) + + print("\n[DEBUG SHIFT-TAB] Line "..lnum.." before:") + debug_line("Original", details) + if not details or not details.is_todo or #details.indent == 0 then + print("[DEBUG SHIFT-TAB] Not a TODO line or at min indent, using default S-Tab") return vim.api.nvim_replace_termcodes("", true, false, true) end @@ -304,6 +332,9 @@ local function setup_buffer_keymaps() local new_indent = details.indent:sub(1, -sw - 1) local new_line = new_indent .. (details.marker or "-") .. " [ ] " .. details.content + + print("[DEBUG SHIFT-TAB] New indent:", "'"..new_indent.."' (length="..#new_indent..")") + print("[DEBUG SHIFT-TAB] New line will be:", new_line) vim.api.nvim_set_current_line(new_line) -- Calculate new cursor column (preserve relative position)