mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(history): align the recent changes chooser (#4917)
fix(history): align the recent changes chooser
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures";
|
||||
|
||||
test("Recent Changes puts aligned dates ahead of the changes and opens the chosen history", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await openFromTree(page, "build.gradle.kts");
|
||||
await page.setViewportSize({ width: 480, height: 300 });
|
||||
await stubDesktop(page);
|
||||
const { file, newest, older } = await page.evaluate(async () => {
|
||||
const root = "/dev/acme-api";
|
||||
const file = `${root}/build.gradle.kts`;
|
||||
const saved = Date.now() - 120_000;
|
||||
const earlier = saved - 300_000;
|
||||
const entries = [
|
||||
{ id: "checkpoint", path: root, timestampMs: saved, label: "Before refactor", size: 0, kind: "label" },
|
||||
{ id: "build", path: file, timestampMs: earlier, label: "Saved", size: 9, kind: "snapshot" },
|
||||
...Array.from({ length: 18 }, (_, i) => ({
|
||||
id: `notes-${i}`,
|
||||
path: `${root}/src/notes-${i}.txt`,
|
||||
timestampMs: earlier - (i + 1) * 60_000,
|
||||
label: "Saved",
|
||||
size: 9,
|
||||
kind: "snapshot",
|
||||
})),
|
||||
];
|
||||
window.__ipc.handlers.history_list_dir = ({ path }) => ({
|
||||
entries: path === root ? entries : entries.filter((entry) => entry.path === path),
|
||||
deleted: [],
|
||||
});
|
||||
window.__ipc.handlers.history_content = () => "plugins {}\n";
|
||||
window.__ipc.handlers.fs_probe = () => ({ size: 9, binary: false, tooLarge: false });
|
||||
window.__ipc.handlers.vcs_file_mode = () => null;
|
||||
const dateModule = "/src/platform/dateFormat.ts";
|
||||
const { formatDateTime } = await import(/* @vite-ignore */ dateModule);
|
||||
const actions = "/src/platform/actions.ts";
|
||||
await (await import(/* @vite-ignore */ actions)).executeAction("localHistory.recentChanges");
|
||||
return { file, newest: formatDateTime(new Date(saved)), older: formatDateTime(new Date(earlier)) };
|
||||
});
|
||||
|
||||
const popup = page.getByRole("dialog", { name: "Recent Changes", exact: true });
|
||||
const list = popup.getByRole("listbox", { name: "Recent Changes", exact: true });
|
||||
const checkpoint = list.getByRole("option", { name: /Before refactor/ });
|
||||
const build = list.getByRole("option", { name: /build\.gradle\.kts/ });
|
||||
const firstTime = checkpoint.getByText(newest, { exact: true });
|
||||
const secondTime = build.getByText(older, { exact: true });
|
||||
const firstLabel = checkpoint.getByText("Before refactor", { exact: true });
|
||||
const secondLabel = build.getByText(/build\.gradle\.kts/);
|
||||
await expect(firstTime).toHaveCSS("font-size", "13px");
|
||||
await expect(secondTime).toBeVisible();
|
||||
const time = (await firstTime.boundingBox())!;
|
||||
const label = (await firstLabel.boundingBox())!;
|
||||
expect(time.x).toBeCloseTo((await secondTime.boundingBox())!.x);
|
||||
expect(label.x).toBeCloseTo((await secondLabel.boundingBox())!.x);
|
||||
expect(time.x + time.width).toBeLessThan(label.x);
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const box = (await popup.boundingBox())!;
|
||||
return Math.max(Math.abs(box.x + box.width / 2 - 240), Math.abs(box.y + box.height / 2 - 150));
|
||||
})
|
||||
.toBeLessThan(2);
|
||||
|
||||
await page.keyboard.press("End");
|
||||
const last = list.getByRole("option", { name: /notes-17\.txt/ });
|
||||
await expect(last).toHaveAttribute("aria-selected", "true");
|
||||
await expect(last).toBeInViewport({ ratio: 1 });
|
||||
await expect(popup.getByText("Recent Changes", { exact: true })).toBeVisible();
|
||||
|
||||
await page.keyboard.type("build.gradle");
|
||||
await expect(list.getByRole("option")).toHaveCount(1);
|
||||
await expect(build).toHaveAttribute("aria-selected", "true");
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(popup).toBeHidden();
|
||||
await expect.poll(async () => ipcCalls(page, "history_list_dir")).toContainEqual({ path: file });
|
||||
await expect(page.getByRole("listbox", { name: "Revisions", exact: true })).toBeVisible();
|
||||
});
|
||||
@@ -131,6 +131,14 @@
|
||||
.listBody > * {
|
||||
flex: 1;
|
||||
}
|
||||
.centeredList {
|
||||
min-width: min(360px, 90vw);
|
||||
}
|
||||
.centeredList .listMain,
|
||||
.centeredList .listBody {
|
||||
flex-shrink: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -190,6 +198,12 @@
|
||||
min-width: 200px;
|
||||
max-width: 420px;
|
||||
}
|
||||
.leadingDetail {
|
||||
flex: 0 0 min(var(--list-leading-detail-width), 42%);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.detail {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
|
||||
@@ -202,7 +202,12 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
const chars = Math.max(
|
||||
popup.title.length + (popup.pin ? 4 : 0),
|
||||
...popup.items.map(
|
||||
(i) => i.label.length + (i.preview?.length ?? 0) + (i.detail?.length ?? 0) + (i.shortcut?.length ?? 0),
|
||||
(i) =>
|
||||
i.label.length +
|
||||
(i.leadingDetail?.length ?? 0) +
|
||||
(i.preview?.length ?? 0) +
|
||||
(i.detail?.length ?? 0) +
|
||||
(i.shortcut?.length ?? 0),
|
||||
),
|
||||
);
|
||||
const padding = popup.compact ? 44 + (showIcons ? 20 : 0) : 90;
|
||||
@@ -216,28 +221,32 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
: null
|
||||
: null;
|
||||
const hasPreview = shownPreview !== null;
|
||||
const point = popup.anchor === "center" ? null : popup.anchor;
|
||||
const previewBelow = hasPreview && viewportWidth <= MIN_SIDE_BY_SIDE_WIDTH;
|
||||
const previewLeft =
|
||||
point &&
|
||||
hasPreview &&
|
||||
!previewBelow &&
|
||||
popup.anchor.x + width + LIST_PREVIEW_WIDTH > viewportWidth - 6 &&
|
||||
popup.anchor.x >= LIST_PREVIEW_WIDTH + 6;
|
||||
point.x + width + LIST_PREVIEW_WIDTH > viewportWidth - 6 &&
|
||||
point.x >= LIST_PREVIEW_WIDTH + 6;
|
||||
const anchor = useMemo(() => {
|
||||
if (!fetchPreview) return popup.anchor;
|
||||
const x = popup.anchor.x - (previewLeft ? LIST_PREVIEW_WIDTH : 0);
|
||||
if (!point || !fetchPreview) return popup.anchor;
|
||||
const x = point.x - (previewLeft ? LIST_PREVIEW_WIDTH : 0);
|
||||
return {
|
||||
getBoundingClientRect: () =>
|
||||
new DOMRect(
|
||||
Math.max(0, Math.min(x, window.innerWidth)),
|
||||
Math.max(0, Math.min(popup.anchor.y, window.innerHeight)),
|
||||
Math.max(0, Math.min(point.y, window.innerHeight)),
|
||||
0,
|
||||
0,
|
||||
),
|
||||
};
|
||||
}, [fetchPreview, popup.anchor, previewLeft]);
|
||||
}, [fetchPreview, point, popup.anchor, previewLeft]);
|
||||
const leadingDetailChars = Math.max(0, ...popup.items.map((item) => item.leadingDetail?.length ?? 0));
|
||||
const popupSize = {
|
||||
width: hasPreview ? width + LIST_PREVIEW_WIDTH : width,
|
||||
"--list-preview-width": `${LIST_PREVIEW_WIDTH}px`,
|
||||
"--list-leading-detail-width": `${leadingDetailChars + 1}ch`,
|
||||
} as CSSProperties;
|
||||
const indexOf = (item: ListPopupItem) => popup.items.indexOf(item);
|
||||
return (
|
||||
@@ -252,6 +261,7 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
hasPreview && styles.withPreview,
|
||||
previewBelow && styles.previewBelow,
|
||||
previewLeft && styles.previewLeft,
|
||||
popup.anchor === "center" && styles.centeredList,
|
||||
)}
|
||||
style={popupSize}
|
||||
>
|
||||
@@ -311,6 +321,11 @@ function ListPopup({ popup }: { popup: Extract<LspPopup, { kind: "list" }> }) {
|
||||
data-path={item.location?.path}
|
||||
data-line={item.location?.line}
|
||||
>
|
||||
{leadingDetailChars > 0 && (
|
||||
<span className={styles.leadingDetail} title={item.leadingDetail}>
|
||||
{item.leadingDetail}
|
||||
</span>
|
||||
)}
|
||||
{popup.numbered && <span className={styles.mnemonic}>{n > 0 && n <= 9 ? n : ""}</span>}
|
||||
{showIcons && <ItemIcon item={item} />}
|
||||
<HighlightedText className={styles.label} text={item.label} indices={match} tone="accent" />
|
||||
|
||||
@@ -18,6 +18,8 @@ export interface ListPopupItem {
|
||||
section?: { id: string; label?: string };
|
||||
/** Muted trailing text (file:line, kind…). */
|
||||
detail?: string;
|
||||
/** In its own column before the label (for example, a timestamp). */
|
||||
leadingDetail?: string;
|
||||
/** Second line / muted text after the label (code preview). */
|
||||
preview?: string;
|
||||
icon?: string;
|
||||
@@ -97,7 +99,7 @@ export type LspPopup =
|
||||
}
|
||||
| {
|
||||
kind: "list";
|
||||
anchor: PopupPoint;
|
||||
anchor: PopupPoint | "center";
|
||||
title: string;
|
||||
items: ListPopupItem[];
|
||||
/** Rows 1-9 get a number; typing it runs the row (IDEA's numbered popups). */
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
*/
|
||||
import type { HistoryEntry } from "@/bindings";
|
||||
import { openPopup, type ListPopupItem } from "@/editor/lsp/popupStore";
|
||||
import { dateFormatOptions, formatDateTime } from "@/platform/dateFormat";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { relativePath, useProject } from "@/platform/project";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { openLocalHistory } from "./localHistoryKind";
|
||||
import { formatTime } from "./model";
|
||||
import { errorMessage } from "./ops";
|
||||
|
||||
const MAX_ROWS = 40;
|
||||
@@ -45,15 +45,15 @@ export async function showRecentChanges() {
|
||||
notifications().notify({ level: "error", title: "Cannot read Local History", body: errorMessage(e) });
|
||||
return;
|
||||
}
|
||||
const now = Date.now();
|
||||
const dateFormat = dateFormatOptions();
|
||||
const items: ListPopupItem[] = entries.map((e, i) => ({
|
||||
id: `${i}`,
|
||||
label: recentChangeLabel(e, root),
|
||||
detail: formatTime(e.timestampMs, now),
|
||||
leadingDetail: e.timestampMs == null ? "" : formatDateTime(new Date(e.timestampMs), dateFormat),
|
||||
icon: e.kind === "label" ? "bookmark" : "history",
|
||||
run: () => openLocalHistory(e.kind === "label" ? root : e.path),
|
||||
}));
|
||||
if (!items.length)
|
||||
items.push({ id: "none", label: "No recent changes", disabled: "Local History has no entries yet", run: () => {} });
|
||||
openPopup({ kind: "list", anchor: { x: window.innerWidth / 2 - 200, y: 96 }, title: "Recent Changes", items });
|
||||
openPopup({ kind: "list", anchor: "center", title: "Recent Changes", items });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user