diff options
Diffstat (limited to 'src/vs/workbench/browser/layout.ts')
-rw-r--r-- | src/vs/workbench/browser/layout.ts | 91 |
1 files changed, 45 insertions, 46 deletions
diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index 240b52cc2b9..2e997f59f0b 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -9,8 +9,7 @@ import { EventType, addDisposableListener, getClientArea, Dimension, position, s import { onDidChangeFullscreen, isFullscreen } from 'vs/base/browser/browser'; import { IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup'; import { isWindows, isLinux, isMacintosh, isWeb, isNative, isIOS } from 'vs/base/common/platform'; -import { IUntypedEditorInput, pathsToEditors } from 'vs/workbench/common/editor'; -import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput'; +import { EditorInputCapabilities, isResourceEditorInput, IUntypedEditorInput, pathsToEditors } from 'vs/workbench/common/editor'; import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart'; import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart'; import { Position, Parts, PanelOpensMaximizedOptions, IWorkbenchLayoutService, positionFromString, positionToString, panelOpensMaximizedFromString, PanelAlignment } from 'vs/workbench/services/layout/browser/layoutService'; @@ -75,7 +74,7 @@ interface IWorkbenchLayoutWindowInitializationState { }; editor: { restoreEditors: boolean; - editorsToOpen: Promise<IUntypedEditorInput[]> | IUntypedEditorInput[]; + editorsToOpen: Promise<IUntypedEditorInput[]>; }; } @@ -98,6 +97,7 @@ enum WorkbenchLayoutClasses { interface IInitialFilesToOpen { filesToOpenOrCreate?: IPath[]; filesToDiff?: IPath[]; + filesToMerge?: IPath[]; } export abstract class Layout extends Disposable implements IWorkbenchLayoutService { @@ -278,7 +278,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi this._register(this.hostService.onDidChangeFocus(e => this.onWindowFocusChanged(e))); } - private onMenubarToggled(visible: boolean) { + private onMenubarToggled(visible: boolean): void { if (visible !== this.windowState.runtime.menuBar.toggled) { this.windowState.runtime.menuBar.toggled = visible; @@ -565,26 +565,33 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi return this.windowState.initialization.editor.restoreEditors; } - private resolveEditorsToOpen(fileService: IFileService, initialFilesToOpen: IInitialFilesToOpen | undefined): Promise<IUntypedEditorInput[]> | IUntypedEditorInput[] { - - // Files to open, diff or create + private async resolveEditorsToOpen(fileService: IFileService, initialFilesToOpen: IInitialFilesToOpen | undefined): Promise<IUntypedEditorInput[]> { if (initialFilesToOpen) { - // Files to diff is exclusive - return pathsToEditors(initialFilesToOpen.filesToDiff, fileService).then(filesToDiff => { - if (filesToDiff.length === 2) { - const diffEditorInput: IUntypedEditorInput[] = [{ - original: { resource: filesToDiff[0].resource }, - modified: { resource: filesToDiff[1].resource }, - options: { pinned: true } - }]; + // Merge editor + const filesToMerge = await pathsToEditors(initialFilesToOpen.filesToMerge, fileService); + if (filesToMerge.length === 4 && isResourceEditorInput(filesToMerge[0]) && isResourceEditorInput(filesToMerge[1]) && isResourceEditorInput(filesToMerge[2]) && isResourceEditorInput(filesToMerge[3])) { + return [{ + input1: { resource: filesToMerge[0].resource }, + input2: { resource: filesToMerge[1].resource }, + base: { resource: filesToMerge[2].resource }, + result: { resource: filesToMerge[3].resource }, + options: { pinned: true, override: 'mergeEditor.Input' } // TODO@bpasero remove the override once the resolver is ready + }]; + } - return diffEditorInput; - } + // Diff editor + const filesToDiff = await pathsToEditors(initialFilesToOpen.filesToDiff, fileService); + if (filesToDiff.length === 2) { + return [{ + original: { resource: filesToDiff[0].resource }, + modified: { resource: filesToDiff[1].resource }, + options: { pinned: true } + }]; + } - // Otherwise: Open/Create files - return pathsToEditors(initialFilesToOpen.filesToOpenOrCreate, fileService); - }); + // Normal editor + return pathsToEditors(initialFilesToOpen.filesToOpenOrCreate, fileService); } // Empty workbench configured to open untitled file if empty @@ -593,13 +600,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi return []; // do not open any empty untitled file if we restored groups/editors from previous session } - return this.workingCopyBackupService.hasBackups().then(hasBackups => { - if (hasBackups) { - return []; // do not open any empty untitled file if we have backups to restore - } + const hasBackups = await this.workingCopyBackupService.hasBackups(); + if (hasBackups) { + return []; // do not open any empty untitled file if we have backups to restore + } - return [{ resource: undefined }]; // open empty untitled file - }); + return [{ resource: undefined }]; // open empty untitled file } return []; @@ -638,10 +644,10 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi }; } - // Then check for files to open, create or diff from main side - const { filesToOpenOrCreate, filesToDiff } = this.environmentService; - if (filesToOpenOrCreate || filesToDiff) { - return { filesToOpenOrCreate, filesToDiff }; + // Then check for files to open, create or diff/merge from main side + const { filesToOpenOrCreate, filesToDiff, filesToMerge } = this.environmentService; + if (filesToOpenOrCreate || filesToDiff || filesToMerge) { + return { filesToOpenOrCreate, filesToDiff, filesToMerge }; } return undefined; @@ -681,12 +687,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi // signaling that layout is restored, but we do // not need to await the editors from having // fully loaded. - let editors: IUntypedEditorInput[]; - if (Array.isArray(this.windowState.initialization.editor.editorsToOpen)) { - editors = this.windowState.initialization.editor.editorsToOpen; - } else { - editors = await this.windowState.initialization.editor.editorsToOpen; - } + const editors = await this.windowState.initialization.editor.editorsToOpen; let openEditorsPromise: Promise<unknown> | undefined = undefined; if (editors.length) { @@ -1307,27 +1308,25 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi centerEditorLayout(active: boolean, skipLayout?: boolean): void { this.stateModel.setRuntimeValue(LayoutStateKeys.EDITOR_CENTERED, active); - let smartActive = active; const activeEditor = this.editorService.activeEditor; - let isEditorSplit = false; + let isEditorComplex = false; if (activeEditor instanceof DiffEditorInput) { - isEditorSplit = this.configurationService.getValue('diffEditor.renderSideBySide'); - } else if (activeEditor instanceof SideBySideEditorInput) { - isEditorSplit = true; + isEditorComplex = this.configurationService.getValue('diffEditor.renderSideBySide'); + } else if (activeEditor?.hasCapability(EditorInputCapabilities.MultipleEditors)) { + isEditorComplex = true; } const isCenteredLayoutAutoResizing = this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize'); if ( isCenteredLayoutAutoResizing && - (this.editorGroupService.groups.length > 1 || isEditorSplit) + (this.editorGroupService.groups.length > 1 || isEditorComplex) ) { - smartActive = false; + active = false; // disable centered layout for complex editors or when there is more than one group } - // Enter Centered Editor Layout - if (this.editorGroupService.isLayoutCentered() !== smartActive) { - this.editorGroupService.centerLayout(smartActive); + if (this.editorGroupService.isLayoutCentered() !== active) { + this.editorGroupService.centerLayout(active); if (!skipLayout) { this.layout(); |