Skip to content

[CTX-1367] fix(ui): include zerowidth scalars in copied text - #2266

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1367/fix-copy-zerowidth
Oct 19, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1367/fix-copy-zerowidth

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Priority: P1 | Area: area:ui | Labels: fix,P1,area:ui | Milestone: 0.0.24 | RFC: CR-TERM-01 | Task: CTX-1367

What & why

Copy, accessibility runs, inspection text, session scrollback capture, view text, and URL detection pushed only Cell::glyph. Cell::zerowidth holds combining marks, ZWJ, and variation selectors, so a decomposed é (e + U+0301) copied as e and a family emoji copied as four separate people.

This adds Cell::push_text_into (glyph followed by every retained zero-width scalar in arrival order) and routes all seven text-extraction surfaces through it. Cell storage, MAX_ZEROWIDTH_CHARS (5), spacer semantics, and the paint/shaping path are unchanged.

Closes #2260

Scope

  • crates/bitty-term-state/src/cell.rs — new push_text_into helper + unit test; no storage change.
  • crates/bitty-ui/src/selection.rs — selection range, block, and persistent-selection text (copy path).
  • crates/bitty-ui/src/a11y.rs — accessibility text runs.
  • crates/bitty-ui/src/view.rs — visible_text_rows projection.
  • crates/bitty-runtime/src/inspect.rs — grid text; the post-trim scalar truncation is removed so a mark cannot be cut off the last cell, and the bound stays a cell bound.
  • crates/bitty-runtime/src/runtime/session.rs — scrollback tail text.
  • crates/bitty-runtime/src/runtime/plaintext_url.rs — row reconstruction; the byte map keeps one entry per glyph plus one per mark, so span anchoring is unchanged.
  • Tests: decomposed e+U+0301, four-cell ZWJ family (Selection::text and block_text), variation selector, regional-indicator pair, a11y baseline, inspect grid text, view visible text, URL decomposed-prefix anchoring.

Rendering is untouched: no crates/bitty-render/** changes.

Mutation evidence

Mutation probe on an independent copy of this head with push_text_into reduced to out.push(self.glyph) (log: recording/ctx-1367-copy-zerowidth/review/mutation.log):

  • bitty-term-state --lib push_text_into_emits_glyph_then_marks_in_order — FAILED
  • bitty-ui --lib selection_text_keeps_decomposed_combining_mark — FAILED
  • bitty-ui --lib selection_text_keeps_zwj_family_cluster_across_spacers — FAILED
  • bitty-ui --lib selection_text_keeps_variation_selector — FAILED
  • bitty-ui --lib visible_text_rows_keeps_zero_width_scalars — FAILED
  • bitty-ui --test a11y_baseline terminal_runs_keep_zero_width_scalars — FAILED
  • bitty-runtime --lib grid_text_keeps_zero_width_scalars — FAILED
  • bitty-runtime --lib decomposed_prefix_shifts_bytes_past_columns — FAILED

The regional-indicator test passes under the mutation by design: regional indicators are leading glyphs, not zero-width scalars.

Multi-line exactness

Rows printed through TerminalAction::Print/ControlChar, then read back via drag copy, line drag, persistent selection, a11y runs, and inspect grid text (all five identical bytes):

abc
你好
e + U+0301 (decomposed, not normalized)
U+1F468 ZWJ U+1F469 ZWJ U+1F467 ZWJ U+1F466

Copied text:

abc\n你好\ne\u{301}\n👨‍👩‍👧‍👦

Asserted: exact bytes (decomposed é preserved, no Unicode normalization), !text.starts_with(' '), text.matches("abc").count() == 1 (first line not duplicated), text.lines().count() == 4, block copy of the emoji row 0..7 == 👨‍👩‍👧‍👦.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings (plus -p bitty-terminal --features dev-tools)
  • cargo nextest run -p bitty-ui -p bitty-runtime -p bitty-term-state -p bitty-terminal --locked
  • Windows cargo check --workspace --all-targets --locked (x86_64-pc-windows-gnu, RUSTFLAGS=-D warnings)

Checklist

  • Public CLI contracts unchanged (command names, JSON schemas, exit codes)
  • No database migrations
  • No secrets or local paths committed

Non-blocking residuals (follow-ups, not merge blockers)

  1. Inspect doc wording. INSPECT_MAX_COLS and GridTextSnapshot doc comments still describe a char-based bound; rows now hold up to max_cols cells (up to max_cols * (1 + MAX_ZEROWIDTH_CHARS) scalars). Documentation drift only — consumers bound by the cell window and the IPC service re-bounds by bytes.
  2. Session-scrollback mark coverage. scrollback_tail_text uses the helper but no test feeds a combining mark through capture/restore, so a regression there would not fail the suite (every other converted surface is mutation-sensitive). Needs a capture-side test next to restore_scrollback_text_handles_wide_and_control_scalars.
  3. Dangling trailing ZWJ on a partial cluster. Copying e.g. columns 0..1 of the family emits a trailing ZWJ. This is inherent to cell-granular extraction and matches the pre-existing boundary behavior; not introduced here. Cluster-aware trimming would be a separate design change.

Independent review: APPROVE at cfd695a2 (reviewer 1367-reviewer); verdict at recording/ctx-1367-copy-zerowidth/review/verdict.md.

@Xuepoo Xuepoo added this to the 0.0.24 milestone Oct 19, 2026
@Xuepoo Xuepoo added fix Bug fix P1 Priority: high area:ui Area: UI / layout labels Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9e562781-6a9f-496e-a946-0e23e019dd7a
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo
Xuepoo merged commit 8fefe56 into main Oct 19, 2026
17 checks passed
@Xuepoo
Xuepoo deleted the ctx-1367/fix-copy-zerowidth branch October 19, 2026 14:15
Xuepoo pushed a commit that referenced this pull request Oct 19, 2026
Fix bitty#2261. The paste bytes were already delivered exactly once; the
duplicate first token and the Ctrl+C ghost were frame/cursor damage.

Root cause: CUF/CUB counted a wide pair's trailing spacer as an extra
column. In fish's two-pass bracketed-paste repaint, CUF 43 landed on 47;
the subsequent CUB 8 ran on a spacer-free row and landed on 39 instead of
35, so the redraw appended `abc` four columns past the first paint and left
the original cell behind.

- bitty-term-state: cursor moves are O(1) `col +/- n` with a lead snap when
  the destination is a spacer; the requested column count is never inflated.
- bitty-runtime: ZWJ/ZWNJ are cluster joiners, not bidi controls; real bidi
  controls still gate, and ZWSP/WORD JOINER/BOM keep a separate `zero-width`
  reason (P0-AC-008 unchanged).
- Copy-side zerowidth emission is already on `main` via #2266
  (`Cell::push_text_into`); this branch carries only the cursor-move clamp and
  the paste-inspection narrowing, so the rebase drops the duplicate bitty-ui
  edits.

Render scope: unshaped mark painting is not part of this change. CTX-1371
owns it, emitting each visible mark at the font pen origin
(`col*cell_width + base_advance + mark.left`), skipping join controls /
selectors / tag scalars, and proving `e` + U+0301 byte-identical to
precomposed U+00E9. This branch keeps `present_golden` at its parent digest
and touches no `bitty-render` paint path. Merge order: CTX-1368 lands first;
CTX-1371 rebases and adds marks (with the `wide_combining` re-record).

Regression: crates/bitty-runtime/tests/paste_confirm_frame.rs replays the
recorded shell repaint. With only `state.rs` reverted it fails with
`> abc abc`; with the fix it passes (`> abc`), the incremental surface equals
one full replay, and banner dismissal pixels equal a never-armed runtime.

Gates: fmt, workspace clippy -D warnings, nextest term-state/ui/runtime/
terminal, Windows all-targets. Evidence in
recording/ctx-1368-paste-duplication/ (gitignored scratch).
Xuepoo added a commit that referenced this pull request Oct 19, 2026
…2261) (#2272)

* [CTX-1368] fix(term-state): clamp cursor moves across wide spacers

Fix bitty#2261. The paste bytes were already delivered exactly once; the
duplicate first token and the Ctrl+C ghost were frame/cursor damage.

Root cause: CUF/CUB counted a wide pair's trailing spacer as an extra
column. In fish's two-pass bracketed-paste repaint, CUF 43 landed on 47;
the subsequent CUB 8 ran on a spacer-free row and landed on 39 instead of
35, so the redraw appended `abc` four columns past the first paint and left
the original cell behind.

- bitty-term-state: cursor moves are O(1) `col +/- n` with a lead snap when
  the destination is a spacer; the requested column count is never inflated.
- bitty-runtime: ZWJ/ZWNJ are cluster joiners, not bidi controls; real bidi
  controls still gate, and ZWSP/WORD JOINER/BOM keep a separate `zero-width`
  reason (P0-AC-008 unchanged).
- Copy-side zerowidth emission is already on `main` via #2266
  (`Cell::push_text_into`); this branch carries only the cursor-move clamp and
  the paste-inspection narrowing, so the rebase drops the duplicate bitty-ui
  edits.

Render scope: unshaped mark painting is not part of this change. CTX-1371
owns it, emitting each visible mark at the font pen origin
(`col*cell_width + base_advance + mark.left`), skipping join controls /
selectors / tag scalars, and proving `e` + U+0301 byte-identical to
precomposed U+00E9. This branch keeps `present_golden` at its parent digest
and touches no `bitty-render` paint path. Merge order: CTX-1368 lands first;
CTX-1371 rebases and adds marks (with the `wide_combining` re-record).

Regression: crates/bitty-runtime/tests/paste_confirm_frame.rs replays the
recorded shell repaint. With only `state.rs` reverted it fails with
`> abc abc`; with the fix it passes (`> abc`), the incremental surface equals
one full replay, and banner dismissal pixels equal a never-armed runtime.

Gates: fmt, workspace clippy -D warnings, nextest term-state/ui/runtime/
terminal, Windows all-targets. Evidence in
recording/ctx-1368-paste-duplication/ (gitignored scratch).

* [CTX-1368] docs(runtime): correct the paste reason-token bound

* [CTX-1368] test(runtime): prove the banner paints and cover the remaining classes

---------

Co-authored-by: reviewer <[email protected]>
Xuepoo added a commit that referenced this pull request Oct 20, 2026
Cover the full `v0.0.23..main` range instead of the earlier partial passes:
all 71 merged commits are grouped under Added, Changed, Fixed, Security, and
Documentation, with PR numbers and the affected CTX tasks.

Explicit call-outs: copy keeps combining marks and ZWJ (#2266), multi-line
paste duplication and ghost fixed by the cursor clamp across wide spacers
(#2272), combining marks paint so decomposed `é` matches precomposed (#2279),
kitty font query and `bitty +show-font` (#2277), bounded native clipboard
acquisition path B (#2273), bounded `bitty.fs.list` (#2271), the
`bitty.history` Lua surface (#2268), the production ComponentBroker plus
activation state (#2267, #2276), Enter-confirm paste (#2269), the `fill` DPI
fix (#2283), landlock `no_new_privs` (#2284), and spawn descriptor
reservation (#2289).

Partials are marked honestly: #2254's request surface is still pending, the
#2213 disposition stays open, #2286 is feature-gated and unwired, the macOS
clipboard read stays a typed refusal, and the RC-1 fuel accounting fix is not
claimed because PR #2292 is unmerged. The heading reads `unreleased` because
the release is on hold; the tag date is set at tag time.

Docs-only: no code, scripts, workflows, or pins touched.
Xuepoo added a commit that referenced this pull request Oct 20, 2026
Cover the full `v0.0.23..main` range instead of the earlier partial passes:
all 71 merged commits are grouped under Added, Changed, Fixed, Security, and
Documentation, with PR numbers and the affected CTX tasks.

Explicit call-outs: copy keeps combining marks and ZWJ (#2266), multi-line
paste duplication and ghost fixed by the cursor clamp across wide spacers
(#2272), combining marks paint so decomposed `é` matches precomposed (#2279),
kitty font query and `bitty +show-font` (#2277), bounded native clipboard
acquisition path B (#2273), bounded `bitty.fs.list` (#2271), the
`bitty.history` Lua surface (#2268), the production ComponentBroker plus
activation state (#2267, #2276), Enter-confirm paste (#2269), the `fill` DPI
fix (#2283), landlock `no_new_privs` (#2284), and spawn descriptor
reservation (#2289).

Partials are marked honestly: #2254's request surface is still pending, the
#2213 disposition stays open, #2286 is feature-gated and unwired, the macOS
clipboard read stays a typed refusal, and the RC-1 fuel accounting fix is not
claimed because PR #2292 is unmerged. The heading reads `unreleased` because
the release is on hold; the tag date is set at tag time.

Docs-only: no code, scripts, workflows, or pins touched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui Area: UI / layout fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.0.24] Copy drops zero-width scalars: combining accents and ZWJ emoji split

1 participant