@ckeditor/ckeditor5-engine 45.2.1 → 46.0.0-alpha.1
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/dist/index.js +2563 -2257
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/controller/datacontroller.d.ts +33 -32
- package/src/controller/datacontroller.js +29 -28
- package/src/controller/editingcontroller.d.ts +8 -8
- package/src/controller/editingcontroller.js +10 -10
- package/src/conversion/conversion.d.ts +18 -19
- package/src/conversion/conversion.js +4 -4
- package/src/conversion/conversionhelpers.d.ts +1 -1
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.d.ts +63 -69
- package/src/conversion/downcastdispatcher.js +16 -16
- package/src/conversion/downcasthelpers.d.ts +94 -83
- package/src/conversion/downcasthelpers.js +63 -53
- package/src/conversion/mapper.d.ts +27 -27
- package/src/conversion/mapper.js +15 -15
- package/src/conversion/modelconsumable.d.ts +26 -26
- package/src/conversion/modelconsumable.js +23 -23
- package/src/conversion/upcastdispatcher.d.ts +33 -32
- package/src/conversion/upcastdispatcher.js +19 -19
- package/src/conversion/upcasthelpers.d.ts +46 -38
- package/src/conversion/upcasthelpers.js +33 -24
- package/src/conversion/viewconsumable.d.ts +50 -45
- package/src/conversion/viewconsumable.js +32 -27
- package/src/dataprocessor/basichtmlwriter.d.ts +4 -2
- package/src/dataprocessor/basichtmlwriter.js +3 -1
- package/src/dataprocessor/dataprocessor.d.ts +7 -6
- package/src/dataprocessor/htmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/htmldataprocessor.js +6 -6
- package/src/dataprocessor/htmlwriter.d.ts +1 -1
- package/src/dataprocessor/xmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/xmldataprocessor.js +6 -6
- package/src/dev-utils/model.d.ts +25 -26
- package/src/dev-utils/model.js +35 -36
- package/src/dev-utils/operationreplayer.d.ts +5 -3
- package/src/dev-utils/operationreplayer.js +4 -2
- package/src/dev-utils/utils.d.ts +8 -0
- package/src/dev-utils/utils.js +8 -0
- package/src/dev-utils/view.d.ts +66 -63
- package/src/dev-utils/view.js +144 -134
- package/src/index.d.ts +135 -106
- package/src/index.js +120 -71
- package/src/legacyerrors.d.ts +5 -0
- package/src/legacyerrors.js +17 -0
- package/src/model/batch.d.ts +2 -15
- package/src/model/batch.js +1 -23
- package/src/model/differ.d.ts +54 -31
- package/src/model/differ.js +15 -15
- package/src/model/document.d.ts +31 -31
- package/src/model/document.js +13 -13
- package/src/model/documentfragment.d.ts +45 -45
- package/src/model/documentfragment.js +40 -40
- package/src/model/documentselection.d.ts +92 -92
- package/src/model/documentselection.js +71 -70
- package/src/model/element.d.ts +31 -31
- package/src/model/element.js +29 -29
- package/src/model/history.d.ts +3 -3
- package/src/model/history.js +2 -2
- package/src/model/item.d.ts +4 -5
- package/src/model/liveposition.d.ts +31 -31
- package/src/model/liveposition.js +18 -18
- package/src/model/liverange.d.ts +42 -38
- package/src/model/liverange.js +17 -16
- package/src/model/markercollection.d.ts +41 -40
- package/src/model/markercollection.js +22 -20
- package/src/model/model.d.ts +82 -81
- package/src/model/model.js +54 -54
- package/src/model/node.d.ts +48 -48
- package/src/model/node.js +31 -31
- package/src/model/nodelist.d.ts +17 -17
- package/src/model/nodelist.js +11 -11
- package/src/model/operation/attributeoperation.d.ts +10 -10
- package/src/model/operation/attributeoperation.js +7 -7
- package/src/model/operation/detachoperation.d.ts +11 -9
- package/src/model/operation/detachoperation.js +8 -6
- package/src/model/operation/insertoperation.d.ts +13 -13
- package/src/model/operation/insertoperation.js +15 -15
- package/src/model/operation/markeroperation.d.ts +12 -12
- package/src/model/operation/markeroperation.js +5 -5
- package/src/model/operation/mergeoperation.d.ts +16 -16
- package/src/model/operation/mergeoperation.js +18 -18
- package/src/model/operation/moveoperation.d.ts +16 -16
- package/src/model/operation/moveoperation.js +18 -15
- package/src/model/operation/nooperation.d.ts +4 -4
- package/src/model/operation/nooperation.js +2 -2
- package/src/model/operation/operation.d.ts +10 -10
- package/src/model/operation/operation.js +5 -5
- package/src/model/operation/operationfactory.d.ts +4 -4
- package/src/model/operation/operationfactory.js +12 -12
- package/src/model/operation/renameoperation.d.ts +10 -10
- package/src/model/operation/renameoperation.js +7 -7
- package/src/model/operation/rootattributeoperation.d.ts +12 -12
- package/src/model/operation/rootattributeoperation.js +8 -8
- package/src/model/operation/rootoperation.d.ts +8 -8
- package/src/model/operation/rootoperation.js +3 -3
- package/src/model/operation/splitoperation.d.ts +17 -17
- package/src/model/operation/splitoperation.js +19 -19
- package/src/model/operation/transform.d.ts +11 -8
- package/src/model/operation/transform.js +66 -49
- package/src/model/operation/utils.d.ts +24 -23
- package/src/model/operation/utils.js +20 -20
- package/src/model/position.d.ts +101 -97
- package/src/model/position.js +69 -64
- package/src/model/range.d.ts +90 -90
- package/src/model/range.js +87 -87
- package/src/model/rootelement.d.ts +11 -11
- package/src/model/rootelement.js +9 -9
- package/src/model/schema.d.ts +158 -154
- package/src/model/schema.js +93 -90
- package/src/model/selection.d.ts +73 -73
- package/src/model/selection.js +62 -62
- package/src/model/text.d.ts +11 -10
- package/src/model/text.js +11 -10
- package/src/model/textproxy.d.ts +39 -38
- package/src/model/textproxy.js +31 -30
- package/src/model/treewalker.d.ts +37 -37
- package/src/model/treewalker.js +14 -14
- package/src/model/typecheckable.d.ts +45 -45
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.d.ts +7 -7
- package/src/model/utils/deletecontent.d.ts +7 -5
- package/src/model/utils/deletecontent.js +13 -11
- package/src/model/utils/getselectedcontent.d.ts +6 -5
- package/src/model/utils/getselectedcontent.js +2 -1
- package/src/model/utils/insertcontent.d.ts +9 -8
- package/src/model/utils/insertcontent.js +41 -40
- package/src/model/utils/insertobject.d.ts +9 -9
- package/src/model/utils/insertobject.js +4 -4
- package/src/model/utils/modifyselection.d.ts +5 -4
- package/src/model/utils/modifyselection.js +12 -11
- package/src/model/utils/selection-post-fixer.d.ts +12 -8
- package/src/model/utils/selection-post-fixer.js +15 -11
- package/src/model/writer.d.ts +102 -101
- package/src/model/writer.js +99 -98
- package/src/view/attributeelement.d.ts +29 -29
- package/src/view/attributeelement.js +25 -25
- package/src/view/containerelement.d.ts +16 -15
- package/src/view/containerelement.js +15 -14
- package/src/view/datatransfer.d.ts +7 -7
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.d.ts +25 -25
- package/src/view/document.js +15 -15
- package/src/view/documentfragment.d.ts +21 -21
- package/src/view/documentfragment.js +14 -14
- package/src/view/documentselection.d.ts +65 -63
- package/src/view/documentselection.js +27 -25
- package/src/view/domconverter.d.ts +96 -91
- package/src/view/domconverter.js +78 -73
- package/src/view/downcastwriter.d.ts +185 -181
- package/src/view/downcastwriter.js +222 -210
- package/src/view/editableelement.d.ts +13 -13
- package/src/view/editableelement.js +8 -8
- package/src/view/element.d.ts +75 -74
- package/src/view/element.js +58 -58
- package/src/view/elementdefinition.d.ts +3 -4
- package/src/view/emptyelement.d.ts +13 -13
- package/src/view/emptyelement.js +13 -13
- package/src/view/filler.d.ts +14 -3
- package/src/view/filler.js +12 -1
- package/src/view/item.d.ts +4 -5
- package/src/view/matcher.d.ts +22 -19
- package/src/view/matcher.js +6 -6
- package/src/view/node.d.ts +33 -33
- package/src/view/node.js +9 -9
- package/src/view/observer/arrowkeysobserver.d.ts +10 -10
- package/src/view/observer/arrowkeysobserver.js +5 -5
- package/src/view/observer/bubblingemittermixin.d.ts +5 -5
- package/src/view/observer/bubblingemittermixin.js +2 -9
- package/src/view/observer/bubblingeventinfo.d.ts +9 -9
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.d.ts +8 -8
- package/src/view/observer/clickobserver.js +4 -4
- package/src/view/observer/compositionobserver.d.ts +19 -19
- package/src/view/observer/compositionobserver.js +6 -6
- package/src/view/observer/domeventdata.d.ts +9 -9
- package/src/view/observer/domeventdata.js +2 -2
- package/src/view/observer/domeventobserver.d.ts +3 -3
- package/src/view/observer/domeventobserver.js +5 -5
- package/src/view/observer/fakeselectionobserver.d.ts +9 -9
- package/src/view/observer/fakeselectionobserver.js +8 -8
- package/src/view/observer/focusobserver.d.ts +16 -16
- package/src/view/observer/focusobserver.js +7 -7
- package/src/view/observer/inputobserver.d.ts +18 -18
- package/src/view/observer/inputobserver.js +5 -5
- package/src/view/observer/keyobserver.d.ts +11 -11
- package/src/view/observer/keyobserver.js +3 -3
- package/src/view/observer/mouseobserver.d.ts +16 -16
- package/src/view/observer/mouseobserver.js +3 -3
- package/src/view/observer/mutationobserver.d.ts +21 -21
- package/src/view/observer/mutationobserver.js +7 -7
- package/src/view/observer/observer.d.ts +12 -12
- package/src/view/observer/observer.js +6 -6
- package/src/view/observer/selectionobserver.d.ts +33 -33
- package/src/view/observer/selectionobserver.js +14 -14
- package/src/view/observer/tabobserver.d.ts +10 -10
- package/src/view/observer/tabobserver.js +5 -5
- package/src/view/observer/touchobserver.d.ts +13 -13
- package/src/view/observer/touchobserver.js +3 -3
- package/src/view/placeholder.d.ts +21 -21
- package/src/view/placeholder.js +23 -23
- package/src/view/position.d.ts +49 -49
- package/src/view/position.js +42 -42
- package/src/view/range.d.ts +76 -74
- package/src/view/range.js +67 -65
- package/src/view/rawelement.d.ts +19 -19
- package/src/view/rawelement.js +16 -16
- package/src/view/renderer.d.ts +14 -14
- package/src/view/renderer.js +7 -7
- package/src/view/rooteditableelement.d.ts +8 -7
- package/src/view/rooteditableelement.js +7 -6
- package/src/view/selection.d.ts +66 -64
- package/src/view/selection.js +50 -48
- package/src/view/styles/background.d.ts +2 -2
- package/src/view/styles/background.js +9 -9
- package/src/view/styles/border.d.ts +2 -2
- package/src/view/styles/border.js +13 -13
- package/src/view/styles/margin.d.ts +2 -2
- package/src/view/styles/margin.js +5 -5
- package/src/view/styles/padding.d.ts +2 -2
- package/src/view/styles/padding.js +5 -5
- package/src/view/styles/utils.d.ts +24 -24
- package/src/view/styles/utils.js +25 -25
- package/src/view/stylesmap.d.ts +28 -32
- package/src/view/stylesmap.js +52 -39
- package/src/view/text.d.ts +11 -11
- package/src/view/text.js +10 -10
- package/src/view/textproxy.d.ts +33 -32
- package/src/view/textproxy.js +23 -22
- package/src/view/tokenlist.d.ts +14 -14
- package/src/view/tokenlist.js +10 -10
- package/src/view/treewalker.d.ts +42 -40
- package/src/view/treewalker.js +36 -35
- package/src/view/typecheckable.d.ts +76 -75
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.d.ts +22 -21
- package/src/view/uielement.js +17 -16
- package/src/view/upcastwriter.d.ts +70 -70
- package/src/view/upcastwriter.js +42 -42
- package/src/view/view.d.ts +70 -69
- package/src/view/view.js +56 -55
|
@@ -5,23 +5,24 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/view/rooteditableelement
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import type
|
|
8
|
+
import { ViewEditableElement } from './editableelement.js';
|
|
9
|
+
import { type ViewDocument } from './document.js';
|
|
10
10
|
/**
|
|
11
|
-
* Class representing a single root in the data view. A root can be either
|
|
12
|
-
*
|
|
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
|
|
13
14
|
* editable elements} making them "nested editables".
|
|
14
15
|
*/
|
|
15
|
-
export
|
|
16
|
+
export declare class ViewRootEditableElement extends ViewEditableElement {
|
|
16
17
|
/**
|
|
17
18
|
* Creates root editable element.
|
|
18
19
|
*
|
|
19
20
|
* @param document The document instance to which this element belongs.
|
|
20
21
|
* @param name Node name.
|
|
21
22
|
*/
|
|
22
|
-
constructor(document:
|
|
23
|
+
constructor(document: ViewDocument, name: string);
|
|
23
24
|
/**
|
|
24
|
-
* Name of this root inside {@link module:engine/view/document~
|
|
25
|
+
* Name of this root inside {@link module:engine/view/document~ViewDocument} that is an owner of this root. If no
|
|
25
26
|
* other name is set, `main` name is used.
|
|
26
27
|
*
|
|
27
28
|
* @readonly
|
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/view/rooteditableelement
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import { ViewEditableElement } from './editableelement.js';
|
|
9
9
|
const rootNameSymbol = Symbol('rootName');
|
|
10
10
|
/**
|
|
11
|
-
* Class representing a single root in the data view. A root can be either
|
|
12
|
-
*
|
|
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
|
|
13
14
|
* editable elements} making them "nested editables".
|
|
14
15
|
*/
|
|
15
|
-
export
|
|
16
|
+
export class ViewRootEditableElement extends ViewEditableElement {
|
|
16
17
|
/**
|
|
17
18
|
* Creates root editable element.
|
|
18
19
|
*
|
|
@@ -24,7 +25,7 @@ export default class RootEditableElement extends EditableElement {
|
|
|
24
25
|
this.rootName = 'main';
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
|
-
* Name of this root inside {@link module:engine/view/document~
|
|
28
|
+
* Name of this root inside {@link module:engine/view/document~ViewDocument} that is an owner of this root. If no
|
|
28
29
|
* other name is set, `main` name is used.
|
|
29
30
|
*
|
|
30
31
|
* @readonly
|
|
@@ -50,7 +51,7 @@ export default class RootEditableElement extends EditableElement {
|
|
|
50
51
|
}
|
|
51
52
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
52
53
|
// Proper overload would interfere with that.
|
|
53
|
-
|
|
54
|
+
ViewRootEditableElement.prototype.is = function (type, name) {
|
|
54
55
|
if (!name) {
|
|
55
56
|
return type === 'rootElement' || type === 'view:rootElement' ||
|
|
56
57
|
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
package/src/view/selection.d.ts
CHANGED
|
@@ -5,28 +5,28 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/view/selection
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import type
|
|
14
|
-
import type
|
|
15
|
-
import type
|
|
16
|
-
declare const
|
|
8
|
+
import { ViewTypeCheckable } from './typecheckable.js';
|
|
9
|
+
import { ViewRange } from './range.js';
|
|
10
|
+
import { ViewPosition, type ViewPositionOffset } from './position.js';
|
|
11
|
+
import { ViewNode } from './node.js';
|
|
12
|
+
import { ViewDocumentSelection } from './documentselection.js';
|
|
13
|
+
import { type ViewElement } from './element.js';
|
|
14
|
+
import { type ViewItem } from './item.js';
|
|
15
|
+
import { type ViewEditableElement } from './editableelement.js';
|
|
16
|
+
declare const ViewSelection_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof ViewTypeCheckable, import("@ckeditor/ckeditor5-utils").Emitter>;
|
|
17
17
|
/**
|
|
18
18
|
* Class representing an arbirtary selection in the view.
|
|
19
|
-
* See also {@link module:engine/view/documentselection~
|
|
19
|
+
* See also {@link module:engine/view/documentselection~ViewDocumentSelection}.
|
|
20
20
|
*
|
|
21
21
|
* New selection instances can be created via the constructor or one these methods:
|
|
22
22
|
*
|
|
23
|
-
* * {@link module:engine/view/view~
|
|
24
|
-
* * {@link module:engine/view/upcastwriter~
|
|
23
|
+
* * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
|
|
24
|
+
* * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
|
|
25
25
|
*
|
|
26
|
-
* A selection can consist of {@link module:engine/view/range~
|
|
27
|
-
* the {@link module:engine/view/selection~
|
|
26
|
+
* A selection can consist of {@link module:engine/view/range~ViewRange ranges} that can be set by using
|
|
27
|
+
* the {@link module:engine/view/selection~ViewSelection#setTo `Selection#setTo()`} method.
|
|
28
28
|
*/
|
|
29
|
-
export
|
|
29
|
+
export declare class ViewSelection extends /* #__PURE__ */ ViewSelection_base {
|
|
30
30
|
/**
|
|
31
31
|
* Stores all ranges that are selected.
|
|
32
32
|
*/
|
|
@@ -48,8 +48,8 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
48
48
|
*
|
|
49
49
|
* **Note**: The selection constructor is available as a factory method:
|
|
50
50
|
*
|
|
51
|
-
* * {@link module:engine/view/view~
|
|
52
|
-
* * {@link module:engine/view/upcastwriter~
|
|
51
|
+
* * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
|
|
52
|
+
* * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
|
|
53
53
|
*
|
|
54
54
|
* ```ts
|
|
55
55
|
* // Creates empty selection without ranges.
|
|
@@ -78,11 +78,11 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
78
78
|
* const paragraph = writer.createContainerElement( 'paragraph' );
|
|
79
79
|
* const selection = writer.createSelection( paragraph, offset );
|
|
80
80
|
*
|
|
81
|
-
* // Creates a range inside an {@link module:engine/view/element~
|
|
81
|
+
* // Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the
|
|
82
82
|
* // first child of that element and ends after the last child of that element.
|
|
83
83
|
* const selection = writer.createSelection( paragraph, 'in' );
|
|
84
84
|
*
|
|
85
|
-
* // Creates a range on an {@link module:engine/view/item~
|
|
85
|
+
* // Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends
|
|
86
86
|
* // just after the item.
|
|
87
87
|
* const selection = writer.createSelection( paragraph, 'on' );
|
|
88
88
|
* ```
|
|
@@ -109,12 +109,12 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
109
109
|
* @internal
|
|
110
110
|
*/
|
|
111
111
|
constructor(...args: [] | [
|
|
112
|
-
selectable:
|
|
113
|
-
placeOrOffset:
|
|
114
|
-
options?:
|
|
112
|
+
selectable: ViewNode,
|
|
113
|
+
placeOrOffset: ViewPlaceOrOffset,
|
|
114
|
+
options?: ViewSelectionOptions
|
|
115
115
|
] | [
|
|
116
|
-
selectable?: Exclude<
|
|
117
|
-
options?:
|
|
116
|
+
selectable?: Exclude<ViewSelectable, ViewNode>,
|
|
117
|
+
options?: ViewSelectionOptions
|
|
118
118
|
]);
|
|
119
119
|
/**
|
|
120
120
|
* Returns true if selection instance is marked as `fake`.
|
|
@@ -136,13 +136,13 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
136
136
|
*
|
|
137
137
|
* @see #focus
|
|
138
138
|
*/
|
|
139
|
-
get anchor():
|
|
139
|
+
get anchor(): ViewPosition | null;
|
|
140
140
|
/**
|
|
141
141
|
* Selection focus. Focus is a position where the selection ends.
|
|
142
142
|
*
|
|
143
143
|
* @see #anchor
|
|
144
144
|
*/
|
|
145
|
-
get focus():
|
|
145
|
+
get focus(): ViewPosition | null;
|
|
146
146
|
/**
|
|
147
147
|
* Returns whether the selection is collapsed. Selection is collapsed when there is exactly one range which is
|
|
148
148
|
* collapsed.
|
|
@@ -157,39 +157,40 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
157
157
|
*/
|
|
158
158
|
get isBackward(): boolean;
|
|
159
159
|
/**
|
|
160
|
-
* {@link module:engine/view/editableelement~
|
|
160
|
+
* {@link module:engine/view/editableelement~ViewEditableElement ViewEditableElement} instance that contains this selection, or `null`
|
|
161
161
|
* if the selection is not inside an editable element.
|
|
162
162
|
*/
|
|
163
|
-
get editableElement():
|
|
163
|
+
get editableElement(): ViewEditableElement | null;
|
|
164
164
|
/**
|
|
165
165
|
* Returns an iterable that contains copies of all ranges added to the selection.
|
|
166
166
|
*/
|
|
167
|
-
getRanges(): IterableIterator<
|
|
167
|
+
getRanges(): IterableIterator<ViewRange>;
|
|
168
168
|
/**
|
|
169
169
|
* Returns copy of the first range in the selection. First range is the one which
|
|
170
|
-
* {@link module:engine/view/range~
|
|
170
|
+
* {@link module:engine/view/range~ViewRange#start start} position
|
|
171
|
+
* {@link module:engine/view/position~ViewPosition#isBefore is before} start
|
|
171
172
|
* position of all other ranges (not to confuse with the first range added to the selection).
|
|
172
173
|
* Returns `null` if no ranges are added to selection.
|
|
173
174
|
*/
|
|
174
|
-
getFirstRange():
|
|
175
|
+
getFirstRange(): ViewRange | null;
|
|
175
176
|
/**
|
|
176
|
-
* Returns copy of the last range in the selection. Last range is the one which {@link module:engine/view/range~
|
|
177
|
-
* position {@link module:engine/view/position~
|
|
177
|
+
* Returns copy of the last range in the selection. Last range is the one which {@link module:engine/view/range~ViewRange#end end}
|
|
178
|
+
* position {@link module:engine/view/position~ViewPosition#isAfter is after} end position of all other ranges (not to confuse
|
|
178
179
|
* with the last range added to the selection). Returns `null` if no ranges are added to selection.
|
|
179
180
|
*/
|
|
180
|
-
getLastRange():
|
|
181
|
+
getLastRange(): ViewRange | null;
|
|
181
182
|
/**
|
|
182
183
|
* Returns copy of the first position in the selection. First position is the position that
|
|
183
|
-
* {@link module:engine/view/position~
|
|
184
|
+
* {@link module:engine/view/position~ViewPosition#isBefore is before} any other position in the selection ranges.
|
|
184
185
|
* Returns `null` if no ranges are added to selection.
|
|
185
186
|
*/
|
|
186
|
-
getFirstPosition():
|
|
187
|
+
getFirstPosition(): ViewPosition | null;
|
|
187
188
|
/**
|
|
188
189
|
* Returns copy of the last position in the selection. Last position is the position that
|
|
189
|
-
* {@link module:engine/view/position~
|
|
190
|
+
* {@link module:engine/view/position~ViewPosition#isAfter is after} any other position in the selection ranges.
|
|
190
191
|
* Returns `null` if no ranges are added to selection.
|
|
191
192
|
*/
|
|
192
|
-
getLastPosition():
|
|
193
|
+
getLastPosition(): ViewPosition | null;
|
|
193
194
|
/**
|
|
194
195
|
* Checks whether, this selection is equal to given selection. Selections are equal if they have same directions,
|
|
195
196
|
* same number of ranges and all ranges from one selection equal to a range from other selection.
|
|
@@ -197,25 +198,25 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
197
198
|
* @param otherSelection Selection to compare with.
|
|
198
199
|
* @returns `true` if selections are equal, `false` otherwise.
|
|
199
200
|
*/
|
|
200
|
-
isEqual(otherSelection:
|
|
201
|
+
isEqual(otherSelection: ViewSelection | ViewDocumentSelection): boolean;
|
|
201
202
|
/**
|
|
202
203
|
* Checks whether this selection is similar to given selection. Selections are similar if they have same directions, same
|
|
203
|
-
* number of ranges, and all {@link module:engine/view/range~
|
|
204
|
+
* number of ranges, and all {@link module:engine/view/range~ViewRange#getTrimmed trimmed} ranges from one selection are
|
|
204
205
|
* equal to any trimmed range from other selection.
|
|
205
206
|
*
|
|
206
207
|
* @param otherSelection Selection to compare with.
|
|
207
208
|
* @returns `true` if selections are similar, `false` otherwise.
|
|
208
209
|
*/
|
|
209
|
-
isSimilar(otherSelection:
|
|
210
|
+
isSimilar(otherSelection: ViewSelection | ViewDocumentSelection): boolean;
|
|
210
211
|
/**
|
|
211
|
-
* Returns the selected element. {@link module:engine/view/element~
|
|
212
|
+
* Returns the selected element. {@link module:engine/view/element~ViewElement Element} is considered as selected if there is only
|
|
212
213
|
* one range in the selection, and that range contains exactly one element.
|
|
213
214
|
* Returns `null` if there is no selected element.
|
|
214
215
|
*/
|
|
215
|
-
getSelectedElement():
|
|
216
|
+
getSelectedElement(): ViewElement | null;
|
|
216
217
|
/**
|
|
217
218
|
* Sets this selection's ranges and direction to the specified location based on the given
|
|
218
|
-
* {@link module:engine/view/selection~
|
|
219
|
+
* {@link module:engine/view/selection~ViewSelectable selectable}.
|
|
219
220
|
*
|
|
220
221
|
* ```ts
|
|
221
222
|
* // Sets selection to the given range.
|
|
@@ -230,7 +231,7 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
230
231
|
* const otherSelection = writer.createSelection();
|
|
231
232
|
* selection.setTo( otherSelection );
|
|
232
233
|
*
|
|
233
|
-
* // Sets selection to contents of
|
|
234
|
+
* // Sets selection to contents of ViewDocumentSelection.
|
|
234
235
|
* selection.setTo( editor.editing.view.document.selection );
|
|
235
236
|
*
|
|
236
237
|
* // Sets collapsed selection at the given position.
|
|
@@ -241,14 +242,14 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
241
242
|
* selection.setTo( paragraph, offset );
|
|
242
243
|
* ```
|
|
243
244
|
*
|
|
244
|
-
* Creates a range inside an {@link module:engine/view/element~
|
|
245
|
+
* Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
|
|
245
246
|
* that element and ends after the last child of that element.
|
|
246
247
|
*
|
|
247
248
|
* ```ts
|
|
248
249
|
* selection.setTo( paragraph, 'in' );
|
|
249
250
|
* ```
|
|
250
251
|
*
|
|
251
|
-
* Creates a range on an {@link module:engine/view/item~
|
|
252
|
+
* Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
|
|
252
253
|
*
|
|
253
254
|
* ```ts
|
|
254
255
|
* selection.setTo( paragraph, 'on' );
|
|
@@ -279,23 +280,24 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
279
280
|
* @fires change
|
|
280
281
|
*/
|
|
281
282
|
setTo(...args: [
|
|
282
|
-
selectable:
|
|
283
|
-
placeOrOffset:
|
|
284
|
-
options?:
|
|
283
|
+
selectable: ViewNode,
|
|
284
|
+
placeOrOffset: ViewPlaceOrOffset,
|
|
285
|
+
options?: ViewSelectionOptions
|
|
285
286
|
] | [
|
|
286
|
-
selectable?: Exclude<
|
|
287
|
-
options?:
|
|
287
|
+
selectable?: Exclude<ViewSelectable, ViewNode>,
|
|
288
|
+
options?: ViewSelectionOptions
|
|
288
289
|
]): void;
|
|
289
290
|
/**
|
|
290
291
|
* Moves {@link #focus} to the specified location.
|
|
291
292
|
*
|
|
292
|
-
* The location can be specified in the same form as
|
|
293
|
+
* The location can be specified in the same form as
|
|
294
|
+
* {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
|
|
293
295
|
* parameters.
|
|
294
296
|
*
|
|
295
297
|
* @fires change
|
|
296
|
-
* @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~
|
|
298
|
+
* @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~ViewItem view item}.
|
|
297
299
|
*/
|
|
298
|
-
setFocus(itemOrPosition:
|
|
300
|
+
setFocus(itemOrPosition: ViewItem | ViewPosition, offset?: ViewPositionOffset): void;
|
|
299
301
|
/**
|
|
300
302
|
* Replaces all ranges that were added to the selection with given array of ranges. Last range of the array
|
|
301
303
|
* is treated like the last added range and is used to set {@link #anchor anchor} and {@link #focus focus}.
|
|
@@ -320,8 +322,8 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
320
322
|
* selection instance and you can safely operate on it.
|
|
321
323
|
*
|
|
322
324
|
* Accepts a flag describing in which way the selection is made - passed range might be selected from
|
|
323
|
-
* {@link module:engine/view/range~
|
|
324
|
-
* or from {@link module:engine/view/range~
|
|
325
|
+
* {@link module:engine/view/range~ViewRange#start start} to {@link module:engine/view/range~ViewRange#end end}
|
|
326
|
+
* or from {@link module:engine/view/range~ViewRange#end end} to {@link module:engine/view/range~ViewRange#start start}.
|
|
325
327
|
* The flag is used to set {@link #anchor anchor} and {@link #focus focus} properties.
|
|
326
328
|
*
|
|
327
329
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
|
|
@@ -337,9 +339,9 @@ export default class Selection extends /* #__PURE__ */ Selection_base {
|
|
|
337
339
|
private _pushRange;
|
|
338
340
|
}
|
|
339
341
|
/**
|
|
340
|
-
* Additional options for {@link ~
|
|
342
|
+
* Additional options for {@link ~ViewSelection}.
|
|
341
343
|
*/
|
|
342
|
-
export interface
|
|
344
|
+
export interface ViewSelectionOptions {
|
|
343
345
|
/**
|
|
344
346
|
* Sets this selection instance to be backward.
|
|
345
347
|
*/
|
|
@@ -356,11 +358,11 @@ export interface SelectionOptions {
|
|
|
356
358
|
/**
|
|
357
359
|
* The place or offset of the selection.
|
|
358
360
|
*/
|
|
359
|
-
export type
|
|
361
|
+
export type ViewPlaceOrOffset = number | 'before' | 'end' | 'after' | 'on' | 'in';
|
|
360
362
|
/**
|
|
361
|
-
* Fired whenever selection ranges are changed through {@link ~
|
|
363
|
+
* Fired whenever selection ranges are changed through {@link ~ViewSelection Selection API}.
|
|
362
364
|
*
|
|
363
|
-
* @eventName ~
|
|
365
|
+
* @eventName ~ViewSelection#change
|
|
364
366
|
*/
|
|
365
367
|
export type ViewSelectionChangeEvent = {
|
|
366
368
|
name: 'change';
|
|
@@ -369,7 +371,7 @@ export type ViewSelectionChangeEvent = {
|
|
|
369
371
|
/**
|
|
370
372
|
* An entity that is used to set selection.
|
|
371
373
|
*
|
|
372
|
-
* See also {@link module:engine/view/selection~
|
|
374
|
+
* See also {@link module:engine/view/selection~ViewSelection#setTo}
|
|
373
375
|
*/
|
|
374
|
-
export type
|
|
376
|
+
export type ViewSelectable = ViewSelection | ViewDocumentSelection | ViewPosition | Iterable<ViewRange> | ViewRange | ViewNode | null;
|
|
375
377
|
export {};
|
package/src/view/selection.js
CHANGED
|
@@ -5,25 +5,25 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/view/selection
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
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
13
|
import { CKEditorError, EmitterMixin, count, isIterable } from '@ckeditor/ckeditor5-utils';
|
|
14
14
|
/**
|
|
15
15
|
* Class representing an arbirtary selection in the view.
|
|
16
|
-
* See also {@link module:engine/view/documentselection~
|
|
16
|
+
* See also {@link module:engine/view/documentselection~ViewDocumentSelection}.
|
|
17
17
|
*
|
|
18
18
|
* New selection instances can be created via the constructor or one these methods:
|
|
19
19
|
*
|
|
20
|
-
* * {@link module:engine/view/view~
|
|
21
|
-
* * {@link module:engine/view/upcastwriter~
|
|
20
|
+
* * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
|
|
21
|
+
* * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
|
|
22
22
|
*
|
|
23
|
-
* A selection can consist of {@link module:engine/view/range~
|
|
24
|
-
* the {@link module:engine/view/selection~
|
|
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
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export class ViewSelection extends /* #__PURE__ */ EmitterMixin(ViewTypeCheckable) {
|
|
27
27
|
/**
|
|
28
28
|
* Stores all ranges that are selected.
|
|
29
29
|
*/
|
|
@@ -45,8 +45,8 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
45
45
|
*
|
|
46
46
|
* **Note**: The selection constructor is available as a factory method:
|
|
47
47
|
*
|
|
48
|
-
* * {@link module:engine/view/view~
|
|
49
|
-
* * {@link module:engine/view/upcastwriter~
|
|
48
|
+
* * {@link module:engine/view/view~EditingView#createSelection `View#createSelection()`},
|
|
49
|
+
* * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createSelection `UpcastWriter#createSelection()`}.
|
|
50
50
|
*
|
|
51
51
|
* ```ts
|
|
52
52
|
* // Creates empty selection without ranges.
|
|
@@ -75,11 +75,11 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
75
75
|
* const paragraph = writer.createContainerElement( 'paragraph' );
|
|
76
76
|
* const selection = writer.createSelection( paragraph, offset );
|
|
77
77
|
*
|
|
78
|
-
* // Creates a range inside an {@link module:engine/view/element~
|
|
78
|
+
* // Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the
|
|
79
79
|
* // first child of that element and ends after the last child of that element.
|
|
80
80
|
* const selection = writer.createSelection( paragraph, 'in' );
|
|
81
81
|
*
|
|
82
|
-
* // Creates a range on an {@link module:engine/view/item~
|
|
82
|
+
* // Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends
|
|
83
83
|
* // just after the item.
|
|
84
84
|
* const selection = writer.createSelection( paragraph, 'on' );
|
|
85
85
|
* ```
|
|
@@ -180,7 +180,7 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
180
180
|
return !this.isCollapsed && this._lastRangeBackward;
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
|
-
* {@link module:engine/view/editableelement~
|
|
183
|
+
* {@link module:engine/view/editableelement~ViewEditableElement ViewEditableElement} instance that contains this selection, or `null`
|
|
184
184
|
* if the selection is not inside an editable element.
|
|
185
185
|
*/
|
|
186
186
|
get editableElement() {
|
|
@@ -199,7 +199,8 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* Returns copy of the first range in the selection. First range is the one which
|
|
202
|
-
* {@link module:engine/view/range~
|
|
202
|
+
* {@link module:engine/view/range~ViewRange#start start} position
|
|
203
|
+
* {@link module:engine/view/position~ViewPosition#isBefore is before} start
|
|
203
204
|
* position of all other ranges (not to confuse with the first range added to the selection).
|
|
204
205
|
* Returns `null` if no ranges are added to selection.
|
|
205
206
|
*/
|
|
@@ -213,8 +214,8 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
213
214
|
return first ? first.clone() : null;
|
|
214
215
|
}
|
|
215
216
|
/**
|
|
216
|
-
* Returns copy of the last range in the selection. Last range is the one which {@link module:engine/view/range~
|
|
217
|
-
* position {@link module:engine/view/position~
|
|
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
|
|
218
219
|
* with the last range added to the selection). Returns `null` if no ranges are added to selection.
|
|
219
220
|
*/
|
|
220
221
|
getLastRange() {
|
|
@@ -228,7 +229,7 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
228
229
|
}
|
|
229
230
|
/**
|
|
230
231
|
* Returns copy of the first position in the selection. First position is the position that
|
|
231
|
-
* {@link module:engine/view/position~
|
|
232
|
+
* {@link module:engine/view/position~ViewPosition#isBefore is before} any other position in the selection ranges.
|
|
232
233
|
* Returns `null` if no ranges are added to selection.
|
|
233
234
|
*/
|
|
234
235
|
getFirstPosition() {
|
|
@@ -237,7 +238,7 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
237
238
|
}
|
|
238
239
|
/**
|
|
239
240
|
* Returns copy of the last position in the selection. Last position is the position that
|
|
240
|
-
* {@link module:engine/view/position~
|
|
241
|
+
* {@link module:engine/view/position~ViewPosition#isAfter is after} any other position in the selection ranges.
|
|
241
242
|
* Returns `null` if no ranges are added to selection.
|
|
242
243
|
*/
|
|
243
244
|
getLastPosition() {
|
|
@@ -283,7 +284,7 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
283
284
|
}
|
|
284
285
|
/**
|
|
285
286
|
* Checks whether this selection is similar to given selection. Selections are similar if they have same directions, same
|
|
286
|
-
* number of ranges, and all {@link module:engine/view/range~
|
|
287
|
+
* number of ranges, and all {@link module:engine/view/range~ViewRange#getTrimmed trimmed} ranges from one selection are
|
|
287
288
|
* equal to any trimmed range from other selection.
|
|
288
289
|
*
|
|
289
290
|
* @param otherSelection Selection to compare with.
|
|
@@ -323,7 +324,7 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
323
324
|
return true;
|
|
324
325
|
}
|
|
325
326
|
/**
|
|
326
|
-
* Returns the selected element. {@link module:engine/view/element~
|
|
327
|
+
* Returns the selected element. {@link module:engine/view/element~ViewElement Element} is considered as selected if there is only
|
|
327
328
|
* one range in the selection, and that range contains exactly one element.
|
|
328
329
|
* Returns `null` if there is no selected element.
|
|
329
330
|
*/
|
|
@@ -335,7 +336,7 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
335
336
|
}
|
|
336
337
|
/**
|
|
337
338
|
* Sets this selection's ranges and direction to the specified location based on the given
|
|
338
|
-
* {@link module:engine/view/selection~
|
|
339
|
+
* {@link module:engine/view/selection~ViewSelectable selectable}.
|
|
339
340
|
*
|
|
340
341
|
* ```ts
|
|
341
342
|
* // Sets selection to the given range.
|
|
@@ -350,7 +351,7 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
350
351
|
* const otherSelection = writer.createSelection();
|
|
351
352
|
* selection.setTo( otherSelection );
|
|
352
353
|
*
|
|
353
|
-
* // Sets selection to contents of
|
|
354
|
+
* // Sets selection to contents of ViewDocumentSelection.
|
|
354
355
|
* selection.setTo( editor.editing.view.document.selection );
|
|
355
356
|
*
|
|
356
357
|
* // Sets collapsed selection at the given position.
|
|
@@ -361,14 +362,14 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
361
362
|
* selection.setTo( paragraph, offset );
|
|
362
363
|
* ```
|
|
363
364
|
*
|
|
364
|
-
* Creates a range inside an {@link module:engine/view/element~
|
|
365
|
+
* Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
|
|
365
366
|
* that element and ends after the last child of that element.
|
|
366
367
|
*
|
|
367
368
|
* ```ts
|
|
368
369
|
* selection.setTo( paragraph, 'in' );
|
|
369
370
|
* ```
|
|
370
371
|
*
|
|
371
|
-
* Creates a range on an {@link module:engine/view/item~
|
|
372
|
+
* Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
|
|
372
373
|
*
|
|
373
374
|
* ```ts
|
|
374
375
|
* selection.setTo( paragraph, 'on' );
|
|
@@ -408,19 +409,19 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
408
409
|
this._setRanges([]);
|
|
409
410
|
this._setFakeOptions(options);
|
|
410
411
|
}
|
|
411
|
-
else if (selectable instanceof
|
|
412
|
+
else if (selectable instanceof ViewSelection || selectable instanceof ViewDocumentSelection) {
|
|
412
413
|
this._setRanges(selectable.getRanges(), selectable.isBackward);
|
|
413
414
|
this._setFakeOptions({ fake: selectable.isFake, label: selectable.fakeSelectionLabel });
|
|
414
415
|
}
|
|
415
|
-
else if (selectable instanceof
|
|
416
|
+
else if (selectable instanceof ViewRange) {
|
|
416
417
|
this._setRanges([selectable], options && options.backward);
|
|
417
418
|
this._setFakeOptions(options);
|
|
418
419
|
}
|
|
419
|
-
else if (selectable instanceof
|
|
420
|
-
this._setRanges([new
|
|
420
|
+
else if (selectable instanceof ViewPosition) {
|
|
421
|
+
this._setRanges([new ViewRange(selectable)]);
|
|
421
422
|
this._setFakeOptions(options);
|
|
422
423
|
}
|
|
423
|
-
else if (selectable instanceof
|
|
424
|
+
else if (selectable instanceof ViewNode) {
|
|
424
425
|
const backward = !!options && !!options.backward;
|
|
425
426
|
let range;
|
|
426
427
|
if (placeOrOffset === undefined) {
|
|
@@ -432,13 +433,13 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
432
433
|
throw new CKEditorError('view-selection-setto-required-second-parameter', this);
|
|
433
434
|
}
|
|
434
435
|
else if (placeOrOffset == 'in') {
|
|
435
|
-
range =
|
|
436
|
+
range = ViewRange._createIn(selectable);
|
|
436
437
|
}
|
|
437
438
|
else if (placeOrOffset == 'on') {
|
|
438
|
-
range =
|
|
439
|
+
range = ViewRange._createOn(selectable);
|
|
439
440
|
}
|
|
440
441
|
else {
|
|
441
|
-
range = new
|
|
442
|
+
range = new ViewRange(ViewPosition._createAt(selectable, placeOrOffset));
|
|
442
443
|
}
|
|
443
444
|
this._setRanges([range], backward);
|
|
444
445
|
this._setFakeOptions(options);
|
|
@@ -462,11 +463,12 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
462
463
|
/**
|
|
463
464
|
* Moves {@link #focus} to the specified location.
|
|
464
465
|
*
|
|
465
|
-
* The location can be specified in the same form as
|
|
466
|
+
* The location can be specified in the same form as
|
|
467
|
+
* {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
|
|
466
468
|
* parameters.
|
|
467
469
|
*
|
|
468
470
|
* @fires change
|
|
469
|
-
* @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~
|
|
471
|
+
* @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~ViewItem view item}.
|
|
470
472
|
*/
|
|
471
473
|
setFocus(itemOrPosition, offset) {
|
|
472
474
|
if (this.anchor === null) {
|
|
@@ -477,17 +479,17 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
477
479
|
*/
|
|
478
480
|
throw new CKEditorError('view-selection-setfocus-no-ranges', this);
|
|
479
481
|
}
|
|
480
|
-
const newFocus =
|
|
482
|
+
const newFocus = ViewPosition._createAt(itemOrPosition, offset);
|
|
481
483
|
if (newFocus.compareWith(this.focus) == 'same') {
|
|
482
484
|
return;
|
|
483
485
|
}
|
|
484
486
|
const anchor = this.anchor;
|
|
485
487
|
this._ranges.pop();
|
|
486
488
|
if (newFocus.compareWith(anchor) == 'before') {
|
|
487
|
-
this._addRange(new
|
|
489
|
+
this._addRange(new ViewRange(newFocus, anchor), true);
|
|
488
490
|
}
|
|
489
491
|
else {
|
|
490
|
-
this._addRange(new
|
|
492
|
+
this._addRange(new ViewRange(anchor, newFocus));
|
|
491
493
|
}
|
|
492
494
|
this.fire('change');
|
|
493
495
|
}
|
|
@@ -527,17 +529,17 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
527
529
|
* selection instance and you can safely operate on it.
|
|
528
530
|
*
|
|
529
531
|
* Accepts a flag describing in which way the selection is made - passed range might be selected from
|
|
530
|
-
* {@link module:engine/view/range~
|
|
531
|
-
* or from {@link module:engine/view/range~
|
|
532
|
+
* {@link module:engine/view/range~ViewRange#start start} to {@link module:engine/view/range~ViewRange#end end}
|
|
533
|
+
* or from {@link module:engine/view/range~ViewRange#end end} to {@link module:engine/view/range~ViewRange#start start}.
|
|
532
534
|
* The flag is used to set {@link #anchor anchor} and {@link #focus focus} properties.
|
|
533
535
|
*
|
|
534
536
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-selection-range-intersects` if added range intersects
|
|
535
537
|
* with ranges already stored in Selection instance.
|
|
536
538
|
*/
|
|
537
539
|
_addRange(range, isBackward = false) {
|
|
538
|
-
if (!(range instanceof
|
|
540
|
+
if (!(range instanceof ViewRange)) {
|
|
539
541
|
/**
|
|
540
|
-
* Selection range set to an object that is not an instance of {@link module:engine/view/range~
|
|
542
|
+
* Selection range set to an object that is not an instance of {@link module:engine/view/range~ViewRange}.
|
|
541
543
|
*
|
|
542
544
|
* @error view-selection-add-range-not-range
|
|
543
545
|
*/
|
|
@@ -559,17 +561,17 @@ export default class Selection extends /* #__PURE__ */ EmitterMixin(TypeCheckabl
|
|
|
559
561
|
* Trying to add a range that intersects with another range from selection.
|
|
560
562
|
*
|
|
561
563
|
* @error view-selection-range-intersects
|
|
562
|
-
* @param {module:engine/view/range~
|
|
563
|
-
* @param {module:engine/view/range~
|
|
564
|
+
* @param {module:engine/view/range~ViewRange} addedRange Range that was added to the selection.
|
|
565
|
+
* @param {module:engine/view/range~ViewRange} intersectingRange Range from selection that intersects with `addedRange`.
|
|
564
566
|
*/
|
|
565
567
|
throw new CKEditorError('view-selection-range-intersects', this, { addedRange: range, intersectingRange: storedRange });
|
|
566
568
|
}
|
|
567
569
|
}
|
|
568
|
-
this._ranges.push(new
|
|
570
|
+
this._ranges.push(new ViewRange(range.start, range.end));
|
|
569
571
|
}
|
|
570
572
|
}
|
|
571
573
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
572
574
|
// Proper overload would interfere with that.
|
|
573
|
-
|
|
575
|
+
ViewSelection.prototype.is = function (type) {
|
|
574
576
|
return type === 'selection' || type === 'view:selection';
|
|
575
577
|
};
|