#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Selection {
pub start: (usize, usize),
pub end: (usize, usize),
}
impl Selection {
pub fn new(start: (usize, usize), end: (usize, usize)) -> Self {
Self { start, end }
}
pub fn normalized(&self) -> Self {
if self.start.0 > self.end.0 || (self.start.0 == self.end.0 && self.start.1 > self.end.1) {
Self {
start: self.end,
end: self.start,
}
} else {
*self
}
}
pub fn contains(&self, line: usize, col: usize) -> bool {
let norm = self.normalized();
if line < norm.start.0 || line > norm.end.0 {
return false;
}
if line == norm.start.0 && line == norm.end.0 {
col >= norm.start.1 && col < norm.end.1
} else if line == norm.start.0 {
col >= norm.start.1
} else if line == norm.end.0 {
col < norm.end.1
} else {
true
}
}
}