0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.0.1374: CTRL-A does not work with an empty line

Problem:    CTRL-A does not work with an empty line. (Alex)
Solution:   Decrement the end only once. (Hirohito Higashi, closes #2387)
This commit is contained in:
Bram Moolenaar
2017-12-05 17:22:12 +01:00
parent 3767c6e9ee
commit 5fe6bdf858
3 changed files with 24 additions and 1 deletions

View File

@@ -5433,7 +5433,7 @@ op_addsub(
} }
else /* oap->motion_type == MCHAR */ else /* oap->motion_type == MCHAR */
{ {
if (!oap->inclusive) if (pos.lnum == oap->start.lnum && !oap->inclusive)
dec(&(oap->end)); dec(&(oap->end));
length = (colnr_T)STRLEN(ml_get(pos.lnum)); length = (colnr_T)STRLEN(ml_get(pos.lnum));
pos.col = 0; pos.col = 0;

View File

@@ -364,11 +364,25 @@ endfunc
" Expected: " Expected:
" 1) Ctrl-a on visually selected zero " 1) Ctrl-a on visually selected zero
" 111 " 111
"
" Also: 019 with "01" selected increments to "029".
func Test_visual_increment_15() func Test_visual_increment_15()
call setline(1, ["101"]) call setline(1, ["101"])
exec "norm! lv\<C-A>" exec "norm! lv\<C-A>"
call assert_equal(["111"], getline(1, '$')) call assert_equal(["111"], getline(1, '$'))
call assert_equal([0, 1, 2, 0], getpos('.')) call assert_equal([0, 1, 2, 0], getpos('.'))
call setline(1, ["019"])
exec "norm! 0vl\<C-A>"
call assert_equal("029", getline(1))
call setline(1, ["01239"])
exec "norm! 0vlll\<C-A>"
call assert_equal("01249", getline(1))
call setline(1, ["01299"])
exec "norm! 0vlll\<C-A>"
call assert_equal("1309", getline(1))
endfunc endfunc
" 16) increment right aligned numbers " 16) increment right aligned numbers
@@ -756,5 +770,12 @@ func Test_normal_increment_03()
call assert_equal([0, 3, 25, 0], getpos('.')) call assert_equal([0, 3, 25, 0], getpos('.'))
endfunc endfunc
func Test_increment_empty_line()
new
call setline(1, ['0', '0', '0', '0', '0', '0', ''])
exe "normal Gvgg\<C-A>"
call assert_equal(['1', '1', '1', '1', '1', '1', ''], getline(1, 7))
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -771,6 +771,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1374,
/**/ /**/
1373, 1373,
/**/ /**/