From a05a096b73b95c4312b77f05472c1dcd74bcbe14 Mon Sep 17 00:00:00 2001 From: borja Date: Mon, 27 Nov 2023 23:23:02 +0100 Subject: [PATCH] =?UTF-8?q?no=20a=C3=B1ade=20espacio=20extra=20al=20a?= =?UTF-8?q?=C3=B1adir=20todo=20si=20ya=20hay=20un=20espacio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/todoer.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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" })