Phenomenon
When composing Chinese text with Pinyin IME in a contenteditable element, pressing Enter cancels the composition and may commit only partial Pinyin or incomplete character conversion. In some browser and IME combinations, the caret moves to the next line but the last composed character or conversion may be lost.
Reproduction example
- Focus the editable area.
- Activate Chinese Pinyin IME.
- Type Pinyin text (e.g., “nihao”) and start character conversion.
- Press Enter to insert a new line before completing the conversion.
Observed behavior
- The compositionend event fires with incomplete data.
- The caret moves to the next line.
- Partial Pinyin or incomplete character conversion may be lost.
- The conversion candidate list may disappear without committing the selection.
Expected behavior
- The IME finalizes the current composition before inserting a line break.
- The last composed character or conversion remains in the DOM text content.
- If a candidate list is active, it should be handled appropriately.
Browser Comparison
- Safari: May cancel composition when Enter is pressed, especially on macOS
- Chrome: May have different behavior
- Firefox: May have different behavior
Notes and possible direction for workarounds
- Observe the sequence of
beforeinput,compositionend, andinputevents. - Check whether the browser emits a
beforeinputevent withinputType = 'insertParagraph'before or aftercompositionend. - A possible workaround is to intercept Enter on
keydownand prevent the default behavior while waiting for composition to complete.