Skip to content

Build your personal knowledge base with Trilium Notes

fix(editor): keep find highlight visible on link widgets

matt wilkie35b2f108eadb
diff --git a/packages/ckeditor5/src/plugins/find_in_link_widgets.spec.ts b/packages/ckeditor5/src/plugins/find_in_link_widgets.spec.ts
index 99d369d7e5..f57c074650 100644
--- a/packages/ckeditor5/src/plugins/find_in_link_widgets.spec.ts
+++ b/packages/ckeditor5/src/plugins/find_in_link_widgets.spec.ts
@@ -93,6 +93,37 @@ describe("FindInLinkWidgets", () => {
expect(selectedReference).not.toBeNull();
});
+ it("keeps the highlight visible on anchor widgets that a theme styles", () => {
+ // The first two rules mirror CKEditor's find-and-replace theme; the last mirrors an
+ // application theme that gives every link its own background.
+ const themeStyle = document.createElement("style");
+ themeStyle.textContent =
+ ":root { --ck-color-highlight-background: rgb(255, 255, 0); }" +
+ ".ck-find-result { background: var(--ck-color-highlight-background); }" +
+ ".ck-content a { background: transparent; }";
+ document.head.append(themeStyle);
+ try {
+ setModelData(
+ editor.model,
+ '<paragraph>match <reference href="#root/ref"></reference></paragraph>'
+ );
+ editor.execute("find", "match");
+
+ const reference = editor.editing.view.getDomRoot()?.querySelector("a.reference-link");
+ if (!reference) {
+ throw new Error("The test editor did not render the reference link.");
+ }
+ expect(reference.classList.contains("ck-find-result")).toBe(true);
+ expect(getComputedStyle(reference).backgroundColor).toBe("rgb(255, 255, 0)");
+
+ editor.execute("findNext");
+ expect(reference.classList.contains("ck-find-result_selected")).toBe(true);
+ expect(getComputedStyle(reference).backgroundColor).toBe("rgb(255, 150, 51)");
+ } finally {
+ themeStyle.remove();
+ }
+ });
+
it("matches only the text that each link widget displays", () => {
setModelData(
editor.model,
diff --git a/packages/ckeditor5/src/plugins/find_in_link_widgets.ts b/packages/ckeditor5/src/plugins/find_in_link_widgets.ts
index 5a7166edac..c1345c3ccd 100644
--- a/packages/ckeditor5/src/plugins/find_in_link_widgets.ts
+++ b/packages/ckeditor5/src/plugins/find_in_link_widgets.ts
@@ -1,3 +1,5 @@
+import "../theme/find_in_link_widgets.css";
+
import {
_sortFindResultsByMarkerPositions as sortFindResults,
Collection,
diff --git a/packages/ckeditor5/src/theme/find_in_link_widgets.css b/packages/ckeditor5/src/theme/find_in_link_widgets.css
new file mode 100644
index 0000000000..86b291f24b
--- /dev/null
+++ b/packages/ckeditor5/src/theme/find_in_link_widgets.css
@@ -0,0 +1,9 @@
+/* Themes style anchors with their own background, which outranks the find highlight on the
+ reference link widget. Restate the CKEditor find colors at widget specificity. */
+.ck-content .ck-widget.ck-find-result {
+ background: var(--ck-color-highlight-background);
+}
+
+.ck-content .ck-widget.ck-find-result_selected {
+ background: hsl(29, 100%, 60%);
+}