use super::*;
use std::cmp::Ordering;
impl LineColumn {
pub fn new(line: u32, column: u32) -> Self {
Self { line, column }
}
pub fn as_offset(&self, text: &TextIndex) -> Option<usize> {
let line_range = text.line_ranges.get(self.line as usize)?;
Some(line_range.start as usize + (self.column as usize))
}
}
impl PartialOrd for LineColumn {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for LineColumn {
fn cmp(&self, other: &Self) -> Ordering {
let line_cmp = self.line.cmp(&other.line);
if line_cmp == Ordering::Equal { self.column.cmp(&other.column) } else { line_cmp }
}
}