提交 bb71a2ea 编写于 作者: B Benjamin Pasero

debt - avoid stringeditormodel for untitled

上级 19b321ba
......@@ -7,7 +7,7 @@
import { IDisposable } from 'vs/base/common/lifecycle';
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 { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
import URI from 'vs/base/common/uri';
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
import { EndOfLinePreference } from 'vs/editor/common/editorCommon';
......@@ -21,7 +21,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import { IBackupFileService, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
export class UntitledEditorModel extends StringEditorModel implements IEncodingSupport {
export class UntitledEditorModel extends BaseTextEditorModel implements IEncodingSupport {
public static DEFAULT_CONTENT_CHANGE_BUFFER_DELAY = CONTENT_CHANGE_EVENT_BUFFER_DELAY;
......@@ -43,8 +43,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
private hasAssociatedFilePath: boolean;
constructor(
modeId: string,
resource: URI,
private modeId: string,
private resource: URI,
hasAssociatedFilePath: boolean,
@IModeService modeService: IModeService,
@IModelService modelService: IModelService,
......@@ -52,7 +52,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
@ITextFileService private textFileService: ITextFileService,
@IConfigurationService private configurationService: IConfigurationService
) {
super('', modeId, resource, modeService, modelService);
super(modelService, modeService);
this.hasAssociatedFilePath = hasAssociatedFilePath;
this.dirty = false;
......@@ -167,13 +167,11 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
return null;
}).then(backupContent => {
if (backupContent) {
this.setValue(backupContent);
}
this.setDirty(this.hasAssociatedFilePath || !!backupContent); // untitled associated to file path are dirty right away as well as untitled with content
// untitled associated to file path are dirty right away as well as untitled with content
this.setDirty(this.hasAssociatedFilePath || !!backupContent);
return super.load().then(model => {
return this.doLoad(backupContent || '').then(model => {
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
// Encoding
......@@ -187,6 +185,21 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
});
}
private doLoad(content: string): TPromise<EditorModel> {
// Create text editor model if not yet done
if (!this.textEditorModel) {
return this.createTextEditorModel(content, this.resource, this.modeId);
}
// Otherwise update
else {
this.updateTextEditorModel(content);
}
return TPromise.as<EditorModel>(this);
}
private onModelContentChanged(): void {
this.versionId++;
......
......@@ -163,7 +163,7 @@ suite('Files - TextFileService', () => {
return untitled.resolve().then((model: UntitledEditorModel) => {
assert.ok(!service.isDirty(untitled.getResource()));
assert.equal(service.getDirty().length, 1);
model.setValue('changed');
model.textEditorModel.setValue('changed');
assert.ok(service.isDirty(untitled.getResource()));
assert.equal(service.getDirty().length, 2);
......
......@@ -162,21 +162,21 @@ suite('Workbench - Untitled Editor', () => {
});
input.resolve().then((model: UntitledEditorModel) => {
model.setValue('foo');
model.textEditorModel.setValue('foo');
assert.equal(counter, 0, 'Dirty model should not trigger event immediately');
TPromise.timeout(3).then(() => {
assert.equal(counter, 1, 'Dirty model should trigger event');
model.setValue('bar');
model.textEditorModel.setValue('bar');
TPromise.timeout(3).then(() => {
assert.equal(counter, 2, 'Content change when dirty should trigger event');
model.setValue('');
model.textEditorModel.setValue('');
TPromise.timeout(3).then(() => {
assert.equal(counter, 3, 'Manual revert should trigger event');
model.setValue('foo');
model.textEditorModel.setValue('foo');
TPromise.timeout(3).then(() => {
assert.equal(counter, 4, 'Dirty model should trigger event');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册