Sign up (with export icon)

ModelLivePosition

Api-class icon class

ModelLivePosition is a type of Position that updates itself as document is changed through operations. It may be used as a bookmark.

Note: Contrary to ModelPosition, ModelLivePosition works only in roots that are ModelRootElement. If ModelDocumentFragment is passed, error will be thrown.

Note: Be very careful when dealing with ModelLivePosition. Each ModelLivePosition instance bind events that might have to be unbound. Use detach whenever you don't need ModelLivePosition anymore.

Properties

  • Chevron-right icon

    index : number
    readonlyinherited

    Position offset converted to an index in position's parent node. It is equal to the index of a node after this position. If position is placed in text node, position index is equal to the index of that text node.

  • Chevron-right icon

    isAtEnd : boolean
    readonlyinherited

    Is true if position is at the end of its parent, false otherwise.

  • Chevron-right icon

    isAtStart : boolean
    readonlyinherited

    Is true if position is at the beginning of its parent, false otherwise.

  • Chevron-right icon

    nodeAfter : null | ModelNode
    readonlyinherited

    Node directly after this position. Returns null if this position is at the end of its parent, or if it is in a text node.

  • Chevron-right icon

    nodeBefore : null | ModelNode
    readonlyinherited

    Node directly before this position. Returns null if this position is at the start of its parent, or if it is in a text node.

  • Chevron-right icon

    offset : number
    inherited

    Offset at which this position is located in its parent. It is equal to the last item in position path.

    Parameters

    newOffset : number
  • Chevron-right icon

    Parent element of this position.

    Keep in mind that parent value is calculated when the property is accessed. If position path leads to a non-existing element, parent property will throw error.

    Also it is a good idea to cache parent property if it is used frequently in an algorithm (i.e. in a long loop).

  • Chevron-right icon

    path : readonly Array<number>
    readonlyinherited

    Position of the node in the tree. Path contains offsets, not indexes.

    Position can be placed before, after or in a node if that node has offsetSize greater than 1. Items in position path are starting offsets of position ancestors, starting from direct root children, down to the position offset in it's parent.

    ROOT
     |- P            before: [ 0 ]         after: [ 1 ]
     |- UL           before: [ 1 ]         after: [ 2 ]
        |- LI        before: [ 1, 0 ]      after: [ 1, 1 ]
        |  |- foo    before: [ 1, 0, 0 ]   after: [ 1, 0, 3 ]
        |- LI        before: [ 1, 1 ]      after: [ 1, 2 ]
           |- bar    before: [ 1, 1, 0 ]   after: [ 1, 1, 3 ]
    
    Copy code

    foo and bar are representing text nodes. Since text nodes has offset size greater than 1 you can place position offset between their start and end:

    ROOT
     |- P
     |- UL
        |- LI
        |  |- f^o|o  ^ has path: [ 1, 0, 1 ]   | has path: [ 1, 0, 2 ]
        |- LI
           |- b^a|r  ^ has path: [ 1, 1, 1 ]   | has path: [ 1, 1, 2 ]
    
    Copy code
  • Chevron-right icon

    Root of the position path.

  • Chevron-right icon

  • Chevron-right icon

    textNode : null | ModelText
    readonlyinherited

    Returns text node instance in which this position is placed or null if this position is not in a text node.

Static properties

Methods

  • Chevron-right icon

    constructor( root, path, stickiness )

    Creates a live position.

    Parameters

    root : ModelRootElement
    path : Array<number>
    stickiness : ModelPositionStickiness

    Defaults to 'toNone'

    Related:

  • Chevron-right icon

    clone() → this
    inherited

    Returns a new position that is equal to current position.

    Returns

    this
  • Chevron-right icon

    compareWith( otherPosition ) → ModelPositionRelation
    inherited

    Checks whether this position is before or after given position.

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    otherPosition : ModelPosition

    Returns

    ModelPositionRelation
  • Chevron-right icon

    delegate( events ) → EmitterMixinDelegateChain
    inherited

    Delegates selected events to another Emitter. For instance:

    emitterA.delegate( 'eventX' ).to( emitterB );
    emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
    
    Copy code

    then eventX is delegated (fired by) emitterB and emitterC along with data:

    emitterA.fire( 'eventX', data );
    
    Copy code

    and eventY is delegated (fired by) emitterC along with data:

    emitterA.fire( 'eventY', data );
    
    Copy code

    Parameters

    events : Array<string>

    Event names that will be delegated to another emitter.

    Returns

    EmitterMixinDelegateChain
  • Chevron-right icon

    detach() → void

    Unbinds all events previously bound by ModelLivePosition. Use it whenever you don't need ModelLivePosition instance anymore (i.e. when leaving scope in which it was declared or before re-assigning variable that was referring to it).

    Returns

    void
  • Chevron-right icon

    findAncestor( parentName ) → null | ModelElement
    inherited

    Returns the parent element of the given name. Returns null if the position is not inside the desired parent.

    Parameters

    parentName : string

    The name of the parent element to find.

    Returns

    null | ModelElement
  • Chevron-right icon

    fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]
    inherited

    Fires an event, executing all callbacks registered for it.

    The first parameter passed to callbacks is an EventInfo object, followed by the optional args provided in the fire() method call.

    Type parameters

    TEvent : extends BaseEvent

    The type describing the event. See BaseEvent.

    Parameters

    eventOrInfo : GetNameOrEventInfo<TEvent>

    The name of the event or EventInfo object 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).

  • Chevron-right icon

    Returns ancestors array of this position, that is this position's parent and its ancestors.

    Returns

    Array<ModelElement | ModelDocumentFragment>

    Array with ancestors.

  • Chevron-right icon

    getCommonAncestor( position ) → null | ModelElement | ModelDocumentFragment
    inherited

    Returns an ModelElement or ModelDocumentFragment which is a common ancestor of both positions. The roots of these two positions must be identical.

    Parameters

    position : ModelPosition

    The second position.

    Returns

    null | ModelElement | ModelDocumentFragment
  • Chevron-right icon

    getCommonPath( position ) → Array<number>
    inherited

    Returns the slice of two position paths which is identical. The roots of these two paths must be identical.

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    position : ModelPosition

    The second position.

    Returns

    Array<number>

    The common path.

  • Chevron-right icon

    getLastMatchingPosition( skip, options ) → ModelPosition
    inherited

    Gets the farthest position which matches the callback using TreeWalker.

    For example:

    getLastMatchingPosition( value => value.type == 'text' );
    // <paragraph>[]foo</paragraph> -> <paragraph>foo[]</paragraph>
    
    getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } );
    // <paragraph>foo[]</paragraph> -> <paragraph>[]foo</paragraph>
    
    getLastMatchingPosition( value => false );
    // Do not move the position.
    
    Copy code

    Parameters

    skip : ( value: ModelTreeWalkerValue ) => boolean

    Callback function. Gets ModelTreeWalkerValue and should return true if the value should be skipped or false if not.

    options : ModelTreeWalkerOptions

    Object with configuration options. See ModelTreeWalker.

    Defaults to {}

    Returns

    ModelPosition

    The position after the last item which matches the skip callback test.

  • Chevron-right icon

    getParentPath() → Array<number>
    inherited

    Returns a path to this position's parent. Parent path is equal to position path but without the last item.

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Returns

    Array<number>

    Path to the parent.

  • Chevron-right icon

    getShiftedBy( shift ) → ModelPosition
    inherited

    Returns a new instance of Position, that has same parent but it's offset is shifted by shift value (can be a negative value).

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    shift : number

    Offset shift. Can be a negative value.

    Returns

    ModelPosition

    Shifted position.

  • Chevron-right icon

    getTransformedByOperation( operation ) → ModelPosition
    inherited

    Returns a copy of this position that is transformed by given operation.

    The new position's parameters are updated accordingly to the effect of the operation.

    For example, if n nodes are inserted before the position, the returned position offset will be increased by n. If the position was in a merged element, it will be accordingly moved to the new element, etc.

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    operation : Operation

    Operation to transform by.

    Returns

    ModelPosition

    Transformed position.

  • Chevron-right icon

    hasSameParentAs( position ) → boolean
    inherited

    Checks if two positions are in the same parent.

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    position : ModelPosition

    Position to compare with.

    Returns

    boolean

    true if positions have the same parent, false otherwise.

  • Chevron-right icon

    is( type ) → this is ModelElement | ModelRootElement
    inherited

    Checks whether the object is of type ModelElement or 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' ); // -> false
    
    Copy 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' ); -> false
    
    Copy code

    Parameters

    type : 'element' | 'model:element'

    Returns

    this is ModelElement | ModelRootElement
  • Chevron-right icon

    is( type ) → this is ModelText
    inherited

    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' ); // -> false
    
    Copy 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
  • Chevron-right icon

    is( type ) → this is ModelRootElement
    inherited

    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' ); // -> false
    
    Copy code

    Assuming that the object being checked is an element, you can also check its name:

    rootElement.is( 'rootElement', '$root' ); // -> same as above
    
    Copy code

    Parameters

    type : 'rootElement' | 'model:rootElement'

    Returns

    this is ModelRootElement
  • Chevron-right icon

    is( type ) → this is ModelLiveRange
    inherited

    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' ); // -> false
    
    Copy code

    Parameters

    type : 'liveRange' | 'model:liveRange'

    Returns

    this is ModelLiveRange
  • Chevron-right icon

    is( type ) → this is ModelRange | ModelLiveRange
    inherited

    Checks whether the object is of type ModelRange or its subclass.

    range.is( 'range' ); // -> true
    range.is( 'model:range' ); // -> true
    
    range.is( 'view:range' ); // -> false
    range.is( 'documentSelection' ); // -> false
    
    Copy code

    Parameters

    type : 'range' | 'model:range'

    Returns

    this is ModelRange | ModelLiveRange
  • Chevron-right icon

    is( type ) → this is ModelLivePosition
    inherited

    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' ); // -> false
    
    Copy code

    Parameters

    type : 'livePosition' | 'model:livePosition'

    Returns

    this is ModelLivePosition
  • Chevron-right icon

    is( type ) → this is ModelPosition | ModelLivePosition
    inherited

    Checks whether the object is of type ModelPosition or its subclass.

    position.is( 'position' ); // -> true
    position.is( 'model:position' ); // -> true
    
    position.is( 'view:position' ); // -> false
    position.is( 'documentSelection' ); // -> false
    
    Copy code

    Parameters

    type : 'position' | 'model:position'

    Returns

    this is ModelPosition | ModelLivePosition
  • Chevron-right icon

    is( type ) → this is ModelSelection | ModelDocumentSelection
    inherited

    Checks whether the object is of type ModelSelection or ModelDocumentSelection.

    selection.is( 'selection' ); // -> true
    selection.is( 'model:selection' ); // -> true
    
    selection.is( 'view:selection' ); // -> false
    selection.is( 'range' ); // -> false
    
    Copy code

    Parameters

    type : 'selection' | 'model:selection'

    Returns

    this is ModelSelection | ModelDocumentSelection
  • Chevron-right icon

    is( type, name ) → boolean
    inherited

    Checks whether the object is of type ModelElement or its subclass and has the specified name.

    element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element
    text.is( 'element', 'imageBlock' ); -> false
    
    Copy code

    Type parameters

    N : extends string

    Parameters

    type : 'element' | 'model:element'
    name : N

    Returns

    boolean
  • Chevron-right icon

    is( type, name ) → boolean
    inherited

    Checks whether the object is of type ModelRootElement and has the specified name.

    rootElement.is( 'rootElement', '$root' );
    
    Copy code

    Type parameters

    N : extends string

    Parameters

    type : 'rootElement' | 'model:rootElement'
    name : N

    Returns

    boolean
  • Chevron-right icon

    is( type ) → this is ModelTextProxy
    inherited

    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' ); // -> false
    
    Copy 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
  • Chevron-right icon

    is( type ) → this is Marker
    inherited

    Checks whether the object is of type Marker.

    marker.is( 'marker' ); // -> true
    marker.is( 'model:marker' ); // -> true
    
    marker.is( 'view:element' ); // -> false
    marker.is( 'documentSelection' ); // -> false
    
    Copy code

    Parameters

    type : 'marker' | 'model:marker'

    Returns

    this is Marker
  • Chevron-right icon

    is( type ) → this is ModelDocumentSelection
    inherited

    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' ); // -> false
    
    Copy code

    Parameters

    type : 'documentSelection' | 'model:documentSelection'

    Returns

    this is ModelDocumentSelection
  • Chevron-right icon

    is( type ) → this is ModelDocumentFragment
    inherited

    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' ); // -> false
    
    Copy code

    Parameters

    type : 'documentFragment' | 'model:documentFragment'

    Returns

    this is ModelDocumentFragment
  • Chevron-right icon

    is( type ) → this is ModelNode | ModelText | ModelElement | ModelRootElement
    inherited

    Checks whether the object is of type ModelNode or its subclass.

    This method is useful when processing model objects that are of unknown type. For example, a function may return a ModelDocumentFragment or a ModelNode that 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 fragment
    
    Copy 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' ); // -> false
    
    Copy 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 precise
    
    Copy code

    Parameters

    type : 'node' | 'model:node'

    Returns

    this is ModelNode | ModelText | ModelElement | ModelRootElement
  • Chevron-right icon

    isAfter( otherPosition ) → boolean
    inherited

    Checks whether this position is after given position.

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    otherPosition : ModelPosition

    Position to compare with.

    Returns

    boolean

    True if this position is after given position.

    Related:

  • Chevron-right icon

    isBefore( otherPosition ) → boolean
    inherited

    Checks whether this position is before given position.

    Note: watch out when using negation of the value returned by this method, because the negation will also be true if positions are in different roots and you might not expect this. You should probably use a.isAfter( b ) || a.isEqual( b ) or !a.isBefore( p ) && a.root == b.root in most scenarios. If your condition uses multiple isAfter and isBefore checks, build them so they do not use negated values, i.e.:

    if ( a.isBefore( b ) && c.isAfter( d ) ) {
    	// do A.
    } else {
    	// do B.
    }
    
    Copy code

    or, if you have only one if-branch:

    if ( !( a.isBefore( b ) && c.isAfter( d ) ) {
    	// do B.
    }
    
    Copy code

    rather than:

    if ( !a.isBefore( b ) || && !c.isAfter( d ) ) {
    	// do B.
    } else {
    	// do A.
    }
    
    Copy code

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    otherPosition : ModelPosition

    Position to compare with.

    Returns

    boolean

    True if this position is before given position.

  • Chevron-right icon

    isEqual( otherPosition ) → boolean
    inherited

    Checks whether this position is equal to given position.

    This method is safe to use it on non-existing positions (for example during operational transformation).

    Parameters

    otherPosition : ModelPosition

    Position to compare with.

    Returns

    boolean

    True if positions are same.

  • Chevron-right icon

    isTouching( otherPosition ) → boolean
    inherited

    Checks whether this position is touching given position. Positions touch when there are no text nodes or empty nodes in a range between them. Technically, those positions are not equal but in many cases they are very similar or even indistinguishable.

    Parameters

    otherPosition : ModelPosition

    Position to compare with.

    Returns

    boolean

    True if positions touch.

  • Chevron-right icon

    isValid() → boolean
    inherited

    Checks whether the position is valid in current model tree, that is whether it points to an existing place in the model.

    Returns

    boolean
  • Chevron-right icon

    listenTo( emitter, event, callback, [ options ] ) → void
    inherited

    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 fire method.

    Type parameters

    TEvent : extends BaseEvent

    The type describing the event. See BaseEvent.

    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
  • Chevron-right icon

    off( event, callback ) → void
    inherited

    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
  • Chevron-right icon

    on( event, callback, [ options ] ) → void
    inherited

    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

    TEvent : extends BaseEvent

    The type descibing the event. See BaseEvent.

    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
  • Chevron-right icon

    once( event, callback, [ options ] ) → void
    inherited

    Registers a callback function to be executed on the next time the event is fired only. This is similar to calling on followed by off in the callback.

    Type parameters

    TEvent : extends BaseEvent

    The type descibing the event. See BaseEvent.

    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
  • Chevron-right icon

    stopDelegating( [ event ], [ emitter ] ) → void
    inherited

    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 event to all emitters.

    Returns

    void
  • Chevron-right icon

    stopListening( [ emitter ], [ event ], [ callback ] ) → void
    inherited

    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
  • Chevron-right icon

    toJSON() → unknown
    inherited

  • Chevron-right icon

    Creates a position instance, which is equal to this live position.

    Returns

    ModelPosition
  • Chevron-right icon

    _getCombined( source, target ) → ModelPosition
    internalinherited

    Returns a new position that is a combination of this position and given positions.

    The combined position is a copy of this position transformed by moving a range starting at source position to the target position. It is expected that this position is inside the moved range.

    Example:

    let original = model.createPositionFromPath( root, [ 2, 3, 1 ] );
    let source = model.createPositionFromPath( root, [ 2, 2 ] );
    let target = model.createPositionFromPath( otherRoot, [ 1, 1, 3 ] );
    original._getCombined( source, target ); // path is [ 1, 1, 4, 1 ], root is `otherRoot`
    
    Copy code

    Explanation:

    We have a position [ 2, 3, 1 ] and move some nodes from [ 2, 2 ] to [ 1, 1, 3 ]. The original position was inside moved nodes and now should point to the new place. The moved nodes will be after positions [ 1, 1, 3 ], [ 1, 1, 4 ], [ 1, 1, 5 ]. Since our position was in the second moved node, the transformed position will be in a sub-tree of a node at [ 1, 1, 4 ]. Looking at original path, we took care of [ 2, 3 ] part of it. Now we have to add the rest of the original path to the transformed path. Finally, the transformed position will point to [ 1, 1, 4, 1 ].

    Parameters

    source : ModelPosition

    Beginning of the moved range.

    target : ModelPosition

    Position where the range is moved.

    Returns

    ModelPosition

    Combined position.

  • Chevron-right icon

    _getTransformedByDeletion( deletePosition, howMany ) → null | ModelPosition
    internalinherited

    Returns a copy of this position that is updated by removing howMany nodes starting from deletePosition. It may happen that this position is in a removed node. If that is the case, null is returned instead.

    Parameters

    deletePosition : ModelPosition

    Position before the first removed node.

    howMany : number

    How many nodes are removed.

    Returns

    null | ModelPosition

    Transformed position or null.

  • Chevron-right icon

    _getTransformedByInsertOperation( operation ) → ModelPosition
    internalinherited

    Returns a copy of this position transformed by an insert operation.

    Parameters

    operation : InsertOperation

    Returns

    ModelPosition
  • Chevron-right icon

    _getTransformedByInsertion( insertPosition, howMany ) → ModelPosition
    internalinherited

    Returns a copy of this position that is updated by inserting howMany nodes at insertPosition.

    Parameters

    insertPosition : ModelPosition

    Position where nodes are inserted.

    howMany : number

    How many nodes are inserted.

    Returns

    ModelPosition

    Transformed position.

  • Chevron-right icon

    _getTransformedByMergeOperation( operation ) → ModelPosition
    internalinherited

    Returns a copy of this position transformed by merge operation.

    Parameters

    operation : MergeOperation

    Returns

    ModelPosition
  • Chevron-right icon

    _getTransformedByMove( sourcePosition, targetPosition, howMany ) → ModelPosition
    internalinherited

    Returns a copy of this position that is updated by moving howMany nodes from sourcePosition to targetPosition.

    Parameters

    sourcePosition : ModelPosition

    Position before the first element to move.

    targetPosition : ModelPosition

    Position where moved elements will be inserted.

    howMany : number

    How many consecutive nodes to move, starting from sourcePosition.

    Returns

    ModelPosition

    Transformed position.

  • Chevron-right icon

    _getTransformedByMoveOperation( operation ) → ModelPosition
    internalinherited

    Returns a copy of this position transformed by a move operation.

    Parameters

    operation : MoveOperation

    Returns

    ModelPosition
  • Chevron-right icon

    _getTransformedBySplitOperation( operation ) → ModelPosition
    internalinherited

    Returns a copy of this position transformed by a split operation.

    Parameters

    operation : SplitOperation

    Returns

    ModelPosition

Static methods

Events

  • Chevron-right icon

    change( eventInfo, oldPosition )

    Fired when ModelLivePosition instance is changed due to changes on ModelDocument.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    oldPosition : ModelPosition

    Position equal to this live position before it got changed.