mirror of https://github.com/encounter/objdiff.git
objdiff-cli diff: Reduce duplicate key event code (#51)
This commit is contained in:
parent
ed5d092b11
commit
9f4a1e86cd
|
@ -408,39 +408,28 @@ impl FunctionDiffUi {
|
|||
// Quit
|
||||
KeyCode::Esc | KeyCode::Char('q') => return FunctionDiffResult::Break,
|
||||
// Page up
|
||||
KeyCode::PageUp => {
|
||||
self.scroll_y = self.scroll_y.saturating_sub(self.per_page);
|
||||
self.redraw = true;
|
||||
}
|
||||
KeyCode::PageUp => self.page_up(false),
|
||||
// Page up (shift + space)
|
||||
KeyCode::Char(' ') if event.modifiers.contains(KeyModifiers::SHIFT) => {
|
||||
self.scroll_y = self.scroll_y.saturating_sub(self.per_page);
|
||||
self.redraw = true;
|
||||
self.page_up(false)
|
||||
}
|
||||
// Page down
|
||||
KeyCode::Char(' ') | KeyCode::PageDown => {
|
||||
self.scroll_y += self.per_page;
|
||||
self.redraw = true;
|
||||
}
|
||||
KeyCode::Char(' ') | KeyCode::PageDown => self.page_down(false),
|
||||
// Page down (ctrl + f)
|
||||
KeyCode::Char('f') if event.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
self.scroll_y += self.per_page;
|
||||
self.redraw = true;
|
||||
self.page_down(false)
|
||||
}
|
||||
// Page up (ctrl + b)
|
||||
KeyCode::Char('b') if event.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
self.scroll_y = self.scroll_y.saturating_sub(self.per_page);
|
||||
self.redraw = true;
|
||||
self.page_up(false)
|
||||
}
|
||||
// Half page down (ctrl + d)
|
||||
KeyCode::Char('d') if event.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
self.scroll_y += self.per_page / 2;
|
||||
self.redraw = true;
|
||||
self.page_down(true)
|
||||
}
|
||||
// Half page up (ctrl + u)
|
||||
KeyCode::Char('u') if event.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||
self.scroll_y = self.scroll_y.saturating_sub(self.per_page / 2);
|
||||
self.redraw = true;
|
||||
self.page_up(true)
|
||||
}
|
||||
// Scroll down
|
||||
KeyCode::Down | KeyCode::Char('j') => {
|
||||
|
@ -517,6 +506,16 @@ impl FunctionDiffUi {
|
|||
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(
|
||||
&self,
|
||||
out: &mut Text,
|
||||
|
|
Loading…
Reference in New Issue