refactor: extract a function for writing a line

This commit is contained in:
Oliver Davies 2022-08-08 18:45:22 -04:00
parent 2a4c5b0682
commit 760b74ee6e

View file

@ -11,18 +11,21 @@ local current_line = vim.api.nvim_buf_get_lines(bufnr, cursor[1] - 1, cursor[1],
-- return string.find(line, checked_checkbox)
-- end
local write_line = function(new_line)
vim.api.nvim_buf_set_lines(bufnr, cursor[1] - 1, cursor[1], false, { new_line })
vim.api.nvim_win_set_cursor(0, cursor)
end
local M = {}
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 })
vim.api.nvim_win_set_cursor(0, cursor)
write_line(new_line)
end
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 })
vim.api.nvim_win_set_cursor(0, cursor)
write_line(new_line)
end
return M