diff --git a/public/contextMenu.js b/public/contextMenu.js new file mode 100644 index 0000000000..fd1c5a0e78 --- /dev/null +++ b/public/contextMenu.js @@ -0,0 +1,30 @@ +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); + } + }); +}; diff --git a/public/electron.js b/public/electron.js index 6e42064903..30659fa214 100644 --- a/public/electron.js +++ b/public/electron.js @@ -16,6 +16,7 @@ const logger = require('./logger'); const menu = require('./menu'); const configStore = require('./configStore'); const { frontendBuildDir } = require('./util'); +const attachContextMenu = require('./contextMenu'); const { checkNewVersion } = require('./update-checker'); @@ -108,6 +109,8 @@ function createWindow() { remote.enable(mainWindow.webContents); + attachContextMenu(mainWindow); + if (isDev) mainWindow.loadURL('http://localhost:3001'); // Need to useloadFile for special characters https://github.com/mifi/lossless-cut/issues/40