@ckeditor/ckeditor5-engine 47.6.1 → 48.0.0-alpha.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/{src → dist}/engineconfig.d.ts +6 -15
- package/dist/index-editor.css +38 -15
- package/dist/index.css +37 -37
- package/dist/index.css.map +1 -1
- package/{src → dist}/index.d.ts +0 -1
- package/dist/index.js +588 -94
- package/dist/index.js.map +1 -1
- package/{src → dist}/model/model.d.ts +10 -4
- package/{src → dist}/model/selection.d.ts +1 -1
- package/{src → dist}/view/downcastwriter.d.ts +3 -2
- package/{src → dist}/view/element.d.ts +2 -2
- package/{src → dist}/view/matcher.d.ts +4 -2
- package/dist/view/styles/background.d.ts +18 -0
- package/{src → dist}/view/styles/border.d.ts +0 -12
- package/{src → dist}/view/styles/margin.d.ts +0 -13
- package/{src → dist}/view/styles/padding.d.ts +0 -13
- package/{src → dist}/view/styles/utils.d.ts +12 -0
- package/package.json +20 -39
- package/src/controller/datacontroller.js +0 -522
- package/src/controller/editingcontroller.js +0 -181
- package/src/conversion/conversion.js +0 -606
- package/src/conversion/conversionhelpers.js +0 -33
- package/src/conversion/downcastdispatcher.js +0 -563
- package/src/conversion/downcasthelpers.js +0 -2160
- package/src/conversion/mapper.js +0 -1050
- package/src/conversion/modelconsumable.js +0 -331
- package/src/conversion/upcastdispatcher.js +0 -470
- package/src/conversion/upcasthelpers.js +0 -952
- package/src/conversion/viewconsumable.js +0 -541
- package/src/dataprocessor/basichtmlwriter.js +0 -22
- package/src/dataprocessor/dataprocessor.js +0 -5
- package/src/dataprocessor/htmldataprocessor.js +0 -107
- package/src/dataprocessor/htmlwriter.js +0 -5
- package/src/dataprocessor/xmldataprocessor.js +0 -127
- package/src/dev-utils/model.js +0 -396
- package/src/dev-utils/operationreplayer.js +0 -116
- package/src/dev-utils/utils.js +0 -122
- package/src/dev-utils/view.js +0 -990
- package/src/engineconfig.js +0 -5
- package/src/index.js +0 -134
- package/src/legacyerrors.js +0 -17
- package/src/model/batch.js +0 -98
- package/src/model/differ.js +0 -1288
- package/src/model/document.js +0 -398
- package/src/model/documentfragment.js +0 -332
- package/src/model/documentselection.js +0 -1026
- package/src/model/element.js +0 -323
- package/src/model/history.js +0 -206
- package/src/model/item.js +0 -5
- package/src/model/liveposition.js +0 -93
- package/src/model/liverange.js +0 -121
- package/src/model/markercollection.js +0 -436
- package/src/model/model.js +0 -866
- package/src/model/node.js +0 -371
- package/src/model/nodelist.js +0 -244
- package/src/model/operation/attributeoperation.js +0 -172
- package/src/model/operation/detachoperation.js +0 -87
- package/src/model/operation/insertoperation.js +0 -153
- package/src/model/operation/markeroperation.js +0 -136
- package/src/model/operation/mergeoperation.js +0 -184
- package/src/model/operation/moveoperation.js +0 -179
- package/src/model/operation/nooperation.js +0 -48
- package/src/model/operation/operation.js +0 -78
- package/src/model/operation/operationfactory.js +0 -44
- package/src/model/operation/renameoperation.js +0 -128
- package/src/model/operation/rootattributeoperation.js +0 -173
- package/src/model/operation/rootoperation.js +0 -106
- package/src/model/operation/splitoperation.js +0 -214
- package/src/model/operation/transform.js +0 -2211
- package/src/model/operation/utils.js +0 -217
- package/src/model/position.js +0 -1041
- package/src/model/range.js +0 -880
- package/src/model/rootelement.js +0 -82
- package/src/model/schema.js +0 -1542
- package/src/model/selection.js +0 -814
- package/src/model/text.js +0 -92
- package/src/model/textproxy.js +0 -202
- package/src/model/treewalker.js +0 -313
- package/src/model/typecheckable.js +0 -16
- package/src/model/utils/autoparagraphing.js +0 -63
- package/src/model/utils/deletecontent.js +0 -509
- package/src/model/utils/getselectedcontent.js +0 -126
- package/src/model/utils/insertcontent.js +0 -750
- package/src/model/utils/insertobject.js +0 -135
- package/src/model/utils/modifyselection.js +0 -187
- package/src/model/utils/selection-post-fixer.js +0 -264
- package/src/model/writer.js +0 -1318
- package/src/view/attributeelement.js +0 -220
- package/src/view/containerelement.js +0 -91
- package/src/view/datatransfer.js +0 -106
- package/src/view/document.js +0 -139
- package/src/view/documentfragment.js +0 -251
- package/src/view/documentselection.js +0 -270
- package/src/view/domconverter.js +0 -1661
- package/src/view/downcastwriter.js +0 -1589
- package/src/view/editableelement.js +0 -74
- package/src/view/element.js +0 -1053
- package/src/view/elementdefinition.js +0 -5
- package/src/view/emptyelement.js +0 -83
- package/src/view/filler.js +0 -161
- package/src/view/item.js +0 -5
- package/src/view/matcher.js +0 -437
- package/src/view/node.js +0 -238
- package/src/view/observer/arrowkeysobserver.js +0 -40
- package/src/view/observer/bubblingemittermixin.js +0 -215
- package/src/view/observer/bubblingeventinfo.js +0 -49
- package/src/view/observer/clickobserver.js +0 -26
- package/src/view/observer/compositionobserver.js +0 -64
- package/src/view/observer/domeventdata.js +0 -63
- package/src/view/observer/domeventobserver.js +0 -81
- package/src/view/observer/fakeselectionobserver.js +0 -95
- package/src/view/observer/focusobserver.js +0 -166
- package/src/view/observer/inputobserver.js +0 -236
- package/src/view/observer/keyobserver.js +0 -36
- package/src/view/observer/mouseobserver.js +0 -26
- package/src/view/observer/mutationobserver.js +0 -219
- package/src/view/observer/observer.js +0 -92
- package/src/view/observer/pointerobserver.js +0 -26
- package/src/view/observer/selectionobserver.js +0 -318
- package/src/view/observer/tabobserver.js +0 -42
- package/src/view/observer/touchobserver.js +0 -26
- package/src/view/placeholder.js +0 -285
- package/src/view/position.js +0 -341
- package/src/view/range.js +0 -451
- package/src/view/rawelement.js +0 -115
- package/src/view/renderer.js +0 -1148
- package/src/view/rooteditableelement.js +0 -78
- package/src/view/selection.js +0 -594
- package/src/view/styles/background.d.ts +0 -33
- package/src/view/styles/background.js +0 -74
- package/src/view/styles/border.js +0 -316
- package/src/view/styles/margin.js +0 -34
- package/src/view/styles/padding.js +0 -34
- package/src/view/styles/utils.js +0 -219
- package/src/view/stylesmap.js +0 -941
- package/src/view/text.js +0 -110
- package/src/view/textproxy.js +0 -136
- package/src/view/tokenlist.js +0 -194
- package/src/view/treewalker.js +0 -389
- package/src/view/typecheckable.js +0 -19
- package/src/view/uielement.js +0 -194
- package/src/view/upcastwriter.js +0 -363
- package/src/view/view.js +0 -579
- package/theme/placeholder.css +0 -36
- package/theme/renderer.css +0 -9
- /package/{src → dist}/controller/datacontroller.d.ts +0 -0
- /package/{src → dist}/controller/editingcontroller.d.ts +0 -0
- /package/{src → dist}/conversion/conversion.d.ts +0 -0
- /package/{src → dist}/conversion/conversionhelpers.d.ts +0 -0
- /package/{src → dist}/conversion/downcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/downcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/mapper.d.ts +0 -0
- /package/{src → dist}/conversion/modelconsumable.d.ts +0 -0
- /package/{src → dist}/conversion/upcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/upcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/viewconsumable.d.ts +0 -0
- /package/{src → dist}/dataprocessor/basichtmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/dataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/xmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dev-utils/model.d.ts +0 -0
- /package/{src → dist}/dev-utils/operationreplayer.d.ts +0 -0
- /package/{src → dist}/dev-utils/utils.d.ts +0 -0
- /package/{src → dist}/dev-utils/view.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/model/batch.d.ts +0 -0
- /package/{src → dist}/model/differ.d.ts +0 -0
- /package/{src → dist}/model/document.d.ts +0 -0
- /package/{src → dist}/model/documentfragment.d.ts +0 -0
- /package/{src → dist}/model/documentselection.d.ts +0 -0
- /package/{src → dist}/model/element.d.ts +0 -0
- /package/{src → dist}/model/history.d.ts +0 -0
- /package/{src → dist}/model/item.d.ts +0 -0
- /package/{src → dist}/model/liveposition.d.ts +0 -0
- /package/{src → dist}/model/liverange.d.ts +0 -0
- /package/{src → dist}/model/markercollection.d.ts +0 -0
- /package/{src → dist}/model/node.d.ts +0 -0
- /package/{src → dist}/model/nodelist.d.ts +0 -0
- /package/{src → dist}/model/operation/attributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/detachoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/insertoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/markeroperation.d.ts +0 -0
- /package/{src → dist}/model/operation/mergeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/moveoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/nooperation.d.ts +0 -0
- /package/{src → dist}/model/operation/operation.d.ts +0 -0
- /package/{src → dist}/model/operation/operationfactory.d.ts +0 -0
- /package/{src → dist}/model/operation/renameoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootattributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/splitoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/transform.d.ts +0 -0
- /package/{src → dist}/model/operation/utils.d.ts +0 -0
- /package/{src → dist}/model/position.d.ts +0 -0
- /package/{src → dist}/model/range.d.ts +0 -0
- /package/{src → dist}/model/rootelement.d.ts +0 -0
- /package/{src → dist}/model/schema.d.ts +0 -0
- /package/{src → dist}/model/text.d.ts +0 -0
- /package/{src → dist}/model/textproxy.d.ts +0 -0
- /package/{src → dist}/model/treewalker.d.ts +0 -0
- /package/{src → dist}/model/typecheckable.d.ts +0 -0
- /package/{src → dist}/model/utils/autoparagraphing.d.ts +0 -0
- /package/{src → dist}/model/utils/deletecontent.d.ts +0 -0
- /package/{src → dist}/model/utils/getselectedcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertobject.d.ts +0 -0
- /package/{src → dist}/model/utils/modifyselection.d.ts +0 -0
- /package/{src → dist}/model/utils/selection-post-fixer.d.ts +0 -0
- /package/{src → dist}/model/writer.d.ts +0 -0
- /package/{src → dist}/view/attributeelement.d.ts +0 -0
- /package/{src → dist}/view/containerelement.d.ts +0 -0
- /package/{src → dist}/view/datatransfer.d.ts +0 -0
- /package/{src → dist}/view/document.d.ts +0 -0
- /package/{src → dist}/view/documentfragment.d.ts +0 -0
- /package/{src → dist}/view/documentselection.d.ts +0 -0
- /package/{src → dist}/view/domconverter.d.ts +0 -0
- /package/{src → dist}/view/editableelement.d.ts +0 -0
- /package/{src → dist}/view/elementdefinition.d.ts +0 -0
- /package/{src → dist}/view/emptyelement.d.ts +0 -0
- /package/{src → dist}/view/filler.d.ts +0 -0
- /package/{src → dist}/view/item.d.ts +0 -0
- /package/{src → dist}/view/node.d.ts +0 -0
- /package/{src → dist}/view/observer/arrowkeysobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingemittermixin.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingeventinfo.d.ts +0 -0
- /package/{src → dist}/view/observer/clickobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/compositionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventdata.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/fakeselectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/focusobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/inputobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/keyobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mouseobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mutationobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/observer.d.ts +0 -0
- /package/{src → dist}/view/observer/pointerobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/selectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/tabobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/touchobserver.d.ts +0 -0
- /package/{src → dist}/view/placeholder.d.ts +0 -0
- /package/{src → dist}/view/position.d.ts +0 -0
- /package/{src → dist}/view/range.d.ts +0 -0
- /package/{src → dist}/view/rawelement.d.ts +0 -0
- /package/{src → dist}/view/renderer.d.ts +0 -0
- /package/{src → dist}/view/rooteditableelement.d.ts +0 -0
- /package/{src → dist}/view/selection.d.ts +0 -0
- /package/{src → dist}/view/stylesmap.d.ts +0 -0
- /package/{src → dist}/view/text.d.ts +0 -0
- /package/{src → dist}/view/textproxy.d.ts +0 -0
- /package/{src → dist}/view/tokenlist.d.ts +0 -0
- /package/{src → dist}/view/treewalker.d.ts +0 -0
- /package/{src → dist}/view/typecheckable.d.ts +0 -0
- /package/{src → dist}/view/uielement.d.ts +0 -0
- /package/{src → dist}/view/upcastwriter.d.ts +0 -0
- /package/{src → dist}/view/view.d.ts +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/view/rooteditableelement
|
|
7
|
-
*/
|
|
8
|
-
import { ViewEditableElement } from './editableelement.js';
|
|
9
|
-
const rootNameSymbol = Symbol('rootName');
|
|
10
|
-
/**
|
|
11
|
-
* Class representing a single root in the data view. A root can be either
|
|
12
|
-
* {@link ~ViewRootEditableElement#isReadOnly editable or read-only},
|
|
13
|
-
* but in both cases it is called "an editable". Roots can contain other {@link module:engine/view/editableelement~ViewEditableElement
|
|
14
|
-
* editable elements} making them "nested editables".
|
|
15
|
-
*/
|
|
16
|
-
export class ViewRootEditableElement extends ViewEditableElement {
|
|
17
|
-
/**
|
|
18
|
-
* Creates root editable element.
|
|
19
|
-
*
|
|
20
|
-
* @param document The document instance to which this element belongs.
|
|
21
|
-
* @param name Node name.
|
|
22
|
-
*/
|
|
23
|
-
constructor(document, name) {
|
|
24
|
-
super(document, name);
|
|
25
|
-
this.rootName = 'main';
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Name of this root inside {@link module:engine/view/document~ViewDocument} that is an owner of this root. If no
|
|
29
|
-
* other name is set, `main` name is used.
|
|
30
|
-
*
|
|
31
|
-
* @readonly
|
|
32
|
-
*/
|
|
33
|
-
get rootName() {
|
|
34
|
-
return this.getCustomProperty(rootNameSymbol);
|
|
35
|
-
}
|
|
36
|
-
set rootName(rootName) {
|
|
37
|
-
this._setCustomProperty(rootNameSymbol, rootName);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Converts `ViewRootEditableElement` instance to string and returns it.
|
|
41
|
-
*
|
|
42
|
-
* @returns `ViewRootEditableElement` instance converted to string.
|
|
43
|
-
*/
|
|
44
|
-
toJSON() {
|
|
45
|
-
return this.rootName;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Overrides old element name and sets new one.
|
|
49
|
-
* This is needed because view roots are created before they are attached to the DOM.
|
|
50
|
-
* The name of the root element is temporary at this stage. It has to be changed when the
|
|
51
|
-
* view root element is attached to the DOM element.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
* @param name The new name of element.
|
|
55
|
-
*/
|
|
56
|
-
set _name(name) {
|
|
57
|
-
this.name = name;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
61
|
-
// Proper overload would interfere with that.
|
|
62
|
-
ViewRootEditableElement.prototype.is = function (type, name) {
|
|
63
|
-
if (!name) {
|
|
64
|
-
return type === 'rootElement' || type === 'view:rootElement' ||
|
|
65
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
66
|
-
type === 'editableElement' || type === 'view:editableElement' ||
|
|
67
|
-
type === 'containerElement' || type === 'view:containerElement' ||
|
|
68
|
-
type === 'element' || type === 'view:element' ||
|
|
69
|
-
type === 'node' || type === 'view:node';
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return name === this.name && (type === 'rootElement' || type === 'view:rootElement' ||
|
|
73
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
74
|
-
type === 'editableElement' || type === 'view:editableElement' ||
|
|
75
|
-
type === 'containerElement' || type === 'view:containerElement' ||
|
|
76
|
-
type === 'element' || type === 'view:element');
|
|
77
|
-
}
|
|
78
|
-
};
|
package/src/view/selection.js
DELETED
|
@@ -1,594 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/view/selection
|
|
7
|
-
*/
|
|
8
|
-
import { ViewTypeCheckable } from './typecheckable.js';
|
|
9
|
-
import { ViewRange } from './range.js';
|
|
10
|
-
import { ViewPosition } from './position.js';
|
|
11
|
-
import { ViewNode } from './node.js';
|
|
12
|
-
import { ViewDocumentSelection } from './documentselection.js';
|
|
13
|
-
import { CKEditorError, EmitterMixin, count, isIterable } from '@ckeditor/ckeditor5-utils';
|
|
14
|
-
/**
|
|
15
|
-
* Class representing an arbirtary selection in the view.
|
|
16
|
-
* See also {@link module:engine/view/documentselection~ViewDocumentSelection}.
|
|
17
|
-
*
|
|
18
|
-
* New selection instances can be created via the constructor or one these methods:
|
|
19
|
-
*
|
|
20
|
-
* * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
|
|
21
|
-
* * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
|
|
22
|
-
*
|
|
23
|
-
* A selection can consist of {@link module:engine/view/range~ViewRange ranges} that can be set by using
|
|
24
|
-
* the {@link module:engine/view/selection~ViewSelection#setTo `Selection#setTo()`} method.
|
|
25
|
-
*/
|
|
26
|
-
export class ViewSelection extends /* #__PURE__ */ EmitterMixin(ViewTypeCheckable) {
|
|
27
|
-
/**
|
|
28
|
-
* Stores all ranges that are selected.
|
|
29
|
-
*/
|
|
30
|
-
_ranges;
|
|
31
|
-
/**
|
|
32
|
-
* Specifies whether the last added range was added as a backward or forward range.
|
|
33
|
-
*/
|
|
34
|
-
_lastRangeBackward;
|
|
35
|
-
/**
|
|
36
|
-
* Specifies whether selection instance is fake.
|
|
37
|
-
*/
|
|
38
|
-
_isFake;
|
|
39
|
-
/**
|
|
40
|
-
* Fake selection's label.
|
|
41
|
-
*/
|
|
42
|
-
_fakeSelectionLabel;
|
|
43
|
-
/**
|
|
44
|
-
* Creates new selection instance.
|
|
45
|
-
*
|
|
46
|
-
* **Note**: The selection constructor is available as a factory method:
|
|
47
|
-
*
|
|
48
|
-
* * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
|
|
49
|
-
* * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
|
|
50
|
-
*
|
|
51
|
-
* ```ts
|
|
52
|
-
* // Creates empty selection without ranges.
|
|
53
|
-
* const selection = writer.createSelection();
|
|
54
|
-
*
|
|
55
|
-
* // Creates selection at the given range.
|
|
56
|
-
* const range = writer.createRange( start, end );
|
|
57
|
-
* const selection = writer.createSelection( range );
|
|
58
|
-
*
|
|
59
|
-
* // Creates selection at the given ranges
|
|
60
|
-
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
|
|
61
|
-
* const selection = writer.createSelection( ranges );
|
|
62
|
-
*
|
|
63
|
-
* // Creates selection from the other selection.
|
|
64
|
-
* const otherSelection = writer.createSelection();
|
|
65
|
-
* const selection = writer.createSelection( otherSelection );
|
|
66
|
-
*
|
|
67
|
-
* // Creates selection from the document selection.
|
|
68
|
-
* const selection = writer.createSelection( editor.editing.view.document.selection );
|
|
69
|
-
*
|
|
70
|
-
* // Creates selection at the given position.
|
|
71
|
-
* const position = writer.createPositionFromPath( root, path );
|
|
72
|
-
* const selection = writer.createSelection( position );
|
|
73
|
-
*
|
|
74
|
-
* // Creates collapsed selection at the position of given item and offset.
|
|
75
|
-
* const paragraph = writer.createContainerElement( 'paragraph' );
|
|
76
|
-
* const selection = writer.createSelection( paragraph, offset );
|
|
77
|
-
*
|
|
78
|
-
* // Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the
|
|
79
|
-
* // first child of that element and ends after the last child of that element.
|
|
80
|
-
* const selection = writer.createSelection( paragraph, 'in' );
|
|
81
|
-
*
|
|
82
|
-
* // Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends
|
|
83
|
-
* // just after the item.
|
|
84
|
-
* const selection = writer.createSelection( paragraph, 'on' );
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
88
|
-
*
|
|
89
|
-
* ```ts
|
|
90
|
-
* // Creates backward selection.
|
|
91
|
-
* const selection = writer.createSelection( range, { backward: true } );
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
95
|
-
* This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
96
|
-
* represented in other way, for example by applying proper CSS class.
|
|
97
|
-
*
|
|
98
|
-
* Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
99
|
-
* (and be properly handled by screen readers).
|
|
100
|
-
*
|
|
101
|
-
* ```ts
|
|
102
|
-
* // Creates fake selection with label.
|
|
103
|
-
* const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
|
|
104
|
-
* ```
|
|
105
|
-
*
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
|
-
constructor(...args) {
|
|
109
|
-
super();
|
|
110
|
-
this._ranges = [];
|
|
111
|
-
this._lastRangeBackward = false;
|
|
112
|
-
this._isFake = false;
|
|
113
|
-
this._fakeSelectionLabel = '';
|
|
114
|
-
if (args.length) {
|
|
115
|
-
this.setTo(...args);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Returns true if selection instance is marked as `fake`.
|
|
120
|
-
*
|
|
121
|
-
* @see #setTo
|
|
122
|
-
*/
|
|
123
|
-
get isFake() {
|
|
124
|
-
return this._isFake;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Returns fake selection label.
|
|
128
|
-
*
|
|
129
|
-
* @see #setTo
|
|
130
|
-
*/
|
|
131
|
-
get fakeSelectionLabel() {
|
|
132
|
-
return this._fakeSelectionLabel;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Selection anchor. Anchor may be described as a position where the selection starts. Together with
|
|
136
|
-
* {@link #focus focus} they define the direction of selection, which is important
|
|
137
|
-
* when expanding/shrinking selection. Anchor is always the start or end of the most recent added range.
|
|
138
|
-
* It may be a bit unintuitive when there are multiple ranges in selection.
|
|
139
|
-
*
|
|
140
|
-
* @see #focus
|
|
141
|
-
*/
|
|
142
|
-
get anchor() {
|
|
143
|
-
if (!this._ranges.length) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
const range = this._ranges[this._ranges.length - 1];
|
|
147
|
-
const anchor = this._lastRangeBackward ? range.end : range.start;
|
|
148
|
-
return anchor.clone();
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Selection focus. Focus is a position where the selection ends.
|
|
152
|
-
*
|
|
153
|
-
* @see #anchor
|
|
154
|
-
*/
|
|
155
|
-
get focus() {
|
|
156
|
-
if (!this._ranges.length) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
const range = this._ranges[this._ranges.length - 1];
|
|
160
|
-
const focus = this._lastRangeBackward ? range.start : range.end;
|
|
161
|
-
return focus.clone();
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Returns whether the selection is collapsed. Selection is collapsed when there is exactly one range which is
|
|
165
|
-
* collapsed.
|
|
166
|
-
*/
|
|
167
|
-
get isCollapsed() {
|
|
168
|
-
return this.rangeCount === 1 && this._ranges[0].isCollapsed;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Returns number of ranges in selection.
|
|
172
|
-
*/
|
|
173
|
-
get rangeCount() {
|
|
174
|
-
return this._ranges.length;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Specifies whether the {@link #focus} precedes {@link #anchor}.
|
|
178
|
-
*/
|
|
179
|
-
get isBackward() {
|
|
180
|
-
return !this.isCollapsed && this._lastRangeBackward;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* {@link module:engine/view/editableelement~ViewEditableElement ViewEditableElement} instance that contains this selection, or `null`
|
|
184
|
-
* if the selection is not inside an editable element.
|
|
185
|
-
*/
|
|
186
|
-
get editableElement() {
|
|
187
|
-
if (this.anchor) {
|
|
188
|
-
return this.anchor.editableElement;
|
|
189
|
-
}
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Returns an iterable that contains copies of all ranges added to the selection.
|
|
194
|
-
*/
|
|
195
|
-
*getRanges() {
|
|
196
|
-
for (const range of this._ranges) {
|
|
197
|
-
yield range.clone();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Returns copy of the first range in the selection. First range is the one which
|
|
202
|
-
* {@link module:engine/view/range~ViewRange#start start} position
|
|
203
|
-
* {@link module:engine/view/position~ViewPosition#isBefore is before} start
|
|
204
|
-
* position of all other ranges (not to confuse with the first range added to the selection).
|
|
205
|
-
* Returns `null` if no ranges are added to selection.
|
|
206
|
-
*/
|
|
207
|
-
getFirstRange() {
|
|
208
|
-
let first = null;
|
|
209
|
-
for (const range of this._ranges) {
|
|
210
|
-
if (!first || range.start.isBefore(first.start)) {
|
|
211
|
-
first = range;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return first ? first.clone() : null;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Returns copy of the last range in the selection. Last range is the one which {@link module:engine/view/range~ViewRange#end end}
|
|
218
|
-
* position {@link module:engine/view/position~ViewPosition#isAfter is after} end position of all other ranges (not to confuse
|
|
219
|
-
* with the last range added to the selection). Returns `null` if no ranges are added to selection.
|
|
220
|
-
*/
|
|
221
|
-
getLastRange() {
|
|
222
|
-
let last = null;
|
|
223
|
-
for (const range of this._ranges) {
|
|
224
|
-
if (!last || range.end.isAfter(last.end)) {
|
|
225
|
-
last = range;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return last ? last.clone() : null;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Returns copy of the first position in the selection. First position is the position that
|
|
232
|
-
* {@link module:engine/view/position~ViewPosition#isBefore is before} any other position in the selection ranges.
|
|
233
|
-
* Returns `null` if no ranges are added to selection.
|
|
234
|
-
*/
|
|
235
|
-
getFirstPosition() {
|
|
236
|
-
const firstRange = this.getFirstRange();
|
|
237
|
-
return firstRange ? firstRange.start.clone() : null;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Returns copy of the last position in the selection. Last position is the position that
|
|
241
|
-
* {@link module:engine/view/position~ViewPosition#isAfter is after} any other position in the selection ranges.
|
|
242
|
-
* Returns `null` if no ranges are added to selection.
|
|
243
|
-
*/
|
|
244
|
-
getLastPosition() {
|
|
245
|
-
const lastRange = this.getLastRange();
|
|
246
|
-
return lastRange ? lastRange.end.clone() : null;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Checks whether, this selection is equal to given selection. Selections are equal if they have same directions,
|
|
250
|
-
* same number of ranges and all ranges from one selection equal to a range from other selection.
|
|
251
|
-
*
|
|
252
|
-
* @param otherSelection Selection to compare with.
|
|
253
|
-
* @returns `true` if selections are equal, `false` otherwise.
|
|
254
|
-
*/
|
|
255
|
-
isEqual(otherSelection) {
|
|
256
|
-
if (this.isFake != otherSelection.isFake) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
if (this.isFake && this.fakeSelectionLabel != otherSelection.fakeSelectionLabel) {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
if (this.rangeCount != otherSelection.rangeCount) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
else if (this.rangeCount === 0) {
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
if (!this.anchor.isEqual(otherSelection.anchor) || !this.focus.isEqual(otherSelection.focus)) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
for (const thisRange of this._ranges) {
|
|
272
|
-
let found = false;
|
|
273
|
-
for (const otherRange of otherSelection._ranges) {
|
|
274
|
-
if (thisRange.isEqual(otherRange)) {
|
|
275
|
-
found = true;
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (!found) {
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Checks whether this selection is similar to given selection. Selections are similar if they have same directions, same
|
|
287
|
-
* number of ranges, and all {@link module:engine/view/range~ViewRange#getTrimmed trimmed} ranges from one selection are
|
|
288
|
-
* equal to any trimmed range from other selection.
|
|
289
|
-
*
|
|
290
|
-
* @param otherSelection Selection to compare with.
|
|
291
|
-
* @returns `true` if selections are similar, `false` otherwise.
|
|
292
|
-
*/
|
|
293
|
-
isSimilar(otherSelection) {
|
|
294
|
-
if (this.isBackward != otherSelection.isBackward) {
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
297
|
-
const numOfRangesA = count(this.getRanges());
|
|
298
|
-
const numOfRangesB = count(otherSelection.getRanges());
|
|
299
|
-
// If selections have different number of ranges, they cannot be similar.
|
|
300
|
-
if (numOfRangesA != numOfRangesB) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
// If both selections have no ranges, they are similar.
|
|
304
|
-
if (numOfRangesA == 0) {
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
// Check if each range in one selection has a similar range in other selection.
|
|
308
|
-
for (let rangeA of this.getRanges()) {
|
|
309
|
-
rangeA = rangeA.getTrimmed();
|
|
310
|
-
let found = false;
|
|
311
|
-
for (let rangeB of otherSelection.getRanges()) {
|
|
312
|
-
rangeB = rangeB.getTrimmed();
|
|
313
|
-
if (rangeA.start.isEqual(rangeB.start) && rangeA.end.isEqual(rangeB.end)) {
|
|
314
|
-
found = true;
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
// For `rangeA`, neither range in `otherSelection` was similar. So selections are not similar.
|
|
319
|
-
if (!found) {
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
// There were no ranges that weren't matched. Selections are similar.
|
|
324
|
-
return true;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Returns the selected element. {@link module:engine/view/element~ViewElement Element} is considered as selected if there is only
|
|
328
|
-
* one range in the selection, and that range contains exactly one element.
|
|
329
|
-
* Returns `null` if there is no selected element.
|
|
330
|
-
*/
|
|
331
|
-
getSelectedElement() {
|
|
332
|
-
if (this.rangeCount !== 1) {
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
return this.getFirstRange().getContainedElement();
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Sets this selection's ranges and direction to the specified location based on the given
|
|
339
|
-
* {@link module:engine/view/selection~ViewSelectable selectable}.
|
|
340
|
-
*
|
|
341
|
-
* ```ts
|
|
342
|
-
* // Sets selection to the given range.
|
|
343
|
-
* const range = writer.createRange( start, end );
|
|
344
|
-
* selection.setTo( range );
|
|
345
|
-
*
|
|
346
|
-
* // Sets selection to given ranges.
|
|
347
|
-
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
|
|
348
|
-
* selection.setTo( range );
|
|
349
|
-
*
|
|
350
|
-
* // Sets selection to the other selection.
|
|
351
|
-
* const otherSelection = writer.createSelection();
|
|
352
|
-
* selection.setTo( otherSelection );
|
|
353
|
-
*
|
|
354
|
-
* // Sets selection to contents of ViewDocumentSelection.
|
|
355
|
-
* selection.setTo( editor.editing.view.document.selection );
|
|
356
|
-
*
|
|
357
|
-
* // Sets collapsed selection at the given position.
|
|
358
|
-
* const position = writer.createPositionAt( root, path );
|
|
359
|
-
* selection.setTo( position );
|
|
360
|
-
*
|
|
361
|
-
* // Sets collapsed selection at the position of given item and offset.
|
|
362
|
-
* selection.setTo( paragraph, offset );
|
|
363
|
-
* ```
|
|
364
|
-
*
|
|
365
|
-
* Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
|
|
366
|
-
* that element and ends after the last child of that element.
|
|
367
|
-
*
|
|
368
|
-
* ```ts
|
|
369
|
-
* selection.setTo( paragraph, 'in' );
|
|
370
|
-
* ```
|
|
371
|
-
*
|
|
372
|
-
* Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
|
|
373
|
-
*
|
|
374
|
-
* ```ts
|
|
375
|
-
* selection.setTo( paragraph, 'on' );
|
|
376
|
-
*
|
|
377
|
-
* // Clears selection. Removes all ranges.
|
|
378
|
-
* selection.setTo( null );
|
|
379
|
-
* ```
|
|
380
|
-
*
|
|
381
|
-
* `Selection#setTo()` method allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
382
|
-
*
|
|
383
|
-
* ```ts
|
|
384
|
-
* // Sets selection as backward.
|
|
385
|
-
* selection.setTo( range, { backward: true } );
|
|
386
|
-
* ```
|
|
387
|
-
*
|
|
388
|
-
* Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
389
|
-
* This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
390
|
-
* represented in other way, for example by applying proper CSS class.
|
|
391
|
-
*
|
|
392
|
-
* Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
393
|
-
* (and be properly handled by screen readers).
|
|
394
|
-
*
|
|
395
|
-
* ```ts
|
|
396
|
-
* // Creates fake selection with label.
|
|
397
|
-
* selection.setTo( range, { fake: true, label: 'foo' } );
|
|
398
|
-
* ```
|
|
399
|
-
*
|
|
400
|
-
* @fires change
|
|
401
|
-
*/
|
|
402
|
-
setTo(...args) {
|
|
403
|
-
let [selectable, placeOrOffset, options] = args;
|
|
404
|
-
if (typeof placeOrOffset == 'object') {
|
|
405
|
-
options = placeOrOffset;
|
|
406
|
-
placeOrOffset = undefined;
|
|
407
|
-
}
|
|
408
|
-
if (selectable === null) {
|
|
409
|
-
this._setRanges([]);
|
|
410
|
-
this._setFakeOptions(options);
|
|
411
|
-
}
|
|
412
|
-
else if (selectable instanceof ViewSelection || selectable instanceof ViewDocumentSelection) {
|
|
413
|
-
this._setRanges(selectable.getRanges(), selectable.isBackward);
|
|
414
|
-
this._setFakeOptions({ fake: selectable.isFake, label: selectable.fakeSelectionLabel });
|
|
415
|
-
}
|
|
416
|
-
else if (selectable instanceof ViewRange) {
|
|
417
|
-
this._setRanges([selectable], options && options.backward);
|
|
418
|
-
this._setFakeOptions(options);
|
|
419
|
-
}
|
|
420
|
-
else if (selectable instanceof ViewPosition) {
|
|
421
|
-
this._setRanges([new ViewRange(selectable)]);
|
|
422
|
-
this._setFakeOptions(options);
|
|
423
|
-
}
|
|
424
|
-
else if (selectable instanceof ViewNode) {
|
|
425
|
-
const backward = !!options && !!options.backward;
|
|
426
|
-
let range;
|
|
427
|
-
if (placeOrOffset === undefined) {
|
|
428
|
-
/**
|
|
429
|
-
* selection.setTo requires the second parameter when the first parameter is a node.
|
|
430
|
-
*
|
|
431
|
-
* @error view-selection-setto-required-second-parameter
|
|
432
|
-
*/
|
|
433
|
-
throw new CKEditorError('view-selection-setto-required-second-parameter', this);
|
|
434
|
-
}
|
|
435
|
-
else if (placeOrOffset == 'in') {
|
|
436
|
-
range = ViewRange._createIn(selectable);
|
|
437
|
-
}
|
|
438
|
-
else if (placeOrOffset == 'on') {
|
|
439
|
-
range = ViewRange._createOn(selectable);
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
range = new ViewRange(ViewPosition._createAt(selectable, placeOrOffset));
|
|
443
|
-
}
|
|
444
|
-
this._setRanges([range], backward);
|
|
445
|
-
this._setFakeOptions(options);
|
|
446
|
-
}
|
|
447
|
-
else if (isIterable(selectable)) {
|
|
448
|
-
// We assume that the selectable is an iterable of ranges.
|
|
449
|
-
// Array.from() is used to prevent setting ranges to the old iterable
|
|
450
|
-
this._setRanges(selectable, options && options.backward);
|
|
451
|
-
this._setFakeOptions(options);
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
/**
|
|
455
|
-
* Cannot set selection to given place.
|
|
456
|
-
*
|
|
457
|
-
* @error view-selection-setto-not-selectable
|
|
458
|
-
*/
|
|
459
|
-
throw new CKEditorError('view-selection-setto-not-selectable', this);
|
|
460
|
-
}
|
|
461
|
-
this.fire('change');
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Moves {@link #focus} to the specified location.
|
|
465
|
-
*
|
|
466
|
-
* The location can be specified in the same form as
|
|
467
|
-
* {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
|
|
468
|
-
* parameters.
|
|
469
|
-
*
|
|
470
|
-
* @fires change
|
|
471
|
-
* @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~ViewItem view item}.
|
|
472
|
-
*/
|
|
473
|
-
setFocus(itemOrPosition, offset) {
|
|
474
|
-
if (this.anchor === null) {
|
|
475
|
-
/**
|
|
476
|
-
* Cannot set selection focus if there are no ranges in selection.
|
|
477
|
-
*
|
|
478
|
-
* @error view-selection-setfocus-no-ranges
|
|
479
|
-
*/
|
|
480
|
-
throw new CKEditorError('view-selection-setfocus-no-ranges', this);
|
|
481
|
-
}
|
|
482
|
-
const newFocus = ViewPosition._createAt(itemOrPosition, offset);
|
|
483
|
-
if (newFocus.compareWith(this.focus) == 'same') {
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
const anchor = this.anchor;
|
|
487
|
-
this._ranges.pop();
|
|
488
|
-
if (newFocus.compareWith(anchor) == 'before') {
|
|
489
|
-
this._addRange(new ViewRange(newFocus, anchor), true);
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
this._addRange(new ViewRange(anchor, newFocus));
|
|
493
|
-
}
|
|
494
|
-
this.fire('change');
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Converts `ViewSelection` instance to plain object and returns it.
|
|
498
|
-
*
|
|
499
|
-
* @returns `ViewSelection` instance converted to plain object.
|
|
500
|
-
*/
|
|
501
|
-
toJSON() {
|
|
502
|
-
const json = {
|
|
503
|
-
ranges: Array.from(this.getRanges()).map(range => range.toJSON())
|
|
504
|
-
};
|
|
505
|
-
if (this.isBackward) {
|
|
506
|
-
json.isBackward = true;
|
|
507
|
-
}
|
|
508
|
-
if (this.isFake) {
|
|
509
|
-
json.isFake = true;
|
|
510
|
-
}
|
|
511
|
-
return json;
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Replaces all ranges that were added to the selection with given array of ranges. Last range of the array
|
|
515
|
-
* is treated like the last added range and is used to set {@link #anchor anchor} and {@link #focus focus}.
|
|
516
|
-
* Accepts a flag describing in which way the selection is made.
|
|
517
|
-
*
|
|
518
|
-
* @param newRanges Iterable object of ranges to set.
|
|
519
|
-
* @param isLastBackward Flag describing if last added range was selected forward - from start to end
|
|
520
|
-
* (`false`) or backward - from end to start (`true`). Defaults to `false`.
|
|
521
|
-
*/
|
|
522
|
-
_setRanges(newRanges, isLastBackward = false) {
|
|
523
|
-
// New ranges should be copied to prevent removing them by setting them to `[]` first.
|
|
524
|
-
// Only applies to situations when selection is set to the same selection or same selection's ranges.
|
|
525
|
-
newRanges = Array.from(newRanges);
|
|
526
|
-
this._ranges = [];
|
|
527
|
-
for (const range of newRanges) {
|
|
528
|
-
this._addRange(range);
|
|
529
|
-
}
|
|
530
|
-
this._lastRangeBackward = !!isLastBackward;
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Sets this selection instance to be marked as `fake`. A fake selection does not render as browser native selection
|
|
534
|
-
* over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to
|
|
535
|
-
* the user and selection over elements can be represented in other way, for example by applying proper CSS class.
|
|
536
|
-
*
|
|
537
|
-
* Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be
|
|
538
|
-
* properly handled by screen readers).
|
|
539
|
-
*/
|
|
540
|
-
_setFakeOptions(options = {}) {
|
|
541
|
-
this._isFake = !!options.fake;
|
|
542
|
-
this._fakeSelectionLabel = options.fake ? options.label || '' : '';
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Adds a range to the selection. Added range is copied. This means that passed range is not saved in the
|
|
546
|
-
* selection instance and you can safely operate on it.
|
|
547
|
-
*
|
|
548
|
-
* Accepts a flag describing in which way the selection is made - passed range might be selected from
|
|
549
|
-
* {@link module:engine/view/range~ViewRange#start start} to {@link module:engine/view/range~ViewRange#end end}
|
|
550
|
-
* or from {@link module:engine/view/range~ViewRange#end end} to {@link module:engine/view/range~ViewRange#start start}.
|
|
551
|
-
* The flag is used to set {@link #anchor anchor} and {@link #focus focus} properties.
|
|
552
|
-
*
|
|
553
|
-
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
|
|
554
|
-
* with ranges already stored in Selection instance.
|
|
555
|
-
*/
|
|
556
|
-
_addRange(range, isBackward = false) {
|
|
557
|
-
if (!(range instanceof ViewRange)) {
|
|
558
|
-
/**
|
|
559
|
-
* Selection range set to an object that is not an instance of {@link module:engine/view/range~ViewRange}.
|
|
560
|
-
*
|
|
561
|
-
* @error view-selection-add-range-not-range
|
|
562
|
-
*/
|
|
563
|
-
throw new CKEditorError('view-selection-add-range-not-range', this);
|
|
564
|
-
}
|
|
565
|
-
this._pushRange(range);
|
|
566
|
-
this._lastRangeBackward = !!isBackward;
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Adds range to selection - creates copy of given range so it can be safely used and modified.
|
|
570
|
-
*
|
|
571
|
-
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
|
|
572
|
-
* with ranges already stored in selection instance.
|
|
573
|
-
*/
|
|
574
|
-
_pushRange(range) {
|
|
575
|
-
for (const storedRange of this._ranges) {
|
|
576
|
-
if (range.isIntersecting(storedRange)) {
|
|
577
|
-
/**
|
|
578
|
-
* Trying to add a range that intersects with another range from selection.
|
|
579
|
-
*
|
|
580
|
-
* @error view-selection-range-intersects
|
|
581
|
-
* @param {module:engine/view/range~ViewRange} addedRange Range that was added to the selection.
|
|
582
|
-
* @param {module:engine/view/range~ViewRange} intersectingRange Range from selection that intersects with `addedRange`.
|
|
583
|
-
*/
|
|
584
|
-
throw new CKEditorError('view-selection-range-intersects', this, { addedRange: range, intersectingRange: storedRange });
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
this._ranges.push(new ViewRange(range.start, range.end));
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
591
|
-
// Proper overload would interfere with that.
|
|
592
|
-
ViewSelection.prototype.is = function (type) {
|
|
593
|
-
return type === 'selection' || type === 'view:selection';
|
|
594
|
-
};
|