From b2e2b449d26a794f10929a2861df4c1b33af7966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 13 Feb 2016 11:18:33 +0100 Subject: vis: add insfrastructure to support global key mappings Except for insert/replace mode keys get translated before any key bindings are evaluated. This is useful for non-english/latin keyboard layouts. --- vis.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 848180f..35516de 100644 --- a/vis.c +++ b/vis.c @@ -341,6 +341,8 @@ Vis *vis_new(Ui *ui, VisEvent *event) { goto err; if (!(vis->search_file = file_new_internal(vis, NULL))) goto err; + if (!(vis->keymap = map_new())) + goto err; vis->mode_prev = vis->mode = &vis_modes[VIS_MODE_NORMAL]; vis->event = event; if (event && event->vis_start) @@ -371,6 +373,7 @@ void vis_free(Vis *vis) { map_free(vis->cmds); map_free(vis->options); map_free(vis->actions); + map_free(vis->keymap); buffer_release(&vis->input_queue); for (int i = 0; i < VIS_MODE_INVALID; i++) map_free(vis_modes[i].bindings); @@ -422,6 +425,10 @@ bool vis_action_register(Vis *vis, const KeyAction *action) { return map_put(vis->actions, action->name, action); } +bool vis_keymap_add(Vis *vis, const char *key, const char *mapping) { + return map_put(vis->keymap, key, mapping); +} + static void window_jumplist_add(Win *win, size_t pos) { Mark mark = text_mark_set(win->file->text, pos); if (mark && win->jumplist) @@ -763,6 +770,11 @@ static const char *getkey(Vis *vis) { if (!key) return NULL; vis_info_hide(vis); + if (!vis->mode->input) { + const char *mapped = map_get(vis->keymap, key); + if (mapped) + return mapped; + } return key; } -- cgit v1.2.3