Файли
openidea/src/features/vcs/allInOneDiff.ts
T
audichuang 92c0e304cd fix(vcs): open the all-in-one diff at the staged or unstaged block that was opened (#5974)
With Show All Files in One Diff View and the staging area on, a partially staged file is listed twice in the all-in-one diff. The tab revealed its block by path, so opening the unstaged entry scrolled to the staged block. openDiff now passes the opened diff's key and the tab reveals that block, falling back to the path.

Co-authored-by: audichuang <[email protected]>
2026-11-26 05:43:27 +08:00

46 рядки
1.5 KiB
TypeScript

/**
* All-in-one diff: every file of a change (a commit, the local changes, a comparison) in
* one scrollable editor tab instead of one tab per file. The diff viewer's settings menu
* switches it on (Show All Files in One Diff View); diffs of a chain then open this way.
*/
import type { DiffData } from "./diffInput";
export const COMBINED_DIFF_KIND = "combined-diff";
export interface CombinedDiffData {
/** The files, each with its own sides (no chain of their own). */
items: DiffData[];
/** Path of the file to scroll to when the tab opens. */
reveal?: string;
/** Diff key of the entry to scroll to when several share `reveal` (staged and unstaged). */
revealKey?: string;
title?: string;
}
const KEY = "openidea.diff.allInOne";
export const combinedDiffDocumentOwner = (tab: string, diff: string) => `${tab}\0${diff}`;
/** Whether diffs of several files open as one all-in-one diff (off by default). */
export function allInOneDiff(): boolean {
try {
return localStorage.getItem(KEY) === "true";
} catch {
return false;
}
}
export function setAllInOneDiff(on: boolean) {
try {
localStorage.setItem(KEY, String(on));
} catch {
// Without storage the choice lasts for this tab only.
}
}
/** The chain of `data` as an all-in-one diff, when that view is on and the chain has several files. */
export function combinedOf(data: DiffData): CombinedDiffData | null {
if (data.middle || data.embedded || !data.chain || data.chain.length < 2 || !allInOneDiff()) return null;
return { items: data.chain, reveal: data.path };
}