fix(selection): skip wide-character continuation cells when copying#9
Merged
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where extra spaces were inserted between wide characters (like CJK) during text selection. It updates the SelectionManager to skip continuation cells (width 0) when building the selection string and adds a corresponding test case to verify the fix. I have no further feedback to provide.
5 tasks
When the selection range covered text containing wide characters (CJK, fullwidth Latin, etc.), copying the selection inserted a stray space between every wide glyph — e.g. "안녕하" came out as "안 녕 하 ". Root cause: wide characters occupy two terminal cells. The first cell has the codepoint and width=2; the second cell is a continuation marker with codepoint=0 and width=0. SelectionManager.getSelection's empty-cell branch treated both empty cells AND continuation cells the same way and appended a space. Fix: skip continuation cells (cell exists with width===0) in the empty-cell branch. Only truly empty cells (no cell, or cell.width!==0 with codepoint===0) get a space. Ports only the selection-manager subset of upstream PR coder#120 — the rest of that PR (IME composition routing, textarea-focus refactor, removal of contenteditable) needs more analysis around regressions with browser extensions and is deferred to a separate port. Adds one regression test asserting that selecting "안녕하" copies as "안녕하", not "안 녕 하". Co-authored-by: Seungwoo Hong <ai.baryon.ai@gmail.com> Inspired-by: coder#120
41de6d8 to
2f4e331
Compare
|
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
Copying a selection that contained wide characters (CJK, fullwidth Latin, etc.) inserted a stray space between every wide glyph:
"안녕하"came out as"안 녕 하 ".Root cause: wide characters occupy two terminal cells. The first cell has the codepoint with
width=2; the second is a continuation marker withcodepoint=0andwidth=0. The selection-text builder's empty-cell branch appended a space for BOTH empty cells AND continuation cells.Fix: skip continuation cells (cell exists with
width===0). Only truly empty cells get a space.Scope difference vs upstream PR coder#120
Upstream #120 bundles three concerns:
contenteditableattribute, and a composition-preview overlay.The deferred parts touch
lib/input-handler.tsandlib/terminal.tsheavily and conflict with our existing PR coder#78 (contenteditableadded to fix browser-extension key interception). They need verification in real browsers against Vimium-style extensions before merging. Full plan in_tasks/upstream-ports/120-korean-cjk-ime.plan.md.Only the selection bugfix subset is ported here — it's purely visual/clipboard, no IME plumbing involved.
Attribution
Thanks to @hongsw for the original implementation.
Test plan
bun run fmt && bun run lint && bun run typecheckbun test— 332 tests pass (1 new regression test covering Korean wide chars), 0 failbun run build:libbun run build:wasmnot run locally (Zig not installed); no WASM path touchedRisk
Low — surgical change inside
SelectionManager.getSelection's empty-cell branch. No public API surface touched. Other PRs in flight do not touchselection-manager.ts.