дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
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
Цей коміт міститься в:
1 джерело
1dd3d64781
коміт
63db10a688
5 files changed
+47
-2
No files matched your search
@@ -43,6 +43,7 @@ import {
|
||||
useTextEditorWrappers,
|
||||
type EditorCloseSession,
|
||||
type EditorInput,
|
||||
type EditorKindContribution,
|
||||
type OpenOptions,
|
||||
type FileEditorResolution,
|
||||
type OpenEditorTab,
|
||||
@@ -310,6 +311,11 @@ function tabModified(tab: Tab): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
/** Whether `input` opens in the preview tab when asked: always for kinds that reuse one, else per the setting. */
|
||||
function previewTabsFor(input: EditorInput, kinds: ReadonlyMap<string, EditorKindContribution>): boolean {
|
||||
return editorPrefs().tabs.previewTab || !!kinds.get(input.kind)?.reusesPreviewTab;
|
||||
}
|
||||
|
||||
export class EditorController implements SlotHost {
|
||||
manager: DocumentManager;
|
||||
readonly slots = new Map<string, EditorSlot>();
|
||||
@@ -1529,7 +1535,7 @@ export class EditorController implements SlotHost {
|
||||
const kinds = useContributions.getState().editorKinds;
|
||||
const lifecycle = documentLifecycle(input, kinds);
|
||||
const canPreview = !lifecycle || (lifecycle.allowPreview && !documentDirty({ input, lifecycle }));
|
||||
const preview = !!o.preview && editorPrefs().tabs.previewTab && canPreview;
|
||||
const preview = !!o.preview && previewTabsFor(input, kinds) && canPreview;
|
||||
if (!activate && preview) return;
|
||||
const kind = kinds.get(input.kind);
|
||||
let paneId = s.panes[generation.pane] ? generation.pane : activate ? s.activePane : null;
|
||||
@@ -2447,7 +2453,8 @@ export class EditorController implements SlotHost {
|
||||
|
||||
activeInput(options?: { previewOnly?: boolean }): EditorInput | null {
|
||||
const tab = this.activeTabOf();
|
||||
if (options?.previewOnly && (!tab?.preview || !editorPrefs().tabs.previewTab)) return null;
|
||||
const kinds = useContributions.getState().editorKinds;
|
||||
if (options?.previewOnly && (!tab?.preview || !previewTabsFor(tab.input, kinds))) return null;
|
||||
return tab?.input ?? null;
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,36 @@ describe("file open order", () => {
|
||||
expect(activePath()).toBe("/p/b.ts");
|
||||
});
|
||||
|
||||
it("reuses one tab for kinds that ask for it while the preview tab is off", async () => {
|
||||
useProject.setState({ settings: { editor: { tabs: { previewTab: false } } } });
|
||||
dispose = registerEditorKind({
|
||||
kind: "test-diff",
|
||||
reusesPreviewTab: true,
|
||||
component: () => null,
|
||||
title: (input) => input.key,
|
||||
});
|
||||
const controller = setup();
|
||||
const diff = (key: string) => ({ kind: "test-diff", key });
|
||||
await controller.openInput(diff("one"), { preview: true, focus: false });
|
||||
await controller.openInput(diff("two"), { preview: true, focus: false });
|
||||
const tabs = () => Object.values(useTabs.getState().panes).flatMap((pane) => pane.tabs);
|
||||
expect(tabs().map((t) => [t.input.key, t.preview])).toEqual([["two", true]]);
|
||||
expect(controller.activeInput({ previewOnly: true })?.key).toBe("two");
|
||||
// Files still don't preview.
|
||||
await controller.openFile("/p/a.ts", { preview: true, focus: false });
|
||||
await controller.openFile("/p/b.ts", { preview: true, focus: false });
|
||||
expect(openFilePaths(useTabs.getState()).sort()).toEqual(["/p/a.ts", "/p/b.ts"]);
|
||||
// A kept diff tab stays.
|
||||
const pane = useTabs.getState().activePane;
|
||||
controller.keepTab(pane, tabs().find((t) => t.input.key == "two")!.id);
|
||||
await controller.openInput(diff("three"), { preview: true, focus: false });
|
||||
expect(
|
||||
tabs()
|
||||
.filter((t) => t.input.kind == "test-diff")
|
||||
.map((t) => t.input.key),
|
||||
).toEqual(["two", "three"]);
|
||||
});
|
||||
|
||||
it("keeps an earlier regular file without removing the newer preview", async () => {
|
||||
const { started, response } = delayProvider();
|
||||
const controller = setup();
|
||||
|
||||
@@ -16,6 +16,7 @@ export function activateDiffViewer(): () => void {
|
||||
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,
|
||||
@@ -28,6 +29,7 @@ export function activateDiffViewer(): () => void {
|
||||
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"),
|
||||
|
||||
@@ -426,6 +426,7 @@ export function activate(): () => void {
|
||||
registerEditorKind({
|
||||
kind: "git-merge-diff",
|
||||
standalone: true,
|
||||
reusesPreviewTab: true,
|
||||
component: lazyComponent(() => import("./GitMergeDiff").then((m) => m.GitMergeDiff)),
|
||||
title: (input) => (input.data as { path: string }).path,
|
||||
icon: () => "diff",
|
||||
|
||||
@@ -169,6 +169,11 @@ export interface EditorKindContribution {
|
||||
* `splitInput`, or moves the tab instead.
|
||||
*/
|
||||
singleton?: boolean;
|
||||
/**
|
||||
* A preview tab its opener asks for is granted even with Opening Policy › Enable preview tab
|
||||
* off, so stepping through a change set's diffs reuses one tab. Pinned or kept tabs stay.
|
||||
*/
|
||||
reusesPreviewTab?: boolean;
|
||||
/** Fresh input opened when splitting a `singleton` tab (e.g. a new shell in the same cwd). */
|
||||
splitInput?(input: EditorInput): EditorInput | Promise<EditorInput | null> | null;
|
||||
/** Last tab showing this input closed (including split tabs and tab-limit eviction). */
|
||||
|
||||
Reference in new issue
Заблокувати користувача