fix: add standard context menu items to prevent empty right-click menu (#5616)

Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com>
This commit is contained in:
Sheikh Limon
2025-11-07 03:37:56 +06:00
committed by GitHub
parent 6e15735676
commit e0f0898781
+48 -11
View File
@@ -614,29 +614,63 @@ const createChat = async (
mainWindow.webContents.session.setSpellCheckerLanguages(['en-US', 'en-GB']); mainWindow.webContents.session.setSpellCheckerLanguages(['en-US', 'en-GB']);
mainWindow.webContents.on('context-menu', (_event, params) => { mainWindow.webContents.on('context-menu', (_event, params) => {
const menu = new Menu(); const menu = new Menu();
const hasSpellingSuggestions = params.dictionarySuggestions.length > 0 || params.misspelledWord;
// Add each spelling suggestion if (hasSpellingSuggestions) {
for (const suggestion of params.dictionarySuggestions) { for (const suggestion of params.dictionarySuggestions) {
menu.append(
new MenuItem({
label: suggestion,
click: () => mainWindow.webContents.replaceMisspelling(suggestion),
})
);
}
if (params.misspelledWord) {
menu.append(
new MenuItem({
label: 'Add to dictionary',
click: () =>
mainWindow.webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord),
})
);
}
if (params.selectionText) {
menu.append(new MenuItem({ type: 'separator' }));
}
}
if (params.selectionText) {
menu.append( menu.append(
new MenuItem({ new MenuItem({
label: suggestion, label: 'Cut',
click: () => mainWindow.webContents.replaceMisspelling(suggestion), accelerator: 'CmdOrCtrl+X',
role: 'cut',
})
);
menu.append(
new MenuItem({
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
role: 'copy',
}) })
); );
} }
// Allow users to add the misspelled word to the dictionary // Only show paste in editable fields (text inputs)
if (params.misspelledWord) { if (params.isEditable) {
menu.append( menu.append(
new MenuItem({ new MenuItem({
label: 'Add to dictionary', label: 'Paste',
click: () => accelerator: 'CmdOrCtrl+V',
mainWindow.webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord), role: 'paste',
}) })
); );
} }
menu.popup(); if (menu.items.length > 0) {
menu.popup();
}
}); });
// Handle new window creation for links // Handle new window creation for links
@@ -681,7 +715,10 @@ const createChat = async (
} }
if ( if (
appPath === '/' && appPath === '/' &&
(recipe !== undefined || recipeDeeplink !== undefined || recipeId !== undefined || initialMessage) (recipe !== undefined ||
recipeDeeplink !== undefined ||
recipeId !== undefined ||
initialMessage)
) { ) {
appPath = '/pair'; appPath = '/pair';
} }