Файли
openidea/src/features/vcs/diffNavigation.ts
T
kkmihaiтаkkMihai a3576fca90 fix(vcs): maximize diffs and keep file navigation (#907)
Diff tabs, including the preview tab, get Maximize Editor / Restore Size in their toolbar (reusing Hide All Tool Windows). Show Diff from the Commit view or the Git log now carries the whole change list: F7 / Shift+F7 at the last or first difference shows a hint, and pressing again moves to the first or last difference of the neighbouring file, skipping binary, oversized and unreadable files. The layout is restored after a preview is replaced and keyboard focus stays in the diff across files. Compare branches stays single-file.

Fixes #904

Co-authored-by: kkMihai <[email protected]>
2026-11-03 23:41:16 +08:00

26 рядки
1.2 KiB
TypeScript

import { Text } from "@codemirror/state";
import { call, commands } from "@/platform/ipc";
import { ideaChunks, type IgnorePolicy } from "./diffOptions";
import { chainNeighbour, loadSide, sideFile, type DiffData } from "./diffInput";
/** Find a textual change without opening binary, unreadable or unchanged siblings. */
export async function changedChainNeighbour(
data: DiffData,
dir: 1 | -1,
ignore: IgnorePolicy,
): Promise<DiffData | null> {
for (let next = chainNeighbour(data, dir); next; next = chainNeighbour(next, dir)) {
try {
const paths = [sideFile(next.left, next.path), sideFile(next.right, next.path)].filter((p): p is string => !!p);
const probes = await Promise.all(paths.map((path) => call(commands.fsProbe(path))));
if (probes.some((probe) => probe.binary || probe.tooLarge)) continue;
const [a, b] = await Promise.all([loadSide(next.path, next.left), loadSide(next.path, next.right)]);
if (a.includes("\0") || b.includes("\0")) continue;
if (ideaChunks(Text.of(a.split(/\r\n?|\n/)), Text.of(b.split(/\r\n?|\n/)), ignore, "none").length) return next;
} catch {
// A stale chain can contain a file that was deleted or is no longer readable.
}
}
return null;
}