diff --git a/plugin/todoer.lua b/plugin/todoer.lua index 6558778..153b6e2 100644 --- a/plugin/todoer.lua +++ b/plugin/todoer.lua @@ -63,21 +63,23 @@ local function add_todo() vim.api.nvim_set_current_line(line) vim.api.nvim_feedkeys("A", "n", true) end - - -- if string.sub(line, 1, 5) ~= "- [ ] " then - -- line = "- [ ] " .. line - -- vim.api.nvim_set_current_line(line) - -- vim.api.nvim_feedkeys("A", "n", true) - -- end end vim.keymap.set("n", "ta", add_todo, { desc = "Add todo" }) -- function that checks if the current line starts with the string "- [ ]" or "- [x]" and, if it does, removes that string from the line local function remove_todo() + local openpattern = "^%s*%- %[[ ]%]" + local closedpattern = "^%s*%- %[[x]%]" local line = vim.api.nvim_get_current_line() - if string.sub(line, 1, 6) == "- [ ] " or string.sub(line, 1, 6) == "- [x] " then - line = string.sub(line, 7, -1) + + if string.match(line, openpattern) or string.match(line, closedpattern) then + line = string.gsub(line, openpattern, "") + 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" })