@devries-cameron20 / t3code-1 / commits / 6567ffd559
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): going back in the command palette keeps the search that led there (#15940)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 04:38 UTC 6567ffd55937d5af1f7b1e1a21c11a98f5bf640e
3 files changed +219 -62
apps/web/src/components/CommandPalette.logic.test.ts
+104
@@ -14,8 +14,11 @@ import {
14 filterCommandPaletteGroups,
15 findHighlightedCommandPaletteItem,
16 reduceCommandPaletteUiState,
17 + createCommandPaletteSearchState,
18 + reduceCommandPaletteSearchState,
19 type CommandPaletteActionItem,
20 type CommandPaletteGroup,
21 + type CommandPaletteUiState,
22 } from "./CommandPalette.logic";
23
24 describe("linked pull request thread navigation", () => {
@@ -894,3 +897,104 @@ describe("virtualized command palette rows", () => {
897 expect(findHighlightedCommandPaletteItem(groups, null)).toBeNull();
898 });
899 });
900 +
901 +describe("command palette search return", () => {
902 + const picker = { addonIcon: null, groups: [] };
903 +
904 + it("restores each parent query when backing out of nested pickers", () => {
905 + let state = createCommandPaletteSearchState(">new thread");
906 + state = reduceCommandPaletteSearchState(state, { type: "push", view: picker });
907 + expect(state.query).toBe("");
908 + state = reduceCommandPaletteSearchState(state, { type: "query", query: "remote project" });
909 + state = reduceCommandPaletteSearchState(state, {
910 + type: "push",
911 + view: { ...picker, initialQuery: "~/" },
912 + });
913 + expect(state.query).toBe("~/");
914 +
915 + state = reduceCommandPaletteSearchState(state, { type: "query", query: "" });
916 + state = reduceCommandPaletteSearchState(state, { type: "back" });
917 + expect(state.query).toBe("remote project");
918 + expect(state.views).toHaveLength(1);
919 + state = reduceCommandPaletteSearchState(state, { type: "back" });
920 + expect(state.query).toBe(">new thread");
921 + expect(state.views).toHaveLength(0);
922 + });
923 +
924 + it("cannot return to an old picker after a new search replaces it", () => {
925 + let state = reduceCommandPaletteSearchState(createCommandPaletteSearchState("old"), {
926 + type: "push",
927 + view: picker,
928 + });
929 + state = reduceCommandPaletteSearchState(state, { type: "reset", query: "fresh" });
930 + state = reduceCommandPaletteSearchState(state, { type: "back" });
931 + expect(state.query).toBe("fresh");
932 + expect(state.views).toHaveLength(0);
933 + });
934 +});
935 +
936 +describe("returning from file and content search", () => {
937 + const root: CommandPaletteUiState = { open: true, mode: "command", openIntent: null };
938 + const query = "https://github.com/acme/web/pull/7";
939 + const context = {
940 + query,
941 + linkedThreadSearch: {
942 + kind: "search" as const,
943 + query,
944 + linkedThreads: {
945 + environmentId: EnvironmentId.make("remote"),
946 + threads: [
947 + {
948 + id: ThreadId.make("linked-thread"),
949 + projectId: ProjectId.make("project"),
950 + title: "Completed work",
951 + archivedAt: "2026-09-01T00:00:00.000Z",
952 + },
953 + ],
954 + },
955 + },
956 + };
957 +
958 + it.each(["files", "content"] as const)(
959 + "Escape from %s restores the query and linked-thread results",
960 + (mode) => {
961 + const child = reduceCommandPaletteUiState(root, { _tag: "OpenChildSearch", mode, context });
962 + expect(child.mode).toBe(mode);
963 + const returned = reduceCommandPaletteUiState(child, { _tag: "BackToCommand" });
964 + expect(returned).toEqual({ ...root, restoredSearch: context });
965 + expect(reduceCommandPaletteUiState(returned, { _tag: "BackToCommand" })).toEqual(returned);
966 + },
967 + );
968 +
969 + it("closing a child search discards its return context before reopening", () => {
970 + const child: CommandPaletteUiState = { ...root, mode: "files", parentSearch: context };
971 + const closed = reduceCommandPaletteUiState(child, { _tag: "SetOpen", open: false });
972 + expect(closed).toEqual({ open: false, mode: "files", openIntent: null });
973 + expect(reduceCommandPaletteUiState(closed, { _tag: "BackToCommand" })).toEqual(closed);
974 + expect(reduceCommandPaletteUiState(closed, { _tag: "SetOpen", open: true })).toEqual(root);
975 + });
976 +
977 + it("a fresh overlay shortcut has no parent search to return to", () => {
978 + const child = reduceCommandPaletteUiState(root, {
979 + _tag: "OpenChildSearch",
980 + mode: "files",
981 + context,
982 + });
983 + const fresh = reduceCommandPaletteUiState(child, { _tag: "ToggleMode", mode: "content" });
984 + expect(fresh).toEqual({ open: true, mode: "content", openIntent: null });
985 + expect(reduceCommandPaletteUiState(fresh, { _tag: "BackToCommand" })).toEqual(root);
986 + });
987 +
988 + it("a direct search intent replaces restored query and linked-thread context", () => {
989 + const child = reduceCommandPaletteUiState(root, {
990 + _tag: "OpenChildSearch",
991 + mode: "content",
992 + context,
993 + });
994 + const returned = reduceCommandPaletteUiState(child, { _tag: "BackToCommand" });
995 + expect(reduceCommandPaletteUiState(returned, { _tag: "OpenSearch", query: "fresh" })).toEqual({
996 + ...root,
997 + openIntent: { kind: "search", query: "fresh" },
998 + });
999 + });
1000 +});
apps/web/src/components/CommandPalette.logic.ts
+65 -3
@@ -65,6 +65,8 @@ export interface CommandPaletteUiState {
65 readonly open: boolean;
66 readonly mode: SearchOverlayMode;
67 readonly openIntent: CommandPaletteOpenIntent | null;
68 + readonly parentSearch?: CommandPaletteReturnContext;
69 + readonly restoredSearch?: CommandPaletteReturnContext;
70 }
71
72 export type CommandPaletteUiAction =
@@ -78,7 +80,13 @@ export type CommandPaletteUiAction =
80 | { readonly _tag: "OpenAddProject" }
81 | { readonly _tag: "OpenNewThreadIn" }
82 | { readonly _tag: "OpenChangeTheme" }
81 - | { readonly _tag: "ClearOpenIntent" };
83 + | { readonly _tag: "ClearOpenIntent" }
84 + | {
85 + readonly _tag: "OpenChildSearch";
86 + readonly mode: "files" | "content";
87 + readonly context: CommandPaletteReturnContext;
88 + }
89 + | { readonly _tag: "BackToCommand" };
90
91 export function reduceCommandPaletteUiState(
92 state: CommandPaletteUiState,
@@ -88,11 +96,22 @@ export function reduceCommandPaletteUiState(
96 case "SetOpen":
97 return action.open
98 ? { open: true, mode: "command", openIntent: state.openIntent }
91 - : { ...state, open: false, openIntent: null };
99 + : { open: false, mode: state.mode, openIntent: null };
100 case "ToggleMode":
101 return state.open && state.mode === action.mode
94 - ? { ...state, open: false, openIntent: null }
102 + ? { open: false, mode: state.mode, openIntent: null }
103 : { open: true, mode: action.mode, openIntent: null };
104 + case "OpenChildSearch":
105 + return { open: true, mode: action.mode, openIntent: null, parentSearch: action.context };
106 + case "BackToCommand":
107 + return state.open && state.mode !== "command"
108 + ? {
109 + open: true,
110 + mode: "command",
111 + openIntent: null,
112 + ...(state.parentSearch ? { restoredSearch: state.parentSearch } : {}),
113 + }
114 + : state;
115 case "OpenSearch":
116 return {
117 open: true,
@@ -162,6 +181,49 @@ export interface CommandPaletteView {
181 readonly initialQuery?: string;
182 }
183
184 +// Child search unmounts the palette; retain search data without its view closures.
185 +export interface CommandPaletteReturnContext {
186 + readonly query: string;
187 + readonly linkedThreadSearch: Extract<CommandPaletteOpenIntent, { kind: "search" }> | null;
188 +}
189 +
190 +export interface CommandPaletteSearchState {
191 + readonly query: string;
192 + readonly views: ReadonlyArray<{
193 + readonly view: CommandPaletteView;
194 + readonly parentQuery: string;
195 + }>;
196 +}
197 +
198 +export function createCommandPaletteSearchState(query = ""): CommandPaletteSearchState {
199 + return { query, views: [] };
200 +}
201 +
202 +export function reduceCommandPaletteSearchState(
203 + state: CommandPaletteSearchState,
204 + action:
205 + | { readonly type: "query"; readonly query: string }
206 + | { readonly type: "push"; readonly view: CommandPaletteView }
207 + | { readonly type: "back" }
208 + | { readonly type: "reset"; readonly query?: string },
209 +): CommandPaletteSearchState {
210 + switch (action.type) {
211 + case "query":
212 + return { ...state, query: action.query };
213 + case "push":
214 + return {
215 + query: action.view.initialQuery ?? "",
216 + views: [...state.views, { view: action.view, parentQuery: state.query }],
217 + };
218 + case "back": {
219 + const parent = state.views.at(-1);
220 + return parent ? { query: parent.parentQuery, views: state.views.slice(0, -1) } : state;
221 + }
222 + case "reset":
223 + return createCommandPaletteSearchState(action.query);
224 + }
225 +}
226 +
227 export type CommandPaletteRow =
228 | {
229 readonly kind: "label";
apps/web/src/components/CommandPalette.tsx
+50 -59
@@ -188,6 +188,7 @@ import {
188 type CommandPaletteActionItem,
189 type CommandPaletteOpenIntent,
190 type CommandPaletteProject,
191 + type CommandPaletteReturnContext,
192 type CommandPaletteSubmenuItem,
193 type CommandPaletteView,
194 filterCommandPaletteGroups,
@@ -197,6 +198,8 @@ import {
198 ITEM_ICON_CLASS,
199 RECENT_THREAD_LIMIT,
200 reduceCommandPaletteUiState,
201 + createCommandPaletteSearchState,
202 + reduceCommandPaletteSearchState,
203 type SearchOverlayMode,
204 } from "./CommandPalette.logic";
205 import { orderItemsByPreferredIds, sortLogicalProjectsForSidebar } from "./Sidebar.logic";
@@ -492,6 +495,8 @@ export function CommandPalette({ children }: { children: ReactNode }) {
495 const openAddProject = () => dispatch({ _tag: "OpenAddProject" });
496 const openNewThreadIn = () => dispatch({ _tag: "OpenNewThreadIn" });
497 const clearOpenIntent = () => dispatch({ _tag: "ClearOpenIntent" });
498 + const openChildSearch = (mode: "files" | "content", context: CommandPaletteReturnContext) =>
499 + dispatch({ _tag: "OpenChildSearch", mode, context });
500 const keybindings = useAtomValue(primaryServerKeybindingsAtom);
501 const { theme, themeHalves, resolvedTheme, appearanceMode, setAppearanceMode } = useTheme();
502 const composerHandleRef = useRef<ChatComposerHandle | null>(null);
@@ -514,11 +519,11 @@ export function CommandPalette({ children }: { children: ReactNode }) {
519 if (event.isComposing || event.key !== "Escape") return;
520 event.preventDefault();
521 event.stopPropagation();
517 - toggleMode("command");
522 + dispatch({ _tag: "BackToCommand" });
523 };
524 window.addEventListener("keydown", onEscapeKeyDown, true);
525 return () => window.removeEventListener("keydown", onEscapeKeyDown, true);
521 - }, [state.mode, state.open, toggleMode]);
526 + }, [state.mode, state.open]);
527
528 useEffect(() => {
529 const onKeyDown = (event: globalThis.KeyboardEvent) => {
@@ -624,7 +629,7 @@ export function CommandPalette({ children }: { children: ReactNode }) {
629 onOpenChange={(open, eventDetails) => {
630 if (!open && eventDetails.reason === "escape-key" && state.mode !== "command") {
631 eventDetails.cancel();
627 - toggleMode("command");
632 + dispatch({ _tag: "BackToCommand" });
633 return;
634 }
635 setOpen(open);
@@ -637,7 +642,8 @@ export function CommandPalette({ children }: { children: ReactNode }) {
642 mode={state.mode}
643 openIntent={state.openIntent}
644 setOpen={setOpen}
640 - openOverlayMode={toggleMode}
645 + openChildSearch={openChildSearch}
646 + initialContext={state.restoredSearch}
647 clearOpenIntent={clearOpenIntent}
648 />
649 </CommandDialog>
@@ -649,7 +655,11 @@ function CommandPaletteDialog(props: {
655 readonly mode: SearchOverlayMode;
656 readonly openIntent: CommandPaletteOpenIntent | null;
657 readonly setOpen: (open: boolean) => void;
652 - readonly openOverlayMode: (mode: SearchOverlayMode) => void;
658 + readonly openChildSearch: (
659 + mode: "files" | "content",
660 + context: CommandPaletteReturnContext,
661 + ) => void;
662 + readonly initialContext: CommandPaletteReturnContext | undefined;
663 readonly clearOpenIntent: () => void;
664 }) {
665 const composerHandleRef = useComposerHandleContext();
@@ -685,7 +695,8 @@ function CommandPaletteDialog(props: {
695 <OpenCommandPaletteDialog
696 openIntent={props.openIntent}
697 setOpen={props.setOpen}
688 - openOverlayMode={props.openOverlayMode}
698 + openChildSearch={props.openChildSearch}
699 + initialContext={props.initialContext}
700 clearOpenIntent={props.clearOpenIntent}
701 />
702 )}
@@ -696,16 +707,28 @@ function CommandPaletteDialog(props: {
707 function OpenCommandPaletteDialog(props: {
708 readonly openIntent: CommandPaletteOpenIntent | null;
709 readonly setOpen: (open: boolean) => void;
699 - readonly openOverlayMode: (mode: SearchOverlayMode) => void;
710 + readonly openChildSearch: (
711 + mode: "files" | "content",
712 + context: CommandPaletteReturnContext,
713 + ) => void;
714 + readonly initialContext: CommandPaletteReturnContext | undefined;
715 readonly clearOpenIntent: () => void;
716 }) {
717 const navigate = useNavigate();
718 const pathname = useLocation({ select: (location) => location.pathname });
704 - const { clearOpenIntent, openIntent, openOverlayMode, setOpen } = props;
705 - const [query, setQuery] = useState(openIntent?.kind === "search" ? openIntent.query : "");
706 - const [linkedThreadSearch, setLinkedThreadSearch] = useState(
707 - openIntent?.kind === "search" ? openIntent : null,
719 + const { clearOpenIntent, openIntent, openChildSearch, setOpen } = props;
720 + const initialSearch = props.initialContext ?? {
721 + query: openIntent?.kind === "search" ? openIntent.query : "",
722 + linkedThreadSearch: openIntent?.kind === "search" ? openIntent : null,
723 + };
724 + const [searchState, dispatchSearch] = useReducer(
725 + reduceCommandPaletteSearchState,
726 + initialSearch.query,
727 + createCommandPaletteSearchState,
728 );
729 + const { query, views: viewStack } = searchState;
730 + const setQuery = (query: string) => dispatchSearch({ type: "query", query });
731 + const [linkedThreadSearch, setLinkedThreadSearch] = useState(initialSearch.linkedThreadSearch);
732 const deferredQuery = useDeferredValue(query);
733 const isActionsOnly = deferredQuery.startsWith(">");
734 const [highlightedItemValue, setHighlightedItemValue] = useState<string | null>(null);
@@ -822,8 +845,7 @@ function OpenCommandPaletteDialog(props: {
845 );
846 }),
847 );
825 - const [viewStack, setViewStack] = useState<CommandPaletteView[]>([]);
826 - const currentView = viewStack.at(-1) ?? null;
848 + const currentView = viewStack.at(-1)?.view ?? null;
849 const environmentIds = environments
850 .filter((environment) => environment.connection.phase === "connected")
851 .map((environment) => environment.environmentId);
@@ -1280,27 +1302,11 @@ function OpenCommandPaletteDialog(props: {
1302 // highlight ref it writes.
1303 const pushPaletteView = useStableCallback((view: CommandPaletteView): void => {
1304 browseNavigation.invalidate();
1283 - setViewStack((previousViews) => [
1284 - ...previousViews,
1285 - {
1286 - addonIcon: view.addonIcon,
1287 - groups: view.groups,
1288 - ...(view.initialQuery ? { initialQuery: view.initialQuery } : {}),
1289 - },
1290 - ]);
1305 + dispatchSearch({ type: "push", view });
1306 highlightClearedRef.current = true;
1307 setHighlightedItemValue(null);
1293 - setQuery(view.initialQuery ?? "");
1308 });
1309
1296 - function pushView(item: CommandPaletteSubmenuItem): void {
1297 - pushPaletteView({
1298 - addonIcon: item.addonIcon,
1299 - groups: item.groups,
1300 - ...(item.initialQuery ? { initialQuery: item.initialQuery } : {}),
1301 - });
1302 - }
1303 -
1310 function popView(): void {
1311 browseNavigation.invalidate();
1312 setAddProjectCloneFlow(null);
@@ -1310,9 +1316,8 @@ function OpenCommandPaletteDialog(props: {
1316 } else if (newProjectFlow?.sourcesEnvironmentId) {
1317 setAddProjectEnvironmentId(newProjectFlow.sourcesEnvironmentId);
1318 }
1313 - setViewStack((previousViews) => previousViews.slice(0, -1));
1319 + dispatchSearch({ type: "back" });
1320 setHighlightedItemValue(null);
1315 - setQuery("");
1321 }
1322
1323 function handleQueryChange(nextQuery: string): void {
@@ -1783,7 +1788,7 @@ function OpenCommandPaletteDialog(props: {
1788 keepOpen: true,
1789 shortcutCommand: "filePicker.toggle",
1790 run: async () => {
1786 - openOverlayMode("files");
1791 + openChildSearch("files", { query, linkedThreadSearch });
1792 },
1793 });
1794
@@ -1796,7 +1801,7 @@ function OpenCommandPaletteDialog(props: {
1801 keepOpen: true,
1802 shortcutCommand: "projectSearch.toggle",
1803 run: async () => {
1799 - openOverlayMode("content");
1804 + openChildSearch("content", { query, linkedThreadSearch });
1805 },
1806 });
1807
@@ -1943,42 +1948,28 @@ function OpenCommandPaletteDialog(props: {
1948 // parent's intent and may navigate, so it runs after commit but before paint.
1949 const projectThreadItemCount = projectThreadItems.length;
1950 const applyOpenIntent = useEffectEvent((intent: CommandPaletteOpenIntent) => {
1951 + clearOpenIntent();
1952 + browseNavigation.invalidate();
1953 + cloneLookupGeneration.current += 1;
1954 + setIsRemoteProjectLookingUp(false);
1955 + setAddProjectEnvironmentId(null);
1956 + setAddProjectCloneFlow(null);
1957 + setNewProjectFlow(null);
1958 + setLinkedThreadSearch(intent.kind === "search" ? intent : null);
1959 + dispatchSearch({ type: "reset", query: intent.kind === "search" ? intent.query : "" });
1960 switch (intent.kind) {
1961 case "search":
1948 - browseNavigation.invalidate();
1949 - cloneLookupGeneration.current += 1;
1950 - setIsRemoteProjectLookingUp(false);
1951 - setAddProjectCloneFlow(null);
1952 - setNewProjectFlow(null);
1953 - setViewStack([]);
1954 - setLinkedThreadSearch(intent);
1955 - setQuery(intent.query);
1956 - clearOpenIntent();
1962 return;
1963 case "add-project":
1959 - clearOpenIntent();
1964 openAddProjectFlow();
1965 return;
1966 case "new-thread-in":
1963 - clearOpenIntent();
1964 - browseNavigation.invalidate();
1965 - setAddProjectCloneFlow(null);
1966 - setNewProjectFlow(null);
1967 - setViewStack([]);
1968 - setQuery("");
1967 pushPaletteView({
1968 addonIcon: <SquarePenIcon className={ADDON_ICON_CLASS} />,
1969 groups: [{ value: "projects", label: "Projects", items: projectThreadItems }],
1970 });
1971 return;
1972 case "change-theme":
1975 - clearOpenIntent();
1976 - browseNavigation.invalidate();
1977 - cloneLookupGeneration.current += 1;
1978 - setIsRemoteProjectLookingUp(false);
1979 - setAddProjectCloneFlow(null);
1980 - setNewProjectFlow(null);
1981 - setViewStack([]);
1973 pushPaletteView({
1974 addonIcon: <PaletteIcon className={ADDON_ICON_CLASS} />,
1975 groups: [{ value: "themes", label: "Change theme", items: [] }],
@@ -2604,7 +2595,7 @@ function OpenCommandPaletteDialog(props: {
2595 return;
2596 }
2597 if (sourcesEnvironmentId !== null) {
2607 - setViewStack((previousViews) => previousViews.slice(0, -1));
2598 + dispatchSearch({ type: "back" });
2599 }
2600 popView();
2601 startAddProjectSourceSelection(environmentId);
@@ -2984,7 +2975,7 @@ function OpenCommandPaletteDialog(props: {
2975 }
2976
2977 if (item.kind === "submenu") {
2987 - pushView(item);
2978 + pushPaletteView(item);
2979 return;
2980 }
2981