Skip to content

Commit

Permalink
fix: recover toggle_checkbox util's condition to create a checkbox wi…
Browse files Browse the repository at this point in the history
…th a line without a checkbox (#537)

* fix: recover toggle_checkbox util's condition to create a checkbox with a line without a checkbox

* clean up

---------

Co-authored-by: CaeChao <winston@An0nym0us1q84>
Co-authored-by: epwalsh <petew@allenai.org>
  • Loading branch information
3 people committed Apr 10, 2024
1 parent 534409d commit d8eb52f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

### Fixed

- Fixed regression with toggle checkbox util/mapping.

## [v3.7.7](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.7) - 2024-04-05

### Fixed
Expand Down
6 changes: 4 additions & 2 deletions lua/obsidian/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,14 @@ util.toggle_checkbox = function(opts)
local checkboxes = opts or { " ", "x" }

if not string.match(line, checkbox_pattern) then
if opts then -- not create new checkbox with command
return
end
local unordered_list_pattern = "^(%s*)[-*+] (.*)"

if string.match(line, unordered_list_pattern) then
line = string.gsub(line, unordered_list_pattern, "%1- [ ] %2")
else
return
line = string.gsub(line, "^(%s*)", "%1- [ ] ")
end
else
for i, check_char in enumerate(checkboxes) do
Expand Down

0 comments on commit d8eb52f

Please sign in to comment.