diff --git a/CHANGELOG.md b/CHANGELOG.md index b585ed0e2..832c76419 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `opts.follow_img_func` option for customizing how to handle image paths. - Added better handling for undefined template fields, which will now be prompted for. +- Added :ObsidianToggleCheckboxReverse command. This command goes in reverse order compared to the :ObsidianToggleCheckbox. ### Changed diff --git a/README.md b/README.md index d5d382b62..58c3fc3a4 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ _Keep in mind this plugin is not meant to replace Obsidian, but to complement it - `:ObsidianToggleCheckbox` to cycle through checkbox options. +- `:ObsidianToggleCheckboxReverse` to cycle through checkbox options in a reverse order. + - `:ObsidianNewFromTemplate [TITLE]` to create a new note from a template in the templates folder. Selecting from a list using your preferred picker. This command has one optional argument: the title of the new note. diff --git a/lua/obsidian/commands/init.lua b/lua/obsidian/commands/init.lua index f31eaf8ea..d52778d90 100644 --- a/lua/obsidian/commands/init.lua +++ b/lua/obsidian/commands/init.lua @@ -4,6 +4,7 @@ local iter = require("obsidian.itertools").iter local command_lookups = { ObsidianCheck = "obsidian.commands.check", ObsidianToggleCheckbox = "obsidian.commands.toggle_checkbox", + ObsidianToggleCheckboxReverse = "obsidian.commands.toggle_checkbox_reverse", ObsidianToday = "obsidian.commands.today", ObsidianYesterday = "obsidian.commands.yesterday", ObsidianTomorrow = "obsidian.commands.tomorrow", @@ -170,6 +171,8 @@ M.register("ObsidianFollowLink", { opts = { nargs = "?", desc = "Follow referenc M.register("ObsidianToggleCheckbox", { opts = { nargs = 0, desc = "Toggle checkbox" } }) +M.register("ObsidianToggleCheckboxReverse", { opts = { nargs = 0, desc = "Toggle checkbox in reverse order" } }) + M.register("ObsidianWorkspace", { opts = { nargs = "?", desc = "Check or switch workspace" } }) M.register( diff --git a/lua/obsidian/commands/toggle_checkbox_reverse.lua b/lua/obsidian/commands/toggle_checkbox_reverse.lua new file mode 100644 index 000000000..39fc249f1 --- /dev/null +++ b/lua/obsidian/commands/toggle_checkbox_reverse.lua @@ -0,0 +1,10 @@ +local toggle_checkbox = require("obsidian.util").toggle_checkbox + +---@param client obsidian.Client +return function(client) + local checkboxes = vim.tbl_keys(client.opts.ui.checkboxes) + table.sort(checkboxes, function(a, b) + return (client.opts.ui.checkboxes[a].order or 1000) > (client.opts.ui.checkboxes[b].order or 1000) + end) + toggle_checkbox(checkboxes) +end