objdiff-cli diff: Reduce duplicate key event code (#51)

This commit is contained in:
Robin Avery 2024-03-02 20:47:54 -05:00 committed by GitHub
parent ed5d092b11
commit 9f4a1e86cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 18 deletions

View File

@ -408,39 +408,28 @@ impl FunctionDiffUi {
// Quit // Quit
KeyCode::Esc | KeyCode::Char('q') => return FunctionDiffResult::Break, KeyCode::Esc | KeyCode::Char('q') => return FunctionDiffResult::Break,
// Page up // Page up
KeyCode::PageUp => { KeyCode::PageUp => self.page_up(false),
self.scroll_y = self.scroll_y.saturating_sub(self.per_page);
self.redraw = true;
}
// Page up (shift + space) // Page up (shift + space)
KeyCode::Char(' ') if event.modifiers.contains(KeyModifiers::SHIFT) => { KeyCode::Char(' ') if event.modifiers.contains(KeyModifiers::SHIFT) => {
self.scroll_y = self.scroll_y.saturating_sub(self.per_page); self.page_up(false)
self.redraw = true;
} }
// Page down // Page down
KeyCode::Char(' ') | KeyCode::PageDown => { KeyCode::Char(' ') | KeyCode::PageDown => self.page_down(false),
self.scroll_y += self.per_page;
self.redraw = true;
}
// Page down (ctrl + f) // Page down (ctrl + f)
KeyCode::Char('f') if event.modifiers.contains(KeyModifiers::CONTROL) => { KeyCode::Char('f') if event.modifiers.contains(KeyModifiers::CONTROL) => {
self.scroll_y += self.per_page; self.page_down(false)
self.redraw = true;
} }
// Page up (ctrl + b) // Page up (ctrl + b)
KeyCode::Char('b') if event.modifiers.contains(KeyModifiers::CONTROL) => { KeyCode::Char('b') if event.modifiers.contains(KeyModifiers::CONTROL) => {
self.scroll_y = self.scroll_y.saturating_sub(self.per_page); self.page_up(false)
self.redraw = true;
} }
// Half page down (ctrl + d) // Half page down (ctrl + d)
KeyCode::Char('d') if event.modifiers.contains(KeyModifiers::CONTROL) => { KeyCode::Char('d') if event.modifiers.contains(KeyModifiers::CONTROL) => {
self.scroll_y += self.per_page / 2; self.page_down(true)
self.redraw = true;
} }
// Half page up (ctrl + u) // Half page up (ctrl + u)
KeyCode::Char('u') if event.modifiers.contains(KeyModifiers::CONTROL) => { KeyCode::Char('u') if event.modifiers.contains(KeyModifiers::CONTROL) => {
self.scroll_y = self.scroll_y.saturating_sub(self.per_page / 2); self.page_up(true)
self.redraw = true;
} }
// Scroll down // Scroll down
KeyCode::Down | KeyCode::Char('j') => { KeyCode::Down | KeyCode::Char('j') => {
@ -517,6 +506,16 @@ impl FunctionDiffUi {
FunctionDiffResult::Continue FunctionDiffResult::Continue
} }
fn page_up(&mut self, half: bool) {
self.scroll_y = self.scroll_y.saturating_sub(self.per_page / if half { 2 } else { 1 });
self.redraw = true;
}
fn page_down(&mut self, half: bool) {
self.scroll_y += self.per_page / if half { 2 } else { 1 };
self.redraw = true;
}
fn print_sym( fn print_sym(
&self, &self,
out: &mut Text, out: &mut Text,