Skip to content

Carry a reply being written to the card a thread moves to - #2604

Merged
max-sixty merged 2 commits into
mainfrom
agent-ab60f6250fa147d20
Oct 12, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-ab60f6250fa147d20

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Issue #84 of the Lit follow-up review. That review numbers its own items, so #84 is not a GitHub issue.

#84: a reply being written goes with its thread to another seat

What changed. A thread can leave a widget's outlet while the user is writing a reply in it. It goes to the margin card, or to the Threads panel when the page draws its annotations in the page margin. Either way, the user now goes on in the same editor, and undo walks back through what they typed before the move. Before, the destination card's own reply editor took the words, the caret and focus, and the history was lost, so Cmd+Z did nothing.

How. The reply row now belongs to the thread's editing session rather than to the card that drew it (thread/replies.js).

  • wireReply wires a row's editor once. What the row does for a card (its send actions, onChange, editLast, the panel's lfRevealReply and row-height observer) is a binding: attach sets it and the detach it returns clears it.
  • Once no card holds the session's row, carry has the card on the thread's current route take it in place of its own row (binding.take: detach, attach the session's row, redraw). That happens at the one point that knows the route, the hand-off's destination: replyControlDestination for a user standing in the box, and the realize loop of holdReplyCompositions for a session left by Tab. So it doesn't matter whether the destination card was built before or after the source card let go. A package mirror, which can't draw another row, keeps its own and takes the caret, as before.
  • take blurs the row it gives up before redrawing, so the card's focus hold doesn't move the user somewhere that cancels the hand-off. replyDestination (thread/focus.js) checks where open left the user before asking the destination for its control, then hands them to it.
  • holdReply forgets a box once the carry lands back on that same box, so the row can be carried again on a later move.
  • attach doesn't call the card's onChange. At construction that call was a no-op for both callers. After a take it made a settled thread request a presentation, whose hand-off carried the other session back. The margin card then alternated between two threads without end.

Not done here.

  • The card itself isn't carried. Outlet cards are <details>, while page and margin cards are <div>. An overlay margin also opens its card only after the outlet has gone, so the source card has nowhere to move to.
  • The editor still blurs once, because it is out of the document between the outlet's removal and the destination taking it. Avoiding that would need a connected place to park it and cards that place their row with move() rather than through Lit.
  • A thread moving the other way, from the margin card back into an outlet, loses focus to the banner's More button. This also happens on main: the margin's rerender close (closePreview, which defaults to letGo) lands the user before the hand-off runs.

Lines. Hand-written source: +127 / −80 (replies.js +106/−52, focus.js +15/−8, thread-card.js +6/−20). Tests: +28 / −9.

Test. test_a_reply_box_whose_thread_leaves_the_diff_takes_the_user_to_its_card now presses undo twice after the move and expects the words typed before the move to go too. It runs on an overlay margin, with and without a resolve, and on a page margin, where the thread lands in the panel. All three cases fail on main. The page case also fails with carry disabled while the overlay cases still pass.

Checks

These pass: npm run test:runtime; the seat, reply, diff, margin, draft, mirror, resolved and composer selections of test_render_threads.py, test_render_drafts.py, test_render_widgets.py, test_thread_response_continuity.py and test_response_pointer.py (318 tests); and pre-commit. test_an_empty_draft_survives_reload_and_a_live_revision and test_the_reading_page_keys_follow_the_user_into_the_panel fail the same way on the base.

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

max-sixty and others added 2 commits October 12, 2026 08:46
A thread leaving a widget's outlet for the margin card or the Threads panel
now brings the user's reply editor with it, so undo walks back through what
they typed before the move. Before, the destination card's own editor took
the words, caret and focus, and the history was lost.

The reply row belongs to the editing session rather than to the card that
drew it. Once no card holds the session's row, the card on the thread's route
takes it in place of its own (`carry`, at the hand-off's destination), so the
order the two cards are built in no longer matters. Per-card behavior and
state (send actions, onChange, editLast, lfRevealReply, the panel's row-height
observer) is a binding attached and detached with the row. Attaching no longer
calls the card's onChange: it was a no-op at construction, and after a take it
made a settled thread request a presentation that carried another session
back, looping.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit cff9a28 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-ab60f6250fa147d20 branch October 12, 2026 16:00
max-sixty added a commit that referenced this pull request Oct 12, 2026
…rgin card to its outlet (#2614)

Item #86 of the Lit follow-up review. The review numbers its own items,
so #86 is not a GitHub issue. This follows #2604, which carries a reply
being written from a widget's outlet into the margin card.

## #86 (a): a reply being written goes back with its thread to the
outlet

**What changed.** A thread can go back from the margin card into a
widget's outlet while the user is typing its reply in the card. A diff
thread does this when the patch it was written on returns. The user now
goes on in the same editor on the diff line, at the same caret, with its
undo history. Before, the card closing under them landed them on the
banner's More button, so the next letters ran page commands. This also
happened before #2604.

**Cause.** The thread pass closes the card in `renderAnnotations`,
before its reply hand-off (`holdReply`) runs. `closePreview` defaults to
`letGo`, and that placement voided the hand-off's hold. Once focus was
handled, a second gap showed: `carry` refused a row any view still held,
so the hidden card kept the user's editor and the user landed in the
outlet's own editor without its history.

**How.**
- `thread/focus.js`: `holdReply` records the box its pass is carrying
until its step has run. `carryingReply(node)` answers for it while the
thread still stands with a reply and the user has done nothing since.
The reply admission both use is one helper (`mayReplyTo`).
- `margin-projection.js`: `closePreview` places no one when the user
stands in a carried reply, so the hand-off decides where they go.
- `thread/replies.js`: `carry` takes the row from a view that holds it
out of sight, as the closed card does. That view gives it up
(`binding.give`): it detaches, wires a fresh row, and draws it once the
taker has moved the row out.

**Lines.** Hand-written source: +73 / −26 (replies.js +37/−13, focus.js
+31/−12, margin-projection.js +5/−1). Tests: +52 / −2.

**Test.**
`test_a_reply_box_whose_thread_returns_to_the_diff_takes_the_user_back`
writes on the diff line, follows the thread to the card, types more
there, and brings the patch back. It then expects focus, words and caret
on the diff line, typing to continue, and two undos to walk back through
the card's typing. On `main`, focus lands on `lf-banner-more`. With only
the `closePreview` change, the user lands in the outlet's own editor and
the undo fails.

## #86 (b): the remaining blur, not done

The editor still blurs once on each move. Going to the card, the outlet
is removed before the card exists, so a blur-free move needs a
connected, rendered place to park the row. Coming back, the blur comes
from ordering: the card hides before the carry, and `open` focuses the
outlet's own editor first. Removing it means opening the destination
without focus (`continueThread` already does this), carrying the row in
with `move()`, which keeps focus through `moveBefore`, and only then
closing the card. That changes the order in `presentation.js`'s commit
and in `openPageThread`'s surface path, which closes the preview first.
So this PR asserts no blur count.

## Test watch

`tests/words_watch.js` now hears a `leaf-text`'s host `input` on the
field itself. That event is not composed, so typing inside a widget's
shadow tree, such as an `lf-diff` outlet, never reached the watch, and
the words it held went stale. With the watch fixed,
`test_replaced_reply_compositions_keep_their_carets_and_leave_commands`
reports the words of the thread the margin card does not show. The
test's own comment calls that state intended: that thread's session
keeps its words and caret until the user selects its route. The test now
consumes the report rather than asserting none. I read this as the
rule's "no usable room" case in `skills/leaf/assets/AGENTS.md`, "Words
stay where they were typed": the card shows one thread at a time.

## Checks

These pass:
- the seat, reply, diff, margin, draft, carried and resolved selections
of `test_render_threads.py` and `test_render_drafts.py`;
- the diff, outlet, composer, comment, editor and visual selections of
the widget, anchor, read-state, file and diff-control browser tests;
- `test_render_words_watch.py`, `test_thread_response_continuity.py` and
`test_response_pointer.py`;
- `pnpm run test:runtime`;
- eslint, prettier and ruff format on the changed files.

`test_the_reading_page_keys_follow_the_user_into_the_panel` failed once
under load and passes alone. #2604 recorded it failing on the base too.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[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