summaryrefslogtreecommitdiffstats
path: root/src/webview/spellchecker.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/webview/spellchecker.ts')
-rw-r--r--src/webview/spellchecker.ts26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/webview/spellchecker.ts b/src/webview/spellchecker.ts
index d0f6663d5..468a1b4ae 100644
--- a/src/webview/spellchecker.ts
+++ b/src/webview/spellchecker.ts
@@ -1,35 +1,25 @@
1import { getCurrentWebContents } from '@electron/remote'; 1import { ipcRenderer } from 'electron';
2import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 2import { SPELLCHECKER_LOCALES } from '../i18n/languages';
3import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; 3import { isMac } from '../environment';
4 4
5const debug = require('debug')('Ferdi:spellchecker'); 5const debug = require('debug')('Ferdi:spellchecker');
6 6
7const { session } = getCurrentWebContents();
8const [defaultLocale] = session.getSpellCheckerLanguages();
9debug('Spellchecker default locale is', defaultLocale);
10
11export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { 7export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) {
12 const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); 8 const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase());
13 9
14 return locales.length > 0 ? locales[0] : null; 10 return locales.length > 0 ? locales[0] : null;
15} 11}
16 12
17export function switchDict(locale: string) { 13export function switchDict(fuzzyLocale: string, serviceId: string) {
18 if (isMac) { 14 if (isMac) {
19 debug('Ignoring dictionary changes on macOS'); 15 debug('Ignoring dictionary changes on macOS');
20 return; 16 return;
21 } 17 }
22 18
23 debug('Setting spellchecker locale to', locale); 19 debug(`Setting spellchecker locale from: ${fuzzyLocale}`);
24 20 const locale = getSpellcheckerLocaleByFuzzyIdentifier(fuzzyLocale);
25 const locales: string[] = []; 21 if (locale) {
26 22 debug(`Sending spellcheck locales to host: ${locale}`);
27 const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); 23 ipcRenderer.send('set-spellchecker-locales', { locale, serviceId });
28 if (foundLocale) {
29 locales.push(foundLocale);
30 } 24 }
31
32 locales.push(defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale);
33
34 session.setSpellCheckerLanguages(locales);
35} 25}