class

Selection

Inherits Reference < Object

A selection is a Span between a pair of Cursors.

Selection subscribes to both cursors, and rebuilds the Span when either of them moves.

In collapsed mode, both cursors have the same position and Span is empty. Selection ensures that: whenever one of the cursors moves, Selection moves the other one to the same position.

In split mode, selection lets the cursors loose. Move them however you like from the outside or using control, and Selection will do the rest.

Constructors

new(document : Document, cursor : Cursor, anchor : Cursor)
Source

Instance methods

<=>(other : Selection)

Compares this and other selections based on their minimum cursors (see min).

Source
==(other : self)

Two selections are equal when their cursors and anchors are equal.

above?

If possible, builds and returns a selection object above this selection. Otherwise, returns nil.

Source
acquire
Source
below?

If possible, builds and returns a selection object below this selection. Otherwise, returns nil.

Source
collapse

"Glues" together anchor and cursor of this selection. Usually called sometime after split.

Yields cursor to the block after collapsing so you can move it (e.g. in situations when the cursor is in an invalid state).

Returns self.

Source
collapse

"Glues" together anchor and cursor of this selection. Usually called sometime after split.

Use collapse(&) if the cursor is in an invalid state (e.g. you need to move it to the beginning after clearing the source). This method will raise if you try to do that.

Source
collapsed?

Returns whether this selection is collapsed (see collapse).

Source
control

Yields cursor and anchor to the block so you can e.g. command them to move.

Source
copy

Returns a copy of this selection, with cursor and anchor copied as well.

Source
del(count = 0, settings = SeekSettings.new)

Deletes count characters starting from cursor if this selection is collapsed. Otherwise, deletes the selected text and ignores count.

See Cursor#seek to learn what settings are.

Source
each_line

Yields member lines of this selection.

Source
each_line_with_bounds
Source
hash(hasher)

Two selections are equal when their cursors and anchors are equal.

ins(object : String)

Appends object after the cursor, or replaces the selected text with object.

Does not collapse this selection. Instead, this selection is resized to fit the inserted object.

Source
ins(object)

Appends object after the cursor, or replaces the selected text with object.

Does not collapse this selection. Instead, this selection is resized to fit the inserted object.

Source
insln(object : String = "")

Same as ins, but follows object with a newline, and keeps indentation from this line.

Source
insln(object)

Same as ins, but follows object with a newline, and keeps indentation from this line.

Source
line

Returns the line this selection is found in if this selection is inline. If this selection is multiline, raises.

Source
max

Returns the maximum (rightmost) of this selection's cursors.

Source
min

Returns the minimum (leftmost) of this selection's cursors.

Source
minmax

Returns a tuple of minimum (leftmost), maximum (rightmost) of this selection's cursors.

Source
multiline?

Returns whether this selection is multiline.

Source
overlaps?(other : Selection)

Returns whether this selection includes other's cursor or other's anchor.

Source
present(window)

Displays this selection in window.

Source
release
Source
resize

Resizes this selection: yields minimum (start), maximum (end) indices to the block, and expects the block to return a tuple of new start, end indices. Moves the anchor to the start index, and cursor to the end index.

Returns self.

Source
select_all

Selects all content in the document.

Source
select_line

Selects the current line. If this selection is multiline, extends both ends to the corresponding line boundaries.

Source
split

By default, anchor and cursor of a selection are "glued" together. This method disables that. Returns self.

Source
sync

Recalculates the span. Does quite a lot of work: try invoking only when you (sort of) know the span changed.

Source
visible?

Returns whether this entire selection, or any part of it, is visible in the document.

Source