diff options
| author | bfredl <bjorn.linse@gmail.com> | 2023-05-14 18:45:56 +0200 |
|---|---|---|
| committer | bfredl <bjorn.linse@gmail.com> | 2023-05-17 12:26:21 +0200 |
| commit | e2fdd53d8c015913e8be4ff708fc3488558c8906 (patch) | |
| tree | 2858a7eb734b605225296c0019aa8048e24e425d /src/nvim/tui | |
| parent | 33687f5e87a0f048f7bc02d4658e58ef8cc0fd49 (diff) | |
| download | rneovim-e2fdd53d8c015913e8be4ff708fc3488558c8906.tar.gz rneovim-e2fdd53d8c015913e8be4ff708fc3488558c8906.tar.bz2 rneovim-e2fdd53d8c015913e8be4ff708fc3488558c8906.zip | |
refactor(map): avoid duplicated khash_t types for values
This reduces the total number of khash_t instantiations from 22 to 8.
Make the khash internal functions take the size of values as a runtime
parameter. This is abstracted with typesafe Map containers which
are still specialized for both key, value type.
Introduce `Set(key)` type for when there is no value.
Refactor shada.c to use Map/Set instead of khash directly.
This requires `map_ref` operation to be more flexible.
Return pointers to both key and value, plus an indicator for new_item.
As a bonus, `map_key` is now redundant.
Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is
humongous.
Make `event_strings` actually work like an intern pool instead of wtf it
was doing before.
Diffstat (limited to 'src/nvim/tui')
| -rw-r--r-- | src/nvim/tui/input.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 73ed7b6096..81a68d5b07 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -33,7 +33,7 @@ #define KEY_BUFFER_SIZE 0xfff static const struct kitty_key_map_entry { - KittyKey key; + int key; const char *name; } kitty_key_map_entry[] = { { KITTY_KEY_ESCAPE, "Esc" }, @@ -115,7 +115,7 @@ static const struct kitty_key_map_entry { { KITTY_KEY_KP_BEGIN, "kOrigin" }, }; -static Map(KittyKey, cstr_t) kitty_key_map = MAP_INIT; +static Map(int, cstr_t) kitty_key_map = MAP_INIT; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "tui/input.c.generated.h" @@ -135,8 +135,8 @@ void tinput_init(TermInput *input, Loop *loop) input->key_buffer = rbuffer_new(KEY_BUFFER_SIZE); for (size_t i = 0; i < ARRAY_SIZE(kitty_key_map_entry); i++) { - map_put(KittyKey, cstr_t)(&kitty_key_map, kitty_key_map_entry[i].key, - kitty_key_map_entry[i].name); + map_put(int, cstr_t)(&kitty_key_map, kitty_key_map_entry[i].key, + kitty_key_map_entry[i].name); } input->in_fd = STDIN_FILENO; @@ -162,7 +162,7 @@ void tinput_init(TermInput *input, Loop *loop) void tinput_destroy(TermInput *input) { - map_destroy(KittyKey, cstr_t)(&kitty_key_map); + map_destroy(int, &kitty_key_map); rbuffer_free(input->key_buffer); time_watcher_close(&input->timer_handle, NULL); stream_close(&input->read_stream, NULL, NULL); @@ -231,7 +231,7 @@ static void tinput_enqueue(TermInput *input, char *buf, size_t size) static void handle_kitty_key_protocol(TermInput *input, TermKeyKey *key) { - const char *name = map_get(KittyKey, cstr_t)(&kitty_key_map, (KittyKey)key->code.codepoint); + const char *name = map_get(int, cstr_t)(&kitty_key_map, (int)key->code.codepoint); if (name) { char buf[64]; size_t len = 0; @@ -257,7 +257,7 @@ static void forward_simple_utf8(TermInput *input, TermKeyKey *key) char *ptr = key->utf8; if (key->code.codepoint >= 0xE000 && key->code.codepoint <= 0xF8FF - && map_has(KittyKey, cstr_t)(&kitty_key_map, (KittyKey)key->code.codepoint)) { + && map_has(int, cstr_t)(&kitty_key_map, (int)key->code.codepoint)) { handle_kitty_key_protocol(input, key); return; } @@ -286,8 +286,7 @@ static void forward_modified_utf8(TermInput *input, TermKeyKey *key) } else { assert(key->modifiers); if (key->code.codepoint >= 0xE000 && key->code.codepoint <= 0xF8FF - && map_has(KittyKey, cstr_t)(&kitty_key_map, - (KittyKey)key->code.codepoint)) { + && map_has(int, cstr_t)(&kitty_key_map, (int)key->code.codepoint)) { handle_kitty_key_protocol(input, key); return; } |