ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.61k stars 336 forks source link

When using insertText to insert Chinese characters in the handleTextInput option, handleTextInput will be triggered twice. #1375

Open leijuns opened 1 year ago

leijuns commented 1 year ago

When I configure the handleTextInput option and use insertText to insert Chinese characters (English characters work fine), the characters are inserted twice. In fact, handleTextInput is being called twice. Testing has revealed that this issue occurs on Windows but works correctly on Mac. Could you please advise me on how to avoid this problem?

Here is a simple test case.

{
  handleTextInput(view, from, to, text) {
    const { state } = view
    const { tr } = state
    tr.insertText(text, from, to)
    view.dispatch(tr)
    return true
  }
}

You can click here to view the demo.

Matrixbirds commented 1 year ago

Can't figure out what do you want to do. Key reason is callback of function named handleTextInput will be invoked twice, here is one of function call in readDOMChange and another in keypress. You can dig the handleTextInput call stack, you will find the difference, input method behaviour handlers are different between Windows and MacOS. In Windows when the composition event emitted by keypress it will trigger keypress then caused readDOMChange callback, and some keypress will not trigger keypress events such as punctuation when using Chinese Pinyin IME.