]> granicus.if.org Git - vim/commitdiff
patch 8.2.1930: wrong input if removing shift results in special key code v8.2.1930
authorBram Moolenaar <Bram@vim.org>
Sat, 31 Oct 2020 15:33:47 +0000 (16:33 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 31 Oct 2020 15:33:47 +0000 (16:33 +0100)
Problem:    Wrong input if removing shift results in special key code.
Solution:   Handle special key codes. (closes #7189)

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

index 4d4cc589d9e169655418d05b29bbcab9d0448e40..56f6e0a93cda1f4c310952924daa39d224d653b3 100644 (file)
@@ -4462,7 +4462,8 @@ modifiers2keycode(int modifiers, int *key, char_u *string)
     if (modifiers != 0)
     {
        // Some keys have the modifier included.  Need to handle that here to
-       // make mappings work.
+       // make mappings work.  This may result in a special key, such as
+       // K_S_TAB.
        *key = simplify_key(*key, &modifiers);
        if (modifiers != 0)
        {
@@ -4793,7 +4794,13 @@ handle_key_with_modifier(
     // insert modifiers with KS_MODIFIER
     new_slen = modifiers2keycode(modifiers, &key, string);
 
-    if (has_mbyte)
+    if (IS_SPECIAL(key))
+    {
+       string[new_slen++] = K_SPECIAL;
+       string[new_slen++] = KEY2TERMCAP0(key);
+       string[new_slen++] = KEY2TERMCAP1(key);
+    }
+    else if (has_mbyte)
        new_slen += (*mb_char2bytes)(key, string + new_slen);
     else
        string[new_slen++] = key;
index 424e285ef16de7b2bd8cefefb72d2fad9ca60409..cfbb7ba3cdf1908bd63d43b80d825ddcae286d37 100644 (file)
@@ -2029,6 +2029,23 @@ func Test_modifyOtherKeys_mapped()
   set timeoutlen&
 endfunc
 
+" Whether Shift-Tab sends "ESC [ Z" or "ESC [ 27 ; 2 ; 9 ~" is unpredictable,
+" both should work.
+func Test_modifyOtherKeys_shift_tab()
+  set timeoutlen=10
+
+  call setline(1, '')
+  call feedkeys("a\<C-K>" .. GetEscCodeCSI27("\t", '2') .. "\<Esc>", 'Lx!')
+  eval getline(1)->assert_equal('<S-Tab>')
+
+  call setline(1, '')
+  call feedkeys("a\<C-K>\<Esc>[Z\<Esc>", 'Lx!')
+  eval getline(1)->assert_equal('<S-Tab>')
+
+  set timeoutlen&
+  bwipe!
+endfunc
+
 func RunTest_mapping_works_with_shift(func)
   new
   set timeoutlen=10
index 9f23c1d2e5e56ffca98c8f181b48df5bffc5eb3a..93de74dec0515dc5a6730fc92d4607cd56cc3d7d 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1930,
 /**/
     1929,
 /**/