Skip to content

feat: add "Copy note URL to clipboard" option (#5728)#9119

Closed
argusagent wants to merge 3 commits intoTriliumNext:mainfrom
argusagent:fix/copy-note-url-to-clipboard
Closed

feat: add "Copy note URL to clipboard" option (#5728)#9119
argusagent wants to merge 3 commits intoTriliumNext:mainfrom
argusagent:fix/copy-note-url-to-clipboard

Conversation

@argusagent
Copy link
Copy Markdown
Contributor

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:

  • Internal path (existing): #root/9d5BlXlV2HqJ/Cr18psi2jD2D
  • Full URL (new): http://localhost:37840/#root/9d5BlXlV2HqJ/Cr18psi2jD2D

Changes

  • apps/client/src/menus/tree_context_menu.ts — added copyNoteUrlToClipboard menu item and handler
  • apps/client/src/translations/en/translation.json — added copy-note-url-to-clipboard translation string
  • apps/client/src/widgets/layout/Breadcrumb.tsx — added URL copy option to breadcrumb context menus

Implementation

// Strips any existing hash and appends the note path
const baseUrl = window.location.href.replace(/#.*$/, "");
navigator.clipboard.writeText(`${baseUrl}#${notePath}`);

This approach correctly handles all environments: web browser, Electron desktop, and any reverse proxy setups.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 20, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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: Copy Note URL: Added a new context menu option "Copy note URL to clipboard" to both the note tree and breadcrumb menus. This allows users to copy a full, shareable URL for a note, addressing the limitation of only being able to copy internal path fragments previously.
  • Cross-Environment Compatibility: The new functionality correctly constructs the full URL by combining the base URL (stripping any existing hash) with the note path, ensuring it works seamlessly across web browsers, Electron desktop applications, and environments with reverse proxies.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +355 to +356
const baseUrl = window.location.href.replace(/#.*$/, "");
navigator.clipboard.writeText(`${baseUrl}#${notePath}`);
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

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.

Suggested change
const baseUrl = window.location.href.replace(/#.*$/, "");
navigator.clipboard.writeText(`${baseUrl}#${notePath}`);
const baseUrl = window.location.href.replace(/#.*$/, "");
copyTextWithToast(`${baseUrl}#${notePath}`);

Comment on lines +445 to +448
handler: () => {
const baseUrl = window.location.href.replace(/#.*$/, "");
copyTextWithToast(`${baseUrl}#${notePath}`);
}
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 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.

@eliandoran
Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflicts size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy link to note

2 participants