@@ -5921,6 +5921,9 @@ handle_osc(char_u *tp, int len, char_u *key_name, int *slen)
59215921 // The whole OSC response may be larger than the typeahead buffer.
59225922 // To handle this, keep reading data in and out of the typeahead
59235923 // buffer until we read an OSC terminator or timeout.
5924+
5925+ // We can't use the previous buffer since we transferred ownership of it
5926+ // to the vim var.
59245927 ga_init2 (& osc_state .buf , 1 , 1024 );
59255928#ifdef ELAPSED_FUNC
59265929 ELAPSED_INIT (osc_state .start_tv );
@@ -5933,7 +5936,6 @@ handle_osc(char_u *tp, int len, char_u *key_name, int *slen)
59335936 last_char = ((char_u * )osc_state .buf .ga_data )[osc_state .buf .ga_len - 1 ];
59345937
59355938 key_name [0 ] = (int )KS_EXTRA ;
5936- key_name [1 ] = (int )KE_IGNORE ;
59375939
59385940 // Read data and append to buffer. If we reach a terminator, then
59395941 // finally set the vim var.
@@ -5945,6 +5947,8 @@ handle_osc(char_u *tp, int len, char_u *key_name, int *slen)
59455947 {
59465948 osc_state .processing = FALSE;
59475949
5950+ key_name [1 ] = (int )KE_OSC ;
5951+
59485952 ga_concat_len (& osc_state .buf , tp , i + 1 + (tp [i ] == ESC ));
59495953 ga_append (& osc_state .buf , NUL );
59505954 * slen = i + 1 + (tp [i ] == ESC );
@@ -5962,6 +5966,8 @@ handle_osc(char_u *tp, int len, char_u *key_name, int *slen)
59625966 return OK ;
59635967 }
59645968
5969+ key_name [1 ] = (int )KE_IGNORE ;
5970+
59655971#ifdef ELAPSED_FUNC
59665972 if (ELAPSED_FUNC (osc_state .start_tv ) >= p_ost )
59675973 {
@@ -6167,9 +6173,15 @@ check_termcode(
61676173 }
61686174
61696175 if (osc_state .processing )
6176+ {
61706177 // Still processing OSC response data, go straight to handler
61716178 // function.
6179+ tp [len ] = NUL ;
6180+ key_name [0 ] = NUL ;
6181+ key_name [1 ] = NUL ;
6182+ modifiers = 0 ;
61726183 goto handle_osc ;
6184+ }
61736185
61746186 /*
61756187 * Skip this position if the character does not appear as the first
@@ -6690,12 +6702,8 @@ check_termcode(
66906702 */
66916703 key = handle_x_keys (TERMCAP2KEY (key_name [0 ], key_name [1 ]));
66926704
6693- if (osc_state .processing )
6694- // We don't want to add anything to the typeahead buffer.
6695- new_slen = 0 ;
6696- else
6697- // Add any modifier codes to our string.
6698- new_slen = modifiers2keycode (modifiers , & key , string );
6705+ // Add any modifier codes to our string.
6706+ new_slen = modifiers2keycode (modifiers , & key , string );
66996707
67006708 // Finally, add the special key code to our string
67016709 key_name [0 ] = KEY2TERMCAP0 (key );
@@ -6708,8 +6716,10 @@ check_termcode(
67086716 else
67096717 string [new_slen ++ ] = key_name [1 ];
67106718 }
6711- else if (new_slen == 0 && key_name [0 ] == KS_EXTRA
6712- && key_name [1 ] == KE_IGNORE )
6719+ else if (osc_state .processing ||
6720+ (new_slen == 0
6721+ && key_name [0 ] == KS_EXTRA
6722+ && key_name [1 ] == KE_IGNORE ))
67136723 {
67146724 // Do not put K_IGNORE into the buffer, do return KEYLEN_REMOVED
67156725 // to indicate what happened.
0 commit comments