ckeditor5-elements / QuickInsertCommand
Class: QuickInsertCommand
Inserts an element by its model name at a position: what the quick insert menu does, when an element is chosen. The menu itself is opened by the ElementQuickInsert plugin, with its open().
The target comes first, as in every ElementOrPositionCommand: a position, an element (meaning the position before it), or none (the selection).
editor.execute('quickInsert', position, 'heading1'); // Inserts a heading at the position.
editor.execute('quickInsert', undefined, 'softBreak'); // Inserts a line break at the selection.Only elements that the schema allows at exactly that position are inserted (see getAllowedElements): nothing is split to make room, so e.g. a heading cannot be inserted inside a paragraph.
After inserting, objects are selected; other elements get the selection inside them, in a new paragraph when they can hold blocks.
Extends
Constructors
Constructor
new QuickInsertCommand(editor): QuickInsertCommand;Parameters
| Parameter | Type |
|---|---|
editor | Editor |
Returns
QuickInsertCommand
Overrides
ElementOrPositionCommand.constructor
Properties
icon
icon: string | undefined;Observable
The icon (SVG string) of the command.
Inherited from
isForceDisabled
readonly isForceDisabled: boolean;Observable
Whether the command is disabled with forceDisabled() (and not enabled back with clearForceDisabled() for every id), so it is disabled for every target.
Inherited from
ElementOrPositionCommand.isForceDisabled
isToggleable
isToggleable: boolean = false;Whether the command can be "on" (see _isOnFor), e.g. because it toggles something. Its buttons then tell assistive technology whether it is on: toolbar buttons with aria-pressed, menu items with aria-checked. Defaults to false; the commands of one element that toggle it set it, e.g. ElementInlineCommand.
Inherited from
ElementOrPositionCommand.isToggleable
title
title: string;Observable
The title of the command.
Inherited from
ElementOrPositionCommand.title
tooltip
tooltip: string | boolean;Observable
The tooltip of the command. true uses the title.
Inherited from
ElementOrPositionCommand.tooltip
Methods
_getElement()
protected _getElement(elementOrPosition?):
| ModelElement
| null;Resolves the target (see _getElementOrPosition) to an element: a position becomes its parent element. Never returns a root.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
| ModelElement | null
Inherited from
ElementOrPositionCommand._getElement
_getElementOrPosition()
protected _getElementOrPosition(elementOrPosition?): ElementOrPosition | null;Returns the given position or element, or resolves it from the current selection when absent. Returns null for a target that is not in the document (any more), e.g. a removed element, so commands ignore such targets.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
ElementOrPosition | null
Inherited from
ElementOrPositionCommand._getElementOrPosition
_getPosition()
protected _getPosition(elementOrPosition?):
| ModelPosition
| null;Resolves the target (see _getElementOrPosition) to a position: an element becomes the position before it.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
| ModelPosition | null
Inherited from
ElementOrPositionCommand._getPosition
_getStateFor()
protected _getStateFor(elementOrPosition?): ElementOrPositionState;Returns whether the command is enabled and "on" for the target, before read-only mode and forceDisabled(): the one source of the state, for refresh and getState. By default, from _isEnabledFor and _isOnFor.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
Inherited from
ElementOrPositionCommand._getStateFor
_isEnabledFor()
protected _isEnabledFor(elementOrPosition?): boolean;Whether the command is enabled for the target. By default: when there is a target and it can be edited.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
boolean
Inherited from
ElementOrPositionCommand._isEnabledFor
_isOnFor()
protected _isOnFor(elementOrPosition?): boolean;Whether the command is "on" for the target. By default: never. Commands that override it should set isToggleable.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
boolean
Inherited from
ElementOrPositionCommand._isOnFor
_requireElement()
protected _requireElement(elementOrPosition?): ModelElement;Returns the element of the target (see _getElement), in execute() of a command that is enabled only for a target with an element: execute() runs only then, so there is one. Throws when there is none.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
Inherited from
ElementOrPositionCommand._requireElement
clearForceDisabled()
clearForceDisabled(id): void;Clears the disabling done by forceDisabled with this id. When no id is left, the command is refreshed, so isEnabled follows the selection again.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
void
Inherited from
ElementOrPositionCommand.clearForceDisabled
execute()
execute(elementOrPosition, name): void;Inserts the element named name at the target, when the schema allows it there.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition | ElementOrPosition | undefined |
name | string |
Returns
void
Overrides
ElementOrPositionCommand.execute
executeFor()
executeFor(elementOrPosition, ...args): unknown;Executes the command for the target, even when the command is disabled for the selection (execute() checks isEnabled, which follows the selection). Does nothing when the command is disabled for the target.
The target is the first argument of execute(); the other arguments are passed after it.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition | ElementOrPosition |
...args | unknown[] |
Returns
unknown
Inherited from
ElementOrPositionCommand.executeFor
forceDisabled()
forceDisabled(id): void;Disables the command for every target until it is enabled back with clearForceDisabled for every id it was disabled with. See isForceDisabled.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
void
Inherited from
ElementOrPositionCommand.forceDisabled
getAllowedElements()
getAllowedElements(elementOrPosition?, exclude?): string[];Returns the names of the model elements allowed at exactly the position (or the selection), in the order they were registered. Generic items (such as $text or $block) and the excluded names are skipped.
Parameters
| Parameter | Type | Default value |
|---|---|---|
elementOrPosition? | ElementOrPosition | undefined |
exclude? | readonly string[] | [] |
Returns
string[]
getInsertPosition()
getInsertPosition(elementOrPosition?):
| ModelPosition
| null;Returns the position where elements are inserted for the target: the position, the position before the element, or the selection.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
| ModelPosition | null
getState()
getState(elementOrPosition?): ElementOrPositionState;Returns whether the command would be enabled and "on" for the target, without changing isEnabled. Commands that change the data are disabled in read-only mode, and all commands are disabled when isForceDisabled.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
Inherited from
ElementOrPositionCommand.getState
hasAllowedElements()
hasAllowedElements(elementOrPosition?, exclude?): boolean;Whether an element is allowed at exactly the position (or the selection), as getAllowedElements returns them: it stops at the first one.
Parameters
| Parameter | Type | Default value |
|---|---|---|
elementOrPosition? | ElementOrPosition | undefined |
exclude? | readonly string[] | [] |
Returns
boolean
refresh()
refresh(elementOrPosition?): void;Sets isEnabled for the target (by default, the selection). See _getStateFor.
Parameters
| Parameter | Type |
|---|---|
elementOrPosition? | ElementOrPosition |
Returns
void