Skip to content

armgit / plexo

Public Imported from GitHub
0

Speed up downloads by combining multiple network connections in parallel

Give text fields a right-click Cut/Copy/Paste menu (#103)

Anmol Kapilf1401290b6ea
diff --git a/src/main/index.ts b/src/main/index.ts
index cb693e2..e709f6e 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -115,6 +115,23 @@ function createWindow(): void {
return { action: 'deny' }
})
+ // Electron shows no right-click menu of its own: give every text field Cut/Copy/Paste, and any
+ // selected text Copy.
+ mainWindow.webContents.on('context-menu', (_, { isEditable, selectionText, editFlags }) => {
+ const template: Electron.MenuItemConstructorOptions[] = isEditable
+ ? [
+ { role: 'cut', enabled: editFlags.canCut },
+ { role: 'copy', enabled: editFlags.canCopy },
+ { role: 'paste', enabled: editFlags.canPaste },
+ { type: 'separator' },
+ { role: 'selectAll', enabled: editFlags.canSelectAll }
+ ]
+ : selectionText.trim()
+ ? [{ role: 'copy' }]
+ : []
+ if (template.length) Menu.buildFromTemplate(template).popup()
+ })
+
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
} else {