@@ -2,7 +2,8 @@ use crate::{
2
2
components:: {
3
3
ChangesComponent , CommandBlocking , CommandInfo ,
4
4
CommitComponent , Component , DiffComponent , DrawableComponent ,
5
- HelpComponent , MsgComponent , ResetComponent ,
5
+ FileTreeItemKind , HelpComponent , MsgComponent ,
6
+ ResetComponent ,
6
7
} ,
7
8
keys,
8
9
queue:: { InternalEvent , NeedsUpdate , Queue } ,
@@ -177,7 +178,9 @@ impl App {
177
178
self . switch_focus ( Focus :: WorkDir )
178
179
}
179
180
keys:: FOCUS_STAGE => self . switch_focus ( Focus :: Stage ) ,
180
- keys:: FOCUS_RIGHT => self . switch_focus ( Focus :: Diff ) ,
181
+ keys:: FOCUS_RIGHT if self . can_focus_diff ( ) => {
182
+ self . switch_focus ( Focus :: Diff )
183
+ }
181
184
keys:: FOCUS_LEFT => {
182
185
self . switch_focus ( match self . diff_target {
183
186
DiffTarget :: Stage => Focus :: Stage ,
@@ -225,6 +228,14 @@ impl App {
225
228
pub fn is_quit ( & self ) -> bool {
226
229
self . do_quit
227
230
}
231
+
232
+ fn can_focus_diff ( & self ) -> bool {
233
+ match self . focus {
234
+ Focus :: WorkDir => self . index_wd . is_file_seleted ( ) ,
235
+ Focus :: Stage => self . index . is_file_seleted ( ) ,
236
+ _ => false ,
237
+ }
238
+ }
228
239
}
229
240
230
241
// private impls
@@ -259,11 +270,12 @@ impl App {
259
270
DiffTarget :: WorkingDir => ( & self . index_wd , false ) ,
260
271
} ;
261
272
262
- if let Some ( i ) = idx. selection ( ) {
263
- Some ( ( i . path , is_stage ) )
264
- } else {
265
- None
273
+ if let Some ( item ) = idx. selection ( ) {
274
+ if let FileTreeItemKind :: File ( i ) = item . kind {
275
+ return Some ( ( i . path , is_stage ) ) ;
276
+ }
266
277
}
278
+ None
267
279
}
268
280
269
281
fn update_commands ( & mut self ) {
@@ -381,7 +393,7 @@ impl App {
381
393
) ) ;
382
394
res. push ( CommandInfo :: new (
383
395
commands:: STATUS_FOCUS_RIGHT ,
384
- true ,
396
+ self . can_focus_diff ( ) ,
385
397
main_cmds_available && !focus_on_diff,
386
398
) ) ;
387
399
}
0 commit comments