diff options
Diffstat (limited to 'src/nvim/getchar.c')
-rw-r--r-- | src/nvim/getchar.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index eddd5ccd14..d615255828 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1590,11 +1590,19 @@ int vgetc(void) c = utf_ptr2char(buf); } - if ((mod_mask & MOD_MASK_CTRL) && (c >= '?' && c <= '_')) { - c = Ctrl_chr(c); - mod_mask &= ~MOD_MASK_CTRL; - if (c == 0) { // <C-@> is <Nul> - c = K_ZERO; + // A modifier was not used for a mapping, apply it to ASCII + // keys. Shift would already have been applied. + if (mod_mask & MOD_MASK_CTRL) { + if ((c >= '`' && c <= 0x7f) || (c >= '@' && c <= '_')) { + c &= 0x1f; + mod_mask &= ~MOD_MASK_CTRL; + if (c == 0) { + c = K_ZERO; + } + } else if (c == '6') { + // CTRL-6 is equivalent to CTRL-^ + c = 0x1e; + mod_mask &= ~MOD_MASK_CTRL; } } @@ -2060,7 +2068,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) } /// unget one character (can only be done once!) -/// If the character was stuffed, vgetc() will get it next time it was called. +/// If the character was stuffed, vgetc() will get it next time it is called. /// Otherwise vgetc() will only get it when the stuff buffer is empty. void vungetc(int c) { @@ -2072,6 +2080,20 @@ void vungetc(int c) old_KeyStuffed = KeyStuffed; } +/// When peeking and not getting a character, reg_executing cannot be cleared +/// yet, so set a flag to clear it later. +void check_end_reg_executing(bool advance) +{ + if (reg_executing != 0 && (typebuf.tb_maplen == 0 || pending_end_reg_executing)) { + if (advance) { + reg_executing = 0; + pending_end_reg_executing = false; + } else { + pending_end_reg_executing = true; + } + } +} + /// Gets a byte: /// 1. from the stuffbuffer /// This is used for abbreviated commands like "D" -> "d$". @@ -2126,9 +2148,7 @@ static int vgetorpeek(bool advance) init_typebuf(); start_stuff(); - if (advance && typebuf.tb_maplen == 0) { - reg_executing = 0; - } + check_end_reg_executing(advance); do { // get a character: 1. from the stuffbuffer if (typeahead_char != 0) { @@ -2155,6 +2175,7 @@ static int vgetorpeek(bool advance) // If a mapped key sequence is found we go back to the start to // try re-mapping. for (;;) { + check_end_reg_executing(advance); // os_breakcheck() is slow, don't use it too often when // inside a mapping. But call it each time for typed // characters. |