Change onDidChangeTab event

This commit is contained in:
Logan Ramos
2022-04-05 14:56:25 -04:00
parent 2154f3d008
commit ef71c65923
3 changed files with 34 additions and 8 deletions

View File

@@ -201,7 +201,7 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
readonly _serviceBrand: undefined;
private readonly _proxy: MainThreadEditorTabsShape;
private readonly _onDidChangeTabs = new Emitter<vscode.Tab[]>();
private readonly _onDidChangeTabs = new Emitter<vscode.TabChangeEvent>();
private readonly _onDidChangeTabGroups = new Emitter<vscode.TabGroup[]>();
// 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;
}
}

View File

@@ -361,7 +361,7 @@ suite('ExtHostEditorTabs', function () {
const tab = extHostEditorTabs.tabGroups.groups[0].tabs[0];
const p = new Promise<readonly vscode.Tab[]>(resolve => extHostEditorTabs.tabGroups.onDidChangeTabs(resolve));
const p = new Promise<vscode.TabChangeEvent>(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');