]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0015: Vim gets confused by OSC handling v9.2.0015
authorFoxe Chen <chen.foxe@gmail.com>
Mon, 16 Feb 2026 22:26:57 +0000 (22:26 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 16 Feb 2026 22:26:57 +0000 (22:26 +0000)
Problem:  Vim gets confused by OSC handling, causing Vim to start in
          search mode (Shane Harper, after v9.1.1703)
Solution: In handle_mapping(), check if we are handling OSC sequences
          and if yes go straight to check_termcode() (Foxe Chen)

fixes:  #19426
closes: #19435

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/getchar.c
src/proto/term.pro
src/term.c
src/version.c

index c7eb7dda40ae879c4c9a653debf26c79a1eba7eb..bbd84c6f9582466a3e407ceac1f9ee316c8dde01 100644 (file)
@@ -2833,9 +2833,13 @@ handle_mapping(
     int                i;
     int                local_State = get_real_state();
     int                is_plug_map = FALSE;
+    bool       in_osc = in_osc_sequence(); // If we are in an OSC sequence,
+                                           // then go straight to
+                                           // check_termcode() in order to
+                                           // consume chars.
 
     // If typeahead starts with <Plug> then remap, even for a "noremap" mapping.
-    if (typebuf.tb_len >= 3
+    if (!in_osc && typebuf.tb_len >= 3
            && typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL
            && typebuf.tb_buf[typebuf.tb_off + 1] == KS_EXTRA
            && typebuf.tb_buf[typebuf.tb_off + 2] == KE_PLUG)
@@ -2853,9 +2857,10 @@ handle_mapping(
      * - waiting for "hit return to continue" and CR or SPACE typed
      * - waiting for a char with --more--
      * - in Ctrl-X mode, and we get a valid char for that mode
+     * - currently receiving OSC sequence
      */
     tb_c1 = typebuf.tb_buf[typebuf.tb_off];
-    if (no_mapping == 0 && is_maphash_valid()
+    if (!in_osc && no_mapping == 0 && is_maphash_valid()
            && (no_zero_mapping == 0 || tb_c1 != '0')
            && (typebuf.tb_maplen == 0 || is_plug_map
                || (p_remap
@@ -3043,7 +3048,8 @@ handle_mapping(
     /*
      * Check for match with 'pastetoggle'
      */
-    if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL)))
+    if (!in_osc && *p_pt != NUL && mp == NULL &&
+           (State & (MODE_INSERT | MODE_NORMAL)))
     {
        for (mlen = 0; mlen < typebuf.tb_len && p_pt[mlen]; ++mlen)
            if (p_pt[mlen] != typebuf.tb_buf[typebuf.tb_off + mlen])
@@ -3082,9 +3088,9 @@ 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 + want_termcode > mp_match_len
+    if (in_osc || ((mp == NULL || max_mlen + want_termcode > mp_match_len
                    || (mp_match_len == 1 && *mp->m_keys == ESC && !*timedout))
-           && keylen != KEYLEN_PART_MAP)
+           && keylen != KEYLEN_PART_MAP))
     {
        int     save_keylen = keylen;
 
@@ -3097,12 +3103,12 @@ handle_mapping(
         * - and not an ESC sequence, not in insert mode or p_ek is on,
         * - and when not timed out,
         */
-       if (no_mapping == 0 || allow_keys != 0)
+       if (in_osc || no_mapping == 0 || allow_keys != 0)
        {
-           if ((typebuf.tb_maplen == 0
+           if (in_osc || ((typebuf.tb_maplen == 0
                            || (p_remap && typebuf.tb_noremap[
                                                    typebuf.tb_off] == RM_YES))
-                   && !*timedout)
+                   && !*timedout))
                keylen = check_termcode(max_mlen + 1, NULL, 0, NULL);
            else
                keylen = 0;
index c76acabbf381813f9fb7b880c0717d899ec9a990..b831bc1818589816b4057c6252fa71f0d93284ed 100644 (file)
@@ -84,6 +84,7 @@ void set_mouse_topline(win_T *wp);
 int is_mouse_topline(win_T *wp);
 int put_string_in_typebuf(int offset, int slen, char_u *string, int new_slen, char_u *buf, int bufsize, int *buflen);
 int decode_modifiers(int n);
+bool in_osc_sequence(void);
 int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen);
 void term_get_fg_color(char_u *r, char_u *g, char_u *b);
 void term_get_bg_color(char_u *r, char_u *g, char_u *b);
index 86d570a6df04ceb908860707e9d9e5ceea2d5be3..69130481db5c1162f3a710c2d0934b9e0732fdd4 100644 (file)
@@ -5900,9 +5900,17 @@ check_for_color_response(char_u *resp, int len)
 static oscstate_T osc_state;
 
 /*
- * Handles any OSC sequence and places the result in "v:termosc". Note that the
- * OSC identifier and terminator character(s) will not be placed in the final
- * result. Returns OK on success and FAIL on failure.
+ * Return true if currently receiving an OSC response.
+ */
+    bool
+in_osc_sequence(void)
+{
+    return osc_state.processing;
+}
+
+/*
+ * Handles any OSC sequence and places the result in "v:termosc". Returns OK on
+ * success and FAIL on failure.
  */
     static int
 handle_osc(char_u *tp, int len, char_u *key_name, int *slen)
index 8db19f9a4ef732e805afa7a407b3a6e22b2cb57e..82487d6f8f3bb8cf9749d5d14fcf73b789420569 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    15,
 /**/
     14,
 /**/