Skip to content

Commit

Permalink
Add g:which_key_floating_opts_explicit and g:which_key_floating_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-descartes2021 committed Nov 30, 2022
1 parent 398adc5 commit 4af795b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
21 changes: 20 additions & 1 deletion autoload/which_key/window.vim
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ endfunction

function! s:show_popup(rows) abort
if !exists('s:popup_id')
let s:popup_id = popup_create([], {'highlight': 'WhichKeyFloating'})
let opts = {
\ 'highlight': 'WhichKeyFloating',
\ }
let opts = s:apply_custom_floating_opts(opts)
let s:popup_id = popup_create([], opts)
call popup_hide(s:popup_id)
call setbufvar(winbufnr(s:popup_id), '&filetype', 'which_key')
call win_execute(s:popup_id, 'setlocal nonumber nowrap')
if exists('g:which_key_floating_vars')
for [key, val] in items(g:which_key_floating_vars)
call setwinvar(s:popup_id, key, val)
endfor
endif
endif

let rows = s:append_prompt(a:rows)
Expand Down Expand Up @@ -91,6 +100,11 @@ function! s:apply_custom_floating_opts(opts) abort
endif
endfor
endif
if exists('g:which_key_floating_opts_explicit')
for [key, val] in items(g:which_key_floating_opts_explicit)
let opts[key] = val
endfor
endif
return opts
endfunction

Expand Down Expand Up @@ -135,6 +149,11 @@ function! s:show_floating_win(rows, layout) abort
call s:hide_cursor()
call setbufvar(s:bufnr, '&ft', 'which_key')
call setwinvar(s:floating_winid, '&winhl', 'Normal:WhichKeyFloating')
if exists('g:which_key_floating_vars')
for [key, val] in items(g:which_key_floating_vars)
call setwinvar(s:floating_winid, key, val)
endfor
endif
else
call nvim_win_set_config(s:floating_winid, opts)
endif
Expand Down
16 changes: 16 additions & 0 deletions doc/vim-which-key.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ or `-[number]` which means plus or minus `numberl` based on the default value
caculated by vim-which-key.
>
let g:which_key_floating_opts = { 'row': '-1' }
<
*g:which_key_floating_opts_explicit*
Type: |Dict|
Default: `Undefined`

You can use this option to pass explicit {options} to |popup_create| or |nvim_open_win|. For example to change the borders:
>
let g:which_key_floating_opts_explicit = { 'border': 'shadow' }
<
*g:which_key_floating_vars*
Type: |Dict|
Default: `Undefined`

You can use this option to set variables on the floating window. For example to make the window transparent (Neovim only):
>
let g:which_key_floating_vars = { '&winblend': '30' }
<
*g:which_key_run_map_on_popup*
Type: |Number|
Expand Down

0 comments on commit 4af795b

Please sign in to comment.