Command
The Command interface manages a collection of commands.
Note
The constructor is not directly accessible. Instead, you can access its methods via the editor.command object.
Example:
editor.command.execute('bold');Instance methods
add()
Adds a new command to the collection.
Parameters:
nameA string that specifies the name of the command.
commandItemA CommandItem object that specifies the command item to be added.
Return value:
None.
Example:
editor.command.add('removeFormat', {
execute: () => {
editor.selection.removeMark();
editor.history.save();
},
});delete()
Removes a command from the collection by its name.
Parameters:
nameA string that specifies the name of the command.
Return value:
None.
Example:
editor.command.delete('removeFormat');getNames()
Returns the names of all registered commands.
Parameters:
None.
Return value:
An
Arrayobject containing the names of all commands.
Example:
const names = editor.command.getNames();has()
Checks whether the specified command exists.
Parameters:
nameA string that specifies the name of the command.
Return value:
trueif the the command exists.falseif not.
Example:
editor.command.has('helloWorld');getItem()
Returns a command item by its name.
Parameters:
nameA string that specifies the name of the command.
Return value:
A CommandItem object.
Example:
const commandItem = editor.command.getItem('bold');isDisabled()
Checks if the specified command is disabled.
Parameters:
nameA string that specifies the name of the command.
Return value:
trueif the the command is disabled.falseif not.
Example:
const isDisabled = editor.command.isDisabled('bold');isSelected()
Checks if the specified command is selected.
Parameters:
nameA string that specifies the name of the command.
Return value:
trueif the command is selected.falseif not.
Example:
const isSelected = editor.command.isSelected('bold');selectedValues()
Returns the selected values for the specified command.
Parameters:
nameA string that specifies the name of the command.
Return value:
An
Arrayobject that contains selected values.
Example:
const selectedValues = editor.command.selectedValues('align');execute()
Executes the specified command.
Parameters:
nameA string that specifies the name of the command.
valueOptionalAn argument required by some commands. For example, the
headingcommand requires a level such ash1,h2, andh3.Return value:
None.
Example:
// Adds bold.
editor.command.execute('bold');
// Changes current block to heading level 1.
editor.command.execute('heading', 'h1');