Skip to content

Commit aab2a68

Browse files
committed
refac
1 parent 9e204e7 commit aab2a68

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

src/main/index.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,61 @@ if (!gotTheLock) {
12721272
// Malformed URL — let it through so Chromium can handle/reject it
12731273
}
12741274
})
1275+
1276+
// ── Native right-click context menu (#161) ──────────────────
1277+
// Electron <webview> guests don't show a context menu by default,
1278+
// which blocks right-click → Paste / Autofill / password-manager
1279+
// integration on login pages. Build a native menu with standard
1280+
// editing actions, spell-check suggestions, and link handling.
1281+
contents.on('context-menu', (_event, params) => {
1282+
const menuItems: Electron.MenuItemConstructorOptions[] = []
1283+
1284+
// Spell-check suggestions (if any)
1285+
if (params.misspelledWord && params.dictionarySuggestions?.length) {
1286+
for (const suggestion of params.dictionarySuggestions) {
1287+
menuItems.push({
1288+
label: suggestion,
1289+
click: () => contents.replaceMisspelling(suggestion)
1290+
})
1291+
}
1292+
menuItems.push({ type: 'separator' })
1293+
}
1294+
1295+
// Link handling
1296+
if (params.linkURL) {
1297+
menuItems.push({
1298+
label: 'Open Link in Browser',
1299+
click: () => openUrl(params.linkURL)
1300+
})
1301+
menuItems.push({
1302+
label: 'Copy Link',
1303+
click: () => clipboard.writeText(params.linkURL)
1304+
})
1305+
menuItems.push({ type: 'separator' })
1306+
}
1307+
1308+
// Editable field actions (input, textarea, contenteditable)
1309+
if (params.isEditable) {
1310+
menuItems.push(
1311+
{ label: 'Undo', role: 'undo', enabled: params.editFlags.canUndo },
1312+
{ label: 'Redo', role: 'redo', enabled: params.editFlags.canRedo },
1313+
{ type: 'separator' },
1314+
{ label: 'Cut', role: 'cut', enabled: params.editFlags.canCut },
1315+
{ label: 'Copy', role: 'copy', enabled: params.editFlags.canCopy },
1316+
{ label: 'Paste', role: 'paste', enabled: params.editFlags.canPaste },
1317+
{ label: 'Select All', role: 'selectAll', enabled: params.editFlags.canSelectAll }
1318+
)
1319+
} else if (params.selectionText) {
1320+
// Non-editable text selection
1321+
menuItems.push(
1322+
{ label: 'Copy', role: 'copy', enabled: params.editFlags.canCopy }
1323+
)
1324+
}
1325+
1326+
if (menuItems.length > 0) {
1327+
Menu.buildFromTemplate(menuItems).popup()
1328+
}
1329+
})
12751330
}
12761331
})
12771332

0 commit comments

Comments
 (0)