A simple CPU rendered GUI IDE experience.
Diffstat (limited to 'src/text/cursor.rs')
| -rw-r--r-- | src/text/cursor.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/text/cursor.rs b/src/text/cursor.rs index f8e4cc9..ed86ec9 100644 --- a/src/text/cursor.rs +++ b/src/text/cursor.rs @@ -113,7 +113,19 @@ pub macro ceach($cursor: expr, $f:expr $( => $q:tt)?) { // use unhygienic2::unhygienic; impl Cursor { pub fn new(c: usize, r: &Rope) -> Self { - Self { column: r.x(c).unwrap(), position: c, sel: None } + Self { + column: r.x(c).unwrap_or_else(|| { + log::error!("couldnt position column"); + 0 + }), + position: if c > r.len_chars() { + log::error!("couldnt add cursor at {c}"); + r.len_chars() - 5 + } else { + c + }, + sel: None, + } } fn cl(self, r: &Rope) -> RopeSlice<'_> { r.line(r.char_to_line(*self)) @@ -245,6 +257,7 @@ impl Cursor { self.set_ho(); } + #[lower::apply(saturating)] fn left(&mut self, r: &Rope) { self.position -= 1; self.setc(r); |