summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-06-12 20:19:44 +0200
committerBram Moolenaar <Bram@vim.org>2020-06-12 20:19:44 +0200
commit6c6be9e88d72a60ee279ccad73d018c534b71d66 (patch)
tree93869209264c264dc481f4d48ecb6cfcb98b827c /src
parentf6e020b1225970d95e6848b79066f82d9e65b66c (diff)
downloadvim-git-6c6be9e88d72a60ee279ccad73d018c534b71d66.tar.gz
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'v8.2.0963
Problem: Number increment/decrement does not work with 'virtualedit'. Solution: Handle coladd changing. (Christian Brabandt, closes #6240, closes #923)
Diffstat (limited to 'src')
-rw-r--r--src/ops.c11
-rw-r--r--src/testdir/test_increment.vim36
-rw-r--r--src/version.c2
3 files changed, 48 insertions, 1 deletions
diff --git a/src/ops.c b/src/ops.c
index ca00c252d..8f31deb67 100644
--- 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;
}
diff --git a/src/testdir/test_increment.vim b/src/testdir/test_increment.vim
index 4a51b9cea..abd85bed8 100644
--- a/src/testdir/test_increment.vim
+++ b/src/testdir/test_increment.vim
@@ -840,4 +840,40 @@ func Test_increment_unsigned()
set nrformats-=unsigned
endfunc
+func Test_normal_increment_with_virtualedit()
+ set virtualedit=all
+
+ call setline(1, ["\<TAB>1"])
+ exec "norm! 0\<C-A>"
+ call assert_equal("\<TAB>2", getline(1))
+ call assert_equal([0, 1, 2, 0], getpos('.'))
+
+ call setline(1, ["\<TAB>1"])
+ exec "norm! 0l\<C-A>"
+ call assert_equal("\<TAB>2", getline(1))
+ call assert_equal([0, 1, 2, 0], getpos('.'))
+
+ call setline(1, ["\<TAB>1"])
+ exec "norm! 07l\<C-A>"
+ call assert_equal("\<TAB>2", getline(1))
+ call assert_equal([0, 1, 2, 0], getpos('.'))
+
+ call setline(1, ["\<TAB>1"])
+ exec "norm! 0w\<C-A>"
+ call assert_equal("\<TAB>2", getline(1))
+ call assert_equal([0, 1, 2, 0], getpos('.'))
+
+ call setline(1, ["\<TAB>1"])
+ exec "norm! 0wl\<C-A>"
+ call assert_equal("\<TAB>1", getline(1))
+ call assert_equal([0, 1, 3, 0], getpos('.'))
+
+ call setline(1, ["\<TAB>1"])
+ exec "norm! 0w30l\<C-A>"
+ call assert_equal("\<TAB>1", getline(1))
+ call assert_equal([0, 1, 3, 29], getpos('.'))
+
+ set virtualedit&
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 8c8efd256..1a2b7050b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 963,
+/**/
962,
/**/
961,