@@ -6,7 +6,7 @@ use super::{
6
6
} ;
7
7
use crate :: {
8
8
keys:: SharedKeyConfig ,
9
- queue:: Queue ,
9
+ queue:: { InternalEvent , Queue } ,
10
10
strings:: { self , order} ,
11
11
ui:: { self , style:: SharedTheme } ,
12
12
} ;
@@ -27,6 +27,7 @@ const FOLDER_ICON_EXPANDED: &str = "\u{25be}"; //▾
27
27
const EMPTY_STR : & str = "" ;
28
28
29
29
pub struct RevisionFilesComponent {
30
+ queue : Queue ,
30
31
title : String ,
31
32
theme : SharedTheme ,
32
33
files : Vec < TreeFile > ,
@@ -41,12 +42,13 @@ pub struct RevisionFilesComponent {
41
42
impl RevisionFilesComponent {
42
43
///
43
44
pub fn new (
44
- _queue : & Queue ,
45
+ queue : & Queue ,
45
46
_sender : & Sender < AsyncNotification > ,
46
47
theme : SharedTheme ,
47
48
key_config : SharedKeyConfig ,
48
49
) -> Self {
49
50
Self {
51
+ queue : queue. clone ( ) ,
50
52
title : String :: new ( ) ,
51
53
tree : FileTree :: default ( ) ,
52
54
theme,
@@ -109,6 +111,20 @@ impl RevisionFilesComponent {
109
111
let path = format ! ( "{}{}{}" , indent_str, path_arrow, path) ;
110
112
Span :: styled ( path, theme. file_tree_item ( is_path, selected) )
111
113
}
114
+
115
+ fn blame ( & self ) -> bool {
116
+ self . tree . selected_file ( ) . map_or ( false , |file| {
117
+ self . queue . borrow_mut ( ) . push_back (
118
+ InternalEvent :: BlameFile (
119
+ file. full_path ( )
120
+ . strip_prefix ( "./" )
121
+ . unwrap_or_default ( )
122
+ . to_string ( ) ,
123
+ ) ,
124
+ ) ;
125
+ true
126
+ } )
127
+ }
112
128
}
113
129
114
130
impl DrawableComponent for RevisionFilesComponent {
@@ -178,6 +194,15 @@ impl Component for RevisionFilesComponent {
178
194
. order ( 1 ) ,
179
195
) ;
180
196
197
+ out. push (
198
+ CommandInfo :: new (
199
+ strings:: commands:: blame_file ( & self . key_config ) ,
200
+ self . tree . selected_file ( ) . is_some ( ) ,
201
+ true ,
202
+ )
203
+ . order ( order:: NAV ) ,
204
+ ) ;
205
+
181
206
tree_nav_cmds ( & self . tree , & self . key_config , out) ;
182
207
}
183
208
@@ -193,6 +218,13 @@ impl Component for RevisionFilesComponent {
193
218
let consumed = if key == self . key_config . exit_popup {
194
219
self . hide ( ) ;
195
220
true
221
+ } else if key == self . key_config . blame {
222
+ if self . blame ( ) {
223
+ self . hide ( ) ;
224
+ true
225
+ } else {
226
+ false
227
+ }
196
228
} else {
197
229
tree_nav ( & mut self . tree , & self . key_config , key)
198
230
} ;
0 commit comments