Commit ad8f1467 authored by chris's avatar chris

use local files

parent d474e2d7
......@@ -15,6 +15,7 @@ class ContainerEditor extends SubstanceContainerEditor {
this.context.editorSession.onUpdate('document', this.checkChange, this)
this.change = {}
this.focus = this.focus.bind(this)
this.spellchecker = false
}
render($$) {
......@@ -24,20 +25,22 @@ class ContainerEditor extends SubstanceContainerEditor {
}
didUpdate() {
if (this.props.spellcheck) {
console.log('first', this.spellchecker)
if (this.props.spellcheck && !this.spellchecker) {
console.log('update', this.spellchecker)
const spellCheck = new SpellCheckManager(this.context.editorSession)
spellCheck.runGlobalCheck()
this.spellchecker = true
} else {
// this.spellchecker = false
}
}
didMount() {
super.didMount()
// load spellCheck
loadTypo(
'en_US',
'https://rawgit.com/kofifus/Typo.js/master/typo/dictionaries/en_US/en_US.aff',
'https://rawgit.com/kofifus/Typo.js/master/typo/dictionaries/en_US/en_US.dic',
).then(typo => {
loadTypo('en_US').then(typo => {
console.log(typo)
window.typo = typo
})
......
......@@ -26,11 +26,22 @@ class SpellCheckManager {
runGlobalCheck() {
let paths = Object.keys(this.textPropertyManager._textProperties)
// console.log(chunk(paths, '3')[0])
chunk(paths, '6')[0].forEach(p => {
this._runSpellCheck(p)
const editor = this.editorSession._context.editorSession.editor
editor.emit('displayNotification', () => {
return `Scanning the document for erros. Please Wait`
})
// console.log(chunk(paths, '3')[0])
setTimeout(() => {
chunk(paths, '20')[0].forEach((p, index) => {
this._runSpellCheck(p)
})
setTimeout(() => {
const count = paths.length
editor.emit('displayNotification', () => {
return `${count} text blocks checked`
})
}, 2000)
}, 2000)
}
_onDocumentChange(change, info) {
......@@ -50,40 +61,32 @@ class SpellCheckManager {
if (!window.typo) return
let startlength = 0
const data = []
const separators = [
' ',
'-',
'/',
':',
'\\.',
'\\,',
'\\;',
'\\+',
'-',
'\\—',
'\\[',
'\\]',
'\\”',
'\\“',
'\\‘',
'\\’',
'\\(',
'\\)',
'\\*',
'/',
':',
'\\?',
]
const textArray = text.split(new RegExp(separators.join('|'), 'g'))
forEach(textArray, (word, index) => {
if (index >= 1) startlength += textArray[index - 1].length + 1
//if not found in dictionairy get suggestions
if (!window.typo.check(word)) {
const obj = {
suggestions: window.typo.suggest(word, null),
path,
start: startlength,
word,
}
data.push(obj)
}
this._addSpellErrors(path, data)
})
const data = typo.checkMultiple(textArray, path)
this._addSpellErrors(path, data)
return
}
/*
......
......@@ -8,13 +8,16 @@
* Typo is a JavaScript implementation of a spellchecker using hunspell-style
* dictionaries.
*/
var affPath = require('./dictionairies/en_US.aff')
var dicPath = require('./dictionairies/en_US.dic')
import { forEach } from 'lodash'
;('use strict')
'use strict'
function loadTypo(dicName, affPath, dicPath) {
function loadTypo(dicName) {
return new Promise(function(resolve, reject) {
let xhr_aff = new XMLHttpRequest()
xhr_aff.open('GET', affPath, true)
console.log(xhr_aff)
xhr_aff.onload = function() {
if (xhr_aff.readyState === 4 && xhr_aff.status === 200) {
// console.log('aff loaded')
......@@ -698,6 +701,29 @@ Typo.prototype = {
return false
},
checkMultiple(textArray, path) {
if (!this.loaded) {
throw 'Dictionary not loaded.'
}
var data = []
var startlength = 0
forEach(textArray, (word, index) => {
if (index >= 1) startlength += textArray[index - 1].length + 1
//if not found in dictionairy get suggestions
if (!this.check(word)) {
const obj = {
suggestions: this.suggest(word, null),
path,
start: startlength,
word,
}
data.push(obj)
}
})
return data
},
/**
* Checks whether a word exists in the current dictionary.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment