fix(ui): copy selection misaligns on wide (CJK) characters#548
Merged
benvinegar merged 1 commit intoJul 17, 2026
Merged
Conversation
Contributor
|
PR author is not in the allowed authors list. |
endotakuya
force-pushed
the
fix/copy-selection-cjk-cells
branch
from
July 15, 2026 15:53
44f07ba to
f62e08a
Compare
Member
|
Thanks for the thoughtful fix and thorough coverage! 🙏 This comment was generated by Pi using OpenAI GPT-5.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mouse-drag copy selection drifted whenever the selection crossed full-width characters (CJK, emoji). Mouse coordinates are terminal cell columns, but the copy path sliced rendered lines with
String.prototype.slice, which counts UTF-16 code units. ASCII stays aligned (1 cell = 1 code unit), but each full-width character is 1 code unit and 2 cells, so every one before a selection endpoint shifted the copied text by one position.cellRangeToCharRangeinsrc/ui/lib/text.tsto convert an inclusive terminal-cell range into code-unit slice bounds, walking grapheme clusters so wide characters and emoji are never splitrenderCopySelectionText(code-only and decorated paths, drag start and end) and inexpandSelectionPoint(double/triple-click word and line selection)renderFileHeaderCopyTextnow measures the gap and clamps by cells, matchingDiffFileHeaderRow's cell-based layout for wide-character filenamesRepro
Drag-select the prefix
export const message = 'こんにちはon this line:That prefix is 29 UTF-16 code units but 34 terminal cells (five full-width characters, +1 cell each), so slicing by code units overshoots by five cells:
export const message = 'こんにちは'; //export const message = 'こんにちは'Testing
bun run typecheckbun run lintbun run format:checkbun run test:theme-contrastbun testbun run test:integrationbun run test:tty-smoke