This automatically triggers a command bound to an actionButton, and notably also shows the keyboard shortcut connected to it (if any)
1.7 KiB
1.7 KiB
description, tags
| description | tags |
|---|---|
| APIs to define custom action buttons | meta/api |
APIs to more conveniently define action buttons (alternative to setting them via regular ^Library/Std/Config).
API
actionButton.define(spec)
Keys to define:
icon: feather icon to use for your buttoncommand(optional): command name to invoke when clicked. When set, the command's keyboard shortcut is automatically shown in the tooltip. Replacesrun.run(optional): function to invoke once the button is pushed. Use this for custom logic that doesn't map to a single command.description(optional): description of button (appears on hover)priority(optional): determines priority of button (the higher, the earlier in the list)mobile: when set totruethis button will only appear on mobile devicesstandalone: when set totruethis button will only appear in standalone/PWA mode; whenfalse, only in browser modedropdown(optional): when set tofalse, the button stays visible outside the dropdown menu on mobile (default:true)
Either command or run should be specified.
Examples
-- Bind a button to a command (keyboard shortcut shown on hover)
actionButton.define {
icon = "pen-tool",
description = "Start journaling",
command = "Journal: Today",
}
-- Custom button with a run function
actionButton.define {
icon = "eye",
run = function()
editor.setUiOption("forcedROMode", true)
editor.rebuildEditorState()
end
}
Implementation
-- priority: 100
actionButton = actionButton or {}
function actionButton.define(spec)
local actionButtonConfig = config.get("actionButtons", {})
table.insert(actionButtonConfig, spec)
end