diff options
author | 2019-09-27 13:56:49 +0200 | |
---|---|---|
committer | 2019-09-27 13:56:49 +0200 | |
commit | 9180318200dc2b398bc2ec248f9ff8fa3f035fbb (patch) | |
tree | 2e080ccc65efa5acab5fb4c2a1e3ef269709623b /src/webview | |
parent | Fix spellchecker integration (diff) | |
download | ferdium-app-9180318200dc2b398bc2ec248f9ff8fa3f035fbb.tar.gz ferdium-app-9180318200dc2b398bc2ec248f9ff8fa3f035fbb.tar.zst ferdium-app-9180318200dc2b398bc2ec248f9ff8fa3f035fbb.zip |
Fix spellchecker
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/spellchecker.js | 32 |
1 files changed, 16 insertions, 16 deletions
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 @@ | |||
1 | import { webFrame } from 'electron'; | 1 | import { webFrame } from 'electron'; |
2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; | 2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; |
3 | import { ENVIRONMENT } from 'hunspell-asm'; | ||
4 | import path from 'path'; | 3 | import path from 'path'; |
5 | import { readFileSync } from 'fs'; | 4 | import { readFileSync } from 'fs'; |
6 | 5 | ||
@@ -14,6 +13,8 @@ let currentDict; | |||
14 | let _isEnabled = false; | 13 | let _isEnabled = false; |
15 | let attached; | 14 | let attached; |
16 | 15 | ||
16 | const DEFAULT_LOCALE = 'en-us'; | ||
17 | |||
17 | async function loadDictionary(locale) { | 18 | async function loadDictionary(locale) { |
18 | try { | 19 | try { |
19 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); | 20 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
@@ -24,7 +25,7 @@ async function loadDictionary(locale) { | |||
24 | } | 25 | } |
25 | } | 26 | } |
26 | 27 | ||
27 | export async function switchDict(locale) { | 28 | export async function switchDict(locale = DEFAULT_LOCALE) { |
28 | try { | 29 | try { |
29 | debug('Trying to load dictionary', locale); | 30 | debug('Trying to load dictionary', locale); |
30 | 31 | ||
@@ -55,13 +56,23 @@ export async function switchDict(locale) { | |||
55 | } | 56 | } |
56 | } | 57 | } |
57 | 58 | ||
58 | export default async function initialize(languageCode = 'en-us') { | 59 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { |
60 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); | ||
61 | |||
62 | if (locales.length >= 1) { | ||
63 | return locales[0]; | ||
64 | } | ||
65 | |||
66 | return null; | ||
67 | } | ||
68 | |||
69 | export default async function initialize(languageCode = DEFAULT_LOCALE) { | ||
59 | try { | 70 | try { |
60 | provider = new SpellCheckerProvider(); | 71 | provider = new SpellCheckerProvider(); |
61 | const locale = languageCode.toLowerCase(); | 72 | const locale = getSpellcheckerLocaleByFuzzyIdentifier(languageCode); |
62 | 73 | ||
63 | debug('Init spellchecker'); | 74 | debug('Init spellchecker'); |
64 | await provider.initialize({ environment: ENVIRONMENT.NODE }); | 75 | await provider.initialize(); |
65 | 76 | ||
66 | debug('Attaching spellcheck provider'); | 77 | debug('Attaching spellcheck provider'); |
67 | attached = await attachSpellCheckProvider(provider); | 78 | attached = await attachSpellCheckProvider(provider); |
@@ -69,7 +80,6 @@ export default async function initialize(languageCode = 'en-us') { | |||
69 | debug('Available spellchecker dictionaries', provider.availableDictionaries); | 80 | debug('Available spellchecker dictionaries', provider.availableDictionaries); |
70 | 81 | ||
71 | attached.switchLanguage(locale); | 82 | attached.switchLanguage(locale); |
72 | console.log('seas oida', attached, provider); | ||
73 | 83 | ||
74 | return provider; | 84 | return provider; |
75 | } catch (err) { | 85 | } catch (err) { |
@@ -89,13 +99,3 @@ export function disable() { | |||
89 | currentDict = null; | 99 | currentDict = null; |
90 | } | 100 | } |
91 | } | 101 | } |
92 | |||
93 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { | ||
94 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); | ||
95 | |||
96 | if (locales.length >= 1) { | ||
97 | return locales[0]; | ||
98 | } | ||
99 | |||
100 | return null; | ||
101 | } | ||