@ckeditor/ckeditor5-highlight 40.0.0 → 40.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,28 +5,28 @@ All changes in the package are documented in the main repository. See: https://g
5
5
 
6
6
  Changes for the past releases are available below.
7
7
 
8
- ## [19.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v18.0.0...v19.0.0) (2020-04-29)
8
+ ## [19.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v18.0.0...v19.0.0) (April 29, 2020)
9
9
 
10
10
  ### Other changes
11
11
 
12
12
  * Updated translations. ([d38fb8b](https://github.com/ckeditor/ckeditor5-highlight/commit/d38fb8b))
13
13
 
14
14
 
15
- ## [18.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v17.0.0...v18.0.0) (2020-03-19)
15
+ ## [18.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v17.0.0...v18.0.0) (March 19, 2020)
16
16
 
17
17
  ### Other changes
18
18
 
19
19
  * Updated translations. ([e7398fe](https://github.com/ckeditor/ckeditor5-highlight/commit/e7398fe))
20
20
 
21
21
 
22
- ## [17.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v16.0.0...v17.0.0) (2020-02-19)
22
+ ## [17.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v16.0.0...v17.0.0) (February 19, 2020)
23
23
 
24
24
  ### Other changes
25
25
 
26
26
  * Updated translations. ([d016764](https://github.com/ckeditor/ckeditor5-highlight/commit/d016764))
27
27
 
28
28
 
29
- ## [16.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v15.0.0...v16.0.0) (2019-12-04)
29
+ ## [16.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v15.0.0...v16.0.0) (December 4, 2019)
30
30
 
31
31
  ### Bug fixes
32
32
 
@@ -37,7 +37,7 @@ Changes for the past releases are available below.
37
37
  * Updated translations. ([65c337a](https://github.com/ckeditor/ckeditor5-highlight/commit/65c337a))
38
38
 
39
39
 
40
- ## [15.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.5...v15.0.0) (2019-10-23)
40
+ ## [15.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.5...v15.0.0) (October 23, 2019)
41
41
 
42
42
  ### Other changes
43
43
 
@@ -45,7 +45,7 @@ Changes for the past releases are available below.
45
45
  * Updated translations. ([ac64146](https://github.com/ckeditor/ckeditor5-highlight/commit/ac64146)) ([d87a3ee](https://github.com/ckeditor/ckeditor5-highlight/commit/d87a3ee))
46
46
 
47
47
 
48
- ## [11.0.5](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.4...v11.0.5) (2019-08-26)
48
+ ## [11.0.5](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.4...v11.0.5) (August 26, 2019)
49
49
 
50
50
  ### Bug fixes
51
51
 
@@ -58,24 +58,24 @@ Changes for the past releases are available below.
58
58
  * Updated translations. ([e0138f6](https://github.com/ckeditor/ckeditor5-highlight/commit/e0138f6))
59
59
 
60
60
 
61
- ## [11.0.4](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.3...v11.0.4) (2019-07-10)
61
+ ## [11.0.4](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.3...v11.0.4) (July 10, 2019)
62
62
 
63
63
  Internal changes only (updated dependencies, documentation, etc.).
64
64
 
65
65
 
66
- ## [11.0.3](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.2...v11.0.3) (2019-07-04)
66
+ ## [11.0.3](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.2...v11.0.3) (July 4, 2019)
67
67
 
68
68
  Internal changes only (updated dependencies, documentation, etc.).
69
69
 
70
70
 
71
- ## [11.0.2](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.1...v11.0.2) (2019-06-05)
71
+ ## [11.0.2](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.1...v11.0.2) (June 6, 2019)
72
72
 
73
73
  ### Other changes
74
74
 
75
75
  * Updated translations. ([6128b76](https://github.com/ckeditor/ckeditor5-highlight/commit/6128b76))
76
76
 
77
77
 
78
- ## [11.0.1](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.0...v11.0.1) (2019-04-10)
78
+ ## [11.0.1](https://github.com/ckeditor/ckeditor5-highlight/compare/v11.0.0...v11.0.1) (April 4, 2019)
79
79
 
80
80
  ### Other changes
81
81
 
@@ -83,7 +83,7 @@ Internal changes only (updated dependencies, documentation, etc.).
83
83
  * Updated translations. ([6695a99](https://github.com/ckeditor/ckeditor5-highlight/commit/6695a99))
84
84
 
85
85
 
86
- ## [11.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.4...v11.0.0) (2019-02-28)
86
+ ## [11.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.4...v11.0.0) (February 28, 2019)
87
87
 
88
88
  ### Other changes
89
89
 
@@ -94,35 +94,35 @@ Internal changes only (updated dependencies, documentation, etc.).
94
94
  * Upgraded minimal versions of Node to `8.0.0` and npm to `5.7.1`. See: [ckeditor/ckeditor5#1507](https://github.com/ckeditor/ckeditor5/issues/1507). ([612ea3c](https://github.com/ckeditor/ckeditor5-cloud-services/commit/612ea3c))
95
95
 
96
96
 
97
- ## [10.0.4](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.3...v10.0.4) (2018-12-05)
97
+ ## [10.0.4](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.3...v10.0.4) (December 5, 2018)
98
98
 
99
99
  ### Other changes
100
100
 
101
101
  * Improved SVG icons size. See [ckeditor/ckeditor5-theme-lark#206](https://github.com/ckeditor/ckeditor5-theme-lark/issues/206). ([70c99a7](https://github.com/ckeditor/ckeditor5-highlight/commit/70c99a7))
102
102
 
103
103
 
104
- ## [10.0.3](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.2...v10.0.3) (2018-10-08)
104
+ ## [10.0.3](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.2...v10.0.3) (October 8, 2018)
105
105
 
106
106
  ### Other changes
107
107
 
108
108
  * Updated translations. ([01fde3f](https://github.com/ckeditor/ckeditor5-highlight/commit/01fde3f))
109
109
 
110
110
 
111
- ## [10.0.2](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.1...v10.0.2) (2018-07-18)
111
+ ## [10.0.2](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.1...v10.0.2) (July 18, 2018)
112
112
 
113
113
  ### Other changes
114
114
 
115
115
  * Updated translations. ([a48a8c1](https://github.com/ckeditor/ckeditor5-highlight/commit/a48a8c1))
116
116
 
117
117
 
118
- ## [10.0.1](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.0...v10.0.1) (2018-06-21)
118
+ ## [10.0.1](https://github.com/ckeditor/ckeditor5-highlight/compare/v10.0.0...v10.0.1) (June 21, 2018)
119
119
 
120
120
  ### Other changes
121
121
 
122
122
  * Updated translations. ([03f079a](https://github.com/ckeditor/ckeditor5-highlight/commit/03f079a))
123
123
 
124
124
 
125
- ## [10.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v1.0.0-beta.4...v10.0.0) (2018-04-25)
125
+ ## [10.0.0](https://github.com/ckeditor/ckeditor5-highlight/compare/v1.0.0-beta.4...v10.0.0) (April 25, 2018)
126
126
 
127
127
  ### Other changes
128
128
 
@@ -134,19 +134,19 @@ Internal changes only (updated dependencies, documentation, etc.).
134
134
  * The license under which CKEditor 5 is released has been changed from a triple GPL, LGPL and MPL license to a GPL2+ only. See [ckeditor/ckeditor5#991](https://github.com/ckeditor/ckeditor5/issues/991) for more information.
135
135
 
136
136
 
137
- ## [1.0.0-beta.4](https://github.com/ckeditor/ckeditor5-highlight/compare/v1.0.0-beta.2...v1.0.0-beta.4) (2018-04-19)
137
+ ## [1.0.0-beta.4](https://github.com/ckeditor/ckeditor5-highlight/compare/v1.0.0-beta.2...v1.0.0-beta.4) (April 19, 2018)
138
138
 
139
139
  ### Other changes
140
140
 
141
141
  * Updated translations. ([479fe41](https://github.com/ckeditor/ckeditor5-highlight/commit/479fe41))
142
142
 
143
143
 
144
- ## [1.0.0-beta.2](https://github.com/ckeditor/ckeditor5-highlight/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2018-04-10)
144
+ ## [1.0.0-beta.2](https://github.com/ckeditor/ckeditor5-highlight/compare/v1.0.0-beta.1...v1.0.0-beta.2) (April 10, 2018)
145
145
 
146
146
  Internal changes only (updated dependencies, documentation, etc.).
147
147
 
148
148
 
149
- ## [1.0.0-beta.1](https://github.com/ckeditor/ckeditor5-highlight/compare/v0.0.1...v1.0.0-beta.1) (2018-03-15)
149
+ ## [1.0.0-beta.1](https://github.com/ckeditor/ckeditor5-highlight/compare/v0.0.1...v1.0.0-beta.1) (March 15, 2018)
150
150
 
151
151
  ### Features
152
152
 
package/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor&nbsp;5 highlight feature** – https://github.com/ckeditor/ckeditor5-highlight <br>
5
- Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
5
+ Copyright (c) 20032023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
14
14
  Trademarks
15
15
  ----------
16
16
 
17
- **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
17
+ **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-highlight",
3
- "version": "40.0.0",
3
+ "version": "40.2.0",
4
4
  "description": "Highlight feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "ckeditor5": "40.0.0"
15
+ "ckeditor5": "40.2.0"
16
16
  },
17
17
  "author": "CKSource (http://cksource.com/)",
18
18
  "license": "GPL-2.0-or-later",
@@ -1,23 +1,23 @@
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 { Highlight, HighlightCommand, HighlightConfig, HighlightEditing, HighlightUI } from './index';
6
- declare module '@ckeditor/ckeditor5-core' {
7
- interface EditorConfig {
8
- /**
9
- * The configuration of the {@link module:highlight/highlight~Highlight} feature.
10
- *
11
- * Read more in {@link module:highlight/highlightconfig~HighlightConfig}.
12
- */
13
- highlight?: HighlightConfig;
14
- }
15
- interface PluginsMap {
16
- [Highlight.pluginName]: Highlight;
17
- [HighlightEditing.pluginName]: HighlightEditing;
18
- [HighlightUI.pluginName]: HighlightUI;
19
- }
20
- interface CommandsMap {
21
- highlight: HighlightCommand;
22
- }
23
- }
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 { Highlight, HighlightCommand, HighlightConfig, HighlightEditing, HighlightUI } from './index';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface EditorConfig {
8
+ /**
9
+ * The configuration of the {@link module:highlight/highlight~Highlight} feature.
10
+ *
11
+ * Read more in {@link module:highlight/highlightconfig~HighlightConfig}.
12
+ */
13
+ highlight?: HighlightConfig;
14
+ }
15
+ interface PluginsMap {
16
+ [Highlight.pluginName]: Highlight;
17
+ [HighlightEditing.pluginName]: HighlightEditing;
18
+ [HighlightUI.pluginName]: HighlightUI;
19
+ }
20
+ interface CommandsMap {
21
+ highlight: HighlightCommand;
22
+ }
23
+ }
@@ -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,28 +1,28 @@
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 highlight/highlight
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import HighlightEditing from './highlightediting';
10
- import HighlightUI from './highlightui';
11
- /**
12
- * The highlight plugin.
13
- *
14
- * For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
15
- *
16
- * This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
17
- * {@link module:highlight/highlightui~HighlightUI} plugins.
18
- */
19
- export default class Highlight extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get requires(): readonly [typeof HighlightEditing, typeof HighlightUI];
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName(): "Highlight";
28
- }
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 highlight/highlight
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import HighlightEditing from './highlightediting';
10
+ import HighlightUI from './highlightui';
11
+ /**
12
+ * The highlight plugin.
13
+ *
14
+ * For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
15
+ *
16
+ * This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
17
+ * {@link module:highlight/highlightui~HighlightUI} plugins.
18
+ */
19
+ export default class Highlight extends Plugin {
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get requires(): readonly [typeof HighlightEditing, typeof HighlightUI];
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName(): "Highlight";
28
+ }
package/src/highlight.js CHANGED
@@ -1,32 +1,32 @@
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 highlight/highlight
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import HighlightEditing from './highlightediting';
10
- import HighlightUI from './highlightui';
11
- /**
12
- * The highlight plugin.
13
- *
14
- * For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
15
- *
16
- * This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
17
- * {@link module:highlight/highlightui~HighlightUI} plugins.
18
- */
19
- export default class Highlight extends Plugin {
20
- /**
21
- * @inheritDoc
22
- */
23
- static get requires() {
24
- return [HighlightEditing, HighlightUI];
25
- }
26
- /**
27
- * @inheritDoc
28
- */
29
- static get pluginName() {
30
- return 'Highlight';
31
- }
32
- }
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 highlight/highlight
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import HighlightEditing from './highlightediting';
10
+ import HighlightUI from './highlightui';
11
+ /**
12
+ * The highlight plugin.
13
+ *
14
+ * For a detailed overview, check the {@glink features/highlight Highlight feature} documentation.
15
+ *
16
+ * This is a "glue" plugin which loads the {@link module:highlight/highlightediting~HighlightEditing} and
17
+ * {@link module:highlight/highlightui~HighlightUI} plugins.
18
+ */
19
+ export default class Highlight extends Plugin {
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get requires() {
24
+ return [HighlightEditing, HighlightUI];
25
+ }
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get pluginName() {
30
+ return 'Highlight';
31
+ }
32
+ }
@@ -1,45 +1,45 @@
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 highlight/highlightcommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- /**
10
- * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
11
- * to apply the text highlighting.
12
- *
13
- * ```ts
14
- * editor.execute( 'highlight', { value: 'greenMarker' } );
15
- * ```
16
- *
17
- * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
18
- * inside a text with the highlight attribute, the command will remove the attribute from the entire range
19
- * of that text.
20
- */
21
- export default class HighlightCommand extends Command {
22
- /**
23
- * A value indicating whether the command is active. If the selection has some highlight attribute,
24
- * it corresponds to the value of that attribute.
25
- *
26
- * @observable
27
- * @readonly
28
- */
29
- value: string | undefined;
30
- /**
31
- * @inheritDoc
32
- */
33
- refresh(): void;
34
- /**
35
- * Executes the command.
36
- *
37
- * @param options Options for the executed command.
38
- * @param options.value The value to apply.
39
- *
40
- * @fires execute
41
- */
42
- execute(options?: {
43
- value?: string | null;
44
- }): void;
45
- }
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 highlight/highlightcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ /**
10
+ * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
11
+ * to apply the text highlighting.
12
+ *
13
+ * ```ts
14
+ * editor.execute( 'highlight', { value: 'greenMarker' } );
15
+ * ```
16
+ *
17
+ * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
18
+ * inside a text with the highlight attribute, the command will remove the attribute from the entire range
19
+ * of that text.
20
+ */
21
+ export default class HighlightCommand extends Command {
22
+ /**
23
+ * A value indicating whether the command is active. If the selection has some highlight attribute,
24
+ * it corresponds to the value of that attribute.
25
+ *
26
+ * @observable
27
+ * @readonly
28
+ */
29
+ value: string | undefined;
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ refresh(): void;
34
+ /**
35
+ * Executes the command.
36
+ *
37
+ * @param options Options for the executed command.
38
+ * @param options.value The value to apply.
39
+ *
40
+ * @fires execute
41
+ */
42
+ execute(options?: {
43
+ value?: string | null;
44
+ }): void;
45
+ }
@@ -1,91 +1,91 @@
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 highlight/highlightcommand
7
- */
8
- import { Command } from 'ckeditor5/src/core';
9
- /**
10
- * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
11
- * to apply the text highlighting.
12
- *
13
- * ```ts
14
- * editor.execute( 'highlight', { value: 'greenMarker' } );
15
- * ```
16
- *
17
- * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
18
- * inside a text with the highlight attribute, the command will remove the attribute from the entire range
19
- * of that text.
20
- */
21
- export default class HighlightCommand extends Command {
22
- /**
23
- * @inheritDoc
24
- */
25
- refresh() {
26
- const model = this.editor.model;
27
- const doc = model.document;
28
- this.value = doc.selection.getAttribute('highlight');
29
- this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'highlight');
30
- }
31
- /**
32
- * Executes the command.
33
- *
34
- * @param options Options for the executed command.
35
- * @param options.value The value to apply.
36
- *
37
- * @fires execute
38
- */
39
- execute(options = {}) {
40
- const model = this.editor.model;
41
- const document = model.document;
42
- const selection = document.selection;
43
- const highlighter = options.value;
44
- model.change(writer => {
45
- if (selection.isCollapsed) {
46
- const position = selection.getFirstPosition();
47
- // When selection is inside text with `highlight` attribute.
48
- if (selection.hasAttribute('highlight')) {
49
- // Find the full highlighted range.
50
- const isSameHighlight = (value) => {
51
- return value.item.hasAttribute('highlight') && value.item.getAttribute('highlight') === this.value;
52
- };
53
- const highlightStart = position.getLastMatchingPosition(isSameHighlight, { direction: 'backward' });
54
- const highlightEnd = position.getLastMatchingPosition(isSameHighlight);
55
- const highlightRange = writer.createRange(highlightStart, highlightEnd);
56
- // Then depending on current value...
57
- if (!highlighter || this.value === highlighter) {
58
- // ...remove attribute when passing highlighter different then current or executing "eraser".
59
- // If we're at the end of the highlighted range, we don't want to remove highlight of the range.
60
- if (!position.isEqual(highlightEnd)) {
61
- writer.removeAttribute('highlight', highlightRange);
62
- }
63
- writer.removeSelectionAttribute('highlight');
64
- }
65
- else {
66
- // ...update `highlight` value.
67
- // If we're at the end of the highlighted range, we don't want to change the highlight of the range.
68
- if (!position.isEqual(highlightEnd)) {
69
- writer.setAttribute('highlight', highlighter, highlightRange);
70
- }
71
- writer.setSelectionAttribute('highlight', highlighter);
72
- }
73
- }
74
- else if (highlighter) {
75
- writer.setSelectionAttribute('highlight', highlighter);
76
- }
77
- }
78
- else {
79
- const ranges = model.schema.getValidRanges(selection.getRanges(), 'highlight');
80
- for (const range of ranges) {
81
- if (highlighter) {
82
- writer.setAttribute('highlight', highlighter, range);
83
- }
84
- else {
85
- writer.removeAttribute('highlight', range);
86
- }
87
- }
88
- }
89
- });
90
- }
91
- }
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 highlight/highlightcommand
7
+ */
8
+ import { Command } from 'ckeditor5/src/core';
9
+ /**
10
+ * The highlight command. It is used by the {@link module:highlight/highlightediting~HighlightEditing highlight feature}
11
+ * to apply the text highlighting.
12
+ *
13
+ * ```ts
14
+ * editor.execute( 'highlight', { value: 'greenMarker' } );
15
+ * ```
16
+ *
17
+ * **Note**: Executing the command without a value removes the attribute from the model. If the selection is collapsed
18
+ * inside a text with the highlight attribute, the command will remove the attribute from the entire range
19
+ * of that text.
20
+ */
21
+ export default class HighlightCommand extends Command {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ refresh() {
26
+ const model = this.editor.model;
27
+ const doc = model.document;
28
+ this.value = doc.selection.getAttribute('highlight');
29
+ this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'highlight');
30
+ }
31
+ /**
32
+ * Executes the command.
33
+ *
34
+ * @param options Options for the executed command.
35
+ * @param options.value The value to apply.
36
+ *
37
+ * @fires execute
38
+ */
39
+ execute(options = {}) {
40
+ const model = this.editor.model;
41
+ const document = model.document;
42
+ const selection = document.selection;
43
+ const highlighter = options.value;
44
+ model.change(writer => {
45
+ if (selection.isCollapsed) {
46
+ const position = selection.getFirstPosition();
47
+ // When selection is inside text with `highlight` attribute.
48
+ if (selection.hasAttribute('highlight')) {
49
+ // Find the full highlighted range.
50
+ const isSameHighlight = (value) => {
51
+ return value.item.hasAttribute('highlight') && value.item.getAttribute('highlight') === this.value;
52
+ };
53
+ const highlightStart = position.getLastMatchingPosition(isSameHighlight, { direction: 'backward' });
54
+ const highlightEnd = position.getLastMatchingPosition(isSameHighlight);
55
+ const highlightRange = writer.createRange(highlightStart, highlightEnd);
56
+ // Then depending on current value...
57
+ if (!highlighter || this.value === highlighter) {
58
+ // ...remove attribute when passing highlighter different then current or executing "eraser".
59
+ // If we're at the end of the highlighted range, we don't want to remove highlight of the range.
60
+ if (!position.isEqual(highlightEnd)) {
61
+ writer.removeAttribute('highlight', highlightRange);
62
+ }
63
+ writer.removeSelectionAttribute('highlight');
64
+ }
65
+ else {
66
+ // ...update `highlight` value.
67
+ // If we're at the end of the highlighted range, we don't want to change the highlight of the range.
68
+ if (!position.isEqual(highlightEnd)) {
69
+ writer.setAttribute('highlight', highlighter, highlightRange);
70
+ }
71
+ writer.setSelectionAttribute('highlight', highlighter);
72
+ }
73
+ }
74
+ else if (highlighter) {
75
+ writer.setSelectionAttribute('highlight', highlighter);
76
+ }
77
+ }
78
+ else {
79
+ const ranges = model.schema.getValidRanges(selection.getRanges(), 'highlight');
80
+ for (const range of ranges) {
81
+ if (highlighter) {
82
+ writer.setAttribute('highlight', highlighter, range);
83
+ }
84
+ else {
85
+ writer.removeAttribute('highlight', range);
86
+ }
87
+ }
88
+ }
89
+ });
90
+ }
91
+ }