ModelLiveRange
ModelLiveRange is a type of Range that updates itself as document is changed through operations. It may be used as a bookmark.
Note: Be very careful when dealing with ModelLiveRange. Each ModelLiveRange instance bind events that might have to be unbound. Use detach whenever you don't need ModelLiveRange anymore.
Properties
- end : ModelPositionreadonlyinherited- module:engine/model/liverange~ModelLiveRange#end- End position. 
- isCollapsed : booleanreadonlyinherited- module:engine/model/liverange~ModelLiveRange#isCollapsed
- isFlat : booleanreadonlyinherited- module:engine/model/liverange~ModelLiveRange#isFlat
- root : ModelElement | ModelDocumentFragmentreadonlyinherited- module:engine/model/liverange~ModelLiveRange#root- Range root element. 
- start : ModelPositionreadonlyinherited- module:engine/model/liverange~ModelLiveRange#start- Start position. 
Static properties
- _createFromPositionAndShift : ( position: ModelPosition, shift: number ) => ModelLiveRangeinternalreadonlystatic- module:engine/model/liverange~ModelLiveRange._createFromPositionAndShift
- _createIn : ( element: ModelElement | ModelDocumentFragment ) => ModelLiveRangeinternalreadonlystatic- module:engine/model/liverange~ModelLiveRange._createIn
- _createOn : ( element: ModelDocumentFragment | ModelItem ) => ModelLiveRangeinternalreadonlystatic- module:engine/model/liverange~ModelLiveRange._createOn
Methods
- constructor( start, [ end ] )- module:engine/model/liverange~ModelLiveRange#constructor
- Symbol.iterator() → IterableIterator<ModelTreeWalkerValue>inherited- module:engine/model/liverange~ModelLiveRange#Symbol.iterator- Iterable interface. - Iterates over all items that are in this range and returns them together with additional information like length or positions, grouped as - ModelTreeWalkerValue. It iterates over all text contents that are inside the range and all the- ModelElements that are entered into when iterating over this range.- This iterator uses - ModelTreeWalkerwith- boundariesset to this range and- ignoreElementEndoption set to- true.- Returns- IterableIterator<ModelTreeWalkerValue>
 
- clone() → thisinherited- module:engine/model/liverange~ModelLiveRange#clone
- containsItem( item ) → booleaninherited- module:engine/model/liverange~ModelLiveRange#containsItem
- containsPosition( position ) → booleaninherited- module:engine/model/liverange~ModelLiveRange#containsPosition- Checks whether this range contains given position. - Parameters- position : ModelPosition
- Position to check. 
 - Returns- boolean
- trueif given position is contained in this range,- falseotherwise.
 
- containsRange( otherRange, loose ) → booleaninherited- module:engine/model/liverange~ModelLiveRange#containsRange- Checks whether this range contains given range. - Parameters- otherRange : ModelRange
- Range to check. 
- loose : boolean
- Whether the check is loose or strict. If the check is strict ( - false), compared range cannot start or end at the same position as this range boundaries. If the check is loose (- true), compared range can start, end or even be equal to this range. Note that collapsed ranges are always compared in strict mode.- Defaults to - false
 - Returns- boolean
- trueif given range boundaries are contained by this range,- falseotherwise.
 
- delegate( events ) → EmitterMixinDelegateChaininherited- module:engine/model/liverange~ModelLiveRange#delegate- Delegates selected events to another - Emitter. For instance:- emitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );Copy code- then - eventXis delegated (fired by)- emitterBand- emitterCalong with- data:- emitterA.fire( 'eventX', data );Copy code- and - eventYis delegated (fired by)- emitterCalong with- data:- emitterA.fire( 'eventY', data );Copy code- Parameters- events : Array<string>
- Event names that will be delegated to another emitter. 
 - Returns
- detach() → void- module:engine/model/liverange~ModelLiveRange#detach- Unbinds all events previously bound by - ModelLiveRange. Use it whenever you don't need- ModelLiveRangeinstance anymore (i.e. when leaving scope in which it was declared or before re-assigning variable that was referring to it).- Returns- void
 
- fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]inherited- module:engine/model/liverange~ModelLiveRange#fire- Fires an event, executing all callbacks registered for it. - The first parameter passed to callbacks is an - EventInfoobject, followed by the optional- argsprovided in the- fire()method call.- Type parameters- Parameters- eventOrInfo : GetNameOrEventInfo<TEvent>
- The name of the event or - EventInfoobject if event is delegated.
- args : TEvent[ 'args' ]
- Additional arguments to be passed to the callbacks. 
 - Returns- GetEventInfo<TEvent>[ 'return' ]
- By default the method returns - undefined. However, the return value can be changed by listeners through modification of the- evt.return's property (the event info is the first param of every callback).
 
- getCommonAncestor() → null | ModelElement | ModelDocumentFragmentinherited- module:engine/model/liverange~ModelLiveRange#getCommonAncestor- Returns an - ModelElementor- ModelDocumentFragmentwhich is a common ancestor of the range's both ends (in which the entire range is contained).- Returns- null | ModelElement | ModelDocumentFragment
 
- getContainedElement() → null | ModelElementinherited- module:engine/model/liverange~ModelLiveRange#getContainedElement- Returns an Element contained by the range. The element will be returned when it is the only node within the range and fully–contained at the same time. - Returns- null | ModelElement
 
- getDifference( otherRange ) → Array<ModelRange>inherited- module:engine/model/liverange~ModelLiveRange#getDifference- Computes which part(s) of this range is not a part of given range. Returned array contains zero, one or two ranges. - Examples: - let range = model.createRange( model.createPositionFromPath( root, [ 2, 7 ] ), model.createPositionFromPath( root, [ 4, 0, 1 ] ) ); let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 5 ] ) ); let transformed = range.getDifference( otherRange ); // transformed array has no ranges because `otherRange` contains `range` otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 3 ] ) ); transformed = range.getDifference( otherRange ); // transformed array has one range: from [ 3 ] to [ 4, 0, 1 ] otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 4 ] ) ); transformed = range.getDifference( otherRange ); // transformed array has two ranges: from [ 2, 7 ] to [ 3 ] and from [ 4 ] to [ 4, 0, 1 ]Copy code- Parameters- otherRange : ModelRange
- Range to differentiate against. 
 - Returns- Array<ModelRange>
- The difference between ranges. 
 
- getIntersection( otherRange ) → null | ModelRangeinherited- module:engine/model/liverange~ModelLiveRange#getIntersection- Returns an intersection of this range and given range. Intersection is a common part of both of those ranges. If ranges has no common part, returns - null.- Examples: - let range = model.createRange( model.createPositionFromPath( root, [ 2, 7 ] ), model.createPositionFromPath( root, [ 4, 0, 1 ] ) ); let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 2 ] ) ); let transformed = range.getIntersection( otherRange ); // null - ranges have no common part otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 5 ] ) ); transformed = range.getIntersection( otherRange ); // range from [ 3 ] to [ 4, 0, 1 ]Copy code- Parameters- otherRange : ModelRange
- Range to check for intersection. 
 - Returns- null | ModelRange
- A common part of given ranges or - nullif ranges have no common part.
 
- module:engine/model/liverange~ModelLiveRange#getItems- Returns an iterator that iterates over all items that are in this range and returns them. - This method uses - ModelTreeWalkerwith- boundariesset to this range and- ignoreElementEndoption set to- true. However it returns only model items, not- ModelTreeWalkerValue.- You may specify additional options for the tree walker. See - ModelTreeWalkerfor a full list of available options.- Parameters- options : ModelTreeWalkerOptions
- Object with configuration options. See - ModelTreeWalker.- Defaults to - {}
 - Returns- IterableIterator<ModelItem>
 
- getJoined( otherRange, loose ) → null | ModelRangeinherited- module:engine/model/liverange~ModelLiveRange#getJoined- Returns a range created by joining this range with the given range. If ranges have no common part, returns - null.- Examples: - let range = model.createRange( model.createPositionFromPath( root, [ 2, 7 ] ), model.createPositionFromPath( root, [ 4, 0, 1 ] ) ); let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 2 ] ) * ); let transformed = range.getJoined( otherRange ); // null - ranges have no common part otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 5 ] ) ); transformed = range.getJoined( otherRange ); // range from [ 2, 7 ] to [ 5 ]Copy code- Parameters- otherRange : ModelRange
- Range to be joined. 
- loose : boolean
- Whether the intersection check is loose or strict. If the check is strict ( - false), ranges are tested for intersection or whether start/end positions are equal. If the check is loose (- true), compared range is also checked if it's touching current range.- Defaults to - false
 - Returns- null | ModelRange
- A sum of given ranges or - nullif ranges have no common part.
 
- getMinimalFlatRanges() → Array<ModelRange>inherited- module:engine/model/liverange~ModelLiveRange#getMinimalFlatRanges- Computes and returns the smallest set of flat ranges, that covers this range in whole. - See an example of a model structure ( - [and- ]are range boundaries):- root root |- element DIV DIV P2 P3 DIV | |- element H H P1 f o o b a r H P4 | | |- "fir[st" fir[st lorem se]cond ipsum | |- element P1 | | |- "lorem" || |- element P2 || | |- "foo" VV |- element P3 | |- "bar" root |- element DIV DIV [P2 P3] DIV | |- element H H [P1] f o o b a r H P4 | | |- "se]cond" fir[st] lorem [se]cond ipsum | |- element P4 | | |- "ipsum"Copy code- As it can be seen, letters contained in the range are: - stloremfoobarse, spread across different parents. We are looking for minimal set of flat ranges that contains the same nodes.- Minimal flat ranges for above range - ( [ 0, 0, 3 ], [ 3, 0, 2 ] )will be:- ( [ 0, 0, 3 ], [ 0, 0, 5 ] ) = "st" ( [ 0, 1 ], [ 0, 2 ] ) = element P1 ("lorem") ( [ 1 ], [ 3 ] ) = element P2, element P3 ("foobar") ( [ 3, 0, 0 ], [ 3, 0, 2 ] ) = "se"Copy code- Note: if an element is not wholly contained in this range, it won't be returned in any of the returned flat ranges. See in the example how - Helements at the beginning and at the end of the range were omitted. Only their parts that were wholly in the range were returned.- Note: this method is not returning flat ranges that contain no nodes. - Returns- Array<ModelRange>
- Array of flat ranges covering this range. 
 
- getPositions( options ) → IterableIterator<ModelPosition>inherited- module:engine/model/liverange~ModelLiveRange#getPositions- Returns an iterator that iterates over all positions that are boundaries or contained in this range. - This method uses - ModelTreeWalkerwith- boundariesset to this range. However it returns only positions, not- ModelTreeWalkerValue.- You may specify additional options for the tree walker. See - ModelTreeWalkerfor a full list of available options.- Parameters- options : ModelTreeWalkerOptions
- Object with configuration options. See - ModelTreeWalker.- Defaults to - {}
 - Returns- IterableIterator<ModelPosition>
 
- getTransformedByOperation( operation ) → Array<ModelRange>inherited- module:engine/model/liverange~ModelLiveRange#getTransformedByOperation- Returns a range that is a result of transforming this range by given - operation.- Note: transformation may break one range into multiple ranges (for example, when a part of the range is moved to a different part of document tree). For this reason, an array is returned by this method and it may contain one or more - Rangeinstances.- Parameters- operation : Operation
- Operation to transform range by. 
 - Returns- Array<ModelRange>
- Range which is the result of transformation. 
 
- getTransformedByOperations( operations ) → Array<ModelRange>inherited- module:engine/model/liverange~ModelLiveRange#getTransformedByOperations- Returns a range that is a result of transforming this range by multiple - operations.- Parameters- operations : Iterable<Operation>
- Operations to transform the range by. 
 - Returns- Array<ModelRange>
- Range which is the result of transformation. 
 - Related:- ModelRange#getTransformedByOperation
 
- getWalker( options ) → ModelTreeWalkerinherited- module:engine/model/liverange~ModelLiveRange#getWalker- Creates a TreeWalker instance with this range as a boundary. - For example, to iterate over all items in the entire document root: - // Create a range spanning over the entire root content: const range = editor.model.createRangeIn( editor.model.document.getRoot() ); // Iterate over all items in this range: for ( const value of range.getWalker() ) { console.log( value.item ); }Copy code- Parameters- options : ModelTreeWalkerOptions
- Object with configuration options. See - ModelTreeWalker.- Defaults to - {}
 - Returns
- is( type ) → this is ModelElement | ModelRootElementinherited- module:engine/model/liverange~ModelLiveRange#is:ELEMENT- Checks whether the object is of type - ModelElementor its subclass.- element.is( 'element' ); // -> true element.is( 'node' ); // -> true element.is( 'model:element' ); // -> true element.is( 'model:node' ); // -> true element.is( 'view:element' ); // -> false element.is( 'documentSelection' ); // -> falseCopy code- Assuming that the object being checked is an element, you can also check its name: - element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element text.is( 'element', 'imageBlock' ); -> falseCopy code- Parameters- type : 'element' | 'model:element'
 - Returns- this is ModelElement | ModelRootElement
 
- module:engine/model/liverange~ModelLiveRange#is:TEXT- Checks whether the object is of type - ModelText.- text.is( '$text' ); // -> true text.is( 'node' ); // -> true text.is( 'model:$text' ); // -> true text.is( 'model:node' ); // -> true text.is( 'view:$text' ); // -> false text.is( 'documentSelection' ); // -> falseCopy code- Note: Until version 20.0.0 this method wasn't accepting - '$text'type. The legacy- 'text'type is still accepted for backward compatibility.- Parameters- type : '$text' | 'model:$text'
 - Returns- this is ModelText
 
- is( type ) → this is ModelRootElementinherited- module:engine/model/liverange~ModelLiveRange#is:ROOT_ELEMENT- Checks whether the object is of type - ModelRootElement.- rootElement.is( 'rootElement' ); // -> true rootElement.is( 'element' ); // -> true rootElement.is( 'node' ); // -> true rootElement.is( 'model:rootElement' ); // -> true rootElement.is( 'model:element' ); // -> true rootElement.is( 'model:node' ); // -> true rootElement.is( 'view:element' ); // -> false rootElement.is( 'documentFragment' ); // -> falseCopy code- Assuming that the object being checked is an element, you can also check its name: - rootElement.is( 'rootElement', '$root' ); // -> same as aboveCopy code- Parameters- type : 'rootElement' | 'model:rootElement'
 - Returns- this is ModelRootElement
 
- is( type ) → this is ModelRange | ModelLiveRangeinherited- module:engine/model/liverange~ModelLiveRange#is:RANGE- Checks whether the object is of type - ModelRangeor its subclass.- range.is( 'range' ); // -> true range.is( 'model:range' ); // -> true range.is( 'view:range' ); // -> false range.is( 'documentSelection' ); // -> falseCopy code- Parameters- type : 'range' | 'model:range'
 - Returns- this is ModelRange | ModelLiveRange
 
- is( type ) → this is ModelDocumentFragmentinherited- module:engine/model/liverange~ModelLiveRange#is:DOCUMENT_FRAGMENT- Checks whether the object is of type - ModelDocumentFragment.- docFrag.is( 'documentFragment' ); // -> true docFrag.is( 'model:documentFragment' ); // -> true docFrag.is( 'view:documentFragment' ); // -> false docFrag.is( 'element' ); // -> false docFrag.is( 'node' ); // -> falseCopy code- Parameters- type : 'documentFragment' | 'model:documentFragment'
 - Returns- this is ModelDocumentFragment
 
- is( type ) → this is ModelLiveRangeinherited- module:engine/model/liverange~ModelLiveRange#is:LIVE_RANGE- Checks whether the object is of type - ModelLiveRange.- liveRange.is( 'range' ); // -> true liveRange.is( 'model:range' ); // -> true liveRange.is( 'liveRange' ); // -> true liveRange.is( 'model:liveRange' ); // -> true liveRange.is( 'view:range' ); // -> false liveRange.is( 'documentSelection' ); // -> falseCopy code- Parameters- type : 'liveRange' | 'model:liveRange'
 - Returns- this is ModelLiveRange
 
- is( type ) → this is ModelLivePositioninherited- module:engine/model/liverange~ModelLiveRange#is:LIVE_POSITION- Checks whether the object is of type - ModelLivePosition.- livePosition.is( 'position' ); // -> true livePosition.is( 'model:position' ); // -> true livePosition.is( 'liveposition' ); // -> true livePosition.is( 'model:livePosition' ); // -> true livePosition.is( 'view:position' ); // -> false livePosition.is( 'documentSelection' ); // -> falseCopy code- Parameters- type : 'livePosition' | 'model:livePosition'
 - Returns- this is ModelLivePosition
 
- is( type ) → this is ModelPosition | ModelLivePositioninherited- module:engine/model/liverange~ModelLiveRange#is:POSITION- Checks whether the object is of type - ModelPositionor its subclass.- position.is( 'position' ); // -> true position.is( 'model:position' ); // -> true position.is( 'view:position' ); // -> false position.is( 'documentSelection' ); // -> falseCopy code- Parameters- type : 'position' | 'model:position'
 - Returns- this is ModelPosition | ModelLivePosition
 
- is( type ) → this is ModelDocumentSelectioninherited- module:engine/model/liverange~ModelLiveRange#is:DOCUMENT_SELECTION- Checks whether the object is of type - ModelDocumentSelection.- selection.is( 'selection' ); // -> true selection.is( 'documentSelection' ); // -> true selection.is( 'model:selection' ); // -> true selection.is( 'model:documentSelection' ); // -> true selection.is( 'view:selection' ); // -> false selection.is( 'element' ); // -> false selection.is( 'node' ); // -> falseCopy code- Parameters- type : 'documentSelection' | 'model:documentSelection'
 - Returns- this is ModelDocumentSelection
 
- is( type, name ) → booleaninherited- module:engine/model/liverange~ModelLiveRange#is:ROOT_ELEMENT_NAME- Checks whether the object is of type - ModelRootElementand has the specified- name.- rootElement.is( 'rootElement', '$root' );Copy code- Type parameters- N : extends string
 - Parameters- type : 'rootElement' | 'model:rootElement'
- name : N
 - Returns- boolean
 
- is( type, name ) → booleaninherited- module:engine/model/liverange~ModelLiveRange#is:ELEMENT_NAME- Checks whether the object is of type - ModelElementor its subclass and has the specified- name.- element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element text.is( 'element', 'imageBlock' ); -> falseCopy code- Type parameters- N : extends string
 - Parameters- type : 'element' | 'model:element'
- name : N
 - Returns- boolean
 
- is( type ) → this is ModelTextProxyinherited- module:engine/model/liverange~ModelLiveRange#is:TEXT_PROXY- Checks whether the object is of type - ModelTextProxy.- textProxy.is( '$textProxy' ); // -> true textProxy.is( 'model:$textProxy' ); // -> true textProxy.is( 'view:$textProxy' ); // -> false textProxy.is( 'range' ); // -> falseCopy code- Note: Until version 20.0.0 this method wasn't accepting - '$textProxy'type. The legacy- 'textProxt'type is still accepted for backward compatibility.- Parameters- type : '$textProxy' | 'model:$textProxy'
 - Returns- this is ModelTextProxy
 
- module:engine/model/liverange~ModelLiveRange#is:MARKER
- is( type ) → this is ModelSelection | ModelDocumentSelectioninherited- module:engine/model/liverange~ModelLiveRange#is:SELECTION- Checks whether the object is of type - ModelSelectionor- ModelDocumentSelection.- selection.is( 'selection' ); // -> true selection.is( 'model:selection' ); // -> true selection.is( 'view:selection' ); // -> false selection.is( 'range' ); // -> falseCopy code- Parameters- type : 'selection' | 'model:selection'
 - Returns- this is ModelSelection | ModelDocumentSelection
 
- is( type ) → this is ModelNode | ModelText | ModelElement | ModelRootElementinherited- module:engine/model/liverange~ModelLiveRange#is:NODE- Checks whether the object is of type - ModelNodeor its subclass.- This method is useful when processing model objects that are of unknown type. For example, a function may return a - ModelDocumentFragmentor a- ModelNodethat can be either a text node or an element. This method can be used to check what kind of object is returned.- someObject.is( 'element' ); // -> true if this is an element someObject.is( 'node' ); // -> true if this is a node (a text node or an element) someObject.is( 'documentFragment' ); // -> true if this is a document fragmentCopy code- Since this method is also available on a range of view objects, you can prefix the type of the object with - model:or- view:to check, for example, if this is the model's or view's element:- modelElement.is( 'model:element' ); // -> true modelElement.is( 'view:element' ); // -> falseCopy code- By using this method it is also possible to check a name of an element: - imageElement.is( 'element', 'imageBlock' ); // -> true imageElement.is( 'element', 'imageBlock' ); // -> same as above imageElement.is( 'model:element', 'imageBlock' ); // -> same as above, but more preciseCopy code- Parameters- type : 'node' | 'model:node'
 - Returns- this is ModelNode | ModelText | ModelElement | ModelRootElement
 
- isEqual( otherRange ) → booleaninherited- module:engine/model/liverange~ModelLiveRange#isEqual- Two ranges are equal if their - startand- endpositions are equal.- Parameters- otherRange : ModelRange
- Range to compare with. 
 - Returns- boolean
- trueif ranges are equal,- falseotherwise.
 
- isIntersecting( otherRange ) → booleaninherited- module:engine/model/liverange~ModelLiveRange#isIntersecting- Checks and returns whether this range intersects with given range. - Parameters- otherRange : ModelRange
- Range to compare with. 
 - Returns- boolean
- trueif ranges intersect,- falseotherwise.
 
- listenTo( emitter, event, callback, [ options ] ) → voidinherited- module:engine/model/liverange~ModelLiveRange#listenTo:BASE_EMITTER- Registers a callback function to be executed when an event is fired in a specific (emitter) object. - Events can be grouped in namespaces using - :. When namespaced event is fired, it additionally fires all callbacks for that namespace.- // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ). myEmitter.on( 'myGroup', genericCallback ); myEmitter.on( 'myGroup:myEvent', specificCallback ); // genericCallback is fired. myEmitter.fire( 'myGroup' ); // both genericCallback and specificCallback are fired. myEmitter.fire( 'myGroup:myEvent' ); // genericCallback is fired even though there are no callbacks for "foo". myEmitter.fire( 'myGroup:foo' );Copy code- An event callback can stop the event and set the return value of the - firemethod.- Type parameters- Parameters- emitter : Emitter
- The object that fires the event. 
- event : TEvent[ 'name' ]
- The name of the event. 
- callback : GetCallback<TEvent>
- The function to be called on event. 
- [ options ] : GetCallbackOptions<TEvent>
- Additional options. 
 - Returns- void
 
- off( event, callback ) → voidinherited- module:engine/model/liverange~ModelLiveRange#off- Stops executing the callback on the given event. Shorthand for - this.stopListening( this, event, callback ).- Parameters- event : string
- The name of the event. 
- callback : Function
- The function to stop being called. 
 - Returns- void
 
- on( event, callback, [ options ] ) → voidinherited- module:engine/model/liverange~ModelLiveRange#on- Registers a callback function to be executed when an event is fired. - Shorthand for - this.listenTo( this, event, callback, options )(it makes the emitter listen on itself).- Type parameters- Parameters- event : TEvent[ 'name' ]
- The name of the event. 
- callback : GetCallback<TEvent>
- The function to be called on event. 
- [ options ] : GetCallbackOptions<TEvent>
- Additional options. 
 - Returns- void
 
- once( event, callback, [ options ] ) → voidinherited- module:engine/model/liverange~ModelLiveRange#once- Registers a callback function to be executed on the next time the event is fired only. This is similar to calling - onfollowed by- offin the callback.- Type parameters- Parameters- event : TEvent[ 'name' ]
- The name of the event. 
- callback : GetCallback<TEvent>
- The function to be called on event. 
- [ options ] : GetCallbackOptions<TEvent>
- Additional options. 
 - Returns- void
 
- stopDelegating( [ event ], [ emitter ] ) → voidinherited- module:engine/model/liverange~ModelLiveRange#stopDelegating- Stops delegating events. It can be used at different levels: - To stop delegating all events.
- To stop delegating a specific event to all emitters.
- To stop delegating a specific event to a specific emitter.
 - Parameters- [ event ] : string
- The name of the event to stop delegating. If omitted, stops it all delegations. 
- [ emitter ] : Emitter
- (requires - event) The object to stop delegating a particular event to. If omitted, stops delegation of- eventto all emitters.
 - Returns- void
 
- stopListening( [ emitter ], [ event ], [ callback ] ) → voidinherited- module:engine/model/liverange~ModelLiveRange#stopListening:BASE_STOP- Stops listening for events. It can be used at different levels: - To stop listening to a specific callback.
- To stop listening to a specific event.
- To stop listening to all events fired by a specific object.
- To stop listening to all events fired by all objects.
 - Parameters- [ emitter ] : Emitter
- The object to stop listening to. If omitted, stops it for all objects. 
- [ event ] : string
- (Requires the - emitter) The name of the event to stop listening to. If omitted, stops it for all events from- emitter.
- [ callback ] : Function
- (Requires the - event) The function to be removed from the call list for the given- event.
 - Returns- void
 
- toJSON() → unknowninherited- module:engine/model/liverange~ModelLiveRange#toJSON- Converts - Rangeto plain object and returns it.- Returns- unknown
- Rangeconverted to plain object.
 
- toRange() → ModelRange- module:engine/model/liverange~ModelLiveRange#toRange- Creates a range instance that is equal to this live range. - Returns
- _getTransformedByDeletion( deletePosition, howMany ) → null | ModelRangeinternalinherited- module:engine/model/liverange~ModelLiveRange#_getTransformedByDeletion- Returns a copy of this range that is transformed by deletion of - howManynodes from- deletePosition.- If the deleted range is intersecting with the transformed range, the transformed range will be shrank. - If the deleted range contains transformed range, - nullwill be returned.- Parameters- deletePosition : ModelPosition
- Position from which nodes are removed. 
- howMany : number
- How many nodes are removed. 
 - Returns- null | ModelRange
- Result of the transformation. 
 
- _getTransformedByInsertOperation( operation, spread ) → Array<ModelRange>internalinherited- module:engine/model/liverange~ModelLiveRange#_getTransformedByInsertOperation- Returns a result of transforming a copy of this range by insert operation. - One or more ranges may be returned as a result of this transformation. - Parameters- operation : InsertOperation
- spread : boolean
- Defaults to - false
 - Returns- Array<ModelRange>
 
- _getTransformedByInsertion( insertPosition, howMany, spread ) → Array<ModelRange>internalinherited- module:engine/model/liverange~ModelLiveRange#_getTransformedByInsertion- Returns an array containing one or two ranges that are a result of transforming this range by inserting - howManynodes at- insertPosition. Two ranges are returned if the insertion was inside this range and- spreadis set to- true.- Examples: - let range = model.createRange( model.createPositionFromPath( root, [ 2, 7 ] ), model.createPositionFromPath( root, [ 4, 0, 1 ] ) ); let transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 1 ] ), 2 ); // transformed array has one range from [ 4, 7 ] to [ 6, 0, 1 ] transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 4, 0, 0 ] ), 4 ); // transformed array has one range from [ 2, 7 ] to [ 4, 0, 5 ] transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4 ); // transformed array has one range, which is equal to original range transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4, true ); // transformed array has two ranges: from [ 2, 7 ] to [ 3, 2 ] and from [ 3, 6 ] to [ 4, 0, 1 ]Copy code- Parameters- insertPosition : ModelPosition
- Position where nodes are inserted. 
- howMany : number
- How many nodes are inserted. 
- spread : boolean
- Flag indicating whether this range should be spread if insertion was inside the range. Defaults to - false.- Defaults to - false
 - Returns- Array<ModelRange>
- Result of the transformation. 
 
- _getTransformedByMergeOperation( operation ) → ModelRangeinternalinherited- module:engine/model/liverange~ModelLiveRange#_getTransformedByMergeOperation- Returns a result of transforming a copy of this range by merge operation. - Always one range is returned. The transformation is done in a way to not break the range. - Parameters- operation : MergeOperation
 - Returns
- _getTransformedByMove( sourcePosition, targetPosition, howMany, spread ) → Array<ModelRange>internalinherited- module:engine/model/liverange~ModelLiveRange#_getTransformedByMove- Returns an array containing ranges that are a result of transforming this range by moving - howManynodes from- sourcePositionto- targetPosition.- Parameters- sourcePosition : ModelPosition
- Position from which nodes are moved. 
- targetPosition : ModelPosition
- Position to where nodes are moved. 
- howMany : number
- How many nodes are moved. 
- spread : boolean
- Whether the range should be spread if the move points inside the range. - Defaults to - false
 - Returns- Array<ModelRange>
- Result of the transformation. 
 
- _getTransformedByMoveOperation( operation, spread ) → Array<ModelRange>internalinherited- module:engine/model/liverange~ModelLiveRange#_getTransformedByMoveOperation- Returns a result of transforming a copy of this range by move operation. - One or more ranges may be returned as a result of this transformation. - Parameters- operation : MoveOperation
- spread : boolean
- Defaults to - false
 - Returns- Array<ModelRange>
 
- _getTransformedBySplitOperation( operation ) → ModelRangeinternalinherited- module:engine/model/liverange~ModelLiveRange#_getTransformedBySplitOperation- Returns a result of transforming a copy of this range by split operation. - Always one range is returned. The transformation is done in a way to not break the range. - Parameters- operation : SplitOperation
 - Returns
Static methods
- fromJSON( json, doc ) → ModelRangeinheritedstatic- module:engine/model/liverange~ModelLiveRange.fromJSON- Creates a - Rangeinstance from given plain object (i.e. parsed JSON string).- Parameters- json : any
- Plain object to be converted to - Range.
- doc : ModelDocument
- Document object that will be range owner. 
 - Returns- ModelRange
- Rangeinstance created using given plain object.
 
- fromRange( range ) → ModelLiveRangestatic- module:engine/model/liverange~ModelLiveRange.fromRange- Creates a - ModelLiveRangeinstance that is equal to the given range.- Parameters- range : ModelRange
 - Returns
- _createFromRanges( ranges ) → ModelRangeinternalinheritedstatic- module:engine/model/liverange~ModelLiveRange._createFromRanges- Combines all ranges from the passed array into a one range. At least one range has to be passed. Passed ranges must not have common parts. - The first range from the array is a reference range. If other ranges start or end on the exactly same position where the reference range, they get combined into one range. - [ ][] [ ][ ][ ][ ][] [ ] // Passed ranges, shown sorted [ ] // The result of the function if the first range was a reference range. [ ] // The result of the function if the third-to-seventh range was a reference range. [ ] // The result of the function if the last range was a reference range.Copy code- Parameters- ranges : Array<ModelRange>
- Ranges to combine. 
 - Returns- ModelRange
- Combined range. 
 
Events
- change( eventInfo, range, data )- module:engine/model/liverange~ModelLiveRange#event:change- Describes - change:rangeor- change:contentevent.- Parameters- eventInfo : EventInfo
- An object containing information about the fired event. 
- range : ModelRange
- data : object
 
- change:content( eventInfo, range, data )- module:engine/model/liverange~ModelLiveRange#event:change:content- Fired when - ModelLiveRangeinstance boundaries have not changed after a change in document but the change took place inside the range, effectively changing its content.- Parameters- eventInfo : EventInfo
- An object containing information about the fired event. 
- range : ModelRange
- Range with start and end position equal to start and end position of change range. 
- data : object
- Object with additional information about the change. 
 
- change:range( eventInfo, range, data )- module:engine/model/liverange~ModelLiveRange#event:change:range- Fired when - ModelLiveRangeinstance boundaries have changed due to changes in the document.- Parameters- eventInfo : EventInfo
- An object containing information about the fired event. 
- range : ModelRange
- data : object
- Object with additional information about the change.