diff --git a/e2e/usagesPopupLayout.spec.ts b/e2e/usagesPopupLayout.spec.ts index 11cbb6379b..3931ed5e0f 100644 --- a/e2e/usagesPopupLayout.spec.ts +++ b/e2e/usagesPopupLayout.spec.ts @@ -1,5 +1,113 @@ import { expect, test } from "./fixtures"; +test.use({ video: "on" }); + +test("Show Usages drags by the title bar, keeps its controls usable and stays inside the viewport", async ({ + workbench: page, +}) => { + await page.evaluate(async () => { + const usages = "/src/features/code-insight/usages.ts"; + const { useUsagesPopup } = await import(/* @vite-ignore */ usages); + const path = "/dev/app/src/Main.ts"; + useUsagesPopup.setState({ + open: true, + anchor: { x: 100, y: 100 }, + symbol: "run", + scope: "project", + groups: [ + { + path, + usages: Array.from({ length: 4 }, (_, line) => ({ path, line, col: 0, endCol: 3, text: "run();" })), + }, + ], + }); + }); + const popup = page.getByRole("dialog", { name: "Usages", exact: true }); + const title = popup.getByText("Usages of run", { exact: true }); + await expect(popup).toBeVisible(); + await popup.evaluate((el) => Promise.all(el.getAnimations().map((a) => a.finished))); + const before = (await popup.boundingBox())!; + await page.screenshot({ path: test.info().outputPath("usages-before-drag.png") }); + + // The empty space after the caption, where the reported drag failed. + const caption = (await title.locator("..").boundingBox())!; + const start = { x: caption.x + caption.width - 4, y: caption.y + caption.height / 2 }; + await page.mouse.move(start.x, start.y); + await page.mouse.down(); + await page.mouse.move(start.x + 120, start.y + 100, { steps: 5 }); + await page.mouse.up(); + await expect.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(before.x + 120, 0); + await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(before.y + 100, 0); + const moved = (await popup.boundingBox())!; + expect(moved.width).toBeCloseTo(before.width, 0); + expect(moved.height).toBeCloseTo(before.height, 0); + await page.screenshot({ path: test.info().outputPath("usages-after-drag.png") }); + + await popup.getByRole("button", { name: "Scope", exact: true }).click(); + await expect(page.getByRole("option", { name: "Project and Libraries", exact: true })).toBeVisible(); + await page.keyboard.press("Escape"); + await popup.getByRole("button", { name: "Show Preview", exact: true }).click(); + await expect(popup.getByRole("region", { name: "Preview", exact: true })).toBeVisible(); + await expect.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(moved.x, 0); + await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(moved.y, 0); + + const resizeBefore = (await popup.boundingBox())!; + const corner = (await popup.getByRole("separator", { name: "Resize" }).boundingBox())!; + await page.mouse.move(corner.x + 4, corner.y + 4); + await page.mouse.down(); + await page.mouse.move(corner.x + 84, corner.y + 64, { steps: 5 }); + await page.mouse.up(); + await expect.poll(async () => (await popup.boundingBox())!.width).toBeCloseTo(resizeBefore.width + 80, 0); + await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(resizeBefore.height + 60, 0); + expect((await popup.boundingBox())!.x).toBeCloseTo(moved.x, 0); + expect((await popup.boundingBox())!.y).toBeCloseTo(moved.y, 0); + + // Cancelling a press must release the drag before the next pointer move. + const cancelAt = (await title.boundingBox())!; + await page.mouse.move(cancelAt.x + 5, cancelAt.y + 5); + await page.mouse.down(); + await page.evaluate(() => window.dispatchEvent(new PointerEvent("pointercancel"))); + await page.mouse.move(cancelAt.x + 45, cancelAt.y + 25); + await page.mouse.up(); + expect((await popup.boundingBox())!.x).toBeCloseTo(moved.x, 0); + expect((await popup.boundingBox())!.y).toBeCloseTo(moved.y, 0); + + // A later drag starts at the new position and clamps at both sides of the viewport. + let handle = (await title.boundingBox())!; + await page.mouse.move(handle.x + 5, handle.y + 5); + await page.mouse.down(); + await page.mouse.move(-1000, -1000, { steps: 5 }); + await page.mouse.up(); + await expect.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(6, 0); + await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(6, 0); + + handle = (await title.boundingBox())!; + await page.mouse.move(handle.x + 5, handle.y + 5); + await page.mouse.down(); + await page.mouse.move(2400, 1600, { steps: 5 }); + await page.mouse.up(); + const viewport = page.viewportSize()!; + await expect + .poll(async () => { + const box = (await popup.boundingBox())!; + return box.x + box.width; + }) + .toBeCloseTo(viewport.width - 6, 0); + await expect + .poll(async () => { + const box = (await popup.boundingBox())!; + return box.y + box.height; + }) + .toBeCloseTo(viewport.height - 6, 0); + handle = (await title.boundingBox())!; + await page.mouse.move(handle.x + 5, handle.y + 5); + await page.mouse.down(); + await page.keyboard.press("Escape"); + await expect(popup).toHaveCount(0); + await expect(page.locator("[data-drag-cursor-surface]")).toHaveCount(0); + await page.mouse.up(); +}); + test("Show Usages distinguishes same-named files without losing the line or snippet", async ({ workbench: page }) => { await page.setViewportSize({ width: 480, height: 620 }); await page.evaluate(async () => { diff --git a/src/features/code-insight/UsagesPopup.module.css b/src/features/code-insight/UsagesPopup.module.css index 015c0542c7..dc89d477d0 100644 --- a/src/features/code-insight/UsagesPopup.module.css +++ b/src/features/code-insight/UsagesPopup.module.css @@ -5,6 +5,8 @@ overflow: hidden; } .header { + cursor: move; + touch-action: none; flex: none; display: flex; align-items: center; diff --git a/src/features/code-insight/UsagesPopup.tsx b/src/features/code-insight/UsagesPopup.tsx index 8b990f236b..734d80088d 100644 --- a/src/features/code-insight/UsagesPopup.tsx +++ b/src/features/code-insight/UsagesPopup.tsx @@ -188,6 +188,7 @@ function UsagesPopupInner() { onClose={close} aria-label="Usages" className={styles.popup} + draggable resizable="both" minWidth={MIN_WIDTH} minHeight={MIN_HEIGHT} @@ -204,7 +205,7 @@ function UsagesPopupInner() { data-scope={scope ?? undefined} onKeyDown={onKeyDown} > -