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.on('context-menu', (_event, params) => {
const menu = new Menu();
const hasSpellingSuggestions = params.dictionarySuggestions.length > 0 || params.misspelledWord;
// Add each spelling suggestion
for (const suggestion of params.dictionarySuggestions) {
if (hasSpellingSuggestions) {
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(
new MenuItem({
label: suggestion,
click: () => mainWindow.webContents.replaceMisspelling(suggestion),
label: 'Cut',
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
if (params.misspelledWord) {
// Only show paste in editable fields (text inputs)
if (params.isEditable) {
menu.append(
new MenuItem({
label: 'Add to dictionary',
click: () =>
mainWindow.webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord),
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
role: 'paste',
})
);
}
menu.popup();
if (menu.items.length > 0) {
menu.popup();
}
});
// Handle new window creation for links
@@ -681,7 +715,10 @@ const createChat = async (
}
if (
appPath === '/' &&
(recipe !== undefined || recipeDeeplink !== undefined || recipeId !== undefined || initialMessage)
(recipe !== undefined ||
recipeDeeplink !== undefined ||
recipeId !== undefined ||
initialMessage)
) {
appPath = '/pair';
}