From 1d8296cc22b3db878f795776ee4ef6aecfcf8b1f Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sat, 3 Sep 2016 10:21:07 +0200 Subject: [PATCH] allow to close dirty diff editor if file is opened anywhere else --- src/vs/workbench/browser/parts/editor/editorPart.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index 72a84f94330..a5e6933f9f4 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -30,6 +30,7 @@ import {IPartService} from 'vs/workbench/services/part/common/partService'; import {Position, POSITIONS, Direction} from 'vs/platform/editor/common/editor'; import {IStorageService} from 'vs/platform/storage/common/storage'; import {IEventService} from 'vs/platform/event/common/event'; +import {DiffEditorInput} from 'vs/workbench/common/editor/diffEditorInput'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollection'; import {IMessageService, IMessageWithAction, Severity} from 'vs/platform/message/common/message'; @@ -658,7 +659,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService } private doHandleDirty(identifier: EditorIdentifier, ignoreIfOpenedInOtherGroup?: boolean): TPromise { - if (!identifier || !identifier.editor || !identifier.editor.isDirty() || (ignoreIfOpenedInOtherGroup && this.stacks.count(identifier.editor) > 1 /* allow to close a dirty editor if it is opened in another group */)) { + if (!identifier || !identifier.editor || !identifier.editor.isDirty() || (ignoreIfOpenedInOtherGroup && this.countEditors(identifier.editor, true /* include diff editors */) > 1 /* allow to close a dirty editor if it is opened in another group */)) { return TPromise.as(false); // no veto } @@ -677,6 +678,15 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService } } + private countEditors(editor: EditorInput, includeDiffEditors: boolean): number { + const editors = [editor]; + if (includeDiffEditors && editor instanceof DiffEditorInput) { + editors.push(editor.modifiedInput); + } + + return editors.reduce((prev, e) => prev += this.stacks.count(editor), 0); + } + public getStacksModel(): EditorStacksModel { return this.stacks; } -- GitLab