import * as CodeMirror from "codemirror";
CodeMirror.defineExtension("spellcheck_highlight", function (
words: string[] | undefined
) {
const cm: any = this;
if (cm._spellcheck_highlight_overlay != null) {
cm.removeOverlay(cm._spellcheck_highlight_overlay);
delete cm._spellcheck_highlight_overlay;
}
if (words != null && words.length > 0) {
const v: Set<string> = new Set(words);
const token = function (stream) {
if (stream.match(/^\w+/) && v.has(stream.current())) {
return "spell-error";
}
while (stream.next() != null) {
if (stream.match(/^\w+/, false)) {
return;
}
}
};
cm._spellcheck_highlight_overlay = { token };
cm.addOverlay(cm._spellcheck_highlight_overlay);
}
});