Paste During IME Composition Corrupts IME

It seems like prosemirror’s handling of the paste during an ime composition is messing with the composition. So for example:

  • Select some text from somewhere and copy it to the clipboard. (e.g. “typing”)
  • Open prosemirror.net (e.g. in Chrome on Windows)
  • Focus the prosemirror editor on that page, select all the content (ctrl+a) and delete (just to make it easier to see)
  • Change to the japanese ime and enable hiragana
  • Type aaa (which in hiragana would end up as あああ
  • Press ctrl + v to paste (you see あああtyping so looks ok)
  • Press enter

The result is the initial text of the composition is duplicated after the pasted text. e.g. あああtypingあああ<caret>. If I try the same thing in a vanilla contentEditable div I get あああ<caret>typing. For now I’ll probably handle this by adding a handler for paste to the handleDOMEvents and just return true if the view.composing is true but I figured I’d mention it here since it might be good to handle that in prosemirror.

BTW I did try calling blur and then focus on the view.dom to try and commit/end the current composition but the result was similarly weird. I see image as soon as I paste so it still duplicated the text but did so replacing the last n characters of the text being replaced and it looks like only the first 2 characters are still in composition.

Hmm … that only helps if the clipboard is plain text. If it’s got html in the clipboard (like some text with an anchor) then the same thing happens but again in a vanilla contentEditable it’s fine. So guess I have to try to find what other processing the view might be doing that’s interfering unless someone has an idea.

Ok the latter part seems to be caused by the manipulation of the dom by the updateStateInner on the EditorView. Not familiar enough with this code to recommend a solution though and it’s not seemingly something i can affect using prosemirror.

Will just preventDefault for paste when composing is true. If the browser(s) ever fix this I can just remove that check but its an uncommon thing to do anyway I suppose.

On Chrome, it seems impossible to intentionally end composition without getting this kinds of character duplication or other types of text corruption. This patch should make things a little less obvious (though it bypasses the editor’s own paste handling in this case, which will break some kinds of paste behavior when you are composing).

Thanks. I appreciate you taking the time to look at it.