Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
text editor/add a copy URL command for links
Adorian Doran61ad26f9173e
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 604c7a6ebb..0dc7a3af27 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2114,7 +2114,8 @@"copy_image_to_clipboard": "Copy image to clipboard"},"link": {- "failed_to_open": "Failed to open link '{{- href}}': {{- message}}"+ "failed_to_open": "Failed to open link '{{- href}}': {{- message}}",+ "copy_url": "Copy URL"},"link_context_menu": {"open_note_in_new_tab": "Open note in a new tab",diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.tsindex 7f7e1ab280..c013aeef26 100644--- a/apps/client/src/widgets/type_widgets/text/config.ts+++ b/apps/client/src/widgets/type_widgets/text/config.ts@@ -135,7 +135,8 @@ export async function buildConfig(opts: BuildEditorOptions): Promise<EditorConfi},link: {defaultProtocol: "https://",- allowedProtocols: ALLOWED_PROTOCOLS+ allowedProtocols: ALLOWED_PROTOCOLS,+ toolbar: ["linkPreview", "copyLinkUrl", "|", "editLink", "linkProperties", "unlink"]},bookmark: {toolbar: [diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.tsindex cdbf4710cf..05a777ca7a 100644--- a/packages/ckeditor5/src/plugins.ts+++ b/packages/ckeditor5/src/plugins.ts@@ -24,6 +24,7 @@ import { Collapsible } from "@triliumnext/ckeditor5-collapsible";import { Footnotes } from "@triliumnext/ckeditor5-footnotes";import { Math, AutoformatMath } from "@triliumnext/ckeditor5-math";import CopyAnchorLinkButton from "./plugins/copy_anchor_link.js";+import CopyLinkUrlButton from "./plugins/copy_link_url.js";import ImageActions from "./plugins/image_actions.js";// import "@triliumnext/ckeditor5-mermaid/index.css";@@ -73,6 +74,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [LinkEmbedToolbar,TodoListMultistate,CopyAnchorLinkButton,+ CopyLinkUrlButton,ImageActions,];diff --git a/packages/ckeditor5/src/plugins/copy_link_url.ts b/packages/ckeditor5/src/plugins/copy_link_url.tsnew file mode 100644index 0000000000..da57764369--- /dev/null+++ b/packages/ckeditor5/src/plugins/copy_link_url.ts@@ -0,0 +1,38 @@+import { ButtonView, Plugin } from "ckeditor5";+import copyIcon from "../icons/copy.svg?raw";++/**+ * Adds a "Copy URL" button to the link balloon toolbar, placed right after the URL preview.+ * Copies the selected link's href to the clipboard via the host-provided `clipboard.copy`+ * callback (which handles the cross-browser fallback and the success/error toast).+ */+export default class CopyLinkUrlButton extends Plugin {++ init() {+ const editor = this.editor;++ editor.ui.componentFactory.add("copyLinkUrl", (locale) => {+ const button = new ButtonView(locale);+ button.set({+ label: this._translate("link.copy_url"),+ icon: copyIcon,+ tooltip: true+ });++ this.listenTo(button, "execute", () => {+ const href = editor.commands.get("link")?.value;+ if (typeof href === "string" && href) {+ editor.config.get("clipboard")?.copy?.(href);+ }+ });++ return button;+ });+ }++ private _translate(key: string) {+ const translate = this.editor.config.get("translate") as ((key: string) => string) | undefined;+ return translate ? translate(key) : key;+ }++}