GeezerVison is showing github.com — feat(web): F6 moves between workspace areas, and the sidebar is keybo… · pingdotgg/t3code@2525252
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/preview/Manager.ts +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1505,7 +1505,16 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function | 1505 | 1505 | ); | 1506 | 1506 | if (forwarded && host) { | 1507 | 1507 | event.preventDefault(); | 1508 | | - if (!input.isAutoRepeat) host.send(MENU_ACTION_CHANNEL, forwarded.command); | | 1508 | + if (!input.isAutoRepeat) { | | 1509 | + if ( | | 1510 | + forwarded.command === "workspace.focusNext" || | | 1511 | + forwarded.command === "workspace.focusPrevious" | | 1512 | + ) { | | 1513 | + // DOM focus in the renderer cannot by itself release the guest's native keyboard focus. | | 1514 | + host.focus(); | | 1515 | + } | | 1516 | + host.send(MENU_ACTION_CHANNEL, forwarded.command); | | 1517 | + } | 1509 | 1518 | return; | 1510 | 1519 | } | 1511 | 1520 | if (isPreviewRefreshShortcut(input)) { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/appInit.tsx +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,6 +48,7 @@ import { appAtomRegistry } from "./rpc/atomRegistry"; | 48 | 48 | import { primaryServerConfigAtom } from "./state/server"; | 49 | 49 | import { environmentShell } from "./state/shell"; | 50 | 50 | import { installChatRouteCommands } from "./shortcuts/chatRouteCommands"; | | 51 | +import { startWorkspaceFocus } from "./lib/workspaceFocus"; | 51 | 52 | import { installCommandPaletteCommands } from "./shortcuts/commandPaletteCommands"; | 52 | 53 | import { registerOpenFavoriteEditorCommand } from "./components/chat/OpenInPickerShortcut"; | 53 | 54 | import { environmentThreadShells } from "./state/threads"; | @@ -191,6 +192,7 @@ export function startAppServices(): AppRouter { | 191 | 192 | shellStateAtom: environmentShell.stateAtom, | 192 | 193 | }); | 193 | 194 | startMainAppLocationTracking(router); | | 195 | + startWorkspaceFocus(router); | 194 | 196 | startBackgroundThreadAnnouncements(appAtomRegistry, router); | 195 | 197 | startThreadVisitedMigration(appAtomRegistry); | 196 | 198 | startSshPasswordPromptQueue(); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/commandPaletteStore.ts +29-1Lines changed: 29 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | type CommandPaletteUiState, | 7 | 7 | reduceCommandPaletteUiState, | 8 | 8 | } from "./components/CommandPalette.logic"; | | 9 | +import { getWorkspaceFocusRequestVersion } from "./lib/workspaceFocus"; | 9 | 10 |
| 10 | 11 | const INITIAL_STATE: CommandPaletteUiState = { | 11 | 12 | open: false, | @@ -16,8 +17,35 @@ const INITIAL_STATE: CommandPaletteUiState = { | 16 | 17 |
| 17 | 18 | export const useCommandPaletteStore = create<CommandPaletteUiState>(() => INITIAL_STATE); | 18 | 19 |
| | 20 | +let returnFocus: { element: HTMLElement | null; href: string; focusRequest: number } | null = null; | | 21 | + | 19 | 22 | export function dispatchCommandPalette(action: CommandPaletteUiAction): void { | 20 | | - useCommandPaletteStore.setState((state) => reduceCommandPaletteUiState(state, action), true); | | 23 | + const state = useCommandPaletteStore.getState(); | | 24 | + const next = reduceCommandPaletteUiState(state, action); | | 25 | + if (!state.open && next.open) { | | 26 | + // The workspace turns inert before the popup mounts, which blurs the opener. | | 27 | + returnFocus = { | | 28 | + element: document.activeElement instanceof HTMLElement ? document.activeElement : null, | | 29 | + href: window.location.href, | | 30 | + focusRequest: getWorkspaceFocusRequestVersion(), | | 31 | + }; | | 32 | + } | | 33 | + useCommandPaletteStore.setState(next, true); | | 34 | +} | | 35 | + | | 36 | +/** | | 37 | + * Where the closing palette should return focus: `false` when a command navigated or asked | | 38 | + * for workspace focus (the destination owns it), else the opener, or `true` for the default. | | 39 | + */ | | 40 | +export function getCommandPaletteReturnFocus(): HTMLElement | boolean { | | 41 | + if ( | | 42 | + !returnFocus || | | 43 | + window.location.href !== returnFocus.href || | | 44 | + getWorkspaceFocusRequestVersion() !== returnFocus.focusRequest | | 45 | + ) | | 46 | + return false; | | 47 | + const { element } = returnFocus; | | 48 | + return element?.isConnected && !element.matches(":disabled") ? element : true; | 21 | 49 | } | 22 | 50 |
| 23 | 51 | // The palette is only mounted on app-shell routes (not /pair, sign-in or | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/AppSidebarLayout.tsx +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 | } from "react"; | 10 | 10 | import { useLocation, useRouter, type AnyRouter } from "@tanstack/react-router"; | 11 | 11 |
| | 12 | +import { moveWorkspaceFocus, workspaceAreaProps } from "../lib/workspaceFocus"; | 12 | 13 | import { isCommandPaletteOpen } from "../commandPaletteBus"; | 13 | 14 | import { isElectron } from "../env"; | 14 | 15 | import { | @@ -170,6 +171,33 @@ export function registerNavigationHistoryCommands(router: AnyRouter): () => void | 170 | 171 | ); | 171 | 172 | } | 172 | 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 | + | 173 | 201 | // Escape leaves the pull requests page when no scope (a selection, a dialog, | 174 | 202 | // a drag) claimed it, so it observes after every other scope. | 175 | 203 | function registerPullRequestsEscapeCommand(router: AnyRouter): () => void { | @@ -272,6 +300,7 @@ function registerAppShellCommands(router: AnyRouter, shellElement: Element): () | 272 | 300 | const disposers = [ | 273 | 301 | registerThreadUndoCommands(router, readSidebarVisible), | 274 | 302 | registerNavigationHistoryCommands(router), | | 303 | + registerWorkspaceFocusCommands(router), | 275 | 304 | registerPullRequestsEscapeCommand(router), | 276 | 305 | registerMenuAction("open-settings", () => { | 277 | 306 | if (!/^\/settings(\/|$)/.test(router.state.location.pathname)) | @@ -373,6 +402,7 @@ function SidebarControl() { | 373 | 402 | } | 374 | 403 |
| 375 | 404 | export function AppSidebarLayout({ children }: { children: ReactNode }) { | | 405 | + const sidebarArea = workspaceAreaProps("sidebar", 0, "Threads"); | 376 | 406 | const legacySidebarEnabled = useLegacySidebarEnabled(); | 377 | 407 | const [sidebarRouteReveal] = useState<SidebarRouteReveal>(() => ({ | 378 | 408 | observedKey: null, | @@ -426,6 +456,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { | 426 | 456 | side="left" | 427 | 457 | collapsible="offcanvas" | 428 | 458 | data-app-sidebar="" | | 459 | + {...sidebarArea} | 429 | 460 | role="navigation" | 430 | 461 | aria-label="Threads" | 431 | 462 | resizable={{ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbar.tsx +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -280,7 +280,11 @@ const RunContextSelector = memo(function RunContextSelector({ | 280 | 280 | isPanel && THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS, | 281 | 281 | )} | 282 | 282 | onContextMenu={handleContextMenu} | 283 | | - aria-label={isPanel ? "Run context" : undefined} | | 283 | + aria-label={ | | 284 | + isPanel | | 285 | + ? `Run context: ${[autoEnvironmentLabel ?? activeEnvironment?.label, workspaceLabel].filter(Boolean).join(", ")}` | | 286 | + : undefined | | 287 | + } | 284 | 288 | data-composer-context-control | 285 | 289 | > | 286 | 290 | {triggerContent} | @@ -301,7 +305,11 @@ const RunContextSelector = memo(function RunContextSelector({ | 301 | 305 | } | 302 | 306 | : undefined | 303 | 307 | } | 304 | | - aria-label={isPanel ? "Run context" : undefined} | | 308 | + aria-label={ | | 309 | + isPanel | | 310 | + ? `Run context: ${[autoEnvironmentLabel ?? activeEnvironment?.label, workspaceLabel].filter(Boolean).join(", ")}` | | 311 | + : undefined | | 312 | + } | 305 | 313 | data-composer-context-control | 306 | 314 | data-composer-shortcut={[ | 307 | 315 | showEnvironmentPicker && !envLocked ? "composer.host" : "", | |
Collapse file Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { expect, it } from "vite-plus/test"; | | 2 | +import { userEvent } from "vite-plus/test/browser"; | | 3 | +import { shouldRefocusComposerOnWindowFocus } from "./ChatView.logic"; | | 4 | + | | 5 | +it("keeps keyboard focus on a sidebar row on window return, but not a clicked row", async () => { | | 6 | + const tree = document.createElement("div"); | | 7 | + tree.setAttribute("role", "tree"); | | 8 | + const row = (name: string, tabIndex: number) => { | | 9 | + const element = document.createElement("div"); | | 10 | + element.setAttribute("role", "treeitem"); | | 11 | + element.tabIndex = tabIndex; | | 12 | + element.textContent = name; | | 13 | + tree.append(element); | | 14 | + return element; | | 15 | + }; | | 16 | + const clicked = row("Clicked thread", -1); | | 17 | + const tabbed = row("Tabbed thread", 0); | | 18 | + document.body.append(tree); | | 19 | + using _tree = { [Symbol.dispose]: () => tree.remove() }; | | 20 | + | | 21 | + await userEvent.click(clicked); | | 22 | + expect(document.activeElement).toBe(clicked); | | 23 | + expect(shouldRefocusComposerOnWindowFocus(document.activeElement)).toBe(true); | | 24 | + | | 25 | + await userEvent.tab(); | | 26 | + expect(document.activeElement).toBe(tabbed); | | 27 | + expect(shouldRefocusComposerOnWindowFocus(document.activeElement)).toBe(false); | | 28 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.logic.ts +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1166,6 +1166,10 @@ export function hasServerAcknowledgedLocalDispatch(input: { | 1166 | 1166 | ); | 1167 | 1167 | } | 1168 | 1168 |
| | 1169 | +// Returning to the window should land the caret in the composer, so the reader can type right | | 1170 | +// away. The exceptions are places where focus is deliberate: another text field, a terminal in | | 1171 | +// the drawer or the right panel, an open dialog, menu, or popup, or a region or sidebar row | | 1172 | +// reached from the keyboard. A plain focused button or a clicked row yields to the composer. | 1169 | 1173 | export function shouldRefocusComposerOnWindowFocus( | 1170 | 1174 | activeElement: | 1171 | 1175 | | (Pick<Element, "tagName" | "closest" | "getAttribute"> & { isContentEditable?: boolean }) | @@ -1185,7 +1189,7 @@ export function shouldRefocusComposerOnWindowFocus( | 1185 | 1189 | } | 1186 | 1190 | return ( | 1187 | 1191 | activeElement.closest( | 1188 | | - '[role="dialog"], [role="alertdialog"], [role="application"], [data-slot$="-popup"], [data-terminal-owner]', | | 1192 | + '[data-workspace-area]:focus-visible, [role="treeitem"]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner]', | 1189 | 1193 | ) === null | 1190 | 1194 | ); | 1191 | 1195 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { workspaceAreaProps } from "../lib/workspaceFocus"; | 1 | 2 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; | 2 | 3 | import { queuedRunEditBlockedReason } from "@t3tools/client-runtime/queued-run-edit"; | 3 | 4 | import { ScrollToEndButton, WorkspaceFileDropOverlay } from "./chat/TimelineOverlays"; | @@ -707,6 +708,8 @@ export default function ChatView(props: ChatViewProps) { | 707 | 708 | const legendListRef = useRef<LegendListRef | null>(null); | 708 | 709 | const getTimelineScrollableNode = () => legendListRef.current?.getScrollableNode() ?? null; | 709 | 710 | const getTimelineScrollableNodeStable = useStableCallback(getTimelineScrollableNode); | | 711 | + const conversationArea = workspaceAreaProps("conversation", 1, "Conversation"); | | 712 | + const composerArea = workspaceAreaProps("composer", 2, "Message input"); | 710 | 713 | const [composerOverlayElement, setComposerOverlayElement] = useState<HTMLDivElement | null>(null); | 711 | 714 | const [composerTimelineInset, setComposerTimelineInset] = useState(0); | 712 | 715 | const composerTimelineInsetRef = useRef(0); | @@ -3173,6 +3176,7 @@ export default function ChatView(props: ChatViewProps) { | 3173 | 3176 | )} | 3174 | 3177 | data-chat-column-maximized-away={rightPanelMaximized ? "true" : "false"} | 3175 | 3178 | data-chat-column | | 3179 | + inert={rightPanelMaximized} | 3176 | 3180 | > | 3177 | 3181 | <header | 3178 | 3182 | ref={threadPanelPopoverAnchorRef} | @@ -3253,7 +3257,10 @@ export default function ChatView(props: ChatViewProps) { | 3253 | 3257 | setThreadError={setThreadError} | 3254 | 3258 | setThreadErrorBannerDismissTick={setThreadErrorBannerDismissTick} | 3255 | 3259 | /> | 3256 | | - <div className="relative flex min-h-0 flex-1 flex-col bg-background"> | | 3260 | + <div | | 3261 | + {...conversationArea} | | 3262 | + className="relative flex min-h-0 flex-1 flex-col bg-background" | | 3263 | + > | 3257 | 3264 | <ThreadTimeline | 3258 | 3265 | threadDetailRef={routeThreadDetailRef} | 3259 | 3266 | entriesInput={timelineEntriesInput} | @@ -3360,6 +3367,7 @@ export default function ChatView(props: ChatViewProps) { | 3360 | 3367 | </div> | 3361 | 3368 |
| 3362 | 3369 | <div | | 3370 | + {...composerArea} | 3363 | 3371 | ref={(overlay: HTMLDivElement | null) => { | 3364 | 3372 | setComposerOverlayElement(overlay); | 3365 | 3373 | attachFollowComposerOverlay(overlay); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/CommandPalette.tsx +26-1Lines changed: 26 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,6 +67,7 @@ import { | 67 | 67 | PaletteIcon, | 68 | 68 | RotateCcwIcon, | 69 | 69 | SettingsIcon, | | 70 | + MonitorIcon, | 70 | 71 | SquarePenIcon, | 71 | 72 | TextSearchIcon, | 72 | 73 | UserPlusIcon, | @@ -89,6 +90,10 @@ import { useDesktopLocalBootstraps } from "../connection/useDesktopLocalBootstra | 89 | 90 | import { useHandleNewThread } from "../hooks/useHandleNewThread"; | 90 | 91 | import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl"; | 91 | 92 | import { copyThreadReference } from "../lib/copyThreadReference"; | | 93 | +import { | | 94 | + queueWorkspaceFocusFromPalette, | | 95 | + restoreWorkspaceFocusFromPalette, | | 96 | +} from "../lib/workspaceFocus"; | 92 | 97 | import { | 93 | 98 | composerPromptLink, | 94 | 99 | copyPromptLink, | @@ -132,6 +137,7 @@ import { | 132 | 137 | } from "../lib/projectPaths"; | 133 | 138 | import { | 134 | 139 | dispatchCommandPalette, | | 140 | + getCommandPaletteReturnFocus, | 135 | 141 | useCommandPaletteMount, | 136 | 142 | useCommandPaletteStore, | 137 | 143 | } from "../commandPaletteStore"; | @@ -326,8 +332,12 @@ function CommandPaletteDialog(props: { | 326 | 332 | data-palette-mode={props.mode} | 327 | 333 | data-testid="command-palette" | 328 | 334 | finalFocus={() => { | | 335 | + if (restoreWorkspaceFocusFromPalette()) return false; | | 336 | + const returnFocus = getCommandPaletteReturnFocus(); | | 337 | + if (returnFocus === false) return false; | 329 | 338 | const composer = composerHandleRef?.current; | 330 | | - if (!composer) return true; | | 339 | + // Behind the Settings modal the composer is inert and cannot take focus. | | 340 | + if (!composer || document.querySelector("[data-app-modal]")) return returnFocus; | 331 | 341 | composer.focusAtEnd(); | 332 | 342 | return false; | 333 | 343 | }} | @@ -1507,6 +1517,21 @@ function OpenCommandPaletteDialog(props: { | 1507 | 1517 | }, | 1508 | 1518 | }); | 1509 | 1519 |
| | 1520 | + for (const direction of [1, -1] as const) { | | 1521 | + const title = direction === 1 ? "Focus Next Workspace Area" : "Focus Previous Workspace Area"; | | 1522 | + actionItems.push({ | | 1523 | + kind: "action", | | 1524 | + value: `action:workspace-focus:${direction}`, | | 1525 | + title, | | 1526 | + searchTerms: [title, "accessibility", "navigation", "focus", "F6"], | | 1527 | + icon: <MonitorIcon className={ITEM_ICON_CLASS} />, | | 1528 | + shortcutCommand: direction === 1 ? "workspace.focusNext" : "workspace.focusPrevious", | | 1529 | + run: async () => { | | 1530 | + queueWorkspaceFocusFromPalette(direction); | | 1531 | + }, | | 1532 | + }); | | 1533 | + } | | 1534 | + | 1510 | 1535 | actionItems.push({ | 1511 | 1536 | kind: "action", | 1512 | 1537 | value: "action:settings", | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/DiffPanel.tsx +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -655,6 +655,7 @@ export default function DiffPanel({ | 655 | 655 | render={<Button size="xs" variant="secondary" />} | 656 | 656 | className="max-w-full" | 657 | 657 | aria-label={`Diff scope: ${selectedScopeLabel}`} | | 658 | + data-workspace-focus-default | 658 | 659 | > | 659 | 660 | <span className="truncate">{selectedScopeLabel}</span> | 660 | 661 | <ChevronDownIcon className="size-3.5 shrink-0 opacity-70" /> | |
|