@ckeditor/ckeditor5-engine 35.0.1 → 35.1.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 +175 -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 +899 -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 +654 -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 +191 -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,13 +2,10 @@
|
|
|
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/compositionobserver
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import DomEventObserver from './domeventobserver';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* {@link module:engine/view/document~Document#event:compositionstart Compositionstart},
|
|
14
11
|
* {@link module:engine/view/document~Document#event:compositionupdate compositionupdate} and
|
|
@@ -19,26 +16,21 @@ import DomEventObserver from './domeventobserver';
|
|
|
19
16
|
* @extends module:engine/view/observer/domeventobserver~DomEventObserver
|
|
20
17
|
*/
|
|
21
18
|
export default class CompositionObserver extends DomEventObserver {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
onDomEvent( domEvent ) {
|
|
38
|
-
this.fire( domEvent.type, domEvent );
|
|
39
|
-
}
|
|
19
|
+
constructor(view) {
|
|
20
|
+
super(view);
|
|
21
|
+
this.domEventType = ['compositionstart', 'compositionupdate', 'compositionend'];
|
|
22
|
+
const document = this.document;
|
|
23
|
+
document.on('compositionstart', () => {
|
|
24
|
+
document.isComposing = true;
|
|
25
|
+
});
|
|
26
|
+
document.on('compositionend', () => {
|
|
27
|
+
document.isComposing = false;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
onDomEvent(domEvent) {
|
|
31
|
+
this.fire(domEvent.type, domEvent);
|
|
32
|
+
}
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
/**
|
|
43
35
|
* Fired when composition starts inside one of the editables.
|
|
44
36
|
*
|
|
@@ -51,7 +43,6 @@ export default class CompositionObserver extends DomEventObserver {
|
|
|
51
43
|
* @event module:engine/view/document~Document#event:compositionstart
|
|
52
44
|
* @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
|
|
53
45
|
*/
|
|
54
|
-
|
|
55
46
|
/**
|
|
56
47
|
* Fired when composition is updated inside one of the editables.
|
|
57
48
|
*
|
|
@@ -64,7 +55,6 @@ export default class CompositionObserver extends DomEventObserver {
|
|
|
64
55
|
* @event module:engine/view/document~Document#event:compositionupdate
|
|
65
56
|
* @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
|
|
66
57
|
*/
|
|
67
|
-
|
|
68
58
|
/**
|
|
69
59
|
* Fired when composition ends inside one of the editables.
|
|
70
60
|
*
|
|
@@ -2,81 +2,71 @@
|
|
|
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/domeventdata
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { extend } from 'lodash-es';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Information about a DOM event in context of the {@link module:engine/view/document~Document}.
|
|
14
11
|
* It wraps the native event, which usually should not be used as the wrapper contains
|
|
15
12
|
* additional data (like key code for keyboard events).
|
|
16
13
|
*/
|
|
17
14
|
export default class DomEventData {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
* Stops native event propagation.
|
|
78
|
-
*/
|
|
79
|
-
stopPropagation() {
|
|
80
|
-
this.domEvent.stopPropagation();
|
|
81
|
-
}
|
|
15
|
+
/**
|
|
16
|
+
* @param {module:engine/view/view~View} view The instance of the view controller.
|
|
17
|
+
* @param {Event} domEvent The DOM event.
|
|
18
|
+
* @param {Object} [additionalData] Additional properties that the instance should contain.
|
|
19
|
+
*/
|
|
20
|
+
constructor(view, domEvent, additionalData) {
|
|
21
|
+
/**
|
|
22
|
+
* Instance of the view controller.
|
|
23
|
+
*
|
|
24
|
+
* @readonly
|
|
25
|
+
* @member {module:engine/view/view~View} module:engine/view/observer/observer~Observer.DomEvent#view
|
|
26
|
+
*/
|
|
27
|
+
this.view = view;
|
|
28
|
+
/**
|
|
29
|
+
* The instance of the document.
|
|
30
|
+
*
|
|
31
|
+
* @readonly
|
|
32
|
+
* @member {module:engine/view/document~Document} module:engine/view/observer/observer~Observer.DomEvent#document
|
|
33
|
+
*/
|
|
34
|
+
this.document = view.document;
|
|
35
|
+
/**
|
|
36
|
+
* The DOM event.
|
|
37
|
+
*
|
|
38
|
+
* @readonly
|
|
39
|
+
* @member {Event} module:engine/view/observer/observer~Observer.DomEvent#domEvent
|
|
40
|
+
*/
|
|
41
|
+
this.domEvent = domEvent;
|
|
42
|
+
/**
|
|
43
|
+
* The DOM target.
|
|
44
|
+
*
|
|
45
|
+
* @readonly
|
|
46
|
+
* @member {HTMLElement} module:engine/view/observer/observer~Observer.DomEvent#target
|
|
47
|
+
*/
|
|
48
|
+
this.domTarget = domEvent.target;
|
|
49
|
+
extend(this, additionalData);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The tree view element representing the target.
|
|
53
|
+
*
|
|
54
|
+
* @readonly
|
|
55
|
+
* @type module:engine/view/element~Element
|
|
56
|
+
*/
|
|
57
|
+
get target() {
|
|
58
|
+
return this.view.domConverter.mapDomToView(this.domTarget);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Prevents the native's event default action.
|
|
62
|
+
*/
|
|
63
|
+
preventDefault() {
|
|
64
|
+
this.domEvent.preventDefault();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Stops native event propagation.
|
|
68
|
+
*/
|
|
69
|
+
stopPropagation() {
|
|
70
|
+
this.domEvent.stopPropagation();
|
|
71
|
+
}
|
|
82
72
|
}
|
|
@@ -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/view/observer/domeventobserver
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Observer from './observer';
|
|
11
9
|
import DomEventData from './domeventdata';
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* Base class for DOM event observers. This class handles
|
|
15
12
|
* {@link module:engine/view/observer/observer~Observer#observe adding} listeners to DOM elements,
|
|
@@ -35,65 +32,44 @@ import DomEventData from './domeventdata';
|
|
|
35
32
|
* @extends module:engine/view/observer/observer~Observer
|
|
36
33
|
*/
|
|
37
34
|
export default class DomEventObserver extends Observer {
|
|
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
|
-
if ( this.isEnabled && !this.checkShouldIgnoreEventFromTarget( domEvent.target ) ) {
|
|
79
|
-
this.onDomEvent( domEvent );
|
|
80
|
-
}
|
|
81
|
-
}, { useCapture: this.useCapture } );
|
|
82
|
-
} );
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Calls `Document#fire()` if observer {@link #isEnabled is enabled}.
|
|
87
|
-
*
|
|
88
|
-
* @see module:utils/emittermixin~EmitterMixin#fire
|
|
89
|
-
* @param {String} eventType The event type (name).
|
|
90
|
-
* @param {Event} domEvent The DOM event.
|
|
91
|
-
* @param {Object} [additionalData] The additional data which should extend the
|
|
92
|
-
* {@link module:engine/view/observer/domeventdata~DomEventData event data} object.
|
|
93
|
-
*/
|
|
94
|
-
fire( eventType, domEvent, additionalData ) {
|
|
95
|
-
if ( this.isEnabled ) {
|
|
96
|
-
this.document.fire( eventType, new DomEventData( this.view, domEvent, additionalData ) );
|
|
97
|
-
}
|
|
98
|
-
}
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
*/
|
|
38
|
+
constructor(view) {
|
|
39
|
+
super(view);
|
|
40
|
+
/**
|
|
41
|
+
* If set to `true` DOM events will be listened on the capturing phase.
|
|
42
|
+
* Default value is `false`.
|
|
43
|
+
*
|
|
44
|
+
* @member {Boolean}
|
|
45
|
+
*/
|
|
46
|
+
this.useCapture = false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @inheritDoc
|
|
50
|
+
*/
|
|
51
|
+
observe(domElement) {
|
|
52
|
+
const types = typeof this.domEventType == 'string' ? [this.domEventType] : this.domEventType;
|
|
53
|
+
types.forEach(type => {
|
|
54
|
+
this.listenTo(domElement, type, (eventInfo, domEvent) => {
|
|
55
|
+
if (this.isEnabled && !this.checkShouldIgnoreEventFromTarget(domEvent.target)) {
|
|
56
|
+
this.onDomEvent(domEvent);
|
|
57
|
+
}
|
|
58
|
+
}, { useCapture: this.useCapture });
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Calls `Document#fire()` if observer {@link #isEnabled is enabled}.
|
|
63
|
+
*
|
|
64
|
+
* @see module:utils/emittermixin~EmitterMixin#fire
|
|
65
|
+
* @param {String} eventType The event type (name).
|
|
66
|
+
* @param {Event} domEvent The DOM event.
|
|
67
|
+
* @param {Object} [additionalData] The additional data which should extend the
|
|
68
|
+
* {@link module:engine/view/observer/domeventdata~DomEventData event data} object.
|
|
69
|
+
*/
|
|
70
|
+
fire(eventType, domEvent, additionalData) {
|
|
71
|
+
if (this.isEnabled) {
|
|
72
|
+
this.document.fire(eventType, new DomEventData(this.view, domEvent, additionalData));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
99
75
|
}
|
|
@@ -2,16 +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/fakeselectionobserver
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Observer from './observer';
|
|
11
9
|
import ViewSelection from '../selection';
|
|
12
10
|
import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
|
|
13
11
|
import { debounce } from 'lodash-es';
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* Fake selection observer class. If view selection is fake it is placed in dummy DOM container. This observer listens
|
|
17
14
|
* on {@link module:engine/view/document~Document#event:keydown keydown} events and handles moving fake view selection to the correct place
|
|
@@ -22,97 +19,85 @@ import { debounce } from 'lodash-es';
|
|
|
22
19
|
* @extends module:engine/view/observer/observer~Observer
|
|
23
20
|
*/
|
|
24
21
|
export default class FakeSelectionObserver extends Observer {
|
|
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
|
-
|
|
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
|
-
domSelection: null
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// Fire dummy selection change event.
|
|
110
|
-
this.document.fire( 'selectionChange', data );
|
|
111
|
-
|
|
112
|
-
// Call` #_fireSelectionChangeDoneDebounced` every time when `selectionChange` event is fired.
|
|
113
|
-
// This function is debounced what means that `selectionChangeDone` event will be fired only when
|
|
114
|
-
// defined int the function time will elapse since the last time the function was called.
|
|
115
|
-
// So `selectionChangeDone` will be fired when selection will stop changing.
|
|
116
|
-
this._fireSelectionChangeDoneDebounced( data );
|
|
117
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates new FakeSelectionObserver instance.
|
|
24
|
+
*
|
|
25
|
+
* @param {module:engine/view/view~View} view
|
|
26
|
+
*/
|
|
27
|
+
constructor(view) {
|
|
28
|
+
super(view);
|
|
29
|
+
/**
|
|
30
|
+
* Fires debounced event `selectionChangeDone`. It uses `lodash#debounce` method to delay function call.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
* @param {Object} data Selection change data.
|
|
34
|
+
* @method #_fireSelectionChangeDoneDebounced
|
|
35
|
+
*/
|
|
36
|
+
this._fireSelectionChangeDoneDebounced = debounce(data => {
|
|
37
|
+
this.document.fire('selectionChangeDone', data);
|
|
38
|
+
}, 200);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
observe() {
|
|
44
|
+
const document = this.document;
|
|
45
|
+
document.on('arrowKey', (eventInfo, data) => {
|
|
46
|
+
const selection = document.selection;
|
|
47
|
+
if (selection.isFake && this.isEnabled) {
|
|
48
|
+
// Prevents default key down handling - no selection change will occur.
|
|
49
|
+
data.preventDefault();
|
|
50
|
+
}
|
|
51
|
+
}, { context: '$capture' });
|
|
52
|
+
document.on('arrowKey', (eventInfo, data) => {
|
|
53
|
+
const selection = document.selection;
|
|
54
|
+
if (selection.isFake && this.isEnabled) {
|
|
55
|
+
this._handleSelectionMove(data.keyCode);
|
|
56
|
+
}
|
|
57
|
+
}, { priority: 'lowest' });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @inheritDoc
|
|
61
|
+
*/
|
|
62
|
+
destroy() {
|
|
63
|
+
super.destroy();
|
|
64
|
+
this._fireSelectionChangeDoneDebounced.cancel();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Handles collapsing view selection according to given key code. If left or up key is provided - new selection will be
|
|
68
|
+
* collapsed to left. If right or down key is pressed - new selection will be collapsed to right.
|
|
69
|
+
*
|
|
70
|
+
* This method fires {@link module:engine/view/document~Document#event:selectionChange} and
|
|
71
|
+
* {@link module:engine/view/document~Document#event:selectionChangeDone} events imitating behaviour of
|
|
72
|
+
* {@link module:engine/view/observer/selectionobserver~SelectionObserver}.
|
|
73
|
+
*
|
|
74
|
+
* @private
|
|
75
|
+
* @param {Number} keyCode
|
|
76
|
+
* @fires module:engine/view/document~Document#event:selectionChange
|
|
77
|
+
* @fires module:engine/view/document~Document#event:selectionChangeDone
|
|
78
|
+
*/
|
|
79
|
+
_handleSelectionMove(keyCode) {
|
|
80
|
+
const selection = this.document.selection;
|
|
81
|
+
const newSelection = new ViewSelection(selection.getRanges(), { backward: selection.isBackward, fake: false });
|
|
82
|
+
// Left or up arrow pressed - move selection to start.
|
|
83
|
+
if (keyCode == keyCodes.arrowleft || keyCode == keyCodes.arrowup) {
|
|
84
|
+
newSelection.setTo(newSelection.getFirstPosition());
|
|
85
|
+
}
|
|
86
|
+
// Right or down arrow pressed - move selection to end.
|
|
87
|
+
if (keyCode == keyCodes.arrowright || keyCode == keyCodes.arrowdown) {
|
|
88
|
+
newSelection.setTo(newSelection.getLastPosition());
|
|
89
|
+
}
|
|
90
|
+
const data = {
|
|
91
|
+
oldSelection: selection,
|
|
92
|
+
newSelection,
|
|
93
|
+
domSelection: null
|
|
94
|
+
};
|
|
95
|
+
// Fire dummy selection change event.
|
|
96
|
+
this.document.fire('selectionChange', data);
|
|
97
|
+
// Call` #_fireSelectionChangeDoneDebounced` every time when `selectionChange` event is fired.
|
|
98
|
+
// This function is debounced what means that `selectionChangeDone` event will be fired only when
|
|
99
|
+
// defined int the function time will elapse since the last time the function was called.
|
|
100
|
+
// So `selectionChangeDone` will be fired when selection will stop changing.
|
|
101
|
+
this._fireSelectionChangeDoneDebounced(data);
|
|
102
|
+
}
|
|
118
103
|
}
|