refactor: extract a variable for the start line

This commit is contained in:
Oliver Davies 2022-08-09 09:48:24 -04:00
parent c23e97c6ca
commit 9c3db1f2cb

View file

@ -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