authorgravatar for 142016413+chuks-qua@users.noreply.github.com(CJ) Chukwudi Nwobodo <142016413+chuks-qua@users.noreply.github.com> 2026-03-09 01:36:52+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-03-08 18:36:52-07:00
log18b6590d2e490bd73ba968b094dc221ffb7c0f67
treedb707b05ad47d0240d7db3fa83c76939b6995582
parentd62ffa7560bffeb2509ed115eed31dd5bc231ca6
signature Signed by PGP key B5690EEEBB952194

feat(desktop): add spellcheck suggestions to context menu (#500)

Wire up Electron's context-menu event on webContents to surface dictionary suggestions for misspelled words. Standard edit actions (Cut, Copy, Paste, Select All) appear in all context menus. Related to #473

1 files changed, 28 insertions(+), 0 deletions(-)

apps/desktop/src/main.ts+28
...@@ -1114,6 +1114,34 @@ function createWindow(): BrowserWindow {...@@ -1114,6 +1114,34 @@ function createWindow(): BrowserWindow {
1114 },1114 },
1115 });1115 });
11161116
1117 window.webContents.on("context-menu", (event, params) => {
1118 event.preventDefault();
1119
1120 const menuTemplate: MenuItemConstructorOptions[] = [];
1121
1122 if (params.misspelledWord) {
1123 for (const suggestion of params.dictionarySuggestions.slice(0, 5)) {
1124 menuTemplate.push({
1125 label: suggestion,
1126 click: () => window.webContents.replaceMisspelling(suggestion),
1127 });
1128 }
1129 if (params.dictionarySuggestions.length === 0) {
1130 menuTemplate.push({ label: "No suggestions", enabled: false });
1131 }
1132 menuTemplate.push({ type: "separator" });
1133 }
1134
1135 menuTemplate.push(
1136 { role: "cut", enabled: params.editFlags.canCut },
1137 { role: "copy", enabled: params.editFlags.canCopy },
1138 { role: "paste", enabled: params.editFlags.canPaste },
1139 { role: "selectAll", enabled: params.editFlags.canSelectAll },
1140 );
1141
1142 Menu.buildFromTemplate(menuTemplate).popup({ window });
1143 });
1144
1117 window.webContents.setWindowOpenHandler(() => ({ action: "deny" }));1145 window.webContents.setWindowOpenHandler(() => ({ action: "deny" }));
1118 window.on("page-title-updated", (event) => {1146 window.on("page-title-updated", (event) => {
1119 event.preventDefault();1147 event.preventDefault();