@ckeditor/ckeditor5-typing 36.0.0 → 37.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-typing",
3
- "version": "36.0.0",
3
+ "version": "37.0.0-alpha.0",
4
4
  "description": "Typing feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,29 +12,29 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "@ckeditor/ckeditor5-core": "^36.0.0",
16
- "@ckeditor/ckeditor5-engine": "^36.0.0",
17
- "@ckeditor/ckeditor5-utils": "^36.0.0",
15
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
16
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.0",
17
+ "@ckeditor/ckeditor5-utils": "^37.0.0-alpha.0",
18
18
  "lodash-es": "^4.17.15"
19
19
  },
20
20
  "devDependencies": {
21
- "@ckeditor/ckeditor5-autoformat": "^36.0.0",
22
- "@ckeditor/ckeditor5-basic-styles": "^36.0.0",
23
- "@ckeditor/ckeditor5-block-quote": "^36.0.0",
24
- "@ckeditor/ckeditor5-code-block": "^36.0.0",
25
- "@ckeditor/ckeditor5-editor-classic": "^36.0.0",
26
- "@ckeditor/ckeditor5-enter": "^36.0.0",
27
- "@ckeditor/ckeditor5-essentials": "^36.0.0",
28
- "@ckeditor/ckeditor5-heading": "^36.0.0",
29
- "@ckeditor/ckeditor5-image": "^36.0.0",
30
- "@ckeditor/ckeditor5-indent": "^36.0.0",
31
- "@ckeditor/ckeditor5-link": "^36.0.0",
32
- "@ckeditor/ckeditor5-list": "^36.0.0",
33
- "@ckeditor/ckeditor5-media-embed": "^36.0.0",
34
- "@ckeditor/ckeditor5-mention": "^36.0.0",
35
- "@ckeditor/ckeditor5-paragraph": "^36.0.0",
36
- "@ckeditor/ckeditor5-table": "^36.0.0",
37
- "@ckeditor/ckeditor5-undo": "^36.0.0",
21
+ "@ckeditor/ckeditor5-autoformat": "^37.0.0-alpha.0",
22
+ "@ckeditor/ckeditor5-basic-styles": "^37.0.0-alpha.0",
23
+ "@ckeditor/ckeditor5-block-quote": "^37.0.0-alpha.0",
24
+ "@ckeditor/ckeditor5-code-block": "^37.0.0-alpha.0",
25
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
26
+ "@ckeditor/ckeditor5-enter": "^37.0.0-alpha.0",
27
+ "@ckeditor/ckeditor5-essentials": "^37.0.0-alpha.0",
28
+ "@ckeditor/ckeditor5-heading": "^37.0.0-alpha.0",
29
+ "@ckeditor/ckeditor5-image": "^37.0.0-alpha.0",
30
+ "@ckeditor/ckeditor5-indent": "^37.0.0-alpha.0",
31
+ "@ckeditor/ckeditor5-link": "^37.0.0-alpha.0",
32
+ "@ckeditor/ckeditor5-list": "^37.0.0-alpha.0",
33
+ "@ckeditor/ckeditor5-media-embed": "^37.0.0-alpha.0",
34
+ "@ckeditor/ckeditor5-mention": "^37.0.0-alpha.0",
35
+ "@ckeditor/ckeditor5-paragraph": "^37.0.0-alpha.0",
36
+ "@ckeditor/ckeditor5-table": "^37.0.0-alpha.0",
37
+ "@ckeditor/ckeditor5-undo": "^37.0.0-alpha.0",
38
38
  "typescript": "^4.8.4",
39
39
  "webpack": "^5.58.1",
40
40
  "webpack-cli": "^4.9.0"
@@ -63,5 +63,6 @@
63
63
  "scripts": {
64
64
  "build": "tsc -p ./tsconfig.release.json",
65
65
  "postversion": "npm run build"
66
- }
66
+ },
67
+ "types": "src/index.d.ts"
67
68
  }
@@ -0,0 +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 typing/delete
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ /**
10
+ * The delete and backspace feature. Handles keys such as <kbd>Delete</kbd> and <kbd>Backspace</kbd>, other
11
+ * keystrokes and user actions that result in deleting content in the editor.
12
+ */
13
+ export default class Delete extends Plugin {
14
+ /**
15
+ * Whether pressing backspace should trigger undo action
16
+ */
17
+ private _undoOnBackspace;
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): 'Delete';
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ init(): void;
26
+ /**
27
+ * If the next user action after calling this method is pressing backspace, it would undo the last change.
28
+ *
29
+ * Requires {@link module:undo/undoediting~UndoEditing} plugin. If not loaded, does nothing.
30
+ */
31
+ requestUndoOnBackspace(): void;
32
+ }
33
+ declare module '@ckeditor/ckeditor5-core' {
34
+ interface PluginsMap {
35
+ [Delete.pluginName]: Delete;
36
+ }
37
+ }
package/src/delete.js CHANGED
@@ -11,8 +11,6 @@ import DeleteObserver from './deleteobserver';
11
11
  /**
12
12
  * The delete and backspace feature. Handles keys such as <kbd>Delete</kbd> and <kbd>Backspace</kbd>, other
13
13
  * keystrokes and user actions that result in deleting content in the editor.
14
- *
15
- * @extends module:core/plugin~Plugin
16
14
  */
17
15
  export default class Delete extends Plugin {
18
16
  /**
@@ -0,0 +1,90 @@
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/deletecommand
7
+ */
8
+ import { Command, type Editor } from '@ckeditor/ckeditor5-core';
9
+ import type { DocumentSelection, Selection } from '@ckeditor/ckeditor5-engine';
10
+ import ChangeBuffer from './utils/changebuffer';
11
+ import './typingconfig';
12
+ /**
13
+ * The delete command. Used by the {@link module:typing/delete~Delete delete feature} to handle the <kbd>Delete</kbd> and
14
+ * <kbd>Backspace</kbd> keys.
15
+ */
16
+ export default class DeleteCommand extends Command {
17
+ /**
18
+ * The directionality of the delete describing in what direction it should
19
+ * consume the content when the selection is collapsed.
20
+ */
21
+ readonly direction: 'forward' | 'backward';
22
+ /**
23
+ * Delete's change buffer used to group subsequent changes into batches.
24
+ */
25
+ private readonly _buffer;
26
+ /**
27
+ * Creates an instance of the command.
28
+ *
29
+ * @param direction The directionality of the delete describing in what direction it
30
+ * should consume the content when the selection is collapsed.
31
+ */
32
+ constructor(editor: Editor, direction: 'forward' | 'backward');
33
+ /**
34
+ * The current change buffer.
35
+ */
36
+ get buffer(): ChangeBuffer;
37
+ /**
38
+ * Executes the delete command. Depending on whether the selection is collapsed or not, deletes its content
39
+ * or a piece of content in the {@link #direction defined direction}.
40
+ *
41
+ * @fires execute
42
+ * @param options The command options.
43
+ * @param options.unit See {@link module:engine/model/utils/modifyselection~modifySelection}'s options.
44
+ * @param options.sequence A number describing which subsequent delete event it is without the key being released.
45
+ * See the {@link module:engine/view/document~Document#event:delete} event data.
46
+ * @param options.selection Selection to remove. If not set, current model selection will be used.
47
+ */
48
+ execute(options?: {
49
+ unit?: 'character' | 'codePoint' | 'word';
50
+ sequence?: number;
51
+ selection?: Selection | DocumentSelection;
52
+ }): void;
53
+ /**
54
+ * If the user keeps <kbd>Backspace</kbd> or <kbd>Delete</kbd> key pressed, the content of the current
55
+ * editable will be cleared. However, this will not yet lead to resetting the remaining block to a paragraph
56
+ * (which happens e.g. when the user does <kbd>Ctrl</kbd> + <kbd>A</kbd>, <kbd>Backspace</kbd>).
57
+ *
58
+ * But, if the user pressed the key in an empty editable for the first time,
59
+ * we want to replace the entire content with a paragraph if:
60
+ *
61
+ * * the current limit element is empty,
62
+ * * the paragraph is allowed in the limit element,
63
+ * * the limit doesn't already have a paragraph inside.
64
+ *
65
+ * See https://github.com/ckeditor/ckeditor5-typing/issues/61.
66
+ *
67
+ * @param sequence A number describing which subsequent delete event it is without the key being released.
68
+ */
69
+ private _shouldEntireContentBeReplacedWithParagraph;
70
+ /**
71
+ * The entire content is replaced with the paragraph. Selection is moved inside the paragraph.
72
+ *
73
+ * @param writer The model writer.
74
+ */
75
+ private _replaceEntireContentWithParagraph;
76
+ /**
77
+ * Checks if the selection is inside an empty element that is the first child of the limit element
78
+ * and should be replaced with a paragraph.
79
+ *
80
+ * @param selection The selection.
81
+ * @param sequence A number describing which subsequent delete event it is without the key being released.
82
+ */
83
+ private _shouldReplaceFirstBlockWithParagraph;
84
+ }
85
+ declare module '@ckeditor/ckeditor5-core' {
86
+ interface CommandsMap {
87
+ deleteForward: DeleteCommand;
88
+ delete: DeleteCommand;
89
+ }
90
+ }
@@ -13,40 +13,21 @@ import './typingconfig';
13
13
  /**
14
14
  * The delete command. Used by the {@link module:typing/delete~Delete delete feature} to handle the <kbd>Delete</kbd> and
15
15
  * <kbd>Backspace</kbd> keys.
16
- *
17
- * @extends module:core/command~Command
18
16
  */
19
17
  export default class DeleteCommand extends Command {
20
18
  /**
21
19
  * Creates an instance of the command.
22
20
  *
23
- * @param {module:core/editor/editor~Editor} editor
24
- * @param {'forward'|'backward'} direction The directionality of the delete describing in what direction it
21
+ * @param direction The directionality of the delete describing in what direction it
25
22
  * should consume the content when the selection is collapsed.
26
23
  */
27
24
  constructor(editor, direction) {
28
25
  super(editor);
29
- /**
30
- * The directionality of the delete describing in what direction it should
31
- * consume the content when the selection is collapsed.
32
- *
33
- * @readonly
34
- * @member {'forward'|'backward'} #direction
35
- */
36
26
  this.direction = direction;
37
- /**
38
- * Delete's change buffer used to group subsequent changes into batches.
39
- *
40
- * @readonly
41
- * @private
42
- * @type {module:typing/utils/changebuffer~ChangeBuffer}
43
- */
44
27
  this._buffer = new ChangeBuffer(editor.model, editor.config.get('typing.undoStep'));
45
28
  }
46
29
  /**
47
30
  * The current change buffer.
48
- *
49
- * @type {module:typing/utils/changebuffer~ChangeBuffer}
50
31
  */
51
32
  get buffer() {
52
33
  return this._buffer;
@@ -56,13 +37,11 @@ export default class DeleteCommand extends Command {
56
37
  * or a piece of content in the {@link #direction defined direction}.
57
38
  *
58
39
  * @fires execute
59
- * @param {Object} [options] The command options.
60
- * @param {'character'|'codePoint'|'word'} [options.unit='character']
61
- * See {@link module:engine/model/utils/modifyselection~modifySelection}'s options.
62
- * @param {Number} [options.sequence=1] A number describing which subsequent delete event it is without the key being released.
40
+ * @param options The command options.
41
+ * @param options.unit See {@link module:engine/model/utils/modifyselection~modifySelection}'s options.
42
+ * @param options.sequence A number describing which subsequent delete event it is without the key being released.
63
43
  * See the {@link module:engine/view/document~Document#event:delete} event data.
64
- * @param {module:engine/model/selection~Selection} [options.selection] Selection to remove. If not set, current model selection
65
- * will be used.
44
+ * @param options.selection Selection to remove. If not set, current model selection will be used.
66
45
  */
67
46
  execute(options = {}) {
68
47
  const model = this.editor.model;
@@ -104,10 +83,10 @@ export default class DeleteCommand extends Command {
104
83
  selection.getFirstRange().getMinimalFlatRanges().forEach(range => {
105
84
  changeCount += count(range.getWalker({ singleCharacters: true, ignoreElementEnd: true, shallow: true }));
106
85
  });
107
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
86
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
108
87
  // @if CK_DEBUG_TYPING // console.log( '%c[DeleteCommand]%c Delete content',
109
88
  // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green;', '',
110
- // @if CK_DEBUG_TYPING // `[${ selection.getFirstPosition().path }]-[${ selection.getLastPosition().path }]`, options
89
+ // @if CK_DEBUG_TYPING // `[${ selection.getFirstPosition()!.path }]-[${ selection.getLastPosition()!.path }]`, options
111
90
  // @if CK_DEBUG_TYPING // );
112
91
  // @if CK_DEBUG_TYPING // }
113
92
  model.deleteContent(selection, {
@@ -133,9 +112,7 @@ export default class DeleteCommand extends Command {
133
112
  *
134
113
  * See https://github.com/ckeditor/ckeditor5-typing/issues/61.
135
114
  *
136
- * @private
137
- * @param {Number} sequence A number describing which subsequent delete event it is without the key being released.
138
- * @returns {Boolean}
115
+ * @param sequence A number describing which subsequent delete event it is without the key being released.
139
116
  */
140
117
  _shouldEntireContentBeReplacedWithParagraph(sequence) {
141
118
  // Does nothing if user pressed and held the "Backspace" or "Delete" key.
@@ -167,8 +144,7 @@ export default class DeleteCommand extends Command {
167
144
  /**
168
145
  * The entire content is replaced with the paragraph. Selection is moved inside the paragraph.
169
146
  *
170
- * @private
171
- * @param {module:engine/model/writer~Writer} writer The model writer.
147
+ * @param writer The model writer.
172
148
  */
173
149
  _replaceEntireContentWithParagraph(writer) {
174
150
  const model = this.editor.model;
@@ -184,10 +160,8 @@ export default class DeleteCommand extends Command {
184
160
  * Checks if the selection is inside an empty element that is the first child of the limit element
185
161
  * and should be replaced with a paragraph.
186
162
  *
187
- * @private
188
- * @param {module:engine/model/selection~Selection} selection The selection.
189
- * @param {Number} sequence A number describing which subsequent delete event it is without the key being released.
190
- * @returns {Boolean}
163
+ * @param selection The selection.
164
+ * @param sequence A number describing which subsequent delete event it is without the key being released.
191
165
  */
192
166
  _shouldReplaceFirstBlockWithParagraph(selection, sequence) {
193
167
  const model = this.editor.model;
@@ -0,0 +1,51 @@
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
+ import { DomEventData, Observer, type BubblingEvent, type ViewDocumentSelection, type ViewSelection, type View } from '@ckeditor/ckeditor5-engine';
6
+ /**
7
+ * Delete observer introduces the {@link module:engine/view/document~Document#event:delete} event.
8
+ */
9
+ export default class DeleteObserver extends Observer {
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ constructor(view: View);
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ observe(): void;
18
+ }
19
+ /**
20
+ * Event fired when the user tries to delete content (e.g. presses <kbd>Delete</kbd> or <kbd>Backspace</kbd>).
21
+ *
22
+ * Note: This event is fired by the {@link module:typing/deleteobserver~DeleteObserver delete observer}
23
+ * (usually registered by the {@link module:typing/delete~Delete delete feature}).
24
+ *
25
+ * @eventName delete
26
+ * @param data The event data.
27
+ */
28
+ export type ViewDocumentDeleteEvent = BubblingEvent<{
29
+ name: 'delete';
30
+ args: [data: DeleteEventData];
31
+ }>;
32
+ export interface DeleteEventData extends DomEventData<InputEvent> {
33
+ /**
34
+ * The direction in which the deletion should happen.
35
+ */
36
+ direction: 'backward' | 'forward';
37
+ /**
38
+ * The "amount" of content that should be deleted.
39
+ */
40
+ unit: 'selection' | 'codePoint' | 'character' | 'word';
41
+ /**
42
+ * A number describing which subsequent delete event it is without the key being released.
43
+ * If it's 2 or more it means that the key was pressed and hold.
44
+ */
45
+ sequence: number;
46
+ /**
47
+ * View selection which content should be removed. If not set,
48
+ * current selection should be used.
49
+ */
50
+ selectionToRemove?: ViewSelection | ViewDocumentSelection;
51
+ }
@@ -94,8 +94,6 @@ const DELETE_EVENT_TYPES = {
94
94
  };
95
95
  /**
96
96
  * Delete observer introduces the {@link module:engine/view/document~Document#event:delete} event.
97
- *
98
- * @extends module:engine/view/observer/observer~Observer
99
97
  */
100
98
  export default class DeleteObserver extends Observer {
101
99
  /**
@@ -165,7 +163,9 @@ export default class DeleteObserver extends Observer {
165
163
  */
166
164
  observe() { }
167
165
  }
168
- // Enables workaround for the issue https://github.com/ckeditor/ckeditor5/issues/11904.
166
+ /**
167
+ * Enables workaround for the issue https://github.com/ckeditor/ckeditor5/issues/11904.
168
+ */
169
169
  function enableChromeWorkaround(observer) {
170
170
  const view = observer.view;
171
171
  const document = view.document;
package/src/index.d.ts ADDED
@@ -0,0 +1,22 @@
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
7
+ */
8
+ export { default as Typing } from './typing';
9
+ export { default as Input } from './input';
10
+ export { default as Delete } from './delete';
11
+ export { default as TextWatcher } from './textwatcher';
12
+ export { default as TwoStepCaretMovement } from './twostepcaretmovement';
13
+ export { default as TextTransformation } from './texttransformation';
14
+ export { default as inlineHighlight } from './utils/inlinehighlight';
15
+ export { default as findAttributeRange } from './utils/findattributerange';
16
+ export { default as getLastTextLine, type LastTextLineData } from './utils/getlasttextline';
17
+ export { default as InsertTextCommand, type InsertTextCommandExecuteEvent } from './inserttextcommand';
18
+ export type { TypingConfig } from './typingconfig';
19
+ export type { ViewDocumentDeleteEvent } from './deleteobserver';
20
+ export type { ViewDocumentInsertTextEvent, InsertTextEventData } from './inserttextobserver';
21
+ export type { TextWatcherMatchedEvent } from './textwatcher';
22
+ export type { TextWatcherMatchedDataEvent } from './textwatcher';
package/src/index.js CHANGED
@@ -14,3 +14,4 @@ export { default as TextTransformation } from './texttransformation';
14
14
  export { default as inlineHighlight } from './utils/inlinehighlight';
15
15
  export { default as findAttributeRange } from './utils/findattributerange';
16
16
  export { default as getLastTextLine } from './utils/getlasttextline';
17
+ export { default as InsertTextCommand } from './inserttextcommand';
package/src/input.d.ts ADDED
@@ -0,0 +1,27 @@
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/input
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import './typingconfig';
10
+ /**
11
+ * Handles text input coming from the keyboard or other input methods.
12
+ */
13
+ export default class Input extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): 'Input';
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ init(): void;
22
+ }
23
+ declare module '@ckeditor/ckeditor5-core' {
24
+ interface PluginsMap {
25
+ [Input.pluginName]: Input;
26
+ }
27
+ }
package/src/input.js CHANGED
@@ -13,8 +13,6 @@ import InsertTextObserver from './inserttextobserver';
13
13
  import './typingconfig';
14
14
  /**
15
15
  * Handles text input coming from the keyboard or other input methods.
16
- *
17
- * @extends module:core/plugin~Plugin
18
16
  */
19
17
  export default class Input extends Plugin {
20
18
  /**
@@ -75,7 +73,7 @@ export default class Input extends Plugin {
75
73
  text: insertText,
76
74
  selection: model.createSelection(modelRanges)
77
75
  };
78
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
76
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
79
77
  // @if CK_DEBUG_TYPING // console.log( '%c[Input]%c Execute insertText:',
80
78
  // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green;', '',
81
79
  // @if CK_DEBUG_TYPING // insertText,
@@ -95,10 +93,12 @@ export default class Input extends Plugin {
95
93
  if (modelSelection.isCollapsed || data.keyCode != 229 || !view.document.isComposing) {
96
94
  return;
97
95
  }
98
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
96
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
97
+ // @if CK_DEBUG_TYPING // const firstPositionPath = modelSelection.getFirstPosition()!.path;
98
+ // @if CK_DEBUG_TYPING // const lastPositionPath = modelSelection.getLastPosition()!.path;
99
99
  // @if CK_DEBUG_TYPING // console.log( '%c[Input]%c KeyDown 229 -> model.deleteContent()',
100
100
  // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green;', '',
101
- // @if CK_DEBUG_TYPING // `[${ modelSelection.getFirstPosition().path }]-[${ modelSelection.getLastPosition().path }]`
101
+ // @if CK_DEBUG_TYPING // `[${ firstPositionPath }]-[${ lastPositionPath }]`
102
102
  // @if CK_DEBUG_TYPING // );
103
103
  // @if CK_DEBUG_TYPING // }
104
104
  deleteSelectionContent(model, insertTextCommand);
@@ -111,10 +111,12 @@ export default class Input extends Plugin {
111
111
  if (modelSelection.isCollapsed) {
112
112
  return;
113
113
  }
114
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
114
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
115
+ // @if CK_DEBUG_TYPING // const firstPositionPath = modelSelection.getFirstPosition()!.path;
116
+ // @if CK_DEBUG_TYPING // const lastPositionPath = modelSelection.getLastPosition()!.path;
115
117
  // @if CK_DEBUG_TYPING // console.log( '%c[Input]%c Composition start -> model.deleteContent()',
116
118
  // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green;', '',
117
- // @if CK_DEBUG_TYPING // `[${ modelSelection.getFirstPosition().path }]-[${ modelSelection.getLastPosition().path }]`
119
+ // @if CK_DEBUG_TYPING // `[${ firstPositionPath }]-[${ lastPositionPath }]`
118
120
  // @if CK_DEBUG_TYPING // );
119
121
  // @if CK_DEBUG_TYPING // }
120
122
  deleteSelectionContent(model, insertTextCommand);
@@ -0,0 +1,81 @@
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/inserttextcommand
7
+ */
8
+ import { Command, type Editor } from '@ckeditor/ckeditor5-core';
9
+ import ChangeBuffer from './utils/changebuffer';
10
+ import type { DocumentSelection, Range, Selection } from '@ckeditor/ckeditor5-engine';
11
+ /**
12
+ * The insert text command. Used by the {@link module:typing/input~Input input feature} to handle typing.
13
+ */
14
+ export default class InsertTextCommand extends Command {
15
+ /**
16
+ * Typing's change buffer used to group subsequent changes into batches.
17
+ */
18
+ private readonly _buffer;
19
+ /**
20
+ * Creates an instance of the command.
21
+ *
22
+ * @param undoStepSize The maximum number of atomic changes
23
+ * which can be contained in one batch in the command buffer.
24
+ */
25
+ constructor(editor: Editor, undoStepSize: number);
26
+ /**
27
+ * The current change buffer.
28
+ */
29
+ get buffer(): ChangeBuffer;
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ destroy(): void;
34
+ /**
35
+ * Executes the input command. It replaces the content within the given range with the given text.
36
+ * Replacing is a two step process, first the content within the range is removed and then the new text is inserted
37
+ * at the beginning of the range (which after the removal is a collapsed range).
38
+ *
39
+ * @fires execute
40
+ * @param options The command options.
41
+ */
42
+ execute(options?: InsertTextCommandOptions): void;
43
+ }
44
+ /**
45
+ * Interface with parameters for executing InsertTextCommand.
46
+ *
47
+ * Both `range` and `selection` parameters are used for defining selection but should not be used together.
48
+ * If both are defined, only `selection` will be considered.
49
+ */
50
+ export interface InsertTextCommandOptions {
51
+ /**
52
+ * The text to be inserted.
53
+ */
54
+ text?: string;
55
+ /**
56
+ * The selection in which the text is inserted.
57
+ * Inserting a text into a selection deletes the current content within selection ranges. If the selection is not specified,
58
+ * the current selection in the model will be used instead.
59
+ */
60
+ selection?: Selection | DocumentSelection;
61
+ /**
62
+ * The range in which the text is inserted. Defaults to the first range in the current selection.
63
+ */
64
+ range?: Range;
65
+ /**
66
+ * The range where the selection should be placed after the insertion.
67
+ * If not specified, the selection will be placed right after the inserted text.
68
+ */
69
+ resultRange?: Range;
70
+ }
71
+ export interface InsertTextCommandExecuteEvent {
72
+ name: 'execute';
73
+ args: [
74
+ data: [options: InsertTextCommandOptions]
75
+ ];
76
+ }
77
+ declare module '@ckeditor/ckeditor5-core' {
78
+ interface CommandsMap {
79
+ insertText: InsertTextCommand;
80
+ }
81
+ }
@@ -9,32 +9,20 @@ import { Command } from '@ckeditor/ckeditor5-core';
9
9
  import ChangeBuffer from './utils/changebuffer';
10
10
  /**
11
11
  * The insert text command. Used by the {@link module:typing/input~Input input feature} to handle typing.
12
- *
13
- * @extends module:core/command~Command
14
12
  */
15
13
  export default class InsertTextCommand extends Command {
16
14
  /**
17
15
  * Creates an instance of the command.
18
16
  *
19
- * @param {module:core/editor/editor~Editor} editor
20
- * @param {Number} undoStepSize The maximum number of atomic changes
17
+ * @param undoStepSize The maximum number of atomic changes
21
18
  * which can be contained in one batch in the command buffer.
22
19
  */
23
20
  constructor(editor, undoStepSize) {
24
21
  super(editor);
25
- /**
26
- * Typing's change buffer used to group subsequent changes into batches.
27
- *
28
- * @readonly
29
- * @private
30
- * @member {module:typing/utils/changebuffer~ChangeBuffer} #_buffer
31
- */
32
22
  this._buffer = new ChangeBuffer(editor.model, undoStepSize);
33
23
  }
34
24
  /**
35
25
  * The current change buffer.
36
- *
37
- * @type {module:typing/utils/changebuffer~ChangeBuffer}
38
26
  */
39
27
  get buffer() {
40
28
  return this._buffer;
@@ -52,17 +40,7 @@ export default class InsertTextCommand extends Command {
52
40
  * at the beginning of the range (which after the removal is a collapsed range).
53
41
  *
54
42
  * @fires execute
55
- * @param {Object} [options] The command options.
56
- * @param {String} [options.text=''] The text to be inserted.
57
- * @param {module:engine/model/selection~Selection} [options.selection] The selection in which the text is inserted.
58
- * Inserting a text into a selection deletes the current content within selection ranges. If the selection is not specified,
59
- * the current selection in the model will be used instead.
60
- * // TODO note that those 2 options are exclusive (either selection or range)
61
- * @param {module:engine/model/range~Range} [options.range] The range in which the text is inserted. Defaults
62
- * to the first range in the current selection.
63
- * @param {module:engine/model/range~Range} [options.resultRange] The range where the selection
64
- * should be placed after the insertion. If not specified, the selection will be placed right after
65
- * the inserted text.
43
+ * @param options The command options.
66
44
  */
67
45
  execute(options = {}) {
68
46
  const model = this.editor.model;