mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Empty untitled file should not show up as dirty (fixes #11554)
This commit is contained in:
@@ -92,7 +92,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
|
||||
public suggestFileName(): string {
|
||||
if (!this.hasAssociatedFilePath) {
|
||||
let mime = this.getMime();
|
||||
const mime = this.getMime();
|
||||
if (mime && mime !== MIME_TEXT /* do not suggest when the mime type is simple plain text */) {
|
||||
return suggestFilename(mime, this.getName());
|
||||
}
|
||||
@@ -131,7 +131,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
}
|
||||
|
||||
// Otherwise Create Model and load
|
||||
let model = this.createModel();
|
||||
const model = this.createModel();
|
||||
return model.load().then((resolvedModel: UntitledEditorModel) => {
|
||||
this.cachedModel = resolvedModel;
|
||||
|
||||
@@ -140,10 +140,10 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
}
|
||||
|
||||
private createModel(): UntitledEditorModel {
|
||||
let content = '';
|
||||
const content = '';
|
||||
let mime = this.modeId;
|
||||
if (!mime && this.hasAssociatedFilePath) {
|
||||
let mimeFromPath = guessMimeTypes(this.resource.fsPath)[0];
|
||||
const mimeFromPath = guessMimeTypes(this.resource.fsPath)[0];
|
||||
if (!isUnspecific(mimeFromPath)) {
|
||||
mime = mimeFromPath; // take most specific mime type if file path is associated and mime is specific
|
||||
}
|
||||
@@ -163,7 +163,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
}
|
||||
|
||||
if (otherInput instanceof UntitledEditorInput) {
|
||||
let otherUntitledEditorInput = <UntitledEditorInput>otherInput;
|
||||
const otherUntitledEditorInput = <UntitledEditorInput>otherInput;
|
||||
|
||||
// Otherwise compare by properties
|
||||
return otherUntitledEditorInput.resource.toString() === this.resource.toString();
|
||||
|
||||
@@ -9,6 +9,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {EditorModel, IEncodingSupport} from 'vs/workbench/common/editor';
|
||||
import {StringEditorModel} from 'vs/workbench/common/editor/stringEditorModel';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import {IModelContentChangedEvent2} from 'vs/editor/common/editorCommon';
|
||||
import {EventType, EndOfLinePreference} from 'vs/editor/common/editorCommon';
|
||||
import {EventType as WorkbenchEventType, ResourceEvent} from 'vs/workbench/common/events';
|
||||
import {IFilesConfiguration} from 'vs/platform/files/common/files';
|
||||
@@ -30,6 +31,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
|
||||
private configuredEncoding: string;
|
||||
private preferredEncoding: string;
|
||||
|
||||
private hasAssociatedFilePath: boolean;
|
||||
|
||||
constructor(
|
||||
value: string,
|
||||
mime: string,
|
||||
@@ -42,6 +45,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
|
||||
) {
|
||||
super(value, mime, resource, modeService, modelService);
|
||||
|
||||
this.hasAssociatedFilePath = hasAssociatedFilePath;
|
||||
this.dirty = hasAssociatedFilePath; // untitled associated to file path are dirty right away
|
||||
|
||||
this._onDidChangeDirty = new Emitter<void>();
|
||||
@@ -92,7 +96,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
|
||||
}
|
||||
|
||||
public setEncoding(encoding: string): void {
|
||||
let oldEncoding = this.getEncoding();
|
||||
const oldEncoding = this.getEncoding();
|
||||
this.preferredEncoding = encoding;
|
||||
|
||||
// Emit if it changed
|
||||
@@ -119,7 +123,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
|
||||
this.configuredEncoding = configuration && configuration.files && configuration.files.encoding;
|
||||
|
||||
// Listen to content changes
|
||||
this.textModelChangeListener = this.textEditorModel.onDidChangeContent(() => this.onModelContentChanged());
|
||||
this.textModelChangeListener = this.textEditorModel.onDidChangeContent(e => this.onModelContentChanged(e));
|
||||
|
||||
// Emit initial dirty event if we are
|
||||
if (this.dirty) {
|
||||
@@ -132,11 +136,20 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
|
||||
});
|
||||
}
|
||||
|
||||
private onModelContentChanged(): void {
|
||||
private onModelContentChanged(e:IModelContentChangedEvent2): void {
|
||||
|
||||
// turn dirty if we were not
|
||||
if (!this.dirty) {
|
||||
this.dirty = true;
|
||||
this._onDidChangeDirty.fire();
|
||||
}
|
||||
|
||||
// mark the untitled editor as non-dirty once its content becomes empty and we do
|
||||
// not have an associated path set
|
||||
else if (!this.hasAssociatedFilePath && !e.text && this.textEditorModel.getValueLength() === 0) {
|
||||
this.dirty = false;
|
||||
this._onDidChangeDirty.fire();
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
|
||||
Reference in New Issue
Block a user