@ckeditor/ckeditor5-typing 47.6.1 → 48.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +1 -1
  3. package/dist/index.css +3 -0
  4. package/dist/index.css.map +1 -0
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/{src → dist}/texttransformation.d.ts +3 -1
  8. package/package.json +22 -41
  9. package/src/augmentation.js +0 -5
  10. package/src/delete.js +0 -122
  11. package/src/deletecommand.js +0 -212
  12. package/src/deleteobserver.js +0 -262
  13. package/src/index.js +0 -21
  14. package/src/input.js +0 -486
  15. package/src/inserttextcommand.js +0 -87
  16. package/src/inserttextobserver.js +0 -112
  17. package/src/texttransformation.js +0 -237
  18. package/src/textwatcher.js +0 -123
  19. package/src/twostepcaretmovement.js +0 -661
  20. package/src/typing.js +0 -33
  21. package/src/typingconfig.js +0 -5
  22. package/src/utils/changebuffer.js +0 -148
  23. package/src/utils/findattributerange.js +0 -41
  24. package/src/utils/getlasttextline.js +0 -43
  25. package/src/utils/inlinehighlight.js +0 -74
  26. /package/{src → dist}/augmentation.d.ts +0 -0
  27. /package/{src → dist}/delete.d.ts +0 -0
  28. /package/{src → dist}/deletecommand.d.ts +0 -0
  29. /package/{src → dist}/deleteobserver.d.ts +0 -0
  30. /package/{src → dist}/index.d.ts +0 -0
  31. /package/{src → dist}/input.d.ts +0 -0
  32. /package/{src → dist}/inserttextcommand.d.ts +0 -0
  33. /package/{src → dist}/inserttextobserver.d.ts +0 -0
  34. /package/{src → dist}/textwatcher.d.ts +0 -0
  35. /package/{src → dist}/twostepcaretmovement.d.ts +0 -0
  36. /package/{src → dist}/typing.d.ts +0 -0
  37. /package/{src → dist}/typingconfig.d.ts +0 -0
  38. /package/{src → dist}/utils/changebuffer.d.ts +0 -0
  39. /package/{src → dist}/utils/findattributerange.d.ts +0 -0
  40. /package/{src → dist}/utils/getlasttextline.d.ts +0 -0
  41. /package/{src → dist}/utils/inlinehighlight.d.ts +0 -0
@@ -1,661 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module typing/twostepcaretmovement
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { keyCodes } from '@ckeditor/ckeditor5-utils';
10
- import { MouseObserver, TouchObserver } from '@ckeditor/ckeditor5-engine';
11
- /**
12
- * This plugin enables the two-step caret (phantom) movement behavior for
13
- * {@link module:typing/twostepcaretmovement~TwoStepCaretMovement#registerAttribute registered attributes}
14
- * on arrow right (<kbd>→</kbd>) and left (<kbd>←</kbd>) key press.
15
- *
16
- * Thanks to this (phantom) caret movement the user is able to type before/after as well as at the
17
- * beginning/end of an attribute.
18
- *
19
- * **Note:** This plugin support right–to–left (Arabic, Hebrew, etc.) content by mirroring its behavior
20
- * but for the sake of simplicity examples showcase only left–to–right use–cases.
21
- *
22
- * # Forward movement
23
- *
24
- * ## "Entering" an attribute:
25
- *
26
- * When this plugin is enabled and registered for the `a` attribute and the selection is right before it
27
- * (at the attribute boundary), pressing the right arrow key will not move the selection but update its
28
- * attributes accordingly:
29
- *
30
- * * When enabled:
31
- *
32
- * ```xml
33
- * foo{}<$text a="true">bar</$text>
34
- * ```
35
- *
36
- * <kbd>→</kbd>
37
- *
38
- * ```xml
39
- * foo<$text a="true">{}bar</$text>
40
- * ```
41
- *
42
- * * When disabled:
43
- *
44
- * ```xml
45
- * foo{}<$text a="true">bar</$text>
46
- * ```
47
- *
48
- * <kbd>→</kbd>
49
- *
50
- * ```xml
51
- * foo<$text a="true">b{}ar</$text>
52
- * ```
53
- *
54
- *
55
- * ## "Leaving" an attribute:
56
- *
57
- * * When enabled:
58
- *
59
- * ```xml
60
- * <$text a="true">bar{}</$text>baz
61
- * ```
62
- *
63
- * <kbd>→</kbd>
64
- *
65
- * ```xml
66
- * <$text a="true">bar</$text>{}baz
67
- * ```
68
- *
69
- * * When disabled:
70
- *
71
- * ```xml
72
- * <$text a="true">bar{}</$text>baz
73
- * ```
74
- *
75
- * <kbd>→</kbd>
76
- *
77
- * ```xml
78
- * <$text a="true">bar</$text>b{}az
79
- * ```
80
- *
81
- * # Backward movement
82
- *
83
- * * When enabled:
84
- *
85
- * ```xml
86
- * <$text a="true">bar</$text>{}baz
87
- * ```
88
- *
89
- * <kbd>←</kbd>
90
- *
91
- * ```xml
92
- * <$text a="true">bar{}</$text>baz
93
- * ```
94
- *
95
- * * When disabled:
96
- *
97
- * ```xml
98
- * <$text a="true">bar</$text>{}baz
99
- * ```
100
- *
101
- * <kbd>←</kbd>
102
- *
103
- * ```xml
104
- * <$text a="true">ba{}r</$text>b{}az
105
- * ```
106
- *
107
- * # Multiple attributes
108
- *
109
- * * When enabled and many attributes starts or ends at the same position:
110
- *
111
- * ```xml
112
- * <$text a="true" b="true">bar</$text>{}baz
113
- * ```
114
- *
115
- * <kbd>←</kbd>
116
- *
117
- * ```xml
118
- * <$text a="true" b="true">bar{}</$text>baz
119
- * ```
120
- *
121
- * * When enabled and one procedes another:
122
- *
123
- * ```xml
124
- * <$text a="true">bar</$text><$text b="true">{}bar</$text>
125
- * ```
126
- *
127
- * <kbd>←</kbd>
128
- *
129
- * ```xml
130
- * <$text a="true">bar{}</$text><$text b="true">bar</$text>
131
- * ```
132
- *
133
- */
134
- export class TwoStepCaretMovement extends Plugin {
135
- /**
136
- * A set of attributes to handle.
137
- */
138
- attributes;
139
- /**
140
- * The current UID of the overridden gravity, as returned by
141
- * {@link module:engine/model/writer~ModelWriter#overrideSelectionGravity}.
142
- */
143
- _overrideUid;
144
- /**
145
- * A flag indicating that the automatic gravity restoration should not happen upon the next
146
- * gravity restoration.
147
- * {@link module:engine/model/selection~ModelSelection#event:change:range} event.
148
- */
149
- _isNextGravityRestorationSkipped = false;
150
- /**
151
- * @inheritDoc
152
- */
153
- static get pluginName() {
154
- return 'TwoStepCaretMovement';
155
- }
156
- /**
157
- * @inheritDoc
158
- */
159
- static get isOfficialPlugin() {
160
- return true;
161
- }
162
- /**
163
- * @inheritDoc
164
- */
165
- constructor(editor) {
166
- super(editor);
167
- this.attributes = new Set();
168
- this._overrideUid = null;
169
- }
170
- /**
171
- * @inheritDoc
172
- */
173
- init() {
174
- const editor = this.editor;
175
- const model = editor.model;
176
- const view = editor.editing.view;
177
- const locale = editor.locale;
178
- const modelSelection = model.document.selection;
179
- // Listen to keyboard events and handle the caret movement according to the 2-step caret logic.
180
- this.listenTo(view.document, 'arrowKey', (evt, data) => {
181
- // This implementation works only for collapsed selection.
182
- if (!modelSelection.isCollapsed) {
183
- return;
184
- }
185
- // When user tries to expand the selection or jump over the whole word or to the beginning/end then
186
- // two-steps movement is not necessary.
187
- if (data.shiftKey || data.altKey || data.ctrlKey) {
188
- return;
189
- }
190
- const arrowRightPressed = data.keyCode == keyCodes.arrowright;
191
- const arrowLeftPressed = data.keyCode == keyCodes.arrowleft;
192
- // When neither left or right arrow has been pressed then do noting.
193
- if (!arrowRightPressed && !arrowLeftPressed) {
194
- return;
195
- }
196
- const contentDirection = locale.contentLanguageDirection;
197
- let isMovementHandled = false;
198
- if ((contentDirection === 'ltr' && arrowRightPressed) || (contentDirection === 'rtl' && arrowLeftPressed)) {
199
- isMovementHandled = this._handleForwardMovement(data);
200
- }
201
- else {
202
- isMovementHandled = this._handleBackwardMovement(data);
203
- }
204
- // Stop the keydown event if the two-step caret movement handled it. Avoid collisions
205
- // with other features which may also take over the caret movement (e.g. Widget).
206
- if (isMovementHandled === true) {
207
- evt.stop();
208
- }
209
- }, { context: '$text', priority: 'highest' });
210
- // The automatic gravity restoration logic.
211
- this.listenTo(modelSelection, 'change:range', (evt, data) => {
212
- // Skipping the automatic restoration is needed if the selection should change
213
- // but the gravity must remain overridden afterwards. See the #handleBackwardMovement
214
- // to learn more.
215
- if (this._isNextGravityRestorationSkipped) {
216
- this._isNextGravityRestorationSkipped = false;
217
- return;
218
- }
219
- // Skip automatic restore when the gravity is not overridden — simply, there's nothing to restore
220
- // at this moment.
221
- if (!this._isGravityOverridden) {
222
- return;
223
- }
224
- // Skip automatic restore when the change is indirect AND the selection is at the attribute boundary.
225
- // It means that e.g. if the change was external (collaboration) and the user had their
226
- // selection around the link, its gravity should remain intact in this change:range event.
227
- if (!data.directChange && isBetweenDifferentAttributes(modelSelection.getFirstPosition(), this.attributes)) {
228
- return;
229
- }
230
- this._restoreGravity();
231
- });
232
- // Handle a click at the beginning/end of a two-step element.
233
- this._enableClickingAfterNode();
234
- // Change the attributes of the selection in certain situations after the two-step node was inserted into the document.
235
- this._enableInsertContentSelectionAttributesFixer();
236
- // Handle removing the content after the two-step node.
237
- this._handleDeleteContentAfterNode();
238
- }
239
- /**
240
- * Registers a given attribute for the two-step caret movement.
241
- *
242
- * @param attribute Name of the attribute to handle.
243
- */
244
- registerAttribute(attribute) {
245
- this.attributes.add(attribute);
246
- }
247
- /**
248
- * Updates the document selection and the view according to the two–step caret movement state
249
- * when moving **forwards**. Executed upon `keypress` in the {@link module:engine/view/view~EditingView}.
250
- *
251
- * @internal
252
- * @param eventData Data of the key press.
253
- * @returns `true` when the handler prevented caret movement.
254
- */
255
- _handleForwardMovement(eventData) {
256
- const attributes = this.attributes;
257
- const model = this.editor.model;
258
- const selection = model.document.selection;
259
- const position = selection.getFirstPosition();
260
- // DON'T ENGAGE 2-SCM if gravity is already overridden. It means that we just entered
261
- //
262
- // <paragraph>foo<$text attribute>{}bar</$text>baz</paragraph>
263
- //
264
- // or left the attribute
265
- //
266
- // <paragraph>foo<$text attribute>bar</$text>{}baz</paragraph>
267
- //
268
- // and the gravity will be restored automatically.
269
- if (this._isGravityOverridden) {
270
- return false;
271
- }
272
- // DON'T ENGAGE 2-SCM when the selection is at the beginning of the block AND already has the
273
- // attribute:
274
- // * when the selection was initially set there using the mouse,
275
- // * when the editor has just started
276
- //
277
- // <paragraph><$text attribute>{}bar</$text>baz</paragraph>
278
- //
279
- if (position.isAtStart && hasAnyAttribute(selection, attributes)) {
280
- return false;
281
- }
282
- // ENGAGE 2-SCM When at least one of the observed attributes changes its value (incl. starts, ends).
283
- //
284
- // <paragraph>foo<$text attribute>bar{}</$text>baz</paragraph>
285
- // <paragraph>foo<$text attribute>bar{}</$text><$text otherAttribute>baz</$text></paragraph>
286
- // <paragraph>foo<$text attribute=1>bar{}</$text><$text attribute=2>baz</$text></paragraph>
287
- // <paragraph>foo{}<$text attribute>bar</$text>baz</paragraph>
288
- //
289
- if (isBetweenDifferentAttributes(position, attributes)) {
290
- if (eventData) {
291
- preventCaretMovement(eventData);
292
- }
293
- // CLEAR 2-SCM attributes if we are at the end of one 2-SCM and before
294
- // the next one with a different value of the same attribute.
295
- //
296
- // <paragraph>foo<$text attribute=1>bar{}</$text><$text attribute=2>bar</$text>baz</paragraph>
297
- //
298
- if (hasAnyAttribute(selection, attributes) &&
299
- isBetweenDifferentAttributes(position, attributes, true)) {
300
- clearSelectionAttributes(model, attributes);
301
- }
302
- else {
303
- this._overrideGravity();
304
- }
305
- return true;
306
- }
307
- return false;
308
- }
309
- /**
310
- * Updates the document selection and the view according to the two–step caret movement state
311
- * when moving **backwards**. Executed upon `keypress` in the {@link module:engine/view/view~EditingView}.
312
- *
313
- * @internal
314
- * @param eventData Data of the key press.
315
- * @returns `true` when the handler prevented caret movement
316
- */
317
- _handleBackwardMovement(eventData) {
318
- const attributes = this.attributes;
319
- const model = this.editor.model;
320
- const selection = model.document.selection;
321
- const position = selection.getFirstPosition();
322
- // When the gravity is already overridden (by this plugin), it means we are on the two-step position.
323
- // Prevent the movement, restore the gravity and update selection attributes.
324
- //
325
- // <paragraph>foo<$text attribute=1>bar</$text><$text attribute=2>{}baz</$text></paragraph>
326
- // <paragraph>foo<$text attribute>bar</$text><$text otherAttribute>{}baz</$text></paragraph>
327
- // <paragraph>foo<$text attribute>{}bar</$text>baz</paragraph>
328
- // <paragraph>foo<$text attribute>bar</$text>{}baz</paragraph>
329
- //
330
- if (this._isGravityOverridden) {
331
- if (eventData) {
332
- preventCaretMovement(eventData);
333
- }
334
- this._restoreGravity();
335
- // CLEAR 2-SCM attributes if we are at the end of one 2-SCM and before
336
- // the next one with a different value of the same attribute.
337
- //
338
- // <paragraph>foo<$text attribute=1>bar</$text><$text attribute=2>{}bar</$text>baz</paragraph>
339
- //
340
- if (isBetweenDifferentAttributes(position, attributes, true)) {
341
- clearSelectionAttributes(model, attributes);
342
- }
343
- else {
344
- setSelectionAttributesFromTheNodeBefore(model, attributes, position);
345
- }
346
- return true;
347
- }
348
- else {
349
- // REMOVE SELECTION ATTRIBUTE when restoring gravity towards a non-existent content at the
350
- // beginning of the block.
351
- //
352
- // <paragraph>{}<$text attribute>bar</$text></paragraph>
353
- //
354
- if (position.isAtStart) {
355
- if (hasAnyAttribute(selection, attributes)) {
356
- if (eventData) {
357
- preventCaretMovement(eventData);
358
- }
359
- setSelectionAttributesFromTheNodeBefore(model, attributes, position);
360
- return true;
361
- }
362
- return false;
363
- }
364
- // SET 2-SCM attributes if we are between nodes with the same attribute but with different values.
365
- //
366
- // <paragraph>foo<$text attribute=1>bar</$text>[]<$text attribute=2>bar</$text>baz</paragraph>
367
- //
368
- if (!hasAnyAttribute(selection, attributes) &&
369
- isBetweenDifferentAttributes(position, attributes, true)) {
370
- if (eventData) {
371
- preventCaretMovement(eventData);
372
- }
373
- setSelectionAttributesFromTheNodeBefore(model, attributes, position);
374
- return true;
375
- }
376
- // When we are moving from natural gravity, to the position of the 2SCM, we need to override the gravity,
377
- // and make sure it won't be restored. Unless it's at the end of the block and an observed attribute.
378
- // We need to check if the caret is a one position before the attribute boundary:
379
- //
380
- // <paragraph>foo<$text attribute=1>bar</$text><$text attribute=2>b{}az</$text></paragraph>
381
- // <paragraph>foo<$text attribute>bar</$text><$text otherAttribute>b{}az</$text></paragraph>
382
- // <paragraph>foo<$text attribute>b{}ar</$text>baz</paragraph>
383
- // <paragraph>foo<$text attribute>bar</$text>b{}az</paragraph>
384
- //
385
- if (isStepAfterAnyAttributeBoundary(position, attributes)) {
386
- // ENGAGE 2-SCM if the selection has no attribute. This may happen when the user
387
- // left the attribute using a FORWARD 2-SCM.
388
- //
389
- // <paragraph><$text attribute>bar</$text>{}</paragraph>
390
- //
391
- if (position.isAtEnd &&
392
- !hasAnyAttribute(selection, attributes) &&
393
- isBetweenDifferentAttributes(position, attributes)) {
394
- if (eventData) {
395
- preventCaretMovement(eventData);
396
- }
397
- setSelectionAttributesFromTheNodeBefore(model, attributes, position);
398
- return true;
399
- }
400
- // Skip the automatic gravity restore upon the next selection#change:range event.
401
- // If not skipped, it would automatically restore the gravity, which should remain
402
- // overridden.
403
- this._isNextGravityRestorationSkipped = true;
404
- this._overrideGravity();
405
- // Don't return "true" here because we didn't call _preventCaretMovement.
406
- // Returning here will destabilize the filler logic, which also listens to
407
- // keydown (and the event would be stopped).
408
- return false;
409
- }
410
- }
411
- return false;
412
- }
413
- /**
414
- * Starts listening to {@link module:engine/view/document~ViewDocument#event:mousedown} and
415
- * {@link module:engine/view/document~ViewDocument#event:selectionChange} and puts the selection before/after a 2-step node
416
- * if clicked at the beginning/ending of the 2-step node.
417
- *
418
- * The purpose of this action is to allow typing around the 2-step node directly after a click.
419
- *
420
- * See https://github.com/ckeditor/ckeditor5/issues/1016.
421
- */
422
- _enableClickingAfterNode() {
423
- const editor = this.editor;
424
- const model = editor.model;
425
- const selection = model.document.selection;
426
- const document = editor.editing.view.document;
427
- editor.editing.view.addObserver(MouseObserver);
428
- editor.editing.view.addObserver(TouchObserver);
429
- let touched = false;
430
- let clicked = false;
431
- // This event should be fired before selection on mobile devices.
432
- this.listenTo(document, 'touchstart', () => {
433
- clicked = false;
434
- touched = true;
435
- });
436
- // Track mouse click event.
437
- // Keep in mind that it's often called after the selection change on iOS devices.
438
- // On the Android devices, it's called before the selection change.
439
- // That's why we watch `touchstart` event on mobile and set `touched` flag, as it's fired before the selection change.
440
- // See more: https://github.com/ckeditor/ckeditor5/issues/17171
441
- this.listenTo(document, 'mousedown', () => {
442
- clicked = true;
443
- });
444
- // When the selection has changed...
445
- this.listenTo(document, 'selectionChange', () => {
446
- const attributes = this.attributes;
447
- if (!clicked && !touched) {
448
- return;
449
- }
450
- // ...and it was caused by the click or touch...
451
- clicked = false;
452
- touched = false;
453
- // ...and no text is selected...
454
- if (!selection.isCollapsed) {
455
- return;
456
- }
457
- // ...and clicked text is the 2-step node...
458
- if (!hasAnyAttribute(selection, attributes)) {
459
- return;
460
- }
461
- const position = selection.getFirstPosition();
462
- if (!isBetweenDifferentAttributes(position, attributes)) {
463
- return;
464
- }
465
- // The selection at the start of a block would use surrounding attributes
466
- // from text after the selection so just clear 2-SCM attributes.
467
- //
468
- // Also, clear attributes for selection between same attribute with different values.
469
- if (position.isAtStart ||
470
- isBetweenDifferentAttributes(position, attributes, true)) {
471
- clearSelectionAttributes(model, attributes);
472
- }
473
- else if (!this._isGravityOverridden) {
474
- this._overrideGravity();
475
- }
476
- });
477
- }
478
- /**
479
- * Starts listening to {@link module:engine/model/model~Model#event:insertContent} and corrects the model
480
- * selection attributes if the selection is at the end of a two-step node after inserting the content.
481
- *
482
- * The purpose of this action is to improve the overall UX because the user is no longer "trapped" by the
483
- * two-step attribute of the selection, and they can type a "clean" (`linkHref`–less) text right away.
484
- *
485
- * See https://github.com/ckeditor/ckeditor5/issues/6053.
486
- */
487
- _enableInsertContentSelectionAttributesFixer() {
488
- const editor = this.editor;
489
- const model = editor.model;
490
- const selection = model.document.selection;
491
- const attributes = this.attributes;
492
- this.listenTo(model, 'insertContent', () => {
493
- const position = selection.getFirstPosition();
494
- if (hasAnyAttribute(selection, attributes) &&
495
- isBetweenDifferentAttributes(position, attributes)) {
496
- clearSelectionAttributes(model, attributes);
497
- }
498
- }, { priority: 'low' });
499
- }
500
- /**
501
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether
502
- * removing a content right after the tow-step attribute.
503
- *
504
- * If so, the selection should not preserve the two-step attribute. However, if
505
- * the {@link module:typing/twostepcaretmovement~TwoStepCaretMovement} plugin is active and
506
- * the selection has the two-step attribute due to overridden gravity (at the end), the two-step attribute should stay untouched.
507
- *
508
- * The purpose of this action is to allow removing the link text and keep the selection outside the link.
509
- *
510
- * See https://github.com/ckeditor/ckeditor5/issues/7521.
511
- */
512
- _handleDeleteContentAfterNode() {
513
- const editor = this.editor;
514
- const model = editor.model;
515
- const selection = model.document.selection;
516
- const view = editor.editing.view;
517
- let isBackspace = false;
518
- let shouldPreserveAttributes = false;
519
- // Detect pressing `Backspace`.
520
- this.listenTo(view.document, 'delete', (evt, data) => {
521
- isBackspace = data.direction === 'backward';
522
- }, { priority: 'high' });
523
- // Before removing the content, check whether the selection is inside a two-step attribute.
524
- // If so, we want to preserve those attributes.
525
- this.listenTo(model, 'deleteContent', () => {
526
- if (!isBackspace) {
527
- return;
528
- }
529
- const position = selection.getFirstPosition();
530
- shouldPreserveAttributes = hasAnyAttribute(selection, this.attributes) &&
531
- !isStepAfterAnyAttributeBoundary(position, this.attributes);
532
- }, { priority: 'high' });
533
- // After removing the content, check whether the current selection should preserve the `linkHref` attribute.
534
- this.listenTo(model, 'deleteContent', () => {
535
- if (!isBackspace) {
536
- return;
537
- }
538
- isBackspace = false;
539
- // Do not escape two-step attribute if it was inside it before content deletion.
540
- if (shouldPreserveAttributes) {
541
- return;
542
- }
543
- // Use `model.enqueueChange()` in order to execute the callback at the end of the changes process.
544
- editor.model.enqueueChange(() => {
545
- const position = selection.getFirstPosition();
546
- if (hasAnyAttribute(selection, this.attributes) &&
547
- isBetweenDifferentAttributes(position, this.attributes)) {
548
- if (position.isAtStart || isBetweenDifferentAttributes(position, this.attributes, true)) {
549
- clearSelectionAttributes(model, this.attributes);
550
- }
551
- else if (!this._isGravityOverridden) {
552
- this._overrideGravity();
553
- }
554
- }
555
- });
556
- }, { priority: 'low' });
557
- }
558
- /**
559
- * `true` when the gravity is overridden for the plugin.
560
- */
561
- get _isGravityOverridden() {
562
- return !!this._overrideUid;
563
- }
564
- /**
565
- * Overrides the gravity using the {@link module:engine/model/writer~ModelWriter model writer}
566
- * and stores the information about this fact in the {@link #_overrideUid}.
567
- *
568
- * A shorthand for {@link module:engine/model/writer~ModelWriter#overrideSelectionGravity}.
569
- */
570
- _overrideGravity() {
571
- this._overrideUid = this.editor.model.change(writer => {
572
- return writer.overrideSelectionGravity();
573
- });
574
- }
575
- /**
576
- * Restores the gravity using the {@link module:engine/model/writer~ModelWriter model writer}.
577
- *
578
- * A shorthand for {@link module:engine/model/writer~ModelWriter#restoreSelectionGravity}.
579
- */
580
- _restoreGravity() {
581
- this.editor.model.change(writer => {
582
- writer.restoreSelectionGravity(this._overrideUid);
583
- this._overrideUid = null;
584
- });
585
- }
586
- }
587
- /**
588
- * Checks whether the selection has any of given attributes.
589
- */
590
- function hasAnyAttribute(selection, attributes) {
591
- for (const observedAttribute of attributes) {
592
- if (selection.hasAttribute(observedAttribute)) {
593
- return true;
594
- }
595
- }
596
- return false;
597
- }
598
- /**
599
- * Applies the given attributes to the current selection using using the
600
- * values from the node before the current position. Uses
601
- * the {@link module:engine/model/writer~ModelWriter model writer}.
602
- */
603
- function setSelectionAttributesFromTheNodeBefore(model, attributes, position) {
604
- const nodeBefore = position.nodeBefore;
605
- model.change(writer => {
606
- if (nodeBefore) {
607
- const attributes = [];
608
- const isInlineObject = model.schema.isObject(nodeBefore) && model.schema.isInline(nodeBefore);
609
- for (const [key, value] of nodeBefore.getAttributes()) {
610
- if (model.schema.checkAttribute('$text', key) &&
611
- (!isInlineObject || model.schema.getAttributeProperties(key).copyFromObject !== false)) {
612
- attributes.push([key, value]);
613
- }
614
- }
615
- writer.setSelectionAttribute(attributes);
616
- }
617
- else {
618
- writer.removeSelectionAttribute(attributes);
619
- }
620
- });
621
- }
622
- /**
623
- * Removes 2-SCM attributes from the selection.
624
- */
625
- function clearSelectionAttributes(model, attributes) {
626
- model.change(writer => {
627
- writer.removeSelectionAttribute(attributes);
628
- });
629
- }
630
- /**
631
- * Prevents the caret movement in the view by calling `preventDefault` on the event data.
632
- *
633
- * @alias data.preventDefault
634
- */
635
- function preventCaretMovement(data) {
636
- data.preventDefault();
637
- }
638
- /**
639
- * Checks whether the step before `isBetweenDifferentAttributes()`.
640
- */
641
- function isStepAfterAnyAttributeBoundary(position, attributes) {
642
- const positionBefore = position.getShiftedBy(-1);
643
- return isBetweenDifferentAttributes(positionBefore, attributes);
644
- }
645
- /**
646
- * Checks whether the given position is between different values of given attributes.
647
- */
648
- function isBetweenDifferentAttributes(position, attributes, isStrict = false) {
649
- const { nodeBefore, nodeAfter } = position;
650
- for (const observedAttribute of attributes) {
651
- const attrBefore = nodeBefore ? nodeBefore.getAttribute(observedAttribute) : undefined;
652
- const attrAfter = nodeAfter ? nodeAfter.getAttribute(observedAttribute) : undefined;
653
- if (isStrict && (attrBefore === undefined || attrAfter === undefined)) {
654
- continue;
655
- }
656
- if (attrAfter !== attrBefore) {
657
- return true;
658
- }
659
- }
660
- return false;
661
- }
package/src/typing.js DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module typing/typing
7
- */
8
- import { Plugin } from '@ckeditor/ckeditor5-core';
9
- import { Input } from './input.js';
10
- import { Delete } from './delete.js';
11
- /**
12
- * The typing feature. It handles typing.
13
- *
14
- * This is a "glue" plugin which loads the {@link module:typing/input~Input} and {@link module:typing/delete~Delete}
15
- * plugins.
16
- */
17
- export class Typing extends Plugin {
18
- static get requires() {
19
- return [Input, Delete];
20
- }
21
- /**
22
- * @inheritDoc
23
- */
24
- static get pluginName() {
25
- return 'Typing';
26
- }
27
- /**
28
- * @inheritDoc
29
- */
30
- static get isOfficialPlugin() {
31
- return true;
32
- }
33
- }