TextProxy (engine/model)
@ckeditor/ckeditor5-engine/src/model/textproxy
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
module:engine/model/textproxy~TextProxy#data
readonly
Text data represented by this text proxy.
-
endOffset : Number
module:engine/model/textproxy~TextProxy#endOffset
readonly
Offset at which this text proxy ends in it's parent.
Related:
-
isPartial : Boolean
module:engine/model/textproxy~TextProxy#isPartial
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 equals0
) and text proxy sizes is equal to text node size. -
offsetInText : Number
module:engine/model/textproxy~TextProxy#offsetInText
readonly
Offset in text node from which the text proxy starts.
-
offsetSize : Number
module:engine/model/textproxy~TextProxy#offsetSize
readonly
Offset size of this text proxy. Equal to the number of characters represented by the text proxy.
Related:
-
parent : Element | DocumentFragment | null
module:engine/model/textproxy~TextProxy#parent
readonly
Parent of this text proxy, which is same as parent of text node represented by this text proxy.
-
root : Node | DocumentFragment
module:engine/model/textproxy~TextProxy#root
readonly
Root of this text proxy, which is same as root of text node represented by this text proxy.
-
startOffset : Number
module:engine/model/textproxy~TextProxy#startOffset
readonly
Offset at which this text proxy starts in it's parent.
Related:
-
Text node which part is represented by this text proxy.
Methods
-
constructor( textNode, offsetInText, length )
module:engine/model/textproxy~TextProxy#constructor
protected
Creates a text proxy.
-
getAncestors( options = { [options.includeSelf], [options.parentFirst] } ) → Array
module:engine/model/textproxy~TextProxy#getAncestors
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 ) → *
module:engine/model/textproxy~TextProxy#getAttribute
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>
module:engine/model/textproxy~TextProxy#getAttributeKeys
Returns iterator that iterates over this node's attribute keys.
Returns
Iterable.<String>
-
getAttributes() → Iterable.<*>
module:engine/model/textproxy~TextProxy#getAttributes
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 inNode
constructor.Returns
Iterable.<*>
-
getPath() → Array.<Number>
module:engine/model/textproxy~TextProxy#getPath
Gets path to this text proxy.
-
hasAttribute( key ) → Boolean
module:engine/model/textproxy~TextProxy#hasAttribute
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
module:engine/model/textproxy~TextProxy#is
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
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.