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

snapshot support for getFirstLineText

上级 d44201fa
...@@ -91,7 +91,9 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd ...@@ -91,7 +91,9 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
return this; return this;
} }
protected getFirstLineText(value: string | ITextBufferFactory): string { protected getFirstLineText(value: string | ITextBufferFactory | ITextSnapshot): string {
// string
if (typeof value === 'string') { if (typeof value === 'string') {
const firstLineText = value.substr(0, 100); const firstLineText = value.substr(0, 100);
...@@ -106,9 +108,17 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd ...@@ -106,9 +108,17 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
} }
return firstLineText.substr(0, Math.min(crIndex, lfIndex)); return firstLineText.substr(0, Math.min(crIndex, lfIndex));
} else {
return value.getFirstLineText(100);
} }
// text buffer factory
const textBufferFactory = value as ITextBufferFactory;
if (typeof textBufferFactory.getFirstLineText === 'function') {
return textBufferFactory.getFirstLineText(100);
}
// text snapshot
const textSnapshot = value as ITextSnapshot;
return this.getFirstLineText(textSnapshot.read() || '');
} }
/** /**
......
...@@ -10,7 +10,6 @@ import { IEncodingSupport } from 'vs/workbench/common/editor'; ...@@ -10,7 +10,6 @@ import { IEncodingSupport } from 'vs/workbench/common/editor';
import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'; import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry'; import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
import { EndOfLinePreference } from 'vs/editor/common/model';
import { CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files'; import { CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService'; import { IModelService } from 'vs/editor/common/services/modelService';
...@@ -113,14 +112,6 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin ...@@ -113,14 +112,6 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
return this.versionId; return this.versionId;
} }
public getValue(): string {
if (this.textEditorModel) {
return this.textEditorModel.getValue(EndOfLinePreference.TextDefined, true /* Preserve BOM */);
}
return null;
}
public getModeId(): string { public getModeId(): string {
if (this.textEditorModel) { if (this.textEditorModel) {
return this.textEditorModel.getLanguageIdentifier().language; return this.textEditorModel.getLanguageIdentifier().language;
......
...@@ -188,7 +188,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil ...@@ -188,7 +188,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return; return;
} }
const firstLineText = this.getFirstLineText(this.textEditorModel.getValue()); const firstLineText = this.getFirstLineText(this.textEditorModel.createSnapshot());
const mode = this.getOrCreateMode(this.modeService, modeId, firstLineText); const mode = this.getOrCreateMode(this.modeService, modeId, firstLineText);
this.modelService.setMode(this.textEditorModel, mode); this.modelService.setMode(this.textEditorModel, mode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册