Skip to content

Commit

Permalink
Add group_dicts_together_option (#192)
Browse files Browse the repository at this point in the history
* Add which_key_group_dicts_together option

Make separating single key (leaves) and dicts mappings configurable.
Also add an option to configure what is shown first leaves or dicts.

* Add docs for which_key_group_dicts_together option

* Combine group_dicts_at and group_dicts_together

As suggested in PR, combined two bool options into one of a type string
And updated docs.

* Change tabs to spaces

Close #191
  • Loading branch information
BrotifyPacha authored Apr 22, 2021
1 parent 7fdff16 commit 20163f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
29 changes: 21 additions & 8 deletions autoload/which_key/renderer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,30 @@ function! s:create_rows(layout, mappings) abort
let row = 0
let col = 0

let leaf_keys = []
let dict_keys = []
for key in sort(filter(keys(mappings), 'v:val !=# "name"'), 'i')
if type(mappings[key]) == s:TYPE.dict
call add(dict_keys, key)
" Separate leaves and dict keys depending on which_key_group_dicts_together
if exists('g:which_key_group_dicts') && g:which_key_group_dicts != ''

let leaf_keys = []
let dict_keys = []

for key in sort(filter(keys(mappings), 'v:val !=# "name"'), 'i')
if type(mappings[key]) == s:TYPE.dict
call add(dict_keys, key)
else
call add(leaf_keys, key)
endif
endfor

" Decide what's shown first leaves or dicts
if g:which_key_group_dicts ==? 'end'
let smap = leaf_keys + dict_keys
else
call add(leaf_keys, key)
let smap = dict_keys + leaf_keys
endif
endfor

let smap = leaf_keys + dict_keys
else
let smap = sort(filter(keys(mappings), 'v:val !=# "name"'), 'i')
endif

let displaynames = which_key#renderer#get_displaynames()
if get(g:, 'which_key_align_by_seperator', 1)
Expand Down
12 changes: 12 additions & 0 deletions doc/vim-which-key.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ Possible value: `{0, 1}` .
let g:which_key_centered = 0
<

*g:which_key_group_dicts*
Type: |String|
Default: `end`

Separate key and dictionary bindings, placing all the dictionary items
accordingly. Set this option to empty string if you want to sort all which-key
items alphabetically in spite of their type.
Possible value: `{'', 'start', 'end'}` .
>
let g:which_key_group_dicts = 'end'
<

==============================================================================
COMMANDS *vim-which-key-commands*

Expand Down
1 change: 1 addition & 0 deletions plugin/which_key.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let g:which_key_max_size = get(g:, 'which_key_max_size', 0)
let g:which_key_vertical = get(g:, 'which_key_vertical', 0)
let g:which_key_position = get(g:, 'which_key_position', 'botright')
let g:which_key_centered = get(g:, 'which_key_centered', 1)
let g:which_key_group_dicts = get(g:, 'which_key_group_dicts', 'end')
let g:which_key_sort_horizontal = get(g:, 'which_key_sort_horizontal', 0)
let g:which_key_run_map_on_popup = get(g:, 'which_key_run_map_on_popup', 1)
let g:which_key_align_by_seperator = get(g:, 'which_key_align_by_seperator', 1)
Expand Down

0 comments on commit 20163f6

Please sign in to comment.