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

Remove redundant loop in s:getchar() #232

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop was introduced to distinguish the mappings like gc and gcc as initially reported in #3, I guess it's still useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok I wasn't completely sure what was going on so I left this as a draft till I could figure things out better.

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has been incorporated into #240, thank you!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

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