Getting Electron Copy/Paste shortcuts working on MAC builds
24 Jan 2017If you are new to Electron and have noticed that when running the Mac/OSX builds there is no copy/paste shortcut support, don’t be alarmed.
The reason for this is that MAC/OSX requires you to have those shortcuts declared/setup in the application menu, or one of it’s sub menus.
You can do a simple fix by loading the Electron Menu module in your application’s code and setting these shortcuts
Sample Code:
const {app,Menu} = require('electron');
// Callback for the ready event
app.on('ready', () => {
/*
This is where your other code would go
*/
// Check if we are on a MAC
if (process.platform === 'darwin') {
// Create our menu entries so that we can use MAC shortcuts
Menu.setApplicationMenu(Menu.buildFromTemplate([
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' }
]
}
]));
}
});
Once you have added this code to your application code, you should see a new menu that looks like the following image