Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow context menu to display options for both copy text and copy URL #3474

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ElectronClient/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
let itemType:ContextMenuItemType = ContextMenuItemType.None;
let resourceId = '';
let textToCopy = '';
const urlToCopy = '';

if (element.nodeName === 'IMG') {
itemType = ContextMenuItemType.Image;
Expand All @@ -638,7 +639,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
textToCopy = editor.selection.getContent({ format: 'text' });
}

contextMenuActionOptions.current = { itemType, resourceId, textToCopy };
contextMenuActionOptions.current = { itemType, resourceId, textToCopy, urlToCopy };


return item.isActive(itemType) ? itemNameNS : '';
Expand Down
8 changes: 5 additions & 3 deletions ElectronClient/gui/NoteEditor/utils/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export enum ContextMenuItemType {
Resource = 'resource',
Text = 'text',
Link = 'link',
LinkAndText = 'linkAndText',
}

export interface ContextMenuOptions {
itemType: ContextMenuItemType,
resourceId: string,
textToCopy: string,
urlToCopy: string,
}

interface ContextMenuItem {
Expand Down Expand Up @@ -86,14 +88,14 @@ export function menuItems():ContextMenuItems {
onAction: async (options:ContextMenuOptions) => {
clipboard.writeText(options.textToCopy);
},
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Text,
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Text || itemType === ContextMenuItemType.LinkAndText,
},
copyLinkUrl: {
label: _('Copy Link Address'),
onAction: async (options:ContextMenuOptions) => {
clipboard.writeText(options.textToCopy);
clipboard.writeText(options.urlToCopy);
},
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Link,
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Link || itemType === ContextMenuItemType.LinkAndText,
},
};
}
Expand Down
1 change: 1 addition & 0 deletions ElectronClient/gui/NoteEditor/utils/useMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function useMessageHandler(scrollWhenReady:any, setScrollWhenRead
itemType: arg0 && arg0.type,
resourceId: arg0.resourceId,
textToCopy: arg0.textToCopy,
urlToCopy: arg0.urlToCopy,
});

menu.popup(bridge().window());
Expand Down
12 changes: 9 additions & 3 deletions ElectronClient/gui/note-viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,21 @@
} else {
const selectedText = window.getSelection().toString();

if (selectedText) {
if (selectedText && !event.target.getAttribute('href')) {
ipcProxySendToHost('contextMenu', {
type: 'text',
textToCopy: selectedText,
});
} else if (event.target.getAttribute('href')) {
} else if (selectedText && event.target.getAttribute('href')) {
ipcProxySendToHost('contextMenu', {
type: 'linkAndText',
textToCopy: selectedText,
urlToCopy: event.target.getAttribute('href'),
});
} else if (!selectedText && event.target.getAttribute('href')) {
ipcProxySendToHost('contextMenu', {
type: 'link',
textToCopy: event.target.getAttribute('href'),
urlToCopy: event.target.getAttribute('href'),
});
}
}
Expand Down