class Selection

Overview

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.

Defined in:

aspis/selection.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(document : Document, cursor : Cursor, anchor : Cursor) #

[View source]

Instance Method Detail

def <=>(other : Selection) #

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


[View source]
def ==(other : self) #

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


def above? #

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


[View source]
def acquire #

[View source]
def below? #

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


[View source]
def 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.


[View source]
def 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.


[View source]
def collapsed? #

Returns whether this selection is collapsed (see #collapse).


[View source]
def control(&) #

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


[View source]
def copy #

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


[View source]
def 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.


[View source]
def each_line(&) #

Yields member lines of this selection.


[View source]
def each_line_with_bounds(&) #

[View source]
def hash(hasher) #

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


def 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.


[View source]
def 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.


[View source]
def insln(object : String = "") #

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


[View source]
def insln(object) #

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


[View source]
def line #

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


[View source]
def max #

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


[View source]
def min #

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


[View source]
def minmax #

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


[View source]
def multiline? #

Returns whether this selection is multiline.


[View source]
def overlaps?(other : Selection) #

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


[View source]
def present(window) #

Displays this selection in window.


[View source]
def release #

[View source]
def 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.


[View source]
def select_all #

Selects all content in the document.


[View source]
def select_line #

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


[View source]
def split #

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


[View source]
def sync #

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


[View source]
def visible? #

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


[View source]