mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-22 08:09:42 +01:00
Have tab label use tab id
This commit is contained in:
@@ -15,6 +15,12 @@ import { columnToEditorGroup, EditorGroupColumn, editorGroupToColumn } from 'vs/
|
||||
import { GroupDirection, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IEditorsChangeEvent, IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
||||
|
||||
interface TabInfo {
|
||||
tab: IEditorTabDto;
|
||||
group: IEditorGroup;
|
||||
editorInput: EditorInput;
|
||||
}
|
||||
@extHostNamedCustomer(MainContext.MainThreadEditorTabs)
|
||||
export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
|
||||
|
||||
@@ -22,6 +28,8 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
|
||||
private readonly _proxy: IExtHostEditorTabsShape;
|
||||
private _tabGroupModel: IEditorTabGroupDto[] = [];
|
||||
private readonly _groupModel: Map<number, IEditorTabGroupDto> = new Map();
|
||||
private readonly _tabInfoLookup: Map<string, TabInfo> = new Map();
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@IEditorGroupsService private readonly _editorGroupsService: IEditorGroupsService,
|
||||
@@ -66,6 +74,16 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
|
||||
return tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique id for a tab
|
||||
* @param editor The editor input
|
||||
* @param groupId The group id
|
||||
* @returns A unique identifier for a specific tab
|
||||
*/
|
||||
private _generateTabId(editor: EditorInput, groupId: number) {
|
||||
return `${groupId}~${editor.editorId}-${editor.typeId}-${editor.resource?.toString()}`;
|
||||
}
|
||||
|
||||
|
||||
private _tabToUntypedEditorInput(tab: IEditorTabDto): IUntypedEditorInput {
|
||||
if (tab.kind !== TabKind.Diff && tab.kind !== TabKind.SidebySide) {
|
||||
@@ -103,9 +121,10 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
|
||||
* @param editorIndex The index of the editor within that group
|
||||
*/
|
||||
private _onDidTabLabelChange(groupId: number, editorInput: EditorInput, editorIndex: number) {
|
||||
const tabs = this._groupModel.get(groupId)?.tabs;
|
||||
if (tabs) {
|
||||
tabs[editorIndex].label = editorInput.getName();
|
||||
const tabId = this._generateTabId(editorInput, groupId);
|
||||
const tabInfo = this._tabInfoLookup.get(tabId);
|
||||
if (tabInfo) {
|
||||
tabInfo.tab.label = editorInput.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +241,7 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
|
||||
private _createTabsModel(): void {
|
||||
this._tabGroupModel = [];
|
||||
this._groupModel.clear();
|
||||
this._tabInfoLookup.clear();
|
||||
let tabs: IEditorTabDto[] = [];
|
||||
for (const group of this._editorGroupsService.groups) {
|
||||
const currentTabGroupModel: IEditorTabGroupDto = {
|
||||
@@ -238,6 +258,12 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
|
||||
currentTabGroupModel.activeTab = tab;
|
||||
}
|
||||
tabs.push(tab);
|
||||
// Add information about the tab to the lookup
|
||||
this._tabInfoLookup.set(this._generateTabId(editor, group.id), {
|
||||
group,
|
||||
tab,
|
||||
editorInput: editor
|
||||
});
|
||||
});
|
||||
currentTabGroupModel.tabs = tabs;
|
||||
this._tabGroupModel.push(currentTabGroupModel);
|
||||
|
||||
Reference in New Issue
Block a user