Skip to content

Fix Chinese IME cursor rendering in terminal preedit text#9919

Open
kill74 wants to merge 1 commit intowarpdotdev:masterfrom
kill74:fix-chinese-ime-marked-text-cursor
Open

Fix Chinese IME cursor rendering in terminal preedit text#9919
kill74 wants to merge 1 commit intowarpdotdev:masterfrom
kill74:fix-chinese-ime-marked-text-cursor

Conversation

@kill74
Copy link
Copy Markdown

@kill74 kill74 commented May 2, 2026

Description

Fixes Chinese IME/preedit cursor rendering in terminal input, including when using Claude Code inside Warp.

Previously, the terminal grid stored only the marked text string and ignored the IME selected_range. As a result, the cursor render point was calculated from the full marked-text cell length instead of the IME cursor position. For CJK text, this could cause the character under the cursor to appear visually split, clipped, or partially overwritten.

This change stores marked text together with its selected range, clamps byte-indexed IME ranges to UTF-8 character boundaries, and calculates the cursor render point from the marked-text prefix before the IME cursor. It also makes wide-character cursor detection aware of marked text so the cursor is rendered correctly over CJK/double-width characters.

Linked Issue

Fixes #9906

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).

Screenshots / Videos

Please attach the issue screenshots or a short before/after recording showing Chinese IME composition in Claude Code.

Testing

Automated tests added:

  • cursor_render_point_respects_marked_text_selected_range_with_cjk
  • marked_text_selected_range_is_clamped_to_char_boundary
  • is_cursor_on_wide_char_checks_marked_text

Automated checks run:

  • cargo fmt
  • cargo test cursor_render_point_respects_marked_text_selected_range_with_cjk
  • cargo test marked_text_selected_range_is_clamped_to_char_boundary
  • cargo test is_cursor_on_wide_char_checks_marked_text

Also ran:

  • cargo nextest run

cargo nextest run did not complete successfully due to unrelated GCP cloud-provider tests failing on Windows:

  • ai::agent_sdk::driver::cloud_provider::tests::collect_provider_env_vars_merges_all_providers
  • ai::agent_sdk::driver::cloud_provider::tests::extract_cloud_providers_creates_gcp_provider
  • ai::agent_sdk::driver::cloud_provider::tests::gcp_provider_env_vars

The failure appears unrelated to this IME/grid rendering change.

Manual test plan:

  1. Launch Warp from this branch on Windows.
  2. Start Claude Code.
  3. Enable Chinese IME.
  4. Type Chinese text during composition.
  5. Move the IME cursor so it is positioned over or inside Chinese preedit text.
  6. Confirm the character under the cursor is not split, clipped, or partially overwritten.
  7. Confirm English and numeric input still render normally.
  8. Confirm committed Chinese text still displays correctly.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-BUG-FIX: Fixed Chinese IME preedit cursor rendering in terminal input on Windows.

@cla-bot cla-bot Bot added the cla-signed label May 2, 2026
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 2, 2026

@kill74

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label May 2, 2026
oz-for-oss[bot]
oz-for-oss Bot previously requested changes May 2, 2026
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR stores terminal marked text with the IME selected range and uses that range to place the preedit cursor for CJK/double-width text.

Concerns

  • The selected-range normalization assumes UTF-8 byte offsets, but the shared terminal path also receives macOS NSRange UTF-16 offsets; this can move CJK IME cursors back to the start of marked text on macOS.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

pub fn set_marked_text(&mut self, marked_text: &str, selected_range: &Range<usize>) {
self.marked_text = Some(MarkedText {
text: marked_text.to_string(),
selected_range: clamp_byte_range_to_char_boundaries(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] This normalizes selected_range as UTF-8 byte offsets, but the macOS path passes NSRange UTF-16 offsets directly into terminal marked text. For "中文", a macOS caret after the first character arrives as 1..1, gets clamped to 0..0, and renders the cursor at the start; normalize platform ranges to a common unit before this clamp.

@kill74 kill74 force-pushed the fix-chinese-ime-marked-text-cursor branch from de5a65a to 13a2274 Compare May 2, 2026 16:58
@kill74 kill74 force-pushed the fix-chinese-ime-marked-text-cursor branch from 13a2274 to 4264f6f Compare May 2, 2026 17:02
@kill74
Copy link
Copy Markdown
Author

kill74 commented May 2, 2026

/oz-review

@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 2, 2026

@kill74

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @warpdotdev/oss-maintainers.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot dismissed their stale review May 2, 2026 17:08

Oz no longer requests changes for this pull request after the latest automated review.

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

Reviewed the terminal grid changes for IME marked-text cursor positioning, selected-range normalization, wide-character cursor detection, and the related tests. The implementation is scoped to rendering state for preedit text and I did not identify correctness or security concerns in the changed lines.

Concerns

  • None identified.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot requested review from a team and vorporeal and removed request for a team May 2, 2026 17:08
@vorporeal vorporeal requested review from abhishekp106 and removed request for vorporeal May 4, 2026 17:03
@vorporeal
Copy link
Copy Markdown
Contributor

reassigning to @abhishekp106, who has done the most IME work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Chinese IME/composition rendering issue in Warp input when using Claude Code

2 participants