@ckeditor/ckeditor5-typing 40.0.0 → 40.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -27
- package/LICENSE.md +3 -3
- package/package.json +4 -4
- package/src/augmentation.d.ts +27 -27
- package/src/augmentation.js +5 -5
- package/src/delete.d.ts +32 -32
- package/src/delete.js +82 -82
- package/src/deletecommand.d.ts +83 -83
- package/src/deletecommand.js +201 -201
- package/src/deleteobserver.d.ts +55 -55
- package/src/deleteobserver.js +261 -261
- package/src/index.d.ts +24 -24
- package/src/index.js +18 -18
- package/src/input.d.ts +21 -21
- package/src/input.js +141 -141
- package/src/inserttextcommand.d.ts +76 -76
- package/src/inserttextcommand.js +83 -80
- package/src/inserttextobserver.d.ts +59 -59
- package/src/inserttextobserver.js +108 -108
- package/src/texttransformation.d.ts +33 -33
- package/src/texttransformation.js +228 -228
- package/src/textwatcher.d.ts +138 -138
- package/src/textwatcher.js +105 -105
- package/src/twostepcaretmovement.d.ts +232 -199
- package/src/twostepcaretmovement.js +622 -435
- package/src/typing.d.ts +23 -23
- package/src/typing.js +27 -27
- package/src/typingconfig.d.ts +204 -204
- package/src/typingconfig.js +5 -5
- package/src/utils/changebuffer.d.ts +103 -103
- package/src/utils/changebuffer.js +123 -123
- package/src/utils/findattributerange.d.ts +33 -33
- package/src/utils/findattributerange.js +41 -41
- package/src/utils/getlasttextline.d.ts +49 -49
- package/src/utils/getlasttextline.js +43 -43
- package/src/utils/inlinehighlight.d.ts +33 -33
- package/src/utils/inlinehighlight.js +74 -74
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module typing/utils/changebuffer
|
|
7
|
-
*/
|
|
8
|
-
import type { Model, Batch } from '@ckeditor/ckeditor5-engine';
|
|
9
|
-
/**
|
|
10
|
-
* Change buffer allows to group atomic changes (like characters that have been typed) into
|
|
11
|
-
* {@link module:engine/model/batch~Batch batches}.
|
|
12
|
-
*
|
|
13
|
-
* Batches represent single undo steps, hence changes added to one single batch are undone together.
|
|
14
|
-
*
|
|
15
|
-
* The buffer has a configurable limit of atomic changes that it can accommodate. After the limit was
|
|
16
|
-
* exceeded (see {@link ~ChangeBuffer#input}), a new batch is created in {@link ~ChangeBuffer#batch}.
|
|
17
|
-
*
|
|
18
|
-
* To use the change buffer you need to let it know about the number of changes that were added to the batch:
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* const buffer = new ChangeBuffer( model, LIMIT );
|
|
22
|
-
*
|
|
23
|
-
* // Later on in your feature:
|
|
24
|
-
* buffer.batch.insert( pos, insertedCharacters );
|
|
25
|
-
* buffer.input( insertedCharacters.length );
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export default class ChangeBuffer {
|
|
29
|
-
/**
|
|
30
|
-
* The model instance.
|
|
31
|
-
*/
|
|
32
|
-
readonly model: Model;
|
|
33
|
-
/**
|
|
34
|
-
* The maximum number of atomic changes which can be contained in one batch.
|
|
35
|
-
*/
|
|
36
|
-
readonly limit: number;
|
|
37
|
-
/**
|
|
38
|
-
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
39
|
-
*/
|
|
40
|
-
private _isLocked;
|
|
41
|
-
/**
|
|
42
|
-
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
43
|
-
* the {@link #batch batch} is set to a new one.
|
|
44
|
-
*/
|
|
45
|
-
private _size;
|
|
46
|
-
/**
|
|
47
|
-
* The current batch instance.
|
|
48
|
-
*/
|
|
49
|
-
private _batch;
|
|
50
|
-
/**
|
|
51
|
-
* The callback to document the change event which later needs to be removed.
|
|
52
|
-
*/
|
|
53
|
-
private readonly _changeCallback;
|
|
54
|
-
/**
|
|
55
|
-
* The callback to document selection `change:attribute` and `change:range` events which resets the buffer.
|
|
56
|
-
*/
|
|
57
|
-
private readonly _selectionChangeCallback;
|
|
58
|
-
/**
|
|
59
|
-
* Creates a new instance of the change buffer.
|
|
60
|
-
*
|
|
61
|
-
* @param limit The maximum number of atomic changes which can be contained in one batch.
|
|
62
|
-
*/
|
|
63
|
-
constructor(model: Model, limit?: number);
|
|
64
|
-
/**
|
|
65
|
-
* The current batch to which a feature should add its operations. Once the {@link #size}
|
|
66
|
-
* is reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
67
|
-
*/
|
|
68
|
-
get batch(): Batch;
|
|
69
|
-
/**
|
|
70
|
-
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
71
|
-
* the {@link #batch batch} is set to a new one.
|
|
72
|
-
*/
|
|
73
|
-
get size(): number;
|
|
74
|
-
/**
|
|
75
|
-
* The input number of changes into the buffer. Once the {@link #size} is
|
|
76
|
-
* reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
77
|
-
*
|
|
78
|
-
* @param changeCount The number of atomic changes to input.
|
|
79
|
-
*/
|
|
80
|
-
input(changeCount: number): void;
|
|
81
|
-
/**
|
|
82
|
-
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
83
|
-
*/
|
|
84
|
-
get isLocked(): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Locks the buffer.
|
|
87
|
-
*/
|
|
88
|
-
lock(): void;
|
|
89
|
-
/**
|
|
90
|
-
* Unlocks the buffer.
|
|
91
|
-
*/
|
|
92
|
-
unlock(): void;
|
|
93
|
-
/**
|
|
94
|
-
* Destroys the buffer.
|
|
95
|
-
*/
|
|
96
|
-
destroy(): void;
|
|
97
|
-
/**
|
|
98
|
-
* Resets the change buffer.
|
|
99
|
-
*
|
|
100
|
-
* @param ignoreLock Whether internal lock {@link #isLocked} should be ignored.
|
|
101
|
-
*/
|
|
102
|
-
private _reset;
|
|
103
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module typing/utils/changebuffer
|
|
7
|
+
*/
|
|
8
|
+
import type { Model, Batch } from '@ckeditor/ckeditor5-engine';
|
|
9
|
+
/**
|
|
10
|
+
* Change buffer allows to group atomic changes (like characters that have been typed) into
|
|
11
|
+
* {@link module:engine/model/batch~Batch batches}.
|
|
12
|
+
*
|
|
13
|
+
* Batches represent single undo steps, hence changes added to one single batch are undone together.
|
|
14
|
+
*
|
|
15
|
+
* The buffer has a configurable limit of atomic changes that it can accommodate. After the limit was
|
|
16
|
+
* exceeded (see {@link ~ChangeBuffer#input}), a new batch is created in {@link ~ChangeBuffer#batch}.
|
|
17
|
+
*
|
|
18
|
+
* To use the change buffer you need to let it know about the number of changes that were added to the batch:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const buffer = new ChangeBuffer( model, LIMIT );
|
|
22
|
+
*
|
|
23
|
+
* // Later on in your feature:
|
|
24
|
+
* buffer.batch.insert( pos, insertedCharacters );
|
|
25
|
+
* buffer.input( insertedCharacters.length );
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export default class ChangeBuffer {
|
|
29
|
+
/**
|
|
30
|
+
* The model instance.
|
|
31
|
+
*/
|
|
32
|
+
readonly model: Model;
|
|
33
|
+
/**
|
|
34
|
+
* The maximum number of atomic changes which can be contained in one batch.
|
|
35
|
+
*/
|
|
36
|
+
readonly limit: number;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
39
|
+
*/
|
|
40
|
+
private _isLocked;
|
|
41
|
+
/**
|
|
42
|
+
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
43
|
+
* the {@link #batch batch} is set to a new one.
|
|
44
|
+
*/
|
|
45
|
+
private _size;
|
|
46
|
+
/**
|
|
47
|
+
* The current batch instance.
|
|
48
|
+
*/
|
|
49
|
+
private _batch;
|
|
50
|
+
/**
|
|
51
|
+
* The callback to document the change event which later needs to be removed.
|
|
52
|
+
*/
|
|
53
|
+
private readonly _changeCallback;
|
|
54
|
+
/**
|
|
55
|
+
* The callback to document selection `change:attribute` and `change:range` events which resets the buffer.
|
|
56
|
+
*/
|
|
57
|
+
private readonly _selectionChangeCallback;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new instance of the change buffer.
|
|
60
|
+
*
|
|
61
|
+
* @param limit The maximum number of atomic changes which can be contained in one batch.
|
|
62
|
+
*/
|
|
63
|
+
constructor(model: Model, limit?: number);
|
|
64
|
+
/**
|
|
65
|
+
* The current batch to which a feature should add its operations. Once the {@link #size}
|
|
66
|
+
* is reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
67
|
+
*/
|
|
68
|
+
get batch(): Batch;
|
|
69
|
+
/**
|
|
70
|
+
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
71
|
+
* the {@link #batch batch} is set to a new one.
|
|
72
|
+
*/
|
|
73
|
+
get size(): number;
|
|
74
|
+
/**
|
|
75
|
+
* The input number of changes into the buffer. Once the {@link #size} is
|
|
76
|
+
* reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
77
|
+
*
|
|
78
|
+
* @param changeCount The number of atomic changes to input.
|
|
79
|
+
*/
|
|
80
|
+
input(changeCount: number): void;
|
|
81
|
+
/**
|
|
82
|
+
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
83
|
+
*/
|
|
84
|
+
get isLocked(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Locks the buffer.
|
|
87
|
+
*/
|
|
88
|
+
lock(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Unlocks the buffer.
|
|
91
|
+
*/
|
|
92
|
+
unlock(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Destroys the buffer.
|
|
95
|
+
*/
|
|
96
|
+
destroy(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Resets the change buffer.
|
|
99
|
+
*
|
|
100
|
+
* @param ignoreLock Whether internal lock {@link #isLocked} should be ignored.
|
|
101
|
+
*/
|
|
102
|
+
private _reset;
|
|
103
|
+
}
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Change buffer allows to group atomic changes (like characters that have been typed) into
|
|
7
|
-
* {@link module:engine/model/batch~Batch batches}.
|
|
8
|
-
*
|
|
9
|
-
* Batches represent single undo steps, hence changes added to one single batch are undone together.
|
|
10
|
-
*
|
|
11
|
-
* The buffer has a configurable limit of atomic changes that it can accommodate. After the limit was
|
|
12
|
-
* exceeded (see {@link ~ChangeBuffer#input}), a new batch is created in {@link ~ChangeBuffer#batch}.
|
|
13
|
-
*
|
|
14
|
-
* To use the change buffer you need to let it know about the number of changes that were added to the batch:
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* const buffer = new ChangeBuffer( model, LIMIT );
|
|
18
|
-
*
|
|
19
|
-
* // Later on in your feature:
|
|
20
|
-
* buffer.batch.insert( pos, insertedCharacters );
|
|
21
|
-
* buffer.input( insertedCharacters.length );
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export default class ChangeBuffer {
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new instance of the change buffer.
|
|
27
|
-
*
|
|
28
|
-
* @param limit The maximum number of atomic changes which can be contained in one batch.
|
|
29
|
-
*/
|
|
30
|
-
constructor(model, limit = 20) {
|
|
31
|
-
/**
|
|
32
|
-
* The current batch instance.
|
|
33
|
-
*/
|
|
34
|
-
this._batch = null;
|
|
35
|
-
this.model = model;
|
|
36
|
-
this._size = 0;
|
|
37
|
-
this.limit = limit;
|
|
38
|
-
this._isLocked = false;
|
|
39
|
-
// The function to be called in order to notify the buffer about batches which appeared in the document.
|
|
40
|
-
// The callback will check whether it is a new batch and in that case the buffer will be flushed.
|
|
41
|
-
//
|
|
42
|
-
// The reason why the buffer needs to be flushed whenever a new batch appears is that the changes added afterwards
|
|
43
|
-
// should be added to a new batch. For instance, when the user types, then inserts an image, and then types again,
|
|
44
|
-
// the characters typed after inserting the image should be added to a different batch than the characters typed before.
|
|
45
|
-
this._changeCallback = (evt, batch) => {
|
|
46
|
-
if (batch.isLocal && batch.isUndoable && batch !== this._batch) {
|
|
47
|
-
this._reset(true);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
this._selectionChangeCallback = () => {
|
|
51
|
-
this._reset();
|
|
52
|
-
};
|
|
53
|
-
this.model.document.on('change', this._changeCallback);
|
|
54
|
-
this.model.document.selection.on('change:range', this._selectionChangeCallback);
|
|
55
|
-
this.model.document.selection.on('change:attribute', this._selectionChangeCallback);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* The current batch to which a feature should add its operations. Once the {@link #size}
|
|
59
|
-
* is reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
60
|
-
*/
|
|
61
|
-
get batch() {
|
|
62
|
-
if (!this._batch) {
|
|
63
|
-
this._batch = this.model.createBatch({ isTyping: true });
|
|
64
|
-
}
|
|
65
|
-
return this._batch;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
69
|
-
* the {@link #batch batch} is set to a new one.
|
|
70
|
-
*/
|
|
71
|
-
get size() {
|
|
72
|
-
return this._size;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* The input number of changes into the buffer. Once the {@link #size} is
|
|
76
|
-
* reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
77
|
-
*
|
|
78
|
-
* @param changeCount The number of atomic changes to input.
|
|
79
|
-
*/
|
|
80
|
-
input(changeCount) {
|
|
81
|
-
this._size += changeCount;
|
|
82
|
-
if (this._size >= this.limit) {
|
|
83
|
-
this._reset(true);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
88
|
-
*/
|
|
89
|
-
get isLocked() {
|
|
90
|
-
return this._isLocked;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Locks the buffer.
|
|
94
|
-
*/
|
|
95
|
-
lock() {
|
|
96
|
-
this._isLocked = true;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Unlocks the buffer.
|
|
100
|
-
*/
|
|
101
|
-
unlock() {
|
|
102
|
-
this._isLocked = false;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Destroys the buffer.
|
|
106
|
-
*/
|
|
107
|
-
destroy() {
|
|
108
|
-
this.model.document.off('change', this._changeCallback);
|
|
109
|
-
this.model.document.selection.off('change:range', this._selectionChangeCallback);
|
|
110
|
-
this.model.document.selection.off('change:attribute', this._selectionChangeCallback);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Resets the change buffer.
|
|
114
|
-
*
|
|
115
|
-
* @param ignoreLock Whether internal lock {@link #isLocked} should be ignored.
|
|
116
|
-
*/
|
|
117
|
-
_reset(ignoreLock = false) {
|
|
118
|
-
if (!this.isLocked || ignoreLock) {
|
|
119
|
-
this._batch = null;
|
|
120
|
-
this._size = 0;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Change buffer allows to group atomic changes (like characters that have been typed) into
|
|
7
|
+
* {@link module:engine/model/batch~Batch batches}.
|
|
8
|
+
*
|
|
9
|
+
* Batches represent single undo steps, hence changes added to one single batch are undone together.
|
|
10
|
+
*
|
|
11
|
+
* The buffer has a configurable limit of atomic changes that it can accommodate. After the limit was
|
|
12
|
+
* exceeded (see {@link ~ChangeBuffer#input}), a new batch is created in {@link ~ChangeBuffer#batch}.
|
|
13
|
+
*
|
|
14
|
+
* To use the change buffer you need to let it know about the number of changes that were added to the batch:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const buffer = new ChangeBuffer( model, LIMIT );
|
|
18
|
+
*
|
|
19
|
+
* // Later on in your feature:
|
|
20
|
+
* buffer.batch.insert( pos, insertedCharacters );
|
|
21
|
+
* buffer.input( insertedCharacters.length );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export default class ChangeBuffer {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new instance of the change buffer.
|
|
27
|
+
*
|
|
28
|
+
* @param limit The maximum number of atomic changes which can be contained in one batch.
|
|
29
|
+
*/
|
|
30
|
+
constructor(model, limit = 20) {
|
|
31
|
+
/**
|
|
32
|
+
* The current batch instance.
|
|
33
|
+
*/
|
|
34
|
+
this._batch = null;
|
|
35
|
+
this.model = model;
|
|
36
|
+
this._size = 0;
|
|
37
|
+
this.limit = limit;
|
|
38
|
+
this._isLocked = false;
|
|
39
|
+
// The function to be called in order to notify the buffer about batches which appeared in the document.
|
|
40
|
+
// The callback will check whether it is a new batch and in that case the buffer will be flushed.
|
|
41
|
+
//
|
|
42
|
+
// The reason why the buffer needs to be flushed whenever a new batch appears is that the changes added afterwards
|
|
43
|
+
// should be added to a new batch. For instance, when the user types, then inserts an image, and then types again,
|
|
44
|
+
// the characters typed after inserting the image should be added to a different batch than the characters typed before.
|
|
45
|
+
this._changeCallback = (evt, batch) => {
|
|
46
|
+
if (batch.isLocal && batch.isUndoable && batch !== this._batch) {
|
|
47
|
+
this._reset(true);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this._selectionChangeCallback = () => {
|
|
51
|
+
this._reset();
|
|
52
|
+
};
|
|
53
|
+
this.model.document.on('change', this._changeCallback);
|
|
54
|
+
this.model.document.selection.on('change:range', this._selectionChangeCallback);
|
|
55
|
+
this.model.document.selection.on('change:attribute', this._selectionChangeCallback);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The current batch to which a feature should add its operations. Once the {@link #size}
|
|
59
|
+
* is reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
60
|
+
*/
|
|
61
|
+
get batch() {
|
|
62
|
+
if (!this._batch) {
|
|
63
|
+
this._batch = this.model.createBatch({ isTyping: true });
|
|
64
|
+
}
|
|
65
|
+
return this._batch;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The number of atomic changes in the buffer. Once it exceeds the {@link #limit},
|
|
69
|
+
* the {@link #batch batch} is set to a new one.
|
|
70
|
+
*/
|
|
71
|
+
get size() {
|
|
72
|
+
return this._size;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The input number of changes into the buffer. Once the {@link #size} is
|
|
76
|
+
* reached or exceeds the {@link #limit}, the batch is set to a new instance and the size is reset.
|
|
77
|
+
*
|
|
78
|
+
* @param changeCount The number of atomic changes to input.
|
|
79
|
+
*/
|
|
80
|
+
input(changeCount) {
|
|
81
|
+
this._size += changeCount;
|
|
82
|
+
if (this._size >= this.limit) {
|
|
83
|
+
this._reset(true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Whether the buffer is locked. A locked buffer cannot be reset unless it gets unlocked.
|
|
88
|
+
*/
|
|
89
|
+
get isLocked() {
|
|
90
|
+
return this._isLocked;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Locks the buffer.
|
|
94
|
+
*/
|
|
95
|
+
lock() {
|
|
96
|
+
this._isLocked = true;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Unlocks the buffer.
|
|
100
|
+
*/
|
|
101
|
+
unlock() {
|
|
102
|
+
this._isLocked = false;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Destroys the buffer.
|
|
106
|
+
*/
|
|
107
|
+
destroy() {
|
|
108
|
+
this.model.document.off('change', this._changeCallback);
|
|
109
|
+
this.model.document.selection.off('change:range', this._selectionChangeCallback);
|
|
110
|
+
this.model.document.selection.off('change:attribute', this._selectionChangeCallback);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Resets the change buffer.
|
|
114
|
+
*
|
|
115
|
+
* @param ignoreLock Whether internal lock {@link #isLocked} should be ignored.
|
|
116
|
+
*/
|
|
117
|
+
_reset(ignoreLock = false) {
|
|
118
|
+
if (!this.isLocked || ignoreLock) {
|
|
119
|
+
this._batch = null;
|
|
120
|
+
this._size = 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module typing/utils/findattributerange
|
|
7
|
-
*/
|
|
8
|
-
import type { Position, Model, Range } from '@ckeditor/ckeditor5-engine';
|
|
9
|
-
/**
|
|
10
|
-
* Returns a model range that covers all consecutive nodes with the same `attributeName` and its `value`
|
|
11
|
-
* that intersect the given `position`.
|
|
12
|
-
*
|
|
13
|
-
* It can be used e.g. to get the entire range on which the `linkHref` attribute needs to be changed when having a
|
|
14
|
-
* selection inside a link.
|
|
15
|
-
*
|
|
16
|
-
* @param position The start position.
|
|
17
|
-
* @param attributeName The attribute name.
|
|
18
|
-
* @param value The attribute value.
|
|
19
|
-
* @param model The model instance.
|
|
20
|
-
* @returns The link range.
|
|
21
|
-
*/
|
|
22
|
-
export default function findAttributeRange(position: Position, attributeName: string, value: unknown, model: Model): Range;
|
|
23
|
-
/**
|
|
24
|
-
* Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
|
|
25
|
-
* and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
|
|
26
|
-
*
|
|
27
|
-
* @param position The start position.
|
|
28
|
-
* @param attributeName The attribute name.
|
|
29
|
-
* @param value The attribute value.
|
|
30
|
-
* @param lookBack Whether the walk direction is forward (`false`) or backward (`true`).
|
|
31
|
-
* @returns The position just before the last matched node.
|
|
32
|
-
*/
|
|
33
|
-
export declare function findAttributeRangeBound(position: Position, attributeName: string, value: unknown, lookBack: boolean, model: Model): Position;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module typing/utils/findattributerange
|
|
7
|
+
*/
|
|
8
|
+
import type { Position, Model, Range } from '@ckeditor/ckeditor5-engine';
|
|
9
|
+
/**
|
|
10
|
+
* Returns a model range that covers all consecutive nodes with the same `attributeName` and its `value`
|
|
11
|
+
* that intersect the given `position`.
|
|
12
|
+
*
|
|
13
|
+
* It can be used e.g. to get the entire range on which the `linkHref` attribute needs to be changed when having a
|
|
14
|
+
* selection inside a link.
|
|
15
|
+
*
|
|
16
|
+
* @param position The start position.
|
|
17
|
+
* @param attributeName The attribute name.
|
|
18
|
+
* @param value The attribute value.
|
|
19
|
+
* @param model The model instance.
|
|
20
|
+
* @returns The link range.
|
|
21
|
+
*/
|
|
22
|
+
export default function findAttributeRange(position: Position, attributeName: string, value: unknown, model: Model): Range;
|
|
23
|
+
/**
|
|
24
|
+
* Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
|
|
25
|
+
* and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
|
|
26
|
+
*
|
|
27
|
+
* @param position The start position.
|
|
28
|
+
* @param attributeName The attribute name.
|
|
29
|
+
* @param value The attribute value.
|
|
30
|
+
* @param lookBack Whether the walk direction is forward (`false`) or backward (`true`).
|
|
31
|
+
* @returns The position just before the last matched node.
|
|
32
|
+
*/
|
|
33
|
+
export declare function findAttributeRangeBound(position: Position, attributeName: string, value: unknown, lookBack: boolean, model: Model): Position;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Returns a model range that covers all consecutive nodes with the same `attributeName` and its `value`
|
|
7
|
-
* that intersect the given `position`.
|
|
8
|
-
*
|
|
9
|
-
* It can be used e.g. to get the entire range on which the `linkHref` attribute needs to be changed when having a
|
|
10
|
-
* selection inside a link.
|
|
11
|
-
*
|
|
12
|
-
* @param position The start position.
|
|
13
|
-
* @param attributeName The attribute name.
|
|
14
|
-
* @param value The attribute value.
|
|
15
|
-
* @param model The model instance.
|
|
16
|
-
* @returns The link range.
|
|
17
|
-
*/
|
|
18
|
-
export default function findAttributeRange(position, attributeName, value, model) {
|
|
19
|
-
return model.createRange(findAttributeRangeBound(position, attributeName, value, true, model), findAttributeRangeBound(position, attributeName, value, false, model));
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
|
|
23
|
-
* and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
|
|
24
|
-
*
|
|
25
|
-
* @param position The start position.
|
|
26
|
-
* @param attributeName The attribute name.
|
|
27
|
-
* @param value The attribute value.
|
|
28
|
-
* @param lookBack Whether the walk direction is forward (`false`) or backward (`true`).
|
|
29
|
-
* @returns The position just before the last matched node.
|
|
30
|
-
*/
|
|
31
|
-
export function findAttributeRangeBound(position, attributeName, value, lookBack, model) {
|
|
32
|
-
// Get node before or after position (depends on `lookBack` flag).
|
|
33
|
-
// When position is inside text node then start searching from text node.
|
|
34
|
-
let node = position.textNode || (lookBack ? position.nodeBefore : position.nodeAfter);
|
|
35
|
-
let lastNode = null;
|
|
36
|
-
while (node && node.getAttribute(attributeName) == value) {
|
|
37
|
-
lastNode = node;
|
|
38
|
-
node = lookBack ? node.previousSibling : node.nextSibling;
|
|
39
|
-
}
|
|
40
|
-
return lastNode ? model.createPositionAt(lastNode, lookBack ? 'before' : 'after') : position;
|
|
41
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns a model range that covers all consecutive nodes with the same `attributeName` and its `value`
|
|
7
|
+
* that intersect the given `position`.
|
|
8
|
+
*
|
|
9
|
+
* It can be used e.g. to get the entire range on which the `linkHref` attribute needs to be changed when having a
|
|
10
|
+
* selection inside a link.
|
|
11
|
+
*
|
|
12
|
+
* @param position The start position.
|
|
13
|
+
* @param attributeName The attribute name.
|
|
14
|
+
* @param value The attribute value.
|
|
15
|
+
* @param model The model instance.
|
|
16
|
+
* @returns The link range.
|
|
17
|
+
*/
|
|
18
|
+
export default function findAttributeRange(position, attributeName, value, model) {
|
|
19
|
+
return model.createRange(findAttributeRangeBound(position, attributeName, value, true, model), findAttributeRangeBound(position, attributeName, value, false, model));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Walks forward or backward (depends on the `lookBack` flag), node by node, as long as they have the same attribute value
|
|
23
|
+
* and returns a position just before or after (depends on the `lookBack` flag) the last matched node.
|
|
24
|
+
*
|
|
25
|
+
* @param position The start position.
|
|
26
|
+
* @param attributeName The attribute name.
|
|
27
|
+
* @param value The attribute value.
|
|
28
|
+
* @param lookBack Whether the walk direction is forward (`false`) or backward (`true`).
|
|
29
|
+
* @returns The position just before the last matched node.
|
|
30
|
+
*/
|
|
31
|
+
export function findAttributeRangeBound(position, attributeName, value, lookBack, model) {
|
|
32
|
+
// Get node before or after position (depends on `lookBack` flag).
|
|
33
|
+
// When position is inside text node then start searching from text node.
|
|
34
|
+
let node = position.textNode || (lookBack ? position.nodeBefore : position.nodeAfter);
|
|
35
|
+
let lastNode = null;
|
|
36
|
+
while (node && node.getAttribute(attributeName) == value) {
|
|
37
|
+
lastNode = node;
|
|
38
|
+
node = lookBack ? node.previousSibling : node.nextSibling;
|
|
39
|
+
}
|
|
40
|
+
return lastNode ? model.createPositionAt(lastNode, lookBack ? 'before' : 'after') : position;
|
|
41
|
+
}
|