diff options
-rw-r--r-- | src/nvim/getchar.c | 7 | ||||
-rw-r--r-- | src/nvim/normal.c | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_registers.vim | 21 |
3 files changed, 32 insertions, 4 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 95720c498a..55bcfa0e97 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -163,6 +163,7 @@ void free_buff(buffheader_T *buf) xfree(p); } buf->bh_first.b_next = NULL; + buf->bh_curr = NULL; } /// Return the contents of a buffer as a single string. @@ -288,8 +289,12 @@ static void add_buff(buffheader_T *const buf, const char *const s, ptrdiff_t sle /// Only works when it was just added. static void delete_buff_tail(buffheader_T *buf, int slen) { - int len = (int)STRLEN(buf->bh_curr->b_str); + int len; + if (buf->bh_curr == NULL) { + return; // nothing to delete + } + len = (int)STRLEN(buf->bh_curr->b_str); if (len >= slen) { buf->bh_curr->b_str[len - slen] = NUL; buf->bh_space += (size_t)slen; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 76ee9f1f40..28e5d47dbc 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1013,9 +1013,11 @@ static int normal_execute(VimState *state, int key) // be mapped in Insert mode. Required for ":lmap" to work. int len = ins_char_typebuf(s->c, mod_mask); - // When recording the character will be recorded again, remove the - // previously recording. - ungetchars(len); + // When recording and gotchars() was called the character will be + // recorded again, remove the previous recording. + if (KeyTyped) { + ungetchars(len); + } if (restart_edit != 0) { s->c = 'd'; diff --git a/src/nvim/testdir/test_registers.vim b/src/nvim/testdir/test_registers.vim index f16793a08c..2e92d9aa2f 100644 --- a/src/nvim/testdir/test_registers.vim +++ b/src/nvim/testdir/test_registers.vim @@ -511,4 +511,25 @@ func Test_insert_small_delete() bwipe! endfunc +func Test_record_in_select_mode() + new + call setline(1, 'text') + sil norm q00 + sil norm q + call assert_equal('0ext', getline(1)) + + %delete + let @r = '' + call setline(1, ['abc', 'abc', 'abc']) + smap <F2> <Right><Right>, + call feedkeys("qrgh\<F2>Dk\<Esc>q", 'xt') + call assert_equal("gh\<F2>Dk\<Esc>", @r) + norm j0@rj0@@ + call assert_equal([',Dk', ',Dk', ',Dk'], getline(1, 3)) + sunmap <F2> + + bwipe! +endfunc + + " vim: shiftwidth=2 sts=2 expandtab |