@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.
- package/CHANGELOG.md +4 -4
- package/package.json +30 -24
- package/src/controller/datacontroller.js +467 -561
- package/src/controller/editingcontroller.js +168 -204
- package/src/conversion/conversion.js +541 -565
- package/src/conversion/conversionhelpers.js +24 -28
- package/src/conversion/downcastdispatcher.js +457 -686
- package/src/conversion/downcasthelpers.js +1583 -1965
- package/src/conversion/mapper.js +518 -707
- package/src/conversion/modelconsumable.js +240 -283
- package/src/conversion/upcastdispatcher.js +372 -718
- package/src/conversion/upcasthelpers.js +707 -818
- package/src/conversion/viewconsumable.js +524 -581
- package/src/dataprocessor/basichtmlwriter.js +12 -16
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.js +100 -116
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +116 -137
- package/src/dev-utils/model.js +260 -352
- package/src/dev-utils/operationreplayer.js +106 -126
- package/src/dev-utils/utils.js +34 -51
- package/src/dev-utils/view.js +632 -753
- package/src/index.js +0 -11
- package/src/model/batch.js +111 -127
- package/src/model/differ.js +988 -1233
- package/src/model/document.js +340 -449
- package/src/model/documentfragment.js +327 -364
- package/src/model/documentselection.js +996 -1189
- package/src/model/element.js +306 -410
- package/src/model/history.js +224 -262
- package/src/model/item.js +5 -0
- package/src/model/liveposition.js +84 -145
- package/src/model/liverange.js +108 -185
- package/src/model/markercollection.js +379 -480
- package/src/model/model.js +883 -1034
- package/src/model/node.js +419 -463
- package/src/model/nodelist.js +176 -201
- package/src/model/operation/attributeoperation.js +153 -182
- package/src/model/operation/detachoperation.js +64 -83
- package/src/model/operation/insertoperation.js +135 -166
- package/src/model/operation/markeroperation.js +114 -140
- package/src/model/operation/mergeoperation.js +163 -191
- package/src/model/operation/moveoperation.js +157 -187
- package/src/model/operation/nooperation.js +28 -38
- package/src/model/operation/operation.js +106 -125
- package/src/model/operation/operationfactory.js +30 -34
- package/src/model/operation/renameoperation.js +109 -135
- package/src/model/operation/rootattributeoperation.js +155 -188
- package/src/model/operation/splitoperation.js +196 -232
- package/src/model/operation/transform.js +1833 -2204
- package/src/model/operation/utils.js +140 -204
- package/src/model/position.js +980 -1053
- package/src/model/range.js +910 -1028
- package/src/model/rootelement.js +77 -97
- package/src/model/schema.js +1189 -1835
- package/src/model/selection.js +745 -862
- package/src/model/text.js +90 -114
- package/src/model/textproxy.js +204 -240
- package/src/model/treewalker.js +316 -397
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.js +32 -44
- package/src/model/utils/deletecontent.js +334 -418
- package/src/model/utils/findoptimalinsertionrange.js +25 -36
- package/src/model/utils/getselectedcontent.js +96 -118
- package/src/model/utils/insertcontent.js +757 -773
- package/src/model/utils/insertobject.js +96 -119
- package/src/model/utils/modifyselection.js +120 -158
- package/src/model/utils/selection-post-fixer.js +153 -201
- package/src/model/writer.js +1305 -1474
- package/src/view/attributeelement.js +189 -225
- package/src/view/containerelement.js +75 -85
- package/src/view/document.js +172 -215
- package/src/view/documentfragment.js +200 -249
- package/src/view/documentselection.js +338 -367
- package/src/view/domconverter.js +1370 -1617
- package/src/view/downcastwriter.js +1747 -2076
- package/src/view/editableelement.js +81 -97
- package/src/view/element.js +739 -890
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.js +82 -92
- package/src/view/filler.js +35 -50
- package/src/view/item.js +5 -0
- package/src/view/matcher.js +260 -559
- package/src/view/node.js +274 -360
- package/src/view/observer/arrowkeysobserver.js +19 -28
- package/src/view/observer/bubblingemittermixin.js +120 -263
- package/src/view/observer/bubblingeventinfo.js +47 -55
- package/src/view/observer/clickobserver.js +7 -13
- package/src/view/observer/compositionobserver.js +14 -24
- package/src/view/observer/domeventdata.js +57 -67
- package/src/view/observer/domeventobserver.js +40 -64
- package/src/view/observer/fakeselectionobserver.js +81 -96
- package/src/view/observer/focusobserver.js +45 -61
- package/src/view/observer/inputobserver.js +7 -13
- package/src/view/observer/keyobserver.js +17 -27
- package/src/view/observer/mouseobserver.js +7 -14
- package/src/view/observer/mutationobserver.js +220 -315
- package/src/view/observer/observer.js +81 -102
- package/src/view/observer/selectionobserver.js +199 -246
- package/src/view/observer/tabobserver.js +23 -36
- package/src/view/placeholder.js +128 -173
- package/src/view/position.js +350 -401
- package/src/view/range.js +453 -513
- package/src/view/rawelement.js +85 -112
- package/src/view/renderer.js +874 -1018
- package/src/view/rooteditableelement.js +80 -90
- package/src/view/selection.js +608 -689
- package/src/view/styles/background.js +43 -44
- package/src/view/styles/border.js +220 -276
- package/src/view/styles/margin.js +8 -17
- package/src/view/styles/padding.js +8 -16
- package/src/view/styles/utils.js +127 -160
- package/src/view/stylesmap.js +728 -905
- package/src/view/text.js +102 -126
- package/src/view/textproxy.js +144 -170
- package/src/view/treewalker.js +383 -479
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.js +166 -187
- package/src/view/upcastwriter.js +395 -449
- package/src/view/view.js +569 -664
- package/src/dataprocessor/dataprocessor.jsdoc +0 -64
- package/src/model/item.jsdoc +0 -14
- package/src/view/elementdefinition.jsdoc +0 -59
- package/src/view/item.jsdoc +0 -14
|
@@ -2,17 +2,13 @@
|
|
|
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/view/observer/selectionobserver
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* global setInterval, clearInterval */
|
|
11
|
-
|
|
12
9
|
import Observer from './observer';
|
|
13
10
|
import MutationObserver from './mutationobserver';
|
|
14
11
|
import { debounce } from 'lodash-es';
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* Selection observer class observes selection changes in the document. If a selection changes on the document this
|
|
18
14
|
* observer checks if there are any mutations and if the DOM selection is different from the
|
|
@@ -28,249 +24,206 @@ import { debounce } from 'lodash-es';
|
|
|
28
24
|
* @extends module:engine/view/observer/observer~Observer
|
|
29
25
|
*/
|
|
30
26
|
export default class SelectionObserver extends Observer {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
oldSelection: this.selection,
|
|
231
|
-
newSelection: newViewSelection,
|
|
232
|
-
domSelection
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// Prepare data for new selection and fire appropriate events.
|
|
236
|
-
this.document.fire( 'selectionChange', data );
|
|
237
|
-
|
|
238
|
-
// Call `#_fireSelectionChangeDoneDebounced` every time when `selectionChange` event is fired.
|
|
239
|
-
// This function is debounced what means that `selectionChangeDone` event will be fired only when
|
|
240
|
-
// defined int the function time will elapse since the last time the function was called.
|
|
241
|
-
// So `selectionChangeDone` will be fired when selection will stop changing.
|
|
242
|
-
this._fireSelectionChangeDoneDebounced( data );
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Clears `SelectionObserver` internal properties connected with preventing infinite loop.
|
|
248
|
-
*
|
|
249
|
-
* @protected
|
|
250
|
-
*/
|
|
251
|
-
_clearInfiniteLoop() {
|
|
252
|
-
this._loopbackCounter = 0;
|
|
253
|
-
}
|
|
27
|
+
constructor(view) {
|
|
28
|
+
super(view);
|
|
29
|
+
/**
|
|
30
|
+
* Instance of the mutation observer. Selection observer calls
|
|
31
|
+
* {@link module:engine/view/observer/mutationobserver~MutationObserver#flush} to ensure that the mutations will be handled
|
|
32
|
+
* before the {@link module:engine/view/document~Document#event:selectionChange} event is fired.
|
|
33
|
+
*
|
|
34
|
+
* @readonly
|
|
35
|
+
* @member {module:engine/view/observer/mutationobserver~MutationObserver}
|
|
36
|
+
* module:engine/view/observer/selectionobserver~SelectionObserver#mutationObserver
|
|
37
|
+
*/
|
|
38
|
+
this.mutationObserver = view.getObserver(MutationObserver);
|
|
39
|
+
/**
|
|
40
|
+
* Reference to the view {@link module:engine/view/documentselection~DocumentSelection} object used to compare
|
|
41
|
+
* new selection with it.
|
|
42
|
+
*
|
|
43
|
+
* @readonly
|
|
44
|
+
* @member {module:engine/view/documentselection~DocumentSelection}
|
|
45
|
+
* module:engine/view/observer/selectionobserver~SelectionObserver#selection
|
|
46
|
+
*/
|
|
47
|
+
this.selection = this.document.selection;
|
|
48
|
+
/* eslint-disable max-len */
|
|
49
|
+
/**
|
|
50
|
+
* Reference to the {@link module:engine/view/view~View#domConverter}.
|
|
51
|
+
*
|
|
52
|
+
* @readonly
|
|
53
|
+
* @member {module:engine/view/domconverter~DomConverter} module:engine/view/observer/selectionobserver~SelectionObserver#domConverter
|
|
54
|
+
*/
|
|
55
|
+
/* eslint-enable max-len */
|
|
56
|
+
this.domConverter = view.domConverter;
|
|
57
|
+
/**
|
|
58
|
+
* A set of documents which have added `selectionchange` listener to avoid adding a listener twice to the same
|
|
59
|
+
* document.
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @member {WeakSet.<Document>} module:engine/view/observer/selectionobserver~SelectionObserver#_documents
|
|
63
|
+
*/
|
|
64
|
+
this._documents = new WeakSet();
|
|
65
|
+
/**
|
|
66
|
+
* Fires debounced event `selectionChangeDone`. It uses `lodash#debounce` method to delay function call.
|
|
67
|
+
*
|
|
68
|
+
* @private
|
|
69
|
+
* @param {Object} data Selection change data.
|
|
70
|
+
* @method #_fireSelectionChangeDoneDebounced
|
|
71
|
+
*/
|
|
72
|
+
this._fireSelectionChangeDoneDebounced = debounce(data => {
|
|
73
|
+
this.document.fire('selectionChangeDone', data);
|
|
74
|
+
}, 200);
|
|
75
|
+
/**
|
|
76
|
+
* When called, starts clearing the {@link #_loopbackCounter} counter in time intervals. When the number of selection
|
|
77
|
+
* changes exceeds a certain limit within the interval of time, the observer will not fire `selectionChange` but warn about
|
|
78
|
+
* possible infinite selection loop.
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
* @member {Number} #_clearInfiniteLoopInterval
|
|
82
|
+
*/
|
|
83
|
+
this._clearInfiniteLoopInterval = setInterval(() => this._clearInfiniteLoop(), 1000);
|
|
84
|
+
/**
|
|
85
|
+
* Unlocks the `isSelecting` state of the view document in case the selection observer did not record this fact
|
|
86
|
+
* correctly (for whatever reason). It is a safeguard (paranoid check), that returns document to the normal state
|
|
87
|
+
* after a certain period of time (debounced, postponed by each selectionchange event).
|
|
88
|
+
*
|
|
89
|
+
* @private
|
|
90
|
+
* @method #_documentIsSelectingInactivityTimeoutDebounced
|
|
91
|
+
*/
|
|
92
|
+
this._documentIsSelectingInactivityTimeoutDebounced = debounce(() => (this.document.isSelecting = false), 5000);
|
|
93
|
+
/**
|
|
94
|
+
* Private property to check if the code does not enter infinite loop.
|
|
95
|
+
*
|
|
96
|
+
* @private
|
|
97
|
+
* @member {Number} module:engine/view/observer/selectionobserver~SelectionObserver#_loopbackCounter
|
|
98
|
+
*/
|
|
99
|
+
this._loopbackCounter = 0;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @inheritDoc
|
|
103
|
+
*/
|
|
104
|
+
observe(domElement) {
|
|
105
|
+
const domDocument = domElement.ownerDocument;
|
|
106
|
+
const startDocumentIsSelecting = () => {
|
|
107
|
+
this.document.isSelecting = true;
|
|
108
|
+
// Let's activate the safety timeout each time the document enters the "is selecting" state.
|
|
109
|
+
this._documentIsSelectingInactivityTimeoutDebounced();
|
|
110
|
+
};
|
|
111
|
+
const endDocumentIsSelecting = () => {
|
|
112
|
+
if (!this.document.isSelecting) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Make sure that model selection is up-to-date at the end of selecting process.
|
|
116
|
+
// Sometimes `selectionchange` events could arrive after the `mouseup` event and that selection could be already outdated.
|
|
117
|
+
this._handleSelectionChange(null, domDocument);
|
|
118
|
+
this.document.isSelecting = false;
|
|
119
|
+
// The safety timeout can be canceled when the document leaves the "is selecting" state.
|
|
120
|
+
this._documentIsSelectingInactivityTimeoutDebounced.cancel();
|
|
121
|
+
};
|
|
122
|
+
// The document has the "is selecting" state while the user keeps making (extending) the selection
|
|
123
|
+
// (e.g. by holding the mouse button and moving the cursor). The state resets when they either released
|
|
124
|
+
// the mouse button or interrupted the process by pressing or releasing any key.
|
|
125
|
+
this.listenTo(domElement, 'selectstart', startDocumentIsSelecting, { priority: 'highest' });
|
|
126
|
+
this.listenTo(domElement, 'keydown', endDocumentIsSelecting, { priority: 'highest', useCapture: true });
|
|
127
|
+
this.listenTo(domElement, 'keyup', endDocumentIsSelecting, { priority: 'highest', useCapture: true });
|
|
128
|
+
// Add document-wide listeners only once. This method could be called for multiple editing roots.
|
|
129
|
+
if (this._documents.has(domDocument)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// This listener is using capture mode to make sure that selection is upcasted before any other
|
|
133
|
+
// handler would like to check it and update (for example table multi cell selection).
|
|
134
|
+
this.listenTo(domDocument, 'mouseup', endDocumentIsSelecting, { priority: 'highest', useCapture: true });
|
|
135
|
+
this.listenTo(domDocument, 'selectionchange', (evt, domEvent) => {
|
|
136
|
+
this._handleSelectionChange(domEvent, domDocument);
|
|
137
|
+
// Defer the safety timeout when the selection changes (e.g. the user keeps extending the selection
|
|
138
|
+
// using their mouse).
|
|
139
|
+
this._documentIsSelectingInactivityTimeoutDebounced();
|
|
140
|
+
});
|
|
141
|
+
this._documents.add(domDocument);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @inheritDoc
|
|
145
|
+
*/
|
|
146
|
+
destroy() {
|
|
147
|
+
super.destroy();
|
|
148
|
+
clearInterval(this._clearInfiniteLoopInterval);
|
|
149
|
+
this._fireSelectionChangeDoneDebounced.cancel();
|
|
150
|
+
this._documentIsSelectingInactivityTimeoutDebounced.cancel();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Selection change listener. {@link module:engine/view/observer/mutationobserver~MutationObserver#flush Flush} mutations, check if
|
|
154
|
+
* a selection changes and fires {@link module:engine/view/document~Document#event:selectionChange} event on every change
|
|
155
|
+
* and {@link module:engine/view/document~Document#event:selectionChangeDone} when a selection stop changing.
|
|
156
|
+
*
|
|
157
|
+
* @private
|
|
158
|
+
* @param {Event} domEvent DOM event.
|
|
159
|
+
* @param {Document} domDocument DOM document.
|
|
160
|
+
*/
|
|
161
|
+
_handleSelectionChange(domEvent, domDocument) {
|
|
162
|
+
if (!this.isEnabled) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const domSelection = domDocument.defaultView.getSelection();
|
|
166
|
+
if (this.checkShouldIgnoreEventFromTarget(domSelection.anchorNode)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// Ensure the mutation event will be before selection event on all browsers.
|
|
170
|
+
this.mutationObserver.flush();
|
|
171
|
+
// If there were mutations then the view will be re-rendered by the mutation observer and the selection
|
|
172
|
+
// will be updated, so the selections will equal and the event will not be fired, as expected.
|
|
173
|
+
const newViewSelection = this.domConverter.domSelectionToView(domSelection);
|
|
174
|
+
// Do not convert selection change if the new view selection has no ranges in it.
|
|
175
|
+
//
|
|
176
|
+
// It means that the DOM selection is in some way incorrect. Ranges that were in the DOM selection could not be
|
|
177
|
+
// converted to the view. This happens when the DOM selection was moved outside of the editable element.
|
|
178
|
+
if (newViewSelection.rangeCount == 0) {
|
|
179
|
+
this.view.hasDomSelection = false;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.view.hasDomSelection = true;
|
|
183
|
+
if (this.selection.isEqual(newViewSelection) && this.domConverter.isDomSelectionCorrect(domSelection)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// Ensure we are not in the infinite loop (#400).
|
|
187
|
+
// This counter is reset each second. 60 selection changes in 1 second is enough high number
|
|
188
|
+
// to be very difficult (impossible) to achieve using just keyboard keys (during normal editor use).
|
|
189
|
+
if (++this._loopbackCounter > 60) {
|
|
190
|
+
// Selection change observer detected an infinite rendering loop.
|
|
191
|
+
// Most probably you try to put the selection in the position which is not allowed
|
|
192
|
+
// by the browser and browser fixes it automatically what causes `selectionchange` event on
|
|
193
|
+
// which a loopback through a model tries to re-render the wrong selection and again.
|
|
194
|
+
//
|
|
195
|
+
// @if CK_DEBUG // console.warn( 'Selection change observer detected an infinite rendering loop.' );
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (this.selection.isSimilar(newViewSelection)) {
|
|
199
|
+
// If selection was equal and we are at this point of algorithm, it means that it was incorrect.
|
|
200
|
+
// Just re-render it, no need to fire any events, etc.
|
|
201
|
+
this.view.forceRender();
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const data = {
|
|
205
|
+
oldSelection: this.selection,
|
|
206
|
+
newSelection: newViewSelection,
|
|
207
|
+
domSelection: domSelection
|
|
208
|
+
};
|
|
209
|
+
// Prepare data for new selection and fire appropriate events.
|
|
210
|
+
this.document.fire('selectionChange', data);
|
|
211
|
+
// Call `#_fireSelectionChangeDoneDebounced` every time when `selectionChange` event is fired.
|
|
212
|
+
// This function is debounced what means that `selectionChangeDone` event will be fired only when
|
|
213
|
+
// defined int the function time will elapse since the last time the function was called.
|
|
214
|
+
// So `selectionChangeDone` will be fired when selection will stop changing.
|
|
215
|
+
this._fireSelectionChangeDoneDebounced(data);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Clears `SelectionObserver` internal properties connected with preventing infinite loop.
|
|
220
|
+
*
|
|
221
|
+
* @protected
|
|
222
|
+
*/
|
|
223
|
+
_clearInfiniteLoop() {
|
|
224
|
+
this._loopbackCounter = 0;
|
|
225
|
+
}
|
|
254
226
|
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Fired when a selection has changed. This event is fired only when the selection change was the only change that happened
|
|
258
|
-
* in the document, and the old selection is different then the new selection.
|
|
259
|
-
*
|
|
260
|
-
* Introduced by {@link module:engine/view/observer/selectionobserver~SelectionObserver}.
|
|
261
|
-
*
|
|
262
|
-
* Note that because {@link module:engine/view/observer/selectionobserver~SelectionObserver} is attached by the
|
|
263
|
-
* {@link module:engine/view/view~View} this event is available by default.
|
|
264
|
-
*
|
|
265
|
-
* @see module:engine/view/observer/selectionobserver~SelectionObserver
|
|
266
|
-
* @event module:engine/view/document~Document#event:selectionChange
|
|
267
|
-
* @param {Object} data
|
|
268
|
-
* @param {module:engine/view/documentselection~DocumentSelection} data.oldSelection Old View selection which is
|
|
269
|
-
* {@link module:engine/view/document~Document#selection}.
|
|
270
|
-
* @param {module:engine/view/selection~Selection} data.newSelection New View selection which is converted DOM selection.
|
|
271
|
-
* @param {Selection} data.domSelection Native DOM selection.
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
227
|
/**
|
|
275
228
|
* Fired when selection stops changing.
|
|
276
229
|
*
|
|
@@ -2,16 +2,12 @@
|
|
|
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/view/observer/tabobserver
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Observer from './observer';
|
|
11
9
|
import BubblingEventInfo from './bubblingeventinfo';
|
|
12
|
-
|
|
13
10
|
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
|
|
14
|
-
|
|
15
11
|
/**
|
|
16
12
|
* Tab observer introduces the {@link module:engine/view/document~Document#event:tab `Document#tab`} event.
|
|
17
13
|
*
|
|
@@ -21,39 +17,30 @@ import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
|
|
|
21
17
|
* @extends module:engine/view/observer/observer~Observer
|
|
22
18
|
*/
|
|
23
19
|
export default class TabObserver extends Observer {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
} );
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @inheritDoc
|
|
53
|
-
*/
|
|
54
|
-
observe() {}
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
constructor(view) {
|
|
24
|
+
super(view);
|
|
25
|
+
const doc = this.document;
|
|
26
|
+
doc.on('keydown', (evt, data) => {
|
|
27
|
+
if (!this.isEnabled ||
|
|
28
|
+
data.keyCode != keyCodes.tab ||
|
|
29
|
+
data.ctrlKey) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const event = new BubblingEventInfo(doc, 'tab', doc.selection.getFirstRange());
|
|
33
|
+
doc.fire(event, data);
|
|
34
|
+
if (event.stop.called) {
|
|
35
|
+
evt.stop();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
*/
|
|
42
|
+
observe() { }
|
|
55
43
|
}
|
|
56
|
-
|
|
57
44
|
/**
|
|
58
45
|
* Event fired when the user presses a tab key.
|
|
59
46
|
*
|