Skip to content

Commit ca0aa47

Browse files
committed
1 parent b5055a9 commit ca0aa47

5 files changed

Lines changed: 77 additions & 8 deletions

File tree

app.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
Table,
3232
Undo,
3333
WoltlabAttachment,
34+
WoltlabAutoLink,
3435
WoltlabAutosave,
3536
WoltlabBbcode,
3637
WoltlabBlockQuote,
@@ -97,6 +98,7 @@ const defaultConfig: Core.EditorConfig = {
9798

9899
// WoltLab
99100
WoltlabAttachment.WoltlabAttachment,
101+
WoltlabAutoLink.WoltlabAutoLink,
100102
WoltlabAutosave.WoltlabAutosave,
101103
WoltlabBlockQuote.WoltlabBlockQuote,
102104
WoltlabBbcode.WoltlabBbcode,
@@ -172,13 +174,5 @@ export async function create(
172174
configuration,
173175
);
174176

175-
// Unconditionally disable the `AutoLink` plugin which interferes with our
176-
// own link detection and all creates potentially invalid links.
177-
// See https://github.com/ckeditor/ckeditor5/issues/14497
178-
if (editor.plugins.has(Link.AutoLink)) {
179-
const autoLink = editor.plugins.get(Link.AutoLink);
180-
autoLink.forceDisabled("app.ts");
181-
}
182-
183177
return editor;
184178
}

modules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export * as Utils from "@ckeditor/ckeditor5-utils";
3333
export * as Widget from "@ckeditor/ckeditor5-widget";
3434

3535
export * as WoltlabAttachment from "./plugins/ckeditor5-woltlab-attachment/src";
36+
export * as WoltlabAutoLink from "./plugins/ckeditor5-woltlab-autolink/src";
3637
export * as WoltlabAutosave from "./plugins/ckeditor5-woltlab-autosave/src";
3738
export * as WoltlabBbcode from "./plugins/ckeditor5-woltlab-bbcode/src";
3839
export * as WoltlabBlockQuote from "./plugins/ckeditor5-woltlab-block-quote/src";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"author": "WoltLab GmbH",
3+
"license": "LGPL-2.1-or-later",
4+
"main": "src/index.ts",
5+
"private": true
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @author Alexander Ebert
3+
* @copyright 2001-2024 WoltLab GmbH
4+
* @license LGPL-2.1-or-later
5+
* @since 6.0
6+
*/
7+
8+
export { WoltlabAutoLink } from "./woltlabautolink";
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Disables the AutoLink plugin during the normal editing to prevent incorrect
3+
* transformations and to defer the link detection to the server side. Pasting
4+
* a link while having an active text selection is selectively enabled.
5+
*
6+
* @author Alexander Ebert
7+
* @copyright 2001-2024 WoltLab GmbH
8+
* @license LGPL-2.1-or-later
9+
* @since 6.0
10+
*/
11+
12+
import { Plugin } from "@ckeditor/ckeditor5-core";
13+
import { AutoLink } from "@ckeditor/ckeditor5-link";
14+
15+
export class WoltlabAutoLink extends Plugin {
16+
readonly #key = "WoltlabAutoLink";
17+
18+
static get pluginName() {
19+
return "WoltlabAutoLink" as const;
20+
}
21+
22+
static get requires() {
23+
return [AutoLink] as const;
24+
}
25+
26+
init() {
27+
if (!this.editor.plugins.has(AutoLink)) {
28+
return;
29+
}
30+
31+
// Unconditionally disable the `AutoLink` plugin which interferes with our
32+
// own link detection and all creates potentially invalid links.
33+
// See https://github.com/ckeditor/ckeditor5/issues/14497
34+
const autoLink = this.editor.plugins.get(AutoLink);
35+
autoLink.forceDisabled(this.#key);
36+
37+
// Replacing text with a link from clipboard is provided by the `AutoLink`
38+
// plugin, requiring us to enable the plugin for the duration of the paste.
39+
//
40+
// AutoLink’s event listener uses the "high" priority.
41+
const clipboardPipeline = this.editor.plugins.get("ClipboardPipeline");
42+
clipboardPipeline.on(
43+
"inputTransformation",
44+
() => {
45+
autoLink.clearForceDisabled(this.#key);
46+
},
47+
{ priority: "highest" },
48+
);
49+
50+
clipboardPipeline.on(
51+
"inputTransformation",
52+
() => {
53+
autoLink.forceDisabled(this.#key);
54+
},
55+
{ priority: "normal" },
56+
);
57+
}
58+
}
59+
60+
export default WoltlabAutoLink;

0 commit comments

Comments
 (0)