Skip to content

Range

A wrapper for a range of numbers. Used for storing the start and end positions of a selection, and providing utility functions for working with ranges. This class is accessible by accessing the range field on the main module.

Types


range

lua
interface range {     startPosition: number, --  The start position of the range.    endPosition: number, --  The end position of the range.}

Functions


new
constructor

lua
Range.new(    startPosition: number, --  The start position of the range.    endPosition: number --  The end position of the range.)Range

Creates a new range object.


clone

lua
Range:clone()Range

Clones the range.


fitsInRange

lua
Range:fitsInRange(    passedRange: Range --  The range to check if it fits within the range.)(boolean, -- Whether the range fits within the range.number?, -- The start position of the range if it fits within the range.number? -- The end position of the range if it fits within the range.)

Checks if the passed range fits within the range. If it does, it returns true, and the start and end positions of the range.


get

lua
Range:get()(number, -- The start position of the range.number -- The end position of the range.)

Gets the start and end positions of the range.


getEnd

lua
Range:getEnd()number

Gets the end position of the range.


getStart

lua
Range:getStart()number

Gets the start position of the range.


looselyFitsInRange

lua
Range:looselyFitsInRange(    passedRange: Range --  The range to check if it loosely fits within the range.)(boolean, -- Whether the range loosely fits within the range.number?, -- The start position of the range if it loosely fits within the range.number? -- The end position of the range if it loosely fits within the range.)

Checks if the passed range loosely fits within the range. If it does, it returns true, and the start and end positions of the range.

"Loosely fits" refers to whether any part fits within the range: for example, when passed (10, 20) and (15, 25), it will return true. You'd use this when you want to check whether ranges are overlapping, but not necessarily fully contained within each other.


merge

lua
Range:merge(    otherRange: Range --  The range to merge with.)Range

Merges the range with another range, returning a new range that contains both ranges.


set

lua
Range:set(    startPosition: number, --  The new start position of the range.    endPosition: number --  The new end position of the range.)

Sets the start and end positions of the range.