diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index 241c4ee510ae8161372ca4f6eb1ae23663f17cea..4ad00003a5967c7207f2a3f5601fefc0bd799f70 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -496,6 +496,17 @@ export class EditorPart extends Part implements IEditorPart { return TPromise.as(null); } + // Check for dirty and veto + return this.handleDirty([input]).then(veto => { + if (veto) { + return; + } + + return this.doCloseEditor(position, input); + }); + } + + private doCloseEditor(position: Position, input: EditorInput): TPromise { const group = this.groupAt(position); // Closing the active editor of the group is a bit more work @@ -504,60 +515,43 @@ export class EditorPart extends Part implements IEditorPart { } // Closing inactive editor is just a model update - this.doCloseInactiveEditor(input, position); + return this.doCloseInactiveEditor(input, position); } private doCloseActiveEditor(position: Position): TPromise { - // Check for dirty and veto - const input = this.visibleInputs[position]; - return this.handleDirty([input]).then(veto => { - if (veto) { - return; - } - - // Update visible inputs for position - this.visibleInputs[position] = null; - - // Dispose previous input listener if any - if (this.visibleInputListeners[position]) { - this.visibleInputListeners[position](); - this.visibleInputListeners[position] = null; - } + // Update visible inputs for position + this.visibleInputs[position] = null; - // Reset counter - this.editorSetInputErrorCounter[position] = 0; + // Dispose previous input listener if any + if (this.visibleInputListeners[position]) { + this.visibleInputListeners[position](); + this.visibleInputListeners[position] = null; + } - // Update stacks model - const group = this.groupAt(position); - group.closeEditor(group.activeEditor); + // Reset counter + this.editorSetInputErrorCounter[position] = 0; - // Close group is this is the last editor in group - if (group.count === 0) { - return this.doCloseGroup(position); - } + // Update stacks model + const group = this.groupAt(position); + group.closeEditor(group.activeEditor); - // Otherwise open next active - return this.openEditor(group.activeEditor, null, position).then(null, (error) => { + // Close group is this is the last editor in group + if (group.count === 0) { + return this.doCloseGroup(position); + } - // in case of an error, continue closing - return this.doCloseActiveEditor(position); - }); - }); + // Otherwise open next active + return this.openEditor(group.activeEditor, null, position).then(() => null); } private doCloseInactiveEditor(input: EditorInput, position: Position): TPromise { - // Check for dirty and veto - return this.handleDirty([input]).then(veto => { - if (veto) { - return; - } + // Closing inactive editor is just a model update + const group = this.groupAt(position); + group.closeEditor(input); - // Closing inactive editor is just a model update - const group = this.groupAt(position); - group.closeEditor(input); - }); + return TPromise.as(null); } private doCloseGroup(position: Position): TPromise { @@ -782,7 +776,7 @@ export class EditorPart extends Part implements IEditorPart { return TPromise.as(null); } - return this.closeEditor(from, input).then(() => { + return this.doCloseEditor(from, input).then(() => { return this.openEditor(input, EditorOptions.create({ pinned: true, index }), this.stacksModel.positionOfGroup(toGroup)); }); }