Skip to content

Fix IME input when composing in the middle of the textarea#5698

Merged
Tyriar merged 3 commits intoxtermjs:masterfrom
ntomoya:fix/ime-middle-composition-suffix
Mar 11, 2026
Merged

Fix IME input when composing in the middle of the textarea#5698
Tyriar merged 3 commits intoxtermjs:masterfrom
ntomoya:fix/ime-middle-composition-suffix

Conversation

@ntomoya
Copy link
Copy Markdown
Contributor

@ntomoya ntomoya commented Feb 12, 2026

Fixes #5456

When screenReaderMode is enabled, moving the caret inside existing text and then committing IME input can cause stale trailing text from the textarea's previous state to be re-sent.

This PR fixes composition range tracking in two places:

  • At compositionstart, it uses textarea.selectionStart/selectionEnd (the actual caret/selection) instead of textarea.value.length.
  • At finalize time, it keeps support for characters typed immediately after compositionend while avoiding re-sending trailing text that already existed before composition started.

This keeps composition diffing aligned with the real insertion point and prevents stale suffix insertion.

Repro

  1. Enable screenReaderMode.
  2. Type 一二 via IME.
  3. Move the caret between and .
  4. Commit via IME.
  • Before: text could become 一二二 (the previous trailing
    is re-sent).
  • After: text becomes 一一二.

Validation

  • Reproduced with screenReaderMode: true before the fix; no repro after the fix.
  • Confirmed no behavior change in normal mode (screenReaderMode: false).
  • Manually verified caret movement + IME insertion in the VS Code integrated terminal scenario.

Related VS Code issues:

Track the composition range using the textarea selection and avoid re-sending trailing text that existed before composition started (notably in screenReaderMode).

Fixes xtermjs#5456
@ntomoya ntomoya mentioned this pull request Feb 12, 2026
@Tyriar
Copy link
Copy Markdown
Member

Tyriar commented Mar 11, 2026

Repro before:

Recording 2026-03-11 at 13 05 22

After:

Recording 2026-03-11 at 13 08 16

Comment thread src/browser/input/CompositionHelper.ts
@Tyriar Tyriar added this to the 7.0.0 milestone Mar 11, 2026
@Tyriar Tyriar enabled auto-merge March 11, 2026 04:12
@Tyriar Tyriar merged commit 26ce9bd into xtermjs:master Mar 11, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

Japanese IME issues

2 participants