From d9106779375288323b5c63bc2bab341515f8a60d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 19 Apr 2014 14:21:57 +0200 Subject: [PATCH] input: discard key history when a key is mapped This is for the sake of multi-key combinations (see github issue #718). Now a multi-key sequence isn't matched if any of the previous keys were actually mapped. --- DOCS/man/en/input.rst | 8 ++++---- input/input.c | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/DOCS/man/en/input.rst b/DOCS/man/en/input.rst index 2710ad9239..4b9d5f1686 100644 --- a/DOCS/man/en/input.rst +++ b/DOCS/man/en/input.rst @@ -58,10 +58,10 @@ It's also possible to bind a command to a sequence of keys: (This is not shown in the general command syntax.) -If ``a`` or ``a-b`` or ``b`` are already bound, this will run all commands. It -doesn't delay key bindings, and it simply considers the past key history on -any key press. Intermediate keys can be mapped to ``ignore`` in order to avoid -this issue. +If ``a`` or ``a-b`` or ``b`` are already bound, this will run the first command +that matches, and the multi-key command will never be called. Intermediate keys +can be remapped to ``ignore`` in order to avoid this issue. The maximum number +of (non-modifier) keys for combinations is currently 4. List of Input Commands ---------------------- diff --git a/input/input.c b/input/input.c index c17d4d3c94..5e25dd9c38 100644 --- a/input/input.c +++ b/input/input.c @@ -559,12 +559,16 @@ static struct mp_cmd *resolve_key(struct input_ctx *ictx, int code) { update_mouse_section(ictx); struct mp_cmd *cmd = get_cmd_from_keys(ictx, NULL, code); - key_buf_add(ictx->key_history, code); - if (cmd && should_drop_cmd(ictx, cmd)) { + if (cmd && cmd->id != MP_CMD_IGNORE) { + memset(ictx->key_history, 0, sizeof(ictx->key_history)); + if (!should_drop_cmd(ictx, cmd)) + return cmd; talloc_free(cmd); return NULL; } - return cmd; + talloc_free(cmd); + key_buf_add(ictx->key_history, code); + return NULL; } static void interpret_key(struct input_ctx *ictx, int code, double scale)