Skip to content

Commit

Permalink
Merge pull request #430 from lambdalisue/use-winbar
Browse files Browse the repository at this point in the history
Use `winbar` instead when `winbar` is available and `laststatus=3`
  • Loading branch information
lambdalisue authored Jun 13, 2022
2 parents 305d644 + 1f01f09 commit 951a05d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions autoload/fern/internal/window.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ function! fern#internal#window#select() abort
\ 'select_chars': g:fern#internal#window#select_chars,
\ 'statusline_hl': 'FernWindowSelectStatusLine',
\ 'indicator_hl': 'FernWindowSelectIndicator',
\ 'use_winbar': g:fern#internal#window#use_winbar,
\})
endfunction

call s:Config.config(expand('<sfile>:p'), {
\ 'auto_select': 1,
\ 'select_chars': split('abcdefghijklmnopqrstuvwxyz', '\zs'),
\ 'use_winbar': exists('&winbar') && &laststatus is# 3,
\})

function! s:highlight() abort
Expand Down
21 changes: 17 additions & 4 deletions autoload/vital/_fern/App/WindowSelector.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ function! s:select(winnrs, ...) abort
\ 'select_chars': split('abcdefghijklmnopqrstuvwxyz', '\zs'),
\ 'statusline_hl': 'VitalWindowSelectorStatusLine',
\ 'indicator_hl': 'VitalWindowSelectorIndicator',
\ 'winbar_hl': 'VitalWindowSelectorWinBar',
\ 'use_winbar': &laststatus is# 3 && exists('&winbar'),
\}, a:0 ? a:1 : {})
if !options.use_winbar && &laststatus is# 3
echohl WarningMsg
echomsg 'vital: App.WindowSelector: The laststatus=3 on Neovim requires winbar feature to show window indicator'
echohl None
endif
if options.auto_select && len(a:winnrs) <= 1
call win_gotoid(len(a:winnrs) ? win_getid(a:winnrs[0]) : win_getid())
return 0
endif
let target = options.use_winbar ? '&winbar' : '&statusline'
let length = len(a:winnrs)
let store = {}
for winnr in a:winnrs
let store[winnr] = getwinvar(winnr, '&statusline')
let store[winnr] = getwinvar(winnr, target)
endfor
try
let scs = options.select_chars
Expand All @@ -30,10 +38,12 @@ function! s:select(winnrs, ...) abort
\ { _, v -> get(scs, v, string(v)) },
\)
let l:S = funcref('s:_statusline', [
\ options.statusline_hl,
\ options.use_winbar
\ ? options.winbar_hl
\ : options.statusline_hl,
\ options.indicator_hl,
\])
call map(keys(store), { k, v -> setwinvar(v, '&statusline', S(v, chars[k])) })
call map(keys(store), { k, v -> setwinvar(v, target, S(v, chars[k])) })
redrawstatus
call s:_cnoremap_all(chars)
let n = input('choose window: ')
Expand All @@ -48,7 +58,7 @@ function! s:select(winnrs, ...) abort
endif
call win_gotoid(win_getid(a:winnrs[n]))
finally
call map(keys(store), { _, v -> setwinvar(v, '&statusline', store[v]) })
call map(keys(store), { _, v -> setwinvar(v, target, store[v]) })
redrawstatus
endtry
endfunction
Expand Down Expand Up @@ -87,6 +97,9 @@ endfunction
function! s:_highlight() abort
highlight default link VitalWindowSelectorStatusLine StatusLineNC
highlight default link VitalWindowSelectorIndicator DiffText
if exists('&winbar')
highlight default link VitalWindowSelectorWinBar WinBarNC
endif
endfunction

augroup vital_app_window_selector_internal
Expand Down

0 comments on commit 951a05d

Please sign in to comment.