ModelWriter
The model can only be modified by using the writer. It should be used whenever you want to create a node, modify child nodes, attributes or text, set the selection's position and its attributes.
The instance of the writer is only available in the change() or enqueueChange().
model.change( writer => {
writer.insertText( 'foo', paragraph, 'end' );
} );
Note that the writer should never be stored and used outside of the change() and enqueueChange() blocks.
Note that writer's methods do not check the ModelSchema. It is possible to create incorrect model structures by using the writer. Read more about in "Who checks the schema?".
Properties
module:engine/model/writer~ModelWriter#batchThe batch to which this writer will add changes.
module:engine/model/writer~ModelWriter#modelInstance of the model on which this writer operates.
Methods
constructor( model, batch )internalmodule:engine/model/writer~ModelWriter#constructorCreates a writer instance.
Note: It is not recommended to use it directly. Use
Model#change()orModel#enqueueChange()instead.Parameters
module:engine/model/writer~ModelWriter#addMarkerAdds a marker. Marker is a named range, which tracks changes in the document and updates its range automatically, when model tree changes.
As the first parameter you can set marker name.
The required
options.usingOperationparameter lets you decide if the marker should be managed by operations or not. See marker class description to learn about the difference between markers managed by operations and not-managed by operations.The
options.affectsDataparameter, which defaults tofalse, allows you to define if a marker affects the data. It should betruewhen the marker change changes the data returned by theeditor.getData()method. When set totrueit fires thechange:dataevent. When set tofalseit fires thechangeevent.Create marker directly base on marker's name:
addMarker( markerName, { range, usingOperation: false } );Copy codeCreate marker using operation:
addMarker( markerName, { range, usingOperation: true } );Copy codeCreate marker that affects the editor data:
addMarker( markerName, { range, usingOperation: false, affectsData: true } );Copy codeNote: For efficiency reasons, it's best to create and keep as little markers as possible.
Parameters
name : stringName of a marker to create - must be unique.
options : object- Properties
[ options.affectsData ] : booleanFlag indicating that the marker changes the editor data.
options.range : ModelRangeMarker range.
options.usingOperation : booleanFlag indicating that the marker should be added by MarkerOperation. See
managedUsingOperations.
Returns
MarkerMarker that was set.
Related:
addRoot( rootName, elementName ) → ModelRootElementmodule:engine/model/writer~ModelWriter#addRootAdds a new root to the document (or re-attaches a detached root).
Throws an error, if trying to add a root that is already added and attached.
Parameters
rootName : stringName of the added root.
elementName : stringThe element name. Defaults to
'$root'which also has some basic schema defined (e.g.$blockelements are allowed inside the$root). Make sure to define a proper schema if you use a different name.Defaults to
'$root'
Returns
ModelRootElementThe added root element.
append( item, parent ) → voidmodule:engine/model/writer~ModelWriter#appendInserts item at the end of the given parent.
const paragraph = writer.createElement( 'paragraph' ); writer.append( paragraph, root );Copy codeNote that if the item already has parent it will be removed from the previous parent.
If you want to move range instead of an item use
Writer#move().Parameters
item : ModelDocumentFragment | ModelItemItem or document fragment to insert.
parent : ModelElement | ModelDocumentFragment
Returns
void
appendElement( name, attributes, parent ) → voidmodule:engine/model/writer~ModelWriter#appendElement:WITH_ATTRIBUTESCreates element with specified attributes and inserts it at the end of the parent.
writer.appendElement( 'paragraph', { alignment: 'center' }, root );Copy codeParameters
name : stringName of the element.
attributes : ModelNodeAttributesElements attributes.
parent : ModelElement | ModelDocumentFragment
Returns
void
appendElement( name, parent ) → voidmodule:engine/model/writer~ModelWriter#appendElement:WITHOUT_ATTRIBUTESCreates element and inserts it at the end of the parent.
writer.appendElement( 'paragraph', root );Copy codeParameters
name : stringName of the element.
parent : ModelElement | ModelDocumentFragment
Returns
void
appendText( text, attributes, parent ) → voidmodule:engine/model/writer~ModelWriter#appendText:WITH_ATTRIBUTESCreates text node with specified attributes and inserts it at the end of the parent.
writer.appendText( 'foo', { bold: true }, paragraph );Copy codeParameters
text : stringText data.
attributes : ModelNodeAttributesText attributes.
parent : ModelElement | ModelDocumentFragment
Returns
void
appendText( text, parent ) → voidmodule:engine/model/writer~ModelWriter#appendText:WITHOUT_ATTRIBUTESCreates text node and inserts it at the end of the parent.
writer.appendText( 'foo', paragraph );Copy codeParameters
text : stringText data.
parent : ModelElement | ModelDocumentFragment
Returns
void
clearAttributes( itemOrRange ) → voidmodule:engine/model/writer~ModelWriter#clearAttributesRemoves all attributes from all elements in the range or from the given item.
Parameters
itemOrRange : ModelRange | ModelItemModel item or range from which all attributes will be removed.
Returns
void
cloneElement( element, deep ) → ModelElementmodule:engine/model/writer~ModelWriter#cloneElementCreates a copy of the element and returns it. Created element has the same name and attributes as the original element. If clone is deep, the original element's children are also cloned. If not, then empty element is returned.
Parameters
element : ModelElementThe element to clone.
deep : booleanIf set to
trueclones element and all its children recursively. When set tofalse, element will be cloned without any child.Defaults to
true
Returns
module:engine/model/writer~ModelWriter#createDocumentFragmentcreateElement( name, [ attributes ] ) → ModelElementmodule:engine/model/writer~ModelWriter#createElementCreates a new element.
writer.createElement( 'paragraph' ); writer.createElement( 'paragraph', { alignment: 'center' } );Copy codeParameters
name : stringName of the element.
[ attributes ] : ModelNodeAttributesElements attributes.
Returns
ModelElementCreated element.
createPositionAfter( item ) → ModelPositionmodule:engine/model/writer~ModelWriter#createPositionAfterShortcut for
Model#createPositionAfter().Parameters
item : ModelItemItem after which the position should be placed.
Returns
createPositionAt( itemOrPosition, [ offset ] ) → ModelPositionmodule:engine/model/writer~ModelWriter#createPositionAtShortcut for
Model#createPositionAt().Parameters
itemOrPosition : ModelDocumentFragment | ModelPosition | ModelItem[ offset ] : ModelPositionOffsetOffset or one of the flags. Used only when first parameter is a model item.
Returns
createPositionBefore( item ) → ModelPositionmodule:engine/model/writer~ModelWriter#createPositionBeforeShortcut for
Model#createPositionBefore().Parameters
item : ModelItemItem after which the position should be placed.
Returns
createPositionFromPath( root, path, [ stickiness ] ) → ModelPositionmodule:engine/model/writer~ModelWriter#createPositionFromPathShortcut for
Model#createPositionFromPath().Parameters
root : ModelElement | ModelDocumentFragmentRoot of the position.
path : readonly Array<number>Position path. See
path.[ stickiness ] : ModelPositionStickinessPosition stickiness. See
ModelPositionStickiness.
Returns
createRange( start, [ end ] ) → ModelRangemodule:engine/model/writer~ModelWriter#createRangeShortcut for
Model#createRange().Parameters
start : ModelPositionStart position.
[ end ] : ModelPositionEnd position. If not set, range will be collapsed at
startposition.
Returns
createRangeIn( element ) → ModelRangemodule:engine/model/writer~ModelWriter#createRangeInShortcut for
Model#createRangeIn().Parameters
element : ModelElement | ModelDocumentFragmentElement which is a parent for the range.
Returns
createRangeOn( element ) → ModelRangemodule:engine/model/writer~ModelWriter#createRangeOnShortcut for
Model#createRangeOn().Parameters
element : ModelItemElement which is a parent for the range.
Returns
createSelection( [ selectable ], [ options ] = { [options.backward] } ) → ModelSelectionmodule:engine/model/writer~ModelWriter#createSelection:SELECTABLEShortcut for
Model#createSelection().Parameters
[ selectable ] : null | ModelPosition | ModelRange | ModelSelection | ModelDocumentSelection | Iterable<ModelRange>[ options ] : object- Properties
[ options.backward ] : boolean
Returns
createSelection( selectable, placeOrOffset, [ options ] = { [options.backward] } ) → ModelSelectionmodule:engine/model/writer~ModelWriter#createSelection:NODE_OFFSETShortcut for
Model#createSelection().Parameters
selectable : ModelNodeplaceOrOffset : ModelPlaceOrOffset[ options ] : object- Properties
[ options.backward ] : boolean
Returns
createText( data, [ attributes ] ) → ModelTextmodule:engine/model/writer~ModelWriter#createTextCreates a new text node.
writer.createText( 'foo' ); writer.createText( 'foo', { bold: true } );Copy codeParameters
data : stringText data.
[ attributes ] : ModelNodeAttributesText attributes.
Returns
ModelTextCreated text node.
detachRoot( rootOrName ) → voidmodule:engine/model/writer~ModelWriter#detachRootDetaches the root from the document.
All content and markers are removed from the root upon detaching. New content and new markers cannot be added to the root, as long as it is detached.
A root cannot be fully removed from the document, it can be only detached. A root is permanently removed only after you re-initialize the editor and do not specify the root in the initial data.
A detached root can be re-attached using
addRoot.Throws an error if the root does not exist or the root is already detached.
Parameters
rootOrName : string | ModelRootElementName of the detached root.
Returns
void
insert( item, itemOrPosition, offset ) → voidmodule:engine/model/writer~ModelWriter#insertInserts item on given position.
const paragraph = writer.createElement( 'paragraph' ); writer.insert( paragraph, position );Copy codeInstead of using position you can use parent and offset:
const text = writer.createText( 'foo' ); writer.insert( text, paragraph, 5 );Copy codeYou can also use
endinstead of the offset to insert at the end:const text = writer.createText( 'foo' ); writer.insert( text, paragraph, 'end' );Copy codeOr insert before or after another element:
const paragraph = writer.createElement( 'paragraph' ); writer.insert( paragraph, anotherParagraph, 'after' );Copy codeThese parameters works the same way as
writer.createPositionAt().Note that if the item already has parent it will be removed from the previous parent.
Note that you cannot re-insert a node from a document to a different document or a document fragment. In this case,
model-writer-insert-forbidden-moveis thrown.If you want to move range instead of an item use
Writer#move().Note: For a paste-like content insertion mechanism see
model.insertContent().Parameters
item : ModelDocumentFragment | ModelItemItem or document fragment to insert.
itemOrPosition : ModelDocumentFragment | ModelPosition | ModelItemoffset : ModelPositionOffsetOffset or one of the flags. Used only when second parameter is a model item.
Defaults to
0
Returns
void
insertElement( name, attributes, itemOrPosition, [ offset ] ) → voidmodule:engine/model/writer~ModelWriter#insertElement:WITH_ATTRIBUTESCreates and inserts element with specified attributes on given position.
writer.insertElement( 'paragraph', { alignment: 'center' }, position );Copy codeInstead of using position you can use parent and offset or define that text should be inserted at the end or before or after other node:
// Inserts paragraph in the root at offset 5: writer.insertElement( 'paragraph', { alignment: 'center' }, root, 5 ); // Inserts paragraph at the end of a blockquote: writer.insertElement( 'paragraph', { alignment: 'center' }, blockquote, 'end' ); // Inserts after an image: writer.insertElement( 'paragraph', { alignment: 'center' }, image, 'after' );Copy codeThese parameters works the same way as
writer.createPositionAt().Parameters
name : stringName of the element.
attributes : ModelNodeAttributesElements attributes.
itemOrPosition : ModelDocumentFragment | ModelPosition | ModelItem[ offset ] : ModelPositionOffsetOffset or one of the flags. Used only when third parameter is a model item.
Returns
void
insertElement( name, itemOrPosition, [ offset ] ) → voidmodule:engine/model/writer~ModelWriter#insertElement:WITHOUT_ATTRIBUTESCreates and inserts element on given position. You can optionally set attributes:
writer.insertElement( 'paragraph', position );Copy codeInstead of using position you can use parent and offset or define that text should be inserted at the end or before or after other node:
// Inserts paragraph in the root at offset 5: writer.insertElement( 'paragraph', root, 5 ); // Inserts paragraph at the end of a blockquote: writer.insertElement( 'paragraph', blockquote, 'end' ); // Inserts after an image: writer.insertElement( 'paragraph', image, 'after' );Copy codeThese parameters works the same way as
writer.createPositionAt().Parameters
name : stringName of the element.
itemOrPosition : ModelDocumentFragment | ModelPosition | ModelItem[ offset ] : ModelPositionOffsetOffset or one of the flags. Used only when second parameter is a model item.
Returns
void
insertText( text, [ attributes ], [ itemOrPosition ], [ offset ] ) → voidmodule:engine/model/writer~ModelWriter#insertText:WITH_ATTRIBUTESCreates and inserts text with specified attributes on given position.
writer.insertText( 'foo', { bold: true }, position );Copy codeInstead of using position you can use parent and offset or define that text should be inserted at the end or before or after other node:
// Inserts 'foo' in paragraph, at offset 5: writer.insertText( 'foo', { bold: true }, paragraph, 5 ); // Inserts 'foo' at the end of a paragraph: writer.insertText( 'foo', { bold: true }, paragraph, 'end' ); // Inserts 'foo' after an image: writer.insertText( 'foo', { bold: true }, image, 'after' );Copy codeThese parameters work in the same way as
writer.createPositionAt().Parameters
text : stringText data.
[ attributes ] : ModelNodeAttributesText attributes.
[ itemOrPosition ] : ModelPosition | ModelItem[ offset ] : ModelPositionOffsetOffset or one of the flags. Used only when third parameter is a model item.
Returns
void
insertText( text, [ itemOrPosition ], [ offset ] ) → voidmodule:engine/model/writer~ModelWriter#insertText:WITHOUT_ATTRIBUTESCreates and inserts text on given position.
writer.insertText( 'foo', position );Copy codeInstead of using position you can use parent and offset or define that text should be inserted at the end or before or after other node:
// Inserts 'foo' in paragraph, at offset 5: writer.insertText( 'foo', paragraph, 5 ); // Inserts 'foo' at the end of a paragraph: writer.insertText( 'foo', paragraph, 'end' ); // Inserts 'foo' after an image: writer.insertText( 'foo', image, 'after' );Copy codeThese parameters work in the same way as
writer.createPositionAt().Parameters
text : stringText data.
[ itemOrPosition ] : ModelPosition | ModelItem[ offset ] : ModelPositionOffsetOffset or one of the flags. Used only when second parameter is a model item.
Returns
void
merge( position ) → voidmodule:engine/model/writer~ModelWriter#mergeMerges two siblings at the given position.
Node before and after the position have to be an element. Otherwise
writer-merge-no-element-beforeorwriter-merge-no-element-aftererror will be thrown.Parameters
position : ModelPositionPosition between merged elements.
Returns
void
move( range, itemOrPosition, [ offset ] ) → voidmodule:engine/model/writer~ModelWriter#moveMoves all items in the source range to the target position.
writer.move( sourceRange, targetPosition );Copy codeInstead of the target position you can use parent and offset or define that range should be moved to the end or before or after chosen item:
// Moves all items in the range to the paragraph at offset 5: writer.move( sourceRange, paragraph, 5 ); // Moves all items in the range to the end of a blockquote: writer.move( sourceRange, blockquote, 'end' ); // Moves all items in the range to a position after an image: writer.move( sourceRange, image, 'after' );Copy codeThese parameters work the same way as
writer.createPositionAt().Note that items can be moved only within the same tree. It means that you can move items within the same root (element or document fragment) or between documents roots, but you cannot move items from document fragment to the document or from one detached element to another. Use
insertin such cases.Parameters
range : ModelRangeSource range.
itemOrPosition : ModelPosition | ModelItem[ offset ] : ModelPositionOffsetOffset or one of the flags. Used only when second parameter is a model item.
Returns
void
overrideSelectionGravity() → stringmodule:engine/model/writer~ModelWriter#overrideSelectionGravityTemporarily changes the gravity of the selection from left to right.
The gravity defines from which direction the selection inherits its attributes. If it's the default left gravity, then the selection (after being moved by the user) inherits attributes from its left-hand side. This method allows to temporarily override this behavior by forcing the gravity to the right.
For the following model fragment:
<$text bold="true" linkHref="url">bar[]</$text><$text bold="true">biz</$text>Copy code- Default gravity: selection will have the
boldandlinkHrefattributes. - Overridden gravity: selection will have
boldattribute.
Note: It returns an unique identifier which is required to restore the gravity. It guarantees the symmetry of the process.
Returns
stringThe unique id which allows restoring the gravity.
- Default gravity: selection will have the
remove( itemOrRange ) → voidmodule:engine/model/writer~ModelWriter#removeRemoves given model item or range.
Parameters
itemOrRange : ModelRange | ModelItemModel item or range to remove.
Returns
void
removeAttribute( key, itemOrRange ) → voidmodule:engine/model/writer~ModelWriter#removeAttributeRemoves an attribute with given key from a model item or from a range.
Parameters
key : stringAttribute key.
itemOrRange : ModelRange | ModelItemModel item or range from which the attribute will be removed.
Returns
void
removeMarker( markerOrName ) → voidmodule:engine/model/writer~ModelWriter#removeMarkerremoveSelectionAttribute( keyOrIterableOfKeys ) → voidmodule:engine/model/writer~ModelWriter#removeSelectionAttributeRemoves attribute(s) with given key(s) from the selection.
Remove one attribute:
writer.removeSelectionAttribute( 'italic' );Copy codeRemove multiple attributes:
writer.removeSelectionAttribute( [ 'italic', 'bold' ] );Copy codeParameters
keyOrIterableOfKeys : string | Iterable<string>Key of the attribute to remove or an iterable of attribute keys to remove.
Returns
void
rename( element, newName ) → voidmodule:engine/model/writer~ModelWriter#renameRenames the given element.
Parameters
element : ModelElement | ModelDocumentFragmentThe element to rename.
newName : stringNew element name.
Returns
void
restoreSelectionGravity( uid ) → voidmodule:engine/model/writer~ModelWriter#restoreSelectionGravityRestores
overrideSelectionGravitygravity to default.Restoring the gravity is only possible using the unique identifier returned by
overrideSelectionGravity. Note that the gravity remains overridden as long as won't be restored the same number of times it was overridden.Parameters
uid : stringThe unique id returned by
overrideSelectionGravity.
Returns
void
setAttribute( key, value, itemOrRange ) → voidmodule:engine/model/writer~ModelWriter#setAttributeSets value of the attribute with given key on a model item or on a range.
Parameters
key : stringAttribute key.
value : unknownAttribute new value.
itemOrRange : ModelRange | ModelItemModel item or range on which the attribute will be set.
Returns
void
setAttributes( attributes, itemOrRange ) → voidmodule:engine/model/writer~ModelWriter#setAttributesSets values of attributes on a model item or on a range.
writer.setAttributes( { bold: true, italic: true }, range );Copy codeParameters
attributes : ModelNodeAttributesAttributes keys and values.
itemOrRange : ModelRange | ModelItemModel item or range on which the attributes will be set.
Returns
void
setSelection( selectable, [ options ] = { [options.backward] } ) → voidmodule:engine/model/writer~ModelWriter#setSelection:SELECTABLESets the document's selection (ranges and direction) to the specified location based on the given selectable or creates an empty selection if no arguments were passed.
// Sets selection to the given range. const range = writer.createRange( start, end ); writer.setSelection( range ); // Sets selection to given ranges. const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ]; writer.setSelection( ranges ); // Sets selection to other selection. const otherSelection = writer.createSelection(); writer.setSelection( otherSelection ); // Sets selection to the given document selection. const documentSelection = model.document.selection; writer.setSelection( documentSelection ); // Sets collapsed selection at the given position. const position = writer.createPosition( root, path ); writer.setSelection( position ); // Removes all selection's ranges. writer.setSelection( null );Copy codeWriter#setSelection()allow passing additional options (backward) as the last argument.// Sets selection as backward. writer.setSelection( range, { backward: true } );Copy codeThrows
writer-incorrect-useerror when the writer is used outside thechange()block.See also:
setSelection( node, placeOrOffset, options ).Parameters
selectable : null | ModelPosition | ModelRange | ModelSelection | ModelDocumentSelection | Iterable<ModelRange>[ options ] : object- Properties
[ options.backward ] : boolean
Returns
void
setSelection( selectable, placeOrOffset, [ options ] = { [options.backward] } ) → voidmodule:engine/model/writer~ModelWriter#setSelection:NODE_OFFSETSets the document's selection (ranges and direction) to the specified location based on the given selectable or creates an empty selection if no arguments were passed.
// Sets collapsed selection at the position of the given node and an offset. writer.setSelection( paragraph, offset );Copy codeCreates a range inside an element which starts before the first child of that element and ends after the last child of that element.
writer.setSelection( paragraph, 'in' );Copy codeCreates a range on an item which starts before the item and ends just after the item.
writer.setSelection( paragraph, 'on' );Copy codeWriter#setSelection()allow passing additional options (backward) as the last argument.// Sets selection as backward. writer.setSelection( element, 'in', { backward: true } );Copy codeThrows
writer-incorrect-useerror when the writer is used outside thechange()block.See also:
setSelection( selectable, options ).Parameters
selectable : ModelNodeplaceOrOffset : ModelPlaceOrOffset[ options ] : object- Properties
[ options.backward ] : boolean
Returns
void
setSelectionAttribute( objectOrIterable ) → voidmodule:engine/model/writer~ModelWriter#setSelectionAttribute:OBJECTSets attributes on the selection. If any attribute with the same key already is set, it's value is overwritten.
Using key-value object:
writer.setSelectionAttribute( { italic: true, bold: false } );Copy codeUsing iterable object:
writer.setSelectionAttribute( new Map( [ [ 'italic', true ] ] ) );Copy codeParameters
objectOrIterable : ModelNodeAttributesObject / iterable of key => value attribute pairs.
Returns
void
setSelectionAttribute( key, value ) → voidmodule:engine/model/writer~ModelWriter#setSelectionAttribute:KEY_VALUESets attribute on the selection. If attribute with the same key already is set, it's value is overwritten.
writer.setSelectionAttribute( 'italic', true );Copy codeParameters
key : stringKey of the attribute to set.
value : unknownAttribute value.
Returns
void
setSelectionFocus( itemOrPosition, [ offset ] ) → voidmodule:engine/model/writer~ModelWriter#setSelectionFocusMoves
focusto the specified location.The location can be specified in the same form as
writer.createPositionAt()parameters.Parameters
itemOrPosition : ModelPosition | ModelItem[ offset ] : ModelPositionOffsetOffset or one of the flags. Used only when first parameter is a model item.
Returns
void
split( position, [ limitElement ] ) → objectmodule:engine/model/writer~ModelWriter#splitSplits elements starting from the given position and going to the top of the model tree as long as given
limitElementis reached. WhenlimitElementis not defined then only the parent of the given position will be split.The element needs to have a parent. It cannot be a root element nor a document fragment. The
writer-split-element-no-parenterror will be thrown if you try to split an element with no parent.Parameters
position : ModelPositionPosition of split.
[ limitElement ] : ModelNode | ModelDocumentFragmentStop splitting when this element will be reached.
Returns
objectSplit result with properties:
position- Position between split elements.range- Range that stars from the end of the first split element and ends at the beginning of the first copy element.
unwrap( element ) → voidmodule:engine/model/writer~ModelWriter#unwrapUnwraps children of the given element – all its children are moved before it and then the element is removed. Throws error if you try to unwrap an element which does not have a parent.
Parameters
element : ModelElementElement to unwrap.
Returns
void
updateMarker( markerOrName, [ options ] = { [options.affectsData], [options.range], [options.usingOperation] } ) → voidmodule:engine/model/writer~ModelWriter#updateMarkerAdds, updates or refreshes a marker. Marker is a named range, which tracks changes in the document and updates its range automatically, when model tree changes. Still, it is possible to change the marker's range directly using this method.
As the first parameter you can set marker name or instance. If none of them is provided, new marker, with a unique name is created and returned.
Note: If you want to change the view element of the marker while its data in the model remains the same, use the dedicated
reconvertMarkermethod.The
options.usingOperationparameter lets you change if the marker should be managed by operations or not. See marker class description to learn about the difference between markers managed by operations and not-managed by operations. It is possible to change this option for an existing marker.The
options.affectsDataparameter, which defaults tofalse, allows you to define if a marker affects the data. It should betruewhen the marker change changes the data returned by theeditor.getData()method. When set totrueit fires thechange:dataevent. When set tofalseit fires thechangeevent.Update marker directly base on marker's name:
updateMarker( markerName, { range } );Copy codeUpdate marker using operation:
updateMarker( marker, { range, usingOperation: true } ); updateMarker( markerName, { range, usingOperation: true } );Copy codeChange marker's option (start using operations to manage it):
updateMarker( marker, { usingOperation: true } );Copy codeChange marker's option (inform the engine, that the marker does not affect the data anymore):
updateMarker( markerName, { affectsData: false } );Copy codeParameters
markerOrName : string | MarkerName of a marker to update, or a marker instance.
[ options ] : objectIf options object is not defined then marker will be refreshed by triggering downcast conversion for this marker with the same data.
Properties[ options.affectsData ] : booleanFlag indicating that the marker changes the editor data.
[ options.range ] : ModelRangeMarker range to update.
[ options.usingOperation ] : booleanFlag indicated whether the marker should be added by MarkerOperation. See
managedUsingOperations.
Returns
void
Related:
wrap( range, elementOrString ) → voidmodule:engine/model/writer~ModelWriter#wrapWraps the given range with the given element or with a new element (if a string was passed).
Note: range to wrap should be a "flat range" (see
Range#isFlat). If not, an error will be thrown.Parameters
range : ModelRangeRange to wrap.
elementOrString : string | ModelElementElement or name of element to wrap the range with.
Returns
void
_addOperationForAffectedMarkers( type, positionOrRange ) → voidprivatemodule:engine/model/writer~ModelWriter#_addOperationForAffectedMarkersFor given action
typeandpositionOrRangewhere the action happens, this function finds all affected markers and applies a marker operation with the new marker range equal to the current range. Thanks to this, the marker range can be later correctly processed during undo.Parameters
type : 'merge' | 'move'Writer action type.
positionOrRange : ModelPosition | ModelRangePosition or range where the writer action happens.
Returns
void
_assertWriterUsedCorrectly() → voidprivatemodule:engine/model/writer~ModelWriter#_assertWriterUsedCorrectlyThrows
writer-detached-writer-tries-to-modify-modelerror when the writer is used outside of thechange()block.Returns
void
_merge( position ) → voidprivatemodule:engine/model/writer~ModelWriter#_mergePerforms merge action in a non-detached tree.
Parameters
position : ModelPositionPosition between merged elements.
Returns
void
_mergeDetached( position ) → voidprivatemodule:engine/model/writer~ModelWriter#_mergeDetachedPerforms merge action in a detached tree.
Parameters
position : ModelPositionPosition between merged elements.
Returns
void
_removeSelectionAttribute( key ) → voidprivatemodule:engine/model/writer~ModelWriter#_removeSelectionAttribute_setSelectionAttribute( key, value ) → voidprivatemodule:engine/model/writer~ModelWriter#_setSelectionAttributeParameters
key : stringKey of the attribute to remove.
value : unknownAttribute value.
Returns
void