aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gen/gen_keycodes.lua33
-rw-r--r--src/nvim/keycodes.c7
-rw-r--r--test/old/testdir/test_options.vim13
3 files changed, 20 insertions, 33 deletions
diff --git a/src/gen/gen_keycodes.lua b/src/gen/gen_keycodes.lua
index 6fbfb5190f..584f0a3d36 100644
--- a/src/gen/gen_keycodes.lua
+++ b/src/gen/gen_keycodes.lua
@@ -38,43 +38,26 @@ hashorder, hashfun = hashy.hashy_hash('get_special_key_code', hashorder, functio
return 'key_names_table[' .. idx .. '].name.data'
end, true)
---- @type table<string,integer>
---- Maps keys to the (after hash) indexes of the entries with preferred names.
-local key_hash_idx = {}
-
-local name_orig_idx_ = vim.deepcopy(name_orig_idx)
-for i, lower_name in ipairs(hashorder) do
- local orig_idx = table.remove(name_orig_idx_[lower_name], 1)
- local keycode = keycode_names[orig_idx]
- local key = keycode[1]
- if key_orig_idx[key] == orig_idx then
- key_hash_idx[key] = i
- end
-end
-assert(vim.iter(vim.tbl_values(name_orig_idx_)):all(vim.tbl_isempty))
-
local names_tgt = assert(io.open(names_file, 'w'))
names_tgt:write([[
static const struct key_name_entry {
- int key; ///< Special key code or ascii value
- String name; ///< Name of key
- const String *pref_name; ///< Pointer to preferred key name
- ///< (may be NULL or point to the name in another entry)
+ int key; ///< Special key code or ascii value
+ bool is_alt; ///< Is an alternative name
+ String name; ///< Name of key
} key_names_table[] = {]])
-name_orig_idx_ = vim.deepcopy(name_orig_idx)
-for i, lower_name in ipairs(hashorder) do
+local name_orig_idx_ = vim.deepcopy(name_orig_idx)
+for _, lower_name in ipairs(hashorder) do
local orig_idx = table.remove(name_orig_idx_[lower_name], 1)
local keycode = keycode_names[orig_idx]
local key = keycode[1]
local name = keycode[2]
- local pref_idx = key_hash_idx[key]
names_tgt:write(
- ('\n {%s, {"%s", %u}, %s},'):format(
+ ('\n {%s, %s, {"%s", %u}},'):format(
key,
+ key_orig_idx[key] == orig_idx and 'false' or 'true',
name,
- #name,
- pref_idx == i and 'NULL' or ('&key_names_table[%u].name'):format(pref_idx - 1)
+ #name
)
)
end
diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c
index 9cb2321eee..778682a881 100644
--- a/src/nvim/keycodes.c
+++ b/src/nvim/keycodes.c
@@ -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;
}
}
diff --git a/test/old/testdir/test_options.vim b/test/old/testdir/test_options.vim
index 9104098baa..9d8122cd8b 100644
--- a/test/old/testdir/test_options.vim
+++ b/test/old/testdir/test_options.vim
@@ -313,11 +313,18 @@ func Test_set_completion()
call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
- " Expand key codes.
+ " " Expand key codes.
" call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
" call assert_equal('"set <Help> <Home>', @:)
-
- " Expand terminal options.
+ " " <BackSpace> (alt name) and <BS> should both show up in auto-complete
+ " call feedkeys(":set <B\<C-A>\<C-B>\"\<CR>", 'tx')
+ " call assert_equal('"set <BackSpace> <Bar> <BS> <Bslash>', @:)
+ " " <ScrollWheelDown> has alt name <MouseUp> but it should not show up here
+ " " nor show up as duplicates
+ " call feedkeys(":set <ScrollWheel\<C-A>\<C-B>\"\<CR>", 'tx')
+ " call assert_equal('"set <ScrollWheelDown> <ScrollWheelLeft> <ScrollWheelRight> <ScrollWheelUp>', @:)
+ "
+ " " Expand terminal options.
" call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
" call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
" call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')