Skip to content

Commit 9d18f9d

Browse files
fix: re-enable the spellchecker when new language list set (electron#26119)
* fix: re-enable the spellchecker when new language list set Chromium recently added prefs logic to disable the spellchecker if the list of languages is empty, but the logic to re-enable if the languages are provided again lives in another part of Chromium. This change makes it so our API re-enables the spellchecker correctly when required. * chore: fix lint
1 parent 6181c03 commit 9d18f9d

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

shell/browser/api/electron_api_session.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,9 @@ void Session::SetSpellCheckerLanguages(
957957
}
958958
browser_context_->prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries,
959959
language_codes);
960+
// Enable spellcheck if > 0 languages, disable if no languages set
961+
browser_context_->prefs()->SetBoolean(spellcheck::prefs::kSpellCheckEnable,
962+
!languages.empty());
960963
}
961964

962965
void SetSpellCheckerDictionaryDownloadURL(gin_helper::ErrorThrower thrower,

spec-main/spec-helpers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@ import * as childProcess from 'child_process';
22
import * as path from 'path';
33
import * as http from 'http';
44
import * as v8 from 'v8';
5+
import { SuiteFunction, TestFunction } from 'mocha';
56

6-
export const ifit = (condition: boolean) => (condition ? it : it.skip);
7-
export const ifdescribe = (condition: boolean) => (condition ? describe : describe.skip);
7+
const addOnly = <T>(fn: Function): T => {
8+
const wrapped = (...args: any[]) => {
9+
return fn(...args);
10+
};
11+
(wrapped as any).only = wrapped;
12+
(wrapped as any).skip = wrapped;
13+
return wrapped as any;
14+
};
15+
16+
export const ifit = (condition: boolean) => (condition ? it : addOnly<TestFunction>(it.skip));
17+
export const ifdescribe = (condition: boolean) => (condition ? describe : addOnly<SuiteFunction>(describe.skip));
818

919
export const delay = (time: number = 0) => new Promise(resolve => setTimeout(resolve, time));
1020

spec-main/spellchecker-spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
1515
w = new BrowserWindow({
1616
show: false,
1717
webPreferences: {
18-
nodeIntegration: true
18+
nodeIntegration: true,
19+
partition: `unique-spell-${Date.now()}`
1920
}
2021
});
22+
w.webContents.session.setSpellCheckerLanguages(['en-US']);
2123
await w.loadFile(path.resolve(__dirname, './fixtures/chromium/spellchecker.html'));
2224
});
2325

@@ -65,6 +67,26 @@ ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
6567
expect(contextMenuParams.dictionarySuggestions).to.have.length.of.at.least(1);
6668
});
6769

70+
ifit(shouldRun)('should detect incorrectly spelled words as incorrect after disabling all languages and re-enabling', async () => {
71+
w.webContents.session.setSpellCheckerLanguages([]);
72+
await delay(500);
73+
w.webContents.session.setSpellCheckerLanguages(['en-US']);
74+
await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautifulllll asd asd"');
75+
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()');
76+
const contextMenuPromise = emittedOnce(w.webContents, 'context-menu');
77+
// Wait for spellchecker to load
78+
await delay(500);
79+
w.webContents.sendInputEvent({
80+
type: 'mouseDown',
81+
button: 'right',
82+
x: 43,
83+
y: 42
84+
});
85+
const contextMenuParams: Electron.ContextMenuParams = (await contextMenuPromise)[1];
86+
expect(contextMenuParams.misspelledWord).to.eq('Beautifulllll');
87+
expect(contextMenuParams.dictionarySuggestions).to.have.length.of.at.least(1);
88+
});
89+
6890
ifit(shouldRun)('should expose webFrame spellchecker correctly', async () => {
6991
await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautifulllll asd asd"');
7092
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()');

0 commit comments

Comments
 (0)