Skip to content

Declare a code block's Copy through the keyboard register - #2558

Merged
max-sixty merged 3 commits into
mainfrom
agent-a05d3b92eb199cc93
Oct 12, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-a05d3b92eb199cc93

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A document code block answered Enter through its own keydown listener and wrote aria-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 offered esc, 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)

  • Behaviour. Enter on a focused code block now copies it in one press. The block carries a code.copy row, projected onto the <pre> with projectCommandScope beside any scope its owner declares, so the bar shows "⏎ copy code", the reference lists it under "On a code block", and aria-keyshortcuts is 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.
  • New register option. Element scopes take at (whether the user stands in the scope), which page scopes already had and declaredScope silently 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.
  • Removed. The hand-written aria-keyshortcuts write and removal, the Enter keydown listener, and the routes bookkeeping. The keydown census in test_interact_layer.py drops code-copy.js to 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-keyshortcuts outside the register (keyboard/scopes.js and keyboard/control-keys.js project 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/selection keyup tracking in drafts.js and composing/surface.js, PhotoSwipe's arrow gate in media.js, and lf-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 nativeClaimAt claims only text entry, radio and slider keys. Today only this scope sits over authored content (the others attach to exact controls), and at covers 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 on main and 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. All code_copy browser cases, the keydown census, the borrowed-scroll-stop cases, the reference and bar cases in test_render_controls.py, and npm run test:runtime pass.

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

max-sixty and others added 3 commits October 12, 2026 01:41
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]>
@max-sixty
max-sixty merged commit 2de049f into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a05d3b92eb199cc93 branch October 12, 2026 09:04
@max-sixty

Copy link
Copy Markdown
Owner Author

@leaf-agent is it standard to have enter copy here?

@leaf-agent

Copy link
Copy Markdown
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 aria-keyshortcuts disclose it, but they do not make it a familiar convention. I would favor a keyboard-reachable Copy button if we revisit this interaction.

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]>
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