Text Document

A Text Document is an immutable value type representing a string of text (the text document's content) and a "selection" or "cursor".

The selection (or cursor) is represented by an anchor and a focus index (both are indices into the content string). The anchor index is the index of the side of the selection that was selected first, and the focus index is the side of the selection that was selected last.

You can use the factory methods to produce new Text Document instances with modified content or changed selection.

Text Document methods may be used when developing an Input Processor to create modifications of the original document and return them. See: Processors.

Hierarchy

  • TextDocument

Constructors

  • Creates a new TextDocument with the given content and selection.

    Parameters

    • anchorIndex: number

      The index of the anchor of the selection.

    • focusIndex: number

      The index of the focus of the selection.

    • text: string

      The content of the text document.

    • noSelection: boolean = false

      Whether or not the selection is active.

    • totalLines: null | number = null

      The total number of lines in the text document.

    • startSelectionLine: null | number = null

      The line number of the first line of the selection.

    • endSelectionLine: null | number = null

      The line number of the last line of the selection.

    Returns TextDocument

Properties

anchorIndex: number

The index of the anchor of the selection.

endSelectionLine: null | number = null

The line number of the last line of the selection.

focusIndex: number

The index of the focus of the selection.

startSelectionLine: null | number = null

The line number of the first line of the selection.

text: string

The content of the text document.

totalLines: null | number = null

The total number of lines in the text document.

Accessors

  • get dir(): "->" | "<-"
  • The direction of the selection (or cursor). -> means the selection is from left to right. <- means the selection is from right to left.

    TODO: DELETE THIS

    Returns

    A string representing the direction of the selection.

    Returns "->" | "<-"

  • get selectionType(): "none" | "caret" | "range"
  • Returns the type of selection that is currently active. none means no selection is active. caret means a single position is selected. range means a range of positions is selected.

    Returns

    A string representing the type of selection that is currently active.

    Returns "none" | "caret" | "range"

Methods

  • Inserts text at the selection.

    Returns

    A new text document with the text inserted at the selection.

    Parameters

    • newText: string

      The text to insert.

    • advanceAnchor: boolean = true

      Whether to advance the anchor index by the length of the text.

    • advanceFocus: boolean = true

      Whether to advance the focus index by the length of the text.

    Returns TextDocument

  • Returns whether the other text document is equal to this one, ignoring the selection.

    Returns

    Whether the other text document is equal to this one, ignoring the selection.

    Parameters

    Returns boolean

Generated using TypeDoc