From 14421f732b63ab35fc7a528be0db9bbd33464772 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 19 Apr 2014 14:31:54 +0200 Subject: input: make key binds order-independent again This is for the sake of multi-key commands again. This could break: SPACE ignore SPACE-SPACE command while this worked: SPACE-SPACE command SPACE ignore The reason being that if the shorter command was first in the list, it would obviously match, and searching was stopped. --- input/input.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'input') diff --git a/input/input.c b/input/input.c index 5e25dd9c38..5245fd8b63 100644 --- a/input/input.c +++ b/input/input.c @@ -393,10 +393,14 @@ static struct cmd_bind *find_bind_for_key_section(struct input_ctx *ictx, memcpy(keys, ictx->key_history, sizeof(keys)); key_buf_add(keys, code); + struct cmd_bind *best = NULL; + // Prefer user-defined keys over builtin bindings for (int builtin = 0; builtin < 2; builtin++) { if (builtin && !ictx->default_bindings) break; + if (best) + break; for (int n = 0; n < bs->num_binds; n++) { if (bs->binds[n].is_builtin == (bool)builtin) { struct cmd_bind *b = &bs->binds[n]; @@ -406,12 +410,13 @@ static struct cmd_bind *find_bind_for_key_section(struct input_ctx *ictx, if (b->keys[i] != keys[b->num_keys - 1 - i]) goto skip; } - return b; + if (!best || b->num_keys >= best->num_keys) + best = b; skip: ; } } } - return NULL; + return best; } static struct cmd_bind *find_any_bind_for_key(struct input_ctx *ictx, -- cgit v1.2.3