Skip to content

Keep a margin card on its thread when a reading moves the thread or empties its row - #7563

Merged
max-sixty merged 2 commits into
mainfrom
thread-step-keeps-focus
Nov 28, 2026
Merged

max-sixty merged 2 commits into
mainfrom
thread-step-keeps-focus

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Resolving a thread in a margin card now keeps the user in the card when the next thread at that paragraph stands in another margin row. Before, with one thread on a whole paragraph and one on a phrase in it, r on the first left the card showing the second while focus and its ring stood on the paragraph: the render closed the card because its row was empty, the settlement's landing focused the paragraph, and the keyboard arrival there reopened the card beside it. The card's departure went by its row, while the arrival went by the target.

The render now asks where the card's thread went before choosing what the card shows (followCardThread, showNextAtTarget in margin-projection.js). A thread moved to another row, as after a revision rewrote its quoted words, takes the card with it. A thread a widget seats closes the card for the thread pass to carry the user. A resolved or withdrawn thread gives its place to the next in its row, else to the next at the card's target by the arrival's rule (threadEntryAt), else the card closes and lets the user go beside the target.

To weigh: a thread that follows to a new row opens afresh, so a reader deep in a long transcript lands where an opening lands. Keeping the card's session across rows kept the place but hid the quote a revision adds under the head line, so I left it. test_a_card_quotes_the_words_a_revision_rewrote_under_its_head_line now expects the card to stay open across that revision rather than close.

The structure that lets such focus bugs recur, several pieces of code each moving focus around one reading, is #7564, for the margin card's Effect UI port.

Max reported it on a live page in Firefox. Reproduced there and on a fixture, before and after; a Codex review found the seat, revision, withdrawal and Back cases, each rechecked in Firefox. Tests: a new browser test across two rows, focused card, revision, Back and seat tests, pnpm run test:runtime and check:browser.

This was written by Claude Code on behalf of max-sixty

…mpties its row

Two threads on one paragraph, one on the whole paragraph and one on a
phrase in it, stand in two margin rows of the same target. Resolving the
first in its card by `r` left the card showing the second while focus
and its ring stood on the paragraph. The render closed the card because
its row was empty, the settlement's landing focused the target, and the
keyboard arrival there opened the card again beside it with the other
row's thread. The card's departure went by its row, while the arrival
went by the target.

The render now asks where the card's thread went before choosing what
the card shows (`followCardThread`, `showNextAtTarget`):

- A thread now in another row, as after a revision rewrote the words it
  quoted, takes the card with it. The card used to close and drop focus
  to the body.
- A thread a widget now seats closes the card, so the thread pass
  carries the user to the seat. A surviving row used to focus a sibling
  first.
- A resolved or withdrawn thread gives its place to the next in its row
  as before. Where the row is empty, it gives its place to the next
  thread at the card's target, by the arrival's own rule
  (`threadEntryAt`). With none left, the card lets the user go beside
  the target rather than from the paragraph at the top of the window.

The target comes from the card's margin host, read before the render
removes it, so a withdrawal that drops the thread's placement still
finds the sibling. The card goes on under either choice of where
threads open, since it is already open, as a card Back restored is.

A thread that follows to a new row opens there afresh, so a reader who
had read back in a long transcript lands where an opening lands.
Keeping the card's session across rows kept that place but hid the
quote a revision adds under the head line.

`test_a_card_quotes_the_words_a_revision_rewrote_under_its_head_line`
asserted that the card closed when a revision moved its thread to the
section's row; it now asserts the card stays open on that thread.

Max reported the Resolve case on a live page in Firefox; reproduced
there and on a fixture, before and after. A Codex review found the seat,
revision, withdrawal and Back cases, each rechecked in Firefox. A new
browser test resolves across two rows and checks focus and the card's
ring.
@max-sixty
max-sixty merged commit 6e7004d into main Nov 28, 2026
7 checks passed
@max-sixty
max-sixty deleted the thread-step-keeps-focus branch November 28, 2026 22:58
leaf-agent added a commit that referenced this pull request Nov 29, 2026
…cused (#7583)

When a patch gives a thread back to its seat on a diff line while the
user is typing in its margin card, the reply editor on the diff line is
now focused again, as #7563's parent left it. The focus is on the same
editor, with the same caret and undo history.

**Cause.** #7563 made the margin render follow a card's thread when the
thread leaves the card's row (`followCardThread` in
`margin-projection.js`). The first render after the patch still finds
the thread in a margin row, because `lf-diff` hasn't seated it yet.
`followCardThread` then reopened the card there, which moved focus from
the reply editor to the card's frame. The thread pass was carrying the
user's place on that editor (`records/thread/focus.js`,
`carryingThreadPlace`), and the focus move broke the carry. On the next
render the thread had its seat, so the card closed and the default
`letGo()` sent the user to the page body. Logging on `main` showed this
sequence: `carryingThreadPlace` was true at the first
`followCardThread`, and false once the reopen had focused the card's
frame.

**Change.** While the thread pass is carrying the user,
`followCardThread` only closes the card, which places no one, and the
pass lands the user where the thread now stands. Resolved and withdrawn
threads take the same path as before.

**What it keeps from #7563.** I checked the case #7563 targets: a
revision moves a card's thread to another margin row while the user
types in the card's reply. On both base and head the user stays in the
card's reply with their words. #7563's own resolve and revision tests
still pass.

**Verification.** Both tests named in #7580 failed on `main` and pass
with the change:

-
`test_a_reply_box_whose_thread_returns_to_the_diff_takes_the_user_back`
-
`test_a_reply_dictated_on_the_diff_keeps_listening_as_its_thread_moves`

These also pass:

- `test_a_reply_box_left_by_tab_returns_to_the_diff_with_its_history`
- `test_resolve_in_a_card_moves_on_across_the_passages_of_its_target`
and `test_resolve_in_a_card_moves_on_to_the_next_thread_at_its_passage`
- `test_a_card_quotes_the_words_a_revision_rewrote_under_its_head_line`
and `test_a_card_open_across_a_revision_opens_where_its_passage_stands`
- `test_a_reflow_that_moves_a_marker_carries_its_open_card`
- `pnpm run test:runtime` and `check:browser`

This is one more place that decides around a carried focus. #7564 tracks
the structural fix, one owner moving focus per reading.

Closes #7580 — automated triage

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 29, 2026
…lement (#7584)

A press on a marked phrase, in the same task in which a script gave the
phrase a second copy, opened the thread's card. Placement had already
moved the thread onto its section, since the quote no longer picks out
one copy. But the anchor paint's `replace`
(`browser/runtime/annotations/anchor-paint.ts`) asked for a whole
repaint for a thread that now stands on an element, and returned before
it removed the passage's pieces from the hit-test index. The repaint
runs later, so `markHit` still found the old mark under the press.

This defect is older than #7563. At #7563's parent `b67c5abf7` the press
also opened a card, as a probe that counted cards right after the click
showed, but the next margin render closed it because its row was gone.
Since #7563, `followCardThread` moves the card to the thread's new row,
as that PR meant it to, so the card stayed open and
`test_a_press_in_the_task_a_script_repeats_a_marked_phrase_opens_nothing`
failed. Now `replace` drops the old pieces before it asks for the
repaint, so the press finds no mark and opens nothing, which is what the
test protects. #7563's card-following behavior is unchanged.

Verification: the test failed in `[browser]` and `[firefox_browser]` on
`main` (`9e2e64d34`) and passes in both with this change. The press,
script and quote tests in `test_render_anchors.py` (35),
`tests/browser/threads/test_resolving.py` with
`tests/browser/margin/test_opening_threads.py` (64), and `pnpm run
test:runtime` all pass.

Closes #7581 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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.

2 participants