diff --git a/plugin/todoer.lua b/plugin/todoer.lua index 153b6e2..eb16fc9 100644 --- a/plugin/todoer.lua +++ b/plugin/todoer.lua @@ -1,3 +1,4 @@ +-- Empty keymap for the menu vim.keymap.set("n", "t", function() end, { desc = "+Todos" }) -- add new todo line when previous is already a todo @@ -59,9 +60,14 @@ local function add_todo() local line = vim.api.nvim_get_current_line() if not string.match(line, openpattern) and not string.match(line, closedpattern) then - line = "- [ ] " .. line - vim.api.nvim_set_current_line(line) - vim.api.nvim_feedkeys("A", "n", true) + if not string.sub(line, 1, 1) == " " then + line = "- [ ] " .. line + vim.api.nvim_set_current_line(line) + else + line = "- [ ]" .. line + vim.api.nvim_set_current_line(line) + end + -- vim.api.nvim_feedkeys("A", "n", true) -- move cursor to the end of the line end end vim.keymap.set("n", "ta", add_todo, { desc = "Add todo" }) @@ -77,9 +83,5 @@ local function remove_todo() line = string.gsub(line, closedpattern, "") vim.api.nvim_set_current_line(line) end - -- if string.sub(line, 1, 6) == "- [ ] " or string.sub(line, 1, 6) == "- [x] " then - -- line = string.sub(line, 7, -1) - -- vim.api.nvim_set_current_line(line) - -- end end vim.keymap.set("n", "td", remove_todo, { desc = "Remove todo" })