| ... | ... | @@ -7,7 +7,7 @@ import { |
| 7 | 7 | type CSSProperties, |
| 8 | 8 | type ReactNode, |
| 9 | 9 | } from "react"; |
| 10 | | import { useLocation, useNavigate } from "@tanstack/react-router"; |
| 10 | import { useLocation, useNavigate, useParams } from "@tanstack/react-router"; |
| 11 | 11 | |
| 12 | 12 | import { isElectron } from "../env"; |
| 13 | 13 | import { getLocalStorageItem, removeLocalStorageItem } from "../hooks/useLocalStorage"; |
| ... | ... | @@ -16,6 +16,13 @@ import { |
| 16 | 16 | resolveShortcutCommand, |
| 17 | 17 | shortcutLabelForCommand, |
| 18 | 18 | } from "../keybindings"; |
| 19 | import { isEditableFocused } from "../lib/editableFocus"; |
| 20 | import { isPreviewFocused } from "../lib/previewFocus"; |
| 21 | import { isTerminalFocused } from "../lib/terminalFocus"; |
| 22 | import { isModelPickerOpen } from "../modelPickerVisibility"; |
| 23 | import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore"; |
| 24 | import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore"; |
| 25 | import { resolveThreadRouteRef } from "../threadRoutes"; |
| 19 | 26 | import { cn, isMacPlatform } from "../lib/utils"; |
| 20 | 27 | import { primaryServerKeybindingsAtom } from "../state/server"; |
| 21 | 28 | import { useEnvironmentIdentificationMode, useLegacySidebarEnabled } from "../hooks/useSettings"; |
| ... | ... | @@ -147,6 +154,56 @@ function SidebarControl() { |
| 147 | 154 | ); |
| 148 | 155 | } |
| 149 | 156 | |
| 157 | // Moves through the app's route history like a browser's back/forward buttons. |
| 158 | function NavigationHistoryShortcuts() { |
| 159 | const keybindings = useAtomValue(primaryServerKeybindingsAtom); |
| 160 | const routeThreadRef = useParams({ |
| 161 | strict: false, |
| 162 | select: (params) => resolveThreadRouteRef(params), |
| 163 | }); |
| 164 | |
| 165 | useEffect(() => { |
| 166 | const onKeyDown = (event: KeyboardEvent) => { |
| 167 | if (event.defaultPrevented) return; |
| 168 | if ( |
| 169 | event.target instanceof HTMLElement && |
| 170 | event.target.closest("[data-keybinding-capture]") |
| 171 | ) { |
| 172 | return; |
| 173 | } |
| 174 | const command = resolveShortcutCommand(event, keybindings, { |
| 175 | context: { |
| 176 | terminalFocus: isTerminalFocused(), |
| 177 | terminalOpen: routeThreadRef |
| 178 | ? selectThreadTerminalUiState( |
| 179 | useTerminalUiStateStore.getState().terminalUiStateByThreadKey, |
| 180 | routeThreadRef, |
| 181 | ).terminalOpen |
| 182 | : false, |
| 183 | previewFocus: isPreviewFocused(), |
| 184 | previewOpen: routeThreadRef |
| 185 | ? selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, routeThreadRef) === |
| 186 | "preview" |
| 187 | : false, |
| 188 | editableFocus: isEditableFocused(event.target), |
| 189 | modelPickerOpen: isModelPickerOpen(), |
| 190 | }, |
| 191 | }); |
| 192 | if (command !== "navigation.back" && command !== "navigation.forward") return; |
| 193 | |
| 194 | event.preventDefault(); |
| 195 | event.stopPropagation(); |
| 196 | if (command === "navigation.back") window.history.back(); |
| 197 | else window.history.forward(); |
| 198 | }; |
| 199 | |
| 200 | window.addEventListener("keydown", onKeyDown); |
| 201 | return () => window.removeEventListener("keydown", onKeyDown); |
| 202 | }, [keybindings, routeThreadRef]); |
| 203 | |
| 204 | return null; |
| 205 | } |
| 206 | |
| 150 | 207 | // Settings swaps the thread sidebar out of the tree. Keep the lightweight |
| 151 | 208 | // project projection subscribed so returning to a draft never renders the |
| 152 | 209 | // zero-project state while the environment snapshot reconnects. |
| ... | ... | @@ -269,6 +326,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { |
| 269 | 326 | </Sidebar> |
| 270 | 327 | {children} |
| 271 | 328 | <SidebarControl /> |
| 329 | <NavigationHistoryShortcuts /> |
| 272 | 330 | </SidebarProvider> |
| 273 | 331 | </PanelAnimationSuppressionProvider> |
| 274 | 332 | ); |