diff --git a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts index c4e1424ba8f..d3095a8ab90 100644 --- a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts +++ b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts @@ -55,7 +55,8 @@ export class MainThreadEditorTabs { resource: editor instanceof SideBySideEditorInput ? EditorResourceAccessor.getCanonicalUri(editor, { supportSideBySide: SideBySideEditor.PRIMARY }) : EditorResourceAccessor.getCanonicalUri(editor), editorId, additionalResourcesAndViewIds: [], - isActive: group.isActive(editor) + isActive: group.isActive(editor), + isDirty: editor.isDirty() }; tab.additionalResourcesAndViewIds.push({ resource: tab.resource, viewId: tab.editorId }); if (editor instanceof SideBySideEditorInput) { @@ -173,6 +174,14 @@ export class MainThreadEditorTabs { this._groupModel.get(groupId)!.activeTab = activeTab; } + private _onDidTabDirty(groupId: number, editorIndex: number, editor: EditorInput) { + const tab = this._groupModel.get(groupId)?.tabs[editorIndex]; + if (!tab) { + return; + } + tab.isDirty = editor.isDirty(); + } + /** * Builds the model from scratch based on the current state of the editor service. */ @@ -254,6 +263,11 @@ export class MainThreadEditorTabs { this._onDidTabActiveChange(event.groupId, event.editorIndex); break; } + case GroupModelChangeKind.EDITOR_DIRTY: + if (event.editorIndex && event.editor) { + this._onDidTabDirty(event.groupId, event.editorIndex, event.editor); + break; + } default: // If it's not an optimized case we rebuild the tabs model from scratch this._createTabsModel(); diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index c448595d763..ea632c99395 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -631,6 +631,7 @@ export interface IEditorTabDto { resource?: UriComponents; editorId?: string; isActive: boolean; + isDirty: boolean; additionalResourcesAndViewIds: { resource?: UriComponents; viewId?: string }[]; } diff --git a/src/vs/workbench/api/common/extHostEditorTabs.ts b/src/vs/workbench/api/common/extHostEditorTabs.ts index 002d80510b8..1f780100c5e 100644 --- a/src/vs/workbench/api/common/extHostEditorTabs.ts +++ b/src/vs/workbench/api/common/extHostEditorTabs.ts @@ -17,6 +17,7 @@ export interface IEditorTab { resource: vscode.Uri | undefined; viewId: string | undefined; isActive: boolean; + isDirty: boolean; additionalResourcesAndViewIds: { resource: vscode.Uri | undefined; viewId: string | undefined }[]; move(index: number, viewColumn: ViewColumn): Promise; close(): Promise; @@ -91,6 +92,7 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs { additionalResourcesAndViewIds: tabDto.additionalResourcesAndViewIds.map(({ resource, viewId }) => ({ resource: URI.revive(resource), viewId })), viewId: tabDto.editorId, isActive: tabDto.isActive, + isDirty: tabDto.isDirty, move: async (index: number, viewColumn: ViewColumn) => { this._proxy.$moveTab(tabDto, index, typeConverters.ViewColumn.from(viewColumn)); // TODO: Need an on did change tab event at the group level diff --git a/src/vscode-dts/vscode.proposed.tabs.d.ts b/src/vscode-dts/vscode.proposed.tabs.d.ts index 619d0184442..09fb65e6d7d 100644 --- a/src/vscode-dts/vscode.proposed.tabs.d.ts +++ b/src/vscode-dts/vscode.proposed.tabs.d.ts @@ -50,6 +50,11 @@ declare module 'vscode' { */ readonly isActive: boolean; + /** + * Whether or not the dirty indicator is present on the tab + */ + readonly isDirty: boolean; + /** * Moves a tab to the given index within the column. * If the index is out of range, the tab will be moved to the end of the column. @@ -77,7 +82,7 @@ declare module 'vscode' { /** * All the groups within the group container */ - all: TabGroup[]; + readonly all: TabGroup[]; /** * An {@link Event} which fires when a group changes. @@ -90,21 +95,21 @@ declare module 'vscode' { /** * Whether or not the group is currently active */ - isActive: boolean; + readonly isActive: boolean; /** * The view column of the groups */ - viewColumn: ViewColumn; + readonly viewColumn: ViewColumn; /** * The active tab within the group */ - activeTab: Tab | undefined; + readonly activeTab: Tab | undefined; /** * The list of tabs contained within the group */ - tabs: Tab[]; + readonly tabs: Tab[]; } }