Interface ITextModel

Expand description

A model.

interface ITextModel {
    id: string;
    onDidChangeAttached: IEvent<void>;
    onDidChangeDecorations: IEvent<
        IModelDecorationsChangedEvent,
    >;
    onDidChangeLanguage: IEvent<IModelLanguageChangedEvent>;
    onDidChangeLanguageConfiguration: IEvent<
        IModelLanguageConfigurationChangedEvent,
    >;
    onDidChangeOptions: IEvent<IModelOptionsChangedEvent>;
    onWillDispose: IEvent<void>;
    uri: Uri;
    applyEdits(
        operations: readonly IIdentifiedSingleEditOperation[],
    ): void;
    applyEdits(
        operations: readonly IIdentifiedSingleEditOperation[],
        computeUndoEdits: false,
    ): void;
    applyEdits(
        operations: readonly IIdentifiedSingleEditOperation[],
        computeUndoEdits: true,
    ): IValidEditOperation[];
    canRedo(): boolean;
    canUndo(): boolean;
    createSnapshot(preserveBOM?: boolean): ITextSnapshot;
    deltaDecorations(
        oldDecorations: string[],
        newDecorations: IModelDeltaDecoration[],
        ownerId?: number,
    ): string[];
    detectIndentation(
        defaultInsertSpaces: boolean,
        defaultTabSize: number,
    ): void;
    dispose(): void;
    findMatches(
        searchString: string,
        searchOnlyEditableRange: boolean,
        isRegex: boolean,
        matchCase: boolean,
        wordSeparators: string,
        captureMatches: boolean,
        limitResultCount?: number,
    ): FindMatch[];
    findMatches(
        searchString: string,
        searchScope: IRange | IRange[],
        isRegex: boolean,
        matchCase: boolean,
        wordSeparators: string,
        captureMatches: boolean,
        limitResultCount?: number,
    ): FindMatch[];
    findNextMatch(
        searchString: string,
        searchStart: IPosition,
        isRegex: boolean,
        matchCase: boolean,
        wordSeparators: string,
        captureMatches: boolean,
    ): FindMatch;
    findPreviousMatch(
        searchString: string,
        searchStart: IPosition,
        isRegex: boolean,
        matchCase: boolean,
        wordSeparators: string,
        captureMatches: boolean,
    ): FindMatch;
    getAllDecorations(
        ownerId?: number,
        filterOutValidation?: boolean,
        filterFontDecorations?: boolean,
    ): IModelDecoration[];
    getAllMarginDecorations(
        ownerId?: number,
    ): IModelDecoration[];
    getAlternativeVersionId(): number;
    getCharacterCountInRange(
        range: IRange,
        eol?: EndOfLinePreference,
    ): number;
    getCustomLineHeightsDecorations(
        ownerId?: number,
    ): IModelDecoration[];
    getDecorationOptions(
        id: string,
    ): IModelDecorationOptions;
    getDecorationRange(id: string): Range;
    getDecorationsInRange(
        range: IRange,
        ownerId?: number,
        filterOutValidation?: boolean,
        filterFontDecorations?: boolean,
        onlyMinimapDecorations?: boolean,
        onlyMarginDecorations?: boolean,
    ): IModelDecoration[];
    getEndOfLineSequence(): EndOfLineSequence;
    getEOL(): string;
    getFullModelRange(): Range;
    getInjectedTextDecorations(
        ownerId?: number,
    ): IModelDecoration[];
    getLanguageId(): string;
    getLineContent(lineNumber: number): string;
    getLineCount(): number;
    getLineDecorations(
        lineNumber: number,
        ownerId?: number,
        filterOutValidation?: boolean,
        filterFontDecorations?: boolean,
    ): IModelDecoration[];
    getLineFirstNonWhitespaceColumn(
        lineNumber: number,
    ): number;
    getLineLastNonWhitespaceColumn(
        lineNumber: number,
    ): number;
    getLineLength(lineNumber: number): number;
    getLineMaxColumn(lineNumber: number): number;
    getLineMinColumn(lineNumber: number): number;
    getLinesContent(): string[];
    getLinesDecorations(
        startLineNumber: number,
        endLineNumber: number,
        ownerId?: number,
        filterOutValidation?: boolean,
        filterFontDecorations?: boolean,
    ): IModelDecoration[];
    getOffsetAt(position: IPosition): number;
    getOptions(): TextModelResolvedOptions;
    getOverviewRulerDecorations(
        ownerId?: number,
        filterOutValidation?: boolean,
        filterFontDecorations?: boolean,
    ): IModelDecoration[];
    getPositionAt(offset: number): Position;
    getValue(
        eol?: EndOfLinePreference,
        preserveBOM?: boolean,
    ): string;
    getValueInRange(
        range: IRange,
        eol?: EndOfLinePreference,
    ): string;
    getValueLength(
        eol?: EndOfLinePreference,
        preserveBOM?: boolean,
    ): number;
    getValueLengthInRange(
        range: IRange,
        eol?: EndOfLinePreference,
    ): number;
    getVersionId(): number;
    getWordAtPosition(position: IPosition): IWordAtPosition;
    getWordUntilPosition(
        position: IPosition,
    ): IWordAtPosition;
    isAttachedToEditor(): boolean;
    isDisposed(): boolean;
    isValidRange(range: IRange): boolean;
    modifyPosition(
        position: IPosition,
        offset: number,
    ): Position;
    normalizeIndentation(str: string): string;
    onDidChangeContent(
        listener: (e: IModelContentChangedEvent) => void,
    ): IDisposable;
    popStackElement(): void;
    pushEditOperations(
        beforeCursorState: Selection[],
        editOperations: IIdentifiedSingleEditOperation[],
        cursorStateComputer: ICursorStateComputer,
    ): Selection[];
    pushEOL(eol: EndOfLineSequence): void;
    pushStackElement(): void;
    redo(): void | Promise<void>;
    setEOL(eol: EndOfLineSequence): void;
    setValue(newValue: string | ITextSnapshot): void;
    undo(): void | Promise<void>;
    updateOptions(newOpts: ITextModelUpdateOptions): void;
    validatePosition(position: IPosition): Position;
    validateRange(range: IRange): Range;
}

Properties§

§readonly id: string

A unique identifier associated with this model.

§readonly uri: Uri

Gets the resource associated with this editor model.

Methods§

§

applyEdits(
    operations: readonly IIdentifiedSingleEditOperation[],
): void

Edit the model without adding the edits to the undo stack. This can have dire consequences on the undo stack! See

pushEditOperations

for the preferred way.

§

applyEdits(
    operations: readonly IIdentifiedSingleEditOperation[],
    computeUndoEdits: false,
): void

§

applyEdits(
    operations: readonly IIdentifiedSingleEditOperation[],
    computeUndoEdits: true,
): IValidEditOperation[]

§

canRedo(): boolean

Is there anything in the redo stack?

§

canUndo(): boolean

Is there anything in the undo stack?

§

createSnapshot(preserveBOM?: boolean): ITextSnapshot

Get the text stored in this model.

§

deltaDecorations(
    oldDecorations: string[],
    newDecorations: IModelDeltaDecoration[],
    ownerId?: number,
): string[]

Perform a minimum amount of operations, in order to transform the decorations identified by oldDecorations to the decorations described by newDecorations and returns the new identifiers associated with the resulting decorations.

§

detectIndentation(
    defaultInsertSpaces: boolean,
    defaultTabSize: number,
): void

Detect the indentation options for this model from its content.

§

dispose(): void

Destroy this model.

§

findMatches(
    searchString: string,
    searchOnlyEditableRange: boolean,
    isRegex: boolean,
    matchCase: boolean,
    wordSeparators: string,
    captureMatches: boolean,
    limitResultCount?: number,
): FindMatch[]

Search the model.

§

findMatches(
    searchString: string,
    searchScope: IRange | IRange[],
    isRegex: boolean,
    matchCase: boolean,
    wordSeparators: string,
    captureMatches: boolean,
    limitResultCount?: number,
): FindMatch[]

Search the model.

§

findNextMatch(
    searchString: string,
    searchStart: IPosition,
    isRegex: boolean,
    matchCase: boolean,
    wordSeparators: string,
    captureMatches: boolean,
): FindMatch

Search the model for the next match. Loops to the beginning of the model if needed.

§

findPreviousMatch(
    searchString: string,
    searchStart: IPosition,
    isRegex: boolean,
    matchCase: boolean,
    wordSeparators: string,
    captureMatches: boolean,
): FindMatch

Search the model for the previous match. Loops to the end of the model if needed.

§

getAllDecorations(
    ownerId?: number,
    filterOutValidation?: boolean,
    filterFontDecorations?: boolean,
): IModelDecoration[]

Gets all the decorations as an array.

§

getAllMarginDecorations(
    ownerId?: number,
): IModelDecoration[]

Gets all decorations that render in the glyph margin as an array.

§

getAlternativeVersionId(): number

Get the alternative version id of the model. This alternative version id is not always incremented, it will return the same values in the case of undo-redo.

§

getCharacterCountInRange(
    range: IRange,
    eol?: EndOfLinePreference,
): number

Get the character count of text in a certain range.

§

getCustomLineHeightsDecorations(
    ownerId?: number,
): IModelDecoration[]

Gets all the decorations that contain custom line heights.

§

getDecorationOptions(id: string): IModelDecorationOptions

Get the options associated with a decoration.

§

getDecorationRange(id: string): Range

Get the range associated with a decoration.

§

getDecorationsInRange(
    range: IRange,
    ownerId?: number,
    filterOutValidation?: boolean,
    filterFontDecorations?: boolean,
    onlyMinimapDecorations?: boolean,
    onlyMarginDecorations?: boolean,
): IModelDecoration[]

Gets all the decorations in a range as an array. Only startLineNumber and endLineNumber from range are used for filtering. So for now it returns all the decorations on the same line as range.

§

getEndOfLineSequence(): EndOfLineSequence

Get the end of line sequence predominantly used in the text buffer.

§

getEOL(): string

Get the end of line sequence predominantly used in the text buffer.

§

getFullModelRange(): Range

Get a range covering the entire model.

§

getInjectedTextDecorations(
    ownerId?: number,
): IModelDecoration[]

Gets all the decorations that contain injected text.

§

getLanguageId(): string

Get the language associated with this model.

§

getLineContent(lineNumber: number): string

Get the text for a certain line.

§

getLineCount(): number

Get the number of lines in the model.

§

getLineDecorations(
    lineNumber: number,
    ownerId?: number,
    filterOutValidation?: boolean,
    filterFontDecorations?: boolean,
): IModelDecoration[]

Gets all the decorations for the line lineNumber as an array.

§

getLineFirstNonWhitespaceColumn(lineNumber: number): number

Returns the column before the first non whitespace character for line at lineNumber. Returns 0 if line is empty or contains only whitespace.

§

getLineLastNonWhitespaceColumn(lineNumber: number): number

Returns the column after the last non whitespace character for line at lineNumber. Returns 0 if line is empty or contains only whitespace.

§

getLineLength(lineNumber: number): number

Get the text length for a certain line.

§

getLineMaxColumn(lineNumber: number): number

Get the maximum legal column for line at lineNumber

§

getLineMinColumn(lineNumber: number): number

Get the minimum legal column for line at lineNumber

§

getLinesContent(): string[]

Get the text for all lines.

§

getLinesDecorations(
    startLineNumber: number,
    endLineNumber: number,
    ownerId?: number,
    filterOutValidation?: boolean,
    filterFontDecorations?: boolean,
): IModelDecoration[]

Gets all the decorations for the lines between startLineNumber and endLineNumber as an array.

§

getOffsetAt(position: IPosition): number

Converts the position to a zero-based offset.

The position will be adjusted.

§

getOptions(): TextModelResolvedOptions

Get the resolved options for this model.

§

getOverviewRulerDecorations(
    ownerId?: number,
    filterOutValidation?: boolean,
    filterFontDecorations?: boolean,
): IModelDecoration[]

Gets all the decorations that should be rendered in the overview ruler as an array.

§

getPositionAt(offset: number): Position

Converts a zero-based offset to a position.

§

getValue(
    eol?: EndOfLinePreference,
    preserveBOM?: boolean,
): string

Get the text stored in this model.

§

getValueInRange(
    range: IRange,
    eol?: EndOfLinePreference,
): string

Get the text in a certain range.

§

getValueLength(
    eol?: EndOfLinePreference,
    preserveBOM?: boolean,
): number

Get the length of the text stored in this model.

§

getValueLengthInRange(
    range: IRange,
    eol?: EndOfLinePreference,
): number

Get the length of text in a certain range.

§

getVersionId(): number

Get the current version id of the model. Anytime a change happens to the model (even undo/redo), the version id is incremented.

§

getWordAtPosition(position: IPosition): IWordAtPosition

Get the word under or besides position.

§

getWordUntilPosition(position: IPosition): IWordAtPosition

Get the word under or besides position trimmed to position.column

§

isAttachedToEditor(): boolean

Returns if this model is attached to an editor or not.

§

isDisposed(): boolean

Returns if the model was disposed or not.

§

isValidRange(range: IRange): boolean

Verifies the range is valid.

§

modifyPosition(
    position: IPosition,
    offset: number,
): Position

Advances the given position by the given offset (negative offsets are also accepted) and returns it as a new valid position.

If the offset and position are such that their combination goes beyond the beginning or end of the model, throws an exception.

If the offset is such that the new position would be in the middle of a multi-byte line terminator, throws an exception.

§

normalizeIndentation(str: string): string

Normalize a string containing whitespace according to indentation rules (converts to spaces or to tabs).

§

popStackElement(): void

Open the current undo-redo element. This offers a way to remove the current undo/redo stop point.

§

pushEditOperations(
    beforeCursorState: Selection[],
    editOperations: IIdentifiedSingleEditOperation[],
    cursorStateComputer: ICursorStateComputer,
): Selection[]

Push edit operations, basically editing the model. This is the preferred way of editing the model. The edit operations will land on the undo stack.

§

pushEOL(eol: EndOfLineSequence): void

Change the end of line sequence. This is the preferred way of changing the eol sequence. This will land on the undo stack.

§

pushStackElement(): void

Close the current undo-redo element. This offers a way to create an undo/redo stop point.

§

redo(): void | Promise<void>

Redo edit operations until the next undo/redo point. The inverse edit operations will be pushed on the undo stack.

§

setEOL(eol: EndOfLineSequence): void

Change the end of line sequence without recording in the undo stack. This can have dire consequences on the undo stack! See

pushEOL

for the preferred way.

§

setValue(newValue: string | ITextSnapshot): void

Replace the entire text buffer value contained in this model.

§

undo(): void | Promise<void>

Undo edit operations until the previous undo/redo point. The inverse edit operations will be pushed on the redo stack.

§

updateOptions(newOpts: ITextModelUpdateOptions): void

Change the options of this model.

§

validatePosition(position: IPosition): Position

Create a valid position.

§

validateRange(range: IRange): Range

Create a valid range.

Events§

§readonly onDidChangeAttached: IEvent<void>

An event emitted when the model has been attached to the first editor or detached from the last editor.

§readonly onDidChangeDecorations: IEvent<IModelDecorationsChangedEvent>

An event emitted when decorations of the model have changed.

§readonly onDidChangeLanguage: IEvent<IModelLanguageChangedEvent>

An event emitted when the language associated with the model has changed.

§readonly onDidChangeLanguageConfiguration: IEvent<IModelLanguageConfigurationChangedEvent>

An event emitted when the language configuration associated with the model has changed.

§readonly onDidChangeOptions: IEvent<IModelOptionsChangedEvent>

An event emitted when the model options have changed.

§readonly onWillDispose: IEvent<void>

An event emitted right before disposing the model.

§

onDidChangeContent(
    listener: (e: IModelContentChangedEvent) => void,
): IDisposable

An event emitted when the contents of the model have changed.