Skip to content

Commit

Permalink
Merge pull request RocketChat#365 from RocketChat/bug/spellcheck
Browse files Browse the repository at this point in the history
Fix speed issues with spell check on Windows
  • Loading branch information
rodrigok authored Feb 22, 2017
2 parents 1aa7029 + de54b56 commit 22aa692
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/public/lib/SpellCheck.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const os = require('os');
const checker = require('spellchecker');
const { remote, webFrame } = require('electron');

const webContents = remote.getCurrentWebContents();
let menu = new remote.Menu();

const path = remote.require('path');
const isWindows = ['win32', 'win64'].indexOf(os.platform());

class SpellCheck {

Expand Down Expand Up @@ -41,7 +43,7 @@ class SpellCheck {
click: (menuItem) => {
menu.checked = menuItem.checked;
// If not using os dictionary then limit to only 1 language
if (!this.usingOsDictionary) {
if (!this.muliLanguage) {
this.languagesMenu.submenu.forEach((m) => {
if (m.label !== menuItem.label) {
m.checked = false;
Expand Down Expand Up @@ -109,7 +111,7 @@ class SpellCheck {
loadAvailableDictionaries () {
this.availableDictionaries = checker.getAvailableDictionaries().sort();
if (this.availableDictionaries.length === 0) {
this.usingOsDictionary = false;
this.muliLanguage = false;
// Dictionaries path is correct for build
this.dictionariesPath = path.join(remote.app.getAppPath(), '../dictionaries');
this.availableDictionaries = [
Expand All @@ -119,7 +121,7 @@ class SpellCheck {
'pt_BR'
];
} else {
this.usingOsDictionary = true;
this.muliLanguage = !isWindows;
this.availableDictionaries = this.availableDictionaries.map((dict) => dict.replace('-', '_'));
}
}
Expand All @@ -131,8 +133,8 @@ class SpellCheck {
if (this.availableDictionaries.indexOf(dictionaries[i]) !== -1) {
result = true;
this.enabledDictionaries.push(dictionaries[i]);
// If using Hunspell then only allow 1 language for performance reasons
if (!this.usingOsDictionary) {
// If using Hunspell or Windows then only allow 1 language for performance reasons
if (!this.muliLanguage) {
this.enabledDictionaries = [dictionaries[i]];
checker.setDictionary(dictionaries[i], this.dictionariesPath);
return true;
Expand Down Expand Up @@ -223,7 +225,7 @@ class SpellCheck {
return true;
}

if (this.usingOsDictionary) {
if (this.muliLanguage) {
for (let i = 0; i < this.enabledDictionaries.length; i++) {
checker.setDictionary(this.enabledDictionaries[i]);
if (!checker.isMisspelled(text)) {
Expand All @@ -237,7 +239,7 @@ class SpellCheck {
}

getCorrections (text) {
if (!this.usingOsDictionary) {
if (!this.muliLanguage) {
return checker.getCorrectionsForMisspelling(text);
}

Expand Down

0 comments on commit 22aa692

Please sign in to comment.