mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 05:51:32 +01:00
Support patching for editor open and editor close
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
import type * as vscode from 'vscode';
|
||||
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
|
||||
import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext, MainThreadEditorTabsShape, TabInputKind } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext, MainThreadEditorTabsShape, TabInputKind, TabModelOperationKind, TabOperation } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -155,20 +155,39 @@ class ExtHostEditorTabGroup {
|
||||
this._dto = dto;
|
||||
}
|
||||
|
||||
acceptTabDtoUpdate(dto: IEditorTabDto) {
|
||||
const tab = this._tabs.find(extHostTab => extHostTab.tabId === dto.id);
|
||||
acceptTabOperation(operation: TabOperation): ExtHostEditorTab {
|
||||
// In the open case we add the tab to the group
|
||||
if (operation.kind === TabModelOperationKind.TAB_OPEN) {
|
||||
const tab = new ExtHostEditorTab(operation.tabDto, this, () => this.activeTabId());
|
||||
// Insert tab at editor index
|
||||
this._tabs.splice(operation.index, 0, tab);
|
||||
if (operation.tabDto.isActive) {
|
||||
this._activeTabId = tab.tabId;
|
||||
}
|
||||
return tab;
|
||||
} else if (operation.kind === TabModelOperationKind.TAB_CLOSE) {
|
||||
const tab = this._tabs.splice(operation.index, 1)[0];
|
||||
if (!tab) {
|
||||
throw new Error(`Tab close updated received for index ${operation.index} which does not exist`);
|
||||
}
|
||||
if (tab.tabId === this._activeTabId) {
|
||||
this._activeTabId = '';
|
||||
}
|
||||
return tab;
|
||||
}
|
||||
const tab = this._tabs.find(extHostTab => extHostTab.tabId === operation.tabDto.id);
|
||||
if (!tab) {
|
||||
throw new Error('INVALID tab');
|
||||
}
|
||||
if (dto.isActive) {
|
||||
this._activeTabId = dto.id;
|
||||
} else if (this._activeTabId === dto.id && !dto.isActive) {
|
||||
if (operation.tabDto.isActive) {
|
||||
this._activeTabId = operation.tabDto.id;
|
||||
} else if (this._activeTabId === operation.tabDto.id && !operation.tabDto.isActive) {
|
||||
// Events aren't guaranteed to be in order so if we receive a dto that matches the active tab id
|
||||
// but isn't active we mark the active tab id as empty. This prevent onDidActiveTabChange frorm
|
||||
// firing incorrectly
|
||||
this._activeTabId = '';
|
||||
}
|
||||
tab.acceptDtoUpdate(dto);
|
||||
tab.acceptDtoUpdate(operation.tabDto);
|
||||
return tab;
|
||||
}
|
||||
|
||||
@@ -285,15 +304,18 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
|
||||
this._onDidChangeTabGroups.fire([group.apiObject]);
|
||||
}
|
||||
|
||||
$acceptTabUpdate(groupId: number, tabDto: IEditorTabDto) {
|
||||
const group = this._extHostTabGroups.find(group => group.groupId === groupId);
|
||||
$acceptTabOperation(operation: TabOperation) {
|
||||
const group = this._extHostTabGroups.find(group => group.groupId === operation.groupId);
|
||||
if (!group) {
|
||||
throw new Error('Update Tabs IPC call received before group creation.');
|
||||
}
|
||||
const tab = group.acceptTabDtoUpdate(tabDto);
|
||||
this._onDidChangeTabs.fire([tab.apiObject]);
|
||||
if (tab.apiObject.isActive) {
|
||||
this._onDidChangeActiveTab.fire(tab.apiObject);
|
||||
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]);
|
||||
if (tab.apiObject.isActive) {
|
||||
this._onDidChangeActiveTab.fire(tab.apiObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user