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 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/nvim/cursor.c') 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; + } } } -- 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 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim/cursor.c') 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; -- cgit