Файли
openidea/e2e/csvDataFind.spec.ts
T
audichuang aad1588d5a fix(database): open the table search on Find in a CSV file's Data tab (#8322)
With a CSV file on its Data tab, Cmd/Ctrl+F opened the Find bar of the text editor hidden underneath: it counted matches in the text, but nothing in the table was selected. The Data view now claims find.inFile with registerKeyClaim, as Markdown Preview Only does, and opens and focuses the table's own search instead; Find Next / Previous step through the table's matches while that search is open. Replace, a Find bar left open on the text, the Value panel's JSON editor and other panes keep their own Find.

Co-authored-by: audichuang <[email protected]>
2026-12-06 22:57:16 +08:00

128 рядки
6.3 KiB
TypeScript

import type { Page } from "@playwright/test";
import { expect, test } from "./fixtures";
async function openFile(page: Page, path: string, text: string) {
await page.evaluate(
async ([path, text]) => {
const backendPath = "/src/editor/core/backend.ts";
const servicePath = "/src/workbench/contributions.ts";
const { docBackend } = await import(backendPath);
const { editorService } = await import(servicePath);
docBackend().files.set(path, text);
await editorService().openFile(path);
},
[path, text],
);
}
const PEOPLE = "name,city\nZhang Wei,Beijing\nLi Na,Shanghai\nWang Fang,Shenzhen\n";
test("⌘F in a CSV file's Data tab searches the table, not the hidden text", async ({ workbench: page }) => {
await openFile(page, "/dev/acme-api/people.csv", PEOPLE);
await page.getByRole("tab", { name: "Data", exact: true }).click();
const table = page.getByRole("grid", { name: "Table view of the file" });
await table.getByText("Shanghai", { exact: true }).click();
await page.keyboard.press("Meta+f");
const search = page.getByRole("search", { name: "Search in results" });
const field = search.getByRole("textbox", { name: "Search in results" });
await expect(field).toBeFocused();
await expect(page.getByRole("search", { name: "Find in file" })).toHaveCount(0);
await field.fill("Li Na");
await expect(search.locator("[aria-live]")).toHaveText("1/1");
await field.press("Escape");
await expect(search).toBeHidden();
await table.getByText("Shanghai", { exact: true }).click();
await page.keyboard.press("Meta+f");
await expect(field).toBeFocused();
await page.keyboard.type("Beijing");
await expect(field).toHaveValue("Beijing");
await table.getByText("Beijing", { exact: true }).click();
await page.keyboard.press("Meta+f");
await expect(field).toBeFocused();
await expect(field).toHaveValue("Beijing");
await page.getByRole("tab", { name: "Text", exact: true }).click();
await page.locator(".cm-content").click();
await page.keyboard.press("Meta+f");
await expect(page.getByRole("search", { name: "Find in file" })).toBeVisible();
});
test("⌘F right after choosing the Data tab opens the table search", async ({ workbench: page }) => {
await openFile(page, "/dev/acme-api/people.csv", PEOPLE);
await page.getByRole("tab", { name: "Data", exact: true }).click();
await expect(page.getByRole("grid", { name: "Table view of the file" })).toBeVisible();
await page.keyboard.press("Meta+f");
await expect(page.getByRole("textbox", { name: "Search in results" })).toBeFocused();
});
test("⌘G and ⇧⌘G step through the table's matches", async ({ workbench: page }) => {
await openFile(page, "/dev/acme-api/people.csv", PEOPLE + "Zhao Lei,Shanghai\n");
await page.getByRole("tab", { name: "Data", exact: true }).click();
const table = page.getByRole("grid", { name: "Table view of the file" });
await table.getByText("Beijing", { exact: true }).click();
await page.keyboard.press("Meta+f");
const search = page.getByRole("search", { name: "Search in results" });
await search.getByRole("textbox").fill("Shanghai");
const count = search.locator("[aria-live]");
await expect(count).toHaveText("1/2");
await page.keyboard.press("Meta+g");
await expect(count).toHaveText("2/2");
await table.getByText("Beijing", { exact: true }).click();
await page.keyboard.press("Meta+Shift+g");
await expect(count).toHaveText("1/2");
await expect(page.getByRole("search", { name: "Find in file" })).toHaveCount(0);
});
test("⌘G in a Find bar left open on the text still steps through the text", async ({ workbench: page }) => {
await openFile(page, "/dev/acme-api/people.csv", PEOPLE + "Zhao Lei,Shanghai\n");
await page.locator(".cm-content").click();
await page.keyboard.press("Meta+f");
const editorFind = page.getByRole("search", { name: "Find in file" });
const editorField = editorFind.getByRole("textbox").first();
await editorField.fill("Shanghai");
const editorCount = editorFind.locator("[aria-live]");
await expect(editorCount).toHaveText("1/2");
await page.getByRole("tab", { name: "Data", exact: true }).click();
await page.getByRole("grid", { name: "Table view of the file" }).getByText("Beijing", { exact: true }).click();
await page.keyboard.press("Meta+f");
const search = page.getByRole("search", { name: "Search in results" });
await search.getByRole("textbox").fill("Shanghai");
const count = search.locator("[aria-live]");
await expect(count).toHaveText("1/2");
await editorField.click();
await page.keyboard.press("Meta+g");
await expect(editorCount).toHaveText("2/2");
await expect(count).toHaveText("1/2");
});
test("⌘F in the Value panel still searches the value", async ({ workbench: page }) => {
await openFile(page, "/dev/acme-api/payloads.csv", 'id,payload\n1,"{""name"":""Ada""}"\n');
await page.getByRole("tab", { name: "Data", exact: true }).click();
const cell = page.getByRole("grid", { name: "Table view of the file" }).getByText('{"name":"Ada"}', { exact: true });
await cell.click({ button: "right" });
await page.getByText("Open in Value Editor", { exact: true }).click();
const panel = page.getByRole("complementary", { name: "Value panel" });
await panel.locator(".cm-content").click();
await page.keyboard.press("Meta+f");
await expect(panel.locator(".cm-search")).toBeVisible();
await expect(page.getByRole("search", { name: "Search in results" })).toHaveCount(0);
});
test("⌘F in another pane still opens that editor's Find bar", async ({ workbench: page }) => {
await openFile(page, "/dev/acme-api/people.csv", PEOPLE);
await page.getByRole("tab", { name: "Data", exact: true }).click();
await expect(page.getByRole("grid", { name: "Table view of the file" })).toBeVisible();
await page.evaluate(async () => {
const path = "/src/platform/actions.ts";
await (await import(/* @vite-ignore */ path)).executeAction("editor.splitRight");
});
const panes = page.locator("[data-pane-id]");
await expect(panes).toHaveCount(2);
await openFile(page, "/dev/acme-api/notes.txt", "Li Na lives in Shanghai\n");
await panes.last().locator(".cm-content").click();
await page.keyboard.press("Meta+f");
await expect(panes.last().getByRole("search", { name: "Find in file" })).toBeVisible();
await expect(page.getByRole("search", { name: "Search in results" })).toHaveCount(0);
});