From e99e19e86b721f4b99d3a97bb4c7491226da1367 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Mejri Date: Mon, 13 Oct 2025 19:55:44 +0100 Subject: [PATCH] feat: add spell check suggestions to context menu (#1509) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR implements spelling correction feature requested in issue #271 --- ## 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 ""” 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. --- src/main.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 8a0f1ca..999029a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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" });