diff --git a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts index 413c53b8155..b4ce189daa9 100644 --- a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts @@ -23,7 +23,8 @@ import { IUndoRedoService, UndoRedoElementType } from 'vs/platform/undoRedo/comm import { MainThreadWebviewPanels } from 'vs/workbench/api/browser/mainThreadWebviewPanels'; import { MainThreadWebviews, reviveWebviewExtension } from 'vs/workbench/api/browser/mainThreadWebviews'; import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol'; -import { editorGroupToViewColumn, IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor'; +import { IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor'; +import { editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { CustomEditorInput } from 'vs/workbench/contrib/customEditor/browser/customEditorInput'; import { CustomDocumentBackupData } from 'vs/workbench/contrib/customEditor/browser/customEditorInputFactory'; import { ICustomEditorModel, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor'; @@ -195,7 +196,7 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc title: webviewInput.getTitle(), webviewOptions: webviewInput.webview.contentOptions, panelOptions: webviewInput.webview.options, - }, editorGroupToViewColumn(this._editorGroupService, webviewInput.group || 0), cancellation); + }, editorGroupToColumn(this._editorGroupService, webviewInput.group || 0), cancellation); } catch (error) { onUnexpectedError(error); webviewInput.webview.html = this.mainThreadWebview.getWebviewResolvedFailedContent(viewType); diff --git a/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts b/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts index 2425212149e..e552be048aa 100644 --- a/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts @@ -20,7 +20,8 @@ import { MainThreadTextEditor } from 'vs/workbench/api/browser/mainThreadEditor' import { MainThreadTextEditors } from 'vs/workbench/api/browser/mainThreadEditors'; import { ExtHostContext, ExtHostDocumentsAndEditorsShape, IDocumentsAndEditorsDelta, IExtHostContext, IModelAddedData, ITextEditorAddData, MainContext } from 'vs/workbench/api/common/extHost.protocol'; import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor'; -import { editorGroupToViewColumn, EditorGroupColumn, IEditorPane } from 'vs/workbench/common/editor'; +import { IEditorPane } from 'vs/workbench/common/editor'; +import { EditorGroupColumn, editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; @@ -412,7 +413,7 @@ export class MainThreadDocumentsAndEditors { private _findEditorPosition(editor: MainThreadTextEditor): EditorGroupColumn | undefined { for (const editorPane of this._editorService.visibleEditorPanes) { if (editor.matches(editorPane)) { - return editorGroupToViewColumn(this._editorGroupService, editorPane.group); + return editorGroupToColumn(this._editorGroupService, editorPane.group); } } return undefined; diff --git a/src/vs/workbench/api/browser/mainThreadEditors.ts b/src/vs/workbench/api/browser/mainThreadEditors.ts index 9cf68817e11..51298a2aa58 100644 --- a/src/vs/workbench/api/browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadEditors.ts @@ -19,7 +19,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation import { MainThreadDocumentsAndEditors } from 'vs/workbench/api/browser/mainThreadDocumentsAndEditors'; import { MainThreadTextEditor } from 'vs/workbench/api/browser/mainThreadEditor'; import { ExtHostContext, ExtHostEditorsShape, IApplyEditsOptions, IExtHostContext, ITextDocumentShowOptions, ITextEditorConfigurationUpdate, ITextEditorPositionData, IUndoStopOptions, MainThreadTextEditorsShape, TextEditorRevealType, IWorkspaceEditDto, WorkspaceEditType } from 'vs/workbench/api/common/extHost.protocol'; -import { editorGroupToViewColumn, EditorGroupColumn, viewColumnToEditorGroup } from 'vs/workbench/common/editor'; +import { editorGroupToColumn, columnToEditorGroup, EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; @@ -126,7 +126,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { for (let editorPane of this._editorService.visibleEditorPanes) { const id = this._documentsAndEditors.findTextEditorIdFor(editorPane); if (id) { - result[id] = editorGroupToViewColumn(this._editorGroupService, editorPane.group); + result[id] = editorGroupToColumn(this._editorGroupService, editorPane.group); } } return result; @@ -152,7 +152,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { options: editorOptions }; - const editor = await this._editorService.openEditor(input, viewColumnToEditorGroup(this._editorGroupService, options.position)); + const editor = await this._editorService.openEditor(input, columnToEditorGroup(this._editorGroupService, options.position)); if (!editor) { return undefined; } @@ -166,7 +166,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { await this._editorService.openEditor({ resource: model.uri, options: { preserveFocus: false } - }, viewColumnToEditorGroup(this._editorGroupService, position)); + }, columnToEditorGroup(this._editorGroupService, position)); return; } } diff --git a/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts index d51940002c3..239cd0fba9c 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts @@ -12,7 +12,7 @@ import { MainThreadNotebookDocuments } from 'vs/workbench/api/browser/mainThread import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto'; import { MainThreadNotebookEditors } from 'vs/workbench/api/browser/mainThreadNotebookEditors'; import { extHostCustomer } from 'vs/workbench/api/common/extHostCustomers'; -import { editorGroupToViewColumn } from 'vs/workbench/common/editor'; +import { editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { getNotebookEditorFromEditorPane, IActiveNotebookEditor, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; @@ -240,7 +240,7 @@ export class MainThreadNotebooksAndEditors { documentUri: add.textModel.uri, selections: add.getSelections(), visibleRanges: add.visibleRanges, - viewColumn: pane && editorGroupToViewColumn(this._editorGroupService, pane.group) + viewColumn: pane && editorGroupToColumn(this._editorGroupService, pane.group) }; } } diff --git a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts index 31d9e978497..fa56e4addb3 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts @@ -17,7 +17,7 @@ import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebo import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; -import { editorGroupToViewColumn } from 'vs/workbench/common/editor'; +import { editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { equals } from 'vs/base/common/objects'; import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto'; @@ -96,7 +96,7 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape for (let editorPane of this._editorService.visibleEditorPanes) { const candidate = getNotebookEditorFromEditorPane(editorPane); if (candidate && this._mainThreadEditors.has(candidate.getId())) { - result[candidate.getId()] = editorGroupToViewColumn(this._editorGroupService, editorPane.group); + result[candidate.getId()] = editorGroupToColumn(this._editorGroupService, editorPane.group); } } if (!equals(result, this._currentViewColumnInfo)) { diff --git a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts index d50f6fe2550..9e6ff061c66 100644 --- a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts +++ b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts @@ -9,7 +9,8 @@ import { URI, UriComponents } from 'vs/base/common/uri'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { MainThreadWebviews, reviveWebviewContentOptions, reviveWebviewExtension } from 'vs/workbench/api/browser/mainThreadWebviews'; import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol'; -import { EditorGroupColumn, editorGroupToViewColumn, IEditorInput, viewColumnToEditorGroup } from 'vs/workbench/common/editor'; +import { IEditorInput } from 'vs/workbench/common/editor'; +import { EditorGroupColumn, columnToEditorGroup, editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview'; import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput'; @@ -161,7 +162,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc const mainThreadShowOptions: ICreateWebViewShowOptions = Object.create(null); if (showOptions) { mainThreadShowOptions.preserveFocus = !!showOptions.preserveFocus; - mainThreadShowOptions.group = viewColumnToEditorGroup(this._editorGroupService, showOptions.viewColumn); + mainThreadShowOptions.group = columnToEditorGroup(this._editorGroupService, showOptions.viewColumn); } const extension = reviveWebviewExtension(extensionData); @@ -202,7 +203,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc return; } - const targetGroup = this._editorGroupService.getGroup(viewColumnToEditorGroup(this._editorGroupService, showOptions.viewColumn)) || this._editorGroupService.getGroup(webview.group || 0); + const targetGroup = this._editorGroupService.getGroup(columnToEditorGroup(this._editorGroupService, showOptions.viewColumn)) || this._editorGroupService.getGroup(webview.group || 0); if (targetGroup) { this._webviewWorkbenchService.revealWebview(webview, targetGroup, !!showOptions.preserveFocus); } @@ -243,7 +244,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc state, panelOptions: webviewInput.webview.options, webviewOptions: webviewInput.webview.contentOptions, - }, editorGroupToViewColumn(this._editorGroupService, webviewInput.group || 0)); + }, editorGroupToColumn(this._editorGroupService, webviewInput.group || 0)); } catch (error) { onUnexpectedError(error); webviewInput.webview.html = this._mainThreadWebviews.getWebviewResolvedFailedContent(viewType); @@ -281,7 +282,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc viewStates[handle] = { visible: topLevelInput === group.activeEditor, active: editorInput === activeEditorInput, - position: editorGroupToViewColumn(this._editorGroupService, group.id), + position: editorGroupToColumn(this._editorGroupService, group.id), }; } }; diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index b5d0325a91f..cdee29bf300 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -48,7 +48,7 @@ import { ExtHostInteractive } from 'vs/workbench/api/common/extHostInteractive'; import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService'; import { DebugConfigurationProviderTriggerKind, TestResultState } from 'vs/workbench/api/common/extHostTypes'; import * as tasks from 'vs/workbench/api/common/shared/tasks'; -import { EditorGroupColumn, SaveReason } from 'vs/workbench/common/editor'; +import { SaveReason } from 'vs/workbench/common/editor'; import { IRevealOptions, ITreeItem } from 'vs/workbench/common/views'; import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy'; import { IAdapterDescriptor, IConfig, IDebugSessionReplMode } from 'vs/workbench/contrib/debug/common/debug'; @@ -59,6 +59,7 @@ import { ITextQueryBuilderOptions } from 'vs/workbench/contrib/search/common/que import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { ExtensionRunTestsRequest, ISerializedTestResults, ITestItem, ITestMessage, ITestRunTask, RunTestForControllerRequest, RunTestsRequest, ITestIdWithSrc, TestsDiff, IFileCoverage, CoverageDetails } from 'vs/workbench/contrib/testing/common/testCollection'; import { InternalTimelineOptions, Timeline, TimelineChangeEvent, TimelineOptions, TimelineProviderDescriptor } from 'vs/workbench/contrib/timeline/common/timeline'; +import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { ActivationKind, ExtensionHostKind, MissingExtensionDependency } from 'vs/workbench/services/extensions/common/extensions'; import { createExtHostContextProxyIdentifier as createExtId, createMainContextProxyIdentifier as createMainId, IRPCProtocol } from 'vs/workbench/services/extensions/common/proxyIdentifier'; import { CandidatePort } from 'vs/workbench/services/remote/common/remoteExplorerService'; diff --git a/src/vs/workbench/api/common/extHostCustomEditors.ts b/src/vs/workbench/api/common/extHostCustomEditors.ts index 69557c2a49b..35eb01c390c 100644 --- a/src/vs/workbench/api/common/extHostCustomEditors.ts +++ b/src/vs/workbench/api/common/extHostCustomEditors.ts @@ -16,7 +16,7 @@ import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePa import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters'; import { ExtHostWebviews, shouldSerializeBuffersForPostMessage, toExtensionData } from 'vs/workbench/api/common/extHostWebview'; import { ExtHostWebviewPanels } from 'vs/workbench/api/common/extHostWebviewPanels'; -import { EditorGroupColumn } from 'vs/workbench/common/editor'; +import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import type * as vscode from 'vscode'; import { Cache } from './cache'; import * as extHostProtocol from './extHost.protocol'; diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index 998e59b2adf..f0c495b6361 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -26,11 +26,12 @@ import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol'; import { CommandsConverter } from 'vs/workbench/api/common/extHostCommands'; import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook'; -import { EditorGroupColumn, SaveReason } from 'vs/workbench/common/editor'; +import { SaveReason } from 'vs/workbench/common/editor'; import * as notebooks from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; import * as search from 'vs/workbench/contrib/search/common/search'; import { CoverageDetails, DetailType, ICoveredCount, IFileCoverage, ISerializedTestResults, ITestItem, ITestItemContext, ITestMessage, SerializedTestResultItem } from 'vs/workbench/contrib/testing/common/testCollection'; +import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import type * as vscode from 'vscode'; import * as types from './extHostTypes'; diff --git a/src/vs/workbench/api/common/extHostWebviewPanels.ts b/src/vs/workbench/api/common/extHostWebviewPanels.ts index 9622f8799cc..73d811a9195 100644 --- a/src/vs/workbench/api/common/extHostWebviewPanels.ts +++ b/src/vs/workbench/api/common/extHostWebviewPanels.ts @@ -11,7 +11,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions' import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters'; import { serializeWebviewOptions, ExtHostWebview, ExtHostWebviews, toExtensionData, shouldSerializeBuffersForPostMessage } from 'vs/workbench/api/common/extHostWebview'; import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; -import { EditorGroupColumn } from 'vs/workbench/common/editor'; +import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import type * as vscode from 'vscode'; import * as extHostProtocol from './extHost.protocol'; import * as extHostTypes from './extHostTypes'; diff --git a/src/vs/workbench/browser/parts/editor/editorCommands.ts b/src/vs/workbench/browser/parts/editor/editorCommands.ts index 4751efaa2d6..b94c735f097 100644 --- a/src/vs/workbench/browser/parts/editor/editorCommands.ts +++ b/src/vs/workbench/browser/parts/editor/editorCommands.ts @@ -7,7 +7,8 @@ import { localize } from 'vs/nls'; import { isObject, isString, isUndefined, isNumber, withNullAsUndefined } from 'vs/base/common/types'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; -import { TextCompareEditorVisibleContext, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IEditorInput, IVisibleEditorPane, ActiveEditorStickyContext, EditorsOrder, viewColumnToEditorGroup, EditorGroupColumn, EditorInputCapabilities, isEditorIdentifier } from 'vs/workbench/common/editor'; +import { TextCompareEditorVisibleContext, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IEditorInput, IVisibleEditorPane, ActiveEditorStickyContext, EditorsOrder, EditorInputCapabilities, isEditorIdentifier } from 'vs/workbench/common/editor'; +import { EditorGroupColumn, columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn'; 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'; @@ -451,7 +452,7 @@ function registerOpenEditorAPICommands(): void { if (optionsArg || typeof columnArg === 'number') { const [options, column] = mixinContext(context, optionsArg, columnArg); - await editorService.openEditor({ resource, options, label }, viewColumnToEditorGroup(editorGroupService, column)); + await editorService.openEditor({ resource, options, label }, columnToEditorGroup(editorGroupService, column)); } // do not allow to execute commands from here @@ -495,7 +496,7 @@ function registerOpenEditorAPICommands(): void { modified: { resource: URI.revive(modifiedResource) }, label, options - }, viewColumnToEditorGroup(editorGroupService, column)); + }, columnToEditorGroup(editorGroupService, column)); }); CommandsRegistry.registerCommand(API_OPEN_WITH_EDITOR_COMMAND_ID, (accessor: ServicesAccessor, resource: UriComponents, id: string, columnAndOptions?: [EditorGroupColumn?, ITextEditorOptions?]) => { @@ -515,7 +516,7 @@ function registerOpenEditorAPICommands(): void { } group = neighbourGroup; } else { - group = editorGroupsService.getGroup(viewColumnToEditorGroup(editorGroupsService, columnArg)) ?? editorGroupsService.activeGroup; + group = editorGroupsService.getGroup(columnToEditorGroup(editorGroupsService, columnArg)) ?? editorGroupsService.activeGroup; } return editorService.openEditor({ resource: URI.revive(resource), options: { ...optionsArg, pinned: true, override: id } }, group); diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index e70ea295e72..cf6f9551b87 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -14,12 +14,11 @@ import { IInstantiationService, IConstructorSignature0, ServicesAccessor, Brande import { IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { Registry } from 'vs/platform/registry/common/platform'; import { IEncodingSupport, IModeSupport } from 'vs/workbench/services/textfile/common/textfiles'; -import { GroupsOrder, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ICompositeControl, IComposite } from 'vs/workbench/common/composite'; import { IFileService } from 'vs/platform/files/common/files'; import { IPathData } from 'vs/platform/windows/common/windows'; import { coalesce } from 'vs/base/common/arrays'; -import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { IExtUri } from 'vs/base/common/resources'; import { Schemas } from 'vs/base/common/network'; @@ -1154,37 +1153,3 @@ export const enum EditorsOrder { */ SEQUENTIAL } - -/** - * 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. - */ -export type EditorGroupColumn = number; - -export function viewColumnToEditorGroup(editorGroupService: IEditorGroupsService, viewColumn?: EditorGroupColumn): GroupIdentifier { - if (typeof viewColumn !== 'number' || viewColumn === ACTIVE_GROUP) { - return ACTIVE_GROUP; // prefer active group when position is undefined or passed in as such - } - - const groups = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE); - - let candidateGroup = groups[viewColumn]; - if (candidateGroup) { - return candidateGroup.id; // found direct match - } - - let firstGroup = groups[0]; - if (groups.length === 1 && firstGroup.count === 0) { - return firstGroup.id; // first editor should always open in first group independent from position provided - } - - return SIDE_GROUP; // open to the side if group not found or we are instructed to -} - -export function editorGroupToViewColumn(editorGroupService: IEditorGroupsService, editorGroup: IEditorGroup | GroupIdentifier): EditorGroupColumn { - let group = (typeof editorGroup === 'number') ? editorGroupService.getGroup(editorGroup) : editorGroup; - group = group ?? editorGroupService.activeGroup; - - return editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE).indexOf(group); -} diff --git a/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts b/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts index 85dfcfc62e2..ac2884d76e6 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts @@ -22,7 +22,8 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor'; import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; import { EditorInput } from 'vs/workbench/common/editor/editorInput'; -import { EditorExtensions, EditorsOrder, IEditorInputSerializer, viewColumnToEditorGroup } from 'vs/workbench/common/editor'; +import { EditorExtensions, EditorsOrder, IEditorInputSerializer } from 'vs/workbench/common/editor'; +import { columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { InteractiveEditor } from 'vs/workbench/contrib/interactive/browser/interactiveEditor'; import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput'; import { NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions'; @@ -288,7 +289,7 @@ registerAction2(class extends Action2 { const editorGroupService = accessor.get(IEditorGroupsService); const historyService = accessor.get(IInteractiveHistoryService); const kernelService = accessor.get(INotebookKernelService); - const group = viewColumnToEditorGroup(editorGroupService, column); + const group = columnToEditorGroup(editorGroupService, column); if (resource && resource.scheme === Schemas.vscodeInteractive) { const resourceUri = URI.revive(resource); diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts index 03bbea664e7..eee6fb7e2df 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.ts @@ -9,7 +9,8 @@ import { Action2, ICommandActionTitle, MenuId, registerAction2 } from 'vs/platfo import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { ActiveEditorContext, viewColumnToEditorGroup } from 'vs/workbench/common/editor'; +import { ActiveEditorContext } from 'vs/workbench/common/editor'; +import { columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { DiffElementViewModelBase } from 'vs/workbench/contrib/notebook/browser/diff/diffElementViewModel'; import { 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'; @@ -55,7 +56,7 @@ registerAction2(class extends Action2 { preserveFocus: false, override: EditorOverride.DISABLED } - }, viewColumnToEditorGroup(editorGroupService, undefined)); + }, columnToEditorGroup(editorGroupService, undefined)); } } }); diff --git a/src/vs/workbench/services/editor/browser/editorOverrideService.ts b/src/vs/workbench/services/editor/browser/editorOverrideService.ts index cecc9f2c41c..f8557b7361f 100644 --- a/src/vs/workbench/services/editor/browser/editorOverrideService.ts +++ b/src/vs/workbench/services/editor/browser/editorOverrideService.ts @@ -22,7 +22,7 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { ILogService } from 'vs/platform/log/common/log'; -import { findGroup } from 'vs/workbench/services/editor/browser/editorGroupFinder'; +import { findGroup } from 'vs/workbench/services/editor/common/editorGroupFinder'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { PreferredGroup } from 'vs/workbench/services/editor/common/editorService'; diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index e76183087b7..a25652ecfac 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -38,7 +38,7 @@ import { RegisteredEditorPriority, IEditorOverrideService, OverrideStatus } from import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService'; import { IWorkspaceTrustRequestService, WorkspaceTrustUriResponse } from 'vs/platform/workspace/common/workspaceTrust'; import { IHostService } from 'vs/workbench/services/host/browser/host'; -import { findGroup } from 'vs/workbench/services/editor/browser/editorGroupFinder'; +import { findGroup } from 'vs/workbench/services/editor/common/editorGroupFinder'; type CachedEditorInput = TextResourceEditorInput | IFileEditorInput | UntitledTextEditorInput; diff --git a/src/vs/workbench/services/editor/common/editorGroupColumn.ts b/src/vs/workbench/services/editor/common/editorGroupColumn.ts new file mode 100644 index 00000000000..89737dfe3de --- /dev/null +++ b/src/vs/workbench/services/editor/common/editorGroupColumn.ts @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { GroupIdentifier } from 'vs/workbench/common/editor'; +import { IEditorGroupsService, GroupsOrder, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { ACTIVE_GROUP, SIDE_GROUP } 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. + */ +export type EditorGroupColumn = number; + +export function columnToEditorGroup(editorGroupService: IEditorGroupsService, column?: EditorGroupColumn): GroupIdentifier { + if (typeof column !== 'number' || column === ACTIVE_GROUP) { + return ACTIVE_GROUP; // prefer active group when position is undefined or passed in as such + } + + const groups = editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE); + + let candidateGroup = groups[column]; + if (candidateGroup) { + return candidateGroup.id; // found direct match + } + + let firstGroup = groups[0]; + if (groups.length === 1 && firstGroup.count === 0) { + return firstGroup.id; // first editor should always open in first group independent from position provided + } + + return SIDE_GROUP; // open to the side if group not found or we are instructed to +} + +export function editorGroupToColumn(editorGroupService: IEditorGroupsService, editorGroup: IEditorGroup | GroupIdentifier): EditorGroupColumn { + let group = (typeof editorGroup === 'number') ? editorGroupService.getGroup(editorGroup) : editorGroup; + group = group ?? editorGroupService.activeGroup; + + return editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE).indexOf(group); +} diff --git a/src/vs/workbench/services/editor/browser/editorGroupFinder.ts b/src/vs/workbench/services/editor/common/editorGroupFinder.ts similarity index 100% rename from src/vs/workbench/services/editor/browser/editorGroupFinder.ts rename to src/vs/workbench/services/editor/common/editorGroupFinder.ts diff --git a/src/vs/workbench/test/browser/api/extHostWebview.test.ts b/src/vs/workbench/test/browser/api/extHostWebview.test.ts index 075e47d631a..b00fe229f84 100644 --- a/src/vs/workbench/test/browser/api/extHostWebview.test.ts +++ b/src/vs/workbench/test/browser/api/extHostWebview.test.ts @@ -16,7 +16,7 @@ import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; import { ExtHostWebviews } from 'vs/workbench/api/common/extHostWebview'; import { ExtHostWebviewPanels } from 'vs/workbench/api/common/extHostWebviewPanels'; import { webviewResourceBaseHost } from 'vs/workbench/api/common/shared/webview'; -import { EditorGroupColumn } from 'vs/workbench/common/editor'; +import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import type * as vscode from 'vscode'; import { SingleProxyRPCProtocol } from './testRPCProtocol';