From c1e592e6f530eadf730a77e4fa551f4eb0dbf337 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 25 Jun 2019 13:00:16 +0200 Subject: Revert: fix spellchecker --- src/webview/contextMenu.js | 5 ++--- src/webview/spellchecker.js | 17 ++++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) (limited to 'src') 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 }; export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { - webContents.on('context-menu', async (e, props) => { + webContents.on('context-menu', (e, props) => { e.preventDefault(); let suggestions = []; if (spellcheckProvider && props.misspelledWord) { - debug('Mispelled word', props.misspelledWord); - suggestions = await spellcheckProvider.getSuggestion(props.misspelledWord); + suggestions = spellcheckProvider.getSuggestion(props.misspelledWord); debug('Suggestions', suggestions); } 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 @@ import { webFrame } from 'electron'; -import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; -import { ENVIRONMENT } from 'hunspell-asm'; +import { SpellCheckerProvider } from 'electron-hunspell'; import path from 'path'; -import { readFileSync } from 'fs'; import { DICTIONARY_PATH } from '../config'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; @@ -12,12 +10,11 @@ const debug = require('debug')('Franz:spellchecker'); let provider; let currentDict; let _isEnabled = false; -let attached; async function loadDictionary(locale) { try { const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); - await provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`)); + await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); debug('Loaded dictionary', locale, 'from', fileLocation); } catch (err) { console.error('Could not load dictionary', err); @@ -44,7 +41,7 @@ export async function switchDict(locale) { provider.unloadDictionary(locale); } loadDictionary(locale); - attached.switchLanguage(locale); + provider.switchDictionary(locale); debug('Switched dictionary to', locale); @@ -61,14 +58,12 @@ export default async function initialize(languageCode = 'en-us') { const locale = languageCode.toLowerCase(); debug('Init spellchecker'); - await provider.initialize({ environment: ENVIRONMENT.NODE }); - - debug('Attaching spellcheck provider'); - attached = await attachSpellCheckProvider(provider); + await provider.initialize(); + // await loadDictionaries(); debug('Available spellchecker dictionaries', provider.availableDictionaries); - attached.switchLanguage(locale); + switchDict(locale); return provider; } catch (err) { -- cgit v1.2.3-70-g09d2