Skip to content

Commit

Permalink
support home button for commit log (#43)
Browse files Browse the repository at this point in the history
clippy fix
  • Loading branch information
Stephan Dilly committed May 10, 2020
1 parent c42a421 commit f5795d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
7 changes: 2 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions src/components/diff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{CommandBlocking, DrawableComponent};
use super::{CommandBlocking, DrawableComponent, ScrollType};
use crate::{
components::{CommandInfo, Component},
keys,
Expand All @@ -25,14 +25,6 @@ struct Current {
hash: u64,
}

#[derive(Copy, Clone)]
enum ScrollType {
Up,
Down,
Home,
End,
}

///
pub struct DiffComponent {
diff: FileDiff,
Expand Down
8 changes: 8 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 20 additions & 9 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
components::{CommandBlocking, CommandInfo, Component},
components::{
CommandBlocking, CommandInfo, Component, ScrollType,
},
keys,
strings::commands,
};
Expand Down Expand Up @@ -158,19 +160,24 @@ 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)]
let speed_int = usize::try_from(self.scroll_state.1 as i64)
.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);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f5795d1

Please sign in to comment.