@ckeditor/ckeditor5-undo 40.0.0 → 40.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/src/undo.d.ts CHANGED
@@ -1,117 +1,117 @@
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 undo/undo
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import UndoEditing from './undoediting';
10
- import UndoUI from './undoui';
11
- /**
12
- * The undo feature.
13
- *
14
- * This is a "glue" plugin which loads the {@link module:undo/undoediting~UndoEditing undo editing feature}
15
- * and the {@link module:undo/undoui~UndoUI undo UI feature}.
16
- *
17
- * Below is an explanation of the undo mechanism working together with {@link module:engine/model/history~History History}:
18
- *
19
- * Whenever an {@link module:engine/model/operation/operation~Operation operation} is applied to the
20
- * {@link module:engine/model/document~Document document}, it is saved to `History` as is.
21
- * The {@link module:engine/model/batch~Batch batch} that owns that operation is also saved, in
22
- * {@link module:undo/undocommand~UndoCommand}, together with the selection that was present in the document before the
23
- * operation was applied. A batch is saved instead of the operation because changes are undone batch-by-batch, not operation-by-operation
24
- * and a batch is seen as one undo step.
25
- *
26
- * After changes happen to the document, the `History` and `UndoCommand` stack can be represented as follows:
27
- *
28
- * ```
29
- * History Undo stack
30
- * ============== ==================================
31
- * [operation A1] [ batch A ]
32
- * [operation B1] [ batch B ]
33
- * [operation B2] [ batch C ]
34
- * [operation C1]
35
- * [operation C2]
36
- * [operation B3]
37
- * [operation C3]
38
- * ```
39
- *
40
- * Where operations starting with the same letter are from same batch.
41
- *
42
- * Undoing a batch means that a set of operations which will reverse the effects of that batch needs to be generated.
43
- * For example, if a batch added several letters, undoing the batch should remove them. It is important to apply undoing
44
- * operations in the reversed order, so if a batch has operation `X`, `Y`, `Z`, reversed operations `Zr`, `Yr` and `Xr`
45
- * need to be applied. Otherwise reversed operation `Xr` would operate on a wrong document state, because operation `X`
46
- * does not know that operations `Y` and `Z` happened.
47
- *
48
- * After operations from an undone batch got {@link module:engine/model/operation/operation~Operation#getReversed reversed},
49
- * one needs to make sure if they are ready to be applied. In the scenario above, operation `C3` is the last operation and `C3r`
50
- * bases on up-to-date document state, so it can be applied to the document.
51
- *
52
- * ```
53
- * History Undo stack
54
- * ================= ==================================
55
- * [ operation A1 ] [ batch A ]
56
- * [ operation B1 ] [ batch B ]
57
- * [ operation B2 ] [ processing undoing batch C ]
58
- * [ operation C1 ]
59
- * [ operation C2 ]
60
- * [ operation B3 ]
61
- * [ operation C3 ]
62
- * [ operation C3r ]
63
- * ```
64
- *
65
- * Next is operation `C2`, reversed to `C2r`. `C2r` bases on `C2`, so it bases on the wrong document state. It needs to be
66
- * transformed by operations from history that happened after it, so it "knows" about them. Let us assume that `C2' = C2r * B3 * C3 * C3r`,
67
- * where `*` means "transformed by". Rest of operations from that batch are processed in the same fashion.
68
- *
69
- * ```
70
- * History Undo stack Redo stack
71
- * ================= ================================== ==================================
72
- * [ operation A1 ] [ batch A ] [ batch Cr ]
73
- * [ operation B1 ] [ batch B ]
74
- * [ operation B2 ]
75
- * [ operation C1 ]
76
- * [ operation C2 ]
77
- * [ operation B3 ]
78
- * [ operation C3 ]
79
- * [ operation C3r ]
80
- * [ operation C2' ]
81
- * [ operation C1' ]
82
- * ```
83
- *
84
- * Selective undo works on the same basis, however, instead of undoing the last batch in the undo stack, any batch can be undone.
85
- * The same algorithm applies: operations from a batch (i.e. `A1`) are reversed and then transformed by operations stored in history.
86
- *
87
- * Redo also is very similar to undo. It has its own stack that is filled with undoing (reversed batches). Operations from
88
- * the batch that is re-done are reversed-back, transformed in proper order and applied to the document.
89
- *
90
- * ```
91
- * History Undo stack Redo stack
92
- * ================= ================================== ==================================
93
- * [ operation A1 ] [ batch A ]
94
- * [ operation B1 ] [ batch B ]
95
- * [ operation B2 ] [ batch Crr ]
96
- * [ operation C1 ]
97
- * [ operation C2 ]
98
- * [ operation B3 ]
99
- * [ operation C3 ]
100
- * [ operation C3r ]
101
- * [ operation C2' ]
102
- * [ operation C1' ]
103
- * [ operation C1'r]
104
- * [ operation C2'r]
105
- * [ operation C3rr]
106
- * ```
107
- */
108
- export default class Undo extends Plugin {
109
- /**
110
- * @inheritDoc
111
- */
112
- static get requires(): readonly [typeof UndoEditing, typeof UndoUI];
113
- /**
114
- * @inheritDoc
115
- */
116
- static get pluginName(): "Undo";
117
- }
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 undo/undo
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import UndoEditing from './undoediting';
10
+ import UndoUI from './undoui';
11
+ /**
12
+ * The undo feature.
13
+ *
14
+ * This is a "glue" plugin which loads the {@link module:undo/undoediting~UndoEditing undo editing feature}
15
+ * and the {@link module:undo/undoui~UndoUI undo UI feature}.
16
+ *
17
+ * Below is an explanation of the undo mechanism working together with {@link module:engine/model/history~History History}:
18
+ *
19
+ * Whenever an {@link module:engine/model/operation/operation~Operation operation} is applied to the
20
+ * {@link module:engine/model/document~Document document}, it is saved to `History` as is.
21
+ * The {@link module:engine/model/batch~Batch batch} that owns that operation is also saved, in
22
+ * {@link module:undo/undocommand~UndoCommand}, together with the selection that was present in the document before the
23
+ * operation was applied. A batch is saved instead of the operation because changes are undone batch-by-batch, not operation-by-operation
24
+ * and a batch is seen as one undo step.
25
+ *
26
+ * After changes happen to the document, the `History` and `UndoCommand` stack can be represented as follows:
27
+ *
28
+ * ```
29
+ * History Undo stack
30
+ * ============== ==================================
31
+ * [operation A1] [ batch A ]
32
+ * [operation B1] [ batch B ]
33
+ * [operation B2] [ batch C ]
34
+ * [operation C1]
35
+ * [operation C2]
36
+ * [operation B3]
37
+ * [operation C3]
38
+ * ```
39
+ *
40
+ * Where operations starting with the same letter are from same batch.
41
+ *
42
+ * Undoing a batch means that a set of operations which will reverse the effects of that batch needs to be generated.
43
+ * For example, if a batch added several letters, undoing the batch should remove them. It is important to apply undoing
44
+ * operations in the reversed order, so if a batch has operation `X`, `Y`, `Z`, reversed operations `Zr`, `Yr` and `Xr`
45
+ * need to be applied. Otherwise reversed operation `Xr` would operate on a wrong document state, because operation `X`
46
+ * does not know that operations `Y` and `Z` happened.
47
+ *
48
+ * After operations from an undone batch got {@link module:engine/model/operation/operation~Operation#getReversed reversed},
49
+ * one needs to make sure if they are ready to be applied. In the scenario above, operation `C3` is the last operation and `C3r`
50
+ * bases on up-to-date document state, so it can be applied to the document.
51
+ *
52
+ * ```
53
+ * History Undo stack
54
+ * ================= ==================================
55
+ * [ operation A1 ] [ batch A ]
56
+ * [ operation B1 ] [ batch B ]
57
+ * [ operation B2 ] [ processing undoing batch C ]
58
+ * [ operation C1 ]
59
+ * [ operation C2 ]
60
+ * [ operation B3 ]
61
+ * [ operation C3 ]
62
+ * [ operation C3r ]
63
+ * ```
64
+ *
65
+ * Next is operation `C2`, reversed to `C2r`. `C2r` bases on `C2`, so it bases on the wrong document state. It needs to be
66
+ * transformed by operations from history that happened after it, so it "knows" about them. Let us assume that `C2' = C2r * B3 * C3 * C3r`,
67
+ * where `*` means "transformed by". Rest of operations from that batch are processed in the same fashion.
68
+ *
69
+ * ```
70
+ * History Undo stack Redo stack
71
+ * ================= ================================== ==================================
72
+ * [ operation A1 ] [ batch A ] [ batch Cr ]
73
+ * [ operation B1 ] [ batch B ]
74
+ * [ operation B2 ]
75
+ * [ operation C1 ]
76
+ * [ operation C2 ]
77
+ * [ operation B3 ]
78
+ * [ operation C3 ]
79
+ * [ operation C3r ]
80
+ * [ operation C2' ]
81
+ * [ operation C1' ]
82
+ * ```
83
+ *
84
+ * Selective undo works on the same basis, however, instead of undoing the last batch in the undo stack, any batch can be undone.
85
+ * The same algorithm applies: operations from a batch (i.e. `A1`) are reversed and then transformed by operations stored in history.
86
+ *
87
+ * Redo also is very similar to undo. It has its own stack that is filled with undoing (reversed batches). Operations from
88
+ * the batch that is re-done are reversed-back, transformed in proper order and applied to the document.
89
+ *
90
+ * ```
91
+ * History Undo stack Redo stack
92
+ * ================= ================================== ==================================
93
+ * [ operation A1 ] [ batch A ]
94
+ * [ operation B1 ] [ batch B ]
95
+ * [ operation B2 ] [ batch Crr ]
96
+ * [ operation C1 ]
97
+ * [ operation C2 ]
98
+ * [ operation B3 ]
99
+ * [ operation C3 ]
100
+ * [ operation C3r ]
101
+ * [ operation C2' ]
102
+ * [ operation C1' ]
103
+ * [ operation C1'r]
104
+ * [ operation C2'r]
105
+ * [ operation C3rr]
106
+ * ```
107
+ */
108
+ export default class Undo extends Plugin {
109
+ /**
110
+ * @inheritDoc
111
+ */
112
+ static get requires(): readonly [typeof UndoEditing, typeof UndoUI];
113
+ /**
114
+ * @inheritDoc
115
+ */
116
+ static get pluginName(): "Undo";
117
+ }
package/src/undo.js CHANGED
@@ -1,121 +1,121 @@
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 undo/undo
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import UndoEditing from './undoediting';
10
- import UndoUI from './undoui';
11
- /**
12
- * The undo feature.
13
- *
14
- * This is a "glue" plugin which loads the {@link module:undo/undoediting~UndoEditing undo editing feature}
15
- * and the {@link module:undo/undoui~UndoUI undo UI feature}.
16
- *
17
- * Below is an explanation of the undo mechanism working together with {@link module:engine/model/history~History History}:
18
- *
19
- * Whenever an {@link module:engine/model/operation/operation~Operation operation} is applied to the
20
- * {@link module:engine/model/document~Document document}, it is saved to `History` as is.
21
- * The {@link module:engine/model/batch~Batch batch} that owns that operation is also saved, in
22
- * {@link module:undo/undocommand~UndoCommand}, together with the selection that was present in the document before the
23
- * operation was applied. A batch is saved instead of the operation because changes are undone batch-by-batch, not operation-by-operation
24
- * and a batch is seen as one undo step.
25
- *
26
- * After changes happen to the document, the `History` and `UndoCommand` stack can be represented as follows:
27
- *
28
- * ```
29
- * History Undo stack
30
- * ============== ==================================
31
- * [operation A1] [ batch A ]
32
- * [operation B1] [ batch B ]
33
- * [operation B2] [ batch C ]
34
- * [operation C1]
35
- * [operation C2]
36
- * [operation B3]
37
- * [operation C3]
38
- * ```
39
- *
40
- * Where operations starting with the same letter are from same batch.
41
- *
42
- * Undoing a batch means that a set of operations which will reverse the effects of that batch needs to be generated.
43
- * For example, if a batch added several letters, undoing the batch should remove them. It is important to apply undoing
44
- * operations in the reversed order, so if a batch has operation `X`, `Y`, `Z`, reversed operations `Zr`, `Yr` and `Xr`
45
- * need to be applied. Otherwise reversed operation `Xr` would operate on a wrong document state, because operation `X`
46
- * does not know that operations `Y` and `Z` happened.
47
- *
48
- * After operations from an undone batch got {@link module:engine/model/operation/operation~Operation#getReversed reversed},
49
- * one needs to make sure if they are ready to be applied. In the scenario above, operation `C3` is the last operation and `C3r`
50
- * bases on up-to-date document state, so it can be applied to the document.
51
- *
52
- * ```
53
- * History Undo stack
54
- * ================= ==================================
55
- * [ operation A1 ] [ batch A ]
56
- * [ operation B1 ] [ batch B ]
57
- * [ operation B2 ] [ processing undoing batch C ]
58
- * [ operation C1 ]
59
- * [ operation C2 ]
60
- * [ operation B3 ]
61
- * [ operation C3 ]
62
- * [ operation C3r ]
63
- * ```
64
- *
65
- * Next is operation `C2`, reversed to `C2r`. `C2r` bases on `C2`, so it bases on the wrong document state. It needs to be
66
- * transformed by operations from history that happened after it, so it "knows" about them. Let us assume that `C2' = C2r * B3 * C3 * C3r`,
67
- * where `*` means "transformed by". Rest of operations from that batch are processed in the same fashion.
68
- *
69
- * ```
70
- * History Undo stack Redo stack
71
- * ================= ================================== ==================================
72
- * [ operation A1 ] [ batch A ] [ batch Cr ]
73
- * [ operation B1 ] [ batch B ]
74
- * [ operation B2 ]
75
- * [ operation C1 ]
76
- * [ operation C2 ]
77
- * [ operation B3 ]
78
- * [ operation C3 ]
79
- * [ operation C3r ]
80
- * [ operation C2' ]
81
- * [ operation C1' ]
82
- * ```
83
- *
84
- * Selective undo works on the same basis, however, instead of undoing the last batch in the undo stack, any batch can be undone.
85
- * The same algorithm applies: operations from a batch (i.e. `A1`) are reversed and then transformed by operations stored in history.
86
- *
87
- * Redo also is very similar to undo. It has its own stack that is filled with undoing (reversed batches). Operations from
88
- * the batch that is re-done are reversed-back, transformed in proper order and applied to the document.
89
- *
90
- * ```
91
- * History Undo stack Redo stack
92
- * ================= ================================== ==================================
93
- * [ operation A1 ] [ batch A ]
94
- * [ operation B1 ] [ batch B ]
95
- * [ operation B2 ] [ batch Crr ]
96
- * [ operation C1 ]
97
- * [ operation C2 ]
98
- * [ operation B3 ]
99
- * [ operation C3 ]
100
- * [ operation C3r ]
101
- * [ operation C2' ]
102
- * [ operation C1' ]
103
- * [ operation C1'r]
104
- * [ operation C2'r]
105
- * [ operation C3rr]
106
- * ```
107
- */
108
- export default class Undo extends Plugin {
109
- /**
110
- * @inheritDoc
111
- */
112
- static get requires() {
113
- return [UndoEditing, UndoUI];
114
- }
115
- /**
116
- * @inheritDoc
117
- */
118
- static get pluginName() {
119
- return 'Undo';
120
- }
121
- }
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 undo/undo
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import UndoEditing from './undoediting';
10
+ import UndoUI from './undoui';
11
+ /**
12
+ * The undo feature.
13
+ *
14
+ * This is a "glue" plugin which loads the {@link module:undo/undoediting~UndoEditing undo editing feature}
15
+ * and the {@link module:undo/undoui~UndoUI undo UI feature}.
16
+ *
17
+ * Below is an explanation of the undo mechanism working together with {@link module:engine/model/history~History History}:
18
+ *
19
+ * Whenever an {@link module:engine/model/operation/operation~Operation operation} is applied to the
20
+ * {@link module:engine/model/document~Document document}, it is saved to `History` as is.
21
+ * The {@link module:engine/model/batch~Batch batch} that owns that operation is also saved, in
22
+ * {@link module:undo/undocommand~UndoCommand}, together with the selection that was present in the document before the
23
+ * operation was applied. A batch is saved instead of the operation because changes are undone batch-by-batch, not operation-by-operation
24
+ * and a batch is seen as one undo step.
25
+ *
26
+ * After changes happen to the document, the `History` and `UndoCommand` stack can be represented as follows:
27
+ *
28
+ * ```
29
+ * History Undo stack
30
+ * ============== ==================================
31
+ * [operation A1] [ batch A ]
32
+ * [operation B1] [ batch B ]
33
+ * [operation B2] [ batch C ]
34
+ * [operation C1]
35
+ * [operation C2]
36
+ * [operation B3]
37
+ * [operation C3]
38
+ * ```
39
+ *
40
+ * Where operations starting with the same letter are from same batch.
41
+ *
42
+ * Undoing a batch means that a set of operations which will reverse the effects of that batch needs to be generated.
43
+ * For example, if a batch added several letters, undoing the batch should remove them. It is important to apply undoing
44
+ * operations in the reversed order, so if a batch has operation `X`, `Y`, `Z`, reversed operations `Zr`, `Yr` and `Xr`
45
+ * need to be applied. Otherwise reversed operation `Xr` would operate on a wrong document state, because operation `X`
46
+ * does not know that operations `Y` and `Z` happened.
47
+ *
48
+ * After operations from an undone batch got {@link module:engine/model/operation/operation~Operation#getReversed reversed},
49
+ * one needs to make sure if they are ready to be applied. In the scenario above, operation `C3` is the last operation and `C3r`
50
+ * bases on up-to-date document state, so it can be applied to the document.
51
+ *
52
+ * ```
53
+ * History Undo stack
54
+ * ================= ==================================
55
+ * [ operation A1 ] [ batch A ]
56
+ * [ operation B1 ] [ batch B ]
57
+ * [ operation B2 ] [ processing undoing batch C ]
58
+ * [ operation C1 ]
59
+ * [ operation C2 ]
60
+ * [ operation B3 ]
61
+ * [ operation C3 ]
62
+ * [ operation C3r ]
63
+ * ```
64
+ *
65
+ * Next is operation `C2`, reversed to `C2r`. `C2r` bases on `C2`, so it bases on the wrong document state. It needs to be
66
+ * transformed by operations from history that happened after it, so it "knows" about them. Let us assume that `C2' = C2r * B3 * C3 * C3r`,
67
+ * where `*` means "transformed by". Rest of operations from that batch are processed in the same fashion.
68
+ *
69
+ * ```
70
+ * History Undo stack Redo stack
71
+ * ================= ================================== ==================================
72
+ * [ operation A1 ] [ batch A ] [ batch Cr ]
73
+ * [ operation B1 ] [ batch B ]
74
+ * [ operation B2 ]
75
+ * [ operation C1 ]
76
+ * [ operation C2 ]
77
+ * [ operation B3 ]
78
+ * [ operation C3 ]
79
+ * [ operation C3r ]
80
+ * [ operation C2' ]
81
+ * [ operation C1' ]
82
+ * ```
83
+ *
84
+ * Selective undo works on the same basis, however, instead of undoing the last batch in the undo stack, any batch can be undone.
85
+ * The same algorithm applies: operations from a batch (i.e. `A1`) are reversed and then transformed by operations stored in history.
86
+ *
87
+ * Redo also is very similar to undo. It has its own stack that is filled with undoing (reversed batches). Operations from
88
+ * the batch that is re-done are reversed-back, transformed in proper order and applied to the document.
89
+ *
90
+ * ```
91
+ * History Undo stack Redo stack
92
+ * ================= ================================== ==================================
93
+ * [ operation A1 ] [ batch A ]
94
+ * [ operation B1 ] [ batch B ]
95
+ * [ operation B2 ] [ batch Crr ]
96
+ * [ operation C1 ]
97
+ * [ operation C2 ]
98
+ * [ operation B3 ]
99
+ * [ operation C3 ]
100
+ * [ operation C3r ]
101
+ * [ operation C2' ]
102
+ * [ operation C1' ]
103
+ * [ operation C1'r]
104
+ * [ operation C2'r]
105
+ * [ operation C3rr]
106
+ * ```
107
+ */
108
+ export default class Undo extends Plugin {
109
+ /**
110
+ * @inheritDoc
111
+ */
112
+ static get requires() {
113
+ return [UndoEditing, UndoUI];
114
+ }
115
+ /**
116
+ * @inheritDoc
117
+ */
118
+ static get pluginName() {
119
+ return 'Undo';
120
+ }
121
+ }
@@ -1,37 +1,37 @@
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 undo/undocommand
7
- */
8
- import BaseCommand from './basecommand';
9
- import type { Batch } from '@ckeditor/ckeditor5-engine';
10
- /**
11
- * The undo command stores {@link module:engine/model/batch~Batch batches} applied to the
12
- * {@link module:engine/model/document~Document document} and is able to undo a batch by reversing it and transforming by
13
- * batches from {@link module:engine/model/document~Document#history history} that happened after the reversed batch.
14
- *
15
- * The undo command also takes care of restoring the {@link module:engine/model/document~Document#selection document selection}.
16
- */
17
- export default class UndoCommand extends BaseCommand {
18
- /**
19
- * Executes the command. This method reverts a {@link module:engine/model/batch~Batch batch} added to the command's stack, transforms
20
- * and applies the reverted version on the {@link module:engine/model/document~Document document} and removes the batch from the stack.
21
- * Then, it restores the {@link module:engine/model/document~Document#selection document selection}.
22
- *
23
- * @fires execute
24
- * @fires revert
25
- * @param batch A batch that should be undone. If not set, the last added batch will be undone.
26
- */
27
- execute(batch?: Batch | null): void;
28
- }
29
- /**
30
- * Fired when execution of the command reverts some batch.
31
- *
32
- * @eventName ~UndoCommand#revert
33
- */
34
- export type UndoCommandRevertEvent = {
35
- name: 'revert';
36
- args: [batch: Batch, undoingBatch: Batch];
37
- };
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 undo/undocommand
7
+ */
8
+ import BaseCommand from './basecommand';
9
+ import type { Batch } from '@ckeditor/ckeditor5-engine';
10
+ /**
11
+ * The undo command stores {@link module:engine/model/batch~Batch batches} applied to the
12
+ * {@link module:engine/model/document~Document document} and is able to undo a batch by reversing it and transforming by
13
+ * batches from {@link module:engine/model/document~Document#history history} that happened after the reversed batch.
14
+ *
15
+ * The undo command also takes care of restoring the {@link module:engine/model/document~Document#selection document selection}.
16
+ */
17
+ export default class UndoCommand extends BaseCommand {
18
+ /**
19
+ * Executes the command. This method reverts a {@link module:engine/model/batch~Batch batch} added to the command's stack, transforms
20
+ * and applies the reverted version on the {@link module:engine/model/document~Document document} and removes the batch from the stack.
21
+ * Then, it restores the {@link module:engine/model/document~Document#selection document selection}.
22
+ *
23
+ * @fires execute
24
+ * @fires revert
25
+ * @param batch A batch that should be undone. If not set, the last added batch will be undone.
26
+ */
27
+ execute(batch?: Batch | null): void;
28
+ }
29
+ /**
30
+ * Fired when execution of the command reverts some batch.
31
+ *
32
+ * @eventName ~UndoCommand#revert
33
+ */
34
+ export type UndoCommandRevertEvent = {
35
+ name: 'revert';
36
+ args: [batch: Batch, undoingBatch: Batch];
37
+ };
@@ -1,44 +1,44 @@
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 undo/undocommand
7
- */
8
- import BaseCommand from './basecommand';
9
- /**
10
- * The undo command stores {@link module:engine/model/batch~Batch batches} applied to the
11
- * {@link module:engine/model/document~Document document} and is able to undo a batch by reversing it and transforming by
12
- * batches from {@link module:engine/model/document~Document#history history} that happened after the reversed batch.
13
- *
14
- * The undo command also takes care of restoring the {@link module:engine/model/document~Document#selection document selection}.
15
- */
16
- export default class UndoCommand extends BaseCommand {
17
- /**
18
- * Executes the command. This method reverts a {@link module:engine/model/batch~Batch batch} added to the command's stack, transforms
19
- * and applies the reverted version on the {@link module:engine/model/document~Document document} and removes the batch from the stack.
20
- * Then, it restores the {@link module:engine/model/document~Document#selection document selection}.
21
- *
22
- * @fires execute
23
- * @fires revert
24
- * @param batch A batch that should be undone. If not set, the last added batch will be undone.
25
- */
26
- execute(batch = null) {
27
- // If batch is not given, set `batchIndex` to the last index in command stack.
28
- const batchIndex = batch ? this._stack.findIndex(a => a.batch == batch) : this._stack.length - 1;
29
- const item = this._stack.splice(batchIndex, 1)[0];
30
- const undoingBatch = this.editor.model.createBatch({ isUndo: true });
31
- // All changes have to be done in one `enqueueChange` callback so other listeners will not
32
- // step between consecutive operations, or won't do changes to the document before selection is properly restored.
33
- this.editor.model.enqueueChange(undoingBatch, () => {
34
- this._undo(item.batch, undoingBatch);
35
- const operations = this.editor.model.document.history.getOperations(item.batch.baseVersion);
36
- this._restoreSelection(item.selection.ranges, item.selection.isBackward, operations);
37
- });
38
- // Firing `revert` event after the change block to make sure that it includes all changes from post-fixers
39
- // and make sure that the selection is "stabilized" (the selection range is saved after undo is executed and then
40
- // restored on redo, so it is important that the selection range is saved after post-fixers are done).
41
- this.fire('revert', item.batch, undoingBatch);
42
- this.refresh();
43
- }
44
- }
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 undo/undocommand
7
+ */
8
+ import BaseCommand from './basecommand';
9
+ /**
10
+ * The undo command stores {@link module:engine/model/batch~Batch batches} applied to the
11
+ * {@link module:engine/model/document~Document document} and is able to undo a batch by reversing it and transforming by
12
+ * batches from {@link module:engine/model/document~Document#history history} that happened after the reversed batch.
13
+ *
14
+ * The undo command also takes care of restoring the {@link module:engine/model/document~Document#selection document selection}.
15
+ */
16
+ export default class UndoCommand extends BaseCommand {
17
+ /**
18
+ * Executes the command. This method reverts a {@link module:engine/model/batch~Batch batch} added to the command's stack, transforms
19
+ * and applies the reverted version on the {@link module:engine/model/document~Document document} and removes the batch from the stack.
20
+ * Then, it restores the {@link module:engine/model/document~Document#selection document selection}.
21
+ *
22
+ * @fires execute
23
+ * @fires revert
24
+ * @param batch A batch that should be undone. If not set, the last added batch will be undone.
25
+ */
26
+ execute(batch = null) {
27
+ // If batch is not given, set `batchIndex` to the last index in command stack.
28
+ const batchIndex = batch ? this._stack.findIndex(a => a.batch == batch) : this._stack.length - 1;
29
+ const item = this._stack.splice(batchIndex, 1)[0];
30
+ const undoingBatch = this.editor.model.createBatch({ isUndo: true });
31
+ // All changes have to be done in one `enqueueChange` callback so other listeners will not
32
+ // step between consecutive operations, or won't do changes to the document before selection is properly restored.
33
+ this.editor.model.enqueueChange(undoingBatch, () => {
34
+ this._undo(item.batch, undoingBatch);
35
+ const operations = this.editor.model.document.history.getOperations(item.batch.baseVersion);
36
+ this._restoreSelection(item.selection.ranges, item.selection.isBackward, operations);
37
+ });
38
+ // Firing `revert` event after the change block to make sure that it includes all changes from post-fixers
39
+ // and make sure that the selection is "stabilized" (the selection range is saved after undo is executed and then
40
+ // restored on redo, so it is important that the selection range is saved after post-fixers are done).
41
+ this.fire('revert', item.batch, undoingBatch);
42
+ this.refresh();
43
+ }
44
+ }