mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 09:39:27 -10:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88572f2ec1 | ||
|
|
204a078432 | ||
|
|
ef051d9e31 |
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures";
|
||||
|
||||
test("Local History gives the diff room and keeps revision selection across layouts", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1180, height: 700 });
|
||||
await openFromTree(page, "build.gradle.kts");
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async () => {
|
||||
const file = "/dev/acme-api/build.gradle.kts";
|
||||
const entries = [
|
||||
{ id: "after", path: file, timestampMs: 2000, label: "Saved", size: 31, kind: "snapshot" },
|
||||
{ id: "before", path: file, timestampMs: 1000, label: "Original", size: 34, kind: "snapshot" },
|
||||
];
|
||||
window.__ipc.handlers.history_list_dir = () => ({ entries, deleted: [] });
|
||||
window.__ipc.handlers.history_content = ({ id }) =>
|
||||
id === "before" ? 'val reportMode = "summary"\n' : 'val reportMode = "detailed"\n';
|
||||
window.__ipc.handlers.vcs_file_mode = () => null;
|
||||
window.__ipc.handlers.fs_probe = () => ({ size: 32, binary: false, tooLarge: false });
|
||||
|
||||
const actionsModule = "/src/platform/actions.ts";
|
||||
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
|
||||
await executeAction("vcs.localHistory", file);
|
||||
});
|
||||
|
||||
const revisions = page.getByRole("listbox", { name: "Revisions" });
|
||||
await expect(revisions.getByRole("option", { name: /Saved/ })).toBeVisible();
|
||||
const separator = page.getByRole("separator", { name: "Revisions" });
|
||||
await expect(separator).toHaveAttribute("aria-orientation", "vertical");
|
||||
const initialWidth = (await revisions.boundingBox())!.width;
|
||||
await separator.press("ArrowLeft");
|
||||
await expect.poll(async () => (await revisions.boundingBox())!.width).toBeLessThan(initialWidth);
|
||||
|
||||
const original = revisions.getByRole("option", { name: /^Original/ });
|
||||
await original.click();
|
||||
await expect(original).toHaveAttribute("aria-selected", "true");
|
||||
await expect.poll(async () => ipcCalls(page, "history_content")).toContainEqual({ id: "before" });
|
||||
|
||||
await page.setViewportSize({ width: 480, height: 620 });
|
||||
await expect(separator).toHaveAttribute("aria-orientation", "horizontal");
|
||||
await expect(original).toHaveAttribute("aria-selected", "true");
|
||||
const diff = page.locator(".cm-mergeView").filter({ hasText: "summary" });
|
||||
await expect(diff).toBeVisible();
|
||||
const listBox = (await revisions.boundingBox())!;
|
||||
const diffBox = (await diff.boundingBox())!;
|
||||
expect(diffBox.y).toBeGreaterThanOrEqual(listBox.y + listBox.height);
|
||||
expect(diffBox.width).toBeGreaterThanOrEqual(listBox.width - 2);
|
||||
|
||||
await page.setViewportSize({ width: 1180, height: 700 });
|
||||
await expect(separator).toHaveAttribute("aria-orientation", "vertical");
|
||||
await expect(original).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
@@ -5,6 +5,9 @@
|
||||
display: flex;
|
||||
background: var(--bg-app);
|
||||
}
|
||||
.resizable {
|
||||
min-width: 0;
|
||||
}
|
||||
.sidebar {
|
||||
flex: none;
|
||||
width: 260px;
|
||||
@@ -18,7 +21,7 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: 0 8px 0 12px;
|
||||
padding: 0 var(--space-2) 0 var(--space-3);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.title {
|
||||
@@ -26,6 +29,14 @@
|
||||
color: var(--fg-emphasis);
|
||||
font-weight: 500;
|
||||
}
|
||||
.resizable .title {
|
||||
min-width: 0;
|
||||
font-size: var(--fs-ui);
|
||||
font-weight: 600;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.list {
|
||||
flex: 1;
|
||||
}
|
||||
@@ -35,14 +46,36 @@
|
||||
min-width: 0;
|
||||
gap: var(--space-0-5);
|
||||
}
|
||||
.time {
|
||||
color: var(--fg-emphasis);
|
||||
.resizable .entry {
|
||||
width: 100%;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.label {
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
.primaryRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1-5);
|
||||
color: var(--fg-strong);
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
.primary,
|
||||
.meta,
|
||||
.path,
|
||||
.deletedPath {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.meta,
|
||||
.path,
|
||||
.deletedPath {
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.meta {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.deletedPath {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
.diff {
|
||||
flex: 1;
|
||||
@@ -51,33 +84,11 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
.message {
|
||||
padding: 16px;
|
||||
padding: var(--space-4);
|
||||
color: var(--fg-faint);
|
||||
text-align: center;
|
||||
}
|
||||
.path,
|
||||
.deletedPath {
|
||||
color: var(--fg);
|
||||
font-size: var(--fs-small);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.deletedPath {
|
||||
color: var(--fg-muted);
|
||||
text-decoration: line-through;
|
||||
}
|
||||
.labelRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
min-width: 0;
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.labelName {
|
||||
font-size: var(--fs-small);
|
||||
font-weight: 500;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
.resizable .message {
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import type { HistoryEntry } from "@/bindings";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { relativePath, useProject } from "@/platform/project";
|
||||
import { Button, Icon, List, Spinner, T } from "@/ui";
|
||||
import { Button, Icon, List, Spinner, SplitGroup, SplitHandle, SplitPanel, T } from "@/ui";
|
||||
import { notifications, type EditorInput } from "@/workbench/contributions";
|
||||
import { DiffEditor } from "./DiffEditor";
|
||||
import { confirmDialog } from "./dialogs";
|
||||
@@ -70,6 +70,19 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) {
|
||||
const anchor = useRef(0);
|
||||
const previous = useRef(0);
|
||||
const pointer = useRef(false);
|
||||
const container = useRef<HTMLDivElement>(null);
|
||||
const [stacked, setStacked] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const el = container.current;
|
||||
if (!el || typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(([entry]) => {
|
||||
const width = entry?.contentRect.width;
|
||||
if (width) setStacked(width < 620);
|
||||
});
|
||||
observer.observe(el);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
const load = useCallback(() => {
|
||||
call(commands.historyListDir(path))
|
||||
@@ -197,9 +210,17 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) {
|
||||
const revertLabel = current && !isLabel(current) && view?.deleted.has(current.path) ? "Restore" : "Revert";
|
||||
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
<div
|
||||
className={styles.sidebar}
|
||||
<SplitGroup
|
||||
elementRef={container}
|
||||
className={`${styles.root} ${styles.resizable}`}
|
||||
orientation={stacked ? "vertical" : "horizontal"}
|
||||
storageKey="openidea.localHistory.layout"
|
||||
>
|
||||
<SplitPanel
|
||||
id="revisions"
|
||||
defaultSize="28%"
|
||||
minSize={stacked ? "24%" : "160px"}
|
||||
maxSize="52%"
|
||||
onMouseDownCapture={(e) => {
|
||||
pointer.current = e.button === 0 && !!(e.target as Element).closest('[role="option"]');
|
||||
}}
|
||||
@@ -253,7 +274,7 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) {
|
||||
setExtra(new Set());
|
||||
}
|
||||
}}
|
||||
rowHeight={view.folder ? 52 : 38}
|
||||
rowHeight={view.folder ? 56 : 44}
|
||||
aria-label="Revisions"
|
||||
className={styles.list}
|
||||
empty={
|
||||
@@ -261,33 +282,36 @@ export function LocalHistoryEditor({ input }: { input: EditorInput }) {
|
||||
{view.folder ? tx`No local history for this folder yet` : tx`No local history for this path yet`}
|
||||
</span>
|
||||
}
|
||||
renderItem={(e) =>
|
||||
isLabel(e) ? (
|
||||
renderItem={(e) => {
|
||||
const label = isLabel(e);
|
||||
const pathText = !label && view.folder ? relativePath(root, e.path) || baseName(e.path) : null;
|
||||
return (
|
||||
<span className={styles.entry}>
|
||||
<span className={styles.time}>{formatTime(e.timestampMs)}</span>
|
||||
<span className={styles.labelRow}>
|
||||
<Icon name="bookmark" size={12} />
|
||||
<span className={styles.labelName}>{e.label}</span>
|
||||
<span className={styles.primaryRow}>
|
||||
{label && <Icon name="bookmark" size={12} />}
|
||||
<span className={styles.primary} title={e.label}>
|
||||
{e.label}
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
<span className={styles.entry}>
|
||||
<span className={styles.time}>{formatTime(e.timestampMs)}</span>
|
||||
{view.folder && (
|
||||
<span className={view.deleted.has(e.path) ? styles.deletedPath : styles.path}>
|
||||
{relativePath(root, e.path) || baseName(e.path)}
|
||||
{pathText && (
|
||||
<span className={view.deleted.has(e.path) ? styles.deletedPath : styles.path} title={pathText}>
|
||||
{pathText}
|
||||
</span>
|
||||
)}
|
||||
<span className={styles.label}>
|
||||
{e.label} · {formatSize(e.size)}
|
||||
<span className={styles.meta}>
|
||||
{formatTime(e.timestampMs)}
|
||||
{!label && ` · ${formatSize(e.size)}`}
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className={styles.diff}>{detail}</div>
|
||||
</div>
|
||||
</SplitPanel>
|
||||
<SplitHandle aria-label={tx("Revisions")} />
|
||||
<SplitPanel id="preview" defaultSize="72%">
|
||||
{detail}
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user