A simple CPU rendered GUI IDE experience.
ups and downs
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/text.rs | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 13ce961..07170b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -660,6 +660,8 @@ fn handle2(key: Key, text: &mut TextArea) { Named(ArrowRight) => text.right(), Named(ArrowUp) => text.up(), Named(ArrowDown) => text.down(), + Named(PageDown) => text.page_down(), + Named(PageUp) => text.page_up(), Named(Enter) => text.enter(), Character(x) => { text.insert(&x); diff --git a/src/text.rs b/src/text.rs index b5535e0..b3ecf1b 100644 --- a/src/text.rs +++ b/src/text.rs @@ -175,6 +175,22 @@ impl TextArea { - self.rope.line_to_char(self.rope.char_to_line(self.cursor)); } + pub fn page_down(&mut self) { + self.cursor = self.rope.line_to_char(min( + self.rope.char_to_line(self.cursor) + self.r, + self.l(), + )); + self.scroll_to_cursor(); + } + + #[lower::apply(saturating)] + pub fn page_up(&mut self) { + self.cursor = self + .rope + .line_to_char(self.rope.char_to_line(self.cursor) - self.r); + self.scroll_to_cursor(); + } + #[lower::apply(saturating)] pub fn left(&mut self) { self.cursor -= 1; |