Файли
openidea/src/features/vcs/diffViewer.ts
T
l0ng-ai 63db10a688 fix(vcs): reuse one diff tab with the preview tab turned off (#7108)
Diffs from the version control views reused one tab only through the preview tab, so turning off Opening Policy > Enable preview tab opened every diff in a new tab. Editor kinds can now have their previews granted regardless of that setting (reusesPreviewTab); the diff, combined diff and merge commit diff kinds do, so Commit / Local Changes, the Git Log, shelves and stashes keep one diff tab while project files still open as regular tabs. Pinned and kept diff tabs stay, and activeInput({ previewOnly }) uses the same check so the Git Log's selection-following preview works too.

Fixes #7096
2026-12-01 03:47:32 +08:00

44 рядки
1.9 KiB
TypeScript

import { tx } from "@/platform/i18n";
import { lazyComponent } from "@/ui";
import { registerEditorKind } from "@/workbench/contributions";
import { COMBINED_DIFF_KIND, combinedDiffDocumentOwner, type CombinedDiffData } from "./allInOneDiff";
import { DIFF_KIND, diffInput, diffInputAtCaret, diffTitle, type DiffData } from "./diffInput";
import { stagedDiffPath, stagedDocumentLifecycle } from "./stagedDocument";
/** The diff viewer (editor kind `diff`), also for windows that show diffs without Git (deployment). */
export function activateDiffViewer(): () => void {
const staged = stagedDocumentLifecycle(true);
const combinedStaged = stagedDocumentLifecycle(true, ({ key, data }) =>
(data as CombinedDiffData).items
.filter(stagedDiffPath)
.map((item) => combinedDiffDocumentOwner(key, diffInput(item).key)),
);
const single = registerEditorKind({
kind: DIFF_KIND,
standalone: true,
reusesPreviewTab: true,
// Switching back shows the diff where it was left (scroll, caret, expanded lines),
// without reloading the revisions.
keepAlive: true,
component: lazyComponent(() => import("./diff-editor-tab").then((m) => m.DiffEditorTab)),
title: (input) => diffTitle(input.data as DiffData),
icon: () => "diff",
navigationInput: diffInputAtCaret,
document: (input) => (stagedDiffPath(input.data as DiffData) ? staged : undefined),
});
const combined = registerEditorKind({
kind: COMBINED_DIFF_KIND,
standalone: true,
reusesPreviewTab: true,
keepAlive: true,
component: lazyComponent(() => import("./CombinedDiff").then((m) => m.CombinedDiffTab)),
title: (input) => (input.data as CombinedDiffData).title ?? tx("Combined Changes Diff"),
document: (input) => ((input.data as CombinedDiffData).items.some(stagedDiffPath) ? combinedStaged : undefined),
icon: () => "diff",
});
return () => {
single();
combined();
};
}