Skip to content

Commit

Permalink
Reduce processes interactions. Add front cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Velikiy Prikalel committed Aug 20, 2022
1 parent d11e3da commit 19e102e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/codemirror/spellcheck-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ type IgnoreListChangeHandler = (newIgnoreList: string[]) => void;

export class CodeMirrorSpellCheck {
private static ignoreWords: Set<string> = new Set<string>();
private static goodWords: Set<string> = new Set<string>();

/** Return tag if word is bad or null if word is ok.
*/
private static checkWord(word: string, language: string) {
if (CodeMirrorSpellCheck.ignoreWords.has(word) ||
CodeMirrorSpellCheck.goodWords.has(word)) {
return null;
}
const {twineElectron} = window as TwineElectronWindow;
return CodeMirrorSpellCheck.ignoreWords.has(word) ||
twineElectron?.ipcRenderer.sendSync('spellcheck-word', word, language)
var result: boolean =
twineElectron?.ipcRenderer.sendSync('spellcheck-word', word, language);
if (result) {
// Save in front-end cache to reduce processes interactions.
CodeMirrorSpellCheck.goodWords.add(word);
}
return result
? null
: 'spell-error';
}
Expand Down

0 comments on commit 19e102e

Please sign in to comment.