Skip to content

fix(selection): skip wide-character continuation cells when copying#9

Merged
diegosouzapw merged 1 commit into
mainfrom
fix/port-pr-120a-cjk-selection-spaces
May 23, 2026
Merged

fix(selection): skip wide-character continuation cells when copying#9
diegosouzapw merged 1 commit into
mainfrom
fix/port-pr-120a-cjk-selection-spaces

Conversation

@diegosouzapw
Copy link
Copy Markdown
Owner

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 with codepoint=0 and width=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:

  1. ✅ This commit: skip wide-char continuation cells in selection text (~10 LOC).
  2. ⏭ Deferred: IME composition event routing onto the hidden textarea, removal of the parent container's contenteditable attribute, and a composition-preview overlay.

The deferred parts touch lib/input-handler.ts and lib/terminal.ts heavily and conflict with our existing PR coder#78 (contenteditable added 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 typecheck
  • bun test — 332 tests pass (1 new regression test covering Korean wide chars), 0 fail
  • bun run build:lib
  • Manual smoke test pending: type Korean text in a real terminal (or paste it), select it, copy it, paste elsewhere — confirm no stray spaces between glyphs
  • bun run build:wasm not run locally (Zig not installed); no WASM path touched

Risk

Low — surgical change inside SelectionManager.getSelection's empty-cell branch. No public API surface touched. Other PRs in flight do not touch selection-manager.ts.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

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
@diegosouzapw diegosouzapw force-pushed the fix/port-pr-120a-cjk-selection-spaces branch from 41de6d8 to 2f4e331 Compare May 23, 2026 16:57
@diegosouzapw diegosouzapw merged commit 332d257 into main May 23, 2026
1 check passed
@diegosouzapw diegosouzapw deleted the fix/port-pr-120a-cjk-selection-spaces branch May 23, 2026 16:58
@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant