Skip to content

Keep letters typed through a reload Leaf asks for, whatever ends the wait - #7090

Merged
max-sixty merged 12 commits into
mainfrom
entry-state
Nov 25, 2026
Merged

max-sixty merged 12 commits into
mainfrom
entry-state

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

When Leaf reloads a page while the user is writing, as for a new revision or a restarted server, the letters typed before it puts them back were dropped if they scrolled, clicked, pressed a key that prints nothing or stepped Back first, or if the page failed to start. SOUL.md promises to drop typed words only when the user no longer wants them. Now each letter goes into its box as it is typed:

  • In a reply or comment, it goes into the draft. The panel shows the letters as "kept in the draft", and the box comes back holding them with the caret after them. If the box doesn't come back, the panel says "Draft kept" with Resume writing. Attached pictures stay attached.
  • In a text field of the page's own, it goes into the field's value, and the page hears it as input. A password never reaches the draft store. A date, time or number field, which has no caret to type at, takes the key once the user is back, as before.
  • After the user moves on, keys they press are page keys again.

For the caret to land after the letters, focus on a control of the page's own and its caret now have one owner on arrival, the reload's handoff, rather than the handoff and then the entry's record. The record still returns the page's selection, and still lands at the reading place where the revision dropped the control (history.js header).

Still open: no leave prompt before Leaf's modules load; a number field's digits are dropped if the user scrolls first, as before; a page field's letters when the page opens at a new history entry; editable areas and fields a widget generates.

The maintainer asked for this as the follow-up to #6860; an independent agent reviewed it over four rounds. Tests: a case in test_readiness.py for each route, in Chromium and Firefox, each failing before the change, plus ones that hold main's behaviour for the page's selection, the landing at the reading place and fields with no caret; the focused selections, pnpm run test:runtime and pnpm run check pass.

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

…eply returns

While a reload Leaf asks for puts the user back in a reply they were writing,
the letters they type are held until the place is back. Every way the hold
ended before then dropped them: a scroll, a press, a key that prints nothing,
a step Back, a page that could not start, a runtime that gave the document up.
None of those says the user no longer wants the words (SOUL.md, "Preserve the
user's attention and work").

The hold now knows that a run typed through the reload is the user's writing
for the box it hands back (bootstrap.js, `writing`), and letting go of such a
run keeps its words in the tab rather than dropping them:

- Where the document goes on, its runtime types them into the box's draft at
  the caret the reload recorded (drafts.js, `takeHeldWords`), and Resume
  writing goes to their end.
- Where the document gives the run up (a startup fault, or the runtime giving
  the document up), the document that replaces it leads its run with them when
  it puts the user back, so they are typed into the box with the caret after
  them, and puts them in the draft otherwise. Typing them into the draft
  before the place came back left the caret in front of them.

The keyboard owner types such a run only into a box and releases it to the
draft otherwise, so in Firefox, where a step Back leaves the run held, its
letters no longer run as single-key commands at the entry the step reached.

Tests: new cases for a scroll, a press, Backspace and Enter (Chromium, with
scroll and Backspace in Firefox), a step Back (both engines) and a page that
can't start. Each failed on the previous code, the draft holding only what was
typed before the reload. `test_a_key_let_go_during_an_arrival_stays_gone_...`
becomes `..._reaches_the_reply_once_...`: Escape now puts the held key in the
reply's draft once rather than dropping it. `reload_with_its_answers_held`
answers requests made after its release rather than holding them forever,
which stranded any draft write made then.
…e opens anew

A document that goes while it holds words typed through a reload, without
letting go of them, leaves its run in the tab for the document that puts the
user back. A document that puts the user back nowhere, as when the user leaves
the page and opens it again at an entry of its own, discarded that run as it
discards any page keys, losing the words (SOUL.md, "Leaf drops words the user
typed only when it knows they no longer want them").

The stored run now says whether it is writing and names its box, the handoff's
`draftEditing`. A document that doesn't put the user back hands such a run's
words to the runtime, which types them into that box's draft. Since the words
can now reach a document whose handoff names nothing, every kept batch of
words carries its box, and drafts.js reads the box from the batch rather than
from the handoff.

Test: `test_words_typed_through_a_reload_reach_the_reply_when_the_page_opens_anew`
leaves the page while the reload's keys are held and opens it again; it failed
before this change with the reply's draft reading only "Hold".
When the user moves on before a reload has put them back in their reply, the
keys they typed through it leave the panel's field, where they stood as
badges, and go into the reply's draft. Nothing said where they went, so the
user saw their letters disappear. `noticeDraftKept()` is what a box that stops
showing the user's words says, with Resume writing, so `takeHeldWords` now
says it once it has typed the words into their draft.

Test: `test_words_typed_through_a_reload_stay_in_the_reply_when_the_user_moves_on`
asserts the panel says "Draft kept" after the input that ends the hold; before
this change it said only "Lost the connection — reconnecting · Comment… c".
The test already checks that Resume writing lands at the words' end.
Words the user types on as a reload Leaf asked for comes wait in the tab for
the reply the reload puts back, and no write carries them yet. Closing the tab
then lost them without a word, where drafts.js's leave prompt asks first over
any draft no write carries (SOUL.md, "Leaf drops words the user typed only
when it knows they no longer want them").

That prompt is the one rule for such words, and the one reader of whether an
unload is Leaf's own reload (`takeLeafUnload`). So it now also asks the
bootstrap, through `lf-held-writing`, whether the hold keeps words of the
user's: a run of writing, or words let go for their box and not yet typed in.
A reload Leaf asks for still asks nothing, and the words follow it.

The prompt stands only once the runtime's modules have run. Before then, and
on a page whose modules never load, closing the tab still loses held words:
the bootstrap can't tell a reload Leaf asks for from a close without a second
reader of `takeLeafUnload`.

Test: `test_leaving_with_words_typed_through_a_reload_still_held_asks_first`
reloads the tab while the keys are held; before this change no prompt came
(the dialogs it saw were []). After accepting the prompt, the reload puts the
user back in the reply with the words typed there.
…ser moves on

Review of 309b9ee found four ways the words typed through a reload went
astray, each now a failing test first:

- Keys typed after a scroll ended the return were read as more of the reply,
  since `typingBack()` asked only whether the reload places the user: "jjk"
  after a scroll went into the reply's draft. The hold now notes the input that
  ends the hand-back (`counted`), and keys after it are the page's again. In
  Firefox, keys typed at the entry a Back reached joined the held run of
  writing; a key typed once the writing is no longer the user's now lets that
  run go and starts its own.
- Words typed for a field of the page's own went into the page's draft, a
  password's characters included, which then reached the server's draft store
  and showed in the panel. A run of writing now knows its box, a draft's
  editor or the page field the carry record focuses; letting go of a field's
  run types its words into the field and the value the reload carries for it,
  and nothing leaves the document. The success path still replays the run
  into the field, since the entry's record puts the caret back after the carry
  does and would leave it in front of words typed in ahead.
- Words for a reply holding a picture were spliced in after the picture's
  Markdown, which then no longer read as attached. `takeHeldWords` now splits
  the draft with `readAttachedMedia` and puts the words among its words.
- A document that gave up the hold but went on (a page's own fault, an
  uncaught error before upgrade, a runtime waiting on another layer) left the
  words in the tab for a load that might never come. Letting go always tells
  the runtime now, and drafts.js moves the reload's own record of the box with
  the words it types in (`draftEditing`'s words, caret and attempt), so a
  reload that does put the user back lands the caret after them. That makes
  leading the next document's run with left words unnecessary, and the code
  for it, the `tell` flag and the switch of `letHeldKeysGo` to `pause` go.
  A document served without drafts, as a release's is, now waits for its
  first reading before typing the words in, rather than starting the draft
  over and having the server's words joined to them as another tab's.

`takeHeldWords` decides where the caret was by `draftEditingStands`, as the
reload's restore does, rather than by comparing words, and has no page-draft
fallback left, since every batch it takes names a draft.

The rule that held writing goes into its box now has one home, the comment on
`letGo`; the other mentions point there.

Tests: `test_keys_typed_once_the_user_moves_on_are_the_pages_again`,
`..._for_a_field_of_the_page_stay_in_it` (text, password, put back),
`..._keep_the_replys_picture`, `..._whose_page_has_a_fault_reach_the_reply`,
`..._once_a_document_served_without_drafts_has_it`, and the step-Back test now
types "jj" after the step. On 1b4cad5 they failed with "Hold morejjk",
"Hold morejj" (Firefox), "ab" in the field, the picture's Markdown before
" more", "Hold" and "Hold\n\n more". `reload_with_its_answers_held`'s release
takes `presents=False` for a page that reported a fault of its own.
…d words

A re-review of 4d4c51f found:

- A page field across a failed start came back as "abcd" with the caret at 2,
  so typing went in the middle ("abecd"). The reload's handoff and the entry's
  record both hold a field's focus and caret, and the record's return ran last.
  The handoff's is the newer, since the key hold types the words into the
  value and caret it carries. On a reload that hands back a place where the
  handoff carries a field's focus, the record's return now leaves focus, caret
  and selection to it (history.js `returnTo`'s `returnsFocus`; version.js
  `landArrival`). The history.js header says which of the two owns what.
- Words let go into a page field set its value without an input event, so the
  page's own listeners never heard them, where a replay through `insertText`
  does. `typeIntoField` now dispatches an `input` event. The clock doesn't
  count it as an input of the user's (`holds` takes any event, and the
  bootstrap holds its own `echo`); otherwise it ended the return and
  recursed through `counted`. `stopHoldingKeys` lets go before it detaches the
  hold for the same reason.
- "Draft kept" showed after a failed start, while the recovery put the user
  back in the reply. Each batch now records whether the return of the user's
  place had ended when it was let go, and drafts.js says the draft is kept
  only for such words.

Batches now name their draft by its context alone, and drafts.js takes the
caret from the reload's own `draftEditing` where it names that draft, so the
bootstrap no longer copies `draftEditing` into the tab. The version.js and
prepaint.js headers now say that the key hold and the drafts write into the
handoff after it is read.

`letGo`'s comment no longer claims every held word ends up there, and
`writes`'s no longer contradicts `queue`.

Tests: `..._for_a_field_of_the_page_stay_in_it[cannot-start]` (failed with
"abecd"), `test_words_let_go_into_a_field_of_the_page_are_its_input` (the
page's listener never heard "abcd"), and the reply's failed-start test now
asserts the panel never said "Draft kept" (it did). The field test's put-back
variant also checks the page heard the replay.
Until now a key typed while a reload Leaf asked for was putting the user back
in a box was held as a run, replayed into the box if the return succeeded, and
otherwise let go into the box's draft or field. That made the run's meaning a
question asked when it was replayed, and every way of ending it needed its own
route: a `writing` flag on the run and on the take, a check in the keyboard
owner, a check in `queue` for Firefox's steps, the box stored with the run in
the tab for a document that puts the user back nowhere, and a leave-prompt
question for words still held.

Now a key typed during the hand-back is a word for its box at once
(bootstrap.js, `typeBack`): a field of the page's own takes it into its
carried value and caret and into the field, with an `input` event; a draft's
takes it through the tab, which drafts.js types in at once where it has
loaded and else as the page next loads, moving the reload's own record of the
box with it. The box comes back holding the words with the caret after them,
which 6803fd1 made possible for a field by giving its caret one owner. No
way of ending the hold leaves anything to route, so every piece above goes.
The hold still shows a draft's words as badges until the box comes back or
the return ends, and marks the kept words ended when it does, so the panel
then says "Draft kept"; so does a document that doesn't put the user back.
Words that are a draft at once fall under the drafts' own leave prompt, so
the bootstrap's `lf-held-writing` answer goes too.

Measured against 93ebc4d, runtime code +170/-35 here against +171/-32 for
6803fd1, comments +102/-31 against +108/-30.

Tests: `test_keys_still_held_as_another_reload_comes_follow_the_first_into_the_reply`
is deleted, since no words are replayed for a reload to interrupt.
`..._still_held_asks_first` becomes
`test_a_reload_the_user_asks_for_keeps_words_typed_through_another`: the words
are the reply's draft at once, so no prompt is owed while a write carries
them, and the user's reload puts them back in the reply. The field tests see
the words in the field as they are typed rather than as held-key badges, and
two docstrings say the words go in as typed.
"Draft kept" was decided by which input ended the return: the hold marked the
kept words ended when the clock counted an input. A Firefox step Back isn't
counted (Gecko bug 1903552), so there the words went into the draft with no
notice, where Chromium gave one; a hand-back that completed without landing
in the box was the same gap. Now, when the hand-back is over and the runtime
takes the hold, the bootstrap asks drafts.js whether the draft's words are on
screen in their box (`shownIn`, now shared with `keepRefusedWords`), and the
panel says the draft is kept where they aren't. Words from a document that
doesn't put the user back still get the notice as they are taken. The
per-batch `ended` flag and the "ended" event go.

The badges for words typed through a reload said they "run when the page is
ready", though the words are in the draft already. They now say "kept in the
draft"; keys still held for the page keep their old words.

Which carried record holds the focus the handoff puts back was read twice,
by version.js (`focus && caret`) and the bootstrap (`focus && part ===
undefined`). prepaint.js now reads it once (`handedFocus`) and both use that,
so the bootstrap no longer reads the handoff's carry records.

Comments: history.js now says the record and the handoff both hold where the
user was writing, and that a draft's caret is the handoff's by call order;
`returnTo` says `returnsFocus` false also skips the selection and the landing
at the reading place; the `holds` comment no longer says every held key waits
for a replay; prepaint.js's sentence on edits to the handoff is rewritten; and
version.js's long sentence on the type-time exception is split.

Tests: the step-Back test now asserts the panel says "Draft kept"; in Firefox
it failed before this change. The move-on tests check the badges say "kept
in the draft" and look for the notice once the page has answered, and the
hand-back tests assert no notice where the words land in the box.
… caret

6803fd1 left focus on a control of the page's own to the reload's
handoff, and `returnTo` then returned before restoring the record's
selection. `handedFocus` names any carried control with focus, a checkbox
included, which holds no caret. So a passage selected on the page with focus
on a checkbox came back after a reload Leaf asked for without the selection,
where main returned it. Now `returnTo` takes focus to stand where the handoff
put it and runs its existing rule: a caret is the field's whole selection, so
the return stops there; otherwise it returns the record's selection.

The history.js header now says why a draft's box stays the record's to
return to rather than the handoff's: the handoff's restore declines once
another tab has rewritten the draft, and the record's return, which doesn't
check the draft, still puts the user in the box, with the caret where the
record had it.

Test: `test_a_reload_returns_a_selection_beside_focus_on_a_control_of_the_page`
passes on 2f79281's runtime in Chromium and Firefox and failed on this
branch before this change in both.
…al wait

Where a reload Leaf asks for brings a revision that no longer has the page
control focus stood on, the handoff finds nothing to focus and focus stays on
the page's body. `returnTo` took that body as focus put back, so it skipped
the landing at the reading place, and Tab then went on from the page's top.
main returned focus through `focusByKey` with the predicate "not the body, and
presented", found nothing and landed. The handed focus now passes the same
predicate (`lands`), so a body or an undrawn element counts as no focus and
the return lands at the reading, as on main.

The selection test's `wait_for_function` named a literal 20 s deadline, which
`tests/model/test_suite_source.py` refuses; it now takes the suite's default.

Test: `test_a_reload_into_a_revision_without_the_focused_control_lands_at_the_reading`
focuses a checkbox, writes a revision without it whose script changed, so the
tab reloads into a fresh document, and presses Tab. It passes on
2f79281's runtime in Chromium and Firefox, and failed on 1eb82d5 in
both, with focus not reaching the link after the reading place.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One regression, in the field route; the suggestion below fixes it.

Comment thread browser/runtime/bootstrap.js Resolved
A key typed through a reload Leaf asked for into a focused date, time or
number field emptied it. Those fields carry no caret (focus.js `readCaret`
answers only for text, search, url, tel and password), so `typeIntoField`
appended the key after the whole value: a date became "2026-11-241", which
value sanitization reads as "", and the arrival's `restoreCarry` wrote that
back. main kept such a key waiting in the run, whose replay through
`insertText` leaves a date unchanged and lets Chromium's number field refuse
a letter.

A field of the page's own now takes the user's words at once only where it
holds a caret, which is what typing into it needs; any other field's keys
wait in the run and the field takes them as it takes any key once the reload
puts the user back, as on main. The fallback for a missing caret in
`typeIntoField` goes, with its guard around `setSelectionRange`, and the
prepaint.js and type comments on `handedFocus` say the hold types only where
there is a caret.

A number field's digits, like main's, still wait in the run and go if the
user scrolls before the reload puts them back: with no caret to type at,
Leaf can't place them.

Test: `test_a_key_typed_through_a_reload_leaves_a_field_with_no_caret_as_it_takes_it`
(date in Chromium and Firefox, number in Chromium) failed on 865fe82 with
the value emptied, and passes on 2f79281's runtime. Firefox's number field
takes a letter as it takes a typed one, so main empties it there too, and the
test leaves that variant out.
@max-sixty
max-sixty merged commit 6a4684d into main Nov 25, 2026
8 checks passed
@max-sixty
max-sixty deleted the entry-state branch November 25, 2026 00:15
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