diff options
Diffstat (limited to 'src/webview/spellchecker.ts')
-rw-r--r-- | src/webview/spellchecker.ts | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/webview/spellchecker.ts b/src/webview/spellchecker.ts index 30b4ef075..468a1b4ae 100644 --- a/src/webview/spellchecker.ts +++ b/src/webview/spellchecker.ts | |||
@@ -1,35 +1,25 @@ | |||
1 | import { getCurrentWebContents } from '@electron/remote'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 2 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
3 | import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; | 3 | import { isMac } from '../environment'; |
4 | 4 | ||
5 | const debug = require('debug')('Ferdi:spellchecker'); | 5 | const debug = require('debug')('Ferdi:spellchecker'); |
6 | 6 | ||
7 | const { session } = getCurrentWebContents(); | ||
8 | const [defaultLocale] = session.getSpellCheckerLanguages(); | ||
9 | debug('Spellchecker default locale is', defaultLocale); | ||
10 | |||
11 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { | 7 | export 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 >= 1 ? locales[0] : null; | 10 | return locales.length > 0 ? locales[0] : null; |
15 | } | 11 | } |
16 | 12 | ||
17 | export function switchDict(locale: string) { | 13 | export 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 | } |