Skip to content

Commit

Permalink
Handle special keys in the mapping properly (#240)
Browse files Browse the repository at this point in the history
* Convert "\<Tab>" to "<Tab>"

The mapping `<Tab>` is tracked in the mappings in String form, while the
returned value from `getchar()` is a Number, convert it to String
manually so that the corresponding entry in `s:runtime` can be
retrieved.

Close #135

* Handle more special keys properly

Part of #232, Thanks to @rene-descartes2021
  • Loading branch information
liuchengxu authored Aug 13, 2023
1 parent ea87707 commit a98626b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions autoload/which_key.vim
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ function! s:show_upper_level_mappings() abort
endfunction

function! s:getchar() abort
let input = ''
try
let c = getchar()
" Handle <C-C>
Expand All @@ -290,13 +289,8 @@ function! s:getchar() abort
return ''
endif

" :h keycode
" <CR>, <Enter>
if c == 13
return '<CR>'
endif
let input = which_key#char_handler#parse_raw(c)

let input .= which_key#char_handler#parse_raw(c)
if s:has_children(input)
while 1
if !which_key#char_handler#timeout_for_next_char()
Expand All @@ -306,6 +300,15 @@ function! s:getchar() abort
endif
endwhile
endif

" Convert special keys to internal data structure that use String as the
" key, e.g., "\<Tab>" => "<Tab>"
if has_key(s:KEYCODES, input)
let input = s:KEYCODES[input]
elseif has_key(s:MERGE_INTO, input)
let input = s:MERGE_INTO[input]
endif

return input
endfunction

Expand Down

0 comments on commit a98626b

Please sign in to comment.