mirror of
https://github.com/opdavies/toggle-checkbox.nvim.git
synced 2025-01-22 20:07:32 +00:00
feat: check or uncheck the current line
This commit is contained in:
parent
805aeab265
commit
c8da955004
|
@ -1,17 +1,26 @@
|
|||
local checked_character = "x"
|
||||
|
||||
local line_contains_a_checked_checkbox = function(line)
|
||||
return string.find(line, "[" .. checked_character .. "]")
|
||||
end
|
||||
local checked_checkbox = "[" .. checked_character .. "]"
|
||||
local unchecked_checkbox = "[ ]"
|
||||
|
||||
local bufnr = vim.api.nvim_buf_get_number(0)
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local current_line = vim.api.nvim_buf_get_lines(bufnr, cursor[1] - 1, cursor[1], false)[1] or ""
|
||||
|
||||
-- local line_contains_a_checked_checkbox = function(line)
|
||||
-- return string.find(line, checked_checkbox)
|
||||
-- end
|
||||
|
||||
local M = {}
|
||||
|
||||
M.check = function(line)
|
||||
return line:gsub("%[ %]", "[" .. checked_character .. "]")
|
||||
M.check = function()
|
||||
local new_line = current_line:gsub("%[ %]", checked_checkbox)
|
||||
vim.api.nvim_buf_set_lines(bufnr, cursor[1] - 1, cursor[1], false, { new_line })
|
||||
end
|
||||
|
||||
M.uncheck = function(line)
|
||||
return line:gsub("%[" .. checked_character .. "%]", "[]")
|
||||
M.uncheck = function()
|
||||
local new_line = current_line:gsub("%[" .. checked_character .. "%]", unchecked_checkbox)
|
||||
vim.api.nvim_buf_set_lines(bufnr, cursor[1] - 1, cursor[1], false, { new_line })
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Reference in a new issue