diff src/ops.c @ 20822:8e5f991db3b4 v8.2.0963

patch 8.2.0963: number increment/decrement does not work with 'virtualedit' Commit: https://github.com/vim/vim/commit/6c6be9e88d72a60ee279ccad73d018c534b71d66 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 12 20:19:44 2020 +0200 patch 8.2.0963: number increment/decrement does not work with 'virtualedit' Problem: Number increment/decrement does not work with 'virtualedit'. Solution: Handle coladd changing. (Christian Brabandt, closes https://github.com/vim/vim/issues/6240, closes #923)
author Bram Moolenaar <Bram@vim.org>
date Fri, 12 Jun 2020 20:30:04 +0200
parents cea8ae407452
children 9064044fd4f6
line wrap: on
line diff
--- a/src/ops.c
+++ b/src/ops.c
@@ -2446,6 +2446,7 @@ do_addsub(
     int		maxlen = 0;
     pos_T	startpos;
     pos_T	endpos;
+    colnr_T	save_coladd = 0;
 
     do_hex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL);	// "heX"
     do_oct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL);	// "Octal"
@@ -2453,11 +2454,17 @@ do_addsub(
     do_alpha = (vim_strchr(curbuf->b_p_nf, 'p') != NULL);	// "alPha"
     do_unsigned = (vim_strchr(curbuf->b_p_nf, 'u') != NULL);	// "Unsigned"
 
+    if (virtual_active())
+    {
+	save_coladd = pos->coladd;
+	pos->coladd = 0;
+    }
+
     curwin->w_cursor = *pos;
     ptr = ml_get(pos->lnum);
     col = pos->col;
 
-    if (*ptr == NUL)
+    if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr))
 	goto theend;
 
     /*
@@ -2824,6 +2831,8 @@ theend:
 	curwin->w_cursor = save_cursor;
     else if (did_change)
 	curwin->w_set_curswant = TRUE;
+    else if (virtual_active())
+	curwin->w_cursor.coladd = save_coladd;
 
     return did_change;
 }