From 4ed19fd336c4672989170992c3fe53cc74392476 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 8 Sep 2025 15:05:13 -0400 Subject: [PATCH] patch 9.1.1741: Regression with kitty protocol and trailing byte "u" Problem: Regression with kitty protocol and trailing byte "u" (chdiza, after v9.1.1736) Solution: Check that trailing byte "~" is present fixes: #18232 closes: #18234 Signed-off-by: Christian Brabandt --- src/term.c | 20 +++++++++++--------- src/testdir/test_termcodes.vim | 12 ++++++++++++ src/version.c | 2 ++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/term.c b/src/term.c index 2de1508f14..aec9559d0e 100644 --- a/src/term.c +++ b/src/term.c @@ -5338,7 +5338,8 @@ handle_key_with_modifier( char_u *buf, int bufsize, int *buflen, - int iskitty) + int iskitty, + int trail) { // Only set seenModifyOtherKeys for the "{lead}27;" code to avoid setting // it for terminals using the kitty keyboard protocol. Xterm sends @@ -5376,11 +5377,11 @@ handle_key_with_modifier( if (key == ESC) key = K_ESC; - else if (arg[0] >= 11 && arg[0] <= 24) + else if (arg[0] >= 11 && arg[0] <= 24 && trail == '~') key = parse_csi_f_keys(arg[0]); - return put_key_modifiers_in_typebuf(key, modifiers, - csi_len, offset, buf, bufsize, buflen); + return put_key_modifiers_in_typebuf(key, modifiers, csi_len, offset, buf, + bufsize, buflen); } /* @@ -5396,7 +5397,8 @@ handle_key_without_modifier( int offset, char_u *buf, int bufsize, - int *buflen) + int *buflen, + int trail) { char_u string[MAX_KEY_CODE_LEN + 1]; int new_slen; @@ -5410,7 +5412,7 @@ handle_key_without_modifier( string[2] = KE_ESC; new_slen = 3; } - else if (arg[0] >= 11 && arg[0] <= 24) + else if (arg[0] >= 11 && arg[0] <= 24 && trail == '~') { int key = parse_csi_f_keys(arg[0]); string[0] = K_SPECIAL; @@ -5724,7 +5726,7 @@ handle_csi( { int iskitty = argc == 2 && (trail == 'u' || trail == '~'); return len + handle_key_with_modifier(arg, csi_len, offset, buf, - bufsize, buflen, iskitty); + bufsize, buflen, iskitty, trail); } // Key without modifier (Kitty sends this for Esc or F3): @@ -5732,8 +5734,8 @@ handle_csi( // {lead}{key}~ else if (argc == 1 && (trail == 'u' || trail == '~')) { - return len + handle_key_without_modifier(arg, - csi_len, offset, buf, bufsize, buflen); + return len + handle_key_without_modifier(arg, csi_len, offset, buf, + bufsize, buflen, trail); } // else: Unknown CSI sequence. We could drop it, but then the diff --git a/src/testdir/test_termcodes.vim b/src/testdir/test_termcodes.vim index f37f618c81..6fb612e276 100644 --- a/src/testdir/test_termcodes.vim +++ b/src/testdir/test_termcodes.vim @@ -2542,6 +2542,18 @@ func Test_mapping_kitty_function_keys2() set timeoutlen& endfunc +func Test_mapping_kitty_shift_enter() + new + set timeoutlen=10 + + imap YYYY + call feedkeys(printf("i123 %s\", GetEscCodeCSIu("\", 2)),'Lx!') + call assert_equal('123 YYYY', getline(1)) + + bwipe! + set timeoutlen& +endfunc + func Test_insert_literal() set timeoutlen=10 diff --git a/src/version.c b/src/version.c index 88906bd898..adf9f20611 100644 --- a/src/version.c +++ b/src/version.c @@ -724,6 +724,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1741, /**/ 1740, /**/