@ckeditor/ckeditor5-engine 35.0.1 → 35.2.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.
Files changed (124) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/package.json +30 -24
  3. package/src/controller/datacontroller.js +467 -561
  4. package/src/controller/editingcontroller.js +168 -204
  5. package/src/conversion/conversion.js +541 -565
  6. package/src/conversion/conversionhelpers.js +24 -28
  7. package/src/conversion/downcastdispatcher.js +457 -686
  8. package/src/conversion/downcasthelpers.js +1583 -1965
  9. package/src/conversion/mapper.js +518 -707
  10. package/src/conversion/modelconsumable.js +240 -283
  11. package/src/conversion/upcastdispatcher.js +372 -718
  12. package/src/conversion/upcasthelpers.js +707 -818
  13. package/src/conversion/viewconsumable.js +524 -581
  14. package/src/dataprocessor/basichtmlwriter.js +12 -16
  15. package/src/dataprocessor/dataprocessor.js +5 -0
  16. package/src/dataprocessor/htmldataprocessor.js +100 -116
  17. package/src/dataprocessor/htmlwriter.js +1 -18
  18. package/src/dataprocessor/xmldataprocessor.js +116 -137
  19. package/src/dev-utils/model.js +260 -352
  20. package/src/dev-utils/operationreplayer.js +106 -126
  21. package/src/dev-utils/utils.js +34 -51
  22. package/src/dev-utils/view.js +632 -753
  23. package/src/index.js +0 -11
  24. package/src/model/batch.js +111 -127
  25. package/src/model/differ.js +988 -1233
  26. package/src/model/document.js +340 -449
  27. package/src/model/documentfragment.js +327 -364
  28. package/src/model/documentselection.js +996 -1189
  29. package/src/model/element.js +306 -410
  30. package/src/model/history.js +224 -262
  31. package/src/model/item.js +5 -0
  32. package/src/model/liveposition.js +84 -145
  33. package/src/model/liverange.js +108 -185
  34. package/src/model/markercollection.js +379 -480
  35. package/src/model/model.js +883 -1034
  36. package/src/model/node.js +419 -463
  37. package/src/model/nodelist.js +176 -201
  38. package/src/model/operation/attributeoperation.js +153 -182
  39. package/src/model/operation/detachoperation.js +64 -83
  40. package/src/model/operation/insertoperation.js +135 -166
  41. package/src/model/operation/markeroperation.js +114 -140
  42. package/src/model/operation/mergeoperation.js +163 -191
  43. package/src/model/operation/moveoperation.js +157 -187
  44. package/src/model/operation/nooperation.js +28 -38
  45. package/src/model/operation/operation.js +106 -125
  46. package/src/model/operation/operationfactory.js +30 -34
  47. package/src/model/operation/renameoperation.js +109 -135
  48. package/src/model/operation/rootattributeoperation.js +155 -188
  49. package/src/model/operation/splitoperation.js +196 -232
  50. package/src/model/operation/transform.js +1833 -2204
  51. package/src/model/operation/utils.js +140 -204
  52. package/src/model/position.js +980 -1053
  53. package/src/model/range.js +910 -1028
  54. package/src/model/rootelement.js +77 -97
  55. package/src/model/schema.js +1189 -1835
  56. package/src/model/selection.js +745 -862
  57. package/src/model/text.js +90 -114
  58. package/src/model/textproxy.js +204 -240
  59. package/src/model/treewalker.js +316 -397
  60. package/src/model/typecheckable.js +16 -0
  61. package/src/model/utils/autoparagraphing.js +32 -44
  62. package/src/model/utils/deletecontent.js +334 -418
  63. package/src/model/utils/findoptimalinsertionrange.js +25 -36
  64. package/src/model/utils/getselectedcontent.js +96 -118
  65. package/src/model/utils/insertcontent.js +757 -773
  66. package/src/model/utils/insertobject.js +96 -119
  67. package/src/model/utils/modifyselection.js +120 -158
  68. package/src/model/utils/selection-post-fixer.js +153 -201
  69. package/src/model/writer.js +1305 -1474
  70. package/src/view/attributeelement.js +189 -225
  71. package/src/view/containerelement.js +75 -85
  72. package/src/view/document.js +172 -215
  73. package/src/view/documentfragment.js +200 -249
  74. package/src/view/documentselection.js +338 -367
  75. package/src/view/domconverter.js +1370 -1617
  76. package/src/view/downcastwriter.js +1747 -2076
  77. package/src/view/editableelement.js +81 -97
  78. package/src/view/element.js +739 -890
  79. package/src/view/elementdefinition.js +5 -0
  80. package/src/view/emptyelement.js +82 -92
  81. package/src/view/filler.js +35 -50
  82. package/src/view/item.js +5 -0
  83. package/src/view/matcher.js +260 -559
  84. package/src/view/node.js +274 -360
  85. package/src/view/observer/arrowkeysobserver.js +19 -28
  86. package/src/view/observer/bubblingemittermixin.js +120 -263
  87. package/src/view/observer/bubblingeventinfo.js +47 -55
  88. package/src/view/observer/clickobserver.js +7 -13
  89. package/src/view/observer/compositionobserver.js +14 -24
  90. package/src/view/observer/domeventdata.js +57 -67
  91. package/src/view/observer/domeventobserver.js +40 -64
  92. package/src/view/observer/fakeselectionobserver.js +81 -96
  93. package/src/view/observer/focusobserver.js +45 -61
  94. package/src/view/observer/inputobserver.js +7 -13
  95. package/src/view/observer/keyobserver.js +17 -27
  96. package/src/view/observer/mouseobserver.js +7 -14
  97. package/src/view/observer/mutationobserver.js +220 -315
  98. package/src/view/observer/observer.js +81 -102
  99. package/src/view/observer/selectionobserver.js +199 -246
  100. package/src/view/observer/tabobserver.js +23 -36
  101. package/src/view/placeholder.js +128 -173
  102. package/src/view/position.js +350 -401
  103. package/src/view/range.js +453 -513
  104. package/src/view/rawelement.js +85 -112
  105. package/src/view/renderer.js +874 -1018
  106. package/src/view/rooteditableelement.js +80 -90
  107. package/src/view/selection.js +608 -689
  108. package/src/view/styles/background.js +43 -44
  109. package/src/view/styles/border.js +220 -276
  110. package/src/view/styles/margin.js +8 -17
  111. package/src/view/styles/padding.js +8 -16
  112. package/src/view/styles/utils.js +127 -160
  113. package/src/view/stylesmap.js +728 -905
  114. package/src/view/text.js +102 -126
  115. package/src/view/textproxy.js +144 -170
  116. package/src/view/treewalker.js +383 -479
  117. package/src/view/typecheckable.js +19 -0
  118. package/src/view/uielement.js +166 -187
  119. package/src/view/upcastwriter.js +395 -449
  120. package/src/view/view.js +569 -664
  121. package/src/dataprocessor/dataprocessor.jsdoc +0 -64
  122. package/src/model/item.jsdoc +0 -14
  123. package/src/view/elementdefinition.jsdoc +0 -59
  124. package/src/view/item.jsdoc +0 -14
@@ -2,14 +2,11 @@
2
2
  * @license Copyright (c) 2003-2022, 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
-
6
5
  /**
7
6
  * @module engine/model/utils/selection-post-fixer
8
7
  */
9
-
10
- import Range from '../range';
11
8
  import Position from '../position';
12
-
9
+ import Range from '../range';
13
10
  /**
14
11
  * Injects selection post-fixer to the model.
15
12
  *
@@ -61,61 +58,54 @@ import Position from '../position';
61
58
  *
62
59
  * @param {module:engine/model/model~Model} model
63
60
  */
64
- export function injectSelectionPostFixer( model ) {
65
- model.document.registerPostFixer( writer => selectionPostFixer( writer, model ) );
61
+ export function injectSelectionPostFixer(model) {
62
+ model.document.registerPostFixer(writer => selectionPostFixer(writer, model));
66
63
  }
67
-
68
64
  // The selection post-fixer.
69
65
  //
70
66
  // @param {module:engine/model/writer~Writer} writer
71
67
  // @param {module:engine/model/model~Model} model
72
- function selectionPostFixer( writer, model ) {
73
- const selection = model.document.selection;
74
- const schema = model.schema;
75
-
76
- const ranges = [];
77
-
78
- let wasFixed = false;
79
-
80
- for ( const modelRange of selection.getRanges() ) {
81
- // Go through all ranges in selection and try fixing each of them.
82
- // Those ranges might overlap but will be corrected later.
83
- const correctedRange = tryFixingRange( modelRange, schema );
84
-
85
- // "Selection fixing" algorithms sometimes get lost. In consequence, it may happen
86
- // that a new range is returned but, in fact, it has the same positions as the original
87
- // range anyway. If this range is not discarded, a new selection will be set and that,
88
- // for instance, would destroy the selection attributes. Let's make sure that the post-fixer
89
- // actually worked first before setting a new selection.
90
- //
91
- // https://github.com/ckeditor/ckeditor5/issues/6693
92
- if ( correctedRange && !correctedRange.isEqual( modelRange ) ) {
93
- ranges.push( correctedRange );
94
- wasFixed = true;
95
- } else {
96
- ranges.push( modelRange );
97
- }
98
- }
99
-
100
- // If any of ranges were corrected update the selection.
101
- if ( wasFixed ) {
102
- writer.setSelection( mergeIntersectingRanges( ranges ), { backward: selection.isBackward } );
103
- }
68
+ function selectionPostFixer(writer, model) {
69
+ const selection = model.document.selection;
70
+ const schema = model.schema;
71
+ const ranges = [];
72
+ let wasFixed = false;
73
+ for (const modelRange of selection.getRanges()) {
74
+ // Go through all ranges in selection and try fixing each of them.
75
+ // Those ranges might overlap but will be corrected later.
76
+ const correctedRange = tryFixingRange(modelRange, schema);
77
+ // "Selection fixing" algorithms sometimes get lost. In consequence, it may happen
78
+ // that a new range is returned but, in fact, it has the same positions as the original
79
+ // range anyway. If this range is not discarded, a new selection will be set and that,
80
+ // for instance, would destroy the selection attributes. Let's make sure that the post-fixer
81
+ // actually worked first before setting a new selection.
82
+ //
83
+ // https://github.com/ckeditor/ckeditor5/issues/6693
84
+ if (correctedRange && !correctedRange.isEqual(modelRange)) {
85
+ ranges.push(correctedRange);
86
+ wasFixed = true;
87
+ }
88
+ else {
89
+ ranges.push(modelRange);
90
+ }
91
+ }
92
+ // If any of ranges were corrected update the selection.
93
+ if (wasFixed) {
94
+ writer.setSelection(mergeIntersectingRanges(ranges), { backward: selection.isBackward });
95
+ }
96
+ return false;
104
97
  }
105
-
106
98
  // Tries fixing a range if it's incorrect.
107
99
  //
108
100
  // @param {module:engine/model/range~Range} range
109
101
  // @param {module:engine/model/schema~Schema} schema
110
102
  // @returns {module:engine/model/range~Range|null} Returns fixed range or null if range is valid.
111
- function tryFixingRange( range, schema ) {
112
- if ( range.isCollapsed ) {
113
- return tryFixingCollapsedRange( range, schema );
114
- }
115
-
116
- return tryFixingNonCollapsedRage( range, schema );
103
+ function tryFixingRange(range, schema) {
104
+ if (range.isCollapsed) {
105
+ return tryFixingCollapsedRange(range, schema);
106
+ }
107
+ return tryFixingNonCollapsedRage(range, schema);
117
108
  }
118
-
119
109
  // Tries to fix collapsed ranges.
120
110
  //
121
111
  // * Fixes situation when a range is in a place where $text is not allowed
@@ -123,190 +113,152 @@ function tryFixingRange( range, schema ) {
123
113
  // @param {module:engine/model/range~Range} range Collapsed range to fix.
124
114
  // @param {module:engine/model/schema~Schema} schema
125
115
  // @returns {module:engine/model/range~Range|null} Returns fixed range or null if range is valid.
126
- function tryFixingCollapsedRange( range, schema ) {
127
- const originalPosition = range.start;
128
-
129
- const nearestSelectionRange = schema.getNearestSelectionRange( originalPosition );
130
-
131
- // This might be null, i.e. when the editor data is empty or the selection is inside a limit element
132
- // that doesn't allow text inside.
133
- // In the first case, there is no need to fix the selection range.
134
- // In the second, let's go up to the outer selectable element
135
- if ( !nearestSelectionRange ) {
136
- const ancestorObject = originalPosition.getAncestors().reverse().find( item => schema.isObject( item ) );
137
-
138
- if ( ancestorObject ) {
139
- return Range._createOn( ancestorObject );
140
- }
141
-
142
- return null;
143
- }
144
-
145
- if ( !nearestSelectionRange.isCollapsed ) {
146
- return nearestSelectionRange;
147
- }
148
-
149
- const fixedPosition = nearestSelectionRange.start;
150
-
151
- // Fixed position is the same as original - no need to return corrected range.
152
- if ( originalPosition.isEqual( fixedPosition ) ) {
153
- return null;
154
- }
155
-
156
- return new Range( fixedPosition );
116
+ function tryFixingCollapsedRange(range, schema) {
117
+ const originalPosition = range.start;
118
+ const nearestSelectionRange = schema.getNearestSelectionRange(originalPosition);
119
+ // This might be null, i.e. when the editor data is empty or the selection is inside a limit element
120
+ // that doesn't allow text inside.
121
+ // In the first case, there is no need to fix the selection range.
122
+ // In the second, let's go up to the outer selectable element
123
+ if (!nearestSelectionRange) {
124
+ const ancestorObject = originalPosition.getAncestors().reverse().find(item => schema.isObject(item));
125
+ if (ancestorObject) {
126
+ return Range._createOn(ancestorObject);
127
+ }
128
+ return null;
129
+ }
130
+ if (!nearestSelectionRange.isCollapsed) {
131
+ return nearestSelectionRange;
132
+ }
133
+ const fixedPosition = nearestSelectionRange.start;
134
+ // Fixed position is the same as original - no need to return corrected range.
135
+ if (originalPosition.isEqual(fixedPosition)) {
136
+ return null;
137
+ }
138
+ return new Range(fixedPosition);
157
139
  }
158
-
159
140
  // Tries to fix an expanded range.
160
141
  //
161
142
  // @param {module:engine/model/range~Range} range Expanded range to fix.
162
143
  // @param {module:engine/model/schema~Schema} schema
163
144
  // @returns {module:engine/model/range~Range|null} Returns fixed range or null if range is valid.
164
- function tryFixingNonCollapsedRage( range, schema ) {
165
- const { start, end } = range;
166
-
167
- const isTextAllowedOnStart = schema.checkChild( start, '$text' );
168
- const isTextAllowedOnEnd = schema.checkChild( end, '$text' );
169
-
170
- const startLimitElement = schema.getLimitElement( start );
171
- const endLimitElement = schema.getLimitElement( end );
172
-
173
- // Ranges which both end are inside the same limit element (or root) might needs only minor fix.
174
- if ( startLimitElement === endLimitElement ) {
175
- // Range is valid when both position allows to place a text:
176
- // - <block>f[oobarba]z</block>
177
- // This would be "fixed" by a next check but as it will be the same it's better to return null so the selection stays the same.
178
- if ( isTextAllowedOnStart && isTextAllowedOnEnd ) {
179
- return null;
180
- }
181
-
182
- // Range that is on non-limit element (or is partially) must be fixed so it is placed inside the block around $text:
183
- // - [<block>foo</block>] -> <block>[foo]</block>
184
- // - [<block>foo]</block> -> <block>[foo]</block>
185
- // - <block>f[oo</block>] -> <block>f[oo]</block>
186
- // - [<block>foo</block><selectable></selectable>] -> <block>[foo</block><selectable></selectable>]
187
- if ( checkSelectionOnNonLimitElements( start, end, schema ) ) {
188
- const isStartBeforeSelectable = start.nodeAfter && schema.isSelectable( start.nodeAfter );
189
- const fixedStart = isStartBeforeSelectable ? null : schema.getNearestSelectionRange( start, 'forward' );
190
-
191
- const isEndAfterSelectable = end.nodeBefore && schema.isSelectable( end.nodeBefore );
192
- const fixedEnd = isEndAfterSelectable ? null : schema.getNearestSelectionRange( end, 'backward' );
193
-
194
- // The schema.getNearestSelectionRange might return null - if that happens use original position.
195
- const rangeStart = fixedStart ? fixedStart.start : start;
196
- const rangeEnd = fixedEnd ? fixedEnd.end : end;
197
-
198
- return new Range( rangeStart, rangeEnd );
199
- }
200
- }
201
-
202
- const isStartInLimit = startLimitElement && !startLimitElement.is( 'rootElement' );
203
- const isEndInLimit = endLimitElement && !endLimitElement.is( 'rootElement' );
204
-
205
- // At this point we eliminated valid positions on text nodes so if one of range positions is placed inside a limit element
206
- // then the range crossed limit element boundaries and needs to be fixed.
207
- if ( isStartInLimit || isEndInLimit ) {
208
- const bothInSameParent = ( start.nodeAfter && end.nodeBefore ) && start.nodeAfter.parent === end.nodeBefore.parent;
209
-
210
- const expandStart = isStartInLimit && ( !bothInSameParent || !isSelectable( start.nodeAfter, schema ) );
211
- const expandEnd = isEndInLimit && ( !bothInSameParent || !isSelectable( end.nodeBefore, schema ) );
212
-
213
- // Although we've already found limit element on start/end positions we must find the outer-most limit element.
214
- // as limit elements might be nested directly inside (ie table > tableRow > tableCell).
215
- let fixedStart = start;
216
- let fixedEnd = end;
217
-
218
- if ( expandStart ) {
219
- fixedStart = Position._createBefore( findOutermostLimitAncestor( startLimitElement, schema ) );
220
- }
221
-
222
- if ( expandEnd ) {
223
- fixedEnd = Position._createAfter( findOutermostLimitAncestor( endLimitElement, schema ) );
224
- }
225
-
226
- return new Range( fixedStart, fixedEnd );
227
- }
228
-
229
- // Range was not fixed at this point so it is valid - ie it was placed around limit element already.
230
- return null;
145
+ function tryFixingNonCollapsedRage(range, schema) {
146
+ const { start, end } = range;
147
+ const isTextAllowedOnStart = schema.checkChild(start, '$text');
148
+ const isTextAllowedOnEnd = schema.checkChild(end, '$text');
149
+ const startLimitElement = schema.getLimitElement(start);
150
+ const endLimitElement = schema.getLimitElement(end);
151
+ // Ranges which both end are inside the same limit element (or root) might needs only minor fix.
152
+ if (startLimitElement === endLimitElement) {
153
+ // Range is valid when both position allows to place a text:
154
+ // - <block>f[oobarba]z</block>
155
+ // This would be "fixed" by a next check but as it will be the same it's better to return null so the selection stays the same.
156
+ if (isTextAllowedOnStart && isTextAllowedOnEnd) {
157
+ return null;
158
+ }
159
+ // Range that is on non-limit element (or is partially) must be fixed so it is placed inside the block around $text:
160
+ // - [<block>foo</block>] -> <block>[foo]</block>
161
+ // - [<block>foo]</block> -> <block>[foo]</block>
162
+ // - <block>f[oo</block>] -> <block>f[oo]</block>
163
+ // - [<block>foo</block><selectable></selectable>] -> <block>[foo</block><selectable></selectable>]
164
+ if (checkSelectionOnNonLimitElements(start, end, schema)) {
165
+ const isStartBeforeSelectable = start.nodeAfter && schema.isSelectable(start.nodeAfter);
166
+ const fixedStart = isStartBeforeSelectable ? null : schema.getNearestSelectionRange(start, 'forward');
167
+ const isEndAfterSelectable = end.nodeBefore && schema.isSelectable(end.nodeBefore);
168
+ const fixedEnd = isEndAfterSelectable ? null : schema.getNearestSelectionRange(end, 'backward');
169
+ // The schema.getNearestSelectionRange might return null - if that happens use original position.
170
+ const rangeStart = fixedStart ? fixedStart.start : start;
171
+ const rangeEnd = fixedEnd ? fixedEnd.end : end;
172
+ return new Range(rangeStart, rangeEnd);
173
+ }
174
+ }
175
+ const isStartInLimit = startLimitElement && !startLimitElement.is('rootElement');
176
+ const isEndInLimit = endLimitElement && !endLimitElement.is('rootElement');
177
+ // At this point we eliminated valid positions on text nodes so if one of range positions is placed inside a limit element
178
+ // then the range crossed limit element boundaries and needs to be fixed.
179
+ if (isStartInLimit || isEndInLimit) {
180
+ const bothInSameParent = (start.nodeAfter && end.nodeBefore) && start.nodeAfter.parent === end.nodeBefore.parent;
181
+ const expandStart = isStartInLimit && (!bothInSameParent || !isSelectable(start.nodeAfter, schema));
182
+ const expandEnd = isEndInLimit && (!bothInSameParent || !isSelectable(end.nodeBefore, schema));
183
+ // Although we've already found limit element on start/end positions we must find the outer-most limit element.
184
+ // as limit elements might be nested directly inside (ie table > tableRow > tableCell).
185
+ let fixedStart = start;
186
+ let fixedEnd = end;
187
+ if (expandStart) {
188
+ fixedStart = Position._createBefore(findOutermostLimitAncestor(startLimitElement, schema));
189
+ }
190
+ if (expandEnd) {
191
+ fixedEnd = Position._createAfter(findOutermostLimitAncestor(endLimitElement, schema));
192
+ }
193
+ return new Range(fixedStart, fixedEnd);
194
+ }
195
+ // Range was not fixed at this point so it is valid - ie it was placed around limit element already.
196
+ return null;
231
197
  }
232
-
233
198
  // Finds the outer-most ancestor.
234
199
  //
235
200
  // @param {module:engine/model/node~Node} startingNode
236
201
  // @param {module:engine/model/schema~Schema} schema
237
- // @param {String} expandToDirection Direction of expansion - either 'start' or 'end' of the range.
238
202
  // @returns {module:engine/model/node~Node}
239
- function findOutermostLimitAncestor( startingNode, schema ) {
240
- let isLimitNode = startingNode;
241
- let parent = isLimitNode;
242
-
243
- // Find outer most isLimit block as such blocks might be nested (ie. in tables).
244
- while ( schema.isLimit( parent ) && parent.parent ) {
245
- isLimitNode = parent;
246
- parent = parent.parent;
247
- }
248
-
249
- return isLimitNode;
203
+ function findOutermostLimitAncestor(startingNode, schema) {
204
+ let isLimitNode = startingNode;
205
+ let parent = isLimitNode;
206
+ // Find outer most isLimit block as such blocks might be nested (ie. in tables).
207
+ while (schema.isLimit(parent) && parent.parent) {
208
+ isLimitNode = parent;
209
+ parent = parent.parent;
210
+ }
211
+ return isLimitNode;
250
212
  }
251
-
252
213
  // Checks whether any of range boundaries is placed around non-limit elements.
253
214
  //
254
215
  // @param {module:engine/model/position~Position} start
255
216
  // @param {module:engine/model/position~Position} end
256
217
  // @param {module:engine/model/schema~Schema} schema
257
218
  // @returns {Boolean}
258
- function checkSelectionOnNonLimitElements( start, end, schema ) {
259
- const startIsOnBlock = ( start.nodeAfter && !schema.isLimit( start.nodeAfter ) ) || schema.checkChild( start, '$text' );
260
- const endIsOnBlock = ( end.nodeBefore && !schema.isLimit( end.nodeBefore ) ) || schema.checkChild( end, '$text' );
261
-
262
- // We should fix such selection when one of those nodes needs fixing.
263
- return startIsOnBlock || endIsOnBlock;
219
+ function checkSelectionOnNonLimitElements(start, end, schema) {
220
+ const startIsOnBlock = (start.nodeAfter && !schema.isLimit(start.nodeAfter)) || schema.checkChild(start, '$text');
221
+ const endIsOnBlock = (end.nodeBefore && !schema.isLimit(end.nodeBefore)) || schema.checkChild(end, '$text');
222
+ // We should fix such selection when one of those nodes needs fixing.
223
+ return startIsOnBlock || endIsOnBlock;
264
224
  }
265
-
266
225
  /**
267
226
  * Returns a minimal non-intersecting array of ranges without duplicates.
268
227
  *
269
228
  * @param {Array.<module:engine/model/range~Range>} Ranges to merge.
270
229
  * @returns {Array.<module:engine/model/range~Range>} Array of unique and nonIntersecting ranges.
271
230
  */
272
- export function mergeIntersectingRanges( ranges ) {
273
- const rangesToMerge = [ ...ranges ];
274
- const rangeIndexesToRemove = new Set();
275
- let currentRangeIndex = 1;
276
-
277
- while ( currentRangeIndex < rangesToMerge.length ) {
278
- const currentRange = rangesToMerge[ currentRangeIndex ];
279
- const previousRanges = rangesToMerge.slice( 0, currentRangeIndex );
280
-
281
- for ( const [ previousRangeIndex, previousRange ] of previousRanges.entries() ) {
282
- if ( rangeIndexesToRemove.has( previousRangeIndex ) ) {
283
- continue;
284
- }
285
-
286
- if ( currentRange.isEqual( previousRange ) ) {
287
- rangeIndexesToRemove.add( previousRangeIndex );
288
- } else if ( currentRange.isIntersecting( previousRange ) ) {
289
- rangeIndexesToRemove.add( previousRangeIndex );
290
- rangeIndexesToRemove.add( currentRangeIndex );
291
-
292
- const mergedRange = currentRange.getJoined( previousRange );
293
- rangesToMerge.push( mergedRange );
294
- }
295
- }
296
-
297
- currentRangeIndex++;
298
- }
299
-
300
- const nonIntersectingRanges = rangesToMerge.filter( ( _, index ) => !rangeIndexesToRemove.has( index ) );
301
-
302
- return nonIntersectingRanges;
231
+ export function mergeIntersectingRanges(ranges) {
232
+ const rangesToMerge = [...ranges];
233
+ const rangeIndexesToRemove = new Set();
234
+ let currentRangeIndex = 1;
235
+ while (currentRangeIndex < rangesToMerge.length) {
236
+ const currentRange = rangesToMerge[currentRangeIndex];
237
+ const previousRanges = rangesToMerge.slice(0, currentRangeIndex);
238
+ for (const [previousRangeIndex, previousRange] of previousRanges.entries()) {
239
+ if (rangeIndexesToRemove.has(previousRangeIndex)) {
240
+ continue;
241
+ }
242
+ if (currentRange.isEqual(previousRange)) {
243
+ rangeIndexesToRemove.add(previousRangeIndex);
244
+ }
245
+ else if (currentRange.isIntersecting(previousRange)) {
246
+ rangeIndexesToRemove.add(previousRangeIndex);
247
+ rangeIndexesToRemove.add(currentRangeIndex);
248
+ const mergedRange = currentRange.getJoined(previousRange);
249
+ rangesToMerge.push(mergedRange);
250
+ }
251
+ }
252
+ currentRangeIndex++;
253
+ }
254
+ const nonIntersectingRanges = rangesToMerge.filter((_, index) => !rangeIndexesToRemove.has(index));
255
+ return nonIntersectingRanges;
303
256
  }
304
-
305
257
  // Checks if node exists and if it's a selectable.
306
258
  //
307
259
  // @param {module:engine/model/node~Node} node
308
260
  // @param {module:engine/model/schema~Schema} schema
309
261
  // @returns {Boolean}
310
- function isSelectable( node, schema ) {
311
- return node && schema.isSelectable( node );
262
+ function isSelectable(node, schema) {
263
+ return node && schema.isSelectable(node);
312
264
  }