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
client/tree pane: update context menu action tooltips
Adorian Doran37cce4dce386
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 94b8dbd95e..96ff6b7901 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2554,11 +2554,11 @@"cut": "Cut","move-to": "Move to...","paste-into": "Paste into",- "paste-into-tooltip_one": "Paste into this note as a clone",- "paste-into-tooltip_other": "Paste into this note as clones",+ "paste-into-tooltip_one": "Paste into this note\nThe note will be pasted as a clone, which means it's the exact same note (not a duplicate), but in multiple places at once.",+ "paste-into-tooltip_other": "Paste into this note\nThe notes will be pasted as clones, which means they're the exact same notes (not duplicates), but in multiple places at once.","paste-after": "Paste after",- "paste-after-tooltip_one": "Paste after this note as a clone",- "paste-after-tooltip_other": "Paste after this note as clones",+ "paste-after-tooltip_one": "Paste after this note\nThe note will be pasted as a clone, which means it's the exact same note (not a duplicate), but in multiple places at once.",+ "paste-after-tooltip_other": "Paste after this note\nThe notes will be pasted as clones, which means they're the exact same notes (not duplicates), but in multiple places at once.","duplicate": "Duplicate","duplicate-with-children": "Note and its children","duplicate-note-only": "This note only",@@ -2570,7 +2570,7 @@"convert-to-attachment-confirm": "Are you sure you want to convert the selected notes into attachments of their parent notes? This operation only applies to Image notes, other notes will be skipped.","open-in-popup": "Quick edit","clone": "Copy",- "clone-tooltip": "Paste it elsewhere to have the same note in two places at once"+ "clone-tooltip": "Copy for pasting as a clone somewhere else in the tree, or as a link into a note"},"read-only-info": {"edit-note": "Edit note"diff --git a/apps/client/src/widgets/react/Menu.spec.tsx b/apps/client/src/widgets/react/Menu.spec.tsxindex a0b3bc7bd7..5233e08c9a 100644--- a/apps/client/src/widgets/react/Menu.spec.tsx+++ b/apps/client/src/widgets/react/Menu.spec.tsx@@ -14,9 +14,13 @@ vi.mock("../../services/keyboard_actions", async (importOriginal) => {...original,default: {...original.default,- getAction: vi.fn(async (name: string) => (name === "cutNotesToClipboard"- ? { effectiveShortcuts: [ "CommandOrControl+X" ] }- : undefined))+ getAction: vi.fn(async (name: string) => {+ const shortcuts: Record<string, string[]> = {+ cutNotesToClipboard: [ "CommandOrControl+X" ],+ deleteNotes: [ "CommandOrControl+D" ]+ };+ return name in shortcuts ? { effectiveShortcuts: shortcuts[name] } : undefined;+ })}};});@@ -343,7 +347,11 @@ describe("Menu with an action row", () => {items: [{ title: "Cut", command: "cut", uiIcon: "bx bx-cut", keyboardShortcut: "cutNotesToClipboard" },{ title: "Copy", command: "copy", uiIcon: "bx bx-copy", enabled: false },- { title: "Delete", command: "delete", uiIcon: "bx bx-trash", uiIconBadge: "bx bx-x", tooltip: "Delete, asking first" }+ {+ title: "Delete", command: "delete",+ uiIcon: "bx bx-trash", uiIconBadge: "bx bx-x",+ keyboardShortcut: "deleteNotes", tooltip: "Delete\nAsks first"+ }]},{ kind: "separator" },@@ -392,7 +400,7 @@ describe("Menu with an action row", () => {]);});- it("names each action, or describes it, with the shortcut a row would show in its tooltip", async () => {+ it("names or describes each action in its tooltip, with the shortcut on line 1", async () => {const { menu } = renderMenu();const [ cut, , remove ] = menu.querySelectorAll<HTMLElement>(".tn-menu-action");const tooltipText = (button: HTMLElement | undefined) => {@@ -408,7 +416,9 @@ describe("Menu with an action row", () => {const shortcut = joinShortcut(formatShortcut("CommandOrControl+X"));await vi.waitFor(() => expect(tooltipText(cut)).toBe(`Cut (${shortcut})`));expect(shortcut).not.toContain("CommandOrControl");- expect(tooltipText(remove)).toBe("Delete, asking first");+ const deleteKey = joinShortcut(formatShortcut("CommandOrControl+D"));+ await vi.waitFor(() =>+ expect(tooltipText(remove)).toBe(`Delete (${deleteKey})\nAsks first`));});it("gives the actions no tooltip on a phone, which has no pointer to hover with", async () => {diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex b57c0b94c9..783f64b9ef 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -1538,12 +1538,16 @@ export function useStaticTooltipWithKeyboardShortcut() {const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>();// Memoized, since `useStaticTooltip` recreates the tooltip whenever its config changes.- const config = useMemo(() => ({- title: keyboardShortcut?.length- ? `${title} (${keyboardShortcut.map((shortcut) => joinShortcut(formatShortcut(shortcut))).join(", ")})`- : title,- ...opts- }), [ title, keyboardShortcut, opts ]);+ const config = useMemo(() => {+ if (!keyboardShortcut?.length) return { title, ...opts };++ // The shortcut follows the first line, which names the action; later lines describe it.+ const shortcuts = keyboardShortcut+ .map((shortcut) => joinShortcut(formatShortcut(shortcut)))+ .join(", ");+ const [ name, ...description ] = title.split("\n");+ return { title: [ `${name} (${shortcuts})`, ...description ].join("\n"), ...opts };+ }, [ title, keyboardShortcut, opts ]);useStaticTooltip(elRef, config);useEffect(() => {