Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a line and character position, such as the position of the cursor.

Position objects are immutable. Use the with or translate methods to derive new positions from an existing position.

Hierarchy

  • Position

Index

Constructors

  • new Position(line: number, character: number): Position

Properties

character: number

The zero-based character value.

line: number

The zero-based line value.

Methods

  • Compare this to other.

    Parameters

    Returns number

    A number smaller than zero if this position is before the given position, a number greater than zero if this position is after the given position, or zero when this and the given position are equal.

  • Check if this position is after other.

    Parameters

    Returns boolean

    true if position is on a greater line or on the same line on a greater character.

  • isAfterOrEqual(other: Position): boolean
  • Check if this position is after or equal to other.

    Parameters

    Returns boolean

    true if position is on a greater line or on the same line on a greater or equal character.

  • Check if this position is before other.

    Parameters

    Returns boolean

    true if position is on a smaller line or on the same line on a smaller character.

  • isBeforeOrEqual(other: Position): boolean
  • Check if this position is before or equal to other.

    Parameters

    Returns boolean

    true if position is on a smaller line or on the same line on a smaller or equal character.

  • Check if this position is equal to other.

    Parameters

    Returns boolean

    true if the line and character of the given position are equal to the line and character of this position.

  • translate(lineDelta?: number, characterDelta?: number): Position
  • translate(change: { characterDelta?: number; lineDelta?: number }): Position
  • Create a new position relative to this position.

    Parameters

    • Optional lineDelta: number

      Delta value for the line value, default is 0.

    • Optional characterDelta: number

      Delta value for the character value, default is 0.

    Returns Position

    A position which line and character is the sum of the current line and character and the corresponding deltas.

  • Derived a new position relative to this position.

    Parameters

    • change: { characterDelta?: number; lineDelta?: number }

      An object that describes a delta to this position.

      • Optional characterDelta?: number
      • Optional lineDelta?: number

    Returns Position

    A position that reflects the given delta. Will return this position if the change is not changing anything.

  • with(line?: number, character?: number): Position
  • with(change: { character?: number; line?: number }): Position
  • Create a new position derived from this position.

    Parameters

    • Optional line: number

      Value that should be used as line value, default is the existing value

    • Optional character: number

      Value that should be used as character value, default is the existing value

    Returns Position

    A position where line and character are replaced by the given values.

  • Derived a new position from this position.

    Parameters

    • change: { character?: number; line?: number }

      An object that describes a change to this position.

      • Optional character?: number
      • Optional line?: number

    Returns Position

    A position that reflects the given change. Will return this position if the change is not changing anything.