Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai a361b0c858 feat(vcs): submenu aim on repository rows of the multi-repository branch popup
Moving the pointer from a repository row toward its open branch list no
longer swaps the list for each repository row it crosses: like submenus of a
menu (menuAim), a row reached while heading for the list waits 300 ms, and
the list stays when the pointer enters it. The repository the window works
on is listed first; the others keep their order and colours.

Fixes #6152
2026-11-27 03:14:01 +08:00
4 змінених файлів з 165 додано та 2 видалено

No files matched your search

+101
Переглянути файл
@@ -0,0 +1,101 @@
/**
* Git Branches of a project with several repositories: the current repository is listed first,
* and moving the pointer from a repository row toward its open branch list keeps that list open
* while it crosses the other repository rows (like a submenu of a menu). Git is stubbed at the
* IPC layer.
*/
import type { Page } from "@playwright/test";
import { expect, stubDesktop, test } from "./fixtures";
const ROOTS = ["/dev/acme/app", "/dev/acme/lib", "/dev/acme/tools", "/dev/acme/web"];
async function openBranches(page: Page) {
await stubDesktop(page);
await page.evaluate(
async ({ roots }) => {
const h = window.__ipc.handlers;
const branch = (name: string, current = false) => ({
name,
current,
remote: false,
upstream: null,
ahead: 0,
behind: 0,
lastCommitMs: null,
commit: "1111111",
});
const repoName = (root: string) => root.split("/").pop()!;
h.vcs_roots = () =>
roots.map((root) => ({ root, operation: null, head: "main", headCommit: "1111111", hasRemotes: false }));
h.vcs_branch_info = () => ({
head: "main",
headCommit: "1111111",
upstream: null,
ahead: 0,
behind: 0,
operation: null,
});
h.vcs_status = () => [];
h.vcs_tags = () => [];
h.vcs_branches = (args: { repo?: string | null }) => [
branch("main", true),
branch(`only-${repoName(args?.repo ?? roots[0]!)}`),
];
const vcsModule = "/src/features/vcs/store.ts";
const { useVcs, refreshNow, loadBranches } = await import(/* @vite-ignore */ vcsModule);
// The window works on the third repository.
useVcs.setState({ available: true, root: roots[0], repo: roots[2], branchesLoaded: false });
await refreshNow();
await loadBranches();
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("vcs.branches");
},
{ roots: ROOTS },
);
const list = page.getByRole("listbox", { name: "Repositories and branches" });
await expect(list).toBeVisible();
return list;
}
const center = async (locator: ReturnType<Page["locator"]>) => {
const box = (await locator.boundingBox())!;
return { x: box.x + box.width / 2, y: box.y + box.height / 2, box };
};
test("multi-repository Git Branches lists the current repository first and keeps a branch list open on the way to it", async ({
workbench: page,
}) => {
const list = await openBranches(page);
const rows = list.getByRole("option").filter({ has: page.locator("[data-row-key^='repo:']") });
await expect(rows).toHaveCount(4);
await expect(rows.first()).toContainText("tools");
// Open the first repository's branches, then head diagonally into the list across the rows below.
const first = await center(rows.nth(0));
await page.mouse.move(first.x, first.y);
const branchesOfTools = page.getByRole("dialog", { name: "Branches of tools" });
await expect(branchesOfTools).toBeVisible();
const target = (await branchesOfTools.boundingBox())!;
const last = await center(rows.nth(3));
await page.mouse.move(target.x + 12, last.y, { steps: 12 });
await expect(branchesOfTools).toBeVisible();
await expect(branchesOfTools.getByText("only-tools", { exact: true })).toBeVisible();
// Moving straight onto another repository row switches to its branches.
const second = await center(rows.nth(1));
await page.mouse.move(second.x - 40, second.y);
await page.mouse.move(second.x - 60, second.y);
const branchesOfApp = page.getByRole("dialog", { name: "Branches of app" });
await expect(branchesOfApp).toBeVisible();
await expect(branchesOfTools).toBeHidden();
// Stopping on a row while heading for the open list switches only after a short delay.
const third = await center(rows.nth(2));
const appList = (await branchesOfApp.boundingBox())!;
await page.mouse.move(appList.x - 30, second.y);
await page.mouse.move(appList.x - 6, third.y);
await expect(branchesOfApp).toBeVisible();
await expect(page.getByRole("dialog", { name: "Branches of lib" })).toBeVisible();
await expect(branchesOfApp).toBeHidden();
});
+52 -2
Переглянути файл
@@ -25,6 +25,7 @@ import {
} from "@/ui";
import { useRowHeight } from "@/ui/density";
import type { PopupAnchor } from "@/ui/Popup";
import { isSubmenuAim, type MenuPointer } from "@/ui/menuAim";
import { useActiveRepository, useWidgetBranch } from "./activeRepository";
import {
buildBranchRows,
@@ -737,6 +738,14 @@ function MultiRepoPanel({
const { menuFor, setMenuFor, openTagMenu } = useBranchSubmenu();
const [repoMenu, setRepoMenu] = useState<{ root: string; el: HTMLElement; focus: boolean } | null>(null);
const listRef = useRef<HTMLDivElement>(null);
const aim = useRef<{
previous: MenuPointer | null;
pointer: MenuPointer | null;
moved: boolean;
pending: number | null;
timer?: ReturnType<typeof setTimeout>;
}>({ previous: null, pointer: null, moved: false, pending: null });
const repoMenuLabel = repoMenu ? tx`Branches of ${repoName(repoMenu.root)}` : "";
const searchRef = useRef<HTMLInputElement>(null);
/** Back from a repository's submenu to the search field. */
const closeRepoMenu = () => {
@@ -867,11 +876,52 @@ function MultiRepoPanel({
}
};
// The pointer on a repository opens its branches right away; elsewhere it closes them.
const hover = (i: number) => {
const applyHover = (i: number) => {
clearTimeout(aim.current.timer);
aim.current.pending = null;
setActive(i);
if (rows[i]?.type === "repo") openSub(i, false);
else setRepoMenu(null);
};
/** While the pointer heads for the open branch list, the rows it crosses wait (like submenus of a menu). */
const aiming = () => {
const { previous, pointer } = aim.current;
const popup = repoMenu && document.querySelector(`[data-popup][aria-label="${CSS.escape(repoMenuLabel)}"]`);
return !!popup && !!pointer && isSubmenuAim(previous, pointer, popup.getBoundingClientRect());
};
const deferHover = (i: number) => {
clearTimeout(aim.current.timer);
aim.current.pending = i;
aim.current.timer = setTimeout(() => applyHover(i), 300);
};
const hover = (i: number) => {
const fromPointer = aim.current.moved;
aim.current.moved = false;
const row = rows[i];
const openRepo = row?.type === "repo" && row.repo.root === repoMenu?.root;
if (fromPointer && repoMenu && !openRepo && aiming()) deferHover(i);
else applyHover(i);
};
// Pointer positions for the aim check, recorded before the rows see the move (capture phase).
useEffect(() => {
if (!repoMenu) return;
const onMove = (e: PointerEvent) => {
const a = aim.current;
if (a.pointer?.x === e.clientX && a.pointer.y === e.clientY) return;
a.previous = a.pointer;
a.pointer = { x: e.clientX, y: e.clientY };
a.moved = true;
if (a.pending === null) return;
const popup = document.querySelector(`[data-popup][aria-label="${CSS.escape(repoMenuLabel)}"]`);
if (popup?.contains(e.target as Node)) {
clearTimeout(a.timer);
a.pending = null;
} else if (!aiming()) applyHover(a.pending);
};
document.addEventListener("pointermove", onMove, true);
return () => document.removeEventListener("pointermove", onMove, true);
});
useEffect(() => () => clearTimeout(aim.current.timer), []);
const onKeyDown = (e: KeyboardEvent) => {
if (isNewBranchStroke(strokeOf(e))) {
@@ -984,7 +1034,7 @@ function MultiRepoPanel({
placement="right-start"
offset={2}
autoFocus={repoMenu.focus}
aria-label={tx`Branches of ${repoName(repoMenu.root)}`}
aria-label={repoMenuLabel}
onClose={closeRepoMenu}
className={styles.popup}
>
+9
Переглянути файл
@@ -160,6 +160,15 @@ describe("buildMultiRepoRows", () => {
]);
});
it("lists the current repository first, keeping the others' order and colours", () => {
const rows = summary(buildMultiRepoRows({ ...input, current: "/p/ology-gateway", query: "" }));
expect(rows.filter((r) => r.startsWith("repo"))).toEqual([
"repo ology-gateway [dev] c3",
"repo ology-collect [dev] c1",
"repo ology-dependencies [dev] c2",
]);
});
it("groups common remote branches by remote when expanded", () => {
const expanded = new Map([
["common:local", false],
+3
Переглянути файл
@@ -215,6 +215,9 @@ export function buildMultiRepoRows({
if (m !== false)
repoRows.push({ type: "repo", key: `repo:${repo.root}`, repo, color: repoColorIndex(i), matches: m });
});
// The repository this window works on comes first; the others keep their order (and colours).
const currentRow = repoRows.findIndex((r) => r.type === "repo" && r.repo.root === current);
if (currentRow > 0) repoRows.unshift(...repoRows.splice(currentRow, 1));
blocks.push(repoRows);
/** A group row followed (when expanded) by its children; nothing when it has none. */