Add middle click to close buffer functionality

Extended the left click to switch buffer functionality to also
support middle click to delete buffer

documentation of clickable buffers
This commit is contained in:
Duncan Williams 2016-04-07 11:46:46 +01:00 committed by Duncan
parent 377010ea6e
commit 0c251e20a7
2 changed files with 18 additions and 5 deletions

View File

@ -73,7 +73,7 @@ function! airline#extensions#tabline#buffers#get()
" Neovim feature: Have clickable buffers
if has("tablineat")
call b.add_raw('%'.nr.'@airline#extensions#tabline#buffers#switchbuf@')
call b.add_raw('%'.nr.'@airline#extensions#tabline#buffers#clickbuf@')
endif
if s:buffer_idx_mode
if len(s:number_map) > 0
@ -196,10 +196,18 @@ function s:map_keys()
endif
endfunction
function airline#extensions#tabline#buffers#switchbuf(minwid, clicks, button, modifiers) abort
" Run the following code only on a single left mouse button click without modifiers pressed
function airline#extensions#tabline#buffers#clickbuf(minwid, clicks, button, modifiers) abort
" Clickable buffers
" works only in recent NeoVim with has('tablineat')
if a:clicks == 1 && a:button is# 'l' && a:modifiers !~# '[^ ]'
sil execute 'buffer' a:minwid
" single mouse button click without modifiers pressed
if a:clicks == 1 && a:modifiers !~# '[^ ]'
if a:button is# 'l'
" left button - switch to buffer
silent execute 'buffer' a:minwid
elseif a:button is# 'm'
" middle button - delete buffer
silent execute 'bdelete' a:minwid
endif
endif
endfunction

View File

@ -508,6 +508,11 @@ are supported!
* enable/disable displaying buffers with a single tab. (c)
let g:airline#extensions#tabline#show_buffers = 1
<
Note: If you are using neovim (has('tablineat') = 1), then you can click
on the tabline with the left mouse button to switch to that buffer, and
with the middle mouse button to delete that buffer.
* enable/disable displaying tabs, regardless of number. (c)
let g:airline#extensions#tabline#show_tabs = 1
<