Skip to content

Commit

Permalink
vis: disable language map for replacement character of r command
Browse files Browse the repository at this point in the history
The character following the `r` command in normal mode should be
treated as regular input given in insert/replace mode, that is no
tranformation should be applied. Temporarily disable the language
map for this reason.

Close martanne#382
  • Loading branch information
martanne committed Sep 25, 2016
1 parent c3bbd83 commit 98bca99
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1630,8 +1630,10 @@ static const char *selections_trim(Vis *vis, const char *keys, const Arg *arg) {
}

static const char *replace(Vis *vis, const char *keys, const Arg *arg) {
if (!keys[0])
if (!keys[0]) {
vis_keymap_disable(vis);
return NULL;
}
const char *next = vis_keys_next(vis, keys);
if (!next)
return NULL;
Expand Down
1 change: 1 addition & 0 deletions vis-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ struct Vis {
Map *usercmds; /* user registered ":"-commands */
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 */
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 */
Expand Down
8 changes: 7 additions & 1 deletion vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ bool vis_keymap_add(Vis *vis, const char *key, const char *mapping) {
return map_put(vis->keymap, key, mapping);
}

void vis_keymap_disable(Vis *vis) {
vis->keymap_disabled = true;
}

static void window_jumplist_add(Win *win, size_t pos) {
Mark mark = text_mark_set(win->file->text, pos);
if (mark && win->jumplist)
Expand Down Expand Up @@ -864,7 +868,9 @@ static const char *getkey(Vis *vis) {
if (!key)
return NULL;
vis_info_hide(vis);
if (!vis->mode->input) {
bool use_keymap = !vis->mode->input && !vis->keymap_disabled;
vis->keymap_disabled = false;
if (use_keymap) {
const char *mapped = map_get(vis->keymap, key);
if (mapped)
return mapped;
Expand Down
2 changes: 2 additions & 0 deletions vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ bool vis_action_register(Vis*, const KeyAction*);
/* add a key mapping which is applied for all modes except insert/replace
* before any key bindings are evaluated */
bool vis_keymap_add(Vis*, const char *key, const char *mapping);
/* disable the keymap for the next key press */
void vis_keymap_disable(Vis*);

enum VisOperator {
VIS_OP_DELETE,
Expand Down

0 comments on commit 98bca99

Please sign in to comment.