more highlights, prevent overscroll

This commit is contained in:
🪞👃🪞 2025-03-03 18:39:21 +02:00
parent 2b855f43d7
commit b3a52c171b
3 changed files with 61 additions and 31 deletions

View file

@ -1,8 +1,12 @@
use crate::*;
const PAGE_SIZE: usize = 10;
impl Handle<TuiIn> for Taggart {
fn handle (&mut self, input: &TuiIn) -> Perhaps<bool> {
Ok(match &*input.event() {
let x_min = self.offset;
let x_max = self.offset + self.size.h().saturating_sub(1);
match &*input.event() {
Event::Key(KeyEvent {
code: KeyCode::Up,
kind: KeyEventKind::Press,
@ -10,7 +14,6 @@ impl Handle<TuiIn> for Taggart {
state: KeyEventState::NONE
}) => {
self.cursor = self.cursor.saturating_sub(1);
None
},
Event::Key(KeyEvent {
code: KeyCode::Down,
@ -19,7 +22,6 @@ impl Handle<TuiIn> for Taggart {
state: KeyEventState::NONE
}) => {
self.cursor = self.cursor + 1;
None
},
Event::Key(KeyEvent {
code: KeyCode::PageUp,
@ -27,8 +29,7 @@ impl Handle<TuiIn> for Taggart {
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.offset = self.offset.saturating_sub(5);
None
self.cursor = self.cursor.saturating_sub(PAGE_SIZE);
},
Event::Key(KeyEvent {
code: KeyCode::PageDown,
@ -36,11 +37,20 @@ impl Handle<TuiIn> for Taggart {
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.offset += 5;
None
self.cursor += PAGE_SIZE;
},
_ => None
})
_ => {}
}
if self.cursor < x_min {
self.offset = self.cursor;
}
if self.cursor > x_max {
self.offset += self.cursor - x_max;
}
if self.cursor >= self.paths.len() {
self.cursor = self.paths.len().saturating_sub(1)
}
Ok(None)
}
}