mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
Use a map instead of a object to store editors
This commit is contained in:
@@ -306,7 +306,7 @@ export class MainThreadDocumentsAndEditors {
|
||||
|
||||
private readonly _toDispose = new DisposableStore();
|
||||
private readonly _proxy: ExtHostDocumentsAndEditorsShape;
|
||||
private _textEditors = <{ [id: string]: MainThreadTextEditor }>Object.create(null);
|
||||
private readonly _textEditors = new Map<string, MainThreadTextEditor>();
|
||||
|
||||
private _onTextEditorAdd = new Emitter<MainThreadTextEditor[]>();
|
||||
private _onTextEditorRemove = new Emitter<string[]>();
|
||||
@@ -368,16 +368,16 @@ export class MainThreadDocumentsAndEditors {
|
||||
const mainThreadEditor = new MainThreadTextEditor(apiEditor.id, apiEditor.editor.getModel(),
|
||||
apiEditor.editor, { onGainedFocus() { }, onLostFocus() { } }, this._modelService);
|
||||
|
||||
this._textEditors[apiEditor.id] = mainThreadEditor;
|
||||
this._textEditors.set(apiEditor.id, mainThreadEditor);
|
||||
addedEditors.push(mainThreadEditor);
|
||||
}
|
||||
|
||||
// removed editors
|
||||
for (const { id } of delta.removedEditors) {
|
||||
const mainThreadEditor = this._textEditors[id];
|
||||
const mainThreadEditor = this._textEditors.get(id);
|
||||
if (mainThreadEditor) {
|
||||
mainThreadEditor.dispose();
|
||||
delete this._textEditors[id];
|
||||
this._textEditors.delete(id);
|
||||
removedEditors.push(id);
|
||||
}
|
||||
}
|
||||
@@ -448,16 +448,16 @@ export class MainThreadDocumentsAndEditors {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
findTextEditorIdFor(editor: IWorkbenchEditor): string | undefined {
|
||||
for (const id in this._textEditors) {
|
||||
if (this._textEditors[id].matches(editor)) {
|
||||
findTextEditorIdFor(inputEditor: IWorkbenchEditor): string | undefined {
|
||||
for (const [id, editor] of this._textEditors) {
|
||||
if (editor.matches(inputEditor)) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getEditor(id: string): MainThreadTextEditor {
|
||||
return this._textEditors[id];
|
||||
getEditor(id: string): MainThreadTextEditor | undefined {
|
||||
return this._textEditors.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user