diff options
| author | Albert Cervin <albert@acervin.com> | 2023-04-06 23:23:46 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-05-01 22:19:14 +0200 |
| commit | a123725a12e948d78badb2cb686d38548f1c633b (patch) | |
| tree | c92c46134ef5536fbbf3bf08983c4f0dea1aaf58 /src/binding.c | |
| parent | b5ed4cf757afc50afb6ac499eee7b87a2648fa4c (diff) | |
| download | dged-a123725a12e948d78badb2cb686d38548f1c633b.tar.gz dged-a123725a12e948d78badb2cb686d38548f1c633b.tar.xz dged-a123725a12e948d78badb2cb686d38548f1c633b.zip | |
Implement window handling
Also implement searching.
fix undo boundaries
when it checked for other save point, it used && instead of == which
caused it to overwrite other types.
Fix bytes vs chars bug in text_get_region
Diffstat (limited to 'src/binding.c')
| -rw-r--r-- | src/binding.c | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/src/binding.c b/src/binding.c deleted file mode 100644 index a0946ee..0000000 --- a/src/binding.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "binding.h" -#include "command.h" - -#include <stdlib.h> -#include <string.h> - -struct keymap keymap_create(const char *name, uint32_t capacity) { - return (struct keymap){ - .name = name, - .bindings = calloc(capacity, sizeof(struct binding)), - .nbindings = 0, - .capacity = capacity, - }; -} - -void keymap_bind_keys(struct keymap *keymap, struct binding *bindings, - uint32_t nbindings) { - if (keymap->nbindings + nbindings >= keymap->capacity) { - keymap->capacity = - nbindings > keymap->capacity * 2 ? nbindings * 2 : keymap->capacity * 2; - keymap->bindings = - realloc(keymap->bindings, sizeof(struct binding) * keymap->capacity); - } - memcpy(keymap->bindings + keymap->nbindings, bindings, - sizeof(struct binding) * nbindings); - - keymap->nbindings += nbindings; -} - -void keymap_destroy(struct keymap *keymap) { - free(keymap->bindings); - keymap->bindings = 0; - keymap->capacity = 0; - keymap->nbindings = 0; -} - -struct lookup_result lookup_key(struct keymap *keymaps, uint32_t nkeymaps, - struct key *key, struct commands *commands) { - // lookup in reverse order in the keymaps - uint32_t kmi = nkeymaps; - while (kmi > 0) { - --kmi; - struct keymap *keymap = &keymaps[kmi]; - - for (uint32_t bi = 0; bi < keymap->nbindings; ++bi) { - struct binding *binding = &keymap->bindings[bi]; - if (key_equal(key, &binding->key)) { - switch (binding->type) { - case BindingType_Command: { - return (struct lookup_result){ - .found = true, - .type = BindingType_Command, - .command = lookup_command_by_hash(commands, binding->command), - }; - } - case BindingType_Keymap: { - return (struct lookup_result){ - .found = true, - .type = BindingType_Keymap, - .keymap = binding->keymap, - }; - } - case BindingType_DirectCommand: - return (struct lookup_result){ - .found = true, - .type = BindingType_Command, - .command = binding->direct_command, - }; - } - } - } - } - - return (struct lookup_result){.found = false}; -} |
