summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-12 13:48:39 +0000
committerBram Moolenaar <Bram@vim.org>2022-03-12 13:48:39 +0000
commitbbf84e2737daf3479e059dc7e7da0c50a07a4bf4 (patch)
tree80ad31a06acef5745f0d4e11259784c5d52d56ae
parent5b4f8a0e8476d57ee8a48e45171d19c1d2b4154e (diff)
patch 8.2.4551: when mapping <Esc> terminal codes are not recognizedv8.2.4551
Problem: When mapping <Esc> terminal codes are not recognized. Solution: Specifically recognize a mapping with just <Esc> and check for terminal codes even though there is no partial mapping. (closes #9903)
-rw-r--r--src/getchar.c7
-rw-r--r--src/testdir/test_termcodes.vim16
-rw-r--r--src/version.c2
3 files changed, 24 insertions, 1 deletions
diff --git a/src/getchar.c b/src/getchar.c
index 03d6d4d96d..2bc7d9dd16 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -2643,7 +2643,12 @@ handle_mapping(
max_mlen = mlen + 1;
}
- if ((mp == NULL || max_mlen > mp_match_len) && keylen != KEYLEN_PART_MAP)
+ // May check for a terminal code when there is no mapping or only a partial
+ // mapping. Also check if there is a full mapping with <Esc>, unless timed
+ // out, since that is nearly always a partial match with a terminal code.
+ if ((mp == NULL || max_mlen > mp_match_len
+ || (mp_match_len == 1 && *mp->m_keys == ESC && !*timedout))
+ && keylen != KEYLEN_PART_MAP)
{
int save_keylen = keylen;
diff --git a/src/testdir/test_termcodes.vim b/src/testdir/test_termcodes.vim
index a68506c1e6..76028e426f 100644
--- a/src/testdir/test_termcodes.vim
+++ b/src/testdir/test_termcodes.vim
@@ -2331,6 +2331,22 @@ func Test_cmdline_literal()
set timeoutlen&
endfunc
+func Test_mapping_esc()
+ set timeoutlen=10
+
+ new
+ nnoremap <Up> iHello<Esc>
+ nnoremap <Esc> <Nop>
+
+ call feedkeys(substitute(&t_ku, '\*', '', 'g'), 'Lx!')
+ call assert_equal("Hello", getline(1))
+
+ bwipe!
+ nunmap <Up>
+ nunmap <Esc>
+ set timeoutlen&
+endfunc
+
" Test for translation of special key codes (<xF1>, <xF2>, etc.)
func Test_Keycode_Translation()
let keycodes = [
diff --git a/src/version.c b/src/version.c
index d5b9380b59..13f5da3d76 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4551,
+/**/
4550,
/**/
4549,