diff --git a/CHANGELOG.md b/CHANGELOG.md index 1183501e7..475927ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added an optional line number argument for `util.toggle_checkbox()`, that defaults to the current line. + ### Fixed - Ensure toggle checkbox mapping uses checkbox configuration. diff --git a/lua/obsidian/util.lua b/lua/obsidian/util.lua index 218dd0e6a..caf06b7e0 100644 --- a/lua/obsidian/util.lua +++ b/lua/obsidian/util.lua @@ -493,9 +493,10 @@ util.zettel_id = function() end ---Toggle the checkbox on the line that the cursor is on. -util.toggle_checkbox = function(opts) - local line_num = unpack(vim.api.nvim_win_get_cursor(0)) -- 1-indexed - local line = vim.api.nvim_get_current_line() +util.toggle_checkbox = function(opts, line_num) + -- Allow line_num to be optional, defaulting to the current line if not provided + line_num = line_num or unpack(vim.api.nvim_win_get_cursor(0)) + local line = vim.api.nvim_buf_get_lines(0, line_num - 1, line_num, false)[1] local checkbox_pattern = "^%s*- %[.] " local checkboxes = opts or { " ", "x" }