Command
The Command
interface is used to manage 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.
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()
Returns a boolean value indicating 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 an item by the name of the specified command.
Parameters:
name
A string that specifies the name of the command.
Return value:
A
CommandItem
object.
Example:
const commandItem = editor.command.getItem('bold');
isDisabled()
Returns a boolean value indicating whether 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()
Returns a boolean value indicating whether the specified command is selected.
Parameters:
name
A string that specifies the name of the command.
Return value:
true
if the 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 the selected value.
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 for commands that require an input argument. For example, the
heading
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');