diff --git a/packages/plugin-ext/src/plugin/editors-and-documents.ts b/packages/plugin-ext/src/plugin/editors-and-documents.ts index a129517ab369b..7203e4aa0ddd4 100644 --- a/packages/plugin-ext/src/plugin/editors-and-documents.ts +++ b/packages/plugin-ext/src/plugin/editors-and-documents.ts @@ -108,18 +108,19 @@ export class EditorsAndDocumentsExtImpl implements EditorsAndDocumentsExt { } } - if (delta.newActiveEditor !== undefined) { - ok(delta.newActiveEditor === null || this.editors.has(delta.newActiveEditor), `active editor '${delta.newActiveEditor}' doesn't exist`); - this.activeEditorId = delta.newActiveEditor; + if (this.activeEditorId && delta.removedEditors && delta.removedEditors.indexOf(this.activeEditorId) !== -1 && this.editors.size !== 0) { + // to be compatible with VSCode, when active editor is closed onDidChangeActiveTextEditor + // should be trigerred with undefined before next editor, if any, become active. + this._onDidChangeActiveTextEditors.fire(undefined); } - dispose(removedDocuments); - dispose(removedEditors); - if (delta.removedDocuments) { this._onDidRemoveDocuments.fire(removedDocuments); } + dispose(removedDocuments); + dispose(removedEditors); + if (delta.addedDocuments) { this._onDidAddDocuments.fire(addedDocuments); } @@ -129,12 +130,16 @@ export class EditorsAndDocumentsExtImpl implements EditorsAndDocumentsExt { } if (delta.newActiveEditor !== undefined) { - this._onDidChangeActiveTextEditors.fire(this.activeEditor()); + ok(delta.newActiveEditor === null || this.editors.has(delta.newActiveEditor), `active editor '${delta.newActiveEditor}' doesn't exist`); + // do not fire event if focus returns to the same editor + if (delta.newActiveEditor !== this.activeEditorId) { + this.activeEditorId = delta.newActiveEditor; + this._onDidChangeActiveTextEditors.fire(this.activeEditor()); + } } else if (this.editors.size === 0 && delta.removedEditors) { this.activeEditorId = undefined; this._onDidChangeActiveTextEditors.fire(undefined); } - } allEditors(): TextEditorExt[] {