]> granicus.if.org Git - vim/commitdiff
patch 8.2.2246: cursor keys not recognized at the hit-Enter prompt v8.2.2246
authorBram Moolenaar <Bram@vim.org>
Tue, 29 Dec 2020 19:53:33 +0000 (20:53 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 29 Dec 2020 19:53:33 +0000 (20:53 +0100)
Problem:    Cursor keys not recognized at the hit-Enter prompt after executing
            an external command.
Solution:   Change the codes for the extra cursor keys. (closes #7562)
            Tune the delays to avoid test flakyness.

runtime/doc/term.txt
src/term.c
src/testdir/test_terminal3.vim
src/version.c

index 87e56240fb93aa2fdaa21ca42cc25b890b75dbe6..0093a96799138e039d73ab9544bc6725f542c956 100644 (file)
@@ -217,6 +217,10 @@ it's different from Alt).  They can be combined.  Examples: >
 Another speciality about these codes is that they are not overwritten by
 another code.  That is to avoid that the codes obtained from xterm directly
 |t_RV| overwrite them.
+
+Another special value is a termcap entry ending in "@;*X".  This is for cursor
+keys, which either use "CSI X" or "CSI 1 ; modifier X".  Thus the "@"
+stands for either "1" if a modifier follows, or nothing.
                                                        *xterm-scroll-region*
 The default termcap entry for xterm on Sun and other platforms does not
 contain the entry for scroll regions.  Add ":cs=\E[%i%d;%dr:" to the xterm
index 26031723d2ca930165becb5ef5551f6308511314..b55d395770cc233eaf4a29b32225ec990ba8e70b 100644 (file)
@@ -914,10 +914,10 @@ static struct builtin_term builtin_termcaps[] =
     {K_RIGHT,          IF_EB("\033O*C", ESC_STR "O*C")},
     {K_LEFT,           IF_EB("\033O*D", ESC_STR "O*D")},
     // An extra set of cursor keys for vt100 mode
-    {K_XUP,            IF_EB("\033[1;*A", ESC_STR "[1;*A")},
-    {K_XDOWN,          IF_EB("\033[1;*B", ESC_STR "[1;*B")},
-    {K_XRIGHT,         IF_EB("\033[1;*C", ESC_STR "[1;*C")},
-    {K_XLEFT,          IF_EB("\033[1;*D", ESC_STR "[1;*D")},
+    {K_XUP,            IF_EB("\033[@;*A", ESC_STR "[@;*A")},
+    {K_XDOWN,          IF_EB("\033[@;*B", ESC_STR "[@;*B")},
+    {K_XRIGHT,         IF_EB("\033[@;*C", ESC_STR "[@;*C")},
+    {K_XLEFT,          IF_EB("\033[@;*D", ESC_STR "[@;*D")},
     // An extra set of function keys for vt100 mode
     {K_XF1,            IF_EB("\033O*P", ESC_STR "O*P")},
     {K_XF2,            IF_EB("\033O*Q", ESC_STR "O*Q")},
@@ -4230,7 +4230,12 @@ add_termcode(char_u *name, char_u *string, int flags)
     termcodes[i].modlen = 0;
     j = termcode_star(s, len);
     if (j > 0)
+    {
        termcodes[i].modlen = len - 1 - j;
+       // For "CSI[@;X" the "@" is not included in "modlen".
+       if (termcodes[i].code[termcodes[i].modlen - 1] == '@')
+           --termcodes[i].modlen;
+    }
     ++tc_len;
 }
 
@@ -4242,7 +4247,7 @@ add_termcode(char_u *name, char_u *string, int flags)
     static int
 termcode_star(char_u *code, int len)
 {
-    // Shortest is <M-O>*X.  With ; shortest is <CSI>1;*X
+    // Shortest is <M-O>*X.  With ; shortest is <CSI>@;*X
     if (len >= 3 && code[len - 2] == '*')
     {
        if (len >= 5 && code[len - 3] == ';')
@@ -5329,15 +5334,19 @@ check_termcode(
                /*
                 * Check for code with modifier, like xterm uses:
                 * <Esc>[123;*X  (modslen == slen - 3)
+                * <Esc>[@;*X    (matches <Esc>[X and <Esc>[1;9X )
                 * Also <Esc>O*X and <M-O>*X (modslen == slen - 2).
                 * When there is a modifier the * matches a number.
                 * When there is no modifier the ;* or * is omitted.
                 */
                if (termcodes[idx].modlen > 0)
                {
+                   int at_code;
+
                    modslen = termcodes[idx].modlen;
                    if (cpo_koffset && offset && len < modslen)
                        continue;
+                   at_code = termcodes[idx].code[modslen] == '@';
                    if (STRNCMP(termcodes[idx].code, tp,
                                (size_t)(modslen > len ? len : modslen)) == 0)
                    {
@@ -5347,9 +5356,14 @@ check_termcode(
                            return -1;          // need to get more chars
 
                        if (tp[modslen] == termcodes[idx].code[slen - 1])
-                           slen = modslen + 1; // no modifiers
+                           // no modifiers
+                           slen = modslen + 1;
                        else if (tp[modslen] != ';' && modslen == slen - 3)
-                           continue;   // no match
+                           // no match for "code;*X" with "code;"
+                           continue;
+                       else if (at_code && tp[modslen] != '1')
+                           // no match for "<Esc>[@" with "<Esc>[1"
+                           continue;
                        else
                        {
                            // Skip over the digits, the final char must
index 75882f1d1a05fb215a11b2f4c445914e907eb7f8..eaf37e6745ec7681e58316e15e8b62dc0cd19488 100644 (file)
@@ -101,7 +101,7 @@ func Test_terminal_in_popup()
   let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15})
   call TermWait(buf, 100)
   call term_sendkeys(buf, ":call OpenTerm(0)\<CR>")
-  call TermWait(buf, 100)
+  call TermWait(buf, 500)
   call term_sendkeys(buf, ":\<CR>")
   call TermWait(buf, 100)
   call term_sendkeys(buf, "\<C-W>:echo getwinvar(g:winid, \"&buftype\") win_gettype(g:winid)\<CR>")
@@ -111,7 +111,7 @@ func Test_terminal_in_popup()
   call VerifyScreenDump(buf, 'Test_terminal_popup_2', {})
  
   call term_sendkeys(buf, ":call OpenTerm(1)\<CR>")
-  call TermWait(buf, 150)
+  call TermWait(buf, 500)
   call term_sendkeys(buf, ":set hlsearch\<CR>")
   call TermWait(buf, 100)
   call term_sendkeys(buf, "/edit\<CR>")
@@ -138,7 +138,7 @@ func Test_terminal_in_popup()
 
   call TermWait(buf, 50)
   call term_sendkeys(buf, ":q\<CR>")
-  call TermWait(buf, 150)  " wait for terminal to vanish
+  call TermWait(buf, 250)  " wait for terminal to vanish
 
   call StopVimInTerminal(buf)
   call delete('Xtext')
@@ -309,6 +309,7 @@ func Test_term_keycode_translation()
 
   let buf = RunVimInTerminal('', {})
   call term_sendkeys(buf, ":set nocompatible\<CR>")
+  call term_sendkeys(buf, ":set timeoutlen=20\<CR>")
 
   let keys = ["\<F1>", "\<F2>", "\<F3>", "\<F4>", "\<F5>", "\<F6>", "\<F7>",
         \ "\<F8>", "\<F9>", "\<F10>", "\<F11>", "\<F12>", "\<Home>",
@@ -325,7 +326,7 @@ func Test_term_keycode_translation()
   call term_sendkeys(buf, "i")
   for i in range(len(keys))
     call term_sendkeys(buf, "\<C-U>\<C-K>" .. keys[i])
-    call WaitForAssert({-> assert_equal(output[i], term_getline(buf, 1))})
+    call WaitForAssert({-> assert_equal(output[i], term_getline(buf, 1))}, 200)
   endfor
 
   let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>",
@@ -340,7 +341,7 @@ func Test_term_keycode_translation()
       continue
     endif
     call term_sendkeys(buf, "\<C-U>" .. keypad_keys[i])
-    call WaitForAssert({-> assert_equal(keypad_output[i], term_getline(buf, 1))})
+    call WaitForAssert({-> assert_equal(keypad_output[i], term_getline(buf, 1))}, 100)
   endfor
 
   call feedkeys("\<C-U>\<kEnter>\<BS>one\<C-W>.two", 'xt')
index bee026c197b663cb582b55b7f5ae98831df08a6e..3894bc0e1d412e0f684c431843567a23f9ee267b 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2246,
 /**/
     2245,
 /**/