mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 05:58:33 +00:00
vim-patch:9.1.1247: fragile setup to get (preferred) keys from key_name_entry (#33102)
Problem: fragile setup to get (preferred) keys from key_name_entry
(after v9.1.1179)
Solution: refactor the code further, fix a bug with "pref_name" key
entry introduced in v9.1.1180 (Yee Cheng Chin)
The optimization introduced for using bsearch() with key_name_entry
in vim/vim#16788 was fragile as it required synchronizing a non-obvious index
(e.g. IDX_KEYNAME_SWU) with the array that could be accidentally changed
by any one adding a key to it. Furthermore, the "pref_name" that was
introduced in that change was unnecessary, and in fact introduced a bug,
as we don't always want to use the canonical name.
The bug is triggered when the user triggers auto-complete using a
keycode, such as `:set <Scroll<Tab>`. The bug would end up showing two
copies of `<ScrollWheelUp>` because both entries end up using the
canonical name.
In this change, remove `pref_name`, and simply use a boolean to track
whether an entry is an alt name or not and modify logic to respect that.
Add test to make sure auto-complete works with alt names
closes: vim/vim#16987
7d8e7df551
In Nvim there is no `enabled` field, so put `is_alt` before `name` to
reduce the size of the struct.
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
This commit is contained in:
@@ -338,10 +338,7 @@ char *get_special_key_name(int c, int modifiers)
|
||||
}
|
||||
}
|
||||
} else { // use name of special key
|
||||
const String *s = key_names_table[table_idx].pref_name != NULL
|
||||
? key_names_table[table_idx].pref_name
|
||||
: &key_names_table[table_idx].name;
|
||||
|
||||
const String *s = &key_names_table[table_idx].name;
|
||||
if ((int)s->size + idx + 2 <= MAX_KEY_NAME_LEN) {
|
||||
STRCPY(string + idx, s->data);
|
||||
idx += (int)s->size;
|
||||
@@ -593,7 +590,7 @@ static int extract_modifiers(int key, int *modp, const bool simplify, bool *cons
|
||||
int find_special_key_in_table(int c)
|
||||
{
|
||||
for (int i = 0; i < (int)ARRAY_SIZE(key_names_table); i++) {
|
||||
if (c == key_names_table[i].key) {
|
||||
if (c == key_names_table[i].key && !key_names_table[i].is_alt) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user