Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add g:which_key_floating_opts_explicit and g:which_key_floating_vars #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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