aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cursor.c
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2018-03-28 21:52:06 -0400
committerJames McCoy <jamessan@jamessan.com>2018-03-28 21:54:39 -0400
commit79f9c2d9c650ceab27cdc6707fd6d7fa1de29fc1 (patch)
tree4e0589d75801f3ff6a9678f84f5009102766661e /src/nvim/cursor.c
parent4403864da3c48412595d439f36458d1e6ccfc49f (diff)
parent3f3de9b1a95d273463a87516365510dbffcaf3d2 (diff)
downloadrneovim-79f9c2d9c650ceab27cdc6707fd6d7fa1de29fc1.tar.gz
rneovim-79f9c2d9c650ceab27cdc6707fd6d7fa1de29fc1.tar.bz2
rneovim-79f9c2d9c650ceab27cdc6707fd6d7fa1de29fc1.zip
Merge branch 'master' into yagebu/option-fixes
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r--src/nvim/cursor.c29
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;
+ }
}
}