Skip to content
Open
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
15 changes: 12 additions & 3 deletions src/context-menu-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const contextMenuStringTable = {
addToDictionary: () => `Add to Dictionary`,
lookUpDefinition: ({word}) => `Look Up "${word}"`,
searchGoogle: () => `Search with Google`,
searchDdg: () => `Search with DuckDuckGo`,
cut: () => `Cut`,
copy: () => `Copy`,
paste: () => `Paste`,
Expand All @@ -37,11 +38,13 @@ module.exports = class ContextMenuBuilder {
* @param {Boolean} debugMode If true, display the "Inspect Element" menu item.
* @param {function} processMenu If passed, this method will be passed the menu to change
* it prior to display. Signature: (menu, info) => menu
* @param {String} searchEngine Optional. Pass either 'google' (default) or 'ddg' (for DuckDuckGo)
*/
constructor(spellCheckHandler, windowOrWebView=null, debugMode=false, processMenu=(m) => m) {
constructor(spellCheckHandler, windowOrWebView=null, debugMode=false, processMenu=null, searchEngine='google') {
this.spellCheckHandler = spellCheckHandler;
this.debugMode = debugMode;
this.processMenu = processMenu;
this.processMenu = processMenu || ((m) => m);
this.searchEngine = searchEngine;
this.menu = null;
this.stringTable = Object.assign({}, contextMenuStringTable);

Expand Down Expand Up @@ -296,7 +299,13 @@ module.exports = class ContextMenuBuilder {
menu.append(lookUpDefinition);
}

let search = new MenuItem({
let search = new MenuItem(this.searchEngine === 'ddg' ? {
label: this.stringTable.searchDdg(),
click: () => {
let url = `https://duckduckgo.com/?q=${encodeURIComponent(menuInfo.selectionText)}`;
shell.openExternal(url);
}
} : {
label: this.stringTable.searchGoogle(),
click: () => {
let url = `https://www.google.com/#q=${encodeURIComponent(menuInfo.selectionText)}`;
Expand Down