Skip to content

Commit

Permalink
Revert: fix spellchecker
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Jun 25, 2019
1 parent 4ec0c1d commit c1e592e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 49 deletions.
50 changes: 16 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"du": "^0.1.0",
"electron-dl": "1.12.0",
"electron-fetch": "1.3.0",
"electron-hunspell": "1.0.0-beta.7",
"electron-hunspell": "0.1.1",
"electron-is-dev": "1.0.1",
"electron-react-titlebar": "0.8.1",
"electron-updater": "4.0.6",
Expand Down
5 changes: 2 additions & 3 deletions src/webview/contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 6 additions & 11 deletions src/webview/spellchecker.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit c1e592e

Please sign in to comment.