support page up/down in log (#43)

This commit is contained in:
Stephan Dilly 2020-05-12 01:21:32 +02:00
parent 0e9ba8aef6
commit 434c793d1c
5 changed files with 29 additions and 1 deletions

View file

@ -59,7 +59,7 @@ impl App {
}
///
pub fn draw<B: Backend>(&self, f: &mut Frame<B>) {
pub fn draw<B: Backend>(&mut self, f: &mut Frame<B>) {
let chunks_main = Layout::default()
.direction(Direction::Vertical)
.constraints(
@ -86,6 +86,7 @@ impl App {
if self.tab == 0 {
self.status_tab.draw(f, chunks_main[1]);
} else {
self.revlog.prepare_draw(chunks_main[1]);
self.revlog.draw(f, chunks_main[1]);
}

View file

@ -104,6 +104,8 @@ impl DiffComponent {
}
ScrollType::Home => self.scroll = 0,
ScrollType::End => self.scroll = scroll_max,
//TODO:
_ => (),
}
if old != self.scroll {

View file

@ -57,6 +57,8 @@ pub enum ScrollType {
Down,
Home,
End,
PageUp,
PageDown,
}
///

View file

@ -31,6 +31,8 @@ pub const HOME: KeyEvent = no_mod(KeyCode::Home);
pub const END: KeyEvent = no_mod(KeyCode::End);
pub const MOVE_UP: KeyEvent = no_mod(KeyCode::Up);
pub const MOVE_DOWN: KeyEvent = no_mod(KeyCode::Down);
pub const PAGE_DOWN: KeyEvent = no_mod(KeyCode::PageDown);
pub const PAGE_UP: KeyEvent = no_mod(KeyCode::PageUp);
pub const SHIFT_UP: KeyEvent =
with_mod(KeyCode::Up, KeyModifiers::SHIFT);
pub const SHIFT_DOWN: KeyEvent =

View file

@ -53,6 +53,7 @@ pub struct Revlog {
first_open_done: bool,
scroll_state: (Instant, f32),
tags: Tags,
current_height: u16,
}
impl Revlog {
@ -67,9 +68,15 @@ impl Revlog {
first_open_done: false,
scroll_state: (Instant::now(), 0_f32),
tags: Tags::new(),
current_height: 0,
}
}
///
pub fn prepare_draw(&mut self, area: Rect) {
self.current_height = area.height.saturating_sub(2);
}
///
pub fn draw<B: Backend>(&self, f: &mut Frame<B>, area: Rect) {
let height = area.height as usize;
@ -155,6 +162,12 @@ impl Revlog {
ScrollType::Down => {
self.selection.saturating_add(speed_int)
}
ScrollType::PageUp => self.selection.saturating_sub(
usize::from(self.current_height).saturating_sub(1),
),
ScrollType::PageDown => self.selection.saturating_add(
usize::from(self.current_height).saturating_sub(1),
),
ScrollType::Home => 0,
ScrollType::End => self.selection_max,
};
@ -281,6 +294,14 @@ impl Component for Revlog {
self.move_selection(ScrollType::End);
true
}
keys::PAGE_UP => {
self.move_selection(ScrollType::PageUp);
true
}
keys::PAGE_DOWN => {
self.move_selection(ScrollType::PageDown);
true
}
_ => false,
};
}