1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
13pub struct Pos {
14 pub line: usize,
15 pub col: usize,
16}
17
18impl Pos {
19 #[inline]
20 pub const fn new(line: usize, col: usize) -> Self {
21 Self { line, col }
22 }
23
24 #[inline]
25 pub const fn zero() -> Self {
26 Self { line: 0, col: 0 }
27 }
28}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
34pub struct Selection {
35 pub anchor: Pos,
36 pub cursor: Pos,
37}
38
39impl Selection {
40 #[inline]
41 pub const fn new(anchor: Pos, cursor: Pos) -> Self {
42 Self { anchor, cursor }
43 }
44
45 #[inline]
46 pub const fn empty(at: Pos) -> Self {
47 Self {
48 anchor: at,
49 cursor: at,
50 }
51 }
52
53 #[inline]
55 pub fn ordered(&self) -> (Pos, Pos) {
56 if self.anchor <= self.cursor {
57 (self.anchor, self.cursor)
58 } else {
59 (self.cursor, self.anchor)
60 }
61 }
62
63 #[inline]
64 pub fn is_empty(&self) -> bool {
65 self.anchor == self.cursor
66 }
67}