]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0974: even when Esc is encoded a timeout is used v9.0.0974
authorBram Moolenaar <Bram@vim.org>
Tue, 29 Nov 2022 20:33:20 +0000 (20:33 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 29 Nov 2022 20:33:20 +0000 (20:33 +0000)
Problem:    Even when Esc is encoded a timeout is used.
Solution:   Use K_ESC when an encoded Esc is found.

src/getchar.c
src/keymap.h
src/term.c
src/version.c

index 142e394aa6ceebf5aca6a0437c3cf3065d9d205d..3fd518b00d951c7d4ea6e9159410a79c1e0d5bce 100644 (file)
@@ -1765,6 +1765,12 @@ vgetc(void)
                }
                c = TO_SPECIAL(c2, c);
 
+               // K_ESC is used to avoid ambiguity with the single Esc
+               // character that might be the start of an escape sequence.
+               // Convert it back to a single Esc here.
+               if (c == K_ESC)
+                   c = ESC;
+
 #if defined(FEAT_GUI_MSWIN) && defined(FEAT_MENU) && defined(FEAT_TEAROFF)
                // Handle K_TEAROFF here, the caller of vgetc() doesn't need to
                // know that a menu was torn off
@@ -3913,6 +3919,12 @@ getcmdkeycmd(
                continue;
            }
            c1 = TO_SPECIAL(c1, c2);
+
+           // K_ESC is used to avoid ambiguity with the single Esc character
+           // that might be the start of an escape sequence.  Convert it back
+           // to a single Esc here.
+           if (c1 == K_ESC)
+               c1 = ESC;
        }
        if (c1 == Ctrl_V)
        {
index 910df7d025503184154d4fb2e9c03cdf14f88e7f..6fddc7f56517cde894345d647737a59cb4dabb99 100644 (file)
@@ -278,13 +278,16 @@ enum key_extra
     , KE_SCRIPT_COMMAND = 104  // <ScriptCmd> special key
     , KE_S_BS = 105            // shift + <BS>
     , KE_SID = 106             // <SID> special key, followed by {nr};
+    , KE_ESC = 107             // used for K_ESC
 };
 
 /*
- * the three byte codes are replaced with the following int when using vgetc()
+ * The three-byte codes are replaced with a negative number when using vgetc().
  */
 #define K_ZERO         TERMCAP2KEY(KS_ZERO, KE_FILLER)
 
+#define K_ESC          TERMCAP2KEY(KS_EXTRA, KE_ESC)
+
 #define K_UP           TERMCAP2KEY('k', 'u')
 #define K_DOWN         TERMCAP2KEY('k', 'd')
 #define K_LEFT         TERMCAP2KEY('k', 'l')
@@ -295,10 +298,12 @@ enum key_extra
 #define K_C_LEFT       TERMCAP2KEY(KS_EXTRA, KE_C_LEFT)
 #define K_S_RIGHT      TERMCAP2KEY('%', 'i')
 #define K_C_RIGHT      TERMCAP2KEY(KS_EXTRA, KE_C_RIGHT)
+
 #define K_S_HOME       TERMCAP2KEY('#', '2')
 #define K_C_HOME       TERMCAP2KEY(KS_EXTRA, KE_C_HOME)
 #define K_S_END                TERMCAP2KEY('*', '7')
 #define K_C_END                TERMCAP2KEY(KS_EXTRA, KE_C_END)
+
 #define K_TAB          TERMCAP2KEY(KS_EXTRA, KE_TAB)
 #define K_S_TAB                TERMCAP2KEY('k', 'B')
 #define K_S_BS         TERMCAP2KEY(KS_EXTRA, KE_S_BS)
index ba288ae8b2eefd0dcd9e2553676c60b6cebdeb60..74c4612992b35d158c9f42c9997f0168939f2842 100644 (file)
@@ -5121,7 +5121,19 @@ handle_key_without_modifier(
        int     *buflen)
 {
     char_u  string[MAX_KEY_CODE_LEN + 1];
-    int            new_slen = add_key_to_buf(arg[0], string);
+    int            new_slen;
+
+    if (arg[0] == ESC)
+    {
+       // Putting Esc in the buffer creates ambiguity, it can be the start of
+       // an escape sequence.  Use K_ESC to avoid that.
+       string[0] = K_SPECIAL;
+       string[1] = KS_EXTRA;
+       string[2] = KE_ESC;
+       new_slen = 3;
+    }
+    else
+       new_slen = add_key_to_buf(arg[0], string);
 
     if (put_string_in_typebuf(offset, csi_len, string, new_slen,
                                                 buf, bufsize, buflen) == FAIL)
index 8a646722f7243fbe6df7887e1bc4cf0e5b1f99f2..6e206df4de0ad9b505152f638bc5a41a08c5cdd1 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    974,
 /**/
     973,
 /**/