@@ -514,15 +514,25 @@ end
514514
515515function ProjectDiffScreen :focus_relative_buffer_entry (buffer )
516516 local filename = buffer :get_relative_name ()
517+ local last_entry_type = vim .b [buffer .bufnr ].vgit_last_entry_type
517518
518- -- Try to find current buffer's file, preferring unstaged
519+ -- Try to find current buffer's file
519520 if filename ~= ' ' then
521+ -- If we have a hint from last quit, prefer that entry type
522+ if last_entry_type then
523+ local list_item = self :move_to (function (status , entry_type )
524+ return status .filename == filename and entry_type == last_entry_type
525+ end )
526+ if list_item then return end
527+ end
528+
529+ -- Otherwise prefer unstaged
520530 local list_item = self :move_to (function (status , entry_type )
521531 return status .filename == filename and entry_type == ' unstaged'
522532 end )
523533 if list_item then return end
524534
525- -- Fall back to staged entry for this file
535+ -- Fall back to any entry for this file
526536 list_item = self :move_to (function (status )
527537 return status .filename == filename
528538 end )
@@ -833,12 +843,18 @@ function ProjectDiffScreen:on_quit()
833843 return false
834844 end
835845
846+ local entry = self .model :get_entry ()
836847 local file_lnum = self .diff_view :get_file_lnum ()
837848 loop .free_textlock ()
838849
839850 self :destroy ()
840851 fs .open (filepath )
841852
853+ -- Store entry type so re-opening returns to same entry
854+ if entry then
855+ vim .b .vgit_last_entry_type = entry .type
856+ end
857+
842858 if file_lnum then
843859 Window (0 ):set_lnum (file_lnum ):position_cursor (' center' )
844860 end
0 commit comments