Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
type MouseEvent as ReactMouseEvent,
type ReactNode,
} from "react";
import { flushSync } from "react-dom";
import { type AnyRouter, useRouter } from "@tanstack/react-router";

import {
Expand All @@ -100,6 +101,7 @@ import { useShortcutModifierState } from "../shortcutModifierState";
import { isTerminalFocused } from "../lib/terminalFocus";
import { isModelPickerOpen } from "../modelPickerVisibility";
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
import { isMacPlatform } from "~/lib/utils";
import { readLocalApi } from "../localApi";
import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore";
Expand All @@ -125,6 +127,7 @@ import { useSidebarProjectGroups } from "../hooks/useSidebarProjectGroups";
import { useTerminalFocus } from "../hooks/useTerminalFocus";
import { isCommandPaletteOpen, openCommandPalette } from "../commandPaletteBus";
import { registerSettleAndAdvance } from "../settleAndAdvance";
import { registerCommands } from "../shortcuts/dispatcher";
import { startNewThreadFromContext } from "../lib/chatThreadActions";
import { useBoringSidebarEnabled, useClientSettings } from "../hooks/useSettings";
import { useCopyToClipboard } from "../hooks/useCopyToClipboard";
Expand Down Expand Up @@ -241,6 +244,7 @@ import {
} from "./ui/combobox";
import { SidebarContent, SidebarGroup, useSidebar } from "./ui/sidebar";
import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChrome";
import { isAppModalPage } from "./sidebar/mainAppLocation";
import { SidebarHeaderIconButton, SidebarThreadHeader } from "./sidebar/SidebarThreadHeader";
import { TooltipProvider } from "./ui/tooltip";
import { composerDraftHasUserContent, DraftId, useComposerDraftStore } from "../composerDraftStore";
Expand Down Expand Up @@ -886,7 +890,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
} = useSidebarLookups();
const delegatedUnderParent = useDelegatedUnderParent();
const router = useRouter();
const { isMobile, setOpenMobile } = useSidebar();
const { isMobile, open: sidebarOpen, setOpen: setSidebarOpen, setOpenMobile } = useSidebar();
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
const confirmThreadArchive = useClientSettings((s) => s.confirmThreadArchive);
Expand Down Expand Up @@ -2885,6 +2889,33 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
openCommandPalette({ open: "new-thread-in" });
};

const onFocusSearchShortcut = useStableCallback((event: KeyboardEvent) => {
if (isAppModalPage(router.state.location.pathname)) return false;
if (isCommandPaletteOpen() || isModelPickerOpen()) return false;
event.preventDefault();
event.stopPropagation();
if (event.repeat) return;
// The collapsed sidebar is inert until the expanded state commits, and an inert input cannot take focus.
if (!isMobile && !sidebarOpen) flushSync(() => setSidebarOpen(true));
threadSearchInputRef.current?.focus();
threadSearchInputRef.current?.select();
});
const readRoutePanelsOpen = useStableCallback(() => ({
Comment thread
serge-the-hedge marked this conversation as resolved.
Resolved
terminalOpen: routeTerminalOpen,
previewOpen:
selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, routeThreadRef) ===
"preview",
}));
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- registers the capture-phase thread search shortcut while the sidebar is mounted
useEffect(
() =>
registerCommands(
{ "sidebar.focusSearch": onFocusSearchShortcut },
{ capture: true, context: readRoutePanelsOpen },
),
[onFocusSearchShortcut, readRoutePanelsOpen],
);

const newThreadShortcutLabel =
shortcutLabelForCommand(keybindings, "chat.new") ??
(projectGroups.length <= 1 ? shortcutLabelForCommand(keybindings, "chat.newLocal") : undefined);
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/files/BrowserDocumentFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const HTML_RENDER_SHORTCUT_COMMANDS: ReadonlySet<KeybindingCommand> = new Set([
"projectSearch.toggle",
"chat.find",
"sidebar.toggle",
"sidebar.focusSearch",
"rightPanel.toggle",
"rightPanel.toggleMaximized",
"threadPanel.toggle",
Expand Down
4 changes: 4 additions & 0 deletions docs/user/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ through the pages you have visited, like a browser's back and forward buttons.
[new-thread defaults](./thread-sidebar.md#start-a-thread). `chat.newWithoutProject`
(`mod+alt+n`) starts a thread [without a project](./thread-sidebar.md#start-without-a-project).

`sidebar.focusSearch` moves focus to the sidebar's Search field and selects the
query, so typing replaces it. A collapsed sidebar opens first. It has no default
shortcut; assign one in **Settings → Keybindings**.

## Reserved shortcuts

In the desktop app, `mod+w` closes the focused terminal or the active right-panel
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
"workspace.focusNext",
"workspace.focusPrevious",
"sidebar.toggle",
"sidebar.focusSearch",
"navigation.back",
"navigation.forward",
"terminal.toggle",
Expand Down
Loading