Skip to content

Commit f5795d1

Browse files
author
Stephan Dilly
committed
support home button for commit log (#43)
clippy fix
1 parent c42a421 commit f5795d1

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

Diff for: src/app.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,8 @@ impl App {
298298

299299
fn check_quit(&mut self, ev: Event) {
300300
if let Event::Key(e) = ev {
301-
match e {
302-
keys::EXIT => {
303-
self.do_quit = true;
304-
}
305-
_ => (),
301+
if let keys::EXIT = e {
302+
self.do_quit = true;
306303
}
307304
}
308305
}

Diff for: src/components/diff.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{CommandBlocking, DrawableComponent};
1+
use super::{CommandBlocking, DrawableComponent, ScrollType};
22
use crate::{
33
components::{CommandInfo, Component},
44
keys,
@@ -25,14 +25,6 @@ struct Current {
2525
hash: u64,
2626
}
2727

28-
#[derive(Copy, Clone)]
29-
enum ScrollType {
30-
Up,
31-
Down,
32-
Home,
33-
End,
34-
}
35-
3628
///
3729
pub struct DiffComponent {
3830
diff: FileDiff,

Diff for: src/components/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ pub use help::HelpComponent;
1919
pub use msg::MsgComponent;
2020
pub use reset::ResetComponent;
2121

22+
#[derive(Copy, Clone)]
23+
pub enum ScrollType {
24+
Up,
25+
Down,
26+
Home,
27+
End,
28+
}
29+
2230
///
2331
#[derive(PartialEq)]
2432
pub enum CommandBlocking {

Diff for: src/tabs/revlog.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::{
2-
components::{CommandBlocking, CommandInfo, Component},
2+
components::{
3+
CommandBlocking, CommandInfo, Component, ScrollType,
4+
},
35
keys,
46
strings::commands,
57
};
@@ -158,19 +160,24 @@ impl Revlog {
158160
}
159161
}
160162

161-
fn move_selection(&mut self, up: bool) {
163+
fn move_selection(&mut self, scroll: ScrollType) {
162164
self.update_scroll_speed();
163165

164166
#[allow(clippy::cast_possible_truncation)]
165167
let speed_int = usize::try_from(self.scroll_state.1 as i64)
166168
.unwrap()
167169
.max(1);
168170

169-
if up {
170-
self.selection = self.selection.saturating_sub(speed_int);
171-
} else {
172-
self.selection = self.selection.saturating_add(speed_int);
173-
}
171+
self.selection = match scroll {
172+
ScrollType::Up => {
173+
self.selection.saturating_sub(speed_int)
174+
}
175+
ScrollType::Down => {
176+
self.selection.saturating_add(speed_int)
177+
}
178+
ScrollType::Home => 0,
179+
_ => self.selection,
180+
};
174181

175182
self.selection = cmp::min(self.selection, self.selection_max);
176183

@@ -278,11 +285,15 @@ impl Component for Revlog {
278285
if let Event::Key(k) = ev {
279286
return match k {
280287
keys::MOVE_UP => {
281-
self.move_selection(true);
288+
self.move_selection(ScrollType::Up);
282289
true
283290
}
284291
keys::MOVE_DOWN => {
285-
self.move_selection(false);
292+
self.move_selection(ScrollType::Down);
293+
true
294+
}
295+
keys::SHIFT_UP | keys::HOME => {
296+
self.move_selection(ScrollType::Home);
286297
true
287298
}
288299
_ => false,

0 commit comments

Comments
 (0)