In a monaco editor instance, you can call addAction
oraddCommand
Both provide the ability to execute a function based on key events
The online playground offers examples of how to add a command or how to add an action to an editor instance.
Example of an Action
editor.addAction({
id: 'my-unique-id',
label: 'My Label!!!',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
run: function() { alert('action called') }
});
Example of a Command
editor.addCommand(
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
function() { alert('called command') }
)
The documentation describes the type definitions, properties, and methods.
However, it's lacking when it comes to providing the context of when to use each, where they show up within the editor, and what each provides.
What's the difference between actions and commands?