Skip to content

Build your personal knowledge base with Trilium Notes

fix(text): centre a note suggestion's icon against its path

Elian Doran9af747feeea5
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index 91c9a4f70a..fe11707a62 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -1723,6 +1723,25 @@ body:not(.mobile) #launcher-pane.horizontal .dropdown-submenu > .dropdown-menu {
white-space: normal !important;
}
+/*
+ * A note suggestion is an icon beside a note path. Laid out as a row so the two are centred against
+ * each other: left inline, the icon aligns on the text baseline, and `vertical-align: middle` only
+ * gets it as far as the x-height — about a pixel below where the capitals it sits beside read as
+ * centred. The icon carries its own font, so no baseline rule can line the two up in general.
+ */
+.ck.ck-mentions .ck-button.note-mention-suggestion {
+ display: flex;
+ align-items: center;
+ gap: 0.4em;
+ text-align: start;
+}
+
+/* Its own box, so the row centres the glyph itself rather than the line box around it. */
+.ck.ck-mentions .ck-button.note-mention-suggestion > .bx {
+ line-height: 1;
+ flex-shrink: 0;
+}
+
/* Slash commands */
.ck.ck-slash-command-button {
diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.ts
index ce78f2654a..4897f8d954 100644
--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts
@@ -258,6 +258,13 @@ describe("CK config - mention feed", () => {
expect((noteItem.firstChild as HTMLElement).className).toBe("bx bx-folder");
expect(noteItem.querySelector("b")?.textContent).toBe("Hello");
+ // The row is exactly the icon and a wrapped title: the stylesheet lays the two out against
+ // each other, which it cannot do if the title is spread into the button as loose nodes.
+ expect(noteItem.className).toBe("note-mention-suggestion");
+ expect(noteItem.childNodes).toHaveLength(2);
+ const title = noteItem.querySelector(".note-mention-suggestion-title");
+ expect(title?.textContent).toBe("Hello");
+
// A "create note" suggestion with no icon/title gets the plus icon and an empty title.
const createItem = feedConfig.itemRenderer({ action: "create-note" });
expect((createItem.firstChild as HTMLElement).className).toBe("bx bx-plus");
diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.ts
index c6e86b53bf..3c276dc15e 100644
--- a/apps/client/src/widgets/type_widgets/text/config.ts
+++ b/apps/client/src/widgets/type_widgets/text/config.ts
@@ -235,6 +235,7 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfi
itemRenderer: (item) => {
const suggestion = item as Suggestion;
const itemElement = document.createElement("button");
+ itemElement.className = "note-mention-suggestion";
const iconElement = document.createElement("span");
// Choose appropriate icon based on action
@@ -244,10 +245,13 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfi
}
iconElement.className = iconClass;
- itemElement.append(iconElement, document.createTextNode(" "));
+ // The title keeps a wrapper of its own rather than being spread into the
+ // button: the row lays the icon out against the title as a whole (see the
+ // `note-mention-suggestion` rule), which it cannot do over loose text nodes.
const titleContainer = document.createElement("span");
+ titleContainer.className = "note-mention-suggestion-title";
titleContainer.innerHTML = suggestion.highlightedNotePathTitle ?? "";
- itemElement.append(...titleContainer.childNodes, document.createTextNode(" "));
+ itemElement.append(iconElement, titleContainer);
return itemElement;
},