class Selection
- Selection
- Reference
- Object
Overview
A selection is a Span
between a pair of Cursor
s.
Selection
subscribes to both cursors, and rebuilds the
Span
when either of them moves.
In #collapse
d 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.crConstructors
Instance Method Summary
-
#<=>(other : Selection)
Compares this and other selections based on their minimum cursors (see
#min
). -
#==(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.
- #acquire
-
#below?
If possible, builds and returns a selection object below this selection.
-
#collapse(&)
"Glues" together anchor and cursor of this selection.
-
#collapse
"Glues" together anchor and cursor of this selection.
-
#collapsed?
Returns whether this selection is collapsed (see
#collapse
). -
#control(&)
Yields cursor and anchor to the block so you can e.g.
-
#copy
Returns a copy of this selection, with cursor and anchor copied as well.
-
#del(count = 0, settings = SeekSettings.new)
Deletes count characters starting from cursor if this selection is collapsed.
-
#each_line(&)
Yields member lines of this selection.
- #each_line_with_bounds(&)
-
#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.
-
#ins(object)
Appends object after the cursor, or replaces the selected text with object.
-
#insln(object : String = "")
Same as
#ins
, but follows object with a newline, and keeps indentation from this line. -
#insln(object)
Same as
#ins
, but follows object with a newline, and keeps indentation from this line. -
#line
Returns the line this selection is found in if this selection is inline.
-
#max
Returns the maximum (rightmost) of this selection's cursors.
-
#min
Returns the minimum (leftmost) of this selection's cursors.
-
#minmax
Returns a tuple of minimum (leftmost), maximum (rightmost) of this selection's cursors.
-
#multiline?
Returns whether this selection is multiline.
-
#overlaps?(other : Selection)
Returns whether this selection includes other's cursor or other's anchor.
-
#present(window)
Displays this selection in window.
- #release
-
#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.
-
#select_all
Selects all content in the document.
-
#select_line
Selects the current line.
-
#split
By default, anchor and cursor of a selection are "glued" together.
-
#sync
Recalculates the span.
-
#visible?
Returns whether this entire selection, or any part of it, is visible in the document.
Constructor Detail
Instance Method Detail
Compares this and other selections based on their minimum
cursors (see #min
).
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.
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.