From ef71c65923e26593a2ac10d74cf442ad53a6ca25 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Tue, 5 Apr 2022 14:56:25 -0400 Subject: [PATCH] Change onDidChangeTab event --- .../workbench/api/common/extHostEditorTabs.ts | 29 ++++++++++++++++--- .../test/browser/extHostEditorTabs.test.ts | 4 +-- src/vscode-dts/vscode.proposed.tabs.d.ts | 9 ++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/api/common/extHostEditorTabs.ts b/src/vs/workbench/api/common/extHostEditorTabs.ts index a4369675619..1c94af226e1 100644 --- a/src/vs/workbench/api/common/extHostEditorTabs.ts +++ b/src/vs/workbench/api/common/extHostEditorTabs.ts @@ -201,7 +201,7 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs { readonly _serviceBrand: undefined; private readonly _proxy: MainThreadEditorTabsShape; - private readonly _onDidChangeTabs = new Emitter(); + private readonly _onDidChangeTabs = new Emitter(); private readonly _onDidChangeTabGroups = new Emitter(); // Have to use ! because this gets initialized via an RPC proxy @@ -291,9 +291,30 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs { throw new Error('Update Tabs IPC call received before group creation.'); } const tab = group.acceptTabOperation(operation); - // We don't want to fire a change event with a closed tab to prevent an invalid tabs from being received - if (operation.kind !== TabModelOperationKind.TAB_CLOSE) { - this._onDidChangeTabs.fire([tab.apiObject]); + + // Construct the tab change event based on the operation + switch (operation.kind) { + case TabModelOperationKind.TAB_OPEN: + this._onDidChangeTabs.fire({ + added: [tab.apiObject], + removed: [], + changed: [] + }); + return; + case TabModelOperationKind.TAB_CLOSE: + this._onDidChangeTabs.fire({ + added: [], + removed: [tab.apiObject], + changed: [] + }); + return; + case TabModelOperationKind.TAB_UPDATE: + this._onDidChangeTabs.fire({ + added: [], + removed: [], + changed: [tab.apiObject] + }); + return; } } diff --git a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts index 9be9b64b71d..8d8f36f9907 100644 --- a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts +++ b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts @@ -361,7 +361,7 @@ suite('ExtHostEditorTabs', function () { const tab = extHostEditorTabs.tabGroups.groups[0].tabs[0]; - const p = new Promise(resolve => extHostEditorTabs.tabGroups.onDidChangeTabs(resolve)); + const p = new Promise(resolve => extHostEditorTabs.tabGroups.onDidChangeTabs(resolve)); extHostEditorTabs.$acceptTabOperation({ groupId: 12, @@ -370,7 +370,7 @@ suite('ExtHostEditorTabs', function () { tabDto: { ...tabDto, label: 'NEW LABEL' } }); - const changedTab = (await p)[0]; + const changedTab = (await p).changed[0]; assert.ok(tab === changedTab); assert.strictEqual(changedTab.label, 'NEW LABEL'); diff --git a/src/vscode-dts/vscode.proposed.tabs.d.ts b/src/vscode-dts/vscode.proposed.tabs.d.ts index 9b424df5b68..b408dd8311f 100644 --- a/src/vscode-dts/vscode.proposed.tabs.d.ts +++ b/src/vscode-dts/vscode.proposed.tabs.d.ts @@ -153,6 +153,12 @@ declare module 'vscode' { export const tabGroups: TabGroups; } + export interface TabChangeEvent { + readonly added: readonly Tab[]; + readonly removed: readonly Tab[]; + readonly changed: readonly Tab[]; + } + export interface TabGroup { /** * Whether or not the group is currently active @@ -199,8 +205,7 @@ declare module 'vscode' { /** * An {@link Event event} which fires when a {@link Tab tabs} have changed. */ - readonly onDidChangeTabs: Event; - // readonly onDidChangeTabs: Event<{ opened: readonly Tab[], closed: readonly Tab[], changed: readonly Tab[] }>; + readonly onDidChangeTabs: Event; /** * Closes the tab. This makes the tab object invalid and the tab