Class

TextProxy (engine/model)

@ckeditor/ckeditor5-engine/src/model/textproxy

class

TextProxy represents a part of text node.

Since positions can be placed between characters of a text node, ranges may contain only parts of text nodes. When getting items contained in such range, we need to represent a part of that text node, since returning the whole text node would be incorrect. TextProxy solves this issue.

TextProxy has an API similar to Text and allows to do most of the common tasks performed on model nodes.

Note: Some TextProxy instances may represent whole text node, not just a part of it. See isPartial.

Note: TextProxy is not an instance of node. Keep this in mind when using it as a parameter of methods.

Note: TextProxy is a readonly interface. If you want to perform changes on model data represented by a TextProxy use model writer API.

Note: TextProxy instances are created on the fly, basing on the current state of model. Because of this, it is highly unrecommended to store references to TextProxy instances. TextProxy instances are not refreshed when model changes, so they might get invalidated. Instead, consider creating live position.

TextProxy instances are created by model tree walker. You should not need to create an instance of this class by your own.

Filtering

Properties

  • data : String

    readonly

    Text data represented by this text proxy.

  • endOffset : Number

    readonly

    Offset at which this text proxy ends in it's parent.

    Related:

  • isPartial : Boolean

    readonly

    Flag indicating whether TextProxy instance covers only part of the original text node (true) or the whole text node (false).

    This is false when text proxy starts at the very beginning of textNode (offsetInText equals 0) and text proxy sizes is equal to text node size.

  • offsetInText : Number

    readonly

    Offset in text node from which the text proxy starts.

  • offsetSize : Number

    readonly

    Offset size of this text proxy. Equal to the number of characters represented by the text proxy.

    Related:

  • parent : Element | DocumentFragment | null

    readonly

    Parent of this text proxy, which is same as parent of text node represented by this text proxy.

  • root : Node | DocumentFragment

    readonly

    Root of this text proxy, which is same as root of text node represented by this text proxy.

  • startOffset : Number

    readonly

    Offset at which this text proxy starts in it's parent.

    Related:

  • textNode : Text

    readonly

    Text node which part is represented by this text proxy.

Methods

  • constructor( textNode, offsetInText, length )

    protected

    Creates a text proxy.

    Parameters

    textNode : Text

    Text node which part is represented by this text proxy.

    offsetInText : Number

    Offset in text node from which the text proxy starts.

    length : Number

    Text proxy length, that is how many text node's characters, starting from offsetInText it represents.

  • getAncestors( options = { [options.includeSelf], [options.parentFirst] } ) → Array

    Returns ancestors array of this text proxy.

    Parameters

    options : Object

    Options object.

    Properties
    [ options.includeSelf ] : Boolean

    When set to true this text proxy will be also included in parent's array.

    Defaults to false

    [ options.parentFirst ] : Boolean

    When set to true, array will be sorted from text proxy parent to root element, otherwise root element will be the first item in the array.

    Defaults to false

    Returns

    Array

    Array with ancestors.

  • getAttribute( key ) → *

    Gets an attribute value for given key or undefined if that attribute is not set on text proxy.

    Parameters

    key : String

    Key of attribute to look for.

    Returns

    *

    Attribute value or undefined.

  • getAttributeKeys() → Iterable.<String>

    Returns iterator that iterates over this node's attribute keys.

    Returns

    Iterable.<String>
  • getAttributes() → Iterable.<*>

    Returns iterator that iterates over this node's attributes. Attributes are returned as arrays containing two items. First one is attribute key and second is attribute value.

    This format is accepted by native Map object and also can be passed in Node constructor.

    Returns

    Iterable.<*>
  • getPath() → Array.<Number>

    Gets path to this text proxy.

    Returns

    Array.<Number>

    Related:

  • hasAttribute( key ) → Boolean

    Checks if this text proxy has an attribute for given key.

    Parameters

    key : String

    Key of attribute to check.

    Returns

    Boolean

    true if attribute with given key is set on text proxy, false otherwise.

  • is( type ) → Boolean

    Checks whether this object is of the given.

    textProxy.is( '$textProxy' ); // -> true
    textProxy.is( 'model:$textProxy' ); // -> true
    
    textProxy.is( 'view:$textProxy' ); // -> false
    textProxy.is( 'range' ); // -> false
    

    Check the entire list of model objects which implement the is() method.

    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 : String

    Type to check.

    Returns

    Boolean