Skip to content

Commit 434c793

Browse files
author
Stephan Dilly
committed
support page up/down in log (#43)
1 parent 0e9ba8a commit 434c793

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl App {
5959
}
6060

6161
///
62-
pub fn draw<B: Backend>(&self, f: &mut Frame<B>) {
62+
pub fn draw<B: Backend>(&mut self, f: &mut Frame<B>) {
6363
let chunks_main = Layout::default()
6464
.direction(Direction::Vertical)
6565
.constraints(
@@ -86,6 +86,7 @@ impl App {
8686
if self.tab == 0 {
8787
self.status_tab.draw(f, chunks_main[1]);
8888
} else {
89+
self.revlog.prepare_draw(chunks_main[1]);
8990
self.revlog.draw(f, chunks_main[1]);
9091
}
9192

src/components/diff.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ impl DiffComponent {
104104
}
105105
ScrollType::Home => self.scroll = 0,
106106
ScrollType::End => self.scroll = scroll_max,
107+
//TODO:
108+
_ => (),
107109
}
108110

109111
if old != self.scroll {

src/components/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub enum ScrollType {
5757
Down,
5858
Home,
5959
End,
60+
PageUp,
61+
PageDown,
6062
}
6163

6264
///

src/keys.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub const HOME: KeyEvent = no_mod(KeyCode::Home);
3131
pub const END: KeyEvent = no_mod(KeyCode::End);
3232
pub const MOVE_UP: KeyEvent = no_mod(KeyCode::Up);
3333
pub const MOVE_DOWN: KeyEvent = no_mod(KeyCode::Down);
34+
pub const PAGE_DOWN: KeyEvent = no_mod(KeyCode::PageDown);
35+
pub const PAGE_UP: KeyEvent = no_mod(KeyCode::PageUp);
3436
pub const SHIFT_UP: KeyEvent =
3537
with_mod(KeyCode::Up, KeyModifiers::SHIFT);
3638
pub const SHIFT_DOWN: KeyEvent =

src/tabs/revlog/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct Revlog {
5353
first_open_done: bool,
5454
scroll_state: (Instant, f32),
5555
tags: Tags,
56+
current_height: u16,
5657
}
5758

5859
impl Revlog {
@@ -67,9 +68,15 @@ impl Revlog {
6768
first_open_done: false,
6869
scroll_state: (Instant::now(), 0_f32),
6970
tags: Tags::new(),
71+
current_height: 0,
7072
}
7173
}
7274

75+
///
76+
pub fn prepare_draw(&mut self, area: Rect) {
77+
self.current_height = area.height.saturating_sub(2);
78+
}
79+
7380
///
7481
pub fn draw<B: Backend>(&self, f: &mut Frame<B>, area: Rect) {
7582
let height = area.height as usize;
@@ -155,6 +162,12 @@ impl Revlog {
155162
ScrollType::Down => {
156163
self.selection.saturating_add(speed_int)
157164
}
165+
ScrollType::PageUp => self.selection.saturating_sub(
166+
usize::from(self.current_height).saturating_sub(1),
167+
),
168+
ScrollType::PageDown => self.selection.saturating_add(
169+
usize::from(self.current_height).saturating_sub(1),
170+
),
158171
ScrollType::Home => 0,
159172
ScrollType::End => self.selection_max,
160173
};
@@ -281,6 +294,14 @@ impl Component for Revlog {
281294
self.move_selection(ScrollType::End);
282295
true
283296
}
297+
keys::PAGE_UP => {
298+
self.move_selection(ScrollType::PageUp);
299+
true
300+
}
301+
keys::PAGE_DOWN => {
302+
self.move_selection(ScrollType::PageDown);
303+
true
304+
}
284305
_ => false,
285306
};
286307
}

0 commit comments

Comments
 (0)