@@ -5,7 +5,7 @@ use crate::{
5
5
strings,
6
6
} ;
7
7
use asyncgit:: { hash, DiffLine , DiffLineType , FileDiff } ;
8
- use crossterm:: event:: { Event , KeyCode } ;
8
+ use crossterm:: event:: { Event , KeyCode , KeyModifiers } ;
9
9
use std:: { borrow:: Cow , cmp, convert:: TryFrom } ;
10
10
use strings:: commands;
11
11
use tui:: {
@@ -24,6 +24,13 @@ struct Current {
24
24
hash : u64 ,
25
25
}
26
26
27
+ enum ScrollType {
28
+ Up ,
29
+ Down ,
30
+ Home ,
31
+ End ,
32
+ }
33
+
27
34
///
28
35
pub struct DiffComponent {
29
36
diff : FileDiff ,
@@ -86,15 +93,25 @@ impl DiffComponent {
86
93
}
87
94
}
88
95
89
- fn scroll ( & mut self , inc : bool ) {
96
+ fn scroll ( & mut self , scroll : ScrollType ) {
90
97
let old = self . scroll ;
91
- if inc {
92
- self . scroll = cmp:: min (
93
- self . diff . lines . saturating_sub ( 1 ) ,
94
- self . scroll . saturating_add ( 1 ) ,
95
- ) ;
96
- } else {
97
- self . scroll = self . scroll . saturating_sub ( 1 ) ;
98
+
99
+ let scroll_max = self . diff . lines . saturating_sub ( 1 ) ;
100
+
101
+ match scroll {
102
+ ScrollType :: Down => {
103
+ self . scroll = cmp:: min (
104
+ scroll_max,
105
+ self . scroll . saturating_add ( 1 ) ,
106
+ ) ;
107
+ }
108
+
109
+ ScrollType :: Up => {
110
+ self . scroll = self . scroll . saturating_sub ( 1 ) ;
111
+ }
112
+
113
+ ScrollType :: Home => self . scroll = 0 ,
114
+ ScrollType :: End => self . scroll = scroll_max,
98
115
}
99
116
100
117
if old != self . scroll {
@@ -322,6 +339,15 @@ impl Component for DiffComponent {
322
339
self . focused ,
323
340
) ) ;
324
341
342
+ out. push (
343
+ CommandInfo :: new (
344
+ commands:: DIFF_HOME_END ,
345
+ self . can_scroll ( ) ,
346
+ self . focused ,
347
+ )
348
+ . hidden ( ) ,
349
+ ) ;
350
+
325
351
let cmd_text = if self . current . is_stage {
326
352
commands:: DIFF_HUNK_REMOVE
327
353
} else {
@@ -340,13 +366,23 @@ impl Component for DiffComponent {
340
366
fn event ( & mut self , ev : Event ) -> bool {
341
367
if self . focused {
342
368
if let Event :: Key ( e) = ev {
369
+ let has_shift =
370
+ e. modifiers . contains ( KeyModifiers :: SHIFT ) ;
343
371
return match e. code {
344
- KeyCode :: Down => {
345
- self . scroll ( true ) ;
372
+ KeyCode :: Down if !has_shift => {
373
+ self . scroll ( ScrollType :: Down ) ;
374
+ true
375
+ }
376
+ KeyCode :: End | KeyCode :: Down if has_shift => {
377
+ self . scroll ( ScrollType :: End ) ;
378
+ true
379
+ }
380
+ KeyCode :: Home | KeyCode :: Up if has_shift => {
381
+ self . scroll ( ScrollType :: Home ) ;
346
382
true
347
383
}
348
- KeyCode :: Up => {
349
- self . scroll ( false ) ;
384
+ KeyCode :: Up if !has_shift => {
385
+ self . scroll ( ScrollType :: Up ) ;
350
386
true
351
387
}
352
388
KeyCode :: Enter => {
0 commit comments