support home button for commit log (#43)

clippy fix
This commit is contained in:
Stephan Dilly 2020-05-10 14:57:49 +02:00
parent c42a421828
commit f5795d1fad
4 changed files with 31 additions and 23 deletions

View file

@ -298,11 +298,8 @@ impl App {
fn check_quit(&mut self, ev: Event) {
if let Event::Key(e) = ev {
match e {
keys::EXIT => {
self.do_quit = true;
}
_ => (),
if let keys::EXIT = e {
self.do_quit = true;
}
}
}

View file

@ -1,4 +1,4 @@
use super::{CommandBlocking, DrawableComponent};
use super::{CommandBlocking, DrawableComponent, ScrollType};
use crate::{
components::{CommandInfo, Component},
keys,
@ -25,14 +25,6 @@ struct Current {
hash: u64,
}
#[derive(Copy, Clone)]
enum ScrollType {
Up,
Down,
Home,
End,
}
///
pub struct DiffComponent {
diff: FileDiff,

View file

@ -19,6 +19,14 @@ pub use help::HelpComponent;
pub use msg::MsgComponent;
pub use reset::ResetComponent;
#[derive(Copy, Clone)]
pub enum ScrollType {
Up,
Down,
Home,
End,
}
///
#[derive(PartialEq)]
pub enum CommandBlocking {

View file

@ -1,5 +1,7 @@
use crate::{
components::{CommandBlocking, CommandInfo, Component},
components::{
CommandBlocking, CommandInfo, Component, ScrollType,
},
keys,
strings::commands,
};
@ -158,7 +160,7 @@ impl Revlog {
}
}
fn move_selection(&mut self, up: bool) {
fn move_selection(&mut self, scroll: ScrollType) {
self.update_scroll_speed();
#[allow(clippy::cast_possible_truncation)]
@ -166,11 +168,16 @@ impl Revlog {
.unwrap()
.max(1);
if up {
self.selection = self.selection.saturating_sub(speed_int);
} else {
self.selection = self.selection.saturating_add(speed_int);
}
self.selection = match scroll {
ScrollType::Up => {
self.selection.saturating_sub(speed_int)
}
ScrollType::Down => {
self.selection.saturating_add(speed_int)
}
ScrollType::Home => 0,
_ => self.selection,
};
self.selection = cmp::min(self.selection, self.selection_max);
@ -278,11 +285,15 @@ impl Component for Revlog {
if let Event::Key(k) = ev {
return match k {
keys::MOVE_UP => {
self.move_selection(true);
self.move_selection(ScrollType::Up);
true
}
keys::MOVE_DOWN => {
self.move_selection(false);
self.move_selection(ScrollType::Down);
true
}
keys::SHIFT_UP | keys::HOME => {
self.move_selection(ScrollType::Home);
true
}
_ => false,