From 82b8382abe6c533fbdd01529cfc93a8d1c5231e2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 21 Oct 2017 02:04:35 +0200 Subject: vim-patch:8.0.0962 closes #6726 Problem: Crash with virtualedit and joining lines. (Joshua T Corbin, Neovim #6726) Solution: When using a mark check that coladd is valid. https://github.com/vim/vim/commit/9aa156912867c05e0a6480925afe11c590378f09 --- src/nvim/cursor.c | 26 ++++++++++++++++++-------- src/nvim/normal.c | 13 +++++++++---- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_virtualedit.vim | 31 +++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 src/nvim/testdir/test_virtualedit.vim (limited to 'src') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 60002f3cea..e575143af0 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -375,17 +375,27 @@ void check_cursor_col_win(win_T *win) win->w_cursor.col = 0; } - /* If virtual editing is on, we can leave the cursor on the old position, - * only we must set it to virtual. But don't do it when at the end of the - * line. */ - if (oldcol == MAXCOL) + // If virtual editing is on, we can leave the cursor on the old position, + // only we must set it to virtual. But don't do it when at the end of the + // line. + if (oldcol == MAXCOL) { win->w_cursor.coladd = 0; - else if (ve_flags == VE_ALL) { - if (oldcoladd > win->w_cursor.col) + } else if (ve_flags == VE_ALL) { + if (oldcoladd > win->w_cursor.col) { win->w_cursor.coladd = oldcoladd - win->w_cursor.col; - else - /* avoid weird number when there is a miscalculation or overflow */ + if (win->w_cursor.col < len && win->w_cursor.coladd > 0) { + int cs, ce; + + // check that coladd is not more than the char width + getvcol(win, &win->w_cursor, &cs, NULL, &ce); + if (win->w_cursor.coladd > ce - cs) { + win->w_cursor.coladd = ce - cs; + } + } + } else { + // avoid weird number when there is a miscalculation or overflow win->w_cursor.coladd = 0; + } } } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index c40ed58550..1103fe15d2 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1548,8 +1548,10 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } oap->start = VIsual; - if (VIsual_mode == 'V') + if (VIsual_mode == 'V') { oap->start.col = 0; + oap->start.coladd = 0; + } } /* @@ -6260,15 +6262,18 @@ static void nv_gomark(cmdarg_T *cap) } else nv_cursormark(cap, cap->arg, pos); - /* May need to clear the coladd that a mark includes. */ - if (!virtual_active()) + // May need to clear the coladd that a mark includes. + if (!virtual_active()) { curwin->w_cursor.coladd = 0; + } + check_cursor_col(); if (cap->oap->op_type == OP_NOP && pos != NULL && (pos == (pos_T *)-1 || !equalpos(old_cursor, *pos)) && (fdo_flags & FDO_MARK) - && old_KeyTyped) + && old_KeyTyped) { foldOpenCursor(); + } } /* diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index d55170c27c..535e290a34 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -34,4 +34,5 @@ source test_taglist.vim source test_true_false.vim source test_unlet.vim source test_utf8.vim +source test_virtualedit.vim source test_window_cmd.vim diff --git a/src/nvim/testdir/test_virtualedit.vim b/src/nvim/testdir/test_virtualedit.vim new file mode 100644 index 0000000000..da143c518f --- /dev/null +++ b/src/nvim/testdir/test_virtualedit.vim @@ -0,0 +1,31 @@ +" Tests for 'virtualedit'. + +func Test_yank_move_change() + split + call setline(1, [ + \ "func foo() error {", + \ "\tif n, err := bar();", + \ "\terr != nil {", + \ "\t\treturn err", + \ "\t}", + \ "\tn = n * n", + \ ]) + set virtualedit=all + set ts=4 + function! MoveSelectionDown(count) abort + normal! m` + silent! exe "'<,'>move'>+".a:count + norm! `` + endfunction + + xmap ]e :call MoveSelectionDown(v:count1) + 2 + normal 2gg + normal J + normal jVj + normal ]e + normal ce + bwipe! + set virtualedit= + set ts=8 +endfunc -- cgit From b5b8966760773421b285ee8b63015fc767bca18d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 21 Oct 2017 02:20:17 +0200 Subject: vim-patch:8.0.1019 Problem: Pasting in virtual edit happens in the wrong place. Solution: Do not adjust coladd when after the end of the line (closes vim/vim#2015) https://github.com/vim/vim/commit/d41babef89a50cdf165f15bc1834c0a4e89ffff8 --- src/nvim/cursor.c | 7 +++++-- src/nvim/testdir/test_virtualedit.vim | 14 +++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index e575143af0..0e97e2203f 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -383,10 +383,13 @@ void check_cursor_col_win(win_T *win) } else if (ve_flags == VE_ALL) { if (oldcoladd > win->w_cursor.col) { win->w_cursor.coladd = oldcoladd - win->w_cursor.col; - if (win->w_cursor.col < len && win->w_cursor.coladd > 0) { + + // Make sure that coladd is not more than the char width. + // Not for the last character, coladd is then used when the cursor + // is actually after the last character. + if (win->w_cursor.col + 1 < len && win->w_cursor.coladd > 0) { int cs, ce; - // check that coladd is not more than the char width getvcol(win, &win->w_cursor, &cs, NULL, &ce); if (win->w_cursor.coladd > ce - cs) { win->w_cursor.coladd = ce - cs; diff --git a/src/nvim/testdir/test_virtualedit.vim b/src/nvim/testdir/test_virtualedit.vim index da143c518f..2b8849f488 100644 --- a/src/nvim/testdir/test_virtualedit.vim +++ b/src/nvim/testdir/test_virtualedit.vim @@ -1,7 +1,7 @@ " Tests for 'virtualedit'. func Test_yank_move_change() - split + new call setline(1, [ \ "func foo() error {", \ "\tif n, err := bar();", @@ -29,3 +29,15 @@ func Test_yank_move_change() set virtualedit= set ts=8 endfunc + +func Test_paste_end_of_line() + new + set virtualedit=all + call setline(1, ['456', '123']) + normal! gg0"ay$ + exe "normal! 2G$lllA\:normal! \"agP\r" + call assert_equal('123456', getline(2)) + + bwipe! + set virtualedit= +endfunc -- cgit