diff options
author | Bennett <hello@vantezzen.io> | 2020-06-21 09:19:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-21 12:49:59 +0530 |
commit | 0d6d623d1e34cdbff2d46229165b49289a9a0619 (patch) | |
tree | 83f6a22a08e354da58adf3ed0393f4d39bca6124 /src/webview/contextMenu.js | |
parent | Prepare and Release/5.6.0 beta.1 (#820) (diff) | |
download | ferdium-app-0d6d623d1e34cdbff2d46229165b49289a9a0619.tar.gz ferdium-app-0d6d623d1e34cdbff2d46229165b49289a9a0619.tar.zst ferdium-app-0d6d623d1e34cdbff2d46229165b49289a9a0619.zip |
Add FAB to service dashboard (#824)
* Implement #387
* Fix lint
* Upgrade to Electron 9
* Remove dependency on electron-spellchecker
* Allow multiple languages to be selected
* Fix lint
* Don't show spellchecker language chooser for macOS
* Fix _requireAuthenticatedUser throwing error on startup
* Add FAB
Diffstat (limited to 'src/webview/contextMenu.js')
-rw-r--r-- | src/webview/contextMenu.js | 48 |
1 files changed, 6 insertions, 42 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index eeb825ece..d04f90830 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -1,50 +1,14 @@ | |||
1 | import { remote } from 'electron'; | 1 | import { remote } from 'electron'; |
2 | import { ContextMenuBuilder, ContextMenuListener } from 'electron-spellchecker'; | 2 | import ContextMenuBuilder from './contextMenuBuilder'; |
3 | 3 | ||
4 | const webContents = remote.getCurrentWebContents(); | 4 | const webContents = remote.getCurrentWebContents(); |
5 | 5 | ||
6 | export default async function setupContextMenu(handler) { | 6 | export default async function setupContextMenu() { |
7 | const addCustomMenuItems = (menu, menuInfo) => { | ||
8 | // Add "Paste as plain text" item when right-clicking editable content | ||
9 | if ( | ||
10 | menuInfo.editFlags.canPaste | ||
11 | && !menuInfo.linkText | ||
12 | && !menuInfo.hasImageContents | ||
13 | ) { | ||
14 | menu.insert( | ||
15 | 3, | ||
16 | new remote.MenuItem({ | ||
17 | label: 'Paste as plain text', | ||
18 | accelerator: 'CommandOrControl+Shift+V', | ||
19 | click: () => webContents.pasteAndMatchStyle(), | ||
20 | }), | ||
21 | ); | ||
22 | } | ||
23 | |||
24 | // Add "Open Link in Ferdi" item for links | ||
25 | if (menuInfo.linkURL) { | ||
26 | menu.insert( | ||
27 | 2, | ||
28 | new remote.MenuItem({ | ||
29 | label: 'Open Link in Ferdi', | ||
30 | click: () => { | ||
31 | window.location.href = menuInfo.linkURL; | ||
32 | }, | ||
33 | }), | ||
34 | ); | ||
35 | } | ||
36 | |||
37 | return menu; | ||
38 | }; | ||
39 | |||
40 | const contextMenuBuilder = new ContextMenuBuilder( | 7 | const contextMenuBuilder = new ContextMenuBuilder( |
41 | handler, | 8 | webContents, |
42 | null, | ||
43 | true, | ||
44 | addCustomMenuItems, | ||
45 | ); | 9 | ); |
46 | // eslint-disable-next-line no-new | 10 | |
47 | new ContextMenuListener((info) => { | 11 | webContents.on('context-menu', (event, params) => { |
48 | contextMenuBuilder.showPopupMenu(info); | 12 | contextMenuBuilder.showPopupMenu(params); |
49 | }); | 13 | }); |
50 | } | 14 | } |