2025-01-19 21:32:11 +08:00
|
|
|
|
APIs related to editor commands
|
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
|
### command.define(commandDef)
|
2025-01-19 21:32:11 +08:00
|
|
|
|
Registers a command.
|
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
|
Available keys:
|
|
|
|
|
|
|
|
|
|
* `name`: Name of the command
|
|
|
|
|
* `run`: Callback function
|
|
|
|
|
* `contexts`: AST node context in which this command should be available
|
|
|
|
|
* `priority`: Command priority (how high it appears in the list)
|
|
|
|
|
* `key`: Windows/Linux key binding (and mac, if not separately defined)
|
|
|
|
|
* `mac`: Mac-specific key binding
|
|
|
|
|
* `hide`: Hide this command from the [[Command Palette]]
|
|
|
|
|
* `requireMode`: `rw` or `ro` — only enable this command in a particular mode (read-write, or read-only)
|
|
|
|
|
|
2025-01-19 21:32:11 +08:00
|
|
|
|
Example:
|
|
|
|
|
```lua
|
|
|
|
|
command.define {
|
|
|
|
|
name = "My custom command",
|
|
|
|
|
run = function()
|
2025-02-06 17:04:45 +08:00
|
|
|
|
editor.flashNotification "Triggered my custom command"
|
2025-01-19 21:32:11 +08:00
|
|
|
|
end
|
|
|
|
|
}
|