Skip to content

Commit

Permalink
add context menu to inputs
Browse files Browse the repository at this point in the history
closes #1217
  • Loading branch information
mifi committed Jul 26, 2023
1 parent 351b867 commit 999e855
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions public/contextMenu.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
};
3 changes: 3 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 999e855

Please sign in to comment.