use super::*;
impl SelectionState {
#[must_use]
#[inline(always)]
pub const fn single(node_id: NodeId, anchor_char: usize, focus_char: usize) -> Self {
Self {
anchor_node: node_id,
anchor_char,
focus_node: node_id,
focus_char,
}
}
#[must_use]
#[inline(always)]
pub const fn get_node_id(&self) -> NodeId {
let Self { anchor_node, .. } = *self;
anchor_node
}
#[must_use]
#[inline(always)]
pub fn is_single_node(&self) -> bool {
let Self {
anchor_node,
focus_node,
..
} = *self;
anchor_node == focus_node
}
#[must_use]
#[inline(always)]
pub const fn ordered_range(&self) -> (usize, usize) {
let Self {
anchor_char,
focus_char,
..
} = *self;
if anchor_char <= focus_char {
(anchor_char, focus_char)
} else {
(focus_char, anchor_char)
}
}
#[must_use]
#[inline(always)]
pub fn is_empty(&self) -> bool {
let Self {
anchor_char,
focus_char,
..
} = *self;
self.is_single_node() && anchor_char == focus_char
}
#[must_use]
pub fn extract_from<'a>(&self, text: &'a str) -> &'a str {
let (start_char, end_char): (usize, usize) = self.ordered_range();
extract_char_range(text, start_char, end_char)
}
}