Файли
openidea/e2e/windowGroupTabDrag.spec.ts
T
l0ng-ai da7125a944 fix(workbench): show ghost and insertion indicator when dragging project tabs (#6135)
## What and why

Reordering project window tabs in `WindowGroupTabs` previously gave almost no visual feedback: the dragged tab only dimmed in place (`opacity: 0.55`) with no drag ghost, no drop-target indicator, no grabbing cursor or `Escape` cancel, and it waited for the backend IPC round-trip before updating the tab order.

This switches `WindowGroupTabs` onto the shared pointer drag-and-drop pipeline (`startPointerDrag`, `registerDropTarget`, and `dropIndex`) matching tool window stripes and tab strips:
- Shows a translucent ghost following the pointer (dimming when outside the tab bar) while keeping the source tab dimmed in place (`opacity: 0.4`) and hiding hover close/detach buttons during the drag.
- Marks the exact drop target with a 2px `var(--accent)` vertical insertion line (omitted on adjacent no-op slots).
- Optimistically applies the new tab order on drop (rolling back via `refreshWindowGroup()` on failure), swallows the trailing `click`, cancels cleanly on `Escape`, and respects `dragRequiresAlt()`.

## How it was verified

- `pnpm vitest run src/workbench/WindowGroupTabs.test.tsx src/platform/windowGroups.test.ts` — 2 test files, 13 tests passed.
- `OPENIDEA_E2E_PORT=1459 pnpm e2e e2e/windowGroupTabDrag.spec.ts e2e/windowGroupTabColor.spec.ts` — 2 Playwright E2E specs passed (both new drag feedback/reorder/cancel coverage and existing tinted-tab hover regression).
- `pnpm typecheck` — passed across all workspace tsconfigs including `e2e`.
- `pnpm exec oxfmt --check src/workbench/WindowGroupTabs.tsx src/workbench/WindowGroupTabs.module.css src/workbench/WindowGroupTabs.test.tsx e2e/windowGroupTabDrag.spec.ts` — passed.

## Review focus

- `projectTabDropTarget` mapping between `dropIndex` (`0..count`) and `reorderedTabs` target indices in `src/workbench/WindowGroupTabs.tsx`.
- `.dropBefore::before` / `.dropAfter::after` styling in `src/workbench/WindowGroupTabs.module.css` alongside the existing tab separator rule.

Made with [Cursor](https://cursor.com)
2026-11-26 20:42:49 +08:00

69 рядки
3.1 KiB
TypeScript

import { expect, test } from "./fixtures";
test("dragging a project tab shows a ghost and accent insertion line, and reorders on drop", async ({
workbench: page,
}) => {
await page.evaluate(async () => {
const windowGroups = "/src/platform/windowGroups.ts";
const { useWindowGroup } = await import(/* @vite-ignore */ windowGroups);
useWindowGroup.setState({
tabs: [
{ label: "first", name: "idea", root: "/first", current: true },
{ label: "second", name: "kalopilot-assistant-stack", root: "/second", current: false },
{ label: "third", name: "kalopilot", root: "/third", current: false },
],
});
});
const tablist = page.locator('[data-window-group] [role="tablist"]');
const first = tablist.locator('[data-project-tab="first"]');
const second = tablist.locator('[data-project-tab="second"]');
const third = tablist.locator('[data-project-tab="third"]');
await expect(third).toBeVisible();
const firstBox = (await first.boundingBox())!;
const secondBox = (await second.boundingBox())!;
const thirdBox = (await third.boundingBox())!;
const startY = firstBox.y + firstBox.height / 2;
await page.mouse.move(firstBox.x + firstBox.width / 2, startY);
await page.mouse.down();
// Past the middle tab's centre: source dims, ghost follows pointer, insertion line marks before third tab.
await page.mouse.move(secondBox.x + secondBox.width * 0.7, startY, { steps: 8 });
await expect(tablist).toHaveAttribute("data-dragging", "");
expect(Number(await first.evaluate((el) => getComputedStyle(el).opacity))).toBeCloseTo(0.4, 1);
const ghost = page.locator('body > div > [aria-hidden="true"][data-project-tab="first"]');
await expect(ghost).toBeVisible();
expect(await third.evaluate((el) => getComputedStyle(el, "::before").width)).toBe("2px");
// Past the last tab's centre: insertion line moves to the trailing edge.
await page.mouse.move(thirdBox.x + thirdBox.width * 0.75, startY, { steps: 6 });
expect(await third.evaluate((el) => getComputedStyle(el, "::after").width)).toBe("2px");
await page.mouse.up();
await expect(tablist).not.toHaveAttribute("data-dragging");
await expect(ghost).toHaveCount(0);
const order = await tablist
.locator("[data-project-tab]")
.evaluateAll((els) => els.map((el) => el.getAttribute("data-project-tab")));
expect(order).toEqual(["second", "third", "first"]);
await expect(first.locator('[role="tab"]')).toHaveAttribute("aria-selected", "true");
// Pressing Escape cancels without reordering.
const box = (await first.boundingBox())!;
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
await page.mouse.move(firstBox.x + 20, box.y + box.height / 2, { steps: 6 });
await expect(tablist).toHaveAttribute("data-dragging", "");
await page.keyboard.press("Escape");
await page.mouse.up();
await expect(tablist).not.toHaveAttribute("data-dragging");
const orderAfterCancel = await tablist
.locator("[data-project-tab]")
.evaluateAll((els) => els.map((el) => el.getAttribute("data-project-tab")));
expect(orderAfterCancel).toEqual(["second", "third", "first"]);
});