Skip to content

Commit cb563ef

Browse files
fix(web): the command palette highlights the first row of a new view again
Resetting only the list on a view change kept the old highlight index, so opening New thread in... from the second root row highlighted the second project. The palette remounts on a view change again, as on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bc9aace commit cb563ef

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

‎apps/web/src/components/CommandPalette.browser.test.tsx‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
22
import { describe, expect, it, vi } from "vite-plus/test";
3-
import { page } from "vite-plus/test/browser";
3+
import { page, userEvent } from "vite-plus/test/browser";
44

55
import { render } from "../../test/render";
66
import { openCommandPalette } from "../commandPaletteBus";
@@ -35,6 +35,39 @@ describe("CommandPalette open intents", () => {
3535
await expect.element(page.getByPlaceholder("Search...")).toHaveFocus();
3636
});
3737

38+
it("highlights the first project when New thread in... opens from the root list", async () => {
39+
const environmentId = EnvironmentId.make("local");
40+
const project = (id: string, title: string): Project => ({
41+
id: ProjectId.make(id),
42+
environmentId,
43+
title,
44+
workspaceRoot: `/work/${id}`,
45+
repositoryIdentity: null,
46+
defaultModelSelection: null,
47+
createdAt: "2026-03-01T00:00:00.000Z",
48+
updatedAt: "2026-03-01T00:00:00.000Z",
49+
scripts: [],
50+
});
51+
setup({
52+
projects: [project("acme", "Acme"), project("beta", "Beta"), project("gamma", "Gamma")],
53+
});
54+
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
55+
56+
openCommandPalette({});
57+
await expect
58+
.element(page.getByPlaceholder("Search commands, projects, and threads..."))
59+
.toHaveFocus();
60+
await userEvent.keyboard("{ArrowDown}");
61+
await expect
62+
.element(page.getByRole("option", { name: /^New thread in\.\.\./ }))
63+
.toHaveAttribute("data-highlighted");
64+
await userEvent.keyboard("{Enter}");
65+
66+
await expect.element(page.getByPlaceholder("Search...")).toHaveFocus();
67+
await expect.element(page.getByRole("option").first()).toHaveAttribute("data-highlighted");
68+
await expect.element(page.getByRole("option").nth(1)).not.toHaveAttribute("data-highlighted");
69+
});
70+
3871
it("opens a search intent with its query in the focused input", async () => {
3972
setup();
4073
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2831,6 +2831,7 @@ function OpenCommandPaletteDialog(props: {
28312831

28322832
return (
28332833
<CommandPaletteContent
2834+
key={`${viewStack.length}-${browseGeneration}-${isBrowsing}-${newProjectFlow ? "new-project" : (addProjectCloneFlow?.step ?? "none")}`}
28342835
aria-label="Command palette"
28352836
autoHighlight={autoHighlightsFirstRow ? "always" : false}
28362837
footerActionLabel={footerActionLabel}
@@ -2911,7 +2912,6 @@ function OpenCommandPaletteDialog(props: {
29112912
) : null}
29122913
<CommandPaletteVirtualizedResults
29132914
rows={resultRows.rows}
2914-
dataKey={`${viewStack.length}-${browseGeneration}-${isBrowsing}-${newProjectFlow ? "new-project" : (addProjectCloneFlow?.step ?? "none")}`}
29152915
listRef={resultListRef}
29162916
highlightedItemValue={highlightedItemValue}
29172917
isActionsOnly={isActionsOnly}

‎apps/web/src/components/CommandPaletteResults.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export function scrollCommandPaletteRowIntoView(list: LegendListRef | null, rowI
8888
interface CommandPaletteVirtualizedResultsProps extends Omit<CommandPaletteResultsProps, "groups"> {
8989
rows: ReadonlyArray<CommandPaletteRow>;
9090
listRef: RefObject<LegendListRef | null>;
91-
dataKey: string;
9291
}
9392

9493
/** Pass flat items with virtualized to Command, scroll highlights via listRef, and handle Enter for
@@ -116,7 +115,6 @@ export function CommandPaletteVirtualizedResults(props: CommandPaletteVirtualize
116115
<LegendList<CommandPaletteRow>
117116
ref={scrollRef}
118117
data={props.rows}
119-
dataKey={props.dataKey}
120118
initialScrollOffset={0}
121119
keyExtractor={(row) => row.key}
122120
getItemType={(row) => row.kind}

0 commit comments

Comments
 (0)