diff options
author | 2019-06-25 13:00:16 +0200 | |
---|---|---|
committer | 2019-06-25 13:00:16 +0200 | |
commit | c1e592e6f530eadf730a77e4fa551f4eb0dbf337 (patch) | |
tree | 4bf073bd1306fd1e1a62be59fe8ecb661ae91590 /src/webview | |
parent | Update CHANGELOG.md (diff) | |
download | ferdium-app-c1e592e6f530eadf730a77e4fa551f4eb0dbf337.tar.gz ferdium-app-c1e592e6f530eadf730a77e4fa551f4eb0dbf337.tar.zst ferdium-app-c1e592e6f530eadf730a77e4fa551f4eb0dbf337.zip |
Revert: fix spellchecker
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/contextMenu.js | 5 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 17 |
2 files changed, 8 insertions, 14 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index 967e8e667..a4a6ab899 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -280,13 +280,12 @@ 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', async (e, props) => { | 283 | webContents.on('context-menu', (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 | debug('Mispelled word', props.misspelledWord); | 288 | suggestions = spellcheckProvider.getSuggestion(props.misspelledWord); |
289 | suggestions = await spellcheckProvider.getSuggestion(props.misspelledWord); | ||
290 | 289 | ||
291 | debug('Suggestions', suggestions); | 290 | debug('Suggestions', suggestions); |
292 | } | 291 | } |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 417d1ea1a..9158b3b94 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -1,8 +1,6 @@ | |||
1 | import { webFrame } from 'electron'; | 1 | import { webFrame } from 'electron'; |
2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; | 2 | import { 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'; | ||
6 | 4 | ||
7 | import { DICTIONARY_PATH } from '../config'; | 5 | import { DICTIONARY_PATH } from '../config'; |
8 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 6 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
@@ -12,12 +10,11 @@ const debug = require('debug')('Franz:spellchecker'); | |||
12 | let provider; | 10 | let provider; |
13 | let currentDict; | 11 | let currentDict; |
14 | let _isEnabled = false; | 12 | let _isEnabled = false; |
15 | let attached; | ||
16 | 13 | ||
17 | async function loadDictionary(locale) { | 14 | async function loadDictionary(locale) { |
18 | try { | 15 | try { |
19 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); | 16 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
20 | await provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`)); | 17 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); |
21 | debug('Loaded dictionary', locale, 'from', fileLocation); | 18 | debug('Loaded dictionary', locale, 'from', fileLocation); |
22 | } catch (err) { | 19 | } catch (err) { |
23 | console.error('Could not load dictionary', err); | 20 | console.error('Could not load dictionary', err); |
@@ -44,7 +41,7 @@ export async function switchDict(locale) { | |||
44 | provider.unloadDictionary(locale); | 41 | provider.unloadDictionary(locale); |
45 | } | 42 | } |
46 | loadDictionary(locale); | 43 | loadDictionary(locale); |
47 | attached.switchLanguage(locale); | 44 | provider.switchDictionary(locale); |
48 | 45 | ||
49 | debug('Switched dictionary to', locale); | 46 | debug('Switched dictionary to', locale); |
50 | 47 | ||
@@ -61,14 +58,12 @@ export default async function initialize(languageCode = 'en-us') { | |||
61 | const locale = languageCode.toLowerCase(); | 58 | const locale = languageCode.toLowerCase(); |
62 | 59 | ||
63 | debug('Init spellchecker'); | 60 | debug('Init spellchecker'); |
64 | await provider.initialize({ environment: ENVIRONMENT.NODE }); | 61 | await provider.initialize(); |
65 | 62 | // await loadDictionaries(); | |
66 | debug('Attaching spellcheck provider'); | ||
67 | attached = await attachSpellCheckProvider(provider); | ||
68 | 63 | ||
69 | debug('Available spellchecker dictionaries', provider.availableDictionaries); | 64 | debug('Available spellchecker dictionaries', provider.availableDictionaries); |
70 | 65 | ||
71 | attached.switchLanguage(locale); | 66 | switchDict(locale); |
72 | 67 | ||
73 | return provider; | 68 | return provider; |
74 | } catch (err) { | 69 | } catch (err) { |