Skip to content

Commit

Permalink
Fix handling checkboxes with regex magic chars
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed May 28, 2024
1 parent 0890a3f commit 3fe34f5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed finding backlinks with URL-encoded path references.
- Fixed using templates with frontmatter when `disable_frontmatter` is set to true. Previously the frontmatter would be removed when the template was inserted, now it will be kept unchanged.
- Add compatibility for NVIM 0.11
- Fixed handling check boxes with characters that have a special meaning in regular expressions (e.g. "?").

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

Expand Down
2 changes: 1 addition & 1 deletion lua/obsidian/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ end
local function get_line_check_extmarks(marks, line, lnum, ui_opts)
for char, opts in pairs(ui_opts.checkboxes) do
-- TODO: escape `char` if needed
if string.match(line, "^%s*- %[" .. char .. "%]") then
if string.match(line, "^%s*- %[" .. util.escape_magic_characters(char) .. "%]") then
local indent = util.count_indent(line)
marks[#marks + 1] = ExtMark.new(
nil,
Expand Down
2 changes: 1 addition & 1 deletion lua/obsidian/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ util.toggle_checkbox = function(opts, line_num)
end
else
for i, check_char in enumerate(checkboxes) do
if string.match(line, "^%s*- %[" .. check_char .. "%].*") then
if string.match(line, "^%s*- %[" .. util.escape_magic_characters(check_char) .. "%].*") then
if i == #checkboxes then
i = 0
end
Expand Down

0 comments on commit 3fe34f5

Please sign in to comment.