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:
name
A string that specifies the name of the command.
commandItem
A 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:
name
A 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
Array
object containing the names of all commands.
Example:
const names = editor.command.getNames();
has()
Checks whether the specified command exists.
Parameters:
name
A string that specifies the name of the command.
Return value:
true
if the the command exists.false
if not.
Example:
editor.command.has('helloWorld');
getItem()
Returns a command item by its name.
Parameters:
name
A 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:
name
A string that specifies the name of the command.
Return value:
true
if the the command is disabled.false
if not.
Example:
const isDisabled = editor.command.isDisabled('bold');
isSelected()
Checks if the specified command is selected.
Parameters:
name
A string that specifies the name of the command.
Return value:
true
if the command is selected.false
if not.
Example:
const isSelected = editor.command.isSelected('bold');
selectedValues()
Returns the selected values for the specified command.
Parameters:
name
A string that specifies the name of the command.
Return value:
An
Array
object that contains selected values.
Example:
const selectedValues = editor.command.selectedValues('align');
execute()
Executes the specified command.
Parameters:
name
A string that specifies the name of the command.
value
OptionalAn argument required by some commands. For example, the
heading
command 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');