# Selection

Contains the cursor position and the text selection of an edit session.

The row/columns used in the selection are in document coordinates representing the coordinates as they appear in the document before applying soft wrap and folding.

### Constructors

- - new Selection(EditSession session)

Creates a new `Selection` object.

Creates a new `Selection` object.

#### Arguments

session | EditSession | Required. The session to use

### Events

- - Selection.on("changeCursor", function())

Emitted when the cursor position changes.

Emitted when the cursor position changes.

- - Selection.on("changeSelection", function())

Emitted when the cursor selection changes.

Emitted when the cursor selection changes.

### Methods

- - Selection.addRange(Range range, Boolean $blockChangeEvents)

Adds a range to a selection by entering multiselect mode, if necessary.

Adds a range to a selection by entering multiselect mode, if necessary.

#### Arguments

range | Range | Required. The new range to add
$blockChangeEvents | Boolean | Required. Whether or not to block changing events

- - Selection.clearSelection()

Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.

Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.

- - Selection.detach()
  - Undocumented

- - Selection.fromOrientedRange()
  - Undocumented

- - Selection.getAllRanges()
  - - Array

Returns a concatenation of all the ranges.

Returns a concatenation of all the ranges.

- - Selection.getCursor()
  - - Number

Gets the current position of the cursor.

Gets the current position of the cursor.

- - Selection.getLineRange()
  - Undocumented

- - Selection.getRange()
  - - Range

Returns the `Range` for the selected text.

Returns the `Range` for the selected text.

- - Selection.getSelectionAnchor()
  - - Object

Returns an object containing the `row` and `column` of the calling selection anchor.

Returns an object containing the `row` and `column` of the calling selection anchor.

- - Selection.getSelectionLead()
  - - Object

Returns an object containing the `row` and `column` of the calling selection lead.

Returns an object containing the `row` and `column` of the calling selection lead.

- - Selection.getWordRange(Object row, Object column)

Moves the selection to highlight the entire word.

Moves the selection to highlight the entire word.

#### Arguments

row | Object | Required.
column | Object | Required.

- - Selection.isBackwards()
  - - Boolean

Returns `true` if the selection is going backwards in the document.

Returns `true` if the selection is going backwards in the document.

- - Selection.isEmpty()
  - - Boolean

Returns `true` if the selection is empty.

Returns `true` if the selection is empty.

- - Selection.isMultiLine()
  - - Boolean

Returns `true` if the selection is a multi-line.

Returns `true` if the selection is a multi-line.

- - Selection.mergeOverlappingRanges()

Merges overlapping ranges ensuring consistency after changes

Merges overlapping ranges ensuring consistency after changes

- - Selection.moveCursorBy(Number rows, Number chars)

Moves the cursor to position indicated by the parameters. Negative numbers move the cursor backwards in the document.

Moves the cursor to position indicated by the parameters. Negative numbers move the cursor backwards in the document.

#### Arguments

rows | Number | Required. The number of rows to move by
chars | Number | Required. The number of characters to move by

- - Selection.moveCursorDown()

Moves the cursor down one row.

Moves the cursor down one row.

- - Selection.moveCursorFileEnd()

Moves the cursor to the end of the file.

Moves the cursor to the end of the file.

- - Selection.moveCursorFileStart()

Moves the cursor to the start of the file.

Moves the cursor to the start of the file.

- - Selection.moveCursorLeft()

Moves the cursor left one column.

Moves the cursor left one column.

- - Selection.moveCursorLineEnd()

Moves the cursor to the end of the line.

Moves the cursor to the end of the line.

- - Selection.moveCursorLineStart()

Moves the cursor to the start of the line.

Moves the cursor to the start of the line.

- - Selection.moveCursorLongWordLeft()

Moves the cursor to the word on the left.

Moves the cursor to the word on the left.

- - Selection.moveCursorLongWordRight()

Moves the cursor to the word on the right.

Moves the cursor to the word on the right.

- - Selection.moveCursorRight()

Moves the cursor right one column.

Moves the cursor right one column.

- - Selection.moveCursorShortWordLeft()
  - Undocumented

- - Selection.moveCursorShortWordRight()
  - Undocumented

- - Selection.moveCursorTo(Number row, Number column, Boolean keepDesiredColumn)

Moves the cursor to the row and column provided. If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.

Moves the cursor to the row and column provided. If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.

#### Arguments

row | Number | Required. The row to move to
column | Number | Required. The column to move to
keepDesiredColumn | Boolean | Required. If `true`, the cursor move does not respect the previous column

- - Selection.moveCursorToPosition(Object position)

Moves the selection to the position indicated by its `row` and `column`.

Moves the selection to the position indicated by its `row` and `column`.

#### Arguments

position | Object | Required. The position to move to

- - Selection.moveCursorToScreen(Number row, Number column, Boolean keepDesiredColumn)

Moves the cursor to the screen position indicated by row and column. If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.

Moves the cursor to the screen position indicated by row and column. If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.

#### Arguments

row | Number | Required. The row to move to
column | Number | Required. The column to move to
keepDesiredColumn | Boolean | Required. If `true`, the cursor move does not respect the previous column

- - Selection.moveCursorUp()

Moves the cursor up one row.

Moves the cursor up one row.

- - Selection.moveCursorWordLeft()
  - Undocumented

- - Selection.moveCursorWordRight()
  - Undocumented

- - Selection.rectangularRangeBlock(Cursor screenCursor, Anchor screenAnchor, Boolean includeEmptyLines)
  - - Range

Gets list of ranges composing rectangular block on the screen

Gets list of ranges composing rectangular block on the screen

#### Arguments

screenCursor | Cursor | Required. The cursor to use
screenAnchor | Anchor | Required. The anchor to use
includeEmptyLines | Boolean | Required. If true, this includes ranges inside the block which are empty due to clipping

- - Selection.selectAll()

Selects all the text in the document.

Selects all the text in the document.

- - Selection.selectAWord()

Selects a word, including its right whitespace.

Selects a word, including its right whitespace.

- - Selection.selectDown()

Moves the selection down one row.

Moves the selection down one row.

- - Selection.selectFileEnd()

Moves the selection to the end of the file.

Moves the selection to the end of the file.

- - Selection.selectFileStart()

Moves the selection to the start of the file.

Moves the selection to the start of the file.

- - Selection.selectLeft()

Moves the selection left one column.

Moves the selection left one column.

- - Selection.selectLine()

Selects the entire line.

Selects the entire line.

- - Selection.selectLineEnd()

Moves the selection to the end of the current line.

Moves the selection to the end of the current line.

- - Selection.selectLineStart()

Moves the selection to the beginning of the current line.

Moves the selection to the beginning of the current line.

- - Selection.selectRight()

Moves the selection right one column.

Moves the selection right one column.

- - Selection.selectTo(Number row, Number column)

Moves the selection cursor to the indicated row and column.

Moves the selection cursor to the indicated row and column.

#### Arguments

row | Number | Required. The row to select to
column | Number | Required. The column to select to

- - Selection.selectToPosition(Object pos)

Moves the selection cursor to the row and column indicated by `pos`.

Moves the selection cursor to the row and column indicated by `pos`.

#### Arguments

pos | Object | Required. An object containing the row and column

- - Selection.selectUp()

Moves the selection up one row.

Moves the selection up one row.

- - Selection.selectWord()

Selects an entire word boundary.

Selects an entire word boundary.

- - Selection.selectWordLeft()

Moves the selection to the first word on the left.

Moves the selection to the first word on the left.

- - Selection.selectWordRight()

Moves the selection to the first word on the right.

Moves the selection to the first word on the right.

- - Selection.setSelectionAnchor(Number row, Number column)

Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event.

Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event.

#### Arguments

row | Number | Required. The new row
column | Number | Required. The new column

- - Selection.setSelectionRange(Range range, Boolean reverse)

Sets the selection to the provided range.

Sets the selection to the provided range.

#### Arguments

range | Range | Required. The range of text to select
reverse | Boolean | Required. Indicates if the range should go backwards (`true`) or not

- - Selection.shiftSelection(Number columns)

Shifts the selection up (or down, if `isBackwards()` is true) the given number of columns.

Shifts the selection up (or down, if `isBackwards()` is true) the given number of columns.

#### Arguments

columns | Number | Required. The number of columns to shift by

- - Selection.splitIntoLines()

Splits all the ranges into lines.

Splits all the ranges into lines.

- - Selection.substractPoint(Range pos)

Removes a Range containing pos (if it exists).

Removes a Range containing pos (if it exists).

#### Arguments

pos | Range | Required. The position to remove, as a `{row, column}` object

- - Selection.toggleBlockSelection()
  - Undocumented

- - Selection.toOrientedRange()
  - Undocumented

- - Selection.toSingleRange()
  - Undocumented