@@ -63,6 +63,20 @@ export default abstract class Node extends TypeCheckable {
63
63
*/
64
64
private _attrs : Map < string , unknown > ;
65
65
66
+ /**
67
+ * Index of this node in its parent or `null` if the node has no parent.
68
+ *
69
+ * @internal
70
+ */
71
+ public _index : number | null = null ;
72
+
73
+ /**
74
+ * Offset at which this node starts in its parent or `null` if the node has no parent.
75
+ *
76
+ * @internal
77
+ */
78
+ public _startOffset : number | null = null ;
79
+
66
80
/**
67
81
* Creates a model node.
68
82
*
@@ -85,66 +99,42 @@ export default abstract class Node extends TypeCheckable {
85
99
86
100
/**
87
101
* Index of this node in its parent or `null` if the node has no parent.
88
- *
89
- * Accessing this property throws an error if this node's parent element does not contain it.
90
- * This means that model tree got broken.
91
102
*/
92
103
public get index ( ) : number | null {
93
- let pos ;
94
-
95
- if ( ! this . parent ) {
96
- return null ;
97
- }
98
-
99
- if ( ( pos = this . parent . getChildIndex ( this ) ) === null ) {
100
- throw new CKEditorError ( 'model-node-not-found-in-parent' , this ) ;
101
- }
102
-
103
- return pos ;
104
+ return this . _index ;
104
105
}
105
106
106
107
/**
107
108
* Offset at which this node starts in its parent. It is equal to the sum of {@link #offsetSize offsetSize}
108
109
* of all its previous siblings. Equals to `null` if node has no parent.
109
- *
110
- * Accessing this property throws an error if this node's parent element does not contain it.
111
- * This means that model tree got broken.
112
110
*/
113
111
public get startOffset ( ) : number | null {
114
- let pos ;
115
-
116
- if ( ! this . parent ) {
117
- return null ;
118
- }
119
-
120
- if ( ( pos = this . parent . getChildStartOffset ( this ) ) === null ) {
121
- throw new CKEditorError ( 'model-node-not-found-in-parent' , this ) ;
122
- }
123
-
124
- return pos ;
112
+ return this . _startOffset ;
125
113
}
126
114
127
115
/**
128
- * Offset size of this node. Represents how much "offset space" is occupied by the node in it's parent.
129
- * It is important for {@link module:engine/model/position~Position position}. When node has `offsetSize` greater than `1`, position
130
- * can be placed between that node start and end. `offsetSize` greater than `1` is for nodes that represents more
131
- * than one entity, i.e. {@link module:engine/model/text~Text text node}.
116
+ * Offset size of this node.
117
+ *
118
+ * Represents how much "offset space" is occupied by the node in its parent. It is important for
119
+ * {@link module:engine/model/position~Position position}. When node has `offsetSize` greater than `1`, position can be placed between
120
+ * that node start and end. `offsetSize` greater than `1` is for nodes that represents more than one entity, i.e.
121
+ * a {@link module:engine/model/text~Text text node}.
132
122
*/
133
123
public get offsetSize ( ) : number {
134
124
return 1 ;
135
125
}
136
126
137
127
/**
138
- * Offset at which this node ends in it's parent. It is equal to the sum of this node's
128
+ * Offset at which this node ends in its parent. It is equal to the sum of this node's
139
129
* {@link module:engine/model/node~Node#startOffset start offset} and {@link #offsetSize offset size}.
140
130
* Equals to `null` if the node has no parent.
141
131
*/
142
132
public get endOffset ( ) : number | null {
143
- if ( ! this . parent ) {
133
+ if ( this . startOffset === null ) {
144
134
return null ;
145
135
}
146
136
147
- return this . startOffset ! + this . offsetSize ;
137
+ return this . startOffset + this . offsetSize ;
148
138
}
149
139
150
140
/**
@@ -387,7 +377,7 @@ export default abstract class Node extends TypeCheckable {
387
377
}
388
378
389
379
/**
390
- * Removes this node from it's parent.
380
+ * Removes this node from its parent.
391
381
*
392
382
* @internal
393
383
* @see module:engine/model/writer~Writer#remove
@@ -448,12 +438,6 @@ Node.prototype.is = function( type: string ): boolean {
448
438
return type === 'node' || type === 'model:node' ;
449
439
} ;
450
440
451
- /**
452
- * The node's parent does not contain this node.
453
- *
454
- * @error model-node-not-found-in-parent
455
- */
456
-
457
441
/**
458
442
* Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
459
443
*/
0 commit comments