Skip to content
This repository was archived by the owner on Jan 8, 2022. It is now read-only.

Commit 3acf2ef

Browse files
committed
add menu items to search selection
1 parent 94b1274 commit 3acf2ef

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

app/renderer/main.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const { configDir } = require('../utils')
88
const config = require('../config')
99
const Searcher = require('./searcher')
1010

11+
const isMac = process.platform === 'darwin'
12+
1113
const win = remote.getCurrentWindow()
1214
let webview // eslint-disable-line prefer-const
1315

@@ -100,7 +102,39 @@ function createWebView() {
100102
// Add context menus
101103
contextMenu({
102104
window: webview,
103-
showInspectElement: true
105+
showInspectElement: true,
106+
append(props, win) {
107+
const hasText = props.selectionText.trim().length > 0
108+
return [
109+
{
110+
id: 'showDefinition',
111+
label: 'Show definition',
112+
enabled: hasText && isMac,
113+
visible: hasText && isMac,
114+
click() {
115+
win.showDefinitionForSelection()
116+
}
117+
},
118+
{
119+
id: 'searchGoogle',
120+
label: 'Search in Google',
121+
enabled: hasText,
122+
visible: hasText,
123+
click() {
124+
shell.openExternal(`https://www.google.com/search?q=${props.selectionText}`)
125+
}
126+
},
127+
{
128+
id: 'searchDuck',
129+
label: 'Search in DuckDuckGo',
130+
enabled: hasText,
131+
visible: hasText,
132+
click() {
133+
shell.openExternal(`https://duckduckgo.com/?q=${props.selectionText}`)
134+
}
135+
}
136+
]
137+
}
104138
})
105139
})
106140

0 commit comments

Comments
 (0)