Repository navigation
Keep a retained editor in the document through a diff's new patch and a file editor's move - #2570
Conversation
… a file editor's move Review items 68 and 69 of the Lit follow-up round. 68: lf-diff took a thread outlet down while preparing a thread placement, before core had moved the comment box out of it, so a new patch blurred the box the user was writing in, and a focus hold put them back. A patch that changed the commented line dropped the outlet earlier still, in the file's re-render. Now: - The placement callback's context carries `onCommit(run)`, which runs once the placement commits (thread/surfaces.js). lf-diff removes the outlets it stopped returning only there, so the composer has gone home or to its new seat first. - A file's re-render keeps every outlet in the document: beside its datum's line where that is drawn again, else beside the line before it. A datum drawn anew takes its outlet along with `move`. - The file hold's outlet loop is gone, since no re-render drops an outlet. - A disconnect retires every outlet and resets the grid spans, rather than leaving empty outlets behind for a reconnection. The new-patch test now asserts zero blurs, for a patch that changes another hunk and one that changes the commented line itself. 69: lf-file-editor kept its view and buffer through a move, since whileConnected follows the arrival batch, but `moveBefore` collapsed CodeMirror's native selection, so the next key landed at the start of the file. It now defines `connectedMoveCallback` and puts each view's recorded selection back as leaf-text does. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…t of a replaced row A hunk added above kept lines gave them indices other kept gutter rows still held, so a lookup after the first re-key found the wrong row and dropped two gutter rows; the rows are now read by their old index before any is re-keyed. A file that becomes a rename moves its line outlets out of the old row before replacing it, and a re-render lays the outlets it kept out again at once. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The new file-editor move test fails the browser health gate. Its setChildren(main, [...main.children].reverse()) call reorders the page without a user gesture. In a focused run, the caret and typing assertions passed, but teardown reported eight passive layout shifts, including the focused editor moving 92 px. That conflicts with skills/leaf/assets/AGENTS.md’s “Stability” rule that reading content stays put without a gesture, and CI will run this new test. If the intended case is a revision reordering sections, the page needs to keep the reader’s place through that move. If it is a user-requested reorder, the fixture should make that gesture explicit before the move. The current test leaves the PR’s claimed revision path unverified and the gate red.
…ng on screen shifts The reversed sections moved the focused editor 92px without input, which the browser health gate refuses. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ng it (#2571) ## Why `x-thread-surface` only gated `placeThreads`. A widget's module registered its surface in `connectedCallback` and unregistered it in `disconnectedCallback`, and `requireSurface` refused the call unless the tag declared the key. The declaration added nothing the call did not, so every surface widget carried the same registration code. The user decided (#29) that the declaration should do the work. ## What changed - **Registration from the declaration.** The runtime registers each instance of a tag declaring `x-thread-surface` once its module has defined it, and retires it when it leaves the page. This uses the arrival lifetime every element owner already holds (`watchArrivals`), so a move within one batch keeps the registration. The watch starts once the registry that names the tags has loaded. It waits for a tag's definition only while none stands, so an element whose constructor threw is not retried; its module's failure report is the outcome. - **The widget answers instead of registering.** On each reconciliation pass the runtime calls the element's own `threadOutlets(targets, {signal, collection, onCommit})`. The batch, the returned outlet array, the commit-time work #2570 added (`onCommit`) and the failure handling are those the callback had; `lf-diff` lays its outlets out in the method and retires unused ones on commit. - **A handle the widget reads.** `threadSurface(element)` from `widget-api.js` gives `update()` and `open(datum, {origin})`. Before registration, or after the widget leaves, `update` does nothing and `open` returns `false`. - **Removed.** `placeThreads` and `requireSurface` are gone. `placePageThreads` stays for page-owned annotations. - **Widgets and docs.** `lf-diff` and `lf-visual-review` implement `threadOutlets` and no longer register or unregister; `lf-diff`'s outlet map, which used that name, is now `threadSeats`. The `$keys` description, `module-authoring.md` ("Widget-local Thread placement"), `docs/registry.html` and the two eval cases that named `placeThreads` describe the new contract. ## Behavior change A package widget that declares `x-thread-surface` must implement `threadOutlets`. Calling `placeThreads` now fails, because the export no longer exists. A widget can no longer withdraw its surface while it stands: to offer no seats, it returns `null` for each target. Tests changed to match: - The adapter-isolation test drops its two cases where the widget unregistered itself. - The widget-before-page and cohort tests withhold seats by returning `null` outlets, instead of registering late or unregistering. ## Tests - `pnpm run test:runtime` (369, including `thread-surfaces.test.mjs` for the failed-constructor case) and `pnpm run check` pass. - The thread-surface browser tests and #2570's retained-editor tests by node id at `-n 2`: 52 passed. These cover the diff, visual-review, read-state, startup adapter-failure, widget-before-page and cohort tests. - The registry contract tests and the `widget-api` export tests pass. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…ding it (#2580) Item 72 of the Lit follow-up review. That review numbers its own items, so #72 is not a GitHub issue. ## Item 72: a comment being written stays in hand when its outlet's content goes **What changed.** A comment being written on a diff line now keeps focus, with no blur, when a change removes the line without a redraw that would keep its outlet. There are four such changes: a new patch that drops the line's file, the file's next deferred patch failing to load, the source being cleared, and a patch the widget refuses (`failSoft`). Before, each of them removed the thread outlet holding core's composer before the thread placement committed. A dropped file lost focus altogether, and the user was left on the page. In the other three the box blurred once and `restoreFab`'s hold put the user back. The same cause affected `lf-visual-review`: a new run that dropped the case being commented on left the user on the next case's title, and a cleared source blurred the box once. Both now keep the user typing too. **How.** #2570 gave the placement an `onCommit` hook, so a widget removes unused outlets only once core has moved the composer. Its hook didn't cover a removal outside the placement, and the runtime had nothing a widget could call first. - `releaseOutlets(node)` (`thread/surfaces.js`, exported from `widget-api`) moves core's composer out of every registered outlet under `node` immediately, to where the next commit would put it. On every path this covers, the composer's datum is gone, so the next commit puts it in the same place and doesn't move it again. The move goes through `move()`, which keeps focus. The released box is in the viewport. - `lf-diff` calls it before dropping a file, before a file's error box replaces its lines, before a cleared source empties its stage, and before `failSoft`. - `lf-visual-review` calls it for the cases a new run drops, at the top of `#show`, and before `failSoft`. - `failSoft` doesn't call it itself. The dependency gate forbids `widget-upgrade.js` from importing the thread layer, because that import closes a cycle through `markdown.js` and `projection/authored.js`. These two are the only widgets that place threads. - A release has to come before any `holdFocus` around the removal. Otherwise that hold reads the user as having left and hands them to Retry or to the case title. `module-authoring.md` ("Widget-local Thread placement") states this next to `onCommit`. **Not done here.** I didn't add a removal hook in `dom-children.js`. `lf-visual-review` removes cases through Lit `repeat` rather than `setChildren`, so the hook wouldn't reach it. A release made during removal would also come after the widget's own focus hold. While the floating bar is still being placed at home, that hold would not count it as drawn. A revision that removes the whole widget while the user is composing is deferred (`midComposition` in `version.js`). I checked this: the revision was not applied within 120 s. **Lines.** Hand-written source: +31 / −1 (surfaces.js +11, widget-api.js +1, lf-diff.js +12/−1, lf-visual-review.js +7). Tests: +102 / −6. **Tests.** - `test_a_comment_being_written_on_a_diff_line_stays_in_hand_across_a_new_patch` runs four new cases: `file-dropped`, `file-refused`, `source-cleared` and `patch-refused`. It now also checks that the box is in the viewport. Each new case fails on `main`. `file-dropped` loses focus, and the other three blur once. `patch-refused` was checked by disabling the release before `failSoft`. - `test_a_comment_being_written_on_a_visual_case_stays_in_hand_as_the_case_goes` has two cases, `case-dropped` and `source-cleared`. Both fail without the release in `#show`. ## Checks These pass: `npm run test:runtime`; the diff, visual-review and failure selections of `test_render_threads.py`, `test_render_diff_controls.py`, `test_render_anchors.py`, `test_render_widgets.py`, `test_render_read_state.py`, `test_render_drafts.py`, `test_thread_response_continuity.py`, `test_response_pointer.py` and `test_render_visual_review_journey.py`; the widget-api export test; and pre-commit. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Items 68 and 69 of the Lit follow-up review. Both are cases where an editor that stays in the page should survive a DOM move, and one of them didn't. The numbers are the review's own, not GitHub issues.
Item 68: the comment box on a diff line no longer blurs on a new patch
What changed. A comment box being written on a diff line now keeps focus through a new patch, and never fires a blur. Before, lf-diff removed the thread outlet holding the box while it prepared the next thread placement. That ran before core moved the box out at commit, so the editor left the document, blurred once, and
restoreFab's focus hold put the user back. A patch that changed the commented line itself caused the same blur one step earlier: the file's re-render dropped the outlet together with the old row.How.
thread/surfaces.js: the placement callback's context gainsonCommit(run). Each registered function runs after the placement commits, so by then core's composer and thread views are no longer in outlets the widget stopped returning. A cancelled preparation never runs its hooks.lf-diff.js: the widget removes unused outlets only inonCommit(retireThreadOutlets). Between preparation and commit,layoutThreadOutletssizes the grid with them still counted. A file re-render keeps every outlet in the document. Each one goes beside its datum's line if that line is drawn again, otherwise beside the line before it (outletPlaces). A datum that is drawn again takes its outlet along withmove()rather than a remove and recreate.holdFileFocusdrops its outlet loop, which only existed because a re-render could take away the outlet the user was standing in.restoreFab's hold stays, because it covers a different case: the reset hides the bar before moving it.module-authoring.md("Widget-local Thread placement") documentsonCommitand the rule that a widget removes an outlet only at commit.Lines: hand-written source +134 / −67 (surfaces.js +19/−2, lf-diff.js +115/−65). Tests: +30 / −21.
Test.
test_a_comment_being_written_on_a_diff_line_stays_in_hand_across_a_new_patchnow asserts zero blurs and that the old line outlet is gone. It runs for two patches: one that changes another hunk, and one that changes the commented line. Both fail onmainwith one blur each. The first blurs inendThreadSurface; the second blurs inreplaceFileContent'ssetChildren.test_a_diff_refresh_keeps_a_selection_in_unchanged_linesgains anearlier-hunkcase. Without the gutter fix, the widget fails with "Pierre returned a diff line without its paired gutter row".Item 69: the file editor keeps its caret through a move
What changed. If the page moves an
lf-file-editorwhile the user is typing, the next key now lands at the caret. Two ways it can be moved: a container re-placing it withsetChildren, which the test drives, or a revision that reorders its section, which I have only read in the code. Both go throughmove(). Onmainit landed at the start of the file. The issue expected the view and buffer to be destroyed on disconnect. They are not:whileConnectedfollows the arrival batch, so a move inside one batch is not a departure, and the view, buffer and focus all survive. The real loss was the caret.moveBeforecollapses the native selection inside the CodeMirror view, and CodeMirror reads that back as a caret at offset 0. That is the same failure #2545 fixed forleaf-text.lf-file-editornow definesconnectedMoveCallback, which puts each view's recorded selection back (createEditor().placeSelection()). This is the rule module-authoring.md already states for any element holding aLeafEditorView. A generic fix insidemove()can't coverleaf-text, whose selection is in a closed shadow root, so the forward stays with each host. There are two hosts.Lines: hand-written source +17 / −0. Tests: +39 / −0.
Test.
test_file_editor_keeps_the_user_typing_through_a_moveusessetChildrento move the editor past an empty sibling while the caret is mid-word, then types. The sibling is empty so that nothing on screen moves. Without the callback, the text lands at the start of the file. With it, the test passes.Checks
These all pass:
pnpm run test:runtime; the diff and seat selections oftest_render_threads.py;test_render_diff_controls.py; the diff-outlet tests intest_render_anchors.py,test_render_read_state.pyandtest_render_widgets.py; the diff, composer and comment-box selections oftest_render_widgets.py,test_render_drafts.py,test_thread_response_continuity.pyandtest_response_pointer.py;test_render_files.py; and eslint and prettier on the changed files.