const { Menu } = require('electron'); // https://github.com/electron/electron/issues/4068#issuecomment-274159726 module.exports = (window) => { 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' }, ]); window.webContents.on('context-menu', (e, props) => { const { selectionText, isEditable } = props; if (isEditable) { inputMenu.popup(window); } else if (selectionText && selectionText.trim() !== '') { selectionMenu.popup(window); } }); };