Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional line number argument to toggle_checkbox, defaulting to the current line number if not provided. #548

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions lua/obsidian/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down