diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-10-27 00:33:53 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-10-27 00:33:53 +0200 |
| commit | 8a85e071fdaa7448e6ec595bcbeba633e7a95af6 (patch) | |
| tree | 80ab2c25bb68e7559dc52b317f36b47708c49cf8 | |
| parent | d4f852269246b07479aa2bbd8db8798509394f99 (diff) | |
| download | vis-8a85e071fdaa7448e6ec595bcbeba633e7a95af6.tar.gz vis-8a85e071fdaa7448e6ec595bcbeba633e7a95af6.tar.xz | |
vis: apply language map only to key values not modifiers
The language map translation should not take modifiers into account.
For example if `a` is mapped to `b` then `<M-a>` should also be mapped
to `<M-b>`.
Fix #404
| -rw-r--r-- | ui-curses.c | 16 | ||||
| -rw-r--r-- | ui.h | 2 | ||||
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis.c | 20 |
4 files changed, 20 insertions, 19 deletions
diff --git a/ui-curses.c b/ui-curses.c index 8f184e3..dc38e2c 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -91,7 +91,6 @@ typedef struct { enum UiLayout layout; /* whether windows are displayed horizontally or vertically */ TermKey *termkey; /* libtermkey instance to handle keyboard input (stdin or /dev/tty) */ struct termios tio; /* terminal state to restore before exiting */ - char key[64]; /* string representation of last pressed key */ } UiCurses; struct UiCursesWin { @@ -1094,10 +1093,9 @@ static bool ui_haskey(Ui *ui) { return c != ERR; } -static const char *ui_getkey(Ui *ui) { +static bool ui_getkey(Ui *ui, TermKeyKey *key) { UiCurses *uic = (UiCurses*)ui; - TermKeyKey key; - TermKeyResult ret = termkey_getkey(uic->termkey, &key); + TermKeyResult ret = termkey_getkey(uic->termkey, key); if (ret == TERMKEY_RES_EOF) { int tty = open("/dev/tty", O_RDWR); @@ -1119,17 +1117,13 @@ static const char *ui_getkey(Ui *ui) { fd.fd = STDIN_FILENO; fd.events = POLLIN; if (poll(&fd, 1, termkey_get_waittime(uic->termkey)) == 0) - ret = termkey_getkey_force(uic->termkey, &key); + ret = termkey_getkey_force(uic->termkey, key); } - if (ret != TERMKEY_RES_KEY) - return NULL; - termkey_strfkey(uic->termkey, uic->key, sizeof(uic->key), &key, TERMKEY_FORMAT_VIM); - return uic->key; - + return ret == TERMKEY_RES_KEY; fatal: ui_die_msg(ui, "Failed to re-open stdin as /dev/tty\n"); - return NULL; + return false; } static void ui_terminal_save(Ui *ui) { @@ -66,7 +66,7 @@ struct Ui { void (*redraw)(Ui*); void (*update)(Ui*); void (*suspend)(Ui*); - const char* (*getkey)(Ui*); + bool (*getkey)(Ui*, TermKeyKey*); bool (*haskey)(Ui*); void (*terminal_save)(Ui*); void (*terminal_restore)(Ui*); @@ -162,6 +162,7 @@ struct Vis { Map *options; /* ":set"-options */ Map *keymap; /* key translation before any bindings are matched */ bool keymap_disabled; /* ignore key map for next key press, gets automatically re-enabled */ + char key[64]; /* last pressed key as reported from the UI */ Buffer input_queue; /* holds pending input keys */ Buffer *keys; /* currently active keys buffer (either the input_queue or a macro) */ bool errorhandler; /* whether we are currently in an error handler, used to avoid recursion */ @@ -864,20 +864,26 @@ static void vis_keys_push(Vis *vis, const char *input, size_t pos, bool record) } static const char *getkey(Vis *vis) { - const char *key = vis->ui->getkey(vis->ui); - if (!key) + TermKeyKey key = { 0 }; + if (!vis->ui->getkey(vis->ui, &key)) return NULL; vis_info_hide(vis); bool use_keymap = vis->mode->id != VIS_MODE_INSERT && vis->mode->id != VIS_MODE_REPLACE && !vis->keymap_disabled; vis->keymap_disabled = false; - if (use_keymap) { - const char *mapped = map_get(vis->keymap, key); - if (mapped) - return mapped; + if (key.type == TERMKEY_TYPE_UNICODE && use_keymap) { + const char *mapped = map_get(vis->keymap, key.utf8); + if (mapped) { + size_t len = strlen(mapped); + if (len < sizeof(key.utf8)) + memcpy(key.utf8, mapped, len); + } } - return key; + + TermKey *termkey = vis->ui->termkey_get(vis->ui); + termkey_strfkey(termkey, vis->key, sizeof(vis->key), &key, TERMKEY_FORMAT_VIM); + return vis->key; } bool vis_signal_handler(Vis *vis, int signum, const siginfo_t *siginfo, const void *context) { |
