diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-10-21 04:17:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-21 04:17:23 +0200 |
commit | d7594f9c33d1a855a5a071e6191e3ccd0a0b44ee (patch) | |
tree | abe6b2b203676374c331aa114753e8b80687c7c0 /src/nvim/cursor.c | |
parent | a3a9ef9ad4ecf6ee1db98148d165755043d3ff04 (diff) | |
parent | b5b8966760773421b285ee8b63015fc767bca18d (diff) | |
download | rneovim-d7594f9c33d1a855a5a071e6191e3ccd0a0b44ee.tar.gz rneovim-d7594f9c33d1a855a5a071e6191e3ccd0a0b44ee.tar.bz2 rneovim-d7594f9c33d1a855a5a071e6191e3ccd0a0b44ee.zip |
Merge #7420 'vim-patch:8.0.0962, 8.0.1019'
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r-- | src/nvim/cursor.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 60002f3cea..0e97e2203f 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -375,17 +375,30 @@ 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 */ + + // 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; + + 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; + } } } |