From e863411b2010e74366c0c4a50faf4807e868d744 Mon Sep 17 00:00:00 2001 From: Rene Descartes Date: Wed, 30 Nov 2022 12:15:09 -0700 Subject: [PATCH] Add g:which_key_floating_opts_explicit and g:which_key_floating_vars --- autoload/which_key/window.vim | 21 ++++++++++++++++++++- doc/vim-which-key.txt | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/autoload/which_key/window.vim b/autoload/which_key/window.vim index 58a6fa1..ef36ac6 100644 --- a/autoload/which_key/window.vim +++ b/autoload/which_key/window.vim @@ -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) @@ -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 @@ -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 diff --git a/doc/vim-which-key.txt b/doc/vim-which-key.txt index 107ff8e..8adb59d 100644 --- a/doc/vim-which-key.txt +++ b/doc/vim-which-key.txt @@ -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|