mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-23 08:49:33 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
869b8a4f43 |
No files matched your search
@@ -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(() => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<string[] | null> {
|
||||
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(() => (
|
||||
<LogPathsEditor
|
||||
roots={roots}
|
||||
initial={initial}
|
||||
base={base}
|
||||
onDone={(value) => {
|
||||
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 (
|
||||
<Dialog
|
||||
<Popup
|
||||
open
|
||||
title="Filter by Paths"
|
||||
width={560}
|
||||
anchor={anchor}
|
||||
aria-label={tx("Filter by Paths")}
|
||||
className={styles.editor}
|
||||
initialSize={{ w: 432, h: 200 }}
|
||||
resizable="both"
|
||||
minWidth={200}
|
||||
minHeight={110}
|
||||
trapFocus
|
||||
onClose={() => onDone(null)}
|
||||
buttons={[
|
||||
{ label: "OK", role: "default", onClick: apply },
|
||||
{ label: "Cancel", role: "cancel" },
|
||||
]}
|
||||
>
|
||||
<SearchField
|
||||
<textarea
|
||||
data-autofocus
|
||||
multiline
|
||||
leadingIcon={null}
|
||||
className={styles.pathInput}
|
||||
spellCheck={false}
|
||||
value={text}
|
||||
onChange={(value) => {
|
||||
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 && <div role="alert">{tx("Choose a path inside a repository.")}</div>}
|
||||
</Dialog>
|
||||
{error && (
|
||||
<div className={styles.editorError} role="alert">
|
||||
<T>Choose a path inside a repository.</T>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.editorFooter}>
|
||||
<span id={hint}>
|
||||
<T>One path per line</T>
|
||||
</span>
|
||||
<span className={styles.apply}>
|
||||
<kbd>{shortcut}</kbd>
|
||||
<Button onClick={apply} size="small" variant="primary">
|
||||
OK
|
||||
</Button>
|
||||
</span>
|
||||
</div>
|
||||
</Popup>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<span
|
||||
className={clsx(styles.filterButton, value && styles.filterActive, hidden && styles.filterHidden)}
|
||||
inert={hidden}
|
||||
>
|
||||
<button
|
||||
ref={triggerRef}
|
||||
type="button"
|
||||
className={styles.filterMain}
|
||||
onClick={(e) => onOpen(e.currentTarget)}
|
||||
@@ -125,6 +133,11 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) {
|
||||
}, [repositories, filters.repositories, version, logGeneration]);
|
||||
const [text, setText] = useState(filters.text);
|
||||
const [branchAnchor, setBranchAnchor] = useState<HTMLElement | null>(null);
|
||||
const [pathEditor, setPathEditor] = useState<{ roots: string[]; initial: string[] } | null>(null);
|
||||
const [pathsTrigger, setPathsTrigger] = useState<HTMLButtonElement | null>(null);
|
||||
const [overflowTrigger, setOverflowTrigger] = useState<HTMLButtonElement | null>(null);
|
||||
const pathEditorAnchor = overflowTrigger ?? pathsTrigger;
|
||||
if (!active && pathEditor) setPathEditor(null);
|
||||
const [menuBelow, dropdown] = useDropdownMenu();
|
||||
// Filters that do not fit move behind a chevron, like a toolbar's overflow.
|
||||
const groupRef = useRef<HTMLSpanElement>(null);
|
||||
@@ -246,7 +259,13 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) {
|
||||
paths: [],
|
||||
repositories: selected.length === repositories.length ? [] : selected,
|
||||
});
|
||||
const closePathEditorAt = (anchor: HTMLElement) => {
|
||||
if (!pathEditor || pathEditorAnchor !== anchor) return false;
|
||||
setPathEditor(null);
|
||||
return true;
|
||||
};
|
||||
const openPaths = (anchor: HTMLElement) => {
|
||||
if (closePathEditorAt(anchor)) return;
|
||||
const modifier = isMacHost() ? "⌘" : "Ctrl";
|
||||
const repositoryItems: MenuItem[] =
|
||||
repositories.length > 1
|
||||
@@ -292,10 +311,7 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) {
|
||||
menuBelow(anchor, [
|
||||
{
|
||||
label: "Select…",
|
||||
run: async () => {
|
||||
const selected = await editLogPaths(pathRoots, paths);
|
||||
if (selected) selectPaths(selected);
|
||||
},
|
||||
run: () => setPathEditor({ roots: pathRoots, initial: paths }),
|
||||
},
|
||||
{
|
||||
label: "Select in Tree…",
|
||||
@@ -373,17 +389,24 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) {
|
||||
/>
|
||||
<span ref={groupRef} className={styles.filterGroup}>
|
||||
{logFilters.map((f, i) => (
|
||||
<FilterButton key={f.label} {...f} hidden={i >= hiddenFrom} />
|
||||
<FilterButton
|
||||
key={f.label}
|
||||
{...f}
|
||||
hidden={i >= hiddenFrom}
|
||||
triggerRef={f.label === "Paths" ? setPathsTrigger : undefined}
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
{hiddenFrom < logFilters.length && (
|
||||
<IconButton
|
||||
ref={setOverflowTrigger}
|
||||
icon="chevron-right"
|
||||
title="More Filters"
|
||||
size="small"
|
||||
aria-haspopup="menu"
|
||||
onClick={(e) => {
|
||||
const anchor = e.currentTarget;
|
||||
if (closePathEditorAt(anchor)) return;
|
||||
menuBelow(
|
||||
anchor,
|
||||
logFilters.slice(hiddenFrom).map((f) => ({
|
||||
@@ -396,6 +419,16 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) {
|
||||
)}
|
||||
</div>
|
||||
{dropdown}
|
||||
{pathEditor && pathEditorAnchor && (
|
||||
<LogPathsEditor
|
||||
{...pathEditor}
|
||||
anchor={pathEditorAnchor}
|
||||
onDone={(paths) => {
|
||||
setPathEditor(null);
|
||||
if (paths) selectPaths(paths);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{branchAnchor && (
|
||||
<BranchFilterPopup
|
||||
anchor={branchAnchor}
|
||||
|
||||
Reference in new issue
Block a user