fix(tui): correct pasted preview replacement for CJK and multi-width characters#17034
fix(tui): correct pasted preview replacement for CJK and multi-width characters#17034AbigailJixiangyuyu wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
there's still a problem when using your commit codes, when input chinese, you can forcus the cursor to a gap between two words, is easy when using mouse, not left or right buttun。then "[" will be included in submitted input |
Thanks for testing this. I’m not sure I fully understand the exact reproduction steps yet. Could you provide a more detailed step-by-step reproduction example? A short screen recording or before/after example would also help a lot. |
看你的昵称应该是中国人,我就用中文来描述现象吧,这边因为信息安全原因没法发图片,我用文字描述一下步骤吧 |
This issue is reproducible in opencode, but the root cause appears to be lower-level in |
|
i was wondering when will your commits merge into dev??? it fixed the bug mostly |
Issue for this PR
Closes #17032
Type of change
What does this PR do?
Fix a TUI bug where
[Pasted ~N lines]preview tokens are not correctly replaced when the prompt contains CJK characters before the paste.The previous implementation used terminal visual column offsets but performed the replacement using JavaScript string slicing. This works for ASCII input but becomes misaligned for multi-width characters such as Chinese, Japanese and Korean.
This PR converts the visual column offsets to the correct string indices before performing the replacement, ensuring the preview token is fully replaced by the actual pasted content.
This issue is particularly important for users typing CJK characters, since the incorrect truncation could leak part of the paste preview token into the submitted prompt, resulting in a polluted prompt.
How did you verify your code works?
Tested locally with
bun dev ..Reproduction steps:
[Pasted ~N lines]appears.Before the fix, part of the preview token could appear in the submitted prompt.
After the fix, the preview is correctly replaced with the pasted content.
Tested with:
Screenshots / recordings
TUI after the fix:
[Pasted ~N lines]fragments when the input includes CJK characters.Checklist