@ckeditor/ckeditor5-engine 35.3.2 → 36.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/package.json +22 -22
- package/src/controller/datacontroller.js +10 -8
- package/src/controller/editingcontroller.js +3 -4
- package/src/conversion/conversion.js +2 -3
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.js +3 -3
- package/src/conversion/downcasthelpers.js +2 -3
- package/src/conversion/mapper.js +3 -4
- package/src/conversion/modelconsumable.js +2 -2
- package/src/conversion/upcastdispatcher.js +3 -4
- package/src/conversion/upcasthelpers.js +10 -3
- package/src/conversion/viewconsumable.js +2 -2
- package/src/dataprocessor/basichtmlwriter.js +1 -1
- package/src/dataprocessor/dataprocessor.js +1 -1
- package/src/dataprocessor/htmldataprocessor.js +3 -3
- package/src/dataprocessor/htmlwriter.js +1 -1
- package/src/dataprocessor/xmldataprocessor.js +6 -2
- package/src/dev-utils/model.js +3 -3
- package/src/dev-utils/operationreplayer.js +1 -1
- package/src/dev-utils/utils.js +1 -1
- package/src/dev-utils/view.js +1 -1
- package/src/index.js +13 -3
- package/src/model/batch.js +10 -47
- package/src/model/differ.js +81 -174
- package/src/model/document.js +38 -97
- package/src/model/documentfragment.js +44 -97
- package/src/model/documentselection.js +152 -251
- package/src/model/element.js +48 -101
- package/src/model/history.js +15 -46
- package/src/model/item.js +1 -1
- package/src/model/liveposition.js +11 -39
- package/src/model/liverange.js +14 -38
- package/src/model/markercollection.js +42 -115
- package/src/model/model.js +214 -292
- package/src/model/node.js +36 -128
- package/src/model/nodelist.js +12 -41
- package/src/model/operation/attributeoperation.js +14 -45
- package/src/model/operation/detachoperation.js +4 -17
- package/src/model/operation/insertoperation.js +7 -35
- package/src/model/operation/markeroperation.js +9 -48
- package/src/model/operation/mergeoperation.js +9 -42
- package/src/model/operation/moveoperation.js +15 -39
- package/src/model/operation/nooperation.js +1 -7
- package/src/model/operation/operation.js +5 -63
- package/src/model/operation/operationfactory.js +3 -6
- package/src/model/operation/renameoperation.js +9 -29
- package/src/model/operation/rootattributeoperation.js +19 -48
- package/src/model/operation/splitoperation.js +10 -48
- package/src/model/operation/transform.js +110 -151
- package/src/model/operation/utils.js +37 -52
- package/src/model/position.js +118 -230
- package/src/model/range.js +146 -202
- package/src/model/rootelement.js +8 -47
- package/src/model/schema.js +245 -282
- package/src/model/selection.js +135 -196
- package/src/model/text.js +10 -37
- package/src/model/textproxy.js +16 -70
- package/src/model/treewalker.js +11 -102
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.js +11 -12
- package/src/model/utils/deletecontent.js +93 -62
- package/src/model/utils/findoptimalinsertionrange.js +25 -25
- package/src/model/utils/getselectedcontent.js +3 -6
- package/src/model/utils/insertcontent.js +37 -130
- package/src/model/utils/insertobject.js +40 -40
- package/src/model/utils/modifyselection.js +24 -34
- package/src/model/utils/selection-post-fixer.js +53 -59
- package/src/model/writer.js +209 -316
- package/src/view/attributeelement.js +2 -2
- package/src/view/containerelement.js +1 -1
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.js +3 -5
- package/src/view/documentfragment.js +50 -4
- package/src/view/documentselection.js +2 -3
- package/src/view/domconverter.js +4 -8
- package/src/view/downcastwriter.js +2 -3
- package/src/view/editableelement.js +2 -3
- package/src/view/element.js +6 -8
- package/src/view/elementdefinition.js +1 -1
- package/src/view/emptyelement.js +2 -2
- package/src/view/filler.js +2 -3
- package/src/view/item.js +1 -1
- package/src/view/matcher.js +2 -2
- package/src/view/node.js +2 -5
- package/src/view/observer/arrowkeysobserver.js +1 -1
- package/src/view/observer/bubblingemittermixin.js +3 -6
- package/src/view/observer/bubblingeventinfo.js +2 -2
- package/src/view/observer/clickobserver.js +1 -1
- package/src/view/observer/compositionobserver.js +1 -1
- package/src/view/observer/domeventdata.js +1 -1
- package/src/view/observer/domeventobserver.js +1 -1
- package/src/view/observer/fakeselectionobserver.js +2 -2
- package/src/view/observer/focusobserver.js +25 -3
- package/src/view/observer/inputobserver.js +2 -2
- package/src/view/observer/keyobserver.js +2 -2
- package/src/view/observer/mouseobserver.js +1 -1
- package/src/view/observer/mutationobserver.js +1 -1
- package/src/view/observer/observer.js +3 -3
- package/src/view/observer/selectionobserver.js +21 -3
- package/src/view/observer/tabobserver.js +2 -2
- package/src/view/placeholder.js +1 -1
- package/src/view/position.js +2 -3
- package/src/view/range.js +1 -1
- package/src/view/rawelement.js +2 -2
- package/src/view/renderer.js +3 -12
- package/src/view/rooteditableelement.js +1 -1
- package/src/view/selection.js +2 -6
- package/src/view/styles/background.js +1 -1
- package/src/view/styles/border.js +1 -1
- package/src/view/styles/margin.js +1 -1
- package/src/view/styles/padding.js +1 -1
- package/src/view/styles/utils.js +1 -1
- package/src/view/stylesmap.js +1 -1
- package/src/view/text.js +1 -1
- package/src/view/textproxy.js +2 -2
- package/src/view/treewalker.js +2 -2
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.js +2 -3
- package/src/view/upcastwriter.js +1 -1
- package/src/view/view.js +7 -7
- package/theme/placeholder.css +1 -1
- package/theme/renderer.css +1 -1
package/src/model/range.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
import TypeCheckable from './typecheckable';
|
|
9
9
|
import Position from './position';
|
|
10
10
|
import TreeWalker from './treewalker';
|
|
11
|
-
import CKEditorError from '@ckeditor/ckeditor5-utils
|
|
12
|
-
import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
|
|
11
|
+
import { CKEditorError, compareArrays } from '@ckeditor/ckeditor5-utils';
|
|
13
12
|
/**
|
|
14
13
|
* Represents a range in the model tree.
|
|
15
14
|
*
|
|
@@ -23,25 +22,12 @@ export default class Range extends TypeCheckable {
|
|
|
23
22
|
/**
|
|
24
23
|
* Creates a range spanning from `start` position to `end` position.
|
|
25
24
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* the range will be collapsed at the `start` position.
|
|
25
|
+
* @param start The start position.
|
|
26
|
+
* @param end The end position. If not set, the range will be collapsed at the `start` position.
|
|
29
27
|
*/
|
|
30
28
|
constructor(start, end) {
|
|
31
29
|
super();
|
|
32
|
-
/**
|
|
33
|
-
* Start position.
|
|
34
|
-
*
|
|
35
|
-
* @readonly
|
|
36
|
-
* @member {module:engine/model/position~Position}
|
|
37
|
-
*/
|
|
38
30
|
this.start = Position._createAt(start);
|
|
39
|
-
/**
|
|
40
|
-
* End position.
|
|
41
|
-
*
|
|
42
|
-
* @readonly
|
|
43
|
-
* @member {module:engine/model/position~Position}
|
|
44
|
-
*/
|
|
45
31
|
this.end = end ? Position._createAt(end) : Position._createAt(start);
|
|
46
32
|
// If the range is collapsed, treat in a similar way as a position and set its boundaries stickiness to 'toNone'.
|
|
47
33
|
// In other case, make the boundaries stick to the "inside" of the range.
|
|
@@ -59,26 +45,20 @@ export default class Range extends TypeCheckable {
|
|
|
59
45
|
*
|
|
60
46
|
* This iterator uses {@link module:engine/model/treewalker~TreeWalker} with `boundaries` set to this range
|
|
61
47
|
* and `ignoreElementEnd` option set to `true`.
|
|
62
|
-
*
|
|
63
|
-
* @returns {Iterator.<module:engine/model/treewalker~TreeWalkerValue>}
|
|
64
48
|
*/
|
|
65
49
|
*[Symbol.iterator]() {
|
|
66
50
|
yield* new TreeWalker({ boundaries: this, ignoreElementEnd: true });
|
|
67
51
|
}
|
|
68
52
|
/**
|
|
69
|
-
*
|
|
53
|
+
* Describes whether the range is collapsed, that is if {@link #start} and
|
|
70
54
|
* {@link #end} positions are equal.
|
|
71
|
-
*
|
|
72
|
-
* @type {Boolean}
|
|
73
55
|
*/
|
|
74
56
|
get isCollapsed() {
|
|
75
57
|
return this.start.isEqual(this.end);
|
|
76
58
|
}
|
|
77
59
|
/**
|
|
78
|
-
*
|
|
60
|
+
* Describes whether this range is flat, that is if {@link #start} position and
|
|
79
61
|
* {@link #end} position are in the same {@link module:engine/model/position~Position#parent}.
|
|
80
|
-
*
|
|
81
|
-
* @type {Boolean}
|
|
82
62
|
*/
|
|
83
63
|
get isFlat() {
|
|
84
64
|
const startParentPath = this.start.getParentPath();
|
|
@@ -87,8 +67,6 @@ export default class Range extends TypeCheckable {
|
|
|
87
67
|
}
|
|
88
68
|
/**
|
|
89
69
|
* Range root element.
|
|
90
|
-
*
|
|
91
|
-
* @type {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment}
|
|
92
70
|
*/
|
|
93
71
|
get root() {
|
|
94
72
|
return this.start.root;
|
|
@@ -96,8 +74,8 @@ export default class Range extends TypeCheckable {
|
|
|
96
74
|
/**
|
|
97
75
|
* Checks whether this range contains given {@link module:engine/model/position~Position position}.
|
|
98
76
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @returns
|
|
77
|
+
* @param position Position to check.
|
|
78
|
+
* @returns `true` if given {@link module:engine/model/position~Position position} is contained
|
|
101
79
|
* in this range,`false` otherwise.
|
|
102
80
|
*/
|
|
103
81
|
containsPosition(position) {
|
|
@@ -106,8 +84,8 @@ export default class Range extends TypeCheckable {
|
|
|
106
84
|
/**
|
|
107
85
|
* Checks whether this range contains given {@link ~Range range}.
|
|
108
86
|
*
|
|
109
|
-
* @param
|
|
110
|
-
* @param
|
|
87
|
+
* @param otherRange Range to check.
|
|
88
|
+
* @param loose Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
|
|
111
89
|
* start or end at the same position as this range boundaries. If the check is loose (`true`), compared range can start, end or
|
|
112
90
|
* even be equal to this range. Note that collapsed ranges are always compared in strict mode.
|
|
113
91
|
* @returns {Boolean} `true` if given {@link ~Range range} boundaries are contained by this range, `false` otherwise.
|
|
@@ -122,8 +100,6 @@ export default class Range extends TypeCheckable {
|
|
|
122
100
|
}
|
|
123
101
|
/**
|
|
124
102
|
* Checks whether given {@link module:engine/model/item~Item} is inside this range.
|
|
125
|
-
*
|
|
126
|
-
* @param {module:engine/model/item~Item} item Model item to check.
|
|
127
103
|
*/
|
|
128
104
|
containsItem(item) {
|
|
129
105
|
const pos = Position._createBefore(item);
|
|
@@ -132,8 +108,8 @@ export default class Range extends TypeCheckable {
|
|
|
132
108
|
/**
|
|
133
109
|
* Two ranges are equal if their {@link #start} and {@link #end} positions are equal.
|
|
134
110
|
*
|
|
135
|
-
* @param
|
|
136
|
-
* @returns
|
|
111
|
+
* @param otherRange Range to compare with.
|
|
112
|
+
* @returns `true` if ranges are equal, `false` otherwise.
|
|
137
113
|
*/
|
|
138
114
|
isEqual(otherRange) {
|
|
139
115
|
return this.start.isEqual(otherRange.start) && this.end.isEqual(otherRange.end);
|
|
@@ -141,8 +117,8 @@ export default class Range extends TypeCheckable {
|
|
|
141
117
|
/**
|
|
142
118
|
* Checks and returns whether this range intersects with given range.
|
|
143
119
|
*
|
|
144
|
-
* @param
|
|
145
|
-
* @returns
|
|
120
|
+
* @param otherRange Range to compare with.
|
|
121
|
+
* @returns `true` if ranges intersect, `false` otherwise.
|
|
146
122
|
*/
|
|
147
123
|
isIntersecting(otherRange) {
|
|
148
124
|
return this.start.isBefore(otherRange.end) && this.end.isAfter(otherRange.start);
|
|
@@ -153,24 +129,26 @@ export default class Range extends TypeCheckable {
|
|
|
153
129
|
*
|
|
154
130
|
* Examples:
|
|
155
131
|
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
132
|
+
* ```ts
|
|
133
|
+
* let range = model.createRange(
|
|
134
|
+
* model.createPositionFromPath( root, [ 2, 7 ] ),
|
|
135
|
+
* model.createPositionFromPath( root, [ 4, 0, 1 ] )
|
|
136
|
+
* );
|
|
137
|
+
* let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 5 ] ) );
|
|
138
|
+
* let transformed = range.getDifference( otherRange );
|
|
139
|
+
* // transformed array has no ranges because `otherRange` contains `range`
|
|
163
140
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
141
|
+
* otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 3 ] ) );
|
|
142
|
+
* transformed = range.getDifference( otherRange );
|
|
143
|
+
* // transformed array has one range: from [ 3 ] to [ 4, 0, 1 ]
|
|
167
144
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
145
|
+
* otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 4 ] ) );
|
|
146
|
+
* transformed = range.getDifference( otherRange );
|
|
147
|
+
* // transformed array has two ranges: from [ 2, 7 ] to [ 3 ] and from [ 4 ] to [ 4, 0, 1 ]
|
|
148
|
+
* ```
|
|
171
149
|
*
|
|
172
|
-
* @param
|
|
173
|
-
* @returns
|
|
150
|
+
* @param otherRange Range to differentiate against.
|
|
151
|
+
* @returns The difference between ranges.
|
|
174
152
|
*/
|
|
175
153
|
getDifference(otherRange) {
|
|
176
154
|
const ranges = [];
|
|
@@ -199,18 +177,20 @@ export default class Range extends TypeCheckable {
|
|
|
199
177
|
*
|
|
200
178
|
* Examples:
|
|
201
179
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* let range = model.createRange(
|
|
182
|
+
* model.createPositionFromPath( root, [ 2, 7 ] ),
|
|
183
|
+
* model.createPositionFromPath( root, [ 4, 0, 1 ] )
|
|
184
|
+
* );
|
|
185
|
+
* let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 2 ] ) );
|
|
186
|
+
* let transformed = range.getIntersection( otherRange ); // null - ranges have no common part
|
|
208
187
|
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
188
|
+
* otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 5 ] ) );
|
|
189
|
+
* transformed = range.getIntersection( otherRange ); // range from [ 3 ] to [ 4, 0, 1 ]
|
|
190
|
+
* ```
|
|
211
191
|
*
|
|
212
|
-
* @param
|
|
213
|
-
* @returns
|
|
192
|
+
* @param otherRange Range to check for intersection.
|
|
193
|
+
* @returns A common part of given ranges or `null` if ranges have no common part.
|
|
214
194
|
*/
|
|
215
195
|
getIntersection(otherRange) {
|
|
216
196
|
if (this.isIntersecting(otherRange)) {
|
|
@@ -239,27 +219,29 @@ export default class Range extends TypeCheckable {
|
|
|
239
219
|
*
|
|
240
220
|
* Examples:
|
|
241
221
|
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
222
|
+
* ```ts
|
|
223
|
+
* let range = model.createRange(
|
|
224
|
+
* model.createPositionFromPath( root, [ 2, 7 ] ),
|
|
225
|
+
* model.createPositionFromPath( root, [ 4, 0, 1 ] )
|
|
226
|
+
* );
|
|
227
|
+
* let otherRange = model.createRange(
|
|
228
|
+
* model.createPositionFromPath( root, [ 1 ] ),
|
|
229
|
+
* model.createPositionFromPath( root, [ 2 ] )
|
|
230
|
+
* );
|
|
231
|
+
* let transformed = range.getJoined( otherRange ); // null - ranges have no common part
|
|
232
|
+
*
|
|
233
|
+
* otherRange = model.createRange(
|
|
234
|
+
* model.createPositionFromPath( root, [ 3 ] ),
|
|
235
|
+
* model.createPositionFromPath( root, [ 5 ] )
|
|
236
|
+
* );
|
|
237
|
+
* transformed = range.getJoined( otherRange ); // range from [ 2, 7 ] to [ 5 ]
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @param otherRange Range to be joined.
|
|
241
|
+
* @param loose Whether the intersection check is loose or strict. If the check is strict (`false`),
|
|
260
242
|
* ranges are tested for intersection or whether start/end positions are equal. If the check is loose (`true`),
|
|
261
243
|
* compared range is also checked if it's {@link module:engine/model/position~Position#isTouching touching} current range.
|
|
262
|
-
* @returns
|
|
244
|
+
* @returns A sum of given ranges or `null` if ranges have no common part.
|
|
263
245
|
*/
|
|
264
246
|
getJoined(otherRange, loose = false) {
|
|
265
247
|
let shouldJoin = this.isIntersecting(otherRange);
|
|
@@ -289,31 +271,35 @@ export default class Range extends TypeCheckable {
|
|
|
289
271
|
*
|
|
290
272
|
* See an example of a model structure (`[` and `]` are range boundaries):
|
|
291
273
|
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
274
|
+
* ```
|
|
275
|
+
* root root
|
|
276
|
+
* |- element DIV DIV P2 P3 DIV
|
|
277
|
+
* | |- element H H P1 f o o b a r H P4
|
|
278
|
+
* | | |- "fir[st" fir[st lorem se]cond ipsum
|
|
279
|
+
* | |- element P1
|
|
280
|
+
* | | |- "lorem" ||
|
|
281
|
+
* |- element P2 ||
|
|
282
|
+
* | |- "foo" VV
|
|
283
|
+
* |- element P3
|
|
284
|
+
* | |- "bar" root
|
|
285
|
+
* |- element DIV DIV [P2 P3] DIV
|
|
286
|
+
* | |- element H H [P1] f o o b a r H P4
|
|
287
|
+
* | | |- "se]cond" fir[st] lorem [se]cond ipsum
|
|
288
|
+
* | |- element P4
|
|
289
|
+
* | | |- "ipsum"
|
|
290
|
+
* ```
|
|
307
291
|
*
|
|
308
292
|
* As it can be seen, letters contained in the range are: `stloremfoobarse`, spread across different parents.
|
|
309
293
|
* We are looking for minimal set of flat ranges that contains the same nodes.
|
|
310
294
|
*
|
|
311
295
|
* Minimal flat ranges for above range `( [ 0, 0, 3 ], [ 3, 0, 2 ] )` will be:
|
|
312
296
|
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
297
|
+
* ```
|
|
298
|
+
* ( [ 0, 0, 3 ], [ 0, 0, 5 ] ) = "st"
|
|
299
|
+
* ( [ 0, 1 ], [ 0, 2 ] ) = element P1 ("lorem")
|
|
300
|
+
* ( [ 1 ], [ 3 ] ) = element P2, element P3 ("foobar")
|
|
301
|
+
* ( [ 3, 0, 0 ], [ 3, 0, 2 ] ) = "se"
|
|
302
|
+
* ```
|
|
317
303
|
*
|
|
318
304
|
* **Note:** if an {@link module:engine/model/element~Element element} is not wholly contained in this range, it won't be returned
|
|
319
305
|
* in any of the returned flat ranges. See in the example how `H` elements at the beginning and at the end of the range
|
|
@@ -321,7 +307,7 @@ export default class Range extends TypeCheckable {
|
|
|
321
307
|
*
|
|
322
308
|
* **Note:** this method is not returning flat ranges that contain no nodes.
|
|
323
309
|
*
|
|
324
|
-
* @returns
|
|
310
|
+
* @returns Array of flat ranges covering this range.
|
|
325
311
|
*/
|
|
326
312
|
getMinimalFlatRanges() {
|
|
327
313
|
const ranges = [];
|
|
@@ -355,20 +341,17 @@ export default class Range extends TypeCheckable {
|
|
|
355
341
|
*
|
|
356
342
|
* For example, to iterate over all items in the entire document root:
|
|
357
343
|
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
344
|
+
* ```ts
|
|
345
|
+
* // Create a range spanning over the entire root content:
|
|
346
|
+
* const range = editor.model.createRangeIn( editor.model.document.getRoot() );
|
|
360
347
|
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
348
|
+
* // Iterate over all items in this range:
|
|
349
|
+
* for ( const value of range.getWalker() ) {
|
|
350
|
+
* console.log( value.item );
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
365
353
|
*
|
|
366
|
-
* @param
|
|
367
|
-
* @param {module:engine/model/position~Position} [options.startPosition]
|
|
368
|
-
* @param {Boolean} [options.singleCharacters=false]
|
|
369
|
-
* @param {Boolean} [options.shallow=false]
|
|
370
|
-
* @param {Boolean} [options.ignoreElementEnd=false]
|
|
371
|
-
* @returns {module:engine/model/treewalker~TreeWalker}
|
|
354
|
+
* @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
|
|
372
355
|
*/
|
|
373
356
|
getWalker(options = {}) {
|
|
374
357
|
options.boundaries = this;
|
|
@@ -385,8 +368,7 @@ export default class Range extends TypeCheckable {
|
|
|
385
368
|
* You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~TreeWalker} for
|
|
386
369
|
* a full list of available options.
|
|
387
370
|
*
|
|
388
|
-
* @param
|
|
389
|
-
* @returns {Iterable.<module:engine/model/item~Item>}
|
|
371
|
+
* @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
|
|
390
372
|
*/
|
|
391
373
|
*getItems(options = {}) {
|
|
392
374
|
options.boundaries = this;
|
|
@@ -406,8 +388,7 @@ export default class Range extends TypeCheckable {
|
|
|
406
388
|
* You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~TreeWalker} for
|
|
407
389
|
* a full list of available options.
|
|
408
390
|
*
|
|
409
|
-
* @param
|
|
410
|
-
* @returns {Iterable.<module:engine/model/position~Position>}
|
|
391
|
+
* @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
|
|
411
392
|
*/
|
|
412
393
|
*getPositions(options = {}) {
|
|
413
394
|
options.boundaries = this;
|
|
@@ -424,8 +405,8 @@ export default class Range extends TypeCheckable {
|
|
|
424
405
|
* moved to a different part of document tree). For this reason, an array is returned by this method and it
|
|
425
406
|
* may contain one or more `Range` instances.
|
|
426
407
|
*
|
|
427
|
-
* @param
|
|
428
|
-
* @returns
|
|
408
|
+
* @param operation Operation to transform range by.
|
|
409
|
+
* @returns Range which is the result of transformation.
|
|
429
410
|
*/
|
|
430
411
|
getTransformedByOperation(operation) {
|
|
431
412
|
switch (operation.type) {
|
|
@@ -446,8 +427,8 @@ export default class Range extends TypeCheckable {
|
|
|
446
427
|
* Returns a range that is a result of transforming this range by multiple `operations`.
|
|
447
428
|
*
|
|
448
429
|
* @see ~Range#getTransformedByOperation
|
|
449
|
-
* @param
|
|
450
|
-
* @returns
|
|
430
|
+
* @param operations Operations to transform the range by.
|
|
431
|
+
* @returns Range which is the result of transformation.
|
|
451
432
|
*/
|
|
452
433
|
getTransformedByOperations(operations) {
|
|
453
434
|
const ranges = [new Range(this.start, this.end)];
|
|
@@ -476,8 +457,6 @@ export default class Range extends TypeCheckable {
|
|
|
476
457
|
/**
|
|
477
458
|
* Returns an {@link module:engine/model/element~Element} or {@link module:engine/model/documentfragment~DocumentFragment}
|
|
478
459
|
* which is a common ancestor of the range's both ends (in which the entire range is contained).
|
|
479
|
-
*
|
|
480
|
-
* @returns {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment|null}
|
|
481
460
|
*/
|
|
482
461
|
getCommonAncestor() {
|
|
483
462
|
return this.start.getCommonAncestor(this.end);
|
|
@@ -486,8 +465,6 @@ export default class Range extends TypeCheckable {
|
|
|
486
465
|
* Returns an {@link module:engine/model/element~Element Element} contained by the range.
|
|
487
466
|
* The element will be returned when it is the **only** node within the range and **fully–contained**
|
|
488
467
|
* at the same time.
|
|
489
|
-
*
|
|
490
|
-
* @returns {module:engine/model/element~Element|null}
|
|
491
468
|
*/
|
|
492
469
|
getContainedElement() {
|
|
493
470
|
if (this.isCollapsed) {
|
|
@@ -503,7 +480,7 @@ export default class Range extends TypeCheckable {
|
|
|
503
480
|
/**
|
|
504
481
|
* Converts `Range` to plain object and returns it.
|
|
505
482
|
*
|
|
506
|
-
* @returns
|
|
483
|
+
* @returns `Node` converted to plain object.
|
|
507
484
|
*/
|
|
508
485
|
toJSON() {
|
|
509
486
|
return {
|
|
@@ -513,8 +490,6 @@ export default class Range extends TypeCheckable {
|
|
|
513
490
|
}
|
|
514
491
|
/**
|
|
515
492
|
* Returns a new range that is equal to current range.
|
|
516
|
-
*
|
|
517
|
-
* @returns {module:engine/model/range~Range}
|
|
518
493
|
*/
|
|
519
494
|
clone() {
|
|
520
495
|
return new this.constructor(this.start, this.end);
|
|
@@ -525,9 +500,6 @@ export default class Range extends TypeCheckable {
|
|
|
525
500
|
* One or more ranges may be returned as a result of this transformation.
|
|
526
501
|
*
|
|
527
502
|
* @internal
|
|
528
|
-
* @protected
|
|
529
|
-
* @param {module:engine/model/operation/insertoperation~InsertOperation} operation
|
|
530
|
-
* @returns {Array.<module:engine/model/range~Range>}
|
|
531
503
|
*/
|
|
532
504
|
_getTransformedByInsertOperation(operation, spread = false) {
|
|
533
505
|
return this._getTransformedByInsertion(operation.position, operation.howMany, spread);
|
|
@@ -538,9 +510,6 @@ export default class Range extends TypeCheckable {
|
|
|
538
510
|
* One or more ranges may be returned as a result of this transformation.
|
|
539
511
|
*
|
|
540
512
|
* @internal
|
|
541
|
-
* @protected
|
|
542
|
-
* @param {module:engine/model/operation/moveoperation~MoveOperation} operation
|
|
543
|
-
* @returns {Array.<module:engine/model/range~Range>}
|
|
544
513
|
*/
|
|
545
514
|
_getTransformedByMoveOperation(operation, spread = false) {
|
|
546
515
|
const sourcePosition = operation.sourcePosition;
|
|
@@ -554,9 +523,6 @@ export default class Range extends TypeCheckable {
|
|
|
554
523
|
* Always one range is returned. The transformation is done in a way to not break the range.
|
|
555
524
|
*
|
|
556
525
|
* @internal
|
|
557
|
-
* @protected
|
|
558
|
-
* @param {module:engine/model/operation/splitoperation~SplitOperation} operation
|
|
559
|
-
* @returns {module:engine/model/range~Range}
|
|
560
526
|
*/
|
|
561
527
|
_getTransformedBySplitOperation(operation) {
|
|
562
528
|
const start = this.start._getTransformedBySplitOperation(operation);
|
|
@@ -578,9 +544,6 @@ export default class Range extends TypeCheckable {
|
|
|
578
544
|
* Always one range is returned. The transformation is done in a way to not break the range.
|
|
579
545
|
*
|
|
580
546
|
* @internal
|
|
581
|
-
* @protected
|
|
582
|
-
* @param {module:engine/model/operation/mergeoperation~MergeOperation} operation
|
|
583
|
-
* @returns {module:engine/model/range~Range}
|
|
584
547
|
*/
|
|
585
548
|
_getTransformedByMergeOperation(operation) {
|
|
586
549
|
// Special case when the marker is set on "the closing tag" of an element. Marker can be set like that during
|
|
@@ -655,29 +618,30 @@ export default class Range extends TypeCheckable {
|
|
|
655
618
|
*
|
|
656
619
|
* Examples:
|
|
657
620
|
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
621
|
+
* ```ts
|
|
622
|
+
* let range = model.createRange(
|
|
623
|
+
* model.createPositionFromPath( root, [ 2, 7 ] ),
|
|
624
|
+
* model.createPositionFromPath( root, [ 4, 0, 1 ] )
|
|
625
|
+
* );
|
|
626
|
+
* let transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 1 ] ), 2 );
|
|
627
|
+
* // transformed array has one range from [ 4, 7 ] to [ 6, 0, 1 ]
|
|
664
628
|
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
629
|
+
* transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 4, 0, 0 ] ), 4 );
|
|
630
|
+
* // transformed array has one range from [ 2, 7 ] to [ 4, 0, 5 ]
|
|
667
631
|
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
632
|
+
* transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4 );
|
|
633
|
+
* // transformed array has one range, which is equal to original range
|
|
670
634
|
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
635
|
+
* transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4, true );
|
|
636
|
+
* // transformed array has two ranges: from [ 2, 7 ] to [ 3, 2 ] and from [ 3, 6 ] to [ 4, 0, 1 ]
|
|
637
|
+
* ```
|
|
673
638
|
*
|
|
674
639
|
* @internal
|
|
675
|
-
* @
|
|
676
|
-
* @param
|
|
677
|
-
* @param {
|
|
678
|
-
* @param {Boolean} [spread] Flag indicating whether this {~Range range} should be spread if insertion
|
|
640
|
+
* @param insertPosition Position where nodes are inserted.
|
|
641
|
+
* @param howMany How many nodes are inserted.
|
|
642
|
+
* @param spread Flag indicating whether this {~Range range} should be spread if insertion
|
|
679
643
|
* was inside the range. Defaults to `false`.
|
|
680
|
-
* @returns
|
|
644
|
+
* @returns Result of the transformation.
|
|
681
645
|
*/
|
|
682
646
|
_getTransformedByInsertion(insertPosition, howMany, spread = false) {
|
|
683
647
|
if (spread && this.containsPosition(insertPosition)) {
|
|
@@ -701,12 +665,11 @@ export default class Range extends TypeCheckable {
|
|
|
701
665
|
* {@link ~Range range} by moving `howMany` nodes from `sourcePosition` to `targetPosition`.
|
|
702
666
|
*
|
|
703
667
|
* @internal
|
|
704
|
-
* @
|
|
705
|
-
* @param
|
|
706
|
-
* @param
|
|
707
|
-
* @param
|
|
708
|
-
* @
|
|
709
|
-
* @returns {Array.<module:engine/model/range~Range>} Result of the transformation.
|
|
668
|
+
* @param sourcePosition Position from which nodes are moved.
|
|
669
|
+
* @param targetPosition Position to where nodes are moved.
|
|
670
|
+
* @param howMany How many nodes are moved.
|
|
671
|
+
* @param spread Whether the range should be spread if the move points inside the range.
|
|
672
|
+
* @returns Result of the transformation.
|
|
710
673
|
*/
|
|
711
674
|
_getTransformedByMove(sourcePosition, targetPosition, howMany, spread = false) {
|
|
712
675
|
// Special case for transforming a collapsed range. Just transform it like a position.
|
|
@@ -773,10 +736,9 @@ export default class Range extends TypeCheckable {
|
|
|
773
736
|
* If the deleted range contains transformed range, `null` will be returned.
|
|
774
737
|
*
|
|
775
738
|
* @internal
|
|
776
|
-
* @
|
|
777
|
-
* @param
|
|
778
|
-
* @
|
|
779
|
-
* @returns {module:engine/model/range~Range|null} Result of the transformation.
|
|
739
|
+
* @param deletionPosition Position from which nodes are removed.
|
|
740
|
+
* @param howMany How many nodes are removed.
|
|
741
|
+
* @returns Result of the transformation.
|
|
780
742
|
*/
|
|
781
743
|
_getTransformedByDeletion(deletePosition, howMany) {
|
|
782
744
|
let newStart = this.start._getTransformedByDeletion(deletePosition, howMany);
|
|
@@ -797,10 +759,8 @@ export default class Range extends TypeCheckable {
|
|
|
797
759
|
* given `shift`. If `shift` is a negative value, shifted position is treated as the beginning of the range.
|
|
798
760
|
*
|
|
799
761
|
* @internal
|
|
800
|
-
* @
|
|
801
|
-
* @param
|
|
802
|
-
* @param {Number} shift How long the range should be.
|
|
803
|
-
* @returns {module:engine/model/range~Range}
|
|
762
|
+
* @param position Beginning of the range.
|
|
763
|
+
* @param shift How long the range should be.
|
|
804
764
|
*/
|
|
805
765
|
static _createFromPositionAndShift(position, shift) {
|
|
806
766
|
const start = position;
|
|
@@ -812,9 +772,7 @@ export default class Range extends TypeCheckable {
|
|
|
812
772
|
* that element and ends after the last child of that element.
|
|
813
773
|
*
|
|
814
774
|
* @internal
|
|
815
|
-
* @
|
|
816
|
-
* @param {module:engine/model/element~Element} element Element which is a parent for the range.
|
|
817
|
-
* @returns {module:engine/model/range~Range}
|
|
775
|
+
* @param element Element which is a parent for the range.
|
|
818
776
|
*/
|
|
819
777
|
static _createIn(element) {
|
|
820
778
|
return new this(Position._createAt(element, 0), Position._createAt(element, element.maxOffset));
|
|
@@ -823,9 +781,6 @@ export default class Range extends TypeCheckable {
|
|
|
823
781
|
* Creates a range that starts before given {@link module:engine/model/item~Item model item} and ends after it.
|
|
824
782
|
*
|
|
825
783
|
* @internal
|
|
826
|
-
* @protected
|
|
827
|
-
* @param {module:engine/model/item~Item} item
|
|
828
|
-
* @returns {module:engine/model/range~Range}
|
|
829
784
|
*/
|
|
830
785
|
static _createOn(item) {
|
|
831
786
|
return this._createFromPositionAndShift(Position._createBefore(item), item.offsetSize);
|
|
@@ -837,15 +792,16 @@ export default class Range extends TypeCheckable {
|
|
|
837
792
|
* The first range from the array is a reference range. If other ranges start or end on the exactly same position where
|
|
838
793
|
* the reference range, they get combined into one range.
|
|
839
794
|
*
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
*
|
|
795
|
+
* ```
|
|
796
|
+
* [ ][] [ ][ ][ ][ ][] [ ] // Passed ranges, shown sorted
|
|
797
|
+
* [ ] // The result of the function if the first range was a reference range.
|
|
798
|
+
* [ ] // The result of the function if the third-to-seventh range was a reference range.
|
|
799
|
+
* [ ] // The result of the function if the last range was a reference range.
|
|
800
|
+
* ```
|
|
844
801
|
*
|
|
845
802
|
* @internal
|
|
846
|
-
* @
|
|
847
|
-
* @
|
|
848
|
-
* @returns {module:engine/model/range~Range} Combined range.
|
|
803
|
+
* @param ranges Ranges to combine.
|
|
804
|
+
* @returns Combined range.
|
|
849
805
|
*/
|
|
850
806
|
static _createFromRanges(ranges) {
|
|
851
807
|
if (ranges.length === 0) {
|
|
@@ -904,28 +860,16 @@ export default class Range extends TypeCheckable {
|
|
|
904
860
|
/**
|
|
905
861
|
* Creates a `Range` instance from given plain object (i.e. parsed JSON string).
|
|
906
862
|
*
|
|
907
|
-
* @param
|
|
908
|
-
* @param
|
|
909
|
-
* @returns
|
|
863
|
+
* @param json Plain object to be converted to `Range`.
|
|
864
|
+
* @param doc Document object that will be range owner.
|
|
865
|
+
* @returns `Range` instance created using given plain object.
|
|
910
866
|
*/
|
|
911
867
|
static fromJSON(json, doc) {
|
|
912
868
|
return new this(Position.fromJSON(json.start, doc), Position.fromJSON(json.end, doc));
|
|
913
869
|
}
|
|
914
870
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
*
|
|
918
|
-
* range.is( 'range' ); // -> true
|
|
919
|
-
* range.is( 'model:range' ); // -> true
|
|
920
|
-
*
|
|
921
|
-
* range.is( 'view:range' ); // -> false
|
|
922
|
-
* range.is( 'documentSelection' ); // -> false
|
|
923
|
-
*
|
|
924
|
-
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
925
|
-
*
|
|
926
|
-
* @param {String} type
|
|
927
|
-
* @returns {Boolean}
|
|
928
|
-
*/
|
|
871
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
872
|
+
// Proper overload would interfere with that.
|
|
929
873
|
Range.prototype.is = function (type) {
|
|
930
874
|
return type === 'range' || type === 'model:range';
|
|
931
875
|
};
|