From 68e4b4eaad265d97996f5f135295616652cf911b Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 22 Oct 2020 16:32:13 +0100 Subject: [PATCH] macOS: Fixes #3404: Show context menu option to copy a link --- ElectronClient/gui/NoteEditor/utils/contextMenu.ts | 2 +- ElectronClient/gui/NoteEditor/utils/useMessageHandler.ts | 2 +- ElectronClient/gui/note-viewer/index.html | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ElectronClient/gui/NoteEditor/utils/contextMenu.ts b/ElectronClient/gui/NoteEditor/utils/contextMenu.ts index ed65ecf74..170d2ff47 100644 --- a/ElectronClient/gui/NoteEditor/utils/contextMenu.ts +++ b/ElectronClient/gui/NoteEditor/utils/contextMenu.ts @@ -117,7 +117,7 @@ export function menuItems():ContextMenuItems { onAction: async (options:ContextMenuOptions) => { clipboard.writeText(options.linkToCopy !== null ? options.linkToCopy : options.textToCopy); }, - isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Link, + isActive: (itemType:ContextMenuItemType, options:ContextMenuOptions) => itemType === ContextMenuItemType.Link || !!options.linkToCopy, }, }; } diff --git a/ElectronClient/gui/NoteEditor/utils/useMessageHandler.ts b/ElectronClient/gui/NoteEditor/utils/useMessageHandler.ts index c9b0d8135..20ec4c08d 100644 --- a/ElectronClient/gui/NoteEditor/utils/useMessageHandler.ts +++ b/ElectronClient/gui/NoteEditor/utils/useMessageHandler.ts @@ -41,7 +41,7 @@ export default function useMessageHandler(scrollWhenReady:any, setScrollWhenRead itemType: arg0 && arg0.type, resourceId: arg0.resourceId, textToCopy: arg0.textToCopy, - linkToCopy: null, + linkToCopy: arg0.linkToCopy || null, htmlToCopy: '', insertContent: () => { console.warn('insertContent() not implemented'); }, }); diff --git a/ElectronClient/gui/note-viewer/index.html b/ElectronClient/gui/note-viewer/index.html index a99fd76e8..5a0dbe00c 100644 --- a/ElectronClient/gui/note-viewer/index.html +++ b/ElectronClient/gui/note-viewer/index.html @@ -368,9 +368,12 @@ const selectedText = window.getSelection().toString(); if (selectedText) { + const linkToCopy = event.target && event.target.getAttribute('href') ? event.target.getAttribute('href') : null; + ipcProxySendToHost('contextMenu', { type: 'text', textToCopy: selectedText, + linkToCopy: linkToCopy, }); } else if (event.target.getAttribute('href')) { ipcProxySendToHost('contextMenu', {