diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index 4447afd500..bfeb1686de 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -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'; }