feat: add "Copy note URL to clipboard" option (#5728)#9119
feat: add "Copy note URL to clipboard" option (#5728)#9119argusagent wants to merge 3 commits intoTriliumNext:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant usability improvement by enabling users to easily obtain a complete, shareable URL for any note. Previously, only internal path fragments were available, which proved insufficient for sharing direct links, especially within the desktop application. The new feature integrates into existing context menus, providing a straightforward way to copy a fully qualified URL, enhancing the sharing and accessibility of notes across different platforms. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'Copy note URL to clipboard' feature, which is a great addition for sharing notes. The implementation is mostly correct, but I've identified a couple of areas for improvement. There's some code duplication for generating the URL across two different files. Additionally, the user feedback for the copy action is inconsistent between the two context menus where this new option is added. My review comments provide specific suggestions to address these points for better maintainability and a more consistent user experience.
| const baseUrl = window.location.href.replace(/#.*$/, ""); | ||
| navigator.clipboard.writeText(`${baseUrl}#${notePath}`); |
There was a problem hiding this comment.
This correctly copies the URL. However, it doesn't provide any feedback to the user. The other implementation of this feature in Breadcrumb.tsx uses copyTextWithToast to show a notification. For a consistent user experience, it's recommended to use copyTextWithToast here as well. You'll need to import copyTextWithToast from ../services/clipboard_ext.js.
| const baseUrl = window.location.href.replace(/#.*$/, ""); | |
| navigator.clipboard.writeText(`${baseUrl}#${notePath}`); | |
| const baseUrl = window.location.href.replace(/#.*$/, ""); | |
| copyTextWithToast(`${baseUrl}#${notePath}`); |
| handler: () => { | ||
| const baseUrl = window.location.href.replace(/#.*$/, ""); | ||
| copyTextWithToast(`${baseUrl}#${notePath}`); | ||
| } |
There was a problem hiding this comment.
The logic to construct the note URL is duplicated here and in apps/client/src/menus/tree_context_menu.ts. To improve maintainability and prevent future inconsistencies, this logic should be extracted into a shared helper function. For instance, a function like getNoteUrl(notePath) could be created in a suitable service (e.g., clipboard_ext.ts or a new url.ts service) and then used in both places.
|
Hi, Thanks for the PR, but copy link to note (#5728) doesn't make much sense on the desktop unless we use a nice trilium:// protocol (as requested by #4988). The reasoning is that in the future the Desktop instance will no longer expose a port by default, making the URL completely useless. In reality, the only reason why the desktop exposes a port is ETAPI and the web clipper API. |
Summary
Closes #5728
Adds a "Copy note URL to clipboard" option to the note tree context menu and breadcrumb context menu.
Problem
The existing "Copy note path to clipboard" option only copies the internal path fragment (e.g.
#root/9d5BlXlV2HqJ/Cr18psi2jD2D), which is not a usable URL for most users. On the desktop app, there is no browser URL bar to copy from, making it difficult to share a direct link to a specific note.Solution
Adds a new context menu item that constructs and copies the full URL by combining the current base URL with the note path hash. This works correctly for both the web interface and the desktop (Electron) app.
Example output:
#root/9d5BlXlV2HqJ/Cr18psi2jD2Dhttp://localhost:37840/#root/9d5BlXlV2HqJ/Cr18psi2jD2DChanges
apps/client/src/menus/tree_context_menu.ts— addedcopyNoteUrlToClipboardmenu item and handlerapps/client/src/translations/en/translation.json— addedcopy-note-url-to-clipboardtranslation stringapps/client/src/widgets/layout/Breadcrumb.tsx— added URL copy option to breadcrumb context menusImplementation
This approach correctly handles all environments: web browser, Electron desktop, and any reverse proxy setups.