diff --git a/lua/obsidian/util.lua b/lua/obsidian/util.lua index 9e1b5ec42..7b1e86a2c 100644 --- a/lua/obsidian/util.lua +++ b/lua/obsidian/util.lua @@ -478,7 +478,18 @@ end util.toggle_checkbox = function() local line_num = unpack(vim.api.nvim_win_get_cursor(0)) -- 1-indexed local line = vim.api.nvim_get_current_line() - if string.match(line, "^%s*- %[ %].*") then + + local checkbox_pattern = "^%s*- %[.*" + + if not string.match(line, checkbox_pattern) then + local unordered_list_pattern = "^([ ]*)[-*+] ([^%[])" + + if string.match(line, unordered_list_pattern) then + line = string.gsub(line, unordered_list_pattern, "%1- [ ] %2") + else + line = string.gsub(line, "^([%s]*)", "%1- [ ] ") + end + elseif string.match(line, "^%s*- %[ %].*") then line = util.string_replace(line, "- [ ]", "- [x]", 1) else for check_char in iter { "x", "~", ">", "-" } do