Skip to content

Commit

Permalink
Open Editors list is displays incorrect list when the SCM Working Set…
Browse files Browse the repository at this point in the history
…s feature is used (fix #219159)
  • Loading branch information
bpasero committed Jul 31, 2024
1 parent cfcc0cd commit 0d2cba3
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/vs/workbench/browser/parts/editor/editorPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {
private readonly _onDidActivateGroup = this._register(new Emitter<IEditorGroupView>());
readonly onDidActivateGroup = this._onDidActivateGroup.event;

private readonly _onDidAddGroup = this._register(new Emitter<IEditorGroupView>());
private readonly _onDidAddGroup = this._register(new PauseableEmitter<IEditorGroupView>());
readonly onDidAddGroup = this._onDidAddGroup.event;

private readonly _onDidRemoveGroup = this._register(new PauseableEmitter<IEditorGroupView>());
Expand Down Expand Up @@ -1356,7 +1356,17 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {

private async doApplyState(state: IEditorPartUIState, options?: IEditorGroupViewOptions): Promise<void> {
const groups = await this.doPrepareApplyState();
const resumeEvents = this.disposeGroups(true /* suspress events for the duration of applying state */);

// Pause add/remove events for groups during the duration of applying the state
// This ensures that we can do this transition atomically with the new state
// being ready when the events are fired. This is important because usually there
// is never the state where no groups are present, but for this transition we
// need to temporarily dispose all groups to restore the new set.

this._onDidAddGroup.pause();
this._onDidRemoveGroup.pause();

this.disposeGroups();

// MRU
this.mostRecentActiveGroups = state.mostRecentActiveGroups;
Expand All @@ -1365,7 +1375,12 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {
try {
this.doApplyGridState(state.serializedGrid, state.activeGroup, undefined, options);
} finally {
resumeEvents();
// It is very important to keep this order: first resume the events for
// removed groups and then for added groups. Many listeners may store
// groups in sets by their identifier and groups can have the same
// identifier before and after.
this._onDidRemoveGroup.resume();
this._onDidAddGroup.resume();
}

// Restore editors that were not closed before and are now opened now
Expand Down Expand Up @@ -1439,13 +1454,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {
};
}

private disposeGroups(): void;
private disposeGroups(surpressEvents: boolean): Function;
private disposeGroups(surpressEvents?: boolean): Function | void {
if (surpressEvents) {
this._onDidRemoveGroup.pause();
}

private disposeGroups(): void {
for (const group of this.groups) {
group.dispose();

Expand All @@ -1454,10 +1463,6 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupsView {

this.groupViews.clear();
this.mostRecentActiveGroups = [];

if (surpressEvents) {
return () => this._onDidRemoveGroup.resume();
}
}

override dispose(): void {
Expand Down

0 comments on commit 0d2cba3

Please sign in to comment.