diff --git a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts index 5b2351f9896..2bd9ae09322 100644 --- a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts +++ b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts @@ -63,11 +63,11 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape { const editorId = editor.editorId; const tab: IEditorTabDto = { id: this._generateTabId(editor, group.id), - viewColumn: editorGroupToColumn(this._editorGroupsService, group), label: editor.getName(), editorId, input: this._editorInputToDto(editor), isPinned: group.isSticky(editorIndex), + isPreview: group.isPinned(editorIndex), isActive: group.isActive(editor), isDirty: editor.isDirty() }; @@ -259,12 +259,12 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape { } /** - * Called when the tab is pinned / unpinned + * Called when the tab is pinned/unpinned * @param groupId The id of the group the tab is in * @param editorIndex The index of the tab * @param editor The editor input represented by the tab */ - private _onDidTabStickyChange(groupId: number, editorIndex: number, editor: EditorInput) { + private _onDidTabPinChange(groupId: number, editorIndex: number, editor: EditorInput) { const tabId = this._generateTabId(editor, groupId); const tabInfo = this._tabInfoLookup.get(tabId); const group = tabInfo?.group; @@ -280,6 +280,28 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape { this._proxy.$acceptTabUpdate(groupId, tab); } + /** + * Called when the tab is preview / unpreviewed + * @param groupId The id of the group the tab is in + * @param editorIndex The index of the tab + * @param editor The editor input represented by the tab + */ + private _onDidTabPreviewChange(groupId: number, editorIndex: number, editor: EditorInput) { + const tabId = this._generateTabId(editor, groupId); + const tabInfo = this._tabInfoLookup.get(tabId); + const group = tabInfo?.group; + const tab = tabInfo?.tab; + // Something wrong with the model state so we rebuild + if (!group || !tab) { + console.error('Invalid model for sticky change, rebuilding'); + this._createTabsModel(); + return; + } + // Whether or not the tab has the pin icon (internally it's called sticky) + tab.isPreview = group.isPinned(editorIndex); + this._proxy.$acceptTabUpdate(groupId, tab); + } + /** * Builds the model from scratch based on the current state of the editor service. */ @@ -374,7 +396,12 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape { } case GroupModelChangeKind.EDITOR_STICKY: if (event.editorIndex !== undefined && event.editor !== undefined) { - this._onDidTabStickyChange(event.groupId, event.editorIndex, event.editor); + this._onDidTabPinChange(event.groupId, event.editorIndex, event.editor); + break; + } + case GroupModelChangeKind.EDITOR_PIN: + if (event.editorIndex !== undefined && event.editor !== undefined) { + this._onDidTabPreviewChange(event.groupId, event.editorIndex, event.editor); break; } default: @@ -391,7 +418,7 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape { throw new Error(`Attempted to close tab with id ${tabId} which does not exist`); } let targetGroup: IEditorGroup | undefined; - const sourceGroup = this._editorGroupsService.getGroup(columnToEditorGroup(this._editorGroupsService, tab.viewColumn)); + const sourceGroup = this._editorGroupsService.getGroup(tabInfo.group.id); if (!sourceGroup) { return; } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index b54a90093a1..07de952e587 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -672,12 +672,12 @@ export interface IEditorTabGroupDto { export interface IEditorTabDto { id: string; - viewColumn: EditorGroupColumn; label: string; input: AnyInputDto; editorId?: string; isActive: boolean; isPinned: boolean; + isPreview: boolean; isDirty: boolean; } diff --git a/src/vs/workbench/api/common/extHostEditorTabs.ts b/src/vs/workbench/api/common/extHostEditorTabs.ts index 586c6005c45..f94c1479fac 100644 --- a/src/vs/workbench/api/common/extHostEditorTabs.ts +++ b/src/vs/workbench/api/common/extHostEditorTabs.ts @@ -25,10 +25,12 @@ class ExtHostEditorTab { private _apiObject: vscode.Tab | undefined; private _dto!: IEditorTabDto; private _input: AnyTabInput | undefined; + private _parentGroup: ExtHostEditorTabGroup; private readonly _activeTabIdGetter: () => string; - constructor(dto: IEditorTabDto, activeTabIdGetter: () => string) { + constructor(dto: IEditorTabDto, parentGroup: ExtHostEditorTabGroup, activeTabIdGetter: () => string) { this._activeTabIdGetter = activeTabIdGetter; + this._parentGroup = parentGroup; this.acceptDtoUpdate(dto); } @@ -53,8 +55,11 @@ class ExtHostEditorTab { get isPinned() { return that._dto.isDirty; }, - get viewColumn() { - return typeConverters.ViewColumn.to(that._dto.viewColumn); + get isPreview() { + return that._dto.isPreview; + }, + get parentGroup() { + return that._parentGroup.apiObject; } }; this._apiObject = Object.freeze(obj); @@ -105,7 +110,7 @@ class ExtHostEditorTabGroup { if (tabDto.isActive) { this._activeTabId = tabDto.id; } - this._tabs.push(new ExtHostEditorTab(tabDto, () => this.activeTabId())); + this._tabs.push(new ExtHostEditorTab(tabDto, this, () => this.activeTabId())); } } diff --git a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts index b50f057178a..cc7d71c94c2 100644 --- a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts +++ b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts @@ -20,8 +20,8 @@ suite('ExtHostEditorTabs', function () { isActive: true, isDirty: true, isPinned: true, + isPreview: false, label: 'label1', - viewColumn: 0, }; function createTabDto(dto?: Partial): IEditorTabDto { @@ -54,7 +54,6 @@ suite('ExtHostEditorTabs', function () { isDirty: true, isPinned: true, label: 'label1', - viewColumn: 0, }); extHostEditorTabs.$acceptEditorTabModel([{ @@ -141,7 +140,6 @@ suite('ExtHostEditorTabs', function () { isPinned: true, label: 'label1', editorId: 'default', - viewColumn: 0, }); extHostEditorTabs.$acceptEditorTabModel([{ @@ -277,8 +275,7 @@ suite('ExtHostEditorTabs', function () { isPinned: true, label: 'label1', input: { kind: TabInputKind.TextInput, uri: URI.parse('file://abc/AAA.txt') }, - editorId: 'default', - viewColumn: 0, + editorId: 'default' }); const tabDtoBBB = createTabDto({ @@ -288,8 +285,7 @@ suite('ExtHostEditorTabs', function () { isPinned: true, label: 'label1', input: { kind: TabInputKind.TextInput, uri: URI.parse('file://abc/BBB.txt') }, - editorId: 'default', - viewColumn: 0, + editorId: 'default' }); // single dirty tab @@ -364,8 +360,7 @@ suite('ExtHostEditorTabs', function () { isDirty: true, isPinned: true, label: 'label1', - editorId: 'default', - viewColumn: 0, + editorId: 'default' }); extHostEditorTabs.$acceptEditorTabModel([{ @@ -402,8 +397,7 @@ suite('ExtHostEditorTabs', function () { isDirty: true, isPinned: true, label: 'label1', - editorId: 'default', - viewColumn: 0, + editorId: 'default' }); extHostEditorTabs.$acceptEditorTabModel([{ diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index ed6e9c20247..2fdee0b8f17 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -854,8 +854,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView { return this.model.previewEditor; } - isPinned(editor: EditorInput): boolean { - return this.model.isPinned(editor); + isPinned(editorOrIndex: EditorInput | number): boolean { + return this.model.isPinned(editorOrIndex); } isSticky(editorOrIndex: EditorInput | number): boolean { diff --git a/src/vs/workbench/services/editor/common/editorGroupsService.ts b/src/vs/workbench/services/editor/common/editorGroupsService.ts index 016a0772389..d19dc93600c 100644 --- a/src/vs/workbench/services/editor/common/editorGroupsService.ts +++ b/src/vs/workbench/services/editor/common/editorGroupsService.ts @@ -579,7 +579,7 @@ export interface IEditorGroup { /** * Find out if the provided editor is pinned in the group. */ - isPinned(editor: EditorInput): boolean; + isPinned(editor: EditorInput | number): boolean; /** * Find out if the provided editor or index of editor is sticky in the group. diff --git a/src/vscode-dts/vscode.proposed.tabs.d.ts b/src/vscode-dts/vscode.proposed.tabs.d.ts index 1350504a46a..b5010d5a597 100644 --- a/src/vscode-dts/vscode.proposed.tabs.d.ts +++ b/src/vscode-dts/vscode.proposed.tabs.d.ts @@ -49,10 +49,9 @@ declare module 'vscode' { readonly label: string; /** - * The column which the tab belongs to + * The group which the tab belongs to */ - // TODO@API point to TabGroup instead? - readonly viewColumn: ViewColumn; + readonly parentGroup: TabGroup; // TODO@API NAME: optional readonly input: TextTabInput | TextDiffTabInput | CustomEditorTabInput | NotebookEditorTabInput | NotebookDiffEditorTabInput | unknown; @@ -69,10 +68,14 @@ declare module 'vscode' { readonly isDirty: boolean; /** - * Whether or not the tab is pinned + * Whether or not the tab is pinned (pin icon is present) */ - // TODO@API name: preview, see TextDocumentShowOptions readonly isPinned: boolean; + + /** + * Whether or not the tab is in preview mode. + */ + readonly isPreview: boolean; } export namespace window {