mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-23 08:49:33 -10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bef07d5a98 | ||
|
|
b44393a989 |
No files matched your search
@@ -19,6 +19,7 @@ export function ComparisonTree<F>({
|
||||
getColor,
|
||||
onOpen,
|
||||
inlineDiff = true,
|
||||
openDiff = (diff) => void openVcsDiff(diff),
|
||||
}: {
|
||||
tree: FileTreeNode<F>[];
|
||||
current: F | null;
|
||||
@@ -32,6 +33,8 @@ export function ComparisonTree<F>({
|
||||
onOpen?: () => void;
|
||||
/** Show the selected file's diff beside the tree; off where there is no room (a sidebar). */
|
||||
inlineDiff?: boolean;
|
||||
/** With `openOnActivate`: where a double-clicked file's diff opens (default: an editor tab). */
|
||||
openDiff?: (diff: DiffData) => void;
|
||||
}) {
|
||||
const [selected, setSelected] = useState<ReadonlySet<string>>(new Set());
|
||||
const [expanded, setExpanded] = useState<ReadonlySet<string> | null>(null);
|
||||
@@ -58,7 +61,7 @@ export function ComparisonTree<F>({
|
||||
onSelect(entry);
|
||||
const diff = diffFor(entry);
|
||||
if (openOnActivate && diff) {
|
||||
void openVcsDiff(diff);
|
||||
openDiff(diff);
|
||||
onOpen?.();
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/**
|
||||
* Push dialog: the files changed by the outgoing commits (the selected commit's, or all of
|
||||
* them), with the selected file's diff beside the tree. The diff stays inside the dialog,
|
||||
* which is modal. A single commit also shows its message, author and time.
|
||||
* them), with the selected file's diff beside the tree. Double-click or Enter opens the diff in
|
||||
* its own window, as IDEA does, since the dialog is modal and small. A single commit also shows
|
||||
* its message, author and time.
|
||||
*/
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import type { ChangedFile, Commit, RevisionChange } from "@/bindings";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { Button, IconButton, Spinner, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui";
|
||||
@@ -94,6 +96,8 @@ export function PushChanges({
|
||||
}}
|
||||
diffFor={(c) => c.diff}
|
||||
inlineDiff={!onSelectFile}
|
||||
openOnActivate
|
||||
openDiff={(diff) => void executeAction("vcs.showDiffInNewWindow", diff)}
|
||||
getColor={(c) => KIND_COLOR[c.kind === "untracked" ? "added" : c.kind]}
|
||||
ariaLabel="Changed files"
|
||||
renderDetails={(n) =>
|
||||
|
||||
@@ -2,7 +2,16 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import type { Commit } from "@/bindings";
|
||||
|
||||
const { files, combined } = vi.hoisted(() => ({ files: vi.fn(), combined: vi.fn() }));
|
||||
const { files, combined, executeAction } = vi.hoisted(() => ({
|
||||
files: vi.fn(),
|
||||
combined: vi.fn(),
|
||||
executeAction: vi.fn(async () => true),
|
||||
}));
|
||||
|
||||
vi.mock("@/platform/actions", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("@/platform/actions")>()),
|
||||
executeAction,
|
||||
}));
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
@@ -76,6 +85,18 @@ describe("Push dialog changes", () => {
|
||||
expect(localStorage.getItem("openidea.vcs.push.groupByDirectory")).toBe("false");
|
||||
});
|
||||
|
||||
it("opens a double-clicked file's diff in its own window and keeps the selection's diff in the dialog", async () => {
|
||||
files.mockResolvedValue({ status: "ok", data: [{ path: "a.txt", oldPath: null, kind: "modified" }] });
|
||||
const select = vi.fn();
|
||||
render(<PushChanges repo="/r" commits={[older]} onSelectFile={select} />);
|
||||
fireEvent.doubleClick(await screen.findByText("a.txt"));
|
||||
expect(select).toHaveBeenLastCalledWith(expect.objectContaining({ path: "a.txt" }));
|
||||
expect(executeAction).toHaveBeenCalledWith(
|
||||
"vcs.showDiffInNewWindow",
|
||||
expect.objectContaining({ path: expect.stringContaining("a.txt") }),
|
||||
);
|
||||
});
|
||||
|
||||
it("shows no commit details for several commits", async () => {
|
||||
combined.mockResolvedValue({ status: "ok", data: [] });
|
||||
render(<PushChanges repo="/r" commits={[newer, older]} />);
|
||||
|
||||
@@ -68,6 +68,16 @@
|
||||
font-size: var(--fs-small);
|
||||
font-weight: 600;
|
||||
}
|
||||
.groupHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1-5);
|
||||
padding: 6px 16px 2px;
|
||||
color: var(--fg);
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
--icon-color: var(--fg-muted);
|
||||
}
|
||||
.badge {
|
||||
align-self: flex-start;
|
||||
margin-top: 1px;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createRef } from "react";
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import type { OpenProject, RecentProject } from "@/platform/ipc";
|
||||
import type { OpenProject, RecentProject, RecentProjectGroup } from "@/platform/ipc";
|
||||
import { remoteLocation } from "@/platform/remote";
|
||||
|
||||
const wsl = { kind: "wsl", distro: "Ubuntu-24.04" } as const;
|
||||
let open: OpenProject[] = [];
|
||||
let recent: RecentProject[] = [];
|
||||
let groups: RecentProjectGroup[] = [];
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
@@ -16,7 +17,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
commands: {
|
||||
...real.commands,
|
||||
recentProjects: async () => recent,
|
||||
recentProjectGroups: async () => [],
|
||||
recentProjectGroups: async () => groups,
|
||||
windowOpenProjects: async () => ({ status: "ok", data: open }),
|
||||
},
|
||||
};
|
||||
@@ -56,4 +57,34 @@ describe("ProjectPopup", () => {
|
||||
expect(text.indexOf("Recent Projects")).toBeLessThan(text.indexOf("other"));
|
||||
expect(within(list).getAllByText("FastAPIProject")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("lists recent projects under the Welcome screen's groups, collapsed or not, then the ungrouped ones", async () => {
|
||||
open = [{ name: "current", root: "/w/current", current: true, remote: null }];
|
||||
const project = (name: string, at: number): RecentProject => ({
|
||||
path: `/w/${name}`,
|
||||
name,
|
||||
openedAtMs: at,
|
||||
branch: null,
|
||||
});
|
||||
recent = [project("current", 9), project("example-web", 5), project("loose", 4), project("example-api", 3)];
|
||||
groups = [
|
||||
{ name: "Frontend", paths: ["/w/example-web"], expanded: true },
|
||||
{ name: "Backend", paths: ["/w/example-api", "/w/current"], expanded: false },
|
||||
];
|
||||
const anchor = createRef<HTMLButtonElement>();
|
||||
render(
|
||||
<>
|
||||
<button ref={anchor} />
|
||||
<ProjectPopup anchor={anchor} onClose={() => {}} />
|
||||
</>,
|
||||
);
|
||||
await screen.findByText("Frontend");
|
||||
const text = screen.getByRole("listbox").textContent ?? "";
|
||||
const order = ["Recent Projects", "Frontend", "example-web", "Backend", "example-api", "loose"];
|
||||
expect(order.map((t) => text.indexOf(t))).toEqual([...order.map((t) => text.indexOf(t))].sort((a, b) => a - b));
|
||||
expect(order.every((t) => text.includes(t))).toBe(true);
|
||||
// The open project stays under Open Projects only.
|
||||
expect(within(screen.getByRole("listbox")).getAllByText("current")).toHaveLength(1);
|
||||
expect(screen.getAllByRole("option").map((o) => o.textContent)).not.toContain("Frontend");
|
||||
});
|
||||
});
|
||||
@@ -5,14 +5,14 @@ import { call, commands, isTauri, type OpenProject, type RecentProject } from "@
|
||||
import { HighlightedText, Icon, Popup, showContextMenu, type IconName, T } from "@/ui";
|
||||
import type { ProjectPopupProps } from "@/workbench/contributions";
|
||||
import { askRemoveRecent, ProjectBadge, recentMenu, unavailableTitle } from "./RecentList";
|
||||
import { filterRecent, loadRecent, openRecent, useRecent, type RecentMatch } from "./recent";
|
||||
import { filterRecent, loadRecent, openRecent, recentRows, useRecent, type RecentMatch } from "./recent";
|
||||
import styles from "./ProjectPopup.module.css";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { parseRemoteLocation, remoteLocation } from "@/platform/remote";
|
||||
|
||||
type Entry =
|
||||
| { kind: "action"; id: string; label: string; icon: IconName }
|
||||
| { kind: "project"; open: boolean; m: RecentMatch };
|
||||
| { kind: "project"; open: boolean; m: RecentMatch; group?: string | null };
|
||||
|
||||
const ACTIONS: { id: string; label: string; icon: IconName }[] = [
|
||||
{ id: "file.newProject", label: "New Project…", icon: "plus" },
|
||||
@@ -36,10 +36,14 @@ function useOpenProjects(): OpenProject[] {
|
||||
return open;
|
||||
}
|
||||
|
||||
/** The title bar project widget's popup, after IDEA's ProjectWidget: actions, open projects, recent projects; type to filter. */
|
||||
/**
|
||||
* The title bar project widget's popup, after IDEA's ProjectWidget: actions, open projects, recent
|
||||
* projects (under the Welcome screen's project groups, then the ungrouped ones); type to filter.
|
||||
*/
|
||||
export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
|
||||
const actions = useActions((s) => s.actions);
|
||||
const recent = useRecent((s) => s.projects);
|
||||
const groups = useRecent((s) => s.groups);
|
||||
const home = useRecent((s) => s.home);
|
||||
const openProjects = useOpenProjects();
|
||||
const [query, setQuery] = useState("");
|
||||
@@ -60,14 +64,17 @@ export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
|
||||
open: true,
|
||||
m,
|
||||
}));
|
||||
const rest = filterRecent(
|
||||
// Every group lists its projects here, collapsed on the Welcome screen or not; a search is flat.
|
||||
const expanded = groups.map((g) => ({ ...g, expanded: true }));
|
||||
const rest = recentRows(
|
||||
recent.filter((r) => !openPaths.has(r.path)),
|
||||
expanded,
|
||||
query,
|
||||
home,
|
||||
).map((m) => ({ kind: "project" as const, open: false, m }));
|
||||
).flatMap((r) => (r.kind === "project" ? [{ kind: "project" as const, open: false, m: r.m, group: r.group }] : []));
|
||||
const acts = query ? [] : ACTIONS.filter((a) => actions.has(a.id)).map((a) => ({ kind: "action" as const, ...a }));
|
||||
return [...acts, ...open, ...rest];
|
||||
}, [actions, recent, home, openProjects, query]);
|
||||
}, [actions, recent, groups, home, openProjects, query]);
|
||||
const current = Math.min(active, entries.length - 1);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -150,6 +157,7 @@ export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
|
||||
<T>Recent Projects</T>
|
||||
</Header>
|
||||
)}
|
||||
{e.kind === "project" && !e.open && <GroupBoundary entry={e} previous={entries[i - 1]} />}
|
||||
<div
|
||||
role="option"
|
||||
aria-selected={i === current}
|
||||
@@ -194,6 +202,26 @@ function Header({ first, children }: { first: boolean; children: ReactNode }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** A project group's name above its first project; a separator where the ungrouped projects start. */
|
||||
function GroupBoundary({
|
||||
entry,
|
||||
previous,
|
||||
}: {
|
||||
entry: Extract<Entry, { kind: "project" }>;
|
||||
previous: Entry | undefined;
|
||||
}) {
|
||||
const before = previous?.kind === "project" && !previous.open ? (previous.group ?? null) : null;
|
||||
const group = entry.group ?? null;
|
||||
if (group === before) return null;
|
||||
if (group === null) return <div className={styles.separator} role="separator" />;
|
||||
return (
|
||||
<div className={styles.groupHeader}>
|
||||
<Icon name="folder" size={14} />
|
||||
<span className={styles.label}>{group}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProjectRow({ m, active }: { m: RecentMatch; active: boolean }) {
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in new issue
Block a user