1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 02:12:30 +01:00
lossless-cut/public/contextMenu.js

31 lines
791 B
JavaScript
Raw Normal View History

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);
}
});
};