mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
more highlights, prevent overscroll
This commit is contained in:
parent
2b855f43d7
commit
b3a52c171b
3 changed files with 61 additions and 31 deletions
28
src/keys.rs
28
src/keys.rs
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue