pub struct Range {
pub start: Position,
pub end: Position,
}Expand description
A range of text in document order — start precedes or equals
end. Built in document order by
Dom::selection_range, which accepts
any two positions and sorts them; Range::ordered_unchecked trusts
the caller’s order.
Use Range::is_collapsed to detect zero-length ranges (the
“caret” case).
v1 note: sorting requires document-order comparison, which
needs the Dom. If you already know your two positions are in
order, use the struct literal directly (or
Range::ordered_unchecked); otherwise call
Dom::selection_range to get
the normalized range for the current Selection.
Fields§
§start: Position§end: PositionImplementations§
Source§impl Range
impl Range
Sourcepub fn ordered_unchecked(start: Position, end: Position) -> Self
pub fn ordered_unchecked(start: Position, end: Position) -> Self
Construct a range assuming the caller already knows the
positions are in document order. Never fails; if you pass
positions in the wrong order the resulting Range is
unusable for paint / copy but will still compile.
For a DOM-ordered normalization, use
Dom::selection_range.
Sourcepub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
true iff start == end — zero-length range (caret
position; no highlighted text).