vim-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 vim/vim#6240,
            closes vim/vim#923)
6c6be9e88d
This commit is contained in:
Jan Edmund Lazo 2020-06-12 23:38:33 -04:00
parent 3c9ec83395
commit 833a5d16a2
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
2 changed files with 45 additions and 1 deletions

View File

@ -4671,17 +4671,23 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
int maxlen = 0;
pos_T startpos;
pos_T endpos;
colnr_T save_coladd = 0;
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"
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;
}
@ -4976,6 +4982,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;

View File

@ -779,4 +779,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