Skip to content

surface: a selection covers every cell it sweeps, code spans included (#294) - #296

Closed
santoshkumarradha wants to merge 3 commits into
devfrom
fix/selection-holds-its-ground
Closed

santoshkumarradha wants to merge 3 commits into
devfrom
fix/selection-holds-its-ground

Conversation

@santoshkumarradha

Copy link
Copy Markdown
Member

Closes #294.

What was wrong

A ground step — palette.mark, palette.selected, palette.cursor — was one
background code, the text, and one reset. That is only true of text carrying no
background of its own, and the transcript is full of text that does: an inline
code span sits on the surface's raised plane, and it both sets a ground and
clears it on the way out with the compound \x1b[49;39m.

Nested inside a selection, the set turned the span into a hole the highlight
visibly skipped, and the clear — the worse of the two — switched the ground off
for the whole rest of the row. Measured at the door, off the bytes a.frame()
hands the terminal:

Row swept Cells lit, before After
The internal/swepro/ directory was deleted, along with the rest. 4 of 80 80 of 80
a row that opens with a code span 0 of 20 20 of 20
a row with two code spans 0 of 31 31 of 31
copy mode (ctrl+s) over a row with one span 4 of 42 42 of 42

The clipboard was always right — dragYank reads ansi.Stripped text — so this
was the paint lying about a copy that was correct. That is the whole damage: the
paint is all a person has to tell them what they are about to take, and
keys.md promised them "What is highlighted is exactly what is copied, to the
character."

The change

palette.background rewrites every background parameter inside the span it
wraps to its own ground: an inner set becomes the step's ground, an inner clear
becomes the step's ground, and a full reset keeps its reset and re-lays the
ground behind it. Every form the styler can emit is answered — 48;5;n,
48;2;r;g;b, the sixteen-colour 40–47 and 100–107, the bare 49, the
compound 49;39 prose actually emits, and 0 spelled as no parameters at all.

Inks and attributes are untouched, so a marked code span keeps its colour, its
bold and its italic; only the plane under it is made one.

THE SELECTION WINS OVER THE CHIP, and that is the ruling rather than an
accident of implementation. The mark is the loudest rung of the ground ladder; a
raised plane inside it says "this cell is a different kind of thing" at exactly
the moment the person is being told "these cells are the ones". Every terminal's
own selection replaces the background it sweeps over, and this one now reads the
same.

Because it lands on the shared step, everything drawn with it comes back at
once: the sweep, copy mode's span, the pointer's row on every list carrying
chips or code spans (memory, spend, search, rewind, task, crew, effortchip), and
pastechip's mark(chip(token)), which nested the two outright.

Text with no escape in it returns untouched and unallocated, which is most of
what this is handed.

Tests

internal/tui3/holdground_test.go, new:

  • e2e TestASweepOverACodeSpanLightsEveryCellItCopies — drives a real press
    and sweep through app.Update, reads the row back out of a.frame(), and
    asserts every cell wears the selection's ground, padding included.
  • e2e TestTheSweepCopiesExactlyWhatItLit — the control: releases the same
    sweep and asserts the OSC 52 payload, so a future change cannot make the
    highlight honest by making the copy wrong.
  • Unit TestAGroundStepCoversEveryCellItIsGiven — mark and selected, at
    TrueColor and ANSI256, over five row shapes to full coverage.
  • Unit TestRegroundAnswersEveryBackgroundForm — every SGR form above.
  • Unit TestHoldGroundLeavesPlainTextAlone, TestAGroundStepLeavesTheInkAlone,
    TestAGroundStepPaintsItsPaddingToo — the things that must NOT change.

The cell counter (litCells) walks SGR the way a terminal does, because the
sequence at fault is compound and a naive scan for \x1b[49m never sees it —
which is why this survived review the first time.

go test ./internal/tui3/ -count=1     ok  483.357s
go vet ./internal/tui3/               ok
go build ./...                        ok

Full internal/tui3 suite green, so no snapshot asserting the old escape stream
broke.

Manual

internal/manual/chat/keys.md gains "The highlight covers inline code too."
under Selecting text with your mouse, stating the ruling in the person's own
words.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B25XERftiFQW619ctN4kRg

santoshkumarradha and others added 3 commits September 1, 2026 20:24
…#294)

A ground step was one background code, the text, and one reset — true only of
text that carries no background of its own. An inline code span carries one,
and it closes with the compound `\x1b[49;39m`: nested inside a selection, the
set turned the span into a hole the highlight skipped, and the clear switched
the ground off for the whole rest of the row. A sweep over a line that opened
with a backticked path lit four cells of sixty-four and read as a selection
that had not happened.

`palette.background` now rewrites every background parameter inside the span it
wraps to its own ground — an inner set, an inner clear, and a full reset, in
every form the styler can emit. Inks and attributes are left alone, so a marked
code span keeps its colour, its bold and its italic; only the plane under it is
made one. THE SELECTION WINS OVER THE CHIP, which is the ruling and not a side
effect: the mark is the loudest rung of the ground ladder, and every terminal's
own selection replaces the background it sweeps over.

The clipboard was always right — the yank reads stripped text — so this was the
paint lying about a copy that was correct, which is the whole damage: the paint
is all a person has to tell them what they are about to take.

The same step draws copy mode's span, the pointer's row on every list that
carries chips, and pastechip's marked token, so all of them come back with it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B25XERftiFQW619ctN4kRg
`internal/manual/chat.pack.gz` is tracked, so a page edited without a repack is
a page the shipped binary has not learned — and the `check` job says so.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01B25XERftiFQW619ctN4kRg
@santoshkumarradha

Copy link
Copy Markdown
Member Author

Superseded by #303, which fixes the same root cause correctly where this branch does not.

Both branches rewrite inner background parameters in palette.background, and the ruling is the same. The difference is sub-parameter handling: my reground walks a parameter list flatly, so a true-colour foreground whose channels collide with background parameter numbers gets mangled — reground("38;2;0;49;100", "48;5;7") returns 38;2;0;48;5;7;48;5;7;48;5;7. That is not an edge case: it hits every colour with a zero channel. #303's regroundParams consumes 38/58's sub-parameters and gets it right.

#303 also already carries every test named in #294's acceptance, under the same names, including the two end-to-end ones through a.frame() and the OSC 52 control. I have left the one case it does not yet pin as a comment there.

Closing unmerged; nothing here is worth carrying over. Issue #294 stays open for #303.

@santoshkumarradha
santoshkumarradha deleted the fix/selection-holds-its-ground branch September 2, 2026 00:42
@santoshkumarradha santoshkumarradha added the area:chat The v3 surface a person sits in front of (internal/tui3) label Oct 3, 2026
@santoshkumarradha santoshkumarradha added this to the Chat & connections milestone Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:chat The v3 surface a person sits in front of (internal/tui3)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The selection highlight stops at the first inline code span — a sweep lights 4 cells of 64

1 participant