Skip to content

Commit dde6a66

Browse files
committed
Fix regression around escape sequences
We mapped esc to cancel the prompt, but when using Vim (not an issue in Nvim due to its proper key parsing via libtermkey), even arrow keys would cancel the prompt because they emit sequences like \eOA, \eOB, etc. Now we reverse the logic. The default mode is to cancel the prompt unless <cr> (or the equivalent <c-m>) is typed. This was once fixed in mhinz@2271e35 but regressed when we removed the need for magic strings. Fixes mhinz#221
1 parent d8fa51d commit dde6a66

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

plugin/grepper.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,13 @@ function! s:prompt(flags)
761761
endif
762762

763763
" Store original mappings
764-
let mapping_esc = maparg('<esc>', 'c', '', 1)
764+
let mapping_cr = maparg('<cr>', 'c', '', 1)
765765
let mapping_tool = maparg(get(g:grepper, 'next_tool', g:grepper.prompt_mapping_tool), 'c', '', 1)
766766
let mapping_dir = maparg(g:grepper.prompt_mapping_dir, 'c', '', 1)
767767
let mapping_side = maparg(g:grepper.prompt_mapping_side, 'c', '', 1)
768768

769769
" Set plugin-specific mappings
770-
cnoremap <silent> <esc> <c-\>e<sid>set_prompt_op('cancelled')<cr><c-c>
770+
cnoremap <silent> <cr> <c-\>e<sid>set_prompt_op('cr')<cr><cr>
771771
execute 'cnoremap <silent>' g:grepper.prompt_mapping_tool "\<c-\>e\<sid>set_prompt_op('flag_tool')<cr><cr>"
772772
execute 'cnoremap <silent>' g:grepper.prompt_mapping_dir "\<c-\>e\<sid>set_prompt_op('flag_dir')<cr><cr>"
773773
execute 'cnoremap <silent>' g:grepper.prompt_mapping_side "\<c-\>e\<sid>set_prompt_op('flag_side')<cr><cr>"
@@ -793,7 +793,7 @@ function! s:prompt(flags)
793793
" 'flag_dir': don't start searching; toggle -dir flag
794794
" 'flag_side': don't start searching; toggle -side flag
795795
" 'cr': start searching
796-
let s:prompt_op = 'cr'
796+
let s:prompt_op = 'cancelled'
797797

798798
echohl GrepperPrompt
799799
call inputsave()
@@ -816,11 +816,11 @@ function! s:prompt(flags)
816816
redraw!
817817

818818
" Restore mappings
819-
cunmap <esc>
819+
cunmap <cr>
820820
execute 'cunmap' g:grepper.prompt_mapping_tool
821821
execute 'cunmap' g:grepper.prompt_mapping_dir
822822
execute 'cunmap' g:grepper.prompt_mapping_side
823-
call s:restore_mapping(mapping_esc)
823+
call s:restore_mapping(mapping_cr)
824824
call s:restore_mapping(mapping_tool)
825825
call s:restore_mapping(mapping_dir)
826826
call s:restore_mapping(mapping_side)

0 commit comments

Comments
 (0)