Fix check overlay not refreshed

Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com>
This commit is contained in:
Yukai Huang 2020-02-05 18:18:29 +08:00
parent 19dad9dfc8
commit 34a69c401c
No known key found for this signature in database
GPG Key ID: D4D3B2F0E99D4914
2 changed files with 13 additions and 6 deletions

View File

@ -754,7 +754,7 @@ export default class Editor {
placeholder: "← Start by entering a title here\n===\nVisit /features if you don't know what to do.\nHappy hacking :)"
})
this.spellchecker = new CodeMirrorSpellChecker(CodeMirror, this.getExistingSpellcheckLang())
this.spellchecker = new CodeMirrorSpellChecker(CodeMirror, this.getExistingSpellcheckLang(), this.editor)
this.tableEditor = initTableEditor(this.editor)
return this.editor

View File

@ -145,7 +145,7 @@ class CodeMirrorSpellChecker {
* @param {CodeMirror} cm
* @param {string} lang
*/
constructor (cm, lang) {
constructor (cm, lang, editor) {
// Verify
if (typeof cm !== 'function' || typeof cm.defineMode !== 'function') {
console.log(
@ -156,17 +156,24 @@ class CodeMirrorSpellChecker {
this.typo = undefined
this.defineSpellCheckerMode(cm, lang)
this.editor = editor
}
setDictLang (lang) {
findOrCreateTypoInstance(lang).then(typo => { this.typo = typo })
findOrCreateTypoInstance(lang).then(typo => {
this.typo = typo
// re-enable overlay mode to refresh spellcheck
this.editor.setOption('mode', 'gfm')
this.editor.setOption('mode', 'spell-checker')
})
}
defineSpellCheckerMode (cm, lang) {
cm.defineMode('spell-checker', config => {
// Load AFF/DIC data async
// Load AFF/DIC data async ASAP
this.setDictLang(lang)
cm.defineMode('spell-checker', config => {
// Define what separates a word
const regexWord = '!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~ '