@@ -9,6 +9,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
99import { EditorModel , IEncodingSupport } from 'vs/workbench/common/editor' ;
1010import { StringEditorModel } from 'vs/workbench/common/editor/stringEditorModel' ;
1111import URI from 'vs/base/common/uri' ;
12+ import { IModelContentChangedEvent2 } from 'vs/editor/common/editorCommon' ;
1213import { EventType , EndOfLinePreference } from 'vs/editor/common/editorCommon' ;
1314import { EventType as WorkbenchEventType , ResourceEvent } from 'vs/workbench/common/events' ;
1415import { IFilesConfiguration } from 'vs/platform/files/common/files' ;
@@ -30,6 +31,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
3031 private configuredEncoding : string ;
3132 private preferredEncoding : string ;
3233
34+ private hasAssociatedFilePath : boolean ;
35+
3336 constructor (
3437 value : string ,
3538 mime : string ,
@@ -42,6 +45,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
4245 ) {
4346 super ( value , mime , resource , modeService , modelService ) ;
4447
48+ this . hasAssociatedFilePath = hasAssociatedFilePath ;
4549 this . dirty = hasAssociatedFilePath ; // untitled associated to file path are dirty right away
4650
4751 this . _onDidChangeDirty = new Emitter < void > ( ) ;
@@ -92,7 +96,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
9296 }
9397
9498 public setEncoding ( encoding : string ) : void {
95- let oldEncoding = this . getEncoding ( ) ;
99+ const oldEncoding = this . getEncoding ( ) ;
96100 this . preferredEncoding = encoding ;
97101
98102 // Emit if it changed
@@ -119,7 +123,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
119123 this . configuredEncoding = configuration && configuration . files && configuration . files . encoding ;
120124
121125 // Listen to content changes
122- this . textModelChangeListener = this . textEditorModel . onDidChangeContent ( ( ) => this . onModelContentChanged ( ) ) ;
126+ this . textModelChangeListener = this . textEditorModel . onDidChangeContent ( e => this . onModelContentChanged ( e ) ) ;
123127
124128 // Emit initial dirty event if we are
125129 if ( this . dirty ) {
@@ -132,11 +136,20 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
132136 } ) ;
133137 }
134138
135- private onModelContentChanged ( ) : void {
139+ private onModelContentChanged ( e :IModelContentChangedEvent2 ) : void {
140+
141+ // turn dirty if we were not
136142 if ( ! this . dirty ) {
137143 this . dirty = true ;
138144 this . _onDidChangeDirty . fire ( ) ;
139145 }
146+
147+ // mark the untitled editor as non-dirty once its content becomes empty and we do
148+ // not have an associated path set
149+ else if ( ! this . hasAssociatedFilePath && ! e . text && this . textEditorModel . getValueLength ( ) === 0 ) {
150+ this . dirty = false ;
151+ this . _onDidChangeDirty . fire ( ) ;
152+ }
140153 }
141154
142155 public dispose ( ) : void {
0 commit comments