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: mention that the items will be pasted as a clone
Adorian Doranb1afdaf104d2
diff --git a/apps/client/src/menus/tree_context_menu.spec.ts b/apps/client/src/menus/tree_context_menu.spec.tsindex b1d8ed629b..e5e6395d30 100644--- a/apps/client/src/menus/tree_context_menu.spec.ts+++ b/apps/client/src/menus/tree_context_menu.spec.ts@@ -8,8 +8,12 @@ import { buildNote } from "../test/easy-froca";import type { MenuItem } from "./context_menu";import { buildTreeContextMenuItems, getDuplicateItems, type TreeCommandNames } from "./tree_context_menu";-vi.mock("../services/clipboard", () => ({ default: { isClipboardEmpty: vi.fn(() => true) } }));+vi.mock("../services/clipboard", () => ({ default: { getContents: vi.fn(() => null) } }));vi.mock("../components/app_context", () => ({ default: { tabManager: { getActiveContext: () => undefined } } }));+vi.mock("../services/i18n", () => ({+ t: (key: string, options?: { count?: number }) =>+ (options?.count === undefined ? key : `${key} ${options.count}`)+}));describe("buildTreeContextMenuItems", () => {/** The menu for a child note, with the note type data the insert submenus read stubbed. */@@ -27,25 +31,42 @@ describe("buildTreeContextMenuItems", () => {return { child, build };}+ async function actionRow(build: () => Promise<MenuItem<TreeCommandNames>[]>) {+ const items = await build();+ type ActionRow = Extract<MenuItem<TreeCommandNames>, { kind: "actions" }>;+ const row = items.find((item): item is ActionRow => "kind" in item && item.kind === "actions");+ return row?.items ?? [];+ }+it("offers the paste actions only while something is cut or copied", async () => {const { build } = setUp();+ const actions = async () => (await actionRow(build)).map((item) => item.command);- async function actions() {- const items = await build();- const row = items.find((item): item is Extract<MenuItem<TreeCommandNames>, { kind: "actions" }> =>- "kind" in item && item.kind === "actions");- return row?.items.map((item) => item.command);- }-+ vi.mocked(clipboard.getContents).mockReturnValue(null);expect(await actions()).toStrictEqual([ "cutNotesToClipboard", "copyNotesToClipboard", "deleteNotes" ]);- vi.mocked(clipboard.isClipboardEmpty).mockReturnValue(false);+ vi.mocked(clipboard.getContents).mockReturnValue({ noteIds: [ "a" ], mode: "cut" });expect(await actions()).toStrictEqual(["cutNotesToClipboard", "copyNotesToClipboard", "pasteNotesFromClipboard", "pasteNotesAfterFromClipboard","deleteNotes"]);});+ it("tells that the paste actions paste clones after Copy, and nothing after Cut", async () => {+ const { build } = setUp();+ const pasteTooltips = async () => (await actionRow(build))+ .filter((item) => item.command?.startsWith("paste"))+ .map((item) => item.tooltip);++ vi.mocked(clipboard.getContents).mockReturnValue({ noteIds: [ "a" ], mode: "cut" });+ expect(await pasteTooltips()).toStrictEqual([ undefined, undefined ]);++ vi.mocked(clipboard.getContents).mockReturnValue({ noteIds: [ "a", "b" ], mode: "copy" });+ expect(await pasteTooltips()).toStrictEqual([+ "tree-context-menu.paste-into-tooltip 2", "tree-context-menu.paste-after-tooltip 2"+ ]);+ });+it("folds the places to open the note in into one split row, quick edit standing on its own", async () => {const { build } = setUp();const items = await build();diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.tsindex 77a2fb1b5c..003a40af9e 100644--- a/apps/client/src/menus/tree_context_menu.ts+++ b/apps/client/src/menus/tree_context_menu.ts@@ -131,6 +131,11 @@ export async function buildTreeContextMenuItems(ctx: TreeContextMenuContext): Prconst notOptionsOrHelp = notOptions && notHelp;const parentNotSearch = !parentNote || parentNote.type !== "search";const insertNoteAfterEnabled = isNotRoot && !isHoisted && parentNotSearch;+ const clipboardContents = clipboard.getContents();+ // Pasting copied notes clones them; pasting cut notes moves them.+ const pasteTooltip = (key: string) => clipboardContents?.mode === "copy"+ ? t(key, { count: clipboardContents.noteIds.length })+ : undefined;// Both submenus are built from the same templates, so they are fetched once and shared.const noteTypeData = insertNoteAfterEnabled || notSearch@@ -159,9 +164,10 @@ export async function buildTreeContextMenuItems(ctx: TreeContextMenuContext): Pr},{ title: t("tree-context-menu.clone"), tooltip: t("tree-context-menu.clone-tooltip"), command: "copyNotesToClipboard", keyboardShortcut: "copyNotesToClipboard", uiIcon: "bx bx-copy", enabled: isNotRoot && !isHoisted && notHelp },// Shown only while something is cut or copied, which is when they are looked for.- ...(clipboard.isClipboardEmpty() ? [] : [+ ...(!clipboardContents ? [] : [{title: t("tree-context-menu.paste-into"),+ tooltip: pasteTooltip("tree-context-menu.paste-into-tooltip"),command: "pasteNotesFromClipboard",keyboardShortcut: "pasteNotesFromClipboard",uiIcon: "bx bx-clipboard",@@ -170,6 +176,7 @@ export async function buildTreeContextMenuItems(ctx: TreeContextMenuContext): Pr},{title: t("tree-context-menu.paste-after"),+ tooltip: pasteTooltip("tree-context-menu.paste-after-tooltip"),command: "pasteNotesAfterFromClipboard",uiIcon: "bx bx-clipboard",uiIconBadge: "bx bx-down-arrow-alt",diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex b0f61a572f..94b8dbd95e 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2554,7 +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-after": "Paste after",+ "paste-after-tooltip_one": "Paste after this note as a clone",+ "paste-after-tooltip_other": "Paste after this note as clones","duplicate": "Duplicate","duplicate-with-children": "Note and its children","duplicate-note-only": "This note only",