Skip to content

Commit

Permalink
Remove redundant loop in s:getchar()
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-descartes2021 committed Dec 13, 2022
1 parent c0eb7a6 commit 2c615f4
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions autoload/which_key.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ let s:MERGE_INTO = {
\ '<Bslash>': '\',
\ '<Bar>': '|'
\ }
let s:REQUIRES_REGEX_ESCAPE = ['$', '*', '~', '.']

let g:which_key#TYPE = s:TYPE

Expand Down Expand Up @@ -215,15 +214,6 @@ function! s:echo_prompt() abort
echohl None
endfunction

function! s:has_children(input) abort
if index(s:REQUIRES_REGEX_ESCAPE, a:input) != -1
let group = map(keys(s:runtime), {_,v -> v =~# '^\'.a:input})
else
let group = map(keys(s:runtime), {_,v -> v =~# '^'.a:input})
endif
return len(filter(group, 'v:val == 1')) > 1
endfunction

function! s:show_upper_level_mappings() abort
" Top level
if empty(s:last_runtime_stack)
Expand All @@ -244,7 +234,6 @@ function! s:show_upper_level_mappings() abort
endfunction

function! s:getchar() abort
let input = ''
try
let c = getchar()
" Handle <C-C>
Expand Down Expand Up @@ -272,17 +261,14 @@ function! s:getchar() abort
return '<CR>'
endif

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()
let input .= which_key#char_handler#parse_raw(getchar())
else
break
endif
endwhile
let c = which_key#char_handler#parse_raw(c)
if has_key(s:KEYCODES, c)
let c = s:KEYCODES[c]
endif
if has_key(s:MERGE_INTO, c)
let c = s:MERGE_INTO[c]
endif
return input
return c
endfunction

function! which_key#wait_for_input() " {{{
Expand Down

0 comments on commit 2c615f4

Please sign in to comment.