Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(text): set the emoji picker's row apart, with the emoji button's icon
Elian Doranbfda42c3adf0
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsxindex 49487edc88..114fee0bde 100644--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx@@ -493,6 +493,8 @@ export interface CommandEntry {iconSvg?: string;/** A character drawn as the icon, such as an emoji, in place of {@link CommandEntry.icon}. */iconText?: string;+ /** Draws a divider above the entry, setting it and those after it apart from the ones before. */+ startsGroup?: boolean;}/**@@ -527,7 +529,8 @@ export function CommandMentionList<T extends CommandEntry>({ query, source, anch// Keeps the focus where the query is typed, which closes the list without it.onMouseDown={(e) => e.preventDefault()}>- {autocomplete.items.map((entry, index) => (+ {autocomplete.items.map((entry, index) => [+ entry.startsGroup && index > 0 && <FormDropdownDivider key={`divider-${entry.id}`} />,<SuggestionOption key={entry.id} autocomplete={autocomplete} index={index}><span><SuggestionRowContent@@ -537,7 +540,7 @@ export function CommandMentionList<T extends CommandEntry>({ query, source, anch/></span></SuggestionOption>- ))}+ ])}</menu></NoteSuggestionPopup>);diff --git a/apps/client/src/widgets/type_widgets/text/mention_list_view.spec.tsx b/apps/client/src/widgets/type_widgets/text/mention_list_view.spec.tsxindex 772f8f3440..9d74745454 100644--- a/apps/client/src/widgets/type_widgets/text/mention_list_view.spec.tsx+++ b/apps/client/src/widgets/type_widgets/text/mention_list_view.spec.tsx@@ -262,7 +262,7 @@ describe("createSlashCommandList", () => {describe("createEmojiList", () => {const suggestions: EmojiSuggestion[] = [{ id: ":grinning face:", title: ":grinning face:", text: "π" },- { id: ":show-all:", title: "Show all emoji...", text: "grin", opensPicker: true }+ { id: ":show-all:", title: "Show all emoji...", text: "grin", opensPicker: true, icon: "<svg class=\"emoji\"></svg>" }];it("lists the emoji as command rows, the emoji as the icon, and commits the one picked", async () => {@@ -277,12 +277,14 @@ describe("createEmojiList", () => {expect(search).toHaveBeenLastCalledWith("grin");expect(list.element?.matches(".dropdown-menu.note-autocomplete-menu")).toBe(true);- const [ grinning, showAll ] = [ ...(list.element?.querySelectorAll(".tn-menu-scroll > .dropdown-item") ?? []) ];+ const [ grinning, showAll ] = [ ...(list.element?.querySelectorAll(".tn-menu-scroll > .dropdown-item:not(.dropdown-divider)") ?? []) ];expect(grinning.classList.contains("tn-menu-active")).toBe(true);expect(grinning.querySelector(".tn-icon.note-suggestion-text-icon")?.textContent).toBe("π");expect(grinning.querySelector(".search-result-title")?.textContent).toBe(":grinning face:");- // The entry opening the picker has an icon of its own.- expect(showAll.querySelector(".tn-icon.bx-smile")).not.toBeNull();+ // The entry opening the picker is set apart, with the icon of the editor's emoji button.+ expect(showAll.previousElementSibling?.matches(".dropdown-divider")).toBe(true);+ expect(showAll.querySelector(".note-suggestion-svg-icon > svg.emoji")).not.toBeNull();+ expect(grinning.previousElementSibling).toBeNull();expect(showAll.querySelector(".search-result-title")?.textContent).toBe("Show all emoji...");expect(key("Enter")).toBe(true);diff --git a/apps/client/src/widgets/type_widgets/text/mention_list_view.tsx b/apps/client/src/widgets/type_widgets/text/mention_list_view.tsxindex b2ed62d7d9..868912e12d 100644--- a/apps/client/src/widgets/type_widgets/text/mention_list_view.tsx+++ b/apps/client/src/widgets/type_widgets/text/mention_list_view.tsx@@ -198,13 +198,17 @@ function toCommandEntry(definition: SlashCommandDefinition): SlashCommandEntry {type EmojiEntry = CommandEntry & { suggestion: EmojiSuggestion };-/** An emoji as a command row, the emoji its icon, or the entry that opens the picker. */+/**+ * An emoji as a command row, the emoji its icon, or the entry that opens the picker, set apart from+ * the emoji above it with the icon of the editor's emoji button.+ */function toEmojiEntry(suggestion: EmojiSuggestion): EmojiEntry {return {id: suggestion.id,title: suggestion.title,- icon: suggestion.opensPicker ? "bx bx-smile" : undefined,+ iconSvg: suggestion.icon,iconText: suggestion.opensPicker ? undefined : suggestion.text,+ startsGroup: suggestion.opensPicker,suggestion};}diff --git a/packages/ckeditor5/src/plugins/mention/emoji_mention.spec.ts b/packages/ckeditor5/src/plugins/mention/emoji_mention.spec.tsindex cfa767bab1..311ef3f603 100644--- a/packages/ckeditor5/src/plugins/mention/emoji_mention.spec.ts+++ b/packages/ckeditor5/src/plugins/mention/emoji_mention.spec.ts@@ -207,7 +207,10 @@ describe("TriliumEmojiMention", () => {const items = query("grinning");expect(items).toHaveLength(2);expect(items[0].text).toBe("π");- expect(items[1]).toEqual({ id: expect.stringContaining("show_all"), title: "Show all emoji...", text: "grinning", opensPicker: true });+ expect(items[1]).toEqual({+ id: expect.stringContaining("show_all"), title: "Show all emoji...", text: "grinning", opensPicker: true,+ icon: expect.stringContaining("<svg")+ });});it("hands the query over to the picker instead of inserting anything", async () => {diff --git a/packages/ckeditor5/src/plugins/mention/emoji_mention.ts b/packages/ckeditor5/src/plugins/mention/emoji_mention.tsindex bee9ecd43d..c4ebff5490 100644--- a/packages/ckeditor5/src/plugins/mention/emoji_mention.ts+++ b/packages/ckeditor5/src/plugins/mention/emoji_mention.ts@@ -1,3 +1,4 @@+import { IconEmoji } from "@ckeditor/ckeditor5-icons";import {type Editor,EmojiPicker,@@ -36,6 +37,8 @@ export interface EmojiSuggestion extends MentionFeedObjectItem {title: string;/** Marks the entry that opens the emoji picker on the query instead of inserting an emoji. */opensPicker?: boolean;+ /** The picker entry's icon as SVG markup: the one of the toolbar button that opens the picker too. */+ icon?: string;}/**@@ -117,7 +120,7 @@ export default class TriliumEmojiMention extends Plugin {// One slot is given up to the hand-off entry, so the list length stays at the limit.return [...emojis.slice(0, limit - 1),- { id: SHOW_ALL_ID, title: this.editor.t("Show all emoji..."), text: query, opensPicker: true }+ { id: SHOW_ALL_ID, title: this.editor.t("Show all emoji..."), text: query, opensPicker: true, icon: IconEmoji }];}