1use super::index::CharIndex;
4
5#[derive(Clone, Copy, Debug, Default)]
9#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
10pub struct CCursor {
11 pub index: CharIndex,
13
14 pub prefer_next_row: bool,
19}
20
21impl CCursor {
22 #[inline]
23 pub fn new(index: impl Into<CharIndex>) -> Self {
24 Self {
25 index: index.into(),
26 prefer_next_row: false,
27 }
28 }
29}
30
31impl PartialEq for CCursor {
34 #[inline]
35 fn eq(&self, other: &Self) -> bool {
36 self.index == other.index
37 }
38}
39
40impl std::ops::Add<usize> for CCursor {
41 type Output = Self;
42
43 fn add(self, rhs: usize) -> Self::Output {
44 Self {
45 index: self.index.saturating_add(rhs),
46 prefer_next_row: self.prefer_next_row,
47 }
48 }
49}
50
51impl std::ops::Add<CharIndex> for CCursor {
52 type Output = Self;
53
54 fn add(self, rhs: CharIndex) -> Self::Output {
55 Self {
56 index: self.index + rhs,
57 prefer_next_row: self.prefer_next_row,
58 }
59 }
60}
61
62impl std::ops::Sub<usize> for CCursor {
63 type Output = Self;
64
65 fn sub(self, rhs: usize) -> Self::Output {
66 Self {
67 index: self.index.saturating_sub(rhs),
68 prefer_next_row: self.prefer_next_row,
69 }
70 }
71}
72
73impl std::ops::Sub<CharIndex> for CCursor {
74 type Output = Self;
75
76 fn sub(self, rhs: CharIndex) -> Self::Output {
77 Self {
78 index: self.index - rhs,
79 prefer_next_row: self.prefer_next_row,
80 }
81 }
82}
83
84impl std::ops::AddAssign<usize> for CCursor {
85 fn add_assign(&mut self, rhs: usize) {
86 self.index = self.index.saturating_add(rhs);
87 }
88}
89
90impl std::ops::SubAssign<usize> for CCursor {
91 fn sub_assign(&mut self, rhs: usize) {
92 self.index = self.index.saturating_sub(rhs);
93 }
94}
95
96#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
100#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
101pub struct LayoutCursor {
102 pub row: usize,
106
107 pub column: CharIndex,
111}