diff --git a/plugin/todoer.lua b/plugin/todoer.lua index 0510f91..17034b2 100644 --- a/plugin/todoer.lua +++ b/plugin/todoer.lua @@ -29,12 +29,8 @@ vim.keymap.set("i", "", press_enter, { desc = "On enter", noremap = true, ex local function toggle_todo() local openpattern = "^%s*%- %[[ ]%]" - local closedpattern = "^%s*%- %[[x]%]" - local titleopenpattern = "^%s*# %[[ ]%]" - - -- create a variable called titleclosedpattern with a pattern that matches a string that starts with "# [x]" local titleclosedpattern = "^%s*# %[[x]%]" local line = vim.api.nvim_get_current_line() @@ -52,35 +48,27 @@ local function toggle_todo() line = string.gsub(line, titleclosedpattern, "# [ ]") vim.api.nvim_set_current_line(line) end - - -- if string.sub(line, 1, 5) == "- [ ]" then - -- line = string.sub(line, 6, -1) - -- line = "- [x]" .. line - -- vim.api.nvim_set_current_line(line) - -- elseif string.sub(line, 1, 5) == "- [x]" then - -- line = string.sub(line, 6, -1) - -- line = "- [ ]" .. line - -- vim.api.nvim_set_current_line(line) - -- elseif string.sub(line, 1, 5) == "# [ ]" then - -- line = string.sub(line, 6, -1) - -- line = "# [x]" .. line - -- vim.api.nvim_set_current_line(line) - -- elseif string.sub(line, 1, 5) == "# [x]" then - -- line = string.sub(line, 6, -1) - -- line = "# [ ]" .. line - -- vim.api.nvim_set_current_line(line) - -- end end vim.keymap.set("n", "tt", toggle_todo, { desc = "Toggle todo" }) -- function that checks if the current line doesn't start with the string "- [ ] " and, if it doesn't, adds the string at the beginning of the line local function add_todo() + local openpattern = "^%s*%- %[[ ]%]" + local closedpattern = "^%s*%- %[[x]%]" + local line = vim.api.nvim_get_current_line() - if string.sub(line, 1, 5) ~= "- [ ] " then + + if !string.match(line, openpattern) and !string.match(line, closedpattern) then line = "- [ ] " .. line 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" })