Files
openidea/e2e/dialogFocus.spec.ts
T
l0ng-ai 4392ffacf6 fix(ui): retain dialog focus and copy text through the native clipboard (#2403)
Refs #2381

- Dialogs: an editor opened behind a dialog (e.g. the new file's tab behind "Add File to Git") could take keyboard focus after the dialog opened, so Enter/Escape went to the editor. Dialogs now keep focus while they are the top layer.
- Copy Reference failed with NotAllowedError: the WebView clipboard requires user activation, which native menu actions and async work (resolving the reference) outlive. Text copies now go through a native clipboard_write_text command (NSPasteboard / Win32 / GTK), and every navigator.clipboard.writeText caller uses the shared helper. The command is allowed in restricted (untrusted) projects like the other clipboard commands.
2026-11-10 03:25:21 +08:00

30 lines
1.4 KiB
TypeScript

import { expect, openFromTree, test } from "./fixtures";
for (const key of ["Enter", "Escape"]) {
test(`confirmation keeps focus across a deferred editor focus until ${key}`, async ({ workbench: page }) => {
const editor = await openFromTree(page, "README.md");
const content = editor.locator(".cm-content");
await content.click();
const before = await content.innerText();
await page.evaluate(async () => {
const messages = "/src/workbench/messages.tsx";
const { confirm } = await import(/* @vite-ignore */ messages);
const content = document.querySelector<HTMLElement>(".cm-content")!;
void confirm({ title: "Add File to Git", message: "Add README.md?", ok: "Add" }).then((accepted: boolean) => {
document.body.dataset.confirmed = String(accepted);
});
requestAnimationFrame(() => {
content.focus();
document.body.dataset.focusAttempted = "true";
});
});
await expect(page.locator("body")).toHaveAttribute("data-focus-attempted", "true");
await expect(page.getByRole("button", { name: "Add", exact: true })).toBeFocused();
await page.keyboard.press(key);
await expect(page.getByRole("dialog", { name: "Add File to Git" })).toBeHidden();
await expect(page.locator("body")).toHaveAttribute("data-confirmed", String(key === "Enter"));
await expect(content).toBeFocused();
await expect(content).toHaveText(before!);
});
}