diff --git a/TODO.md b/TODO.md index 416b2a2..cd3137b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,4 @@ # TODO - [ ] Fix press_enter when line is indented - +- [ ] When line is a todo, tab indents diff --git a/plugin/todoer.lua b/plugin/todoer.lua index fa5906f..8c8d695 100644 --- a/plugin/todoer.lua +++ b/plugin/todoer.lua @@ -27,6 +27,22 @@ local function press_enter() end vim.keymap.set("i", "", press_enter, { desc = "On enter", noremap = true, expr = true }) +-- indent line if tab is pressed when line is a todo +local function press_tab() + local current_line = vim.api.nvim_get_current_line() + + -- Check if current line matches the patterns + local openpattern = "%- %[[ ]%]" + local closedpattern = "%- %[[x]%]" + + if string.match(current_line, openpattern) or string.match(current_line, closedpattern) then + vim.api.nvim_feedkeys(vim.api.nvim_eval('"\\"'), "n", true) + vim.api.nvim_feedkeys(">", "n", true) + vim.api.nvim_feedkeys("A", "n", true) + end +end +vim.keymap.set("i", "", press_tab, { desc = "On tab", noremap = true, expr = true }) + -- function that checks if the current line starts with the string "- [ ]" or "- [x]" and toggles the x local function toggle_todo()