Repository navigation
Keep keys typed into Leaf's fields from bubbling to the page - #5037
Merged
Merged
Conversation
A page script listening for keydown on the document hears every key typed into a Leaf comment: page shortcut code skips keys typed into an input, a textarea or an editable element, and the focused element is the leaf-text host, which is none of those. A reveal.js deck blacks out on a typed `b`. The test listens on the document, the window and `main`, types into the comment box (in Leaf's chrome) and the draft's editor (inside `main`), and fails while the page hears those keys. Its controls: a key pressed on the page reaches the page, Enter sends the comment and Escape closes the editor. Part of #5023. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A page script listening for keydown on the document heard every key typed into a Leaf comment, so a reveal.js deck blacked out on a typed `b`. Page shortcut code skips keys typed into a text field by asking whether the focused element is an input, a textarea or editable, and from outside the field's closed shadow root the focused element is the `leaf-text` host, which is none of those. The host now stops each keydown, keypress and keyup as it bubbles out of the field, after CodeMirror inside it has handled the key. Leaf's key dispatcher, whose pass after a control's own handling ran on the document, reads a field's keys at the host instead (`readLeavingKeys`), so Enter, Escape and Tab from a field behave as before. The two other Leaf readers of these keys move to capture: the draft editor's caret keeper (keyup) and the ⌥ aim (keydown, keyup). Every listener outside the field, on `main`, the document or the window, no longer hears the key bubble; a key pressed anywhere else reaches the page as before. Rejected: the host answering `isContentEditable`, which reveal.js asks of the focused element but a check by tag or selector never does, and which leaves a page that checks nothing hearing every typed key. page-behavior.md tells page authors that keys typed into a Leaf comment box or draft editor don't reach their listeners; keyboard/AGENTS.md states the capture rule for Leaf's own readers. Closes #5023. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
reviewed
Nov 2, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
Keep the shared keyboard guarantee in maintainer guidance and the host-handling mechanism in its owning module.
Comment on lines
+32
to
+34
| typed into a `leaf-text` stops at its host once the editor and the dispatcher have read | ||
| it there (`composing/text-field.js`), so the page never hears it bubble, and any other | ||
| Leaf listener that needs keys typed into a field listens in capture. |
Collaborator
There was a problem hiding this comment.
The host/editor/dispatcher sequence duplicates the implementation contract already in composing/text-field.js. The repository’s running-tend review rule asks maintainer guidance to state what other code relies on. Keep the propagation guarantee and capture requirement here:
Suggested change
| typed into a `leaf-text` stops at its host once the editor and the dispatcher have read | |
| it there (`composing/text-field.js`), so the page never hears it bubble, and any other | |
| Leaf listener that needs keys typed into a field listens in capture. | |
| typed into a Leaf field never bubbles to the page. Any other | |
| Leaf listener that needs keys typed into a field listens in capture. |
Leaf's page search, Page Map search and command reference search are `searchField`s, `wa-input` elements whose native input sits in a shadow root, so a page's shortcut check by tag or by `isContentEditable` saw a `WA-INPUT` host and acted on every key typed there. The panel's Threads and menu search is a native input, which a page's checks recognize but which the page's author never wrote a check for. The stop-and-read moves from text-field.js into field-keys.js, a dependency-free module exporting `keepFieldKeys(host)` and `readLeavingKeys`. `LeafText`'s constructor, `searchField()` and the panel's search input call `keepFieldKeys`; the key dispatcher reads from the same module. Package widgets that build a `searchField`, such as lf-diff's file filter, keep their keys the same way. The browser test, renamed to say the keys never bubble to the page (a page listener in capture still hears them), adds a `/` page-search step: type, then Escape closes the search. Without the `searchField` stop it fails with "the page heard keys typed into the page search". page-behavior.md now names comment box, draft editor or search box. Part of #5023. Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty
marked this pull request as ready for review
November 2, 2026 05:22
# Conflicts: # dist/kernel/kernel.json # dist/kernel/leaf.js # dist/kernel/runtime/bundle-portable.js
leaf-agent
added a commit
that referenced
this pull request
Nov 4, 2026
…d state answers and deferred fault reports (#5334) Every test in #5070 fails on main because three merged changes moved contracts these tests still read the old way. Each repair updates only the test, to the behavior its change intended. None moves product behavior. - **Control+Alt+r never pressed Latest (14 tests, plus the journey in #5070's comment).** The test page's script listens for Control+Alt+r on `window` and clicks the panel's Latest row notice. #5037 stops keys typed into a Leaf field at the field so a page's bubble listeners never hear them; its contract (`field-keys.js`) keeps capture listeners hearing them. With an editor focused, the hook never ran, the revision stayed deferred behind the composition, and `wait_for_revision(page, 2)` timed out. The hook now listens in capture. Bisect: the composer case passes at `1c38e1070` and times out at `8a4e213d0` (#5037). - **`test_a_mechanical_revision_failure_leaves_accepted_publication_ready`.** It began as `StopIteration`, from the same missing press. With the press fixed, it raised `KeyError: 'reading'`, because #5307 answers a tab that names its held reading with a patch. The test now reads the new reading's name from the patch's `["reading"]` change. - **`test_a_fresh_revision_caret_failure_does_not_strand_deferred_arrivals`.** This one had a separate cause and was failing before #5037 with `assert ([])`. Bisecting over `7c1e4494ac..9a142d1` points to #4966, which reports a fault in the next task. The test took the errors as soon as the revision installed, so it now waits for the report with `reported_browser_errors`. Verification: all 16 tests listed in #5070 and `tests/journeys/test_render_drafts.py::test_executable_revision_does_not_restore_a_new_draft_generation` pass locally on this head (29 passed across `test_revisions.py` and the two named tests). Before the change, the composer case failed on main after its 120 s timeout. Closes #5070 — automated triage Co-authored-by: leaf-agent <[email protected]>
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.
Keys typed into a Leaf comment box, draft editor or search box no longer bubble to the page's own keyboard listeners. On a reveal.js deck served by Leaf, typing
binto a comment blacked the deck out. Page shortcut code skips a key typed into a text field by asking whether the focused element is an input, a textarea or editable. Leaf's comment box (leaf-text) and its search boxes (wa-input) hide their editors in shadow roots, so the page sees only a host that is none of those.What changed
field-keys.js, new and dependency-free).keepFieldKeys(host)stops each keydown, keypress and keyup at the field's host as it bubbles out, after the field's own handling has run. No listener outside the field (onmain, the document or the window) hears it bubble. A field'sinputevents still reach the page, as a textarea's do.LeafText's constructor covers the comment box, reply box, panel field, draft editor and option field.searchField()covers page search, Page Map search, command reference search and a package widget's search, such as lf-diff's file filter. The panel's native Threads and menu search calls it too.keyboard/controller.js). Its pass after a control's own handling ran on the document; for a key from a field it now runs at the host, throughreadLeavingKeysin the same module. Enter, Escape and Tab from a field keep their meanings and their order after the field's own handling. Printed characters still go through the dispatcher's capture pass on the document, as before.drafts.js, keyup) and the ⌥ aim (composing/aim.js, keydown and keyup) listened in bubble on the document or window, and now listen in capture.page-behavior.mdtells page authors that keys typed into a Leaf comment box, draft editor or search box never bubble to their listeners.keyboard/AGENTS.mdstates the capture rule for Leaf's own readers.A key pressed anywhere else, the page itself included, reaches the page as before.
Rejected: the field answering
isContentEditable. reveal.js asks that of the focused element, but a check by tag or selector never does, and a page that checks nothing would still hear every typed key.Evidence
The issue's repro through
leaf-dev probe: a page script logging keydown, keypress and keyup on the document and window, plus reveal.js's own filter (document.activeElement.isContentEditableor an input/textarea tag); select a word, pressc, typeband ArrowLeft.keydown b,reveal b,window keydown b,keypress b,keyup b, and the same for ArrowLeft.b. Same result in Chromium, Firefox and WebKit.The new test,
tests/browser/drafts/test_keys.py::test_keys_typed_into_leaf_fields_never_bubble_to_the_page, listens onmain, the document and the window. It types into the comment box and the page search (both in Leaf's chrome) and the draft's editor (insidemain). It fails on the first commit of this PR, where the page hears 16 key events from the comment box. With only thesearchFieldstop reverted, it fails with "the page heard keys typed into the page search". It passes with the fix. Its controls: a key pressed on the page still reaches all three listeners, Enter sends the comment, and Escape closes the draft's editor and the page search.What I ran
uv run pytest -n 4overtests/browser/drafts/test_keys.pyand selections fromdrafts/test_composer.py(Return, a single space, Resume writing, line keys, Markdown source),navigation/test_key_scopes.py(text boxes, unsent words, Escape steps),test_render_aim.py(⌥ aim with a composer open),threads/test_composing.py(Escape from a box, Enter send, input method composition) andtest_render_reactions.py(Tab opens the picker): 41 passed, 1 failed.-k searchtest intest_render_semantic_selection.py,test_render_floating_panel.py,navigation/test_command_reference.py,threads/test_summaries.pyandmargin/test_page_map.py, plustest_keys.pyand the composing selection: 45 passed, 1 failed.test_a_text_box_keeps_its_keys_from_the_widget_around_ituses a native textarea this change doesn't touch, and fails the same way on this PR's first commit, without the fix.test_the_reference_keeps_local_search_state_on_one_lit_surfacewaits for athread.resolution.togglerow the reference doesn't list, and fails onmaintoo.pnpm run test:runtime: 737 passed.pnpm run check:browser: the committed kernel matches a fresh build.abcdand two ArrowLefts in a comment box, the kept writing place reads[2, 2]before and after the change.Not verified
Input.imeSetComposition) sends no keydown; the composition test above passed. The dispatcher already ignores composing keydowns.searchField; it filters oninputevents, which still pass.Closes #5023