Skip to content

Host core: one Space shortcut, roving choice and play button for every UI - #113

Merged
agorischek merged 2 commits into
mainfrom
headless-keys
Nov 21, 2026
Merged

agorischek merged 2 commits into
mainfrom
headless-keys

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Stacked on #112 (the headless view model). Third item of the headless-host plan, G5 ("keyboard and button behaviour").

Why

Each UI had its own copy of three behaviours, and the copies disagreed:

Behaviour Copies How they differed
Space plays and pauses ui/playback.tsx (spaceTogglesPlayback), vscode-ui/src/playback.tsx (handlePlaybackKey), Primer blocks.tsx Different lists of elements that keep Space. Only the default UI ignored held repeats and let a dialog around the view through. Only the VS Code UI ignored keys from portaled overlays.
The play button's name playLabel, playButtonState (VS Code, and verbatim in Primer) Checked reduced motion and playing in different orders.
Arrows, Home and End in radio groups and tabs the default UI's ViewSwitch, VS Code's scope switch and mode switch, and Primer Copy-pasted.

What's in the core now

These are framework-free and take any keydown event:

  • handlePlaybackShortcut(event, projection, keeps?) and isPlaybackShortcut(event, keeps?). The rules, which combine all three copies:
    • Space without modifiers, not yet handled;
    • from the listener, or from an element in it that doesn't keep Space (spaceKeeping, plus keeps for a design system's custom elements);
    • an element that keeps Space but encloses the listener (a dialog around the view) doesn't count;
    • a key from outside the listener (a portaled overlay) is never the shortcut;
    • one toggle per press.
  • rovingIndex(key, index, count, orientation?): wraps; horizontal or vertical keeps to one axis.
  • playButton(projection, beforeLabel, afterLabel) → {action: 'pause' | 'play' | 'show', direction, label}. The icon stays the UI's.

The existing public names keep working and now use these:

  • spaceTogglesPlayback and playLabel (default UI);
  • handlePlaybackKey and playButtonState (VS Code UI, which passes VSCode Elements' tags as keeps).

Behaviour changes

  • VS Code UI: a held Space no longer toggles repeatedly, and a dialog around the view no longer swallows the shortcut.
  • Default UI: a Space from an overlay portaled out of the toolbar is no longer the shortcut. Its overlays were Space-keeping menus and dialogs anyway.

Docs and tests

  • docs/guides/host-core.md (the view model section) documents playButton and the keyboard helpers.
  • packages/host/core/test/keyboard.test.mjs (node:test, with a small DOM stand-in) covers:
    • the shortcut and its modifiers;
    • Space-keeping elements, an enclosing dialog and portaled keys;
    • rovingIndex axes, wrapping and other keys;
    • playButton.
  • The existing browser specs cover Space in the toolbar and stage, and arrow keys in the switches. They run in CI.

Run locally:

  • tools check --fast: pass.
  • node --test test/keyboard.test.mjs test/view-model.test.mjs: 12/12.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests never call handlePlaybackShortcut, leaving held-Space toggle suppression and default-prevention behavior for accepted and rejected events unverified.

1 open issue
What changed in this PR

Builds on the headless view model by centralizing keyboard navigation and play-button behavior in host core, reducing duplication between the default and VS Code UIs.

Changes:

  • Adds shared Space-shortcut, roving-navigation, and play-button helpers while preserving existing public wrappers.
  • Aligns shortcut handling for held keys, enclosing dialogs, and portaled overlays.
  • Documents the helpers and adds unit tests for shortcut eligibility, navigation, and button state.
File Description
packages/​host/​vscode-ui/​src/​view-controls.tsx Uses shared roving navigation for the mode switch.
packages/​host/​vscode-ui/​src/​scope-switch.tsx Uses shared roving navigation for scope choices.
packages/​host/​vscode-ui/​src/​playback.tsx Delegates playback behavior to core with custom-element exclusions.
packages/​host/​core/​test/​keyboard.test.mjs Adds shortcut, navigation, and play-button tests.
packages/​host/​core/​src/​view-model.ts Defines shared play-button action, direction, and label.
packages/​host/​core/​src/​ui/​view-controls.tsx Uses shared horizontal navigation for view tabs.
packages/​host/​core/​src/​ui/​playback.tsx Preserves public wrappers around shared playback helpers.
packages/​host/​core/​src/​keyboard.ts Implements framework-free shortcut and navigation helpers.
packages/​host/​core/​src/​index.ts Exports the new helpers and types.
docs/​guides/​host-core.md Documents shared keyboard and play-button behavior.

Review effort: Balanced

Comment thread packages/host/core/src/keyboard.ts Resolved
@agorischek
agorischek force-pushed the headless-keys branch 2 times, most recently from 1378b59 to cd6a8c1 Compare November 21, 2026 15:19
@agorischek
agorischek force-pushed the headless-view-model branch 2 times, most recently from 415c5f4 to fcdeef9 Compare November 21, 2026 17:39
Base automatically changed from headless-view-model to main November 21, 2026 19:02
agorischek and others added 2 commits November 21, 2026 11:07
…y UI

The default UI, the VS Code UI and Primer each had their own Space-to-play handler, with different lists of elements
that keep Space and different rules for held keys and enclosing dialogs, their own play-button naming, and three
copies of the arrow, Home and End rule for radio groups and tabs. The core now has them, framework-free:

- `handlePlaybackShortcut` and `isPlaybackShortcut`, with `spaceKeeping` and a `keeps` option for a design system's
  custom elements: one press, one toggle; a Space-keeping element that encloses the listener doesn't count; a key
  from a portaled overlay is never the shortcut;
- `rovingIndex(key, index, count, orientation?)`;
- `playButton(projection, beforeLabel, afterLabel)`: `{action, direction, label}`.

`spaceTogglesPlayback`, `playLabel`, `handlePlaybackKey` and `playButtonState` keep their names and use them.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit c264a89 into main Nov 21, 2026
46 checks passed
@agorischek
agorischek deleted the headless-keys branch November 21, 2026 19:46
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