From 9180318200dc2b398bc2ec248f9ff8fa3f035fbb Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 27 Sep 2019 13:56:49 +0200 Subject: Fix spellchecker --- src/webview/spellchecker.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/webview/spellchecker.js') diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 64575753f..d7bb983dc 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js @@ -1,6 +1,5 @@ import { webFrame } from 'electron'; import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; -import { ENVIRONMENT } from 'hunspell-asm'; import path from 'path'; import { readFileSync } from 'fs'; @@ -14,6 +13,8 @@ let currentDict; let _isEnabled = false; let attached; +const DEFAULT_LOCALE = 'en-us'; + async function loadDictionary(locale) { try { const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); @@ -24,7 +25,7 @@ async function loadDictionary(locale) { } } -export async function switchDict(locale) { +export async function switchDict(locale = DEFAULT_LOCALE) { try { debug('Trying to load dictionary', locale); @@ -55,13 +56,23 @@ export async function switchDict(locale) { } } -export default async function initialize(languageCode = 'en-us') { +export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { + const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); + + if (locales.length >= 1) { + return locales[0]; + } + + return null; +} + +export default async function initialize(languageCode = DEFAULT_LOCALE) { try { provider = new SpellCheckerProvider(); - const locale = languageCode.toLowerCase(); + const locale = getSpellcheckerLocaleByFuzzyIdentifier(languageCode); debug('Init spellchecker'); - await provider.initialize({ environment: ENVIRONMENT.NODE }); + await provider.initialize(); debug('Attaching spellcheck provider'); attached = await attachSpellCheckProvider(provider); @@ -69,7 +80,6 @@ export default async function initialize(languageCode = 'en-us') { debug('Available spellchecker dictionaries', provider.availableDictionaries); attached.switchLanguage(locale); - console.log('seas oida', attached, provider); return provider; } catch (err) { @@ -89,13 +99,3 @@ export function disable() { currentDict = null; } } - -export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { - const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); - - if (locales.length >= 1) { - return locales[0]; - } - - return null; -} -- cgit v1.2.3-54-g00ecf