diff --git a/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts b/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts index 01f7703ee43..dbc22090414 100644 --- a/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts @@ -31,7 +31,7 @@ import { IPathService } from 'vs/workbench/services/path/common/pathService'; import { diffSets, diffMaps } from 'vs/base/common/collections'; import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; import { ViewContainerLocation } from 'vs/workbench/common/views'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; class TextEditorSnapshot { @@ -296,14 +296,14 @@ export class MainThreadDocumentsAndEditors { @IUriIdentityService uriIdentityService: IUriIdentityService, @IClipboardService private readonly _clipboardService: IClipboardService, @IPathService pathService: IPathService, - @IInstantiationService instantiationService: IInstantiationService + @IConfigurationService configurationService: IConfigurationService ) { this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostDocumentsAndEditors); this._mainThreadDocuments = this._toDispose.add(new MainThreadDocuments(extHostContext, this._modelService, this._textFileService, fileService, textModelResolverService, environmentService, uriIdentityService, workingCopyFileService, pathService)); extHostContext.set(MainContext.MainThreadDocuments, this._mainThreadDocuments); - this._mainThreadEditors = this._toDispose.add(new MainThreadTextEditors(this, extHostContext, codeEditorService, this._editorService, this._editorGroupService)); + this._mainThreadEditors = this._toDispose.add(new MainThreadTextEditors(this, extHostContext, codeEditorService, this._editorService, this._editorGroupService, configurationService)); extHostContext.set(MainContext.MainThreadTextEditors, this._mainThreadEditors); // It is expected that the ctor of the state computer calls our `_onDelta`. diff --git a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts index 3b9b4dec1fe..bda93934177 100644 --- a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts +++ b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts @@ -548,7 +548,7 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape { } //#region Messages received from Ext Host $moveTab(tabId: string, index: number, viewColumn: EditorGroupColumn, preserveFocus?: boolean): void { - const groupId = columnToEditorGroup(this._editorGroupsService, viewColumn); + const groupId = columnToEditorGroup(this._editorGroupsService, this._configurationService, viewColumn); const tabInfo = this._tabInfoLookup.get(tabId); const tab = tabInfo?.tab; if (!tab) { diff --git a/src/vs/workbench/api/browser/mainThreadEditors.ts b/src/vs/workbench/api/browser/mainThreadEditors.ts index 5a131dcc0b7..f1a03ff3d7f 100644 --- a/src/vs/workbench/api/browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadEditors.ts @@ -13,7 +13,7 @@ import { ISelection } from 'vs/editor/common/core/selection'; import { IDecorationOptions, IDecorationRenderOptions } from 'vs/editor/common/editorCommon'; import { ISingleEditOperation } from 'vs/editor/common/core/editOperation'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; -import { ITextEditorOptions, IResourceEditorInput, EditorActivation, EditorResolution } from 'vs/platform/editor/common/editor'; +import { ITextEditorOptions, IResourceEditorInput, EditorActivation } from 'vs/platform/editor/common/editor'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { MainThreadTextEditor } from 'vs/workbench/api/browser/mainThreadEditor'; import { ExtHostContext, ExtHostEditorsShape, IApplyEditsOptions, ITextDocumentShowOptions, ITextEditorConfigurationUpdate, ITextEditorPositionData, IUndoStopOptions, MainThreadTextEditorsShape, TextEditorRevealType } from 'vs/workbench/api/common/extHost.protocol'; @@ -25,8 +25,9 @@ import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/wo import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { ILineChange } from 'vs/editor/common/diff/smartLinesDiffComputer'; import { IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'; -import { IEditorControl } from 'vs/workbench/common/editor'; +import { DEFAULT_EDITOR_ASSOCIATION, IEditorControl } from 'vs/workbench/common/editor'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; export interface IMainThreadEditorLocator { getEditor(id: string): MainThreadTextEditor | undefined; @@ -51,6 +52,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { @ICodeEditorService private readonly _codeEditorService: ICodeEditorService, @IEditorService private readonly _editorService: IEditorService, @IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService, + @IConfigurationService private readonly _configurationService: IConfigurationService ) { this._instanceId = String(++MainThreadTextEditors.INSTANCE_COUNT); this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostEditors); @@ -125,7 +127,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { // preserve pre 1.38 behaviour to not make group active when preserveFocus: true // but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633 activation: options.preserveFocus ? EditorActivation.RESTORE : undefined, - override: EditorResolution.DISABLED + override: DEFAULT_EDITOR_ASSOCIATION.id }; const input: IResourceEditorInput = { @@ -133,7 +135,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { options: editorOptions }; - const editor = await this._editorService.openEditor(input, columnToEditorGroup(this._editorGroupService, options.position)); + const editor = await this._editorService.openEditor(input, columnToEditorGroup(this._editorGroupService, this._configurationService, options.position)); if (!editor) { return undefined; } @@ -147,7 +149,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { await this._editorService.openEditor({ resource: model.uri, options: { preserveFocus: false } - }, columnToEditorGroup(this._editorGroupService, position)); + }, columnToEditorGroup(this._editorGroupService, this._configurationService, position)); return; } } diff --git a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts index 861c1e680e2..21d61097634 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts @@ -17,6 +17,7 @@ import { columnToEditorGroup, editorGroupToColumn } from 'vs/workbench/services/ import { equals } from 'vs/base/common/objects'; import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto'; import { IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; class MainThreadNotebook { @@ -44,7 +45,8 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape @IEditorService private readonly _editorService: IEditorService, @ILogService private readonly _logService: ILogService, @INotebookEditorService private readonly _notebookEditorService: INotebookEditorService, - @IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService + @IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService, + @IConfigurationService private readonly _configurationService: IConfigurationService ) { this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostNotebookEditors); @@ -126,7 +128,7 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape override: viewType }; - const editorPane = await this._editorService.openEditor({ resource: URI.revive(resource), options: editorOptions }, columnToEditorGroup(this._editorGroupService, options.position)); + const editorPane = await this._editorService.openEditor({ resource: URI.revive(resource), options: editorOptions }, columnToEditorGroup(this._editorGroupService, this._configurationService, options.position)); const notebookEditor = getNotebookEditorFromEditorPane(editorPane); if (notebookEditor) { diff --git a/src/vs/workbench/api/test/browser/mainThreadDocumentsAndEditors.test.ts b/src/vs/workbench/api/test/browser/mainThreadDocumentsAndEditors.test.ts index 8e0aa30b356..ab26fbc33b0 100644 --- a/src/vs/workbench/api/test/browser/mainThreadDocumentsAndEditors.test.ts +++ b/src/vs/workbench/api/test/browser/mainThreadDocumentsAndEditors.test.ts @@ -34,7 +34,6 @@ import { LanguageService } from 'vs/editor/common/services/languageService'; import { DisposableStore } from 'vs/base/common/lifecycle'; import { LanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce'; import { LanguageFeaturesService } from 'vs/editor/common/services/languageFeaturesService'; -import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; suite('MainThreadDocumentsAndEditors', () => { @@ -121,7 +120,7 @@ suite('MainThreadDocumentsAndEditors', () => { } }, new TestPathService(), - new TestInstantiationService(), + new TestConfigurationService(), ); }); diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index 5215338e573..3abf0c262fc 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -7,11 +7,11 @@ import { localize } from 'vs/nls'; import { isObject, isString, isUndefined, isNumber, withNullAsUndefined } from 'vs/base/common/types'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; -import { IEditorIdentifier, IEditorCommandsContext, CloseDirection, IVisibleEditorPane, EditorsOrder, EditorInputCapabilities, isEditorIdentifier, GroupIdentifier, isEditorInputWithOptionsAndGroup, IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor'; +import { IEditorIdentifier, IEditorCommandsContext, CloseDirection, IVisibleEditorPane, EditorsOrder, EditorInputCapabilities, isEditorIdentifier, isEditorInputWithOptionsAndGroup, IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor'; import { TextCompareEditorVisibleContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, ActiveEditorStickyContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, TextCompareEditorActiveContext, SideBySideEditorActiveContext } from 'vs/workbench/common/contextkeys'; import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { EditorGroupColumn, columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn'; -import { ACTIVE_GROUP_TYPE, IEditorService, SIDE_GROUP, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService'; +import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor'; import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes'; @@ -499,6 +499,7 @@ function registerOpenEditorAPICommands(): void { const editorGroupService = accessor.get(IEditorGroupsService); const openerService = accessor.get(IOpenerService); const pathService = accessor.get(IPathService); + const configurationService = accessor.get(IConfigurationService); const resourceOrString = typeof resourceArg === 'string' ? resourceArg : URI.revive(resourceArg); const [columnArg, optionsArg] = columnAndOptions ?? []; @@ -523,7 +524,7 @@ function registerOpenEditorAPICommands(): void { input = { resource, options, label }; } - await editorService.openEditor(input, columnToEditorGroup(editorGroupService, column)); + await editorService.openEditor(input, columnToEditorGroup(editorGroupService, configurationService, column)); } // do not allow to execute commands from here @@ -557,6 +558,7 @@ function registerOpenEditorAPICommands(): void { CommandsRegistry.registerCommand(API_OPEN_DIFF_EDITOR_COMMAND_ID, async function (accessor: ServicesAccessor, originalResource: UriComponents, modifiedResource: UriComponents, labelAndOrDescription?: string | { label: string; description: string }, columnAndOptions?: [EditorGroupColumn?, ITextEditorOptions?], context?: IOpenEvent) { const editorService = accessor.get(IEditorService); const editorGroupService = accessor.get(IEditorGroupsService); + const configurationService = accessor.get(IConfigurationService); const [columnArg, optionsArg] = columnAndOptions ?? []; const [options, column] = mixinContext(context, optionsArg, columnArg); @@ -576,7 +578,7 @@ function registerOpenEditorAPICommands(): void { label, description, options - }, columnToEditorGroup(editorGroupService, column)); + }, columnToEditorGroup(editorGroupService, configurationService, column)); }); CommandsRegistry.registerCommand(API_OPEN_WITH_EDITOR_COMMAND_ID, (accessor: ServicesAccessor, resource: UriComponents, id: string, columnAndOptions?: [EditorGroupColumn?, ITextEditorOptions?]) => { @@ -585,21 +587,8 @@ function registerOpenEditorAPICommands(): void { const configurationService = accessor.get(IConfigurationService); const [columnArg, optionsArg] = columnAndOptions ?? []; - let group: IEditorGroup | GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE | undefined = undefined; - if (columnArg === SIDE_GROUP) { - const direction = preferredSideBySideGroupDirection(configurationService); - - let neighbourGroup = editorGroupsService.findGroup({ direction }); - if (!neighbourGroup) { - neighbourGroup = editorGroupsService.addGroup(editorGroupsService.activeGroup, direction); - } - group = neighbourGroup; - } else { - group = columnToEditorGroup(editorGroupsService, columnArg); - } - - return editorService.openEditor({ resource: URI.revive(resource), options: { ...optionsArg, pinned: true, override: id } }, group); + return editorService.openEditor({ resource: URI.revive(resource), options: { ...optionsArg, pinned: true, override: id } }, columnToEditorGroup(editorGroupsService, configurationService, columnArg)); }); } diff --git a/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts b/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts index de846c66d56..86fb1f94e9b 100644 --- a/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts +++ b/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts @@ -37,6 +37,10 @@ suite('Files - FileEditorInput', () => { override createTextEditor(input: IResourceEditorInput) { return createFileInput(input.resource); } + + override async resolveTextEditor(input: IResourceEditorInput) { + return createFileInput(input.resource); + } } setup(() => { diff --git a/src/vs/workbench/contrib/files/test/browser/textFileEditorTracker.test.ts b/src/vs/workbench/contrib/files/test/browser/textFileEditorTracker.test.ts index a3b0a4ddcf8..c25a53fd785 100644 --- a/src/vs/workbench/contrib/files/test/browser/textFileEditorTracker.test.ts +++ b/src/vs/workbench/contrib/files/test/browser/textFileEditorTracker.test.ts @@ -157,7 +157,7 @@ suite('Files - TextFileEditorTracker', () => { test('dirty untitled text file model opens as editor', async function () { const accessor = await createTracker(); - const untitledTextEditor = accessor.textEditorService.createTextEditor({ resource: undefined, forceUntitled: true }) as UntitledTextEditorInput; + const untitledTextEditor = await accessor.textEditorService.resolveTextEditor({ resource: undefined, forceUntitled: true }) as UntitledTextEditorInput; const model = disposables.add(await untitledTextEditor.resolve()); assert.ok(!accessor.editorService.isOpened(untitledTextEditor)); @@ -177,7 +177,7 @@ suite('Files - TextFileEditorTracker', () => { const resource = toResource.call(this, '/path/index.txt'); - await accessor.editorService.openEditor(accessor.textEditorService.createTextEditor({ resource, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } })); + await accessor.editorService.openEditor(await accessor.textEditorService.resolveTextEditor({ resource, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } })); accessor.hostService.setFocus(false); accessor.hostService.setFocus(true); diff --git a/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts b/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts index 3db0fd13064..b57fdb46eb0 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts @@ -378,7 +378,8 @@ registerAction2(class extends Action2 { const historyService = accessor.get(IInteractiveHistoryService); const kernelService = accessor.get(INotebookKernelService); const logService = accessor.get(ILogService); - const group = columnToEditorGroup(editorGroupService, typeof showOptions === 'number' ? showOptions : showOptions?.viewColumn); + const configurationService = accessor.get(IConfigurationService); + const group = columnToEditorGroup(editorGroupService, configurationService, typeof showOptions === 'number' ? showOptions : showOptions?.viewColumn); const editorOptions = { activation: EditorActivation.PRESERVE, preserveFocus: typeof showOptions !== 'number' ? (showOptions?.preserveFocus ?? false) : false diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts index a14192041ab..ce9b3651aad 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts @@ -10,13 +10,11 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { ActiveEditorContext } from 'vs/workbench/common/contextkeys'; -import { columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { DiffElementViewModelBase } from 'vs/workbench/contrib/notebook/browser/diff/diffElementViewModel'; import { NOTEBOOK_DIFF_CELL_INPUT, NOTEBOOK_DIFF_CELL_PROPERTY, NOTEBOOK_DIFF_CELL_PROPERTY_EXPANDED } from 'vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser'; import { NotebookTextDiffEditor } from 'vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor'; import { NotebookDiffEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookDiffEditorInput'; import { openAsTextIcon, renderOutputIcon, revertIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons'; -import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { Registry } from 'vs/platform/registry/common/platform'; import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry'; @@ -42,7 +40,6 @@ registerAction2(class extends Action2 { async run(accessor: ServicesAccessor): Promise { const editorService = accessor.get(IEditorService); - const editorGroupService = accessor.get(IEditorGroupsService); const activeEditor = editorService.activeEditorPane; if (activeEditor && activeEditor instanceof NotebookTextDiffEditor) { @@ -57,7 +54,7 @@ registerAction2(class extends Action2 { preserveFocus: false, override: EditorResolution.DISABLED } - }, columnToEditorGroup(editorGroupService, undefined)); + }); } } }); diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 81dd80a4cc6..bb862ed6754 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -518,7 +518,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Override is disabled or did not apply: fallback to default if (!typedEditor) { - typedEditor = isEditorInput(editor) ? editor : this.textEditorService.createTextEditor(editor); + typedEditor = isEditorInput(editor) ? editor : await this.textEditorService.resolveTextEditor(editor); } // If group still isn't defined because of a disabled override we resolve it @@ -577,7 +577,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Override is disabled or did not apply: fallback to default if (!typedEditor) { - typedEditor = isEditorInputWithOptions(editor) ? editor : { editor: this.textEditorService.createTextEditor(editor), options: editor.options }; + typedEditor = isEditorInputWithOptions(editor) ? editor : { editor: await this.textEditorService.resolveTextEditor(editor), options: editor.options }; } // If group still isn't defined because of a disabled override we resolve it @@ -885,7 +885,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { if (!typedReplacement) { typedReplacement = { editor: replacement.editor, - replacement: isEditorReplacement(replacement) ? replacement.replacement : this.textEditorService.createTextEditor(replacement.replacement), + replacement: isEditorReplacement(replacement) ? replacement.replacement : await this.textEditorService.resolveTextEditor(replacement.replacement), options: isEditorReplacement(replacement) ? replacement.options : replacement.replacement.options, forceReplaceDirty: replacement.forceReplaceDirty }; diff --git a/src/vs/workbench/services/editor/common/editorGroupColumn.ts b/src/vs/workbench/services/editor/common/editorGroupColumn.ts index 651eeb9d456..7cb66600f44 100644 --- a/src/vs/workbench/services/editor/common/editorGroupColumn.ts +++ b/src/vs/workbench/services/editor/common/editorGroupColumn.ts @@ -3,36 +3,40 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { GroupIdentifier } from 'vs/workbench/common/editor'; -import { IEditorGroupsService, GroupsOrder, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { IEditorGroupsService, GroupsOrder, IEditorGroup, preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ACTIVE_GROUP, ACTIVE_GROUP_TYPE, SIDE_GROUP, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService'; /** * A way to address editor groups through a column based system * where `0` is the first column. Will fallback to `SIDE_GROUP` - * in case the column does not exist yet. + * in case the column is invalid. */ export type EditorGroupColumn = number; -export function columnToEditorGroup(editorGroupService: IEditorGroupsService, column?: EditorGroupColumn): GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE { - if ( - typeof column !== 'number' || - column === ACTIVE_GROUP || - (editorGroupService.count === 1 && editorGroupService.activeGroup.isEmpty) - ) { - return ACTIVE_GROUP; // prefer active group when position is undefined or passed in as such or when no editor is opened +export function columnToEditorGroup(editorGroupService: IEditorGroupsService, configurationService: IConfigurationService, column = ACTIVE_GROUP): GroupIdentifier | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE { + if (column === ACTIVE_GROUP || column === SIDE_GROUP) { + return column; // return early for when column is well known } - if (column === SIDE_GROUP) { - return SIDE_GROUP; // return early for when column is to the side + let groupInColumn = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE)[column]; + + // If a column is asked for that does not exist, we create up to 9 columns in accordance + // to what `ViewColumn` provides and otherwise fallback to `SIDE_GROUP`. + + if (!groupInColumn && column < 9) { + for (let i = 0; i <= column; i++) { + const editorGroups = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE); + if (!editorGroups[i]) { + editorGroupService.addGroup(editorGroups[i - 1], preferredSideBySideGroupDirection(configurationService)); + } + } + + groupInColumn = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE)[column]; } - const groupInColumn = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE)[column]; - if (groupInColumn) { - return groupInColumn.id; // return group when a direct match is found in column - } - - return SIDE_GROUP; // finally open to the side when group not found + return groupInColumn?.id ?? SIDE_GROUP; // finally open to the side when group not found } export function editorGroupToColumn(editorGroupService: IEditorGroupsService, editorGroup: IEditorGroup | GroupIdentifier): EditorGroupColumn { diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts index 32f2c303e1e..66c22bba6b2 100644 --- a/src/vs/workbench/services/editor/common/editorService.ts +++ b/src/vs/workbench/services/editor/common/editorService.ts @@ -205,7 +205,7 @@ export interface IEditorService { * @param editor the editor to open * @param options the options to use for the editor * @param group the target group. If unspecified, the editor will open in the currently - * active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side + * active group. Use `SIDE_GROUP` to open the editor in a new editor group to the side * of the currently active group. * * @returns the editor that opened or `undefined` if the operation failed or the editor was not @@ -235,7 +235,7 @@ export interface IEditorService { * * @param editors the editors to open with associated options * @param group the target group. If unspecified, the editor will open in the currently - * active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side + * active group. Use `SIDE_GROUP` to open the editor in a new editor group to the side * of the currently active group. * * @returns the editors that opened. The array can be empty or have less elements for editors diff --git a/src/vs/workbench/services/textfile/common/textEditorService.ts b/src/vs/workbench/services/textfile/common/textEditorService.ts index 28cd548aad3..f6ba61bfc28 100644 --- a/src/vs/workbench/services/textfile/common/textEditorService.ts +++ b/src/vs/workbench/services/textfile/common/textEditorService.ts @@ -30,6 +30,18 @@ export interface ITextEditorService { readonly _serviceBrand: undefined; + /** + * @deprecated this method should not be used, rather consider using + * `IEditorResolverService` instead with `DEFAULT_EDITOR_ASSOCIATION.id`. + */ + createTextEditor(input: IUntypedEditorInput): EditorInput; + + /** + * @deprecated this method should not be used, rather consider using + * `IEditorResolverService` instead with `DEFAULT_EDITOR_ASSOCIATION.id`. + */ + createTextEditor(input: IUntypedFileEditorInput): IFileEditorInput; + /** * A way to create text editor inputs from an untyped editor input. Depending * on the passed in input this will be: @@ -39,8 +51,8 @@ export interface ITextEditorService { * * @param input the untyped editor input to create a typed input from */ - createTextEditor(input: IUntypedEditorInput): EditorInput; - createTextEditor(input: IUntypedFileEditorInput): IFileEditorInput; + resolveTextEditor(input: IUntypedEditorInput): Promise; + resolveTextEditor(input: IUntypedFileEditorInput): Promise; } export class TextEditorService extends Disposable implements ITextEditorService { @@ -83,6 +95,12 @@ export class TextEditorService extends Disposable implements ITextEditorService )); } + resolveTextEditor(input: IUntypedEditorInput): Promise; + resolveTextEditor(input: IUntypedFileEditorInput): Promise; + async resolveTextEditor(input: IUntypedEditorInput | IUntypedFileEditorInput): Promise { + return this.createTextEditor(input); + } + createTextEditor(input: IUntypedEditorInput): EditorInput; createTextEditor(input: IUntypedFileEditorInput): IFileEditorInput; createTextEditor(input: IUntypedEditorInput | IUntypedFileEditorInput): EditorInput | IFileEditorInput { diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index ce6493008c1..3be319b1704 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -6178,6 +6178,8 @@ declare module 'vscode' { * Denotes a location of an editor in the window. Editors can be arranged in a grid * and each column represents one editor location in that grid by counting the editors * in order of their appearance. + * + * Columns that do not exists will be created as needed up to the maximum of `ViewColumn.Nine`. */ export enum ViewColumn { /**