Repository navigation
Fix app shortcuts and Escape in the chat input - #1166
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
cb614e2 to
6379e24
Compare
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
I am the SlopCop. I am now reviewing this change for security, quality, performance, architecture, and user behavior.
I will post the complete findings after the parallel checks finish.
| context ??= currentContext(event.target); | ||
| if (!matchesAppCommandContext(binding, context)) continue; | ||
| if (!dispatch(binding.command, event.target)) return; | ||
| if (!dispatch(binding.command, event.target)) return false; |
There was a problem hiding this comment.
🚨 slopcop/review — Prevent a second command dispatch after all handlers return false.
The editor calls dispatch here. If all handlers return false, this function leaves the event unconsumed.
The same event then reaches the window listener. The provider calls the same handlers again.
Please mark each keyboard event after its first dispatch attempt. Add a test where all handlers return false.
There was a problem hiding this comment.
Fixed in 426ab77. The provider now keeps a WeakSet of key events it has already offered to the handlers, so the window listener skips an event the editor path already tried. Test added: offers a declined chord to the handlers only once.
| // capture listener that stops the event before the editor sees it. | ||
| // TipTap's `blur` command defers to the next animation frame, so blur the | ||
| // editor DOM directly and drop the caret with it. | ||
| if (event.key === "Escape") { |
There was a problem hiding this comment.
🚨 slopcop/review — Make Escape release a focused editor after the input becomes locked.
setEditable(false) prevents ProseMirror from calling this key handler. A focused editor can remain focused after the lock.
Escape cannot run this blur path in that state. Please handle Escape outside the editable-only handler.
Add a test for a locked editor that already has focus.
There was a problem hiding this comment.
Fixed in 426ab77. Escape now also runs from an onKeyDown on the editor container, which fires while the editor is locked and ProseMirror skips its own handlers. It acts only when editor.isEditable is false, so the editable path keeps its typeahead-first priority. Test added: releases focus on Escape while a plugin locks the composer.
| if (!matchesAppCommandContext(binding, context)) continue; | ||
| if (!dispatch(binding.command, event.target)) return; | ||
| if (!dispatch(binding.command, event.target)) return false; | ||
| event.preventDefault(); |
There was a problem hiding this comment.
🚨 slopcop/review — Clear keyboard hints before this editor path stops event propagation.
The window hint listener normally clears hints after a non-modifier key. This direct editor path stops the event before that listener runs.
A displayed hint stays active until modifier release or window blur.
Please clear the hint state in the shared dispatcher. Add a test for a consumed editor shortcut.
There was a problem hiding this comment.
Fixed in 426ab77. The shared dispatcher clears the hint hold through a ref before it consumes the event, so a chord dispatched from the composer releases the hint exactly as the window path did. Test added: clears the keyboard hint when the composer runs a shortcut.
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5
The chat box now lets app key shortcuts pass through. Escape moves focus out without deleting text.
It works like a door that lets app keys leave the chat box.
Findings
I found two correctness issues and one small UI issue.
- When all handlers say no, the editor path and window path call them twice.
- A locked editor skips ProseMirror key handlers, so Escape cannot release existing focus.
- An editor shortcut can stop the event before the window clears keyboard hints.
I found no security defect. The performance review found negligible extra work and no listener or render loop.
Architecture and duplicate code
The shared dispatcher removes duplicate shortcut matching logic. Its two event paths still need per-event dispatch state.
An older useEscapeToHide hook is inactive and appears stale. The modal-menu gap and alternate editable checks predate this pull request.
Validation
- GitHub CI passed all required jobs.
- The Turbo app type check passed.
- The two focused files passed all 17 tests.
- Browser QA confirmed that Escape keeps text and removes focus.
- Browser QA confirmed that Meta+Backslash toggles the sidebar from the composer.
- The full local suite passed 2,417 tests. One unrelated scroll test failed, while the GitHub app job passed.
I posted a comment review. I did not approve the pull request or request changes.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Fixes #1397 ## Root cause This is the regression created by #1166's app-first composer dispatch. `PromptBoxInternal` offers each keydown to `AppCommandProvider` before TipTap or the browser handles it, so `Mod+Shift+ArrowUp/ArrowDown` matched `thread.previous/next`, stopped propagation, and navigated before native selection could run. The later window listener was not the winning layer. ## Implementation - Treat semantic navigation and deletion keys from an editable target as owned by that target, regardless of modifier combination. - Keep arbitration independent of command IDs and configured shortcut literals, so user-customized bindings follow the same rule. - Cover arrows, Home/End, PageUp/PageDown, Backspace, and Delete. This preserves character-, word-, line-, document-, and page-wise navigation/selection and deletion conventions across macOS, Windows, and Linux. - Preserve #1162: non-editing app chords still dispatch before the editor keymap, including `Mod+Shift+B` when rebound to an app command. ## Validation - Reproduced both directions on clean `origin/main`: the route changed threads and the selection stayed empty. - Live dev-app QA after the fix: `Cmd+Shift+Up/Down` selected the full multiline draft in both directions, kept editor focus, and stayed on the same thread. - Live dev-app QA for #1162: the ordinary sidebar shortcut fired with composer focus; after rebinding it to `Mod+Shift+B`, it still toggled the sidebar instead of creating a blockquote. - `pnpm exec turbo run typecheck --filter=@bb/app` - `pnpm exec turbo run test --filter=@bb/app --force` — 336 files, 2,546 tests passed - `pnpm exec turbo run lint --filter=@bb/app` — 0 errors > AGENT GENERATED: by GPT-5 Codex
Fixes get-bb#1162 ## Root cause The prompt editor consumes key events before the app command layer sees them. 1. `AppCommandProvider` listens on `window` in the bubble phase and skips any event whose default is already prevented (`AppCommandProvider.tsx:270`). TipTap's keymap cancels every chord it owns. Live check in the dev app, with the chat input focused: `Ctrl+Shift+B` (blockquote) and `Ctrl+B` reached the `window` listener with `defaultPrevented === true`. A sidebar shortcut bound to such a chord therefore did nothing while the chat input had focus. 2. ProseMirror cancels Escape unconditionally, but nothing released the editor. Live check: after Escape, `document.activeElement` was still the editor. ## User impact - The sidebar shortcut, and any other app shortcut, silently did nothing while the chat input had focus, whenever its chord collided with the editor keymap. Users had to click the toggle. - Escape did not release the chat input, so the keyboard could not reach the rest of the app. ## Implementation - `AppCommandProvider.tsx`: the keybinding match and dispatch loop moves into `handleKeyboardEvent`, which reports whether a command ran. A new `useAppCommandKeyDispatch()` hook exposes it. The window listener keeps its current behavior. - `PromptBoxInternal.tsx`: the editor keydown handler asks the app command layer first, so app keybindings win over the editor keymap. Escape blurs the editor DOM and drops the caret. Escape priority stays intact. The typeahead menu claims Escape earlier in the same handler, so the first Escape dismisses the menu and the second releases focus. Voice recording cancels from a window capture listener that stops the event before the editor. No server or daemon payload changed, so `HOST_DAEMON_PROTOCOL_VERSION` stays as it is. ## Validation - New `PromptBoxAppShortcuts.test.tsx`: shortcut from a focused composer, shortcut on a chord the editor keymap also claims, Escape blur, and plain typing unaffected. - `pnpm exec turbo run typecheck --filter=@bb/app` — pass. - `pnpm exec vitest run --project @bb/app` — 322 files, 2418 tests, all pass. - `pnpm exec turbo run lint --filter=@bb/app` — 0 errors, no warnings in the changed files. - Live QA in the dev app, thread view and new-thread composer: the sidebar toggles from the focused chat input, the first Escape dismisses the mention menu and keeps focus, the second Escape blurs, and the draft text survives. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Fixes #1162
Root cause
The prompt editor consumes key events before the app command layer sees them.
AppCommandProviderlistens onwindowin the bubble phase and skips any event whose default is already prevented (AppCommandProvider.tsx:270). TipTap's keymap cancels every chord it owns. Live check in the dev app, with the chat input focused:Ctrl+Shift+B(blockquote) andCtrl+Breached thewindowlistener withdefaultPrevented === true. A sidebar shortcut bound to such a chord therefore did nothing while the chat input had focus.document.activeElementwas still the editor.User impact
Implementation
AppCommandProvider.tsx: the keybinding match and dispatch loop moves intohandleKeyboardEvent, which reports whether a command ran. A newuseAppCommandKeyDispatch()hook exposes it. The window listener keeps its current behavior.PromptBoxInternal.tsx: the editor keydown handler asks the app command layer first, so app keybindings win over the editor keymap. Escape blurs the editor DOM and drops the caret.Escape priority stays intact. The typeahead menu claims Escape earlier in the same handler, so the first Escape dismisses the menu and the second releases focus. Voice recording cancels from a window capture listener that stops the event before the editor.
No server or daemon payload changed, so
HOST_DAEMON_PROTOCOL_VERSIONstays as it is.Validation
PromptBoxAppShortcuts.test.tsx: shortcut from a focused composer, shortcut on a chord the editor keymap also claims, Escape blur, and plain typing unaffected.pnpm exec turbo run typecheck --filter=@bb/app— pass.pnpm exec vitest run --project @bb/app— 322 files, 2418 tests, all pass.pnpm exec turbo run lint --filter=@bb/app— 0 errors, no warnings in the changed files.🤖 Generated with Claude Code