fix(tui): restore Playbook menu after keyboard selection - #1289
Merged
Conversation
This was referenced Aug 19, 2026
Merged
edwin-zvs
added a commit
that referenced
this pull request
Aug 21, 2026
* fix(webui): let Tab focus the Playbook selection menu
Selecting text in the web Playbook editor pops up the selection action
menu, but the editor's keydown handler gave Tab exactly one job: insert an
indent. With a selection live, `document.execCommand("insertText")`
*replaces* it — so Tab both failed to reach the menu and destroyed the very
text the menu was offering to act on.
The TUI has settled this contract over #1240/#1285/#1286/#1289 and spec 0196
records it. This mirrors that end state rather than inventing a web one:
- Bare Tab moves focus into a visible menu; the document is untouched.
- Once focused, Tab/S-Tab and the arrows walk the rows, Enter runs the
focused one (Shift: in a fork), C-g cancels selection and menu together.
- Escape peels the menu off but keeps the selection, so the next Tab reaches
the editor and nests every list line the selection spans (S-Tab un-nests).
A second Escape then cancels the region — two stages, as in the TUI.
- C-o still focuses the menu, and can reopen one Escape dismissed.
Menu focus is real focus: the rows are `role="menuitem"` buttons that the
browser reports as `document.activeElement`, not a painted highlight. Two
details the round trip needs — the editor's `blur` handler disarms the mark,
and a blurred contenteditable does not reliably keep a readable Range — so
both are parked on focus and restored when focus comes back, leaving the
region extendable and Escape's second stage with something to cancel.
Tab with no selection still inserts a tab stop, and nothing outside the
Playbook editor changes.
Spec 0196 previously scoped itself to the TUI and listed web menu focus as a
non-goal; it now states the contract for any client that shows the menu.
Verified against a real Chrome over CDP with trusted key events, for both a
pointer drag and a C-Space region. The new web_smoke coverage asserts
`activeElement` moves into the menu and `playbookSerialize()` is unchanged;
reverting the Tab branch fails it with `text: "- item"` — the original bug.
* chore: temporary PR screenshots (removed in the next commit)
* chore: remove temporary PR screenshots
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.
Summary\n\n- preserve the pending Playbook selection menu between a zero-width C-Space mark and the movement key that makes the selection non-empty\n- add a TestBackend regression through top-level terminal key ingress and rendered frames\n- interleave real renders through the existing mouse Down, Drag, and Up regression\n- retain Tab focus, two-layer Escape, and the no-ghost rule when selection_menu is absent\n\n## Root cause\n\nThe selection-menu key handler runs before editor movement. C-Space created a zero-width mark with a pending menu, but the following movement key saw no non-empty range and cleared the menu before extending the mark. The renderer then correctly honored selection_menu == None, leaving visibly selected text with no action menu.\n\nMouse drag does not pass through that intermediate key-handler transition, so the archived mouse test remained green.\n\n## Web parity\n\nThe web Playbook derives selection from the browser DOM and only shows its menu for a non-collapsed DOM range. It has no analogous pending zero-width mark/menu state, so no web change is needed.\n\n## Verification\n\n- cargo test -p construct-cli --bin construct playbook: 356 passed\n- cargo test -p construct-e2e --test playbook_view: 8 passed\n- cargo build: passed\n- git diff --check: passed\n- full CLI suite: 1,442 passed; only the known environment-sensitive color::tests::truecolor_backend_still_emits_rgb baseline failed, matching PRs #1285 and #1286\n\nNo spec update: spec 0196 already requires a passive menu for a non-empty selection, Tab focus, two-stage Escape, and no ghost menu after dismissal.\n\nReviewer media is omitted because the frame-level regressions directly verify the transient passive, focused, dismissed, and mouse-drag frames.