summaryrefslogtreecommitdiff
path: root/src/binding.c
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-01-23 21:56:39 +0100
committerAlbert Cervin <albert@acervin.com>2023-01-23 21:56:39 +0100
commit9eda570311ffd292d333f7687074403ff46cc838 (patch)
tree40265e3d2c23831afaf352bb64b8d6634bae9730 /src/binding.c
parent385c9d62a5507d901ff7e54d7a4c0342cf3aff43 (diff)
downloaddged-9eda570311ffd292d333f7687074403ff46cc838.tar.gz
dged-9eda570311ffd292d333f7687074403ff46cc838.tar.xz
dged-9eda570311ffd292d333f7687074403ff46cc838.zip
Implement some more commands
- More bug fixes for keys: You can now have mod-less keys in keymaps as binds. - Fix calculation bug with space fillouts.
Diffstat (limited to 'src/binding.c')
-rw-r--r--src/binding.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/binding.c b/src/binding.c
index 5147c97..a0946ee 100644
--- a/src/binding.c
+++ b/src/binding.c
@@ -36,26 +36,37 @@ void keymap_destroy(struct keymap *keymap) {
struct lookup_result lookup_key(struct keymap *keymaps, uint32_t nkeymaps,
struct key *key, struct commands *commands) {
- // lookup in order in the keymaps
- for (uint32_t kmi = 0; kmi < nkeymaps; ++kmi) {
+ // 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)) {
- if (binding->type == BindingType_Command) {
+ switch (binding->type) {
+ case BindingType_Command: {
return (struct lookup_result){
.found = true,
.type = BindingType_Command,
.command = lookup_command_by_hash(commands, binding->command),
};
- } else if (binding->type == BindingType_Keymap) {
+ }
+ 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,
+ };
+ }
}
}
}