Text (engine/view)
@ckeditor/ckeditor5-engine/src/view/text
Tree view text node.
The constructor of this class should not be used directly. To create a new text node instance
use the DowncastWriter#createText()
method when working on data downcasted from the model or the
UpcastWriter#createText()
method when working on non-semantic views.
Filtering
Properties
-
data : String
module:engine/view/text~Text#data
readonly
The text content.
-
The document instance to which this node belongs.
-
index : Number | null
module:engine/view/text~Text#index
readonly inherited
Index of the node in the parent element or null if the node has no parent.
Accessing this property throws an error if this node's parent element does not contain it. This means that view tree got broken.
-
nextSibling : Node | null
module:engine/view/text~Text#nextSibling
readonly inherited
Node's next sibling, or
null
if it is the last child. -
parent : Element | DocumentFragment | null
module:engine/view/text~Text#parent
readonly inherited
Parent element. Null by default. Set by
_insertChild
. -
previousSibling : Node | null
module:engine/view/text~Text#previousSibling
readonly inherited
Node's previous sibling, or
null
if it is the first child. -
root : Node | DocumentFragment
module:engine/view/text~Text#root
readonly inherited
Top-most ancestor of the node. If the node has no parent it is the root itself.
-
_data : String
module:engine/view/text~Text#_data
protected
The
_data
property is controlled by a getter and a setter.The getter is required when using the addition assignment operator on protected property:
const foo = downcastWriter.createText( 'foo' ); const bar = downcastWriter.createText( 'bar' ); foo._data += bar.data; // executes: `foo._data = foo._data + bar.data` console.log( foo.data ); // prints: 'foobar'
If the protected getter didn't exist,
foo._data
will returnundefined
and result of the merge will be invalid.The setter sets data and fires the change event.
-
_textData : String
module:engine/view/text~Text#_textData
protected
The text content.
Setting the data fires the change event.
Methods
-
constructor( document, data )
module:engine/view/text~Text#constructor
protected
Creates a tree view text node.
Parameters
document : Document
The document instance to which this text node belongs.
data : String
The text's data.
-
getAncestors( options = { [options.includeSelf], [options.parentFirst] } ) → Array
module:engine/view/text~Text#getAncestors
inherited
Returns ancestors array of this node.
Parameters
options : Object
Options object.
Properties[ options.includeSelf ] : Boolean
When set to
true
this node will be also included in parent's array.Defaults to
false
[ options.parentFirst ] : Boolean
When set to
true
, array will be sorted from node's parent to root element, otherwise root element will be the first item in the array.Defaults to
false
Returns
Array
Array with ancestors.
-
getCommonAncestor( node, options = { [options.includeSelf] } ) → Element | DocumentFragment | null
module:engine/view/text~Text#getCommonAncestor
inherited
Returns a
Element
orDocumentFragment
which is a common ancestor of both nodes.Parameters
node : Node
The second node.
options : Object
Options object.
Properties[ options.includeSelf ] : Boolean
When set to
true
both nodes will be considered "ancestors" too. Which means that if e.g. node A is inside B, then their common ancestor will be B.Defaults to
false
Returns
Element | DocumentFragment | null
-
getPath() → Array.<Number>
module:engine/view/text~Text#getPath
inherited
Gets a path to the node. The path is an array containing indices of consecutive ancestors of this node, beginning from root, down to this node's index.
const abc = downcastWriter.createText( 'abc' ); const foo = downcastWriter.createText( 'foo' ); const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) ); const p = downcastWriter.createElement( 'p', null, [ abc, foo ] ); const div = downcastWriter.createElement( 'div', null, [ h1, p ] ); foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3. h1.getPath(); // Returns [ 0 ]. div.getPath(); // Returns [].
Returns
Array.<Number>
The path.
-
is( type ) → Boolean
module:engine/view/text~Text#is
Checks whether this object is of the given type.
text.is( '$text' ); // -> true text.is( 'node' ); // -> true text.is( 'view:$text' ); // -> true text.is( 'view:node' ); // -> true text.is( 'model:$text' ); // -> false text.is( 'element' ); // -> false text.is( 'range' ); // -> false
Check the entire list of view objects which implement the
is()
method.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 : String
Type to check.
Returns
Boolean
-
isAfter( node ) → Boolean
module:engine/view/text~Text#isAfter
inherited
Returns whether this node is after given node.
false
is returned if nodes are in different trees (for example, in differentDocumentFragment
s). -
isAttached() → Boolean
module:engine/view/text~Text#isAttached
inherited
Returns true if the node is in a tree rooted in the document (is a descendant of one of its roots).
Returns
Boolean
-
isBefore( node ) → Boolean
module:engine/view/text~Text#isBefore
inherited
Returns whether this node is before given node.
false
is returned if nodes are in different trees (for example, in differentDocumentFragment
s). -
isSimilar( otherNode ) → Boolean
module:engine/view/text~Text#isSimilar
Checks if this text node is similar to other text node. Both nodes should have the same data to be considered as similar.
-
toJSON() → Object
module:engine/view/text~Text#toJSON
inherited
Custom toJSON method to solve child-parent circular dependencies.
Returns
Object
Clone of this object with the parent property removed.
-
Clones this node.
Returns
Text
Text node that is a clone of this node.
-
_fireChange( type, node )
module:engine/view/text~Text#_fireChange
protected inherited
-
_remove()
module:engine/view/text~Text#_remove
protected inherited
Removes node from parent.
Events
-
change( eventInfo )
module:engine/view/text~Text#event:change
inherited
Parameters
eventInfo : EventInfo
An object containing information about the fired event.
-
change:attributes( eventInfo, changedNode )
module:engine/view/text~Text#event:change:attributes
inherited
Fired when list of elements attributes changes.
-
change:children( eventInfo, changedNode )
module:engine/view/text~Text#event:change:children
inherited
Fired when list of elements children changes.
-
change:text( eventInfo, changedNode )
module:engine/view/text~Text#event:change:text
inherited
Fired when text nodes data changes.
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.