From 043a183d1465f578775e2a28bdc0a5c44afccd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 28 Jan 2017 14:03:57 +0100 Subject: vis: keep track of most recently processed keys of input queue Currently the key handling functions do not know through which mapping they were invoked. As an example the `count` handler exploits the implementation detail that the input queue is stored in contiguous memory, meaning `keys[-1]` gives access to the digit being pressed. This adds infrastructure to keep track of the two most recently processed keys of the input queue. The information is guaranteed to be accurate for the initial invocation of the key handler but will be overwritten in case new keys are pushed to the input queue (e.g. through vis_keys_feed). --- vis.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 12d364a..790069a 100644 --- a/vis.c +++ b/vis.c @@ -995,6 +995,10 @@ static void vis_keys_process(Vis *vis, size_t pos) { end = start; } else if (binding) { /* exact match */ if (binding->action) { + size_t len = binding_end - start; + strcpy(vis->key_prev, vis->key_current); + strncpy(vis->key_current, start, len); + vis->key_current[len] = '\0'; end = (char*)binding->action->func(vis, binding_end, &binding->action->arg); if (!end) { end = start; @@ -1017,6 +1021,10 @@ static void vis_keys_process(Vis *vis, size_t pos) { action = map_get(vis->actions, start+1); end[-1] = tmp; if (action) { + size_t len = end - start; + strcpy(vis->key_prev, vis->key_current); + strncpy(vis->key_current, start, len); + vis->key_current[len] = '\0'; end = (char*)action->func(vis, end, &action->arg); if (!end) { end = start; -- cgit v1.2.3