|
9 | 9 | } from "react"; |
10 | 10 | import { useLocation, useRouter, type AnyRouter } from "@tanstack/react-router"; |
11 | 11 |
|
12 | | -import { WorkspaceNavigation, workspaceAreaProps } from "./WorkspaceNavigation"; |
| 12 | +import { moveWorkspaceFocus, workspaceAreaProps } from "../lib/workspaceFocus"; |
13 | 13 | import { isCommandPaletteOpen } from "../commandPaletteBus"; |
14 | 14 | import { isElectron } from "../env"; |
15 | 15 | import { |
@@ -171,6 +171,33 @@ export function registerNavigationHistoryCommands(router: AnyRouter): () => void |
171 | 171 | ); |
172 | 172 | } |
173 | 173 |
|
| 174 | +// Capture phase, so F6 also leaves widgets that swallow keys, such as the terminal. |
| 175 | +function registerWorkspaceFocusCommands(router: AnyRouter): () => void { |
| 176 | + const move = (direction: 1 | -1) => (event: KeyboardEvent) => { |
| 177 | + if (event.isComposing) return false; |
| 178 | + // Inside a dialog the move is refused, but the key is still consumed. |
| 179 | + event.preventDefault(); |
| 180 | + event.stopPropagation(); |
| 181 | + moveWorkspaceFocus(direction); |
| 182 | + }; |
| 183 | + const disposers = [ |
| 184 | + registerCommands( |
| 185 | + { "workspace.focusNext": move(1), "workspace.focusPrevious": move(-1) }, |
| 186 | + { |
| 187 | + capture: true, |
| 188 | + when: (event) => !isKeybindingCaptureTarget(event), |
| 189 | + context: () => readRoutePanelsOpen(router), |
| 190 | + }, |
| 191 | + ), |
| 192 | + // A focused desktop browser forwards the keys; its renderer focus is stale. |
| 193 | + registerMenuAction("workspace.focusNext", () => moveWorkspaceFocus(1, "panel")), |
| 194 | + registerMenuAction("workspace.focusPrevious", () => moveWorkspaceFocus(-1, "panel")), |
| 195 | + ]; |
| 196 | + return () => { |
| 197 | + for (const dispose of disposers) dispose(); |
| 198 | + }; |
| 199 | +} |
| 200 | + |
174 | 201 | // Escape leaves the pull requests page when no scope (a selection, a dialog, |
175 | 202 | // a drag) claimed it, so it observes after every other scope. |
176 | 203 | function registerPullRequestsEscapeCommand(router: AnyRouter): () => void { |
@@ -273,6 +300,7 @@ function registerAppShellCommands(router: AnyRouter, shellElement: Element): () |
273 | 300 | const disposers = [ |
274 | 301 | registerThreadUndoCommands(router, readSidebarVisible), |
275 | 302 | registerNavigationHistoryCommands(router), |
| 303 | + registerWorkspaceFocusCommands(router), |
276 | 304 | registerPullRequestsEscapeCommand(router), |
277 | 305 | registerMenuAction("open-settings", () => { |
278 | 306 | if (!/^\/settings(\/|$)/.test(router.state.location.pathname)) |
@@ -374,7 +402,6 @@ function SidebarControl() { |
374 | 402 | } |
375 | 403 |
|
376 | 404 | export function AppSidebarLayout({ children }: { children: ReactNode }) { |
377 | | - const router = useRouter(); |
378 | 405 | const sidebarArea = workspaceAreaProps("sidebar", 0, "Threads"); |
379 | 406 | const legacySidebarEnabled = useLegacySidebarEnabled(); |
380 | 407 | const [sidebarRouteReveal] = useState<SidebarRouteReveal>(() => ({ |
@@ -453,7 +480,6 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { |
453 | 480 | {children} |
454 | 481 | <BackgroundThreadAnnouncer /> |
455 | 482 | <SidebarControl /> |
456 | | - <WorkspaceNavigation readPanelContext={() => readRoutePanelsOpen(router)} /> |
457 | 483 | </SidebarProvider> |
458 | 484 | </PanelAnimationSuppressionProvider> |
459 | 485 | ); |
|
0 commit comments