From 869b8a4f438f2005bc47e2eb155dc293c6e6370c Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:26:57 +0800 Subject: [PATCH] fix(vcs): anchor the Git Log path editor --- e2e/gitLogToolbarMenus.spec.ts | 93 +++++++++++++++++++ src/features/vcs/PathFilterDialog.module.css | 53 +++++++++++ src/features/vcs/PathFilterDialog.tsx | 95 ++++++++++++-------- src/features/vcs/log/FilterBar.tsx | 47 ++++++++-- 4 files changed, 246 insertions(+), 42 deletions(-) diff --git a/e2e/gitLogToolbarMenus.spec.ts b/e2e/gitLogToolbarMenus.spec.ts index d7bb22552..30bfd09e0 100644 --- a/e2e/gitLogToolbarMenus.spec.ts +++ b/e2e/gitLogToolbarMenus.spec.ts @@ -2,6 +2,7 @@ * Git Log toolbar buttons close their popup when clicked again, as in IDEA, instead of * keeping it open (Branch) or replaying its opening (the menus). Git is stubbed at the IPC layer. */ +import type { Page } from "@playwright/test"; import { expect, stubDesktop, test } from "./fixtures"; test.beforeEach(async ({ workbench: page }) => { @@ -60,6 +61,98 @@ test.beforeEach(async ({ workbench: page }) => { await expect(page.getByRole("listbox", { name: "Commits" }).getByRole("option").first()).toBeVisible(); }); +async function openLogPathEditor(page: Page) { + const toolbar = page.getByRole("toolbar", { name: "Log filters", exact: true }); + const filter = toolbar.getByRole("button", { name: /^Paths(:|$)/ }); + const overflow = toolbar.getByRole("button", { name: "More Filters", exact: true }); + const visible = await filter.isVisible(); + const anchor = visible ? filter : overflow; + await anchor.click(); + if (!visible) await page.getByRole("menuitem", { name: /^Paths(:|$)/ }).click(); + await page.getByRole("menuitem", { name: "Select…", exact: true }).click(); + const editor = page.getByRole("dialog", { name: "Filter by Paths", exact: true }); + await expect(editor.getByRole("textbox", { name: "Paths", exact: true })).toBeFocused(); + return { anchor, editor }; +} + +test("the Git Log path editor anchors to its filter and wraps long paths", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1220, height: 760 }); + await page.evaluate(async () => { + const logPath = "/src/features/vcs/logStore.ts"; + const optionsPath = "/src/features/vcs/logOptions.ts"; + const { setLogFilters } = await import(/* @vite-ignore */ logPath); + const { setLogOptions } = await import(/* @vite-ignore */ optionsPath); + setLogOptions({ showBranches: false, showDetails: false }); + setLogFilters({ + paths: ["/dev/acme-api/src/" + "settlement-".repeat(12) + "report.ts", "/dev/acme-api/docs/guide.md"], + }); + }); + const { anchor, editor } = await openLogPathEditor(page); + const input = editor.getByRole("textbox", { name: "Paths", exact: true }); + const popupBox = (await editor.boundingBox())!; + const anchorBox = (await anchor.boundingBox())!; + const gap = Math.min( + Math.abs(popupBox.y - anchorBox.y - anchorBox.height), + Math.abs(anchorBox.y - popupBox.y - popupBox.height), + ); + expect(gap).toBeLessThanOrEqual(6); + expect((await input.boundingBox())!.height).toBeGreaterThan(120); + expect(await input.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); + await expect(editor.getByText("One path per line", { exact: true })).toBeVisible(); + + const grip = (await editor.getByRole("separator", { name: "Resize", exact: true }).boundingBox())!; + const x = grip.x + grip.width / 2; + const y = grip.y + grip.height / 2; + await page.mouse.move(x, y); + await page.mouse.down(); + await page.mouse.move(x, y + 34, { steps: 4 }); + await page.mouse.up(); + await expect.poll(async () => (await editor.boundingBox())!.height).toBeGreaterThan(popupBox.height + 20); + await input.fill("src\ndocs/draft.md"); + await page.setViewportSize({ width: 460, height: 550 }); + const overflow = page.getByRole("toolbar", { name: "Log filters" }).getByRole("button", { name: "More Filters" }); + await expect(overflow).toBeVisible(); + await expect(input).toHaveValue("src\ndocs/draft.md"); + await expect(editor).toBeInViewport({ ratio: 0.98 }); + await input.press("Escape"); + await expect(editor).toHaveCount(0); +}); + +test("the narrow Git Log path editor applies with the primary shortcut and discards outside clicks", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 460, height: 550 }); + const { editor } = await openLogPathEditor(page); + const input = editor.getByRole("textbox", { name: "Paths", exact: true }); + await expect(editor.getByRole("separator", { name: "Resize", exact: true })).toBeVisible(); + await expect(editor.getByRole("button", { name: "OK", exact: true })).toBeInViewport({ ratio: 0.98 }); + const modifier = await page.evaluate(async () => { + const module = "/src/platform/keymap.ts"; + const { isMacHost } = await import(/* @vite-ignore */ module); + return isMacHost() ? "Meta" : "Control"; + }); + await input.fill("src"); + await input.press("End"); + await input.press("Enter"); + await expect(input).toHaveValue("src\n"); + await input.fill("../outside"); + await input.press(`${modifier}+Enter`); + await expect(editor.getByRole("alert")).toHaveText("Choose a path inside a repository."); + await input.fill("src\ndocs/guide.md\nsrc"); + await input.press(`${modifier}+Enter`); + await expect(editor).toHaveCount(0); + + const reopened = await openLogPathEditor(page); + await expect(input).toHaveValue("src\ndocs/guide.md"); + await input.fill("discarded"); + await page.mouse.click(4, 4); + await expect(reopened.editor).toHaveCount(0); + const again = await openLogPathEditor(page); + await expect(input).toHaveValue("src\ndocs/guide.md"); + await again.anchor.click(); + await expect(again.editor).toHaveCount(0); +}); + test("Git Log separates commit message typography from compact metadata", async ({ workbench: page }) => { await page.setViewportSize({ width: 860, height: 720 }); await page.evaluate(() => { diff --git a/src/features/vcs/PathFilterDialog.module.css b/src/features/vcs/PathFilterDialog.module.css index 5c739844e..5af188966 100644 --- a/src/features/vcs/PathFilterDialog.module.css +++ b/src/features/vcs/PathFilterDialog.module.css @@ -68,3 +68,56 @@ overflow-wrap: anywhere; color: var(--danger); } + +.editor { + display: flex; + flex-direction: column; + overflow: hidden; +} + +.pathInput { + flex: 1; + min-height: 0; + width: 100%; + padding: var(--space-2) var(--space-3); + resize: none; + border: 0; + outline: none; + background: var(--bg-editor); + color: var(--fg-editor); + font-family: var(--font-mono); + font-size: var(--fs-code); + line-height: var(--lh-code); + white-space: pre-wrap; + overflow-wrap: anywhere; +} + +.pathInput:focus-visible { + box-shadow: inset 0 0 0 1px var(--focus-ring); +} + +.editorError { + flex: none; + padding: var(--space-1) var(--space-2); + color: var(--danger); +} + +.editorFooter { + flex: none; + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: space-between; + gap: var(--space-1) var(--space-2); + padding: var(--space-1) var(--space-2); + border-top: 1px solid var(--border-popup); + color: var(--fg-secondary); + font-size: var(--fs-small); +} + +.apply { + display: inline-flex; + align-items: center; + gap: var(--space-2); + margin-inline-start: auto; +} diff --git a/src/features/vcs/PathFilterDialog.tsx b/src/features/vcs/PathFilterDialog.tsx index b534bc8ac..ee794fc3e 100644 --- a/src/features/vcs/PathFilterDialog.tsx +++ b/src/features/vcs/PathFilterDialog.tsx @@ -1,11 +1,13 @@ -import { useState } from "react"; -import { Checkbox, Dialog, Icon, SearchField, Tree, fileIconName } from "@/ui"; +import { useId, useState } from "react"; +import { Button, Checkbox, Dialog, Icon, Popup, T, Tree, fileIconName } from "@/ui"; import { projectFs } from "@/features/project-tree/fs"; import { openDialog } from "./dialogs"; import { dirName, relTo, stripSlash } from "./model"; import { repoName, repoOf } from "./store"; import { call, commands } from "@/platform/ipc"; import { tx } from "@/platform/i18n"; +import { isImeKey } from "@/platform/ime"; +import { formatBinding, hasPrimaryModifier, isMacHost } from "@/platform/keymap"; import { ipcPath, isSameOrInside } from "@/platform/paths"; import styles from "./PathFilterDialog.module.css"; @@ -31,42 +33,33 @@ export function chooseLogPaths(roots: string[], initial: string[], readOnly = fa }); } -export function editLogPaths(roots: string[], initial: string[]): Promise { +function commonRoot(roots: string[]): string | undefined { let base = roots[0]; while (base && !roots.every((root) => isSameOrInside(root, base!))) { const parent = dirName(base); base = parent || (base.startsWith("/") && base !== "/" ? "/" : undefined); } - return new Promise((resolve) => { - const close = openDialog(() => ( - { - close(); - resolve(value); - }} - /> - )); - }); + return base; } -function LogPathsEditor({ +export function LogPathsEditor({ + anchor, roots, initial, - base, onDone, }: { + anchor: HTMLElement; roots: string[]; initial: string[]; - base?: string; onDone: (value: string[] | null) => void; }) { + const [base] = useState(() => commonRoot(roots)); const [text, setText] = useState(() => initial.map((path) => (base ? (path === base ? "." : relTo(stripSlash(base), path)) : path)).join("\n"), ); const [error, setError] = useState(false); + const hint = useId(); + const shortcut = formatBinding(isMacHost() ? "Meta+Enter" : "Ctrl+Enter"); const apply = () => { const paths = text .split("\n") @@ -88,30 +81,62 @@ function LogPathsEditor({ onDone([...new Set(paths)]); }; return ( - onDone(null)} - buttons={[ - { label: "OK", role: "default", onClick: apply }, - { label: "Cancel", role: "cancel" }, - ]} > - { - setText(value); + onChange={(event) => { + setText(event.target.value); setError(false); }} - aria-label="Paths" - placeholder="One path per line" + onKeyDown={(event) => { + if ( + event.key !== "Enter" || + !hasPrimaryModifier(event) || + event.shiftKey || + event.altKey || + isImeKey(event.nativeEvent) + ) { + return; + } + event.preventDefault(); + event.stopPropagation(); + apply(); + }} + aria-label={tx("Paths")} + aria-describedby={hint} + aria-invalid={error || undefined} /> - {error &&
{tx("Choose a path inside a repository.")}
} -
+ {error && ( +
+ Choose a path inside a repository. +
+ )} +
+ + One path per line + + + {shortcut} + + +
+ ); } diff --git a/src/features/vcs/log/FilterBar.tsx b/src/features/vcs/log/FilterBar.tsx index ca3b417b5..ce0f5299b 100644 --- a/src/features/vcs/log/FilterBar.tsx +++ b/src/features/vcs/log/FilterBar.tsx @@ -27,7 +27,7 @@ import { } from "../logStore"; import { relTo } from "../model"; import { branchesByRepo } from "../multiRoot"; -import { chooseLogPaths, editLogPaths } from "../PathFilterDialog"; +import { LogPathsEditor, chooseLogPaths } from "../PathFilterDialog"; import { openExternalLog } from "../RevisionBrowser"; import { currentRepo, repoName, useVcs } from "../store"; import { useDropdownMenu, useLogRepositories, useReadOnlyLog } from "./logHooks"; @@ -51,13 +51,21 @@ interface LogFilter { onClear: () => void; } -function FilterButton({ label, value, onOpen, onClear, hidden }: LogFilter & { hidden?: boolean }) { +function FilterButton({ + label, + value, + onOpen, + onClear, + hidden, + triggerRef, +}: LogFilter & { hidden?: boolean; triggerRef?: (button: HTMLButtonElement | null) => void }) { return (