Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(electron): add a spellcheck toggle to editable context menus

jonathanwxh-cell8a2e7b8f37a2
diff --git a/electron/context-menu.mjs b/electron/context-menu.mjs
index 49159b3b7d..068b15c329 100644
--- a/electron/context-menu.mjs
+++ b/electron/context-menu.mjs
@@ -170,7 +170,7 @@ function mediaItems(params, { webContents, downloads, t }) {
}
/** The window's right-click menu, built from Electron's context-menu params: never empty, so right-click always answers. */
-export function contextMenuTemplate(params, { webContents, clipboard, downloads, t = nativeText.englishText.t }) {
+export function contextMenuTemplate(params, { webContents, clipboard, downloads, platform = process.platform, t = nativeText.englishText.t }) {
const sections = [];
if (params.misspelledWord) {
sections.push((params.dictionarySuggestions ?? []).slice(0, 5).map((suggestion) => ({
@@ -197,5 +197,15 @@ export function contextMenuTemplate(params, { webContents, clipboard, downloads,
{ label: t("native.role.reload"), click: () => webContents.reload() },
]);
}
+ if (params.isEditable && (platform === "win32" || platform === "linux")) {
+ const { session } = webContents;
+ const checked = session.isSpellCheckerEnabled();
+ sections.push([{
+ label: t("native.context.checkSpelling"),
+ type: "checkbox",
+ checked,
+ click: () => session.setSpellCheckerEnabled(!checked),
+ }]);
+ }
return sections.filter((section) => section.length > 0).flatMap((section, index) => index === 0 ? section : [{ type: "separator" }, ...section]);
}
diff --git a/electron/context-menu.node-test.mjs b/electron/context-menu.node-test.mjs
index b860a0f889..fba5a244bc 100644
--- a/electron/context-menu.node-test.mjs
+++ b/electron/context-menu.node-test.mjs
@@ -12,9 +12,14 @@ const VIDEO = `${CLOUD}/api/threads/t1/messages/m1/file?media=${"a".repeat(43)}`
const editFlags = { canUndo: false, canRedo: false, canCut: false, canCopy: false, canPaste: false, canSelectAll: true };
const base = { mediaType: "none", srcURL: "", hasImageContents: false, linkURL: "", isEditable: false, misspelledWord: "", dictionarySuggestions: [], selectionText: "", x: 12, y: 34, editFlags, pageURL: `${CLOUD}/` };
-function harness() {
+function harness(platform = "darwin") {
const calls = [];
+ let spellcheckEnabled = true;
const webContents = {
+ session: {
+ isSpellCheckerEnabled: () => spellcheckEnabled,
+ setSpellCheckerEnabled: (enabled) => { spellcheckEnabled = enabled; },
+ },
copyImageAt: (x, y) => calls.push(["copyImageAt", x, y]),
downloadURL: (url) => calls.push(["downloadURL", url]),
reload: () => calls.push(["reload"]),
@@ -23,7 +28,7 @@ function harness() {
};
const clipboard = { writeText: (text) => calls.push(["writeText", text]), availableFormats: () => [], readImage: () => ({ isEmpty: () => true }) };
const downloads = { start: (contents, url, mode) => { assert.equal(contents, webContents); calls.push(["download", url, mode]); return true; } };
- const menu = (params) => contextMenuTemplate({ ...base, ...params }, { webContents, clipboard, downloads });
+ const menu = (params) => contextMenuTemplate({ ...base, ...params }, { webContents, clipboard, downloads, platform });
return { calls, menu };
}
@@ -107,6 +112,21 @@ test("a plain spot answers with Copy, Select All and Reload", () => {
assert.deepEqual(calls, [["reload"]]);
});
+for (const platform of ["win32", "linux"]) {
+ test(`the ${platform} editable menu can turn session spellchecking off and back on`, () => {
+ const { menu } = harness(platform);
+ const spellcheck = () => menu({ isEditable: true }).find((item) => item.label === "Check Spelling");
+
+ assert.equal(spellcheck().type, "checkbox");
+ assert.equal(spellcheck().checked, true);
+ spellcheck().click();
+ assert.equal(spellcheck().checked, false);
+ spellcheck().click();
+ assert.equal(spellcheck().checked, true);
+ assert.equal(menu({ selectionText: "words" }).some((item) => item.label === "Check Spelling"), false);
+ });
+}
+
function scratch() {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "omb-context-menu-"));
return { dir, done: () => fs.rmSync(dir, { recursive: true, force: true }) };
diff --git a/src/locales/en.json b/src/locales/en.json
index b40b7035e4..604c8af0c0 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -9729,6 +9729,7 @@
"native.role.zoom": "Zoom",
"native.role.front": "Bring All to Front",
"native.context.copyLink": "Copy Link",
+ "native.context.checkSpelling": "Check Spelling",
"native.context.copyImage": "Copy Image",
"native.context.saveImageAs": "Save Image As…",
"native.context.saveVideoAs": "Save Video As…",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 7df6ca3063..dbd8cd04e7 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -9645,6 +9645,7 @@
"native.role.zoom": "Zoom",
"native.role.front": "Trazer todas as janelas para a frente",
"native.context.copyLink": "Copiar link",
+ "native.context.checkSpelling": "Verificar ortografia",
"native.context.copyImage": "Copiar imagem",
"native.context.saveImageAs": "Salvar imagem como…",
"native.context.saveVideoAs": "Salvar vídeo como…",
diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.json
index 8c17d3cfe8..6baf99b682 100644
--- a/src/locales/source-hashes.json
+++ b/src/locales/source-hashes.json
@@ -37079,6 +37079,7 @@
"botAccess.teamFiles.on": "56d18fbd01530bc0bf2edfdc3bf67add81509fa083345f4986e03302779b4b66",
"botAccess.teamFiles.off": "2c4905650646cdf562db5af5260a74341ceb874468fa2044b95432189c5f5a0e",
"botAccess.teamFiles.adminsOnly": "78b69d593f4ce419176eb42e2e2fd320f500885d106005e0edf75f168a77ddbb",
+ "native.context.checkSpelling": "2f1912628aecd56dfd95fcb249b3daeece3c6954a2e71721e5fbe09f9e653aaf",
"native.context.copyImage": "bf21aa9bebe41ba69dab0d5a172aea1b9124d8fb824eabe7d7c46df5c1237e14",
"native.context.saveImageAs": "bbbda8c84f5fd419ee4ec680301910a75bfd4e6d46c9ea0495f3c818ac4b9a59",
"native.context.saveVideoAs": "a697fb64a2f1f67e7a33825a7f574653a957827be60531aa58dc1e3ae0ee2f8c",