cambio quitar todo

main
borja 1 year ago
parent 8bc9e689b4
commit e75c9d3a82

@ -63,21 +63,23 @@ local function add_todo()
vim.api.nvim_set_current_line(line) vim.api.nvim_set_current_line(line)
vim.api.nvim_feedkeys("A", "n", true) vim.api.nvim_feedkeys("A", "n", true)
end 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 end
vim.keymap.set("n", "<leader>ta", add_todo, { desc = "Add todo" }) vim.keymap.set("n", "<leader>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 -- 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 function remove_todo()
local openpattern = "^%s*%- %[[ ]%]"
local closedpattern = "^%s*%- %[[x]%]"
local line = vim.api.nvim_get_current_line() 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) 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