Skip to content

Commit 645df45

Browse files
only21milcodexmaria-rcks
authored
fix(web): keep add-project inputs open during IME composition (#24016)
Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 7f005d4 commit 645df45

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
import { page, userEvent } from "vite-plus/test/browser";
3+
import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
4+
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
5+
import { act, render } from "../../test/render";
6+
import { CommandPalette } from "./CommandPalette";
7+
import { openCommandPalette } from "../commandPaletteBus";
8+
import { primaryServerKeybindingsAtom } from "../state/server";
9+
10+
vi.mock("@effect/atom-react", async (original) => ({
11+
...(await original<typeof import("@effect/atom-react")>()),
12+
useAtomValue: (atom: unknown) =>
13+
atom === primaryServerKeybindingsAtom ? DEFAULT_RESOLVED_KEYBINDINGS : [],
14+
}));
15+
vi.mock("../hooks/useTheme", () => ({
16+
useRenderedAppearance: () => "light",
17+
useTheme: () => ({ theme: "t3-chat", resolvedTheme: "light", appearanceMode: "light" }),
18+
}));
19+
vi.mock("../hooks/useCustomThemes", () => ({ useCustomThemes: () => [] }));
20+
vi.mock("../hooks/useEnvironmentTheme", () => ({ useEnvironmentThemeDefinitions: () => [] }));
21+
vi.mock("../hooks/useSettings", async (original) => ({
22+
...(await original<typeof import("../hooks/useSettings")>()),
23+
useClientSettings: () => DEFAULT_CLIENT_SETTINGS,
24+
}));
25+
vi.mock("../hooks/useScratchProject", () => ({
26+
useScratchProject: () => ({ scratchEnvironmentId: () => null }),
27+
}));
28+
vi.mock("../hooks/useNewProject", () => ({ useNewProject: () => async () => undefined }));
29+
vi.mock("../hooks/useHandleNewThread", () => ({
30+
useHandleNewThread: () => ({
31+
activeDraftThread: null,
32+
activeThread: null,
33+
defaultProjectRef: null,
34+
handleNewThread: async () => undefined,
35+
}),
36+
useNewThreadHandler: () => async () => undefined,
37+
}));
38+
vi.mock("../hooks/useOpenPanelPullRequestUrl", () => ({ useOpenPanelPullRequestUrl: () => null }));
39+
vi.mock("../connection/useDesktopLocalBootstraps", () => ({ useDesktopLocalBootstraps: () => [] }));
40+
vi.mock("../state/use-atom-command", () => ({
41+
useAtomCommand: () => async () => ({ _tag: "Success", value: undefined }),
42+
}));
43+
vi.mock("../state/use-atom-query-runner", () => ({
44+
useAtomQueryRunner: () => async () => ({ _tag: "Success", value: undefined }),
45+
}));
46+
vi.mock("../state/environments", async (original) => ({
47+
...(await original<typeof import("../state/environments")>()),
48+
useEnvironments: () => ({
49+
environments: [
50+
{
51+
environmentId: "local",
52+
label: "Local",
53+
connection: { phase: "connected" },
54+
entry: { target: { _tag: "PrimaryConnectionTarget" } },
55+
serverConfig: {
56+
environment: { platform: { os: "linux" }, capabilities: { projectCloneTracking: true } },
57+
settings: { addProjectBaseDirectory: "/workspace/" },
58+
},
59+
},
60+
],
61+
}),
62+
usePrimaryEnvironmentId: () => "local",
63+
useEnvironmentProviders: () => new Map(),
64+
}));
65+
vi.mock("../state/entities", async (original) => ({
66+
...(await original<typeof import("../state/entities")>()),
67+
useProjects: () => [],
68+
useThreadShells: () => [],
69+
useServerConfigs: () => new Map(),
70+
waitForProject: async () => undefined,
71+
}));
72+
vi.mock("../state/queries", async (original) => ({
73+
...(await original<typeof import("../state/queries")>()),
74+
useThreadSearch: (_environmentIds: unknown, query: string) => ({
75+
matches: [],
76+
query,
77+
isPending: false,
78+
}),
79+
}));
80+
vi.mock("../state/session", async (original) => ({
81+
...(await original<typeof import("../state/session")>()),
82+
useEnvironmentScope: () => true,
83+
readEnvironmentScope: () => true,
84+
}));
85+
vi.mock("../state/filesystem", async (original) => ({
86+
...(await original<typeof import("../state/filesystem")>()),
87+
useFilesystemReadAccess: () => ({ canReadFiles: true, isPending: false, error: null }),
88+
}));
89+
vi.mock("../state/query", async (original) => ({
90+
...(await original<typeof import("../state/query")>()),
91+
useEnvironmentQuery: () => ({ data: undefined, isLoading: false }),
92+
}));
93+
vi.mock("./settings/useAvailableSettingsSearchItems", () => ({
94+
useAvailableSettingsSearchItems: () => [],
95+
}));
96+
97+
// The real palette and Base UI input must agree that confirming composition is typing.
98+
describe.each(["repository", "folder", "destination"] as const)("add-project %s", (step) => {
99+
it.each([
100+
{ isComposing: true, keyCode: 13 },
101+
{ isComposing: false, keyCode: 229 },
102+
])("keeps Enter in the input during composition: %j", async (composition) => {
103+
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
104+
await act(() => openCommandPalette({ open: "add-project" }));
105+
await page.getByText(step === "folder" ? "Local folder" : "Git URL", { exact: true }).click();
106+
const input = () => page.getByRole("combobox");
107+
if (step === "destination") {
108+
await input().fill("https://example.com/team/project.git");
109+
await userEvent.keyboard("{Enter}");
110+
}
111+
const value = step === "repository" ? "https://example.com/team/計画.git" : "/workspace/計画";
112+
await input().fill(value);
113+
const event = new KeyboardEvent("keydown", {
114+
key: "Enter",
115+
bubbles: true,
116+
cancelable: true,
117+
...composition,
118+
});
119+
await act(() => input().element().dispatchEvent(event));
120+
expect(event.defaultPrevented).toBe(false);
121+
await expect.element(input()).toHaveValue(value);
122+
if (step === "repository") {
123+
await userEvent.keyboard("{Enter}");
124+
await expect.element(input()).toHaveValue("/workspace/計画");
125+
} else {
126+
await userEvent.keyboard("{Enter}");
127+
await expect.element(page.getByRole("combobox")).not.toBeInTheDocument();
128+
}
129+
});
130+
});

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,12 @@ function OpenCommandPaletteDialog(props: {
22872287
}
22882288

22892289
function handleKeyDown(event: KeyboardEvent<HTMLInputElement>): void {
2290+
if (event.key === "Enter" && (event.nativeEvent.isComposing || event.keyCode === 229)) {
2291+
// Confirming an IME candidate must not submit a path or select a row.
2292+
(event as typeof event & { preventBaseUIHandler?: () => void }).preventBaseUIHandler?.();
2293+
return;
2294+
}
2295+
22902296
const command = resolveShortcutCommand(event, keybindings, {
22912297
platform: navigator.platform,
22922298
context: { modelPickerOpen: false, editableFocus: true },

0 commit comments

Comments
 (0)