]> granicus.if.org Git - vim/commitdiff
patch 8.2.4551: when mapping <Esc> terminal codes are not recognized v8.2.4551
authorBram Moolenaar <Bram@vim.org>
Sat, 12 Mar 2022 13:48:39 +0000 (13:48 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 12 Mar 2022 13:48:39 +0000 (13:48 +0000)
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)

src/getchar.c
src/testdir/test_termcodes.vim
src/version.c

index 03d6d4d96d333ee8f8312e3206a807c04d7544a4..2bc7d9dd16de08db727b3312c63e9c2353dfc553 100644 (file)
@@ -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;
 
index a68506c1e6b526fea8904e22d97bbc33e1b77aed..76028e426fcd2292260b61bf3b7e32e835ee63bb 100644 (file)
@@ -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 = [
index d5b9380b595aa9f761f8ab7f7227690a332e6e67..13f5da3d764de24782de78b66d0d460f0423ac33 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4551,
 /**/
     4550,
 /**/