From 233125f586c2658be28dc6cf8e06ff2d7d2a4223 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Wed, 31 Jan 2018 13:11:59 -0600 Subject: [PATCH 1/2] fix(input): give feature full menu for inputs --- app/menu.js | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/app/menu.js b/app/menu.js index b71fac01b4b..8a8a493a31d 100644 --- a/app/menu.js +++ b/app/menu.js @@ -21,28 +21,48 @@ export default class MenuBuilder { template = this.buildDefaultTemplate() } + this.setupInputTemplate() + const menu = Menu.buildFromTemplate(template) Menu.setApplicationMenu(menu) + return menu } - setupDevelopmentEnvironment() { - this.mainWindow.openDevTools() + setupInputTemplate() { + const selectionMenu = Menu.buildFromTemplate([ + { role: 'copy' }, + { type: 'separator' }, + { role: 'selectall' }, + ]) + + const inputMenu = Menu.buildFromTemplate([ + { role: 'undo' }, + { role: 'redo' }, + { type: 'separator' }, + { role: 'cut' }, + { role: 'copy' }, + { role: 'paste' }, + { type: 'separator' }, + { role: 'selectall' }, + ]) + this.mainWindow.webContents.on('context-menu', (e, props) => { - const { x, y } = props - - Menu - .buildFromTemplate([{ - label: 'Inspect element', - click: () => { - this.mainWindow.inspectElement(x, y) - } - }]) - .popup(this.mainWindow) + const { selectionText, isEditable } = props; + + if (isEditable) { + inputMenu.popup(this.mainWindow); + } else if (selectionText && selectionText.trim() !== '') { + selectionMenu.popup(this.mainWindow); + } }) } + setupDevelopmentEnvironment() { + this.mainWindow.openDevTools() + } + buildDarwinTemplate() { const subMenuAbout = { label: 'Electron', From b3aaeb400b31f2a6fa97a132fa7c56fa7016c486 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Wed, 31 Jan 2018 13:30:03 -0600 Subject: [PATCH 2/2] fix(lint): fix linter errors --- app/menu.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/menu.js b/app/menu.js index 8a8a493a31d..2420f000cc6 100644 --- a/app/menu.js +++ b/app/menu.js @@ -34,7 +34,7 @@ export default class MenuBuilder { const selectionMenu = Menu.buildFromTemplate([ { role: 'copy' }, { type: 'separator' }, - { role: 'selectall' }, + { role: 'selectall' } ]) const inputMenu = Menu.buildFromTemplate([ @@ -45,16 +45,16 @@ export default class MenuBuilder { { role: 'copy' }, { role: 'paste' }, { type: 'separator' }, - { role: 'selectall' }, + { role: 'selectall' } ]) this.mainWindow.webContents.on('context-menu', (e, props) => { - const { selectionText, isEditable } = props; + const { selectionText, isEditable } = props if (isEditable) { - inputMenu.popup(this.mainWindow); + inputMenu.popup(this.mainWindow) } else if (selectionText && selectionText.trim() !== '') { - selectionMenu.popup(this.mainWindow); + selectionMenu.popup(this.mainWindow) } }) }