patch 9.1.1180: short-description Commit: https://github.com/vim/vim/commit/b3a9127494b8b4389bc39877b98b79a832730f2b Author: zeertzjq <zeert...@outlook.com> Date: Fri Mar 7 18:51:40 2025 +0100
patch 9.1.1180: short-description Problem: The meaning of <Tab> depends on unspecified behavior (after 9.1.1179). Solution: Return TAB in case bsearch() finds K_TAB. Rename alt_name to pref_name as that's closer to it meaning (zeertzjq). The man page of bsearch() says: The bsearch() function returns a pointer to a matching member of the array, or NULL if no match is found. If there are multiple elements that match the key, the element returned is unspecified. So it's possible that bsearch() finds K_TAB instead of TAB when trying to get the key code for <Tab>. Actually, it can happen when adding a single key to end of the table: closes: #16821 Signed-off-by: zeertzjq <zeert...@outlook.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/misc2.c b/src/misc2.c index 151745ca2..90f108a24 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -1141,7 +1141,8 @@ static struct key_name_entry {TRUE, K_XRIGHT, STRING_INIT("xRight"), NULL}, {TRUE, K_XUP, STRING_INIT("xUp"), NULL}, {TRUE, K_ZEND, STRING_INIT("zEnd"), NULL}, - {TRUE, K_ZHOME, STRING_INIT("zHome"), NULL} + {TRUE, K_ZHOME, STRING_INIT("zHome"), NULL}, + {TRUE, -1, STRING_INIT("zzDummyKey"), NULL} // NOTE: When adding a long name update MAX_KEY_NAME_LEN. }; #undef STRING_INIT Meanwhile IDX_KEYNAME_TAB doesn't do anything, as TAB and K_TAB have the same name. Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/misc2.c b/src/misc2.c index e4360aa8e..75fd13bc8 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -930,7 +930,6 @@ static char_u modifier_keys_table[] = #define IDX_KEYNAME_NL 101 #define IDX_KEYNAME_SWD 115 #define IDX_KEYNAME_SWU 118 -#define IDX_KEYNAME_TAB 124 #define STRING_INIT(s) \ {(char_u *)(s), STRLEN_LITERAL(s)} @@ -939,7 +938,7 @@ static struct key_name_entry int enabled; // is this entry available (TRUE/FALSE)? int key; // special key code or ascii value string_T name; // name of key - string_T *alt_name; // pointer to alternative key name + string_T *pref_name; // pointer to preferred key name // (may be NULL or point to the name in another entry) } key_names_table[] = // Must be sorted by the 'name.string' field in ascending order because it is used by bsearch()! @@ -1065,7 +1064,7 @@ static struct key_name_entry {TRUE, K_MIDDLERELEASE, STRING_INIT("MiddleRelease"), NULL}, {TRUE, K_MOUSE, STRING_INIT("Mouse"), NULL}, {TRUE, K_MOUSEDOWN, STRING_INIT("MouseDown"), - &key_names_table[IDX_KEYNAME_SWU].name}, // OBSOLETE: Use ScrollWheelUP instead + &key_names_table[IDX_KEYNAME_SWU].name}, // OBSOLETE: Use ScrollWheelUp instead {TRUE, K_MOUSEMOVE, STRING_INIT("MouseMove"), NULL}, {TRUE, K_MOUSEUP, STRING_INIT("MouseUp"), &key_names_table[IDX_KEYNAME_SWD].name}, // OBSELETE: Use ScrollWheelDown instead @@ -1114,8 +1113,7 @@ static struct key_name_entry K_SNR, STRING_INIT("SNR"), NULL}, {TRUE, ' ', STRING_INIT("Space"), NULL}, {TRUE, TAB, STRING_INIT("Tab"), NULL}, - {TRUE, K_TAB, STRING_INIT("Tab"), - &key_names_table[IDX_KEYNAME_TAB].name}, + {TRUE, K_TAB, STRING_INIT("Tab"), NULL}, {TRUE, K_UNDO, STRING_INIT("Undo"), NULL}, {TRUE, K_UP, STRING_INIT("Up"), NULL}, { @@ -1325,8 +1323,8 @@ get_special_key_name(int c, int modifiers) { string_T *s; - if (key_names_table[table_idx].alt_name != NULL) - s = key_names_table[table_idx].alt_name; + if (key_names_table[table_idx].pref_name != NULL) + s = key_names_table[table_idx].pref_name; else s = &key_names_table[table_idx].name; @@ -1801,7 +1799,7 @@ get_special_key_code(char_u *name) target.key = 0; target.name.string = name; target.name.length = 0; - target.alt_name = NULL; + target.pref_name = NULL; entry = (struct key_name_entry *)bsearch( &target, @@ -1810,7 +1808,12 @@ get_special_key_code(char_u *name) sizeof(key_names_table[0]), cmp_key_name_entry); if (entry != NULL && entry->enabled) - return entry->key; + { + int key = entry->key; + // Both TAB and K_TAB have name "Tab", and it's unspecified which + // one bsearch() will return. TAB is the expected one. + return key == K_TAB ? TAB : key; + } } return 0; @@ -1822,8 +1825,8 @@ get_key_name(int i) if (i < 0 || i >= (int)ARRAY_LENGTH(key_names_table)) return NULL; - return (key_names_table[i].alt_name != NULL) ? - key_names_table[i].alt_name->string : + return (key_names_table[i].pref_name != NULL) ? + key_names_table[i].pref_name->string : key_names_table[i].name.string; } diff --git a/src/version.c b/src/version.c index 973b1b6fb..0592d8083 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1180, /**/ 1179, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tqbzW-00EFEm-Rf%40256bit.org.