Repository navigation
Declare a code block's Copy through the keyboard register - #2558
Merged
Merged
Conversation
A document code block answered Enter through its own keydown listener and wrote `aria-keyshortcuts="Enter"` by hand, so the shortcut bar and the command reference never named the press. Enter also only moved focus to the copy control; a second press copied. The block now carries a `code.copy` row, projected onto the pre beside any scope its owner declares, and Enter copies in one press. The bar shows "⏎ copy code" on the block, the reference lists it under "On a code block", and `aria-keyshortcuts` is derived from the row. The row answers only while the block itself holds focus, through a new `at` option on element scopes, so a link inside the code keeps its own Enter. Because focus stays on the block, each copy's result also takes the status line and the live region, as the banner's copy controls already do. Tests: the copy journey now checks the bar, the reference, the live region and the clipboard after Enter, on desktop and touch; the keydown listener census drops code-copy.js to its one Tab hand-back. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…reference The status-line notice no longer speaks, since the copy button's own log region already announces the result. The command reference now asks an element scope's at before reading its rows' liveness, as dispatch and the bar do. The nested-link case pins the bar's Follow on a link in code. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 12, 2026
Owner
Author
|
@leaf-agent is it standard to have enter copy here? |
Collaborator
|
No. Enter is the expected activation key when the Copy button has focus, but a focused code block is not itself a button. The usual keyboard route is to reach a Copy button with Tab and activate it with Enter or Space; Ctrl/Cmd+C copies selected text. WAI's keyboard guidance treats Ctrl/Cmd+C as the copy convention and shortcuts as additions to standard keyboard access. Here, Enter on the block is a Leaf-specific shortcut because the Copy control is kept out of the Tab order. The shortcut bar and |
max-sixty
added a commit
that referenced
this pull request
Oct 12, 2026
) In the keyboard register, native activation now belongs to the focused control the way text entry already did. A scope declared on a container could take Enter or Space from a link or button inside it: with a container scope binding Enter, Enter on a nested link ran the container's command and suppressed the browser's follow. #2558 hit this with the code block's Copy and worked around it with an `at` option on element scopes. That option is deleted here, since nothing else used it. ## What changed (Lit follow-up review, item 64) - **Behaviour.** `nativeActivationAt` (`keyboard/text-entry.js`) names the platform's activation press at the focused control: Enter on a link; Enter or Space on a button, a button-type input or a `<details>` summary; Space on a checkbox or radio button. Unmodified presses only. No scope around the control runs a different Leaf command on that press. A row that only names the press, with nothing of its own to run, still names it: a link's Follow, or the versions menu's "open that version". A mode that owns the keyboard (Go-to, reactions, Page Map) still stands nearer, as before. - **What speaks for the control.** The control's own exact element scope, a page scope rooted at the focused control (a page disclosure's toggle, a thread title's reply), and a row whose `control` is the focused element all keep the press. A contextual alias on the control yields, as it yields to native editing, so dispatch and `aria-keyshortcuts` agree. - **Plumbing.** `shadow().takes` now receives the row and its scope at every call site (dispatch, `lineOwner`, reference reachability, the shortcut bar's `lineRows`), so the bar never shows a row that the dispatcher would withhold. A container's Enter that activation took makes no claim further out, so "On a link" still names Follow inside a code block. - **Removed.** Element scopes' `at` option (`keyboard/scopes.js`), its reading in `command-reference.js`, and its use in `code-copy.js`. - **Choice.** A plain button gets no "press" hint on the bar. Its Enter and Space are the most universal press there is, and a hint would spend one of the compact bar's two slots on every focused page button. Links get Follow because Enter and Space differ on a link. The new test asserts that the bar names nothing for a plain button rather than the container's command. Hand-written source: +97 / −45 lines (`text-entry.js`, `dispatch.js`, `scopes.js`, `command-reference.js`, `shortcut-bar.js`, `page.js`, `touch-controls.js`, `code-copy.js`), most of it comments. Tests: +120 / −18. ## Tests - `tests/runtime/native-activation.test.mjs` fails on `main`: Enter on a link inside a container ran the container's command. It checks a container scope binding Enter and Space around a link, a button and a disclosure button: the dispatcher's answer, the preserved default, and the row the bar names. It also checks that a contextual Enter/Space alias on a button yields in both dispatch and `aria-keyshortcuts`. - `command-controls.test.mjs` used Enter as an incidental context alias on a button. It now uses a digit, the only kind any widget declares. - `test_each_sampled_focus_ring_is_shown_whole_in_its_surface` failed on `main` since #2558. Enter on a code block copies, and the copy control is out of the Tab sequence, so the sweep's sample of the copy control's ring is dropped. ## Checks - `npm run test:runtime` passes. - I ran every render test whose body presses Enter or Space (288 functions), plus the reference, bar and disclosure cases in `test_render_controls.py`. Two tests still fail, and neither comes from this change: - `test_primary_reader_revision_replaces_owner_without_losing_thread_draft` fails the same way on `main` ("The page already has a Thread presentation" from `dom-move.js`). - `test_code_copy_enter_leaves_nested_links_usable` passes alone but failed under suite load, on its count of visible copy controls at presentation, not on keys. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[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.
A document code block answered Enter through its own
keydownlistener and wrotearia-keyshortcuts="Enter"by hand, a second key owner beside the keyboard register. So the shortcut bar and the command reference never named the press: with focus on a code block, the bar offeredesc,c,s, … and no Enter, and none of the reference's 177 rows mentioned the block. Enter also only moved focus to the copy control; a second press copied.What changed (Lit follow-up review, item 58)
code.copyrow, projected onto the<pre>withprojectCommandScopebeside any scope its owner declares, so the bar shows "⏎ copy code", the reference lists it under "On a code block", andaria-keyshortcutsis derived from the row. Focus stays on the block, so each copy's result (mouse, touch or key) also takes the status line, as the banner's copy controls already do; Web Awesome's own log region announces it.at(whether the user stands in the scope), which page scopes already had anddeclaredScopesilently dropped. Dispatch and the bar already honoured it; the command reference now does too. The code block's row answers only while the block itself holds focus, so a link inside the code keeps its own Enter and the bar's "⏎ Follow". Without it, Enter on a nested link copied instead of following the link.aria-keyshortcutswrite and removal, the Enterkeydownlistener, and theroutesbookkeeping. The keydown census intest_interact_layer.pydropscode-copy.jsto its one Tab hand-back.Hand-written source: +45 / −35 lines (
code-copy.js,keyboard/scopes.js,keyboard/command-reference.js). Tests: +29 / −11.Sweep for other second owners
No other runtime or package code writes
aria-keyshortcutsoutside the register (keyboard/scopes.jsandkeyboard/control-keys.jsproject it). The remaining raw key listeners answer no command: the code copy control's Tab hand-back, the covering surface's Tab loop, the aim latch, the prepaint hold, caret/selectionkeyuptracking indrafts.jsandcomposing/surface.js, PhotoSwipe's arrow gate inmedia.js, andlf-trace's pause on native scroll keys.Left for later
Any ancestor element scope that binds Enter or Space would still take the key from a nested link or button, because
nativeClaimAtclaims only text entry, radio and slider keys. Today only this scope sits over authored content (the others attach to exact controls), andatcovers it. A register-level claim for native activation keys would also shadow the "On a link" Follow row, which would then need to become that claim's own row.Checks
The copy journey (
test_code_copy_keeps_source_and_stays_beside_scrolling_and_revised_blocks) fails onmainand now checks the bar, the reference, the status line and the clipboard after Enter on desktop and touch; the nested-link case checks the bar on a link inside code. Allcode_copybrowser cases, the keydown census, the borrowed-scroll-stop cases, the reference and bar cases intest_render_controls.py, andnpm run test:runtimepass.