mirror of
https://github.com/opdavies/toggle-checkbox.nvim.git
synced 2025-01-22 20:07:32 +00:00
refactor: extract a variable for the start line
This commit is contained in:
parent
c23e97c6ca
commit
9c3db1f2cb
|
@ -22,7 +22,8 @@ local M = {}
|
||||||
M.toggle = function()
|
M.toggle = function()
|
||||||
local bufnr = vim.api.nvim_buf_get_number(0)
|
local bufnr = vim.api.nvim_buf_get_number(0)
|
||||||
local cursor = vim.api.nvim_win_get_cursor(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 start_line = cursor[1] - 1
|
||||||
|
local current_line = vim.api.nvim_buf_get_lines(bufnr, start_line, start_line + 1, false)[1] or ""
|
||||||
|
|
||||||
-- If the line contains a checked checkbox then uncheck it.
|
-- If the line contains a checked checkbox then uncheck it.
|
||||||
-- Otherwise, if it contains an unchecked checkbox, check it.
|
-- Otherwise, if it contains an unchecked checkbox, check it.
|
||||||
|
@ -33,7 +34,7 @@ M.toggle = function()
|
||||||
new_line = checkbox.uncheck(current_line)
|
new_line = checkbox.uncheck(current_line)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, cursor[1] - 1, cursor[1], false, { new_line })
|
vim.api.nvim_buf_set_lines(bufnr, start_line, start_line + 1, false, { new_line })
|
||||||
vim.api.nvim_win_set_cursor(0, cursor)
|
vim.api.nvim_win_set_cursor(0, cursor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue