Repository navigation
Keep the user in the box a rebuilt widget drops: a thread's reply follows the thread, a comment follows its composer - #1396
Merged
Conversation
…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]>
leaf-agent
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user writing on an
lf-diffline 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: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
restoreFabrun afterwards. Each read its hold while focus was already on the body, so each held nothing.A hold reads a dropped node
runtime/focus.jsnow remembers where the user last stood: the node eachfocusinlands on, and the node afocusoutwith 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 insidescope, so every existing hold answers for a change that ran before it. The composer'srestoreFabneeds nothing more.holdStanding()is the same reading without a scope.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) takesholdStanding()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'sopenPageThread, 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
tandr.ui-sweep's unmerged87ff1908danswers the same "has the user moved on" question infocus.jswith afocusoutrule. Whichever lands second folds its rule into the other's.🤖 Generated with Claude Code