mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
debt - avoid stringeditormodel for untitled
This commit is contained in:
@@ -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++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user