From e0b157f56694a5b5e535083c8fc0bc0e1194c9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 12 Feb 2016 20:05:05 +0100 Subject: vis: respect window local mappings for child modes Since commit 197ab824206335eab7ceed774ddeccac18fafc09 visual line and replace modes are child modes, hence we also have to consider the window local key bindings of their respective parent modes. For example in replace mode the key lookup chain is now as follows: window local replace mode -> global replace mode -> window local insert mode -> global insert mode This fixes behaviour in prompt for replace and visual line modes. --- vis.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 489957a..1138dd7 100644 --- a/vis.c +++ b/vis.c @@ -670,25 +670,19 @@ static const char *vis_keys_raw(Vis *vis, Buffer *buf, const char *input) { prefix = false; binding = NULL; - Mode *mode = vis->mode; - for (size_t i = 0; i < LENGTH(vis->win->modes); i++) { - if (mode == &vis_modes[i]) { - if (vis->win->modes[i].bindings) - mode = &vis->win->modes[i]; - break; + for (Mode *mode = vis->mode; mode && !binding && !prefix; mode = mode->parent) { + for (int global = 0; global < 2 && !binding && !prefix; global++) { + Mode *mode_local = global ? mode : &vis->win->modes[mode->id]; + if (!mode_local->bindings) + continue; + binding = map_get(mode_local->bindings, start); + /* "<" is never treated as a prefix because it is used to denote + * special key symbols */ + if (strcmp(cur, "<")) + prefix = !binding && map_contains(mode_local->bindings, start); } } - for (; mode && !binding && !prefix; mode = mode->parent) { - if (!mode->bindings) - continue; - binding = map_get(mode->bindings, start); - /* "<" is never treated as a prefix because it is used to denote - * special key symbols */ - if (strcmp(cur, "<")) - prefix = !binding && map_contains(mode->bindings, start); - } - *end = tmp; vis->keys = buf; -- cgit v1.2.3