engine/model/utils/deletecontent
@ckeditor/ckeditor5-engine/src/model/utils/deletecontent
Filtering
Functions
-
deleteContent( model, selection, options = { [options.doNotAutoparagraph], [options.doNotFixSelection], [options.doNotResetEntireContent], [options.leaveUnmerged] } ) → void
module:engine/model/utils/deletecontent~deleteContent
Deletes content of the selection and merge siblings. The resulting selection is always collapsed.
Note: Use
deleteContent
instead of this function. This function is only exposed to be reusable in algorithms which change thedeleteContent
method's behavior.Parameters
model : Model
The model in context of which the insertion should be performed.
selection : Selection | DocumentSelection
Selection of which the content should be deleted.
options : object
-
Properties
[ options.doNotAutoparagraph ] : boolean
Whether to create a paragraph if after content deletion selection is moved to a place where text cannot be inserted.
For example
<paragraph>x</paragraph>[<imageBlock src="foo.jpg"></imageBlock>]
will become:<paragraph>x</paragraph><paragraph>[]</paragraph>
with the option disabled (doNotAutoparagraph == false
)<paragraph>x</paragraph>[]
with the option enabled (doNotAutoparagraph == true
).
If you use this option you need to make sure to handle invalid selections yourself or leave them to the selection post-fixer (may not always work).
Note: If there is no valid position for the selection, the paragraph will always be created:
[<imageBlock src="foo.jpg"></imageBlock>]
-><paragraph>[]</paragraph>
.[ options.doNotFixSelection ] : boolean
Whether given selection-to-remove should be fixed if it ends at the beginning of an element.
By default,
deleteContent()
will fix selection before performing a deletion, so that the selection does not end at the beginning of an element. For example, selection<heading>[Heading</heading><paragraph>]Some text.</paragraph>
will be treated as it was<heading>[Heading]</heading><paragraph>Some text.</paragraph>
. As a result, the elements will not get merged.If selection is as in example, visually, the next element (paragraph) is not selected and it may be confusing for the user that the elements got merged. Selection is set up like this by browsers when a user triple-clicks on some text.
However, in some cases, it is expected to remove content exactly as selected in the selection, without any fixing. In these cases, this flag can be set to
true
, which will prevent fixing the selection.[ options.doNotResetEntireContent ] : boolean
Whether to skip replacing the entire content with a paragraph when the entire content was selected.
For example
<heading>[x</heading><paragraph>y]</paragraph>
will become:<paragraph>^</paragraph>
with the option disabled (doNotResetEntireContent == false
)<heading>^</heading>
with enabled (doNotResetEntireContent == true
).
[ options.leaveUnmerged ] : boolean
Whether to merge elements after removing the content of the selection.
For example
<heading>x[x</heading><paragraph>y]y</paragraph>
will become:<heading>x^y</heading>
with the option disabled (leaveUnmerged == false
)<heading>x^</heading><paragraph>y</paragraph>
with enabled (leaveUnmerged == true
).
Defaults to
{}
Returns
void
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.