每次击键时Slatejs拼写检查都会闪烁

时间:2019-08-12 11:06:58

标签: javascript reactjs rich-text-editor slatejs

启用拼写检查后,当富文本中有错字时,Slatejs当前会在每次击键时闪烁。

我正在尝试实施一种几乎可行的解决方案,但仍然存在问题。键入whiteSpaceAndPunctuation中未包含的第一个字符后,例如,如果按Backspace键,则需要重复两次以使其起作用。

请参见demoRichText文件第23行onKeyDown

这就是我的实现方式:

const whiteSpaceAndPunctuation = [".", ",", ";", ":", "'", '"', " ", "Enter"]
const [spellCheckEnabled, setSpellCheckEnabled] = useState(true);

const onKeyDown = (event, editor, next) => {
    const containsWhiteSpaceAndPunctuation = whiteSpaceAndPunctuation.includes(
      event.key
    );
    if (!containsWhiteSpaceAndPunctuation) {
      next();
    }
    setSpellCheckEnabled(containsWhiteSpaceAndPunctuation);
}

0 个答案:

没有答案
相关问题