Fix enabling buffer when plugin disabled

Fixes #803.
This commit is contained in:
Andy Stewart
2022-02-02 10:58:53 +00:00
parent 54b94f98de
commit 23a65f370b
2 changed files with 24 additions and 13 deletions

View File

@@ -21,6 +21,10 @@ endfunction
function! gitgutter#process_buffer(bufnr, force) abort function! gitgutter#process_buffer(bufnr, force) abort
" NOTE a:bufnr is not necessarily the current buffer. " NOTE a:bufnr is not necessarily the current buffer.
if gitgutter#utility#getbufvar(a:bufnr, 'enabled', -1) == -1
call gitgutter#utility#setbufvar(a:bufnr, 'enabled', g:gitgutter_enabled)
endif
if gitgutter#utility#is_active(a:bufnr) if gitgutter#utility#is_active(a:bufnr)
if has('patch-7.4.1559') if has('patch-7.4.1559')
@@ -55,12 +59,11 @@ endfunction
function! gitgutter#disable() abort function! gitgutter#disable() abort
" get list of all buffers (across all tabs)
for bufnr in range(1, bufnr('$') + 1) for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr) if buflisted(bufnr)
let file = expand('#'.bufnr.':p') let file = expand('#'.bufnr.':p')
if !empty(file) if !empty(file)
call s:clear(bufnr) call gitgutter#buffer_disable(bufnr)
endif endif
endif endif
endfor endfor
@@ -69,8 +72,16 @@ function! gitgutter#disable() abort
endfunction endfunction
function! gitgutter#enable() abort function! gitgutter#enable() abort
for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr)
let file = expand('#'.bufnr.':p')
if !empty(file)
call gitgutter#buffer_enable(bufnr)
endif
endif
endfor
let g:gitgutter_enabled = 1 let g:gitgutter_enabled = 1
call gitgutter#all(1)
endfunction endfunction
function! gitgutter#toggle() abort function! gitgutter#toggle() abort
@@ -82,23 +93,24 @@ function! gitgutter#toggle() abort
endfunction endfunction
function! gitgutter#buffer_disable() abort function! gitgutter#buffer_disable(...) abort
let bufnr = bufnr('') let bufnr = a:0 ? a:1 : bufnr('')
call gitgutter#utility#setbufvar(bufnr, 'enabled', 0) call gitgutter#utility#setbufvar(bufnr, 'enabled', 0)
call s:clear(bufnr) call s:clear(bufnr)
endfunction endfunction
function! gitgutter#buffer_enable() abort function! gitgutter#buffer_enable(...) abort
let bufnr = bufnr('') let bufnr = a:0 ? a:1 : bufnr('')
call gitgutter#utility#setbufvar(bufnr, 'enabled', 1) call gitgutter#utility#setbufvar(bufnr, 'enabled', 1)
call gitgutter#process_buffer(bufnr, 1) call gitgutter#process_buffer(bufnr, 1)
endfunction endfunction
function! gitgutter#buffer_toggle() abort function! gitgutter#buffer_toggle(...) abort
if gitgutter#utility#getbufvar(bufnr(''), 'enabled', 1) let bufnr = a:0 ? a:1 : bufnr('')
call gitgutter#buffer_disable() if gitgutter#utility#getbufvar(bufnr, 'enabled', 1)
call gitgutter#buffer_disable(bufnr)
else else
call gitgutter#buffer_enable() call gitgutter#buffer_enable(bufnr)
endif endif
endfunction endfunction

View File

@@ -48,8 +48,7 @@ endfunction
" Returns truthy when the buffer's file should be processed; and falsey when it shouldn't. " Returns truthy when the buffer's file should be processed; and falsey when it shouldn't.
" This function does not and should not make any system calls. " This function does not and should not make any system calls.
function! gitgutter#utility#is_active(bufnr) abort function! gitgutter#utility#is_active(bufnr) abort
return g:gitgutter_enabled && return gitgutter#utility#getbufvar(a:bufnr, 'enabled') &&
\ gitgutter#utility#getbufvar(a:bufnr, 'enabled', 1) &&
\ !pumvisible() && \ !pumvisible() &&
\ s:is_file_buffer(a:bufnr) && \ s:is_file_buffer(a:bufnr) &&
\ s:exists_file(a:bufnr) && \ s:exists_file(a:bufnr) &&