mirror of
https://github.com/microsoft/vscode.git
synced 2026-10-01 04:37:56 +01:00
snapshot support for getFirstLineText
This commit is contained in:
@@ -91,7 +91,9 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
|
||||
return this;
|
||||
}
|
||||
|
||||
protected getFirstLineText(value: string | ITextBufferFactory): string {
|
||||
protected getFirstLineText(value: string | ITextBufferFactory | ITextSnapshot): string {
|
||||
|
||||
// string
|
||||
if (typeof value === 'string') {
|
||||
const firstLineText = value.substr(0, 100);
|
||||
|
||||
@@ -106,9 +108,17 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
|
||||
}
|
||||
|
||||
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';
|
||||
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/model';
|
||||
import { CONTENT_CHANGE_EVENT_BUFFER_DELAY } from 'vs/platform/files/common/files';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
@@ -113,14 +112,6 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
|
||||
return this.versionId;
|
||||
}
|
||||
|
||||
public getValue(): string {
|
||||
if (this.textEditorModel) {
|
||||
return this.textEditorModel.getValue(EndOfLinePreference.TextDefined, true /* Preserve BOM */);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getModeId(): string {
|
||||
if (this.textEditorModel) {
|
||||
return this.textEditorModel.getLanguageIdentifier().language;
|
||||
|
||||
@@ -188,7 +188,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||
return;
|
||||
}
|
||||
|
||||
const firstLineText = this.getFirstLineText(this.textEditorModel.getValue());
|
||||
const firstLineText = this.getFirstLineText(this.textEditorModel.createSnapshot());
|
||||
const mode = this.getOrCreateMode(this.modeService, modeId, firstLineText);
|
||||
|
||||
this.modelService.setMode(this.textEditorModel, mode);
|
||||
|
||||
Reference in New Issue
Block a user