Skip to content

Build your personal knowledge base with Trilium Notes

perf(text): stop the hidden CKEditor badge working on every scroll

Elian Doranca21fc568441
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 186aae71ab..1ead2ec4ea 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -2208,10 +2208,6 @@ textarea {
cursor: auto;
}
-.ck-powered-by-balloon {
- display: none !important;
-}
-
.attachment-actions-toolbar {
display: flex;
align-items: center;
diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts
index 6547b6451c..f19885f93c 100644
--- a/packages/ckeditor5/src/plugins.ts
+++ b/packages/ckeditor5/src/plugins.ts
@@ -12,6 +12,7 @@ import StrikethroughAsDel from "./plugins/strikethrough_as_del.js";
import InternalLinkPlugin from "./plugins/internallink.js";
import InsertDateTimePlugin from "./plugins/insert_date_time.js";
import ReferenceLink from "./plugins/referencelink.js";
+import NoPoweredByBadge from "./plugins/no_powered_by_badge.js";
import RemoveFormatLinksPlugin from "./plugins/remove_format_links.js";
import IndentBlockShortcutPlugin from "./plugins/indent_block_shortcut.js";
import MarkdownImportPlugin from "./plugins/markdownimport.js";
@@ -186,7 +187,8 @@ export const CORE_PLUGINS: typeof Plugin[] = [
// Trilium plugins
TriliumMentionUI,
MentionCustomization,
- ReferenceLink
+ ReferenceLink,
+ NoPoweredByBadge
];
/**
diff --git a/packages/ckeditor5/src/plugins/no_powered_by_badge.spec.ts b/packages/ckeditor5/src/plugins/no_powered_by_badge.spec.ts
new file mode 100644
index 0000000000..33d92875cd
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/no_powered_by_badge.spec.ts
@@ -0,0 +1,22 @@
+import { _setModelData as setModelData, Essentials, Paragraph } from "ckeditor5";
+import { describe, expect, it } from "vitest";
+
+import { createTestEditor } from "../../test/editor-kit.js";
+import NoPoweredByBadge from "./no_powered_by_badge.js";
+
+describe("NoPoweredByBadge", () => {
+ it("adds no badge to a focused editor", async () => {
+ const editor = await createTestEditor([ Essentials, Paragraph, NoPoweredByBadge ]);
+ // The badge needs an editable of at least 350 × 50 pixels.
+ editor.ui.view.element?.style.setProperty("width", "600px");
+ editor.ui.getEditableElement()?.style.setProperty("min-height", "200px");
+ setModelData(editor.model, "<paragraph>fo[]o</paragraph>");
+
+ editor.editing.view.focus();
+ await expect.poll(() => editor.ui.focusTracker.isFocused).toBe(true);
+ editor.ui.update();
+ await new Promise((resolve) => setTimeout(resolve, 100));
+
+ expect(document.querySelector(".ck-powered-by-balloon")).toBeNull();
+ });
+});
diff --git a/packages/ckeditor5/src/plugins/no_powered_by_badge.ts b/packages/ckeditor5/src/plugins/no_powered_by_badge.ts
new file mode 100644
index 0000000000..993967856e
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/no_powered_by_badge.ts
@@ -0,0 +1,24 @@
+import { Plugin } from "ckeditor5";
+
+/**
+ * Keeps the "Powered by CKEditor" badge from starting. With a GPL license, `PoweredBy` pins a
+ * balloon to the focused editable and measures and moves it on every scroll and every UI update.
+ * `PoweredBy` checks `_isEnabled()` when the editor is ready, after the plugins are initialized.
+ */
+export default class NoPoweredByBadge extends Plugin {
+
+ static get pluginName() {
+ return "NoPoweredByBadge" as const;
+ }
+
+ init() {
+ const poweredBy = this.editor.ui.poweredBy as unknown as { _isEnabled(): boolean };
+ poweredBy._isEnabled = () => false;
+ }
+}
+
+declare module "ckeditor5" {
+ interface PluginsMap {
+ [NoPoweredByBadge.pluginName]: NoPoweredByBadge;
+ }
+}