Skip to content

Commit

Permalink
Implement link copying option for PDF view context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Oct 14, 2024
1 parent ffc5593 commit 1918a73
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/common/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions src/en-us.strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion src/pdf/pdf-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1918a73

Please sign in to comment.