@ckeditor/ckeditor5-restricted-editing 38.0.1 → 38.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
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
- export {};
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
+ export {};
@@ -1,30 +1,30 @@
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 restricted-editing/restrictededitingexceptioncommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- /**
10
- * The command that toggles exceptions from the restricted editing on text.
11
- */
12
- export default class RestrictedEditingExceptionCommand extends Command {
13
- /**
14
- * A flag indicating whether the command is active
15
- *
16
- * @readonly
17
- */
18
- value: boolean;
19
- /**
20
- * @inheritDoc
21
- */
22
- refresh(): void;
23
- /**
24
- * @inheritDoc
25
- */
26
- execute(options?: RestrictedEditingExceptionCommandParams): void;
27
- }
28
- export interface RestrictedEditingExceptionCommandParams {
29
- forceValue?: unknown;
30
- }
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 restricted-editing/restrictededitingexceptioncommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ /**
10
+ * The command that toggles exceptions from the restricted editing on text.
11
+ */
12
+ export default class RestrictedEditingExceptionCommand extends Command {
13
+ /**
14
+ * A flag indicating whether the command is active
15
+ *
16
+ * @readonly
17
+ */
18
+ value: boolean;
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ refresh(): void;
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ execute(options?: RestrictedEditingExceptionCommandParams): void;
27
+ }
28
+ export interface RestrictedEditingExceptionCommandParams {
29
+ forceValue?: unknown;
30
+ }
@@ -1,61 +1,61 @@
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 restricted-editing/restrictededitingexceptioncommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- /**
10
- * The command that toggles exceptions from the restricted editing on text.
11
- */
12
- export default class RestrictedEditingExceptionCommand extends Command {
13
- /**
14
- * @inheritDoc
15
- */
16
- refresh() {
17
- const model = this.editor.model;
18
- const doc = model.document;
19
- this.value = !!doc.selection.getAttribute('restrictedEditingException');
20
- this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'restrictedEditingException');
21
- }
22
- /**
23
- * @inheritDoc
24
- */
25
- execute(options = {}) {
26
- const model = this.editor.model;
27
- const document = model.document;
28
- const selection = document.selection;
29
- const valueToSet = (options.forceValue === undefined) ? !this.value : options.forceValue;
30
- model.change(writer => {
31
- const ranges = model.schema.getValidRanges(selection.getRanges(), 'restrictedEditingException');
32
- if (selection.isCollapsed) {
33
- if (valueToSet) {
34
- writer.setSelectionAttribute('restrictedEditingException', valueToSet);
35
- }
36
- else {
37
- const isSameException = (value) => {
38
- return value.item.getAttribute('restrictedEditingException') === this.value;
39
- };
40
- const focus = selection.focus;
41
- const exceptionStart = focus.getLastMatchingPosition(isSameException, { direction: 'backward' });
42
- const exceptionEnd = focus.getLastMatchingPosition(isSameException);
43
- writer.removeSelectionAttribute('restrictedEditingException');
44
- if (!(focus.isEqual(exceptionStart) || focus.isEqual(exceptionEnd))) {
45
- writer.removeAttribute('restrictedEditingException', writer.createRange(exceptionStart, exceptionEnd));
46
- }
47
- }
48
- }
49
- else {
50
- for (const range of ranges) {
51
- if (valueToSet) {
52
- writer.setAttribute('restrictedEditingException', valueToSet, range);
53
- }
54
- else {
55
- writer.removeAttribute('restrictedEditingException', range);
56
- }
57
- }
58
- }
59
- });
60
- }
61
- }
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 restricted-editing/restrictededitingexceptioncommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ /**
10
+ * The command that toggles exceptions from the restricted editing on text.
11
+ */
12
+ export default class RestrictedEditingExceptionCommand extends Command {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ refresh() {
17
+ const model = this.editor.model;
18
+ const doc = model.document;
19
+ this.value = !!doc.selection.getAttribute('restrictedEditingException');
20
+ this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'restrictedEditingException');
21
+ }
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ execute(options = {}) {
26
+ const model = this.editor.model;
27
+ const document = model.document;
28
+ const selection = document.selection;
29
+ const valueToSet = (options.forceValue === undefined) ? !this.value : options.forceValue;
30
+ model.change(writer => {
31
+ const ranges = model.schema.getValidRanges(selection.getRanges(), 'restrictedEditingException');
32
+ if (selection.isCollapsed) {
33
+ if (valueToSet) {
34
+ writer.setSelectionAttribute('restrictedEditingException', valueToSet);
35
+ }
36
+ else {
37
+ const isSameException = (value) => {
38
+ return value.item.getAttribute('restrictedEditingException') === this.value;
39
+ };
40
+ const focus = selection.focus;
41
+ const exceptionStart = focus.getLastMatchingPosition(isSameException, { direction: 'backward' });
42
+ const exceptionEnd = focus.getLastMatchingPosition(isSameException);
43
+ writer.removeSelectionAttribute('restrictedEditingException');
44
+ if (!(focus.isEqual(exceptionStart) || focus.isEqual(exceptionEnd))) {
45
+ writer.removeAttribute('restrictedEditingException', writer.createRange(exceptionStart, exceptionEnd));
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ for (const range of ranges) {
51
+ if (valueToSet) {
52
+ writer.setAttribute('restrictedEditingException', valueToSet, range);
53
+ }
54
+ else {
55
+ writer.removeAttribute('restrictedEditingException', range);
56
+ }
57
+ }
58
+ }
59
+ });
60
+ }
61
+ }
@@ -1,39 +1,39 @@
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 restricted-editing/restrictededitingmode/converters
7
- */
8
- import type { Editor } from 'ckeditor5/src/core';
9
- import { type MatcherPattern, type ModelPostFixer, type UpcastDispatcher } from 'ckeditor5/src/engine';
10
- /**
11
- * Adds a visual highlight style to a restricted editing exception that the selection is anchored to.
12
- *
13
- * The highlight is turned on by adding the `.restricted-editing-exception_selected` class to the
14
- * exception in the view:
15
- *
16
- * * The class is removed before the conversion starts, as callbacks added with the `'highest'` priority
17
- * to {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher} events.
18
- * * The class is added in the view post-fixer, after other changes in the model tree are converted to the view.
19
- *
20
- * This way, adding and removing the highlight does not interfere with conversion.
21
- */
22
- export declare function setupExceptionHighlighting(editor: Editor): void;
23
- /**
24
- * A post-fixer that prevents removing a collapsed marker from the document.
25
- */
26
- export declare function resurrectCollapsedMarkerPostFixer(editor: Editor): ModelPostFixer;
27
- /**
28
- * A post-fixer that extends a marker when the user types on its boundaries.
29
- */
30
- export declare function extendMarkerOnTypingPostFixer(editor: Editor): ModelPostFixer;
31
- /**
32
- * A view highlight-to-marker conversion helper.
33
- *
34
- * @param config Conversion configuration.
35
- */
36
- export declare function upcastHighlightToMarker(config: {
37
- view: MatcherPattern;
38
- model: () => string;
39
- }): (dispatcher: UpcastDispatcher) => void;
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 restricted-editing/restrictededitingmode/converters
7
+ */
8
+ import type { Editor } from 'ckeditor5/src/core';
9
+ import { type MatcherPattern, type ModelPostFixer, type UpcastDispatcher } from 'ckeditor5/src/engine';
10
+ /**
11
+ * Adds a visual highlight style to a restricted editing exception that the selection is anchored to.
12
+ *
13
+ * The highlight is turned on by adding the `.restricted-editing-exception_selected` class to the
14
+ * exception in the view:
15
+ *
16
+ * * The class is removed before the conversion starts, as callbacks added with the `'highest'` priority
17
+ * to {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher} events.
18
+ * * The class is added in the view post-fixer, after other changes in the model tree are converted to the view.
19
+ *
20
+ * This way, adding and removing the highlight does not interfere with conversion.
21
+ */
22
+ export declare function setupExceptionHighlighting(editor: Editor): void;
23
+ /**
24
+ * A post-fixer that prevents removing a collapsed marker from the document.
25
+ */
26
+ export declare function resurrectCollapsedMarkerPostFixer(editor: Editor): ModelPostFixer;
27
+ /**
28
+ * A post-fixer that extends a marker when the user types on its boundaries.
29
+ */
30
+ export declare function extendMarkerOnTypingPostFixer(editor: Editor): ModelPostFixer;
31
+ /**
32
+ * A view highlight-to-marker conversion helper.
33
+ *
34
+ * @param config Conversion configuration.
35
+ */
36
+ export declare function upcastHighlightToMarker(config: {
37
+ view: MatcherPattern;
38
+ model: () => string;
39
+ }): (dispatcher: UpcastDispatcher) => void;
@@ -1,142 +1,142 @@
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 { Matcher } from 'ckeditor5/src/engine';
6
- import { getMarkerAtPosition } from './utils';
7
- const HIGHLIGHT_CLASS = 'restricted-editing-exception_selected';
8
- /**
9
- * Adds a visual highlight style to a restricted editing exception that the selection is anchored to.
10
- *
11
- * The highlight is turned on by adding the `.restricted-editing-exception_selected` class to the
12
- * exception in the view:
13
- *
14
- * * The class is removed before the conversion starts, as callbacks added with the `'highest'` priority
15
- * to {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher} events.
16
- * * The class is added in the view post-fixer, after other changes in the model tree are converted to the view.
17
- *
18
- * This way, adding and removing the highlight does not interfere with conversion.
19
- */
20
- export function setupExceptionHighlighting(editor) {
21
- const view = editor.editing.view;
22
- const model = editor.model;
23
- const highlightedMarkers = new Set();
24
- // Adding the class.
25
- view.document.registerPostFixer((writer) => {
26
- const modelSelection = model.document.selection;
27
- const marker = getMarkerAtPosition(editor, modelSelection.anchor);
28
- if (!marker) {
29
- return false;
30
- }
31
- for (const viewElement of editor.editing.mapper.markerNameToElements(marker.name)) {
32
- writer.addClass(HIGHLIGHT_CLASS, viewElement);
33
- highlightedMarkers.add(viewElement);
34
- }
35
- return false;
36
- });
37
- // Removing the class.
38
- editor.conversion.for('editingDowncast').add(dispatcher => {
39
- // Make sure the highlight is removed on every possible event, before conversion is started.
40
- dispatcher.on('insert', removeHighlight, { priority: 'highest' });
41
- dispatcher.on('remove', removeHighlight, { priority: 'highest' });
42
- dispatcher.on('attribute', removeHighlight, { priority: 'highest' });
43
- dispatcher.on('selection', removeHighlight, { priority: 'highest' });
44
- function removeHighlight() {
45
- view.change(writer => {
46
- for (const item of highlightedMarkers.values()) {
47
- writer.removeClass(HIGHLIGHT_CLASS, item);
48
- highlightedMarkers.delete(item);
49
- }
50
- });
51
- }
52
- });
53
- }
54
- /**
55
- * A post-fixer that prevents removing a collapsed marker from the document.
56
- */
57
- export function resurrectCollapsedMarkerPostFixer(editor) {
58
- // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
59
- return writer => {
60
- let changeApplied = false;
61
- for (const { name, data } of editor.model.document.differ.getChangedMarkers()) {
62
- if (name.startsWith('restrictedEditingException') && data.newRange && data.newRange.root.rootName == '$graveyard') {
63
- writer.updateMarker(name, {
64
- range: writer.createRange(writer.createPositionAt(data.oldRange.start))
65
- });
66
- changeApplied = true;
67
- }
68
- }
69
- return changeApplied;
70
- };
71
- }
72
- /**
73
- * A post-fixer that extends a marker when the user types on its boundaries.
74
- */
75
- export function extendMarkerOnTypingPostFixer(editor) {
76
- // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
77
- return writer => {
78
- let changeApplied = false;
79
- for (const change of editor.model.document.differ.getChanges()) {
80
- if (change.type == 'insert' && change.name == '$text') {
81
- changeApplied = _tryExtendMarkerStart(editor, change.position, change.length, writer) || changeApplied;
82
- changeApplied = _tryExtendMarkedEnd(editor, change.position, change.length, writer) || changeApplied;
83
- }
84
- }
85
- return changeApplied;
86
- };
87
- }
88
- /**
89
- * A view highlight-to-marker conversion helper.
90
- *
91
- * @param config Conversion configuration.
92
- */
93
- export function upcastHighlightToMarker(config) {
94
- return (dispatcher) => dispatcher.on('element:span', (evt, data, conversionApi) => {
95
- const { writer } = conversionApi;
96
- const matcher = new Matcher(config.view);
97
- const matcherResult = matcher.match(data.viewItem);
98
- // If there is no match, this callback should not do anything.
99
- if (!matcherResult) {
100
- return;
101
- }
102
- const match = matcherResult.match;
103
- // Force consuming element's name (taken from upcast helpers elementToElement converter).
104
- match.name = true;
105
- const { modelRange: convertedChildrenRange } = conversionApi.convertChildren(data.viewItem, data.modelCursor);
106
- conversionApi.consumable.consume(data.viewItem, match);
107
- const markerName = config.model();
108
- const fakeMarkerStart = writer.createElement('$marker', { 'data-name': markerName });
109
- const fakeMarkerEnd = writer.createElement('$marker', { 'data-name': markerName });
110
- // Insert in reverse order to use converter content positions directly (without recalculating).
111
- writer.insert(fakeMarkerEnd, convertedChildrenRange.end);
112
- writer.insert(fakeMarkerStart, convertedChildrenRange.start);
113
- data.modelRange = writer.createRange(writer.createPositionBefore(fakeMarkerStart), writer.createPositionAfter(fakeMarkerEnd));
114
- data.modelCursor = data.modelRange.end;
115
- });
116
- }
117
- /**
118
- * Extend marker if change detected on marker's start position.
119
- */
120
- function _tryExtendMarkerStart(editor, position, length, writer) {
121
- const markerAtStart = getMarkerAtPosition(editor, position.getShiftedBy(length));
122
- if (markerAtStart && markerAtStart.getStart().isEqual(position.getShiftedBy(length))) {
123
- writer.updateMarker(markerAtStart, {
124
- range: writer.createRange(markerAtStart.getStart().getShiftedBy(-length), markerAtStart.getEnd())
125
- });
126
- return true;
127
- }
128
- return false;
129
- }
130
- /**
131
- * Extend marker if change detected on marker's end position.
132
- */
133
- function _tryExtendMarkedEnd(editor, position, length, writer) {
134
- const markerAtEnd = getMarkerAtPosition(editor, position);
135
- if (markerAtEnd && markerAtEnd.getEnd().isEqual(position)) {
136
- writer.updateMarker(markerAtEnd, {
137
- range: writer.createRange(markerAtEnd.getStart(), markerAtEnd.getEnd().getShiftedBy(length))
138
- });
139
- return true;
140
- }
141
- return false;
142
- }
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 { Matcher } from 'ckeditor5/src/engine';
6
+ import { getMarkerAtPosition } from './utils';
7
+ const HIGHLIGHT_CLASS = 'restricted-editing-exception_selected';
8
+ /**
9
+ * Adds a visual highlight style to a restricted editing exception that the selection is anchored to.
10
+ *
11
+ * The highlight is turned on by adding the `.restricted-editing-exception_selected` class to the
12
+ * exception in the view:
13
+ *
14
+ * * The class is removed before the conversion starts, as callbacks added with the `'highest'` priority
15
+ * to {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher} events.
16
+ * * The class is added in the view post-fixer, after other changes in the model tree are converted to the view.
17
+ *
18
+ * This way, adding and removing the highlight does not interfere with conversion.
19
+ */
20
+ export function setupExceptionHighlighting(editor) {
21
+ const view = editor.editing.view;
22
+ const model = editor.model;
23
+ const highlightedMarkers = new Set();
24
+ // Adding the class.
25
+ view.document.registerPostFixer((writer) => {
26
+ const modelSelection = model.document.selection;
27
+ const marker = getMarkerAtPosition(editor, modelSelection.anchor);
28
+ if (!marker) {
29
+ return false;
30
+ }
31
+ for (const viewElement of editor.editing.mapper.markerNameToElements(marker.name)) {
32
+ writer.addClass(HIGHLIGHT_CLASS, viewElement);
33
+ highlightedMarkers.add(viewElement);
34
+ }
35
+ return false;
36
+ });
37
+ // Removing the class.
38
+ editor.conversion.for('editingDowncast').add(dispatcher => {
39
+ // Make sure the highlight is removed on every possible event, before conversion is started.
40
+ dispatcher.on('insert', removeHighlight, { priority: 'highest' });
41
+ dispatcher.on('remove', removeHighlight, { priority: 'highest' });
42
+ dispatcher.on('attribute', removeHighlight, { priority: 'highest' });
43
+ dispatcher.on('selection', removeHighlight, { priority: 'highest' });
44
+ function removeHighlight() {
45
+ view.change(writer => {
46
+ for (const item of highlightedMarkers.values()) {
47
+ writer.removeClass(HIGHLIGHT_CLASS, item);
48
+ highlightedMarkers.delete(item);
49
+ }
50
+ });
51
+ }
52
+ });
53
+ }
54
+ /**
55
+ * A post-fixer that prevents removing a collapsed marker from the document.
56
+ */
57
+ export function resurrectCollapsedMarkerPostFixer(editor) {
58
+ // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
59
+ return writer => {
60
+ let changeApplied = false;
61
+ for (const { name, data } of editor.model.document.differ.getChangedMarkers()) {
62
+ if (name.startsWith('restrictedEditingException') && data.newRange && data.newRange.root.rootName == '$graveyard') {
63
+ writer.updateMarker(name, {
64
+ range: writer.createRange(writer.createPositionAt(data.oldRange.start))
65
+ });
66
+ changeApplied = true;
67
+ }
68
+ }
69
+ return changeApplied;
70
+ };
71
+ }
72
+ /**
73
+ * A post-fixer that extends a marker when the user types on its boundaries.
74
+ */
75
+ export function extendMarkerOnTypingPostFixer(editor) {
76
+ // This post-fixer shouldn't be necessary after https://github.com/ckeditor/ckeditor5/issues/5778.
77
+ return writer => {
78
+ let changeApplied = false;
79
+ for (const change of editor.model.document.differ.getChanges()) {
80
+ if (change.type == 'insert' && change.name == '$text') {
81
+ changeApplied = _tryExtendMarkerStart(editor, change.position, change.length, writer) || changeApplied;
82
+ changeApplied = _tryExtendMarkedEnd(editor, change.position, change.length, writer) || changeApplied;
83
+ }
84
+ }
85
+ return changeApplied;
86
+ };
87
+ }
88
+ /**
89
+ * A view highlight-to-marker conversion helper.
90
+ *
91
+ * @param config Conversion configuration.
92
+ */
93
+ export function upcastHighlightToMarker(config) {
94
+ return (dispatcher) => dispatcher.on('element:span', (evt, data, conversionApi) => {
95
+ const { writer } = conversionApi;
96
+ const matcher = new Matcher(config.view);
97
+ const matcherResult = matcher.match(data.viewItem);
98
+ // If there is no match, this callback should not do anything.
99
+ if (!matcherResult) {
100
+ return;
101
+ }
102
+ const match = matcherResult.match;
103
+ // Force consuming element's name (taken from upcast helpers elementToElement converter).
104
+ match.name = true;
105
+ const { modelRange: convertedChildrenRange } = conversionApi.convertChildren(data.viewItem, data.modelCursor);
106
+ conversionApi.consumable.consume(data.viewItem, match);
107
+ const markerName = config.model();
108
+ const fakeMarkerStart = writer.createElement('$marker', { 'data-name': markerName });
109
+ const fakeMarkerEnd = writer.createElement('$marker', { 'data-name': markerName });
110
+ // Insert in reverse order to use converter content positions directly (without recalculating).
111
+ writer.insert(fakeMarkerEnd, convertedChildrenRange.end);
112
+ writer.insert(fakeMarkerStart, convertedChildrenRange.start);
113
+ data.modelRange = writer.createRange(writer.createPositionBefore(fakeMarkerStart), writer.createPositionAfter(fakeMarkerEnd));
114
+ data.modelCursor = data.modelRange.end;
115
+ });
116
+ }
117
+ /**
118
+ * Extend marker if change detected on marker's start position.
119
+ */
120
+ function _tryExtendMarkerStart(editor, position, length, writer) {
121
+ const markerAtStart = getMarkerAtPosition(editor, position.getShiftedBy(length));
122
+ if (markerAtStart && markerAtStart.getStart().isEqual(position.getShiftedBy(length))) {
123
+ writer.updateMarker(markerAtStart, {
124
+ range: writer.createRange(markerAtStart.getStart().getShiftedBy(-length), markerAtStart.getEnd())
125
+ });
126
+ return true;
127
+ }
128
+ return false;
129
+ }
130
+ /**
131
+ * Extend marker if change detected on marker's end position.
132
+ */
133
+ function _tryExtendMarkedEnd(editor, position, length, writer) {
134
+ const markerAtEnd = getMarkerAtPosition(editor, position);
135
+ if (markerAtEnd && markerAtEnd.getEnd().isEqual(position)) {
136
+ writer.updateMarker(markerAtEnd, {
137
+ range: writer.createRange(markerAtEnd.getStart(), markerAtEnd.getEnd().getShiftedBy(length))
138
+ });
139
+ return true;
140
+ }
141
+ return false;
142
+ }
@@ -1,30 +1,30 @@
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 type { Editor } from 'ckeditor5/src/core';
6
- import type { DocumentSelection, Marker, Position, Range } from 'ckeditor5/src/engine';
7
- /**
8
- * @module restricted-editing/restrictededitingmode/utils
9
- */
10
- /**
11
- * Returns a single "restricted-editing-exception" marker at a given position. Contrary to
12
- * {@link module:engine/model/markercollection~MarkerCollection#getMarkersAtPosition}, it returnd a marker also when the postion is
13
- * equal to one of the marker's start or end positions.
14
- */
15
- export declare function getMarkerAtPosition(editor: Editor, position: Position): Marker | undefined;
16
- /**
17
- * Checks if the position is fully contained in the range. Positions equal to range start or end are considered "in".
18
- */
19
- export declare function isPositionInRangeBoundaries(range: Range, position: Position): boolean;
20
- /**
21
- * Checks if the selection is fully contained in the marker. Positions on marker boundaries are considered "in".
22
- *
23
- * ```xml
24
- * <marker>[]foo</marker> -> true
25
- * <marker>f[oo]</marker> -> true
26
- * <marker>f[oo</marker> ba]r -> false
27
- * <marker>foo</marker> []bar -> false
28
- * ```
29
- */
30
- export declare function isSelectionInMarker(selection: DocumentSelection, marker?: Marker): boolean;
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 type { Editor } from 'ckeditor5/src/core';
6
+ import type { DocumentSelection, Marker, Position, Range } from 'ckeditor5/src/engine';
7
+ /**
8
+ * @module restricted-editing/restrictededitingmode/utils
9
+ */
10
+ /**
11
+ * Returns a single "restricted-editing-exception" marker at a given position. Contrary to
12
+ * {@link module:engine/model/markercollection~MarkerCollection#getMarkersAtPosition}, it returnd a marker also when the postion is
13
+ * equal to one of the marker's start or end positions.
14
+ */
15
+ export declare function getMarkerAtPosition(editor: Editor, position: Position): Marker | undefined;
16
+ /**
17
+ * Checks if the position is fully contained in the range. Positions equal to range start or end are considered "in".
18
+ */
19
+ export declare function isPositionInRangeBoundaries(range: Range, position: Position): boolean;
20
+ /**
21
+ * Checks if the selection is fully contained in the marker. Positions on marker boundaries are considered "in".
22
+ *
23
+ * ```xml
24
+ * <marker>[]foo</marker> -> true
25
+ * <marker>f[oo]</marker> -> true
26
+ * <marker>f[oo</marker> ba]r -> false
27
+ * <marker>foo</marker> []bar -> false
28
+ * ```
29
+ */
30
+ export declare function isSelectionInMarker(selection: DocumentSelection, marker?: Marker): boolean;