diff --git a/src/vs/workbench/common/editor/untitledEditorInput.ts b/src/vs/workbench/common/editor/untitledEditorInput.ts index 7761d5135a5..5f6d0c9771b 100644 --- a/src/vs/workbench/common/editor/untitledEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledEditorInput.ts @@ -75,7 +75,11 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { } public isDirty(): boolean { - return this.cachedModel && this.cachedModel.isDirty(); + if (this.cachedModel) { + return this.cachedModel.isDirty(); + } + + return this.hasAssociatedFilePath; // untitled files with associated path are always dirty } public confirmSave(): ConfirmResult { diff --git a/src/vs/workbench/common/editor/untitledEditorModel.ts b/src/vs/workbench/common/editor/untitledEditorModel.ts index ee8d1203866..fb4c699ce39 100644 --- a/src/vs/workbench/common/editor/untitledEditorModel.ts +++ b/src/vs/workbench/common/editor/untitledEditorModel.ts @@ -127,13 +127,6 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS // Listen to content changes this.textModelChangeListener = this.textEditorModel.onDidChangeContent(e => this.onModelContentChanged()); - // Emit initial dirty event if we are - if (this.dirty) { - setTimeout(() => { - this._onDidChangeDirty.fire(); - }, 0 /* prevent race condition between creating model and emitting dirty event */); - } - return model; }); } diff --git a/src/vs/workbench/services/untitled/common/untitledEditorService.ts b/src/vs/workbench/services/untitled/common/untitledEditorService.ts index e064aa9da5f..dfa4462df83 100644 --- a/src/vs/workbench/services/untitled/common/untitledEditorService.ts +++ b/src/vs/workbench/services/untitled/common/untitledEditorService.ts @@ -162,6 +162,11 @@ export class UntitledEditorService implements IUntitledEditorService { } const input = this.instantiationService.createInstance(UntitledEditorInput, resource, hasAssociatedFilePath, modeId); + if (input.isDirty()) { + setTimeout(() => { + this._onDidChangeDirty.fire(resource); + }, 0 /* prevent race condition between creating input and emitting dirty event */); + } const dirtyListener = input.onDidChangeDirty(() => { this._onDidChangeDirty.fire(resource);