diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d45587..835fa421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ This is the Changelog for the vim-airline project. - Display executable symbol for executable script - Support for Neovims global statusline - whitespace extensions: add git conflict marker support - - Support tabpanel (Vim only) + - Support tabpanel, including mouse and scroll support (Vim only) - Support multi-line statusline (Vim only) - Support clickable buffers in Vim - Support for showing `repo:/path/file` path like style using the `gitrepo` style diff --git a/autoload/airline/extensions/tabpanel.vim b/autoload/airline/extensions/tabpanel.vim index cd4d6819..cc92be31 100644 --- a/autoload/airline/extensions/tabpanel.vim +++ b/autoload/airline/extensions/tabpanel.vim @@ -6,6 +6,7 @@ vim9script scriptencoding utf-8 var spc = g:airline_symbols.space +var mouse_support = has('patch-9.2.0386') def IsTabModified(tabnr: number): bool if !g:airline_detect_modified @@ -51,15 +52,43 @@ export def Get(): string endif endif + if mouse_support + label ..= '%' .. tabnr .. '[airline#extensions#tabpanel#ClickTab]' + endif + if get(g:, 'airline#extensions#tabline#show_tab_nr', 1) label ..= spc .. tabnr label ..= spc endif label ..= title .. spc + + if mouse_support + label ..= '%[]' + endif return label enddef +export def ClickTab(info: dict): number + if info.nclicks != 1 || !empty(info.mods) + return 0 + endif + if info.button ==# 'l' + try + silent execute 'tabnext' info.minwid + catch + airline#util#warning('Cannot switch tab') + endtry + elseif info.button ==# 'm' + try + silent execute 'tabclose' info.minwid + catch + airline#util#warning('Cannot close tab') + endtry + endif + return 0 +enddef + def LinkHighlights(): void highlight! link TabPanelFill airline_tabfill highlight! link TabPanelSel airline_tabsel @@ -77,10 +106,19 @@ def Enable(): void &tabpanel = '%!airline#extensions#tabpanel#Get()' var cols = get(g:, 'airline#extensions#tabpanel#columns', 20) var align = get(g:, 'airline#extensions#tabpanel#align', '') + var scroll = get(g:, 'airline#extensions#tabpanel#scroll', 1) + var scrollbar = get(g:, 'airline#extensions#tabpanel#scrollbar', 1) var opts = 'columns:' .. cols if !empty(align) opts ..= ',align:' .. align endif + if mouse_support + if scrollbar + opts ..= ',scrollbar' + elseif scroll + opts ..= ',scroll' + endif + endif &tabpanelopt = opts &showtabpanel = 2 enddef diff --git a/doc/airline.txt b/doc/airline.txt index 26d305c7..a0033a1f 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -1485,12 +1485,27 @@ Vim >9.1.1391). let g:airline#extensions#tabpanel#align = 'left' < default: '' (uses Vim's default) +* enable mouse wheel scrolling over the tabpanel area when the tab list + exceeds the visible screen height (requires Vim patch 9.2.386) > + let g:airline#extensions#tabpanel#scroll = 1 +< default: 0 + +* reserve a one-column scrollbar in the tabpanel showing the current scroll + position; clicking or dragging the thumb jumps to that position (requires + Vim patch 9.2.386; implies scroll) > + let g:airline#extensions#tabpanel#scrollbar = 1 +< default: 0 + Note: The tabpanel extension reuses the tabline highlight groups (|airline-tabline-hlgroups|) and respects the tabline tab number settings (|g:airline#extensions#tabline#show_tab_nr|, |g:airline#extensions#tabline#tab_nr_type|, |g:airline#extensions#tabline#tabnr_formatter|). +Note: Starting with Vim v9.2.0386 Vim adds mouse support for the tabpanel +and each tab entry is clickable: a left mouse click switches to the tab and a +middle click closes it, however 'mouse' setting needs to be enabled. + ------------------------------------- *airline-scrollbar* Displays an Ascii Scrollbar for active windows with a width > 200.