Skip to content

fix: convert display-width offsets to char indices when expanding paste extmarks#29712

Open
xodmd45-ctrl wants to merge 1 commit into
anomalyco:devfrom
xodmd45-ctrl:fix/cjk-paste-extmark
Open

fix: convert display-width offsets to char indices when expanding paste extmarks#29712
xodmd45-ctrl wants to merge 1 commit into
anomalyco:devfrom
xodmd45-ctrl:fix/cjk-paste-extmark

Conversation

@xodmd45-ctrl

Copy link
Copy Markdown

Issue for this PR

Closes #29711

Type of change

  • Bug fix

What does this PR do?

When submitting a prompt with pasted content after typing CJK characters, extmark start/end positions are display-width offsets (visual columns), not JS string indices. For CJK characters (visual width 2, string length 1), using these offsets directly with slice() cuts at wrong positions, causing [Pasted text] to appear literally in the submitted message.

Added visualOffsetToCharIndex() that walks the string accumulating visual width until reaching the target offset, then returns the corresponding character index. Used it to convert extmark positions before slicing.

How did you verify your code works?

Tested by typing Korean characters in the prompt, pasting text after them, and submitting — the pasted content now correctly appears inline instead of [Pasted text].

Screenshots / recordings

N/A (TUI change, no visible UI difference when working correctly)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.

fix: pasted text not expanded correctly after CJK input

2 participants