Skip to content

Commit 89ed871

Browse files
author
Fabian Wermelinger
committed
Manage active buffers for edit command in state dictionary
Adds an additional 'active_buffers' dictionary to the state dictionary for tracking of possibly multiple buffers for the edit command. The 'active_buffers' dictionary has the buffer ID as key and associated file as value. The function s:RunEdit initializes the dictionary and s:RunBufDelete modifies its state.
1 parent 0ae7c0f commit 89ed871

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

autoload/fugitive.vim

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,9 +3443,9 @@ function! s:RunEdit(state, tmp, job) abort
34433443
endif
34443444
call remove(a:state, 'request')
34453445
let sentinel = a:state.file . '.edit'
3446-
let files = readfile(sentinel, '')
3447-
call writefile([len(files)], sentinel)
3448-
for file in reverse(files)
3446+
let active_buffers = {}
3447+
let buf_sequence = []
3448+
for file in readfile(sentinel, '')
34493449
let file = FugitiveVimPath(file)
34503450
try
34513451
if !&equalalways && a:state.mods !~# '\<\d*tab\>' && 3 > (a:state.mods =~# '\<vert' ? winwidth(0) : winheight(0))
@@ -3462,6 +3462,8 @@ function! s:RunEdit(state, tmp, job) abort
34623462
set bufhidden=wipe
34633463
call s:InitializeBuffer(a:state)
34643464
let bufnr = bufnr('')
3465+
call add(buf_sequence, bufnr)
3466+
let active_buffers[bufnr] = file
34653467
let s:edit_jobs[bufnr] = [a:state, a:tmp, a:job, sentinel]
34663468
call fugitive#DidChange(a:state.git_dir)
34673469
if bufnr == bufnr('') && !exists('g:fugitive_event')
@@ -3474,6 +3476,8 @@ function! s:RunEdit(state, tmp, job) abort
34743476
endtry
34753477
endif
34763478
endfor
3479+
let a:state['active_buffers'] = active_buffers
3480+
call win_gotoid(bufwinid(buf_sequence[0]))
34773481
return 1
34783482
endfunction
34793483

@@ -3626,10 +3630,10 @@ if !exists('s:edit_jobs')
36263630
let s:edit_jobs = {}
36273631
endif
36283632
function! s:RunWait(state, tmp, job, ...) abort
3633+
if has_key(a:state, 'active_buffers')
3634+
return ''
3635+
endif
36293636
if a:0 && filereadable(a:1)
3630-
if a:0 > 1 && a:2 > 0
3631-
return ''
3632-
endif
36333637
call delete(a:1)
36343638
endif
36353639
try
@@ -3732,15 +3736,18 @@ function! s:RunBufDelete(bufnr) abort
37323736
endif
37333737
if has_key(s:edit_jobs, a:bufnr) |
37343738
call add(s:resume_queue, remove(s:edit_jobs, a:bufnr))
3735-
let sentinel = s:resume_queue[-1][0].file . '.edit'
3736-
let active_buffers = str2nr(readfile(sentinel, '', 1)[0]) - 1
3737-
call add(s:resume_queue[-1], active_buffers)
3738-
if active_buffers < 1
3739-
call feedkeys("\<C-\>\<C-N>:redraw!|call delete(" . string(sentinel) .
3740-
\ ")|call fugitive#Resume()|checktime\r", 'n')
3741-
else
3742-
call writefile([active_buffers], sentinel)
3739+
let state = s:resume_queue[-1][0]
3740+
if has_key(state, 'active_buffers')
3741+
call remove(state.active_buffers, a:bufnr)
3742+
if !len(state.active_buffers)
3743+
call remove(state, 'active_buffers')
3744+
endif
3745+
endif
3746+
if has_key(state, 'active_buffers')
37433747
call fugitive#Resume()
3748+
else
3749+
call feedkeys("\<C-\>\<C-N>:redraw!|call delete(" . string(state.file . '.edit') .
3750+
\ ")|call fugitive#Resume()|checktime\r", 'n')
37443751
endif
37453752
endif
37463753
endfunction

0 commit comments

Comments
 (0)