Skip to content

fix(viewer): Enter and Space press the focused control, and a redraw keeps focus - #34

Merged
jackulau merged 2 commits into
mainfrom
fix/viewer-keyboard-focus
Nov 12, 2026
Merged

jackulau merged 2 commits into
mainfrom
fix/viewer-keyboard-focus

Conversation

@jackulau

Copy link
Copy Markdown
Owner

What

In the viewer, a page or list shortcut no longer takes a key the focused control uses itself, and a redraw no longer drops keyboard focus onto the page body.

  • Enter and Space. Enter on a focused button, filter chip, link or summary presses it, and so does Space on a button. Before, Enter on a filter chip opened the selected session, Enter on a button inside an open case row folded the row, and Space on a replay button started Play.
  • Scroll keys. ↑ ↓ PageUp PageDown Home End scroll the step detail when it has focus and more to scroll. j and k still move between steps from there.
  • Focus after a redraw. When a redraw removes the focused control, focus goes to the control now in its place (a rebuilt chip, speed button or Explore control), else to its pane or the page. A page change focuses the page. A "show more" button that removes itself hands focus on the same way.

Behaviour change to know about

Clicking inside the step detail focuses it, so ↓ after a click there now scrolls the detail instead of moving to the next step (j still does). To undo only this, drop the SCROLL_KEYS branch in ownKey().

How

  • ownKey(e) in index.html is the one rule: the global key handler and each list's Enter/Space handler ask it first.
  • swap() now runs through keepFocus(root, redraw), so every redraw that goes through the page's one DOM helper keeps focus. Three direct replaceWith/remove sites use it too.

Tests

test/viewer/keyboard-browser.test.ts: eight tests with real key presses (Input.dispatchKeyEvent, new page.press() in the test driver). The existing tests dispatch KeyboardEvents from the page, which never run a key's default action, so they could not see these bugs. Each new test fails without its part of the fix.

  • Viewer and docs tests: 277 pass. Typecheck, npm run build and npm run lint pass.
  • Full npm run check on a Mac (run before the list-row fix and the docs rewording): 6257 tests, 6244 pass, 11 skipped, 2 fail. The two failures (test/capture/hook.test.ts "concurrent hooks ... never interleave" and test/cli/rebuild-redactions.test.ts) fail the same way on an untouched origin/main in the same shell; cause not found, and this change does not touch that code.
  • coding.sh doctor on a live install: not run (no adapter change).

…keeps focus

A page or list shortcut no longer takes a key the focused element uses itself:
Enter on a button, link or summary, Space on a button, and the scroll keys in a
step detail that has more to scroll. Before, Enter on a filter chip opened the
selected session, Enter on a button inside an open row folded the row, and Space
on a replay button started Play.

A redraw that removes the focused control moves focus to the control now in its
place, else to its pane or the page, instead of leaving it on the body.
@jackulau
jackulau merged commit c3ee63b into main Nov 12, 2026
28 checks passed
@jackulau
jackulau deleted the fix/viewer-keyboard-focus branch November 12, 2026 23:19
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.

1 participant