Skip to content

Commit 2bb55b7

Browse files
author
Benjamin Pasero
committed
faster check for empty model
1 parent 5e92eb1 commit 2bb55b7

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/vs/workbench/common/editor/untitledEditorModel.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {TPromise} from 'vs/base/common/winjs.base';
99
import {EditorModel, IEncodingSupport} from 'vs/workbench/common/editor';
1010
import {StringEditorModel} from 'vs/workbench/common/editor/stringEditorModel';
1111
import URI from 'vs/base/common/uri';
12-
import {IModelContentChangedEvent2} from 'vs/editor/common/editorCommon';
1312
import {EventType, EndOfLinePreference} from 'vs/editor/common/editorCommon';
1413
import {EventType as WorkbenchEventType, ResourceEvent} from 'vs/workbench/common/events';
1514
import {IFilesConfiguration} from 'vs/platform/files/common/files';
@@ -123,7 +122,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
123122
this.configuredEncoding = configuration && configuration.files && configuration.files.encoding;
124123

125124
// Listen to content changes
126-
this.textModelChangeListener = this.textEditorModel.onDidChangeContent(e => this.onModelContentChanged(e));
125+
this.textModelChangeListener = this.textEditorModel.onDidChangeContent(e => this.onModelContentChanged());
127126

128127
// Emit initial dirty event if we are
129128
if (this.dirty) {
@@ -136,7 +135,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
136135
});
137136
}
138137

139-
private onModelContentChanged(e:IModelContentChangedEvent2): void {
138+
private onModelContentChanged(): void {
140139

141140
// turn dirty if we were not
142141
if (!this.dirty) {
@@ -146,7 +145,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
146145

147146
// mark the untitled editor as non-dirty once its content becomes empty and we do
148147
// not have an associated path set
149-
else if (!this.hasAssociatedFilePath && !e.text && this.textEditorModel.getValueLength() === 0) {
148+
else if (!this.hasAssociatedFilePath && this.textEditorModel.getLineCount() === 1 && this.textEditorModel.getLineContent(1) === '') {
150149
this.dirty = false;
151150
this._onDidChangeDirty.fire();
152151
}

0 commit comments

Comments
 (0)