From 19e102ee1c6d90adfec55a82870ebf901168937e Mon Sep 17 00:00:00 2001 From: Velikiy Prikalel Date: Sat, 20 Aug 2022 16:08:38 +0300 Subject: [PATCH] Reduce processes interactions. Add front cache. --- src/codemirror/spellcheck-mode.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/codemirror/spellcheck-mode.ts b/src/codemirror/spellcheck-mode.ts index 87984799b..57c429c6e 100644 --- a/src/codemirror/spellcheck-mode.ts +++ b/src/codemirror/spellcheck-mode.ts @@ -24,13 +24,23 @@ type IgnoreListChangeHandler = (newIgnoreList: string[]) => void; export class CodeMirrorSpellCheck { private static ignoreWords: Set = new Set(); + private static goodWords: Set = new Set(); /** 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'; }