[PR #5109] Fix broken Chinese IME when deleting composition #26113

Open
opened 2026-01-31 09:13:59 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/5109

State: closed
Merged: Yes


Summary of the Pull Request

This PR fixes an out of bounds access when deleting composition during Chinese IME. What's happening is that we're receiving a CompositionCompleted before receiving the TextUpdate to tell us to delete the last character in the composition. This creates two problems for us:

  1. The final character gets sent to the Terminal when it should have been deleted.
  2. _activeTextStart gets set to _inputBuffer.length() when sending the character to the terminal, so when the TextUpdate comes right after the CompositionCompleted event, _activeTextStart is out of sync.

This PR fixes the second issue, by updating _activeTextStart during a TextUpdate in case we run into this issue.
The first issue is trickier to resolve since we assume that if the text server api tells us a composition is completed, we should send what we have. It'll be tracked here: #5110.
At the very least, this PR will let users continue to type in Chinese IME without it breaking, but it will still be annoying to see the first letter of your composition reappear after deleting it.

PR Checklist

Validation Steps Performed

Play around with Chinese IME deleting and composing, and play around with Korean and Japanese IME to see that it still works as expected.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/5109 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request This PR fixes an out of bounds access when deleting composition during Chinese IME. What's happening is that we're receiving a CompositionCompleted before receiving the TextUpdate to tell us to delete the last character in the composition. This creates two problems for us: 1. The final character gets sent to the Terminal when it should have been deleted. 2. `_activeTextStart` gets set to `_inputBuffer.length()` when sending the character to the terminal, so when the `TextUpdate` comes right after the `CompositionCompleted` event, `_activeTextStart` is out of sync. This PR fixes the second issue, by updating `_activeTextStart` during a `TextUpdate` in case we run into this issue. The first issue is trickier to resolve since we assume that if the text server api tells us a composition is completed, we should send what we have. It'll be tracked here: #5110. At the very least, this PR will let users continue to type in Chinese IME without it breaking, but it will still be annoying to see the first letter of your composition reappear after deleting it. ## PR Checklist * [x] Closes #5054 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed ## Validation Steps Performed Play around with Chinese IME deleting and composing, and play around with Korean and Japanese IME to see that it still works as expected.
claunia added the pull-request label 2026-01-31 09:13:59 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26113