]> granicus.if.org Git - vim/commitdiff
patch 8.2.4588: mapping with key after other matching mapping does not work v8.2.4588
authorBram Moolenaar <Bram@vim.org>
Fri, 18 Mar 2022 15:41:17 +0000 (15:41 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 18 Mar 2022 15:41:17 +0000 (15:41 +0000)
Problem:    Mapping with key code after other matching mapping does not work.
Solution:   Change ">" to ">=". (closes #9903)

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

index 2bc7d9dd16de08db727b3312c63e9c2353dfc553..505d5a979e3eff640aba4e662fc3523623448804 100644 (file)
@@ -2416,6 +2416,7 @@ handle_mapping(
     mapblock_T *mp_match;
     int                mp_match_len = 0;
     int                max_mlen = 0;
+    int                want_termcode = 0;  // 1 if termcode expected after max_mlen
     int                tb_c1;
     int                mlen;
 #ifdef FEAT_LANGMAP
@@ -2591,9 +2592,16 @@ handle_mapping(
                }
                else
                    // No match; may have to check for termcode at next
-                   // character.
+                   // character.  If the first character that didn't match is
+                   // K_SPECIAL then check for a termcode.  This isn't perfect
+                   // but should work in most cases.
                    if (max_mlen < mlen)
+                   {
                        max_mlen = mlen;
+                       want_termcode = mp->m_keys[mlen] == K_SPECIAL;
+                   }
+                   else if (max_mlen == mlen && mp->m_keys[mlen] == K_SPECIAL)
+                       want_termcode = 1;
            }
        }
 
@@ -2646,7 +2654,7 @@ handle_mapping(
     // 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
+    if ((mp == NULL || max_mlen + want_termcode > mp_match_len
                    || (mp_match_len == 1 && *mp->m_keys == ESC && !*timedout))
            && keylen != KEYLEN_PART_MAP)
     {
index 76028e426fcd2292260b61bf3b7e32e835ee63bb..66191722882b5a80292a5c7c701c933f2d7c3cd6 100644 (file)
@@ -2111,6 +2111,15 @@ func Test_modifyOtherKeys_ambiguous_mapping()
 
   unmap <C-J>
   unmap <C-J>x
+
+  " if a special character is following there should be a check for a termcode
+  nnoremap s aX<Esc>
+  nnoremap s<BS> aY<Esc>
+  set t_kb=\b
+  call setline(1, 'x')
+  call feedkeys("s\x08", 'Lx!')
+  call assert_equal('xY', getline(1))
+
   set timeoutlen&
   bwipe!
 endfunc
index 5cb21e832f3b48add4e37bab0ea5b1dd3fef1e7d..6c59f951c5b202d41a9f9436c1cab14c9441ebf1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4588,
 /**/
     4587,
 /**/