Skip to content
Open
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
1 change: 1 addition & 0 deletions apps/server/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
assert.equal(defaultsByCommand.get("modelPicker.toggle"), "mod+shift+m");
assert.equal(defaultsByCommand.get("sidebar.toggle"), "mod+b");
assert.equal(defaultsByCommand.get("rightPanel.toggle"), "mod+alt+b");
assert.equal(defaultsByCommand.get("project.add"), "alt+a");
assert.equal(defaultsByCommand.get("terminal.splitVertical"), "mod+shift+d");
assert.equal(defaultsByCommand.get("modelPicker.jump.1"), "mod+1");
assert.equal(defaultsByCommand.get("modelPicker.jump.9"), "mod+9");
Expand Down
75 changes: 75 additions & 0 deletions apps/web/src/components/CommandPalette.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { describe, expect, it, vi } from "vite-plus/test";
import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
import type { Thread } from "../types";
import {
buildNewThreadInGroups,
buildThreadActionItems,
enumerateCommandPaletteItems,
filterCommandPaletteGroups,
resetAddProjectFlowState,
shouldIgnoreAddProjectShortcut,
shouldResetPaletteFlowOnPop,
type CommandPaletteActionItem,
type CommandPaletteGroup,
} from "./CommandPalette.logic";

Expand Down Expand Up @@ -38,6 +43,76 @@ describe("enumerateCommandPaletteItems", () => {
const LOCAL_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
const PROJECT_ID = ProjectId.make("project-1");

describe("shouldIgnoreAddProjectShortcut", () => {
it("allows Alt+A from the editable search input while the new-task palette is open", () => {
expect(shouldIgnoreAddProjectShortcut({ paletteOpen: true, editableTarget: true })).toBe(false);
});

it("continues to ignore Alt+A from editors outside the palette", () => {
expect(shouldIgnoreAddProjectShortcut({ paletteOpen: false, editableTarget: true })).toBe(true);
});
});

describe("shouldResetPaletteFlowOnPop", () => {
it("resets a flow opened from a nested parent when its first view is popped", () => {
expect(shouldResetPaletteFlowOnPop(1, 2)).toBe(true);
});

it("keeps a flow active while popping between its own nested views", () => {
expect(shouldResetPaletteFlowOnPop(1, 3)).toBe(false);
});
});

describe("resetAddProjectFlowState", () => {
it("clears every piece of add-project state before opening another palette flow", () => {
const flowBaseDepthRef = { current: 2 as number | null };
const clearEnvironment = vi.fn();
const clearCloneFlow = vi.fn();

resetAddProjectFlowState({
flowBaseDepthRef,
clearEnvironment,
clearCloneFlow,
});

expect(clearEnvironment).toHaveBeenCalledOnce();
expect(clearCloneFlow).toHaveBeenCalledOnce();
expect(flowBaseDepthRef.current).toBeNull();
});
});

describe("buildNewThreadInGroups", () => {
it("includes Add project alongside projects for every new-thread picker entry point", () => {
const projectItem: CommandPaletteActionItem = {
kind: "action",
value: "new-thread-in:environment-1:project-1",
searchTerms: ["Project"],
title: "Project",
icon: null,
run: async () => undefined,
};
const addProjectAction: CommandPaletteActionItem = {
kind: "action",
value: "action:add-project",
searchTerms: ["Add project"],
title: "Add project",
icon: null,
shortcutCommand: "project.add",
run: async () => undefined,
};

const groups = buildNewThreadInGroups({
projectItems: [projectItem],
addProjectAction,
});

expect(groups.map((group) => group.value)).toEqual(["projects", "actions"]);
expect(groups[0]?.items).toEqual([projectItem]);
expect(groups[1]?.items).toEqual([addProjectAction]);
expect(groups[1]?.items[0]?.shortcutCommand).toBe("project.add");
});
});

function makeThread(overrides: Partial<Thread> = {}): Thread {
return {
id: ThreadId.make("thread-1"),
Expand Down
34 changes: 34 additions & 0 deletions apps/web/src/components/CommandPalette.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ export function enumerateCommandPaletteItems(
});
}

export function shouldResetPaletteFlowOnPop(
flowBaseDepth: number | null,
currentDepth: number,
): boolean {
return flowBaseDepth !== null && Math.max(0, currentDepth - 1) <= flowBaseDepth;
}

export function shouldIgnoreAddProjectShortcut(input: {
paletteOpen: boolean;
editableTarget: boolean;
}): boolean {
return input.editableTarget && !input.paletteOpen;
}

export function resetAddProjectFlowState(input: {
flowBaseDepthRef: { current: number | null };
clearEnvironment: () => void;
clearCloneFlow: () => void;
}): void {
input.clearCloneFlow();
input.clearEnvironment();
input.flowBaseDepthRef.current = null;
}

export function buildNewThreadInGroups(input: {
projectItems: ReadonlyArray<CommandPaletteActionItem>;
addProjectAction: CommandPaletteActionItem;
}): CommandPaletteGroup[] {
return [
{ value: "projects", label: "Projects", items: input.projectItems },
{ value: "actions", label: "Actions", items: [input.addProjectAction] },
];
}

export type CommandPaletteMode = "root" | "root-browse" | "submenu" | "submenu-browse";

export function filterBrowseEntries(input: {
Expand Down
Loading
Loading