Skip to content

feat: add "Copy Note URL" option to tree context menu#9424

Closed
abdussamad567 wants to merge 1 commit intoTriliumNext:mainfrom
abdussamad567:feature/copy-note-url
Closed

feat: add "Copy Note URL" option to tree context menu#9424
abdussamad567 wants to merge 1 commit intoTriliumNext:mainfrom
abdussamad567:feature/copy-note-url

Conversation

@abdussamad567
Copy link
Copy Markdown

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

  • New menu item: Copy Note URL
  • Copies a full URL:
    ${window.location.origin}/#root/<noteId>
  • Uses existing clipboard service

Notes

  • Follows existing patterns in tree_context_menu.ts
  • No breaking changes
  • Minimal and isolated change

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 14, 2026
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 '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.

Comment on lines +355 to +364
}
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) {
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) {

Comment on lines +177 to +181
{ 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 }
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 }

@abdussamad567
Copy link
Copy Markdown
Author

I’ve fixed the issues mentioned:

  • Updated clipboard usage
  • Fixed URL format

Please review again 🙌

@eliandoran
Copy link
Copy Markdown
Contributor

Hi,

Thanks for your efforts, but unfortunately we cannot accept this PR. For more information, see #9119 (comment).

@eliandoran eliandoran closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants