no añade espacio extra al añadir todo si ya hay un espacio

main
borja 1 year ago
parent e75c9d3a82
commit a05a096b73

@ -1,3 +1,4 @@
-- Empty keymap for the menu
vim.keymap.set("n", "<leader>t", function() end, { desc = "+Todos" }) vim.keymap.set("n", "<leader>t", function() end, { desc = "+Todos" })
-- add new todo line when previous is already a todo -- 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() local line = vim.api.nvim_get_current_line()
if not string.match(line, openpattern) and not string.match(line, closedpattern) then if not string.match(line, openpattern) and not string.match(line, closedpattern) then
if not string.sub(line, 1, 1) == " " then
line = "- [ ] " .. line line = "- [ ] " .. line
vim.api.nvim_set_current_line(line) vim.api.nvim_set_current_line(line)
vim.api.nvim_feedkeys("A", "n", true) 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
end end
vim.keymap.set("n", "<leader>ta", add_todo, { desc = "Add todo" }) vim.keymap.set("n", "<leader>ta", add_todo, { desc = "Add todo" })
@ -77,9 +83,5 @@ local function remove_todo()
line = string.gsub(line, closedpattern, "") line = string.gsub(line, closedpattern, "")
vim.api.nvim_set_current_line(line) vim.api.nvim_set_current_line(line)
end 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 end
vim.keymap.set("n", "<leader>td", remove_todo, { desc = "Remove todo" }) vim.keymap.set("n", "<leader>td", remove_todo, { desc = "Remove todo" })

Loading…
Cancel
Save