]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0611: ambiguous mappings not correctly resolved with modifyOtherKeys v9.1.0611
authorOleg Goncharov <goncharovoi@yandex.ru>
Tue, 23 Jul 2024 18:34:15 +0000 (20:34 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 23 Jul 2024 18:42:02 +0000 (20:42 +0200)
Problem:  ambiguous mappings not correctly resolved with modifyOtherKeys
Solution: Check for termcode when an upper case mapping is received and
          does not match (Oleg Goncharov)

Fix for mapping processing when capital leters are represented with terminal codes.

Problem: there are two mappings and
1) the first mapping is substring of the second,
2) the first non-matching letter is capital,
3) capital letters are represented with termcodes "ESC[27;2;<ascii code>~" in given system
then first mapping is applied instead of second.

Example:

    :map B b
    :map BBB blimp!

and then

    BBB -> bbb

instead of

    BBB -> blimp!

Solution: force termcodes check if capital letter does not match.

closes: #15251

Signed-off-by: Oleg Goncharov <goncharovoi@yandex.ru>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/getchar.c
src/testdir/test_termcodes.vim
src/testdir/view_util.vim
src/version.c

index df89f4cd2f3b6e473a0f4e0788e972d2a5d9bbff..4af176978c8f8e14eb3fbda51c3757403a216e17 100644 (file)
@@ -2935,8 +2935,11 @@ handle_mapping(
                    }
                }
                else
+               {
                    // No match; may have to check for termcode at next
-                   // character.  If the first character that didn't match is
+                   // 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)
@@ -2946,6 +2949,12 @@ handle_mapping(
                    }
                    else if (max_mlen == mlen && mp->m_keys[mlen] == K_SPECIAL)
                        want_termcode = 1;
+
+                   // Check termcode for uppercase character to properly
+                   // process "ESC[27;2;<ascii code>~" control sequences.
+                   if (ASCII_ISUPPER(mp->m_keys[mlen]))
+                       want_termcode = 1;
+               }
            }
        }
 
index 7e450d998db7dfcc0636628c6adb1719c12238ab..507753c21a7736ef550ac3df91502d66eddbd2a2 100644 (file)
@@ -2256,6 +2256,17 @@ func Test_modifyOtherKeys_mapped()
 
   iunmap '
   iunmap <C-W><C-A>
+
+  " clean buffer
+  %d _
+  imap B b
+  imap BBB blimp
+  let input = repeat(GetEscCodeCSI27('B', 2), 3)
+  call feedkeys("a" .. input .. "\<Esc>", 'Lx!')
+  call assert_equal('blimp', getline(1))
+  " cleanup
+  iunmap BBB
+  iunmap B
   set timeoutlen&
 endfunc
 
index 71cb071ab75faf1765742b213d874578301ed398..161c8b20cdf3077f871576abd54a16ea8383633b 100644 (file)
@@ -71,7 +71,7 @@ endfunc
 " than the raw code.
 
 " Return the modifyOtherKeys level 2 encoding for "key" with "modifier"
-" (number value, e.g. CTRL is 5).
+" (number value, e.g. CTRL is 5, Shift is 2, Alt is 3).
 func GetEscCodeCSI27(key, modifier)
   let key = printf("%d", char2nr(a:key))
   let mod = printf("%d", a:modifier)
index 91286bb75dbe98aed7bcd6914b2e19536a03588d..3963996e77df2546710ec9db93050b0642a5cf97 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    611,
 /**/
     610,
 /**/