From 1918a735a3d4bbba5aab18167a5c2a172f204579 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Mon, 14 Oct 2024 19:58:44 +0300 Subject: [PATCH] Implement link copying option for PDF view context menu Fixes zotero/zotero#3494 --- src/common/context-menu.js | 9 +++++++++ src/en-us.strings.js | 1 + src/pdf/pdf-view.js | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/common/context-menu.js b/src/common/context-menu.js index bf7b01be..1d79bd70 100644 --- a/src/common/context-menu.js +++ b/src/common/context-menu.js @@ -91,6 +91,15 @@ export function createViewContextMenu(reader, params) { x: params.x, y: params.y, itemGroups: createItemGroup([ + [ + { + label: reader._getString('pdfReader.copyLink'), + disabled: !(params.overlay && params.overlay.type === 'external-link' && !reader.canCopy), + onCommand: () => { + navigator.clipboard.writeText(params.overlay.url); + } + } + ], [ { label: reader._getString('general.copy'), diff --git a/src/en-us.strings.js b/src/en-us.strings.js index b0ef361a..908af38f 100644 --- a/src/en-us.strings.js +++ b/src/en-us.strings.js @@ -191,6 +191,7 @@ export default { 'pdfReader.convertToUnderline': 'Convert to Underline', 'pdfReader.size': 'Size', 'pdfReader.merge': 'Merge', + 'pdfReader.copyLink': 'Copy Link', 'pdfReader.a11yAnnotationModifierMac': 'Option', 'pdfReader.a11yAnnotationModifier': 'Alt', 'pdfReader.a11yAnnotationModifierControl': 'Control', diff --git a/src/pdf/pdf-view.js b/src/pdf/pdf-view.js index 6e5df5a4..6360ab1f 100644 --- a/src/pdf/pdf-view.js +++ b/src/pdf/pdf-view.js @@ -1680,7 +1680,11 @@ class PDFView { if (this._selectedAnnotationIDs.length !== 0) { this._onSelectAnnotations([], event); } - this._onOpenViewContextMenu({ x: br.x + event.clientX, y: br.y + event.clientY }); + let overlay; + if (position) { + overlay = this._getSelectableOverlay(position); + } + this._onOpenViewContextMenu({ x: br.x + event.clientX, y: br.y + event.clientY, overlay }); } else if (!selectedAnnotations.includes(selectableAnnotation)) { this._onSelectAnnotations([selectableAnnotation.id], event);