feat: add "Copy Note URL" option to tree context menu#9424
feat: add "Copy Note URL" option to tree context menu#9424abdussamad567 wants to merge 1 commit intoTriliumNext:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a 'Copy Note URL' feature to the tree context menu. The review identifies several issues, including a critical runtime error where the 'clipboard' service is used incorrectly instead of the 'navigator.clipboard' API. Additionally, the feedback highlights inconsistent indentation, the need for internationalization of the new menu item, and a recommendation to use the full note path in the URL for better context. A TypeScript compilation error was also noted due to the missing command mapping for the new feature.
| } | ||
| 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) { |
There was a problem hiding this comment.
There are several issues in this block:
- Critical Bug: The
clipboardservice (imported from../services/clipboard.js) does not have awriteTextmethod. This will cause a runtime error and breaks both the new feature and the existing "Copy Note Path" functionality. You must usenavigator.clipboard.writeTextto interact with the system clipboard. - Indentation: The indentation is inconsistent with the rest of the method.
- URL Format: It is recommended to use the full
notePathinstead of just thenoteId. In Trilium, the path (e.g.,root/.../noteId) preserves the navigational context, which is especially important for cloned notes.
| } | |
| 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) { |
| { 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 } |
There was a problem hiding this comment.
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 }|
I’ve fixed the issues mentioned:
Please review again 🙌 |
|
Hi, Thanks for your efforts, but unfortunately we cannot accept this PR. For more information, see #9119 (comment). |
Summary
This PR adds a small improvement to the note context menu by introducing a "Copy Note URL" option.
Why
The existing "Copy note link" uses an internal format, which isn’t very useful outside Trilium.
This change makes it easier to open or share notes from external tools like browsers or task managers.
What’s added
${window.location.origin}/#root/<noteId>Notes
tree_context_menu.ts