A simple CPU rendered GUI IDE experience.
fix hl overflows
| -rw-r--r-- | src/main.rs | 7 | ||||
| -rw-r--r-- | src/text.rs | 15 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 0cda409..53e27a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -435,7 +435,12 @@ pub(crate) fn entry(event_loop: EventLoop<()>) { window.request_redraw(); } Event::WindowEvent { - event: WindowEvent::KeyboardInput { event, is_synthetic: false, .. }, + event: + WindowEvent::KeyboardInput { + event, + is_synthetic: false, + .. + }, .. } if event.state == ElementState::Pressed => { if matches!( diff --git a/src/text.rs b/src/text.rs index e71b32b..ff619b8 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1,3 +1,4 @@ +use std::cmp::min; use std::fmt::{Debug, Display}; use std::ops::{Not as _, Range}; use std::sync::LazyLock; @@ -422,10 +423,16 @@ impl TextArea { // } let y1 = self.rope.byte_to_line(start); let y2 = self.rope.byte_to_line(end); - let x1 = self.rope.byte_to_char(start) - - self.rope.line_to_char(y1); - let x2 = self.rope.byte_to_char(end) - - self.rope.line_to_char(y2); + let x1 = min( + self.rope.byte_to_char(start) + - self.rope.line_to_char(y1), + c, + ); + let x2 = min( + self.rope.byte_to_char(end) + - self.rope.line_to_char(y2), + c, + ); cells.get_mut(y1 * c + x1..y2 * c + x2).map(|x| { x.iter_mut().for_each(|x| { |