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): void;
    applyEdits(operations, computeUndoEdits): void;
    applyEdits(operations, computeUndoEdits): IValidEditOperation[];
    createSnapshot(preserveBOM?): ITextSnapshot;
    deltaDecorations(oldDecorations, newDecorations, ownerId?): string[];
    detectIndentation(defaultInsertSpaces, defaultTabSize): void;
    dispose(): void;
    findMatches(searchString, searchOnlyEditableRange, isRegex, matchCase, wordSeparators, captureMatches, limitResultCount?): FindMatch[];
    findMatches(searchString, searchScope, isRegex, matchCase, wordSeparators, captureMatches, limitResultCount?): FindMatch[];
    findNextMatch(searchString, searchStart, isRegex, matchCase, wordSeparators, captureMatches): FindMatch;
    findPreviousMatch(searchString, searchStart, isRegex, matchCase, wordSeparators, captureMatches): FindMatch;
    getAllDecorations(ownerId?, filterOutValidation?): IModelDecoration[];
    getAllMarginDecorations(ownerId?): IModelDecoration[];
    getAlternativeVersionId(): number;
    getCharacterCountInRange(range, eol?): number;
    getDecorationOptions(id): IModelDecorationOptions;
    getDecorationRange(id): Range;
    getDecorationsInRange(range, ownerId?, filterOutValidation?, onlyMinimapDecorations?, onlyMarginDecorations?): IModelDecoration[];
    getEOL(): string;
    getEndOfLineSequence(): EndOfLineSequence;
    getFullModelRange(): Range;
    getInjectedTextDecorations(ownerId?): IModelDecoration[];
    getLanguageId(): string;
    getLineContent(lineNumber): string;
    getLineCount(): number;
    getLineDecorations(lineNumber, ownerId?, filterOutValidation?): IModelDecoration[];
    getLineFirstNonWhitespaceColumn(lineNumber): number;
    getLineLastNonWhitespaceColumn(lineNumber): number;
    getLineLength(lineNumber): number;
    getLineMaxColumn(lineNumber): number;
    getLineMinColumn(lineNumber): number;
    getLinesContent(): string[];
    getLinesDecorations(startLineNumber, endLineNumber, ownerId?, filterOutValidation?): IModelDecoration[];
    getOffsetAt(position): number;
    getOptions(): TextModelResolvedOptions;
    getOverviewRulerDecorations(ownerId?, filterOutValidation?): IModelDecoration[];
    getPositionAt(offset): Position;
    getValue(eol?, preserveBOM?): string;
    getValueInRange(range, eol?): string;
    getValueLength(eol?, preserveBOM?): number;
    getValueLengthInRange(range, eol?): number;
    getVersionId(): number;
    getWordAtPosition(position): IWordAtPosition;
    getWordUntilPosition(position): IWordAtPosition;
    isAttachedToEditor(): boolean;
    isDisposed(): boolean;
    modifyPosition(position, offset): Position;
    normalizeIndentation(str): string;
    onDidChangeContent(listener): IDisposable;
    popStackElement(): void;
    pushEOL(eol): void;
    pushEditOperations(beforeCursorState, editOperations, cursorStateComputer): Selection[];
    pushStackElement(): void;
    setEOL(eol): void;
    setValue(newValue): void;
    updateOptions(newOpts): void;
    validatePosition(position): Position;
    validateRange(range): Range;
}

Properties

id: string

A unique identifier associated with this model.

uri: Uri

Gets the resource associated with this editor model.

Methods

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

    Parameters

    Returns void

    If desired, the inverse edit operations, that, when applied, will bring the model back to the previous state.

    Push Edit Operations

    for the preferred way.

  • Parameters

    Returns void

  • Parameters

    Returns IValidEditOperation[]

  • Get the text stored in this model.

    Parameters

    • Optional preserveBOM: boolean

    Returns ITextSnapshot

    The text snapshot (it is safe to consume it asynchronously).

  • 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.

    Parameters

    • oldDecorations: string[]

      Array containing previous decorations identifiers.

    • newDecorations: IModelDeltaDecoration[]

      Array describing what decorations should result after the call.

    • Optional ownerId: number

      Identifies the editor id in which these decorations should appear. If no ownerId is provided, the decorations will appear in all editors that attach this model.

    Returns string[]

    An array containing the new decorations identifiers.

  • Detect the indentation options for this model from its content.

    Parameters

    • defaultInsertSpaces: boolean
    • defaultTabSize: number

    Returns void

  • Destroy this model.

    Returns void

  • Search the model.

    Parameters

    • searchString: string

      The string used to search. If it is a regular expression, set isRegex to true.

    • searchOnlyEditableRange: boolean

      Limit the searching to only search inside the editable range of the model.

    • isRegex: boolean

      Used to indicate that searchString is a regular expression.

    • matchCase: boolean

      Force the matching to match lower/upper case exactly.

    • wordSeparators: string

      Force the matching to match entire words only. Pass null otherwise.

    • captureMatches: boolean

      The result will contain the captured groups.

    • Optional limitResultCount: number

      Limit the number of results

    Returns FindMatch[]

    The ranges where the matches are. It is empty if not matches have been found.

  • Search the model.

    Parameters

    • searchString: string

      The string used to search. If it is a regular expression, set isRegex to true.

    • searchScope: IRange | IRange[]

      Limit the searching to only search inside these ranges.

    • isRegex: boolean

      Used to indicate that searchString is a regular expression.

    • matchCase: boolean

      Force the matching to match lower/upper case exactly.

    • wordSeparators: string

      Force the matching to match entire words only. Pass null otherwise.

    • captureMatches: boolean

      The result will contain the captured groups.

    • Optional limitResultCount: number

      Limit the number of results

    Returns FindMatch[]

    The ranges where the matches are. It is empty if no matches have been found.

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

    Parameters

    • searchString: string

      The string used to search. If it is a regular expression, set isRegex to true.

    • searchStart: IPosition

      Start the searching at the specified position.

    • isRegex: boolean

      Used to indicate that searchString is a regular expression.

    • matchCase: boolean

      Force the matching to match lower/upper case exactly.

    • wordSeparators: string

      Force the matching to match entire words only. Pass null otherwise.

    • captureMatches: boolean

      The result will contain the captured groups.

    Returns FindMatch

    The range where the next match is. It is null if no next match has been found.

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

    Parameters

    • searchString: string

      The string used to search. If it is a regular expression, set isRegex to true.

    • searchStart: IPosition

      Start the searching at the specified position.

    • isRegex: boolean

      Used to indicate that searchString is a regular expression.

    • matchCase: boolean

      Force the matching to match lower/upper case exactly.

    • wordSeparators: string

      Force the matching to match entire words only. Pass null otherwise.

    • captureMatches: boolean

      The result will contain the captured groups.

    Returns FindMatch

    The range where the previous match is. It is null if no previous match has been found.

  • Gets all the decorations as an array.

    Parameters

    • Optional ownerId: number

      If set, it will ignore decorations belonging to other owners.

    • Optional filterOutValidation: boolean

      If set, it will ignore decorations specific to validation (i.e. warnings, errors).

    Returns IModelDecoration[]

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

    Parameters

    • Optional ownerId: number

      If set, it will ignore decorations belonging to other owners.

    Returns IModelDecoration[]

  • 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.

    Returns number

  • Get the character count of text in a certain range.

    Parameters

    Returns number

  • Get the options associated with a decoration.

    Parameters

    • id: string

      The decoration id.

    Returns IModelDecorationOptions

    The decoration options or null if the decoration was not found.

  • Get the range associated with a decoration.

    Parameters

    • id: string

      The decoration id.

    Returns Range

    The decoration range or null if the decoration was not found.

  • 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.

    Parameters

    • range: IRange

      The range to search in

    • Optional ownerId: number

      If set, it will ignore decorations belonging to other owners.

    • Optional filterOutValidation: boolean

      If set, it will ignore decorations specific to validation (i.e. warnings, errors).

    • Optional onlyMinimapDecorations: boolean

      If set, it will return only decorations that render in the minimap.

    • Optional onlyMarginDecorations: boolean

      If set, it will return only decorations that render in the glyph margin.

    Returns IModelDecoration[]

    An array with the decorations

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

    Returns string

    EOL char sequence (e.g.: '\n' or '\r\n').

  • Get a range covering the entire model.

    Returns Range

  • Gets all the decorations that contain injected text.

    Parameters

    • Optional ownerId: number

      If set, it will ignore decorations belonging to other owners.

    Returns IModelDecoration[]

  • Get the language associated with this model.

    Returns string

  • Get the text for a certain line.

    Parameters

    • lineNumber: number

    Returns string

  • Get the number of lines in the model.

    Returns number

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

    Parameters

    • lineNumber: number

      The line number

    • Optional ownerId: number

      If set, it will ignore decorations belonging to other owners.

    • Optional filterOutValidation: boolean

      If set, it will ignore decorations specific to validation (i.e. warnings, errors).

    Returns IModelDecoration[]

    An array with the decorations

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

    Parameters

    • lineNumber: number

    Returns number

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

    Parameters

    • lineNumber: number

    Returns number

  • Get the text length for a certain line.

    Parameters

    • lineNumber: number

    Returns number

  • Get the maximum legal column for line at lineNumber

    Parameters

    • lineNumber: number

    Returns number

  • Get the minimum legal column for line at lineNumber

    Parameters

    • lineNumber: number

    Returns number

  • Get the text for all lines.

    Returns string[]

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

    Parameters

    • startLineNumber: number

      The start line number

    • endLineNumber: number

      The end line number

    • Optional ownerId: number

      If set, it will ignore decorations belonging to other owners.

    • Optional filterOutValidation: boolean

      If set, it will ignore decorations specific to validation (i.e. warnings, errors).

    Returns IModelDecoration[]

    An array with the decorations

  • Converts the position to a zero-based offset.

    The position will be adjusted.

    Parameters

    Returns number

    A valid zero-based offset.

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

    Parameters

    • Optional ownerId: number

      If set, it will ignore decorations belonging to other owners.

    • Optional filterOutValidation: boolean

      If set, it will ignore decorations specific to validation (i.e. warnings, errors).

    Returns IModelDecoration[]

  • Converts a zero-based offset to a position.

    Parameters

    • offset: number

      A zero-based offset.

    Returns Position

    A valid position.

  • Get the text stored in this model.

    Parameters

    • Optional eol: EndOfLinePreference

      The end of line character preference. Defaults to EndOfLinePreference.TextDefined.

    • Optional preserveBOM: boolean

    Returns string

    The text.

  • Get the text in a certain range.

    Parameters

    • range: IRange

      The range describing what text to get.

    • Optional eol: EndOfLinePreference

      The end of line character preference. This will only be used for multiline ranges. Defaults to EndOfLinePreference.TextDefined.

    Returns string

    The text.

  • Get the length of the text stored in this model.

    Parameters

    Returns number

  • Get the length of text in a certain range.

    Parameters

    Returns number

    The text length.

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

    Returns number

  • Get the word under or besides position.

    Parameters

    • position: IPosition

      The position to look for a word.

    Returns IWordAtPosition

    The word under or besides position. Might be null.

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

    Parameters

    • position: IPosition

      The position to look for a word.

    Returns IWordAtPosition

    The word under or besides position. Will never be null.

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

    Returns boolean

  • Returns if the model was disposed or not.

    Returns boolean

  • 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.

    Parameters

    Returns Position

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

    Parameters

    • str: string

    Returns string

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

    Returns void

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

    Parameters

    Returns void

  • 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.

    Parameters

    • beforeCursorState: Selection[]

      The cursor state before the edit operations. This cursor state will be returned when undo or redo are invoked.

    • editOperations: IIdentifiedSingleEditOperation[]

      The edit operations.

    • cursorStateComputer: ICursorStateComputer

      A callback that can compute the resulting cursors state after the edit operations have been executed.

    Returns Selection[]

    The cursor state returned by the cursorStateComputer.

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

    Returns void

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

    Parameters

    Returns void

    Push EOL

    for the preferred way.

  • Replace the entire text buffer value contained in this model.

    Parameters

    Returns void

  • Change the options of this model.

    Parameters

    Returns void

  • Create a valid position.

    Parameters

    Returns Position

  • Create a valid range.

    Parameters

    Returns Range

Events

onDidChangeAttached: IEvent<void>

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

onDidChangeDecorations: IEvent<IModelDecorationsChangedEvent>

An event emitted when decorations of the model have changed.

onDidChangeLanguage: IEvent<IModelLanguageChangedEvent>

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

onDidChangeLanguageConfiguration: IEvent<IModelLanguageConfigurationChangedEvent>

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

onDidChangeOptions: IEvent<IModelOptionsChangedEvent>

An event emitted when the model options have changed.

onWillDispose: IEvent<void>

An event emitted right before disposing the model.

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

    Parameters

    Returns IDisposable