Skip to content

Keep the user in the box a rebuilt widget drops: a thread's reply follows the thread, a comment follows its composer - #1396

Merged
max-sixty merged 2 commits into
mainfrom
reply-follows-rebuilt-widget
Sep 28, 2026
Merged

max-sixty merged 2 commits into
mainfrom
reply-follows-rebuilt-widget

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A user writing on an lf-diff line lost the box when the agent set a new patch. Focus fell to the page, so the next letters ran page commands. Two boxes did this:

  • a reply in a thread on that line: each thread's anchor names the patch it was written on, so a new patch moved every thread out to the margin as "Earlier data";
  • a new comment in the composer the diff seats on the line.

In both cases the diff rebuilds its whole shadow tree for the new data, and that removes the focused box before any code that could hand the user on runs. The thread pass and the composer's restoreFab run afterwards. Each read its hold while focus was already on the body, so each held nothing.

A hold reads a dropped node

runtime/focus.js now remembers where the user last stood: the node each focusin lands on, and the node a focusout with no destination leaves. When the user stands nowhere and that node is no longer drawn, the user was dropped from it.

Every placement rewrites the record. A key, press, wheel or touch made while the user stands nowhere clears it, because that is the user going on from nowhere.

  • holdFocus(scope) holds the dropped node when it lies inside scope, so every existing hold answers for a change that ran before it. The composer's restoreFab needs nothing more.
  • holdStanding() is the same reading without a scope.
  • A function stand-in now runs as the owner's own act rather than inside land, so wherever it moves focus counts as a placement to every other open hold.

A thread's reply follows the thread

holdReply (thread/focus.js) takes holdStanding() at the start of every thread pass when it names a thread's reply box. It restores it once every surface is drawn: the thread goes up where it now stands, through the margin's openPageThread, and the user lands in that view's reply box. The draft carries over, since every view keys it on the thread. Neither route is specific to the diff.

This is option #3 ("Follow it to the margin card"), picked on the thread-focus review page.

Tests

Each new test fails on main at its focus assertion:

  • test_a_reply_box_whose_thread_leaves_the_diff_takes_the_user_to_its_card: the margin card's reply box ends up focused, with the draft and caret kept.
  • test_a_comment_being_written_on_a_diff_line_stays_in_hand_across_a_new_patch: the same for the line's composer.
  • test_a_thread_resolved_while_its_reply_is_written_keeps_the_user_on_it: an agent resolving a thread the user is replying to leaves them on the thread's card.

The first two also check that typing " tr" afterwards goes into the draft rather than running t and r.

ui-sweep's unmerged 87ff1908d answers the same "has the user moved on" question in focus.js with a focusout rule. Whichever lands second folds its rule into the other's.

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

🤖 Generated with Claude Code

max-sixty and others added 2 commits September 27, 2026 17:27
…lows the thread, a comment follows its composer

A user writing on an `lf-diff` line lost the box when the agent set a new
patch, and focus fell to the page, so the next letters ran page commands. Two
boxes did this:

- a reply in a thread on the line: each thread's anchor names the patch it was
  written on, so every thread moved out to the margin as "Earlier data";
- a new comment in the composer the diff seats on the line.

In both the box goes before any owner that could hand the user on runs. The
diff rebuilds its whole shadow tree for the new data (`shadowStage` →
`setChildren`), removing the outlet with the focused box; the thread pass and
the composer's `restoreFab` come afterwards, and each read its hold while
focus was already on the body, so each held nothing.

## A hold reads a dropped node

focus.js now remembers where the user last stood: the node each `focusin`
lands on, and the node a `focusout` with no destination leaves. The second is
needed because a move between two nodes of one shadow tree, such as the diff's
Comment button to its composer, reaches the document as neither event. A user
who stands nowhere was dropped from that node while it is no longer drawn.
Every placement rewrites the record, and a key, press, wheel or touch made while
the user stands nowhere clears it: that is the user going on from nowhere, and
a later owner putting them back would take them from whatever they went on to.

- `holdFocus(scope)` holds that dropped node when it lies inside `scope`, so
  every existing hold answers for a change that ran before it. The composer's
  `restoreFab` needs nothing more: it already holds the bar before moving it
  home, and now finds the dropped field in it and puts the user back once the
  bar is placed, beside the diff, since a source replacement keeps the draft
  about its prior revision (`standsIn`).
- `holdStanding()` is the same reading with no scope, for an owner that learns
  from the node which place it holds. Both return one restore (`holdOn`), and a
  function stand-in may now resolve to an element, which the user lands on with
  the caret as they would on an element stand-in.
- A function stand-in now runs as the owner's own act rather than inside
  `land`, so wherever it moves focus is a placement to every other open hold;
  only a restore to the held place is not. Before, a thread card that landed
  the user on a thread resolved under their reply did it as a restore, so the
  pass's outer hold still thought the user unplaced and went looking for a
  reply box, opening Threads.

## A thread's reply follows the thread

`holdReply` (thread/focus.js) takes `holdStanding()` at the start of every
thread pass when it names a thread's reply box, and restores it once every
surface is drawn and committed. Its stand-in puts the thread up where it now
stands through the margin's `openPageThread` (the surface drawing it, its
margin card, or the panel) and resolves to that view's reply box; the draft is
the same record there, since every view keys it on the thread. A box is carried
once, and only to a thread with a reply box to carry it to (one the reading
holds, open), so nothing is put up for a resolved or vanished thread.

Neither route is diff-specific: any surface that stops drawing a thread whose
box the user stands in hands them to the thread's other view, and any hold over
a subtree a change already removed finds the user it dropped.

Nothing buffers keys meanwhile. In these journeys no task falls between the
drop and the landing, and the tests check that. The thread pass after the
rebuild starts from `flushQueuedInvalidation` once `receiveState` finishes,
which awaits every data subscriber in that read, so a sibling data widget that
awaits a real task would open a window in which a key reaches the page. The
panel route lands its box asynchronously and puts the caret at the end.

Tests, each failing on main at its focus assertion:

- `test_a_reply_box_whose_thread_leaves_the_diff_takes_the_user_to_its_card`
  types half a reply with the caret mid-word, sets a new patch, and asserts the
  margin card's reply box is focused with the draft and caret.
- `test_a_comment_being_written_on_a_diff_line_stays_in_hand_across_a_new_patch`
  does the same for the line's composer, which returns floating beside the
  diff.

Both also assert that no task after the box left found focus on the body, and
that typing " tr" appends to the draft rather than running `t` and `r`.

`test_a_thread_resolved_while_its_reply_is_written_keeps_the_user_on_it` holds
the resolve journey where main has it: an agent resolving a seat thread the
user is typing a reply in leaves them on the thread's card, with Threads
closed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 83a7204 into main Sep 28, 2026
5 checks passed
@max-sixty
max-sixty deleted the reply-follows-rebuilt-widget branch September 28, 2026 16:37
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