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

Open
opened 2023-05-15 08:38:39 +02:00 by leijuns · 1 comment
leijuns commented 2023-05-15 08:38:39 +02:00 (Migrated from github.com)

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.

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. ```js { 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](https://codesandbox.io/s/prosemirror-example-forked-c50ije?file=/src/index.js) to view the demo.
Matrixbirds commented 2023-05-29 12:15:25 +02:00 (Migrated from github.com)

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.

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](https://github.com/ProseMirror/prosemirror-view/blob/6bfe0c43af771a86f3a473b0f53270ce6b958fc8/src/domchange.ts#L88) and another in [keypress](https://github.com/ProseMirror/prosemirror-view/blob/6bfe0c43af771a86f3a473b0f53270ce6b958fc8/src/input.ts#L151). 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 in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror#1375
No description provided.