From 434c793d1c29e46fdbc52140a6db2d5386f3ed85 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Tue, 12 May 2020 01:21:32 +0200 Subject: [PATCH] support page up/down in log (#43) --- src/app.rs | 3 ++- src/components/diff.rs | 2 ++ src/components/mod.rs | 2 ++ src/keys.rs | 2 ++ src/tabs/revlog/mod.rs | 21 +++++++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 98ea895d..620b8f8f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -59,7 +59,7 @@ impl App { } /// - pub fn draw(&self, f: &mut Frame) { + pub fn draw(&mut self, f: &mut Frame) { 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]); } diff --git a/src/components/diff.rs b/src/components/diff.rs index 7ae3374f..db35d861 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -104,6 +104,8 @@ impl DiffComponent { } ScrollType::Home => self.scroll = 0, ScrollType::End => self.scroll = scroll_max, + //TODO: + _ => (), } if old != self.scroll { diff --git a/src/components/mod.rs b/src/components/mod.rs index dd3ea927..56b33768 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -57,6 +57,8 @@ pub enum ScrollType { Down, Home, End, + PageUp, + PageDown, } /// diff --git a/src/keys.rs b/src/keys.rs index f87c7a3b..914a5e8c 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -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 = diff --git a/src/tabs/revlog/mod.rs b/src/tabs/revlog/mod.rs index 6a49878d..7945514b 100644 --- a/src/tabs/revlog/mod.rs +++ b/src/tabs/revlog/mod.rs @@ -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(&self, f: &mut Frame, 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, }; }