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
Instance methods
Compares this and other selections based on their minimum
cursors (see min).
Two selections are equal when their cursors and anchors are equal.
If possible, builds and returns a selection object above this selection. Otherwise, returns nil.
If possible, builds and returns a selection object below this selection. Otherwise, returns nil.
"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.
"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.
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.
Two selections are equal when their cursors and anchors are equal.
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.
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.
Same as ins, but follows object with a newline, and
keeps indentation from this line.
Same as ins, but follows object with a newline, and
keeps indentation from this line.
Returns the line this selection is found in if this selection is inline. If this selection is multiline, raises.
Returns a tuple of minimum (leftmost), maximum (rightmost) of this selection's cursors.
Returns whether this selection includes other's cursor or other's anchor.
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.
Selects the current line. If this selection is multiline, extends both ends to the corresponding line boundaries.
By default, anchor and cursor of a selection are "glued" together. This method disables that. Returns self.
Recalculates the span. Does quite a lot of work: try invoking only when you (sort of) know the span changed.
Returns whether this entire selection, or any part of it, is visible in the document.