From 95f8ad710e7fba0919a9dbdd3043862affae342e Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 14 Mar 2017 13:16:19 +0100 Subject: [PATCH] smart cursor position when no previous file ref #125 --- plugin/magit.vim | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 2e1adcc..d1c5180 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -791,6 +791,17 @@ function! magit#show_magit(display, ...) call magit#update_buffer() + function! s:jump_first_file() + let unstaged_files = b:state.get_files_ordered('unstaged') + if ( !empty(unstaged_files) ) + call cursor(unstaged_files[0].line_pos, 0) + else + let staged_files = b:state.get_files_ordered('staged') + if ( !empty(staged_files) ) + call cursor(staged_files[0].line_pos, 0) + endif + endif + endfunction " move cursor to (in priority order if not found): " - current file unstaged " - current file staged @@ -807,17 +818,11 @@ function! magit#show_magit(display, ...) let file = b:state.get_file('staged', cur_file, 0) call cursor(file.line_pos, 0) catch 'file_doesnt_exists' - let unstaged_files = b:state.get_files_ordered('unstaged') - if ( !empty(unstaged_files) ) - call cursor(unstaged_files[0].line_pos, 0) - else - let staged_files = b:state.get_files_ordered('staged') - if ( !empty(staged_files) ) - call cursor(staged_files[0].line_pos, 0) - endif - endif + call s:jump_first_file() endtry endtry + else + call s:jump_first_file() endif endfunction