Hi Bram,
2016-8-2(Tue) 0:21:40 UTC+9 Bram Moolenaar:
> Hirohito Higashi wrote:
>
> [...]
>
> > > this almost works, except that after incrementing/decrementing ml_get()
> > > still returns the wrong line. I don't know why yet.
> > >
> > > On the other hand, one could argue, that the number shouldn't be
> > > incremented/decremented at all if the cursor is actually not on a
> > > number, so you could even consider the successful increment to be a bug.
> >
> > ChrisB>
> > Your patch is a good hint for me. Thanks!
> >
> > I wrote a patch with a test.
> > Please check and include this.
>
> Thanks!
This issue is in the todo list yet.
> Patch to fix increment/decrement not working properly when 'virtualedit' is
> set. (Hirohito Higashi, 2016 Aug 1, #923)
You said "Thanks!" a year and a half ago.
Perhaps you forgot to include my patch? :-)
I attached the updated patch.
Thank you for your consideration.
--
Best regards,
Hirohito Higashi (h_east)
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ops.c b/src/ops.c
index cb019cfd0..8a5e3fa96 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -5629,17 +5629,32 @@ do_addsub(
int maxlen = 0;
pos_T startpos;
pos_T endpos;
+#ifdef FEAT_VIRTUALEDIT
+ colnr_T save_coladd = 0;
+#endif
dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */
dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */
dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */
doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */
+#ifdef FEAT_VIRTUALEDIT
+ if (virtual_active())
+ {
+ save_coladd = pos->coladd;
+ pos->coladd = 0;
+ }
+#endif
+
curwin->w_cursor = *pos;
ptr = ml_get(pos->lnum);
col = pos->col;
- if (*ptr == NUL)
+ if (*ptr == NUL
+#ifdef FEAT_VIRTUALEDIT
+ || col + !!save_coladd >= (int)STRLEN(ptr)
+#endif
+ )
goto theend;
/*
@@ -6015,8 +6030,15 @@ do_addsub(
theend:
if (visual)
curwin->w_cursor = save_cursor;
- else if (did_change)
- curwin->w_set_curswant = TRUE;
+ else
+ {
+ if (did_change)
+ curwin->w_set_curswant = TRUE;
+#ifdef FEAT_VIRTUALEDIT
+ else if (virtual_active())
+ curwin->w_cursor.coladd = save_coladd;
+#endif
+ }
return did_change;
}
diff --git a/src/testdir/test_increment.vim b/src/testdir/test_increment.vim
index ad355dce9..db0e57d79 100644
--- a/src/testdir/test_increment.vim
+++ b/src/testdir/test_increment.vim
@@ -1,4 +1,4 @@
-" Tests for using Ctrl-A/Ctrl-X on visual selections
+" Tests for using Ctrl-A/Ctrl-X
func SetUp()
new dummy
@@ -778,4 +778,40 @@ func Test_increment_empty_line()
bwipe!
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