Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions apps/client/src/menus/tree_context_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree

{ kind: "separator" },

{ title: t("tree-context-menu.copy-note-path-to-clipboard"), command: "copyNotePathToClipboard", uiIcon: "bx bx-directions", enabled: true },
{ title: t("tree-context-menu.recent-changes-in-subtree"), command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes && notOptionsOrHelp }
{ title: t("tree-context-menu.copy-note-path-to-clipboard"), command: "copyNotePathToClipboard", uiIcon: "bx bx-directions", enabled: true },

{ title: "Copy Note URL", command: "copyNoteUrl", uiIcon: "bx bx-link", enabled: true },

{ title: t("tree-context-menu.recent-changes-in-subtree"), command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes && notOptionsOrHelp }
Comment on lines +177 to +181
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The indentation of the added lines is inconsistent with the surrounding code. Additionally, the menu title should be internationalized using the t() function to support different languages.

Note: You will also need to add copyNoteUrl to the CommandMappings interface in apps/client/src/components/app_context.ts so that it is included in the TreeCommandNames type, otherwise this will cause a TypeScript compilation error.

                    { title: t("tree-context-menu.copy-note-path-to-clipboard"), command: "copyNotePathToClipboard", uiIcon: "bx bx-directions", enabled: true },
                    { title: t("tree-context-menu.copy-note-url"), command: "copyNoteUrl", uiIcon: "bx bx-link", enabled: true },
                    { title: t("tree-context-menu.recent-changes-in-subtree"), command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes && notOptionsOrHelp }


].filter(Boolean) as MenuItem<TreeCommandNames>[]
},

Expand Down Expand Up @@ -348,9 +352,16 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
}

toastService.showMessage(t("tree-context-menu.converted-to-attachments", { count: converted }));
} else if (command === "copyNotePathToClipboard") {
navigator.clipboard.writeText(`#${ notePath}`);
} else if (command) {
}
else if (command === "copyNotePathToClipboard") {
clipboard.writeText(`#${notePath}`);
}
else if (command === "copyNoteUrl") {
const baseUrl = window.location.origin;
clipboard.writeText(
`${baseUrl}/#root/${this.node.data.noteId}`
);
}else if (command) {
Comment on lines +355 to +364
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There are several issues in this block:

  1. Critical Bug: The clipboard service (imported from ../services/clipboard.js) does not have a writeText method. This will cause a runtime error and breaks both the new feature and the existing "Copy Note Path" functionality. You must use navigator.clipboard.writeText to interact with the system clipboard.
  2. Indentation: The indentation is inconsistent with the rest of the method.
  3. URL Format: It is recommended to use the full notePath instead of just the noteId. In Trilium, the path (e.g., root/.../noteId) preserves the navigational context, which is especially important for cloned notes.
Suggested change
}
else if (command === "copyNotePathToClipboard") {
clipboard.writeText(`#${notePath}`);
}
else if (command === "copyNoteUrl") {
const baseUrl = window.location.origin;
clipboard.writeText(
`${baseUrl}/#root/${this.node.data.noteId}`
);
}else if (command) {
} else if (command === "copyNotePathToClipboard") {
navigator.clipboard.writeText(`#${notePath}`);
} else if (command === "copyNoteUrl") {
const baseUrl = window.location.origin;
navigator.clipboard.writeText(`${baseUrl}/#${notePath}`);
} else if (command) {

this.treeWidget.triggerCommand<TreeCommandNames>(command, {
node: this.node,
notePath,
Expand Down