feat: add spell check suggestions to context menu (#1509)

This PR implements spelling correction feature requested in issue #271 
    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Add spell check suggestions to the context menu in editable fields.
Right-clicking a misspelled word shows up to five suggestions for
one-click replacement.

- **New Features**
- Shows a “Correct "<misspelled>"” submenu when a misspelled word is
detected.
- Provides up to 5 dictionary suggestions; clicking replaces the word
via replaceMisspelling.
- Keeps standard edit actions and tidies menu order with separators;
logs errors on failure.

<!-- End of auto-generated description by cubic. -->
This commit is contained in:
Mohamed Aziz Mejri
2025-10-13 19:55:44 +01:00
committed by GitHub
parent fe80146260
commit e99e19e86b

View File

@@ -170,7 +170,6 @@ const createWindow = () => {
event.preventDefault();
const template: Electron.MenuItemConstructorOptions[] = [];
if (params.isEditable) {
template.push(
{ role: "undo" },
@@ -180,9 +179,29 @@ const createWindow = () => {
{ role: "copy" },
{ role: "paste" },
{ role: "delete" },
{ type: "separator" },
{ role: "selectAll" },
);
if (params.misspelledWord) {
const suggestions: Electron.MenuItemConstructorOptions[] =
params.dictionarySuggestions.slice(0, 5).map((suggestion) => ({
label: suggestion,
click: () => {
try {
mainWindow?.webContents.replaceMisspelling(suggestion);
} catch (error) {
logger.error("Failed to replace misspelling:", error);
}
},
}));
template.push(
{ type: "separator" },
{
type: "submenu",
label: `Correct "${params.misspelledWord}"`,
submenu: suggestions,
},
);
}
template.push({ type: "separator" }, { role: "selectAll" });
} else {
if (params.selectionText && params.selectionText.length > 0) {
template.push({ role: "copy" });