Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leijuns opened this issue May 15, 2023 · 1 comment

Comments

@leijuns
Copy link

leijuns commented May 15, 2023

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants