@@ -550,28 +589,7 @@ export function CommitDetails({ commits, fileHistory = false }: { commits: Commi
- {selectedChange ? (
- selectedChange.mergeParents?.length === 2 && selectedChange.after ? (
-
- ) : (
-
- )
- ) : (
-
- Select a file to preview its changes
-
- )}
+
) : (
diff --git a/src/features/vcs/log/FileHistoryDiffPreview.tsx b/src/features/vcs/log/FileHistoryDiffPreview.tsx
new file mode 100644
index 0000000000..17c020d09f
--- /dev/null
+++ b/src/features/vcs/log/FileHistoryDiffPreview.tsx
@@ -0,0 +1,57 @@
+import type { Commit } from "@/bindings";
+import { EmptyState, Spinner, T } from "@/ui";
+import { useEffect, useState } from "react";
+import styles from "../GitLog.module.css";
+import { historyFileChanges, type LogChange } from "../logChanges";
+import { useGitLog } from "../logStore";
+import { commitKey, commitRepo } from "../multiRoot";
+import { useVcsKind } from "../store";
+import { ChangePreview, loadLogChanges } from "./CommitDetails";
+import { useReadOnlyLog } from "./logHooks";
+
+/**
+ * IDEA's file history diff preview (FileHistoryPanel's FrameDiffPreview): the selected
+ * revision's change to the file, beside the revisions and their details.
+ */
+export function FileHistoryDiffPreview({ commits, target }: { commits: Commit[]; target: string }) {
+ const selection = useGitLog((s) => s.selection);
+ const commit = selection.length === 1 ? commits.find((c) => commitKey(c) === selection[0]) : undefined;
+ const commitRoot = commit ? commitRepo(commit) : null;
+ const kind = useVcsKind(commitRoot);
+ const readOnly = useReadOnlyLog();
+ const key = commit ? `${commitKey(commit)}\0${kind}\0${target}` : null;
+ const [result, setResult] = useState<{ key: string; change?: LogChange; error?: string } | null>(null);
+
+ useEffect(() => {
+ if (!commit || !key) return;
+ let alive = true;
+ loadLogChanges([commit], { kind, commitRoot, readOnly, fromParents: false, parentIndex: -1 })
+ .then((all) => alive && setResult({ key, change: historyFileChanges(commit, target, all)[0] }))
+ .catch((e: unknown) => alive && setResult({ key, error: e instanceof Error ? e.message : String(e) }));
+ return () => {
+ alive = false;
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [key]);
+
+ if (!commit)
+ return (
+
+ Select a commit to view changes
+
+ );
+ if (result?.key !== key)
+ return (
+
+
+
+ );
+ if (result.error) return
{result.error}
;
+ if (!result.change)
+ return (
+
+ No changes
+
+ );
+ return
;
+}
diff --git a/src/features/vcs/logChanges.ts b/src/features/vcs/logChanges.ts
index 3ba9b60d45..4ac4ad37e6 100644
--- a/src/features/vcs/logChanges.ts
+++ b/src/features/vcs/logChanges.ts
@@ -8,6 +8,7 @@ import type { ChangedFile, Commit, FileLineStats, LinkTarget, RevisionChange } f
import { call, commands } from "@/platform/ipc";
import { editorService } from "@/workbench/contributions";
import { tx } from "@/platform/i18n";
+import { relativePath } from "@/platform/project";
import { workflowSettings } from "@/platform/workflowSettings";
import { combinedOf } from "./allInOneDiff";
import {
@@ -483,3 +484,20 @@ export async function applySelectedChanges(changes: readonly LogChange[]) {
);
if (outcome) await reportApply(outcome, tx("Changes applied"));
}
+
+/** The changes of `commit` to the file whose history shows `target` (its name at that revision, after a rename). */
+export function historyFileChanges
>(
+ commit: Commit & { repo?: string | null; historyPath?: string | null },
+ target: string,
+ changes: readonly T[],
+): T[] {
+ const root = commitRepo(commit) ?? currentRepoRoot();
+ const targetPath = root ? relativePath(root, target) : target;
+ const historyPath = typeof commit.historyPath === "string" ? commit.historyPath : null;
+ return changes.filter(
+ (change) =>
+ change.path === targetPath ||
+ change.oldPath === targetPath ||
+ (historyPath !== null && (change.path === historyPath || change.oldPath === historyPath)),
+ );
+}
diff --git a/src/features/vcs/logOptions.ts b/src/features/vcs/logOptions.ts
index ecb2338368..a56277d18b 100644
--- a/src/features/vcs/logOptions.ts
+++ b/src/features/vcs/logOptions.ts
@@ -8,6 +8,8 @@ import { LogOptionsContext } from "./logContext";
export type LogSort = "date" | "topo" | "standard";
+export type DiffLocation = "editor" | "right" | "bottom";
+
export interface LogOptions {
sort: LogSort;
firstParent: boolean;
@@ -42,7 +44,9 @@ export interface LogOptions {
showRepository: boolean;
showOnlyAffected: boolean;
changesFromParents: boolean;
- diffLocation: "editor" | "right" | "bottom";
+ diffLocation: DiffLocation;
+ /** File history keeps its own location (IDEA's FileHistoryUiProperties): its file's diff beside the revisions. */
+ historyDiffLocation: DiffLocation;
columnOrder: string[];
columnWidths: Record;
linearizeMerges: boolean;
@@ -78,6 +82,7 @@ export const DEFAULT_LOG_OPTIONS: LogOptions = {
showOnlyAffected: false,
changesFromParents: false,
diffLocation: "editor",
+ historyDiffLocation: "right",
columnOrder: ["author", "date", "hash"],
columnWidths: {},
linearizeMerges: false,
@@ -99,6 +104,7 @@ const APPLICATION_LOG_OPTION_KEYS = [
"diffPreview",
"changesFromParents",
"diffLocation",
+ "historyDiffLocation",
"columnOrder",
] as const satisfies readonly (keyof LogOptions)[];
@@ -112,9 +118,10 @@ export function parseLogOptions(raw: unknown): LogOptions {
for (const k of Object.keys(out) as Array) {
if (k === "sort")
out.sort = o.sort === "standard" || o.sort === "topo" || o.sort === "date" ? o.sort : DEFAULT_LOG_OPTIONS.sort;
- else if (k === "diffLocation")
- out.diffLocation = o.diffLocation === "right" || o.diffLocation === "bottom" ? o.diffLocation : "editor";
- else if (k === "columnOrder")
+ else if (k === "diffLocation" || k === "historyDiffLocation") {
+ const v = o[k];
+ out[k] = v === "editor" || v === "right" || v === "bottom" ? v : DEFAULT_LOG_OPTIONS[k];
+ } else if (k === "columnOrder")
out.columnOrder = Array.isArray(o.columnOrder)
? [...new Set(o.columnOrder.filter((v): v is string => typeof v === "string"))]
: [...DEFAULT_LOG_OPTIONS.columnOrder];
diff --git a/src/features/vcs/logPaneActions.ts b/src/features/vcs/logPaneActions.ts
index 39a692bc83..85a28670a1 100644
--- a/src/features/vcs/logPaneActions.ts
+++ b/src/features/vcs/logPaneActions.ts
@@ -6,7 +6,6 @@ import { create } from "zustand";
import { gateByVcsKind } from "./vcsKind";
import type { Branch, Commit } from "@/bindings";
import { executeAction, registerActions, type Action } from "@/platform/actions";
-import { relativePath } from "@/platform/project";
import { notifications, toolWindowService } from "@/workbench/contributions";
import {
deleteBranches,
@@ -24,6 +23,7 @@ import {
changesArg,
compareChangesWithLocal,
getFromRevision,
+ historyFileChanges,
openChangeSource,
revertSelectedChanges,
showChangesDiff,
@@ -32,7 +32,7 @@ import {
} from "./logChanges";
import { logOptions } from "./logOptions";
import { goToRef, selectedCommits, toggleCherryHighlight, updateLogOptions, useGitLog } from "./logStore";
-import { commitKey, commitRepo } from "./multiRoot";
+import { commitKey } from "./multiRoot";
import { dropSelectedChanges, extractSelectedChanges } from "./rebase";
import { copyLogChangesAsPatch, showCreatePatchForLogChanges } from "./patches";
import { openRevisionFile } from "./revisionInput";
@@ -68,15 +68,7 @@ function showFocusedHistoryDiff() {
return;
}
- const root = commitRepo(commit) ?? currentRepoRoot();
- const targetPath = root ? relativePath(root, tab.target) : tab.target;
- const historyPath = "historyPath" in commit && typeof commit.historyPath === "string" ? commit.historyPath : null;
- const relevant = changes.all.filter(
- (change) =>
- change.path === targetPath ||
- change.oldPath === targetPath ||
- (historyPath !== null && (change.path === historyPath || change.oldPath === historyPath)),
- );
+ const relevant = historyFileChanges(commit, tab.target, changes.all);
if (relevant.length) void showChangesDiff(relevant, false, relevant);
}