@@ -2,7 +2,8 @@ use crate::{
22 components:: {
33 ChangesComponent , CommandBlocking , CommandInfo ,
44 CommitComponent , Component , DiffComponent , DrawableComponent ,
5- HelpComponent , MsgComponent , ResetComponent ,
5+ FileTreeItemKind , HelpComponent , MsgComponent ,
6+ ResetComponent ,
67 } ,
78 keys,
89 queue:: { InternalEvent , NeedsUpdate , Queue } ,
@@ -177,7 +178,9 @@ impl App {
177178 self . switch_focus ( Focus :: WorkDir )
178179 }
179180 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+ }
181184 keys:: FOCUS_LEFT => {
182185 self . switch_focus ( match self . diff_target {
183186 DiffTarget :: Stage => Focus :: Stage ,
@@ -225,6 +228,14 @@ impl App {
225228 pub fn is_quit ( & self ) -> bool {
226229 self . do_quit
227230 }
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+ }
228239}
229240
230241// private impls
@@ -259,11 +270,12 @@ impl App {
259270 DiffTarget :: WorkingDir => ( & self . index_wd , false ) ,
260271 } ;
261272
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+ }
266277 }
278+ None
267279 }
268280
269281 fn update_commands ( & mut self ) {
@@ -381,7 +393,7 @@ impl App {
381393 ) ) ;
382394 res. push ( CommandInfo :: new (
383395 commands:: STATUS_FOCUS_RIGHT ,
384- true ,
396+ self . can_focus_diff ( ) ,
385397 main_cmds_available && !focus_on_diff,
386398 ) ) ;
387399 }
0 commit comments