diff options
author | Stefan Malzner <stefan@adlk.io> | 2019-06-05 17:18:52 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2019-06-05 17:18:52 +0200 |
commit | 830b6f88f3d30708cf0264375b8db5b2e5714218 (patch) | |
tree | 1afb8dcf6cb85473f8d37cadb0c4667a61d10162 /src | |
parent | Update package-lock.json (diff) | |
download | ferdium-app-830b6f88f3d30708cf0264375b8db5b2e5714218.tar.gz ferdium-app-830b6f88f3d30708cf0264375b8db5b2e5714218.tar.zst ferdium-app-830b6f88f3d30708cf0264375b8db5b2e5714218.zip |
Fix spellchecker integration
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/contextMenu.js | 5 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 18 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index a4a6ab899..967e8e667 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -280,12 +280,13 @@ const buildMenuTpl = (props, suggestions, isSpellcheckEnabled, defaultSpellcheck | |||
280 | }; | 280 | }; |
281 | 281 | ||
282 | export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { | 282 | export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { |
283 | webContents.on('context-menu', (e, props) => { | 283 | webContents.on('context-menu', async (e, props) => { |
284 | e.preventDefault(); | 284 | e.preventDefault(); |
285 | 285 | ||
286 | let suggestions = []; | 286 | let suggestions = []; |
287 | if (spellcheckProvider && props.misspelledWord) { | 287 | if (spellcheckProvider && props.misspelledWord) { |
288 | suggestions = spellcheckProvider.getSuggestion(props.misspelledWord); | 288 | debug('Mispelled word', props.misspelledWord); |
289 | suggestions = await spellcheckProvider.getSuggestion(props.misspelledWord); | ||
289 | 290 | ||
290 | debug('Suggestions', suggestions); | 291 | debug('Suggestions', suggestions); |
291 | } | 292 | } |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 9158b3b94..64575753f 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -1,6 +1,8 @@ | |||
1 | import { webFrame } from 'electron'; | 1 | import { webFrame } from 'electron'; |
2 | import { SpellCheckerProvider } from 'electron-hunspell'; | 2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; |
3 | import { ENVIRONMENT } from 'hunspell-asm'; | ||
3 | import path from 'path'; | 4 | import path from 'path'; |
5 | import { readFileSync } from 'fs'; | ||
4 | 6 | ||
5 | import { DICTIONARY_PATH } from '../config'; | 7 | import { DICTIONARY_PATH } from '../config'; |
6 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 8 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
@@ -10,11 +12,12 @@ const debug = require('debug')('Franz:spellchecker'); | |||
10 | let provider; | 12 | let provider; |
11 | let currentDict; | 13 | let currentDict; |
12 | let _isEnabled = false; | 14 | let _isEnabled = false; |
15 | let attached; | ||
13 | 16 | ||
14 | async function loadDictionary(locale) { | 17 | async function loadDictionary(locale) { |
15 | try { | 18 | try { |
16 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); | 19 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
17 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); | 20 | await provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`)); |
18 | debug('Loaded dictionary', locale, 'from', fileLocation); | 21 | debug('Loaded dictionary', locale, 'from', fileLocation); |
19 | } catch (err) { | 22 | } catch (err) { |
20 | console.error('Could not load dictionary', err); | 23 | console.error('Could not load dictionary', err); |
@@ -41,7 +44,7 @@ export async function switchDict(locale) { | |||
41 | provider.unloadDictionary(locale); | 44 | provider.unloadDictionary(locale); |
42 | } | 45 | } |
43 | loadDictionary(locale); | 46 | loadDictionary(locale); |
44 | provider.switchDictionary(locale); | 47 | attached.switchLanguage(locale); |
45 | 48 | ||
46 | debug('Switched dictionary to', locale); | 49 | debug('Switched dictionary to', locale); |
47 | 50 | ||
@@ -58,12 +61,15 @@ export default async function initialize(languageCode = 'en-us') { | |||
58 | const locale = languageCode.toLowerCase(); | 61 | const locale = languageCode.toLowerCase(); |
59 | 62 | ||
60 | debug('Init spellchecker'); | 63 | debug('Init spellchecker'); |
61 | await provider.initialize(); | 64 | await provider.initialize({ environment: ENVIRONMENT.NODE }); |
62 | // await loadDictionaries(); | 65 | |
66 | debug('Attaching spellcheck provider'); | ||
67 | attached = await attachSpellCheckProvider(provider); | ||
63 | 68 | ||
64 | debug('Available spellchecker dictionaries', provider.availableDictionaries); | 69 | debug('Available spellchecker dictionaries', provider.availableDictionaries); |
65 | 70 | ||
66 | switchDict(locale); | 71 | attached.switchLanguage(locale); |
72 | console.log('seas oida', attached, provider); | ||
67 | 73 | ||
68 | return provider; | 74 | return provider; |
69 | } catch (err) { | 75 | } catch (err) { |