Compare commits

...
Author SHA1 Message Date
l0ng-ai ee2aa4de51 fix(vcs): keep Git Log file selection in place 2026-11-24 13:47:43 +08:00
6 changed files with 80 additions and 24 deletions

No files matched your search

+47
View File
@@ -430,6 +430,53 @@ test("Git Log puts affected changes on the changed-files toolbar and groups prev
await expect(notes).toBeVisible();
});
test("Git Log file selection stays in place and opens a diff on activation", async ({ workbench: page }) => {
await page.clock.install();
await page.evaluate(() => {
window.__ipc.handlers.vcs_commit_files = () =>
Array.from({ length: 30 }, (_, index) => ({
path: `src/change-${String(index).padStart(2, "0")}.ts`,
kind: "modified",
oldPath: null,
}));
});
await page.getByRole("listbox", { name: "Commits" }).getByRole("option").first().click();
const tree = page.getByRole("tree", { name: "Changed files" });
const first = tree.getByRole("treeitem", { name: "change-10.ts" });
const second = tree.getByRole("treeitem", { name: "change-11.ts" });
const firstDiff = page.getByRole("tab", { name: /^change-10\.ts/ });
const secondDiff = page.getByRole("tab", { name: /^change-11\.ts/ });
await tree.evaluate((el) => (el.scrollTop = 24 * 11));
await expect(first).toBeInViewport({ ratio: 1 });
await expect(second).toBeInViewport({ ratio: 1 });
const scrollTop = () => tree.evaluate((el) => el.scrollTop);
const initialScroll = await scrollTop();
await first.click();
await page.clock.runFor(150);
await expect(first).toHaveAttribute("aria-selected", "true");
await expect(firstDiff).toHaveCount(0);
expect(await scrollTop()).toBe(initialScroll);
await first.dblclick();
await expect(firstDiff).toHaveAttribute("aria-selected", "true");
expect(await scrollTop()).toBe(initialScroll);
await second.click();
await expect(secondDiff).toHaveAttribute("aria-selected", "true");
await expect(firstDiff).toHaveCount(0);
await expect(second).toHaveAttribute("aria-selected", "true");
expect(await scrollTop()).toBe(initialScroll);
await secondDiff.dblclick(); // Keep the preview tab open.
await first.click();
await page.clock.runFor(150);
await expect(firstDiff).toHaveCount(0);
await expect(secondDiff).toHaveAttribute("aria-selected", "true");
await tree.press("Enter");
await expect(firstDiff).toHaveAttribute("aria-selected", "true");
});
test("Not Cherry-Picked Commits dims other rows while keeping unpicked commits readable", async ({
workbench: page,
}) => {
+4 -2
View File
@@ -2171,8 +2171,10 @@ export class EditorController implements SlotHost {
return this.removeGuarded((s) => closeKey(s, key));
}
activeInput(): EditorInput | null {
return this.activeTabOf()?.input ?? null;
activeInput(options?: { previewOnly?: boolean }): EditorInput | null {
const tab = this.activeTabOf();
if (options?.previewOnly && (!tab?.preview || !editorPrefs().tabs.previewTab)) return null;
return tab?.input ?? null;
}
onActiveInputChange(fn: (input: EditorInput | null) => void): () => void {
+1 -1
View File
@@ -58,7 +58,7 @@ export function activate(): void | (() => void) {
onOpenTabsChange: (fn) => useTabs.subscribe(fn),
openTabs: () => ctrl.openTabs(),
tabInput: (paneId, tabId) => ctrl.tabInput(paneId, tabId),
activeInput: () => ctrl.activeInput(),
activeInput: (options) => ctrl.activeInput(options),
onActiveInputChange: (fn) => ctrl.onActiveInputChange(fn),
closePath: (path) => ctrl.closePath(path),
closeInput: (key) => ctrl.closeInput(key),
+25 -18
View File
@@ -21,18 +21,20 @@ import {
type TreeHandle,
} from "@/ui";
import { maybeEditorService, type EditorInput } from "@/workbench/contributions";
import { useToolWindowLayout } from "@/workbench/toolwindows/store";
import clsx from "clsx";
import {
useCallback,
useContext,
useEffect,
useEffectEvent,
useLayoutEffect,
useMemo,
useRef,
useState,
type MouseEvent as ReactMouseEvent,
} from "react";
import { DIFF_KIND, diffInput, vcsDiffInFront } from "../diffInput";
import { DIFF_KIND, diffInput } from "../diffInput";
import { buildFileTree, dirKeys, type FileTreeNode } from "../fileTree";
import styles from "../GitLog.module.css";
import {
@@ -213,29 +215,28 @@ export function CommitDetails({ commits, fileHistory = false }: { commits: Commi
const ordered = useMemo(() => filesUnder(tree), [tree]);
const chosenChanges = useMemo(() => filesUnder(tree, selectedKeys), [tree, selectedKeys]);
// Show Diff Preview: a single selected file follows into the editor's preview tab.
// Selection updates an open preview. Double-click, Enter and Show Diff open it.
const previewTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
useEffect(() => {
if (!active) clearTimeout(previewTimer.current);
return () => clearTimeout(previewTimer.current);
}, [active]);
useEffect(() => () => clearTimeout(previewTimer.current), [active, diffLocation, ordered, preview]);
const previewSelection = (sel: ReadonlySet<string>) => {
clearTimeout(previewTimer.current);
if (syncingDiff.current || sel.size !== 1) return;
// While the editor shows one of this pane's diffs, the selection walks it along (a click or
// arrow key), as in the Commit window.
const shown = maybeEditorService()?.activeInput?.();
const following = shown?.kind === DIFF_KIND && ordered.some((c) => diffInput(c.diff).key === shown.key);
if (!following && (!logOptions().diffPreview || logOptions().diffLocation !== "editor" || vcsDiffInFront())) return;
if (!active || !preview || diffLocation !== "editor" || syncingDiff.current || sel.size !== 1) return;
const editor = maybeEditorService();
const shown = editor?.activeInput?.({ previewOnly: true });
if (shown?.kind !== DIFF_KIND || !ordered.some((c) => diffInput(c.diff).key === shown.key)) return;
const file = fileNodeAt(tree, [...sel][0]!)?.file;
// A preview that cannot open (no editor yet, the file went away) is just skipped.
if (file)
previewTimer.current = setTimeout(() => void showChangesDiff([file], true).catch(() => undefined), PREVIEW_DELAY);
if (!file || diffInput(file.diff).key === shown.key) return;
previewTimer.current = setTimeout(() => {
if (!useToolWindowLayout.getState().maximized && editor?.activeInput?.({ previewOnly: true })?.key === shown.key)
void showChangesDiff([file], true, ordered).catch(() => undefined);
}, PREVIEW_DELAY);
};
// Follow only this pane's exact diff (path AND revisions); another commit or
// Compare with Local must not move its selection. Never take focus from F7.
const isOnlySelected = useEffectEvent((key: string) => selectedKeys.size === 1 && selectedKeys.has(key));
useEffect(() => {
if (!active) return;
const editor = maybeEditorService();
const followDiff = (input: EditorInput | null) => {
if (input?.kind !== DIFF_KIND) return;
@@ -243,16 +244,19 @@ export function CommitDetails({ commits, fileHistory = false }: { commits: Commi
if (!change) return;
clearTimeout(previewTimer.current);
const rel = changeTreePath(change);
const key = `f:${rel}`;
// The tree already selected this row. Revealing it would scroll it to the center.
if (isOnlySelected(key)) return;
setExpanded((current) => {
const next = new Set(current ?? allDirs);
for (const key of allDirs) if (rel.startsWith(key.slice(2) + "/")) next.add(key);
return next;
});
setDiffToReveal({ key: `f:${rel}` });
setDiffToReveal({ key });
};
followDiff(editor?.activeInput?.() ?? null);
return editor?.onActiveInputChange?.(followDiff);
}, [ordered, allDirs, changeTreePath]);
}, [active, ordered, allDirs, changeTreePath]);
// Tree.reveal needs the expanded rows to have rendered. Suppress the reverse
// preview update so it cannot reopen the diff and lose its requested chunk.
@@ -440,7 +444,10 @@ export function CommitDetails({ commits, fileHistory = false }: { commits: Commi
previewSelection(sel);
}}
renderNode={(n) => <ChangedFileRow node={n} flat={!groupByDirectory} />}
onActivate={(n) => n.file && void showChangesDiff([n.file])}
onActivate={(n) => {
clearTimeout(previewTimer.current);
if (n.file) void showChangesDiff([n.file]);
}}
onJumpToSource={(n, sel) => {
const files = sel.has(n.key) ? filesUnder(tree, sel) : filesUnder([n]);
void executeAction("vcs.log.changes.jumpToSource", files);
+1 -1
View File
@@ -34,7 +34,7 @@ export interface LogOptions {
showBranches: boolean;
/** Changed files grouped by directory (else a flat list). */
groupByDirectory: boolean;
/** Selecting a changed file shows its diff in the editor's preview tab. */
/** Selecting a changed file updates the embedded preview or an open editor preview. */
diffPreview: boolean;
/** Changed files show how many lines the commit added and deleted. */
showLineStats: boolean;
+2 -2
View File
@@ -770,8 +770,8 @@ export interface EditorService {
openTabs?(): OpenEditorTab[];
/** Input of the tab `tabId` in pane `paneId` (dragging tabs between views), null if there is none. */
tabInput?(paneId: string, tabId: string): EditorInput | null;
/** Input of the active tab (any kind), if any. */
activeInput?(): EditorInput | null;
/** Input of the active tab, optionally restricted to the replaceable preview tab. */
activeInput?(options?: { previewOnly?: boolean }): EditorInput | null;
/** Calls `fn` whenever the active tab changes; returns the unsubscribe. */
onActiveInputChange?(fn: (input: EditorInput | null) => void): () => void;
/**