mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Problem: When cursor is move for block append wrong text is inserted. Solution: Calculate an offset. (Christian Brabandt, closes #8433, closes #8288)
This commit is contained in:
69
src/ops.c
69
src/ops.c
@@ -545,6 +545,8 @@ block_insert(
|
|||||||
spaces -= off;
|
spaces -= off;
|
||||||
count -= off;
|
count -= off;
|
||||||
}
|
}
|
||||||
|
if (spaces < 0) // can happen when the cursor was moved
|
||||||
|
spaces = 0;
|
||||||
|
|
||||||
newp = alloc(STRLEN(oldp) + s_len + count + 1);
|
newp = alloc(STRLEN(oldp) + s_len + count + 1);
|
||||||
if (newp == NULL)
|
if (newp == NULL)
|
||||||
@@ -1455,6 +1457,9 @@ op_insert(oparg_T *oap, long count1)
|
|||||||
struct block_def bd;
|
struct block_def bd;
|
||||||
int i;
|
int i;
|
||||||
pos_T t1;
|
pos_T t1;
|
||||||
|
pos_T start_insert;
|
||||||
|
// offset when cursor was moved in insert mode
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
// edit() changes this - record it for OP_APPEND
|
// edit() changes this - record it for OP_APPEND
|
||||||
bd.is_MAX = (curwin->w_curswant == MAXCOL);
|
bd.is_MAX = (curwin->w_curswant == MAXCOL);
|
||||||
@@ -1526,6 +1531,7 @@ op_insert(oparg_T *oap, long count1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
t1 = oap->start;
|
t1 = oap->start;
|
||||||
|
start_insert = curwin->w_cursor;
|
||||||
(void)edit(NUL, FALSE, (linenr_T)count1);
|
(void)edit(NUL, FALSE, (linenr_T)count1);
|
||||||
|
|
||||||
// When a tab was inserted, and the characters in front of the tab
|
// When a tab was inserted, and the characters in front of the tab
|
||||||
@@ -1564,30 +1570,38 @@ op_insert(oparg_T *oap, long count1)
|
|||||||
if (oap->start.lnum == curbuf->b_op_start_orig.lnum
|
if (oap->start.lnum == curbuf->b_op_start_orig.lnum
|
||||||
&& !bd.is_MAX && !did_indent)
|
&& !bd.is_MAX && !did_indent)
|
||||||
{
|
{
|
||||||
if (oap->op_type == OP_INSERT
|
int t = getviscol2(curbuf->b_op_start_orig.col,
|
||||||
&& oap->start.col + oap->start.coladd
|
curbuf->b_op_start_orig.coladd);
|
||||||
!= curbuf->b_op_start_orig.col
|
|
||||||
+ curbuf->b_op_start_orig.coladd)
|
if (!bd.is_MAX)
|
||||||
{
|
{
|
||||||
int t = getviscol2(curbuf->b_op_start_orig.col,
|
if (oap->op_type == OP_INSERT
|
||||||
curbuf->b_op_start_orig.coladd);
|
&& oap->start.col + oap->start.coladd
|
||||||
oap->start.col = curbuf->b_op_start_orig.col;
|
!= curbuf->b_op_start_orig.col
|
||||||
pre_textlen -= t - oap->start_vcol;
|
+ curbuf->b_op_start_orig.coladd)
|
||||||
oap->start_vcol = t;
|
{
|
||||||
|
oap->start.col = curbuf->b_op_start_orig.col;
|
||||||
|
pre_textlen -= t - oap->start_vcol;
|
||||||
|
oap->start_vcol = t;
|
||||||
|
}
|
||||||
|
else if (oap->op_type == OP_APPEND
|
||||||
|
&& oap->end.col + oap->end.coladd
|
||||||
|
>= curbuf->b_op_start_orig.col
|
||||||
|
+ curbuf->b_op_start_orig.coladd)
|
||||||
|
{
|
||||||
|
oap->start.col = curbuf->b_op_start_orig.col;
|
||||||
|
// reset pre_textlen to the value of OP_INSERT
|
||||||
|
pre_textlen += bd.textlen;
|
||||||
|
pre_textlen -= t - oap->start_vcol;
|
||||||
|
oap->start_vcol = t;
|
||||||
|
oap->op_type = OP_INSERT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (oap->op_type == OP_APPEND
|
else if (bd.is_MAX && oap->op_type == OP_APPEND)
|
||||||
&& oap->end.col + oap->end.coladd
|
|
||||||
>= curbuf->b_op_start_orig.col
|
|
||||||
+ curbuf->b_op_start_orig.coladd)
|
|
||||||
{
|
{
|
||||||
int t = getviscol2(curbuf->b_op_start_orig.col,
|
|
||||||
curbuf->b_op_start_orig.coladd);
|
|
||||||
oap->start.col = curbuf->b_op_start_orig.col;
|
|
||||||
// reset pre_textlen to the value of OP_INSERT
|
// reset pre_textlen to the value of OP_INSERT
|
||||||
pre_textlen += bd.textlen;
|
pre_textlen += bd.textlen;
|
||||||
pre_textlen -= t - oap->start_vcol;
|
pre_textlen -= t - oap->start_vcol;
|
||||||
oap->start_vcol = t;
|
|
||||||
oap->op_type = OP_INSERT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1617,13 +1631,28 @@ op_insert(oparg_T *oap, long count1)
|
|||||||
len = STRLEN(firstline);
|
len = STRLEN(firstline);
|
||||||
add = bd.textcol;
|
add = bd.textcol;
|
||||||
if (oap->op_type == OP_APPEND)
|
if (oap->op_type == OP_APPEND)
|
||||||
|
{
|
||||||
add += bd.textlen;
|
add += bd.textlen;
|
||||||
|
// account for pressing cursor in insert mode when '$' was used
|
||||||
|
if (bd.is_MAX
|
||||||
|
&& (start_insert.lnum == Insstart.lnum
|
||||||
|
&& start_insert.col > Insstart.col))
|
||||||
|
{
|
||||||
|
offset = (start_insert.col - Insstart.col);
|
||||||
|
add -= offset;
|
||||||
|
if (oap->end_vcol > offset)
|
||||||
|
oap->end_vcol -= (offset + 1);
|
||||||
|
else
|
||||||
|
// moved outside of the visual block, what to do?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((size_t)add > len)
|
if ((size_t)add > len)
|
||||||
firstline += len; // short line, point to the NUL
|
firstline += len; // short line, point to the NUL
|
||||||
else
|
else
|
||||||
firstline += add;
|
firstline += add;
|
||||||
if (pre_textlen >= 0
|
if (pre_textlen >= 0 && (ins_len =
|
||||||
&& (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0)
|
(long)STRLEN(firstline) - pre_textlen - offset) > 0)
|
||||||
{
|
{
|
||||||
ins_text = vim_strnsave(firstline, ins_len);
|
ins_text = vim_strnsave(firstline, ins_len);
|
||||||
if (ins_text != NULL)
|
if (ins_text != NULL)
|
||||||
|
@@ -28,4 +28,52 @@ func Test_blockinsert_delete()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_blockappend_eol_cursor()
|
||||||
|
new
|
||||||
|
" Test 1 Move 1 char left
|
||||||
|
call setline(1, ['aaa', 'bbb', 'ccc'])
|
||||||
|
exe "norm! gg$\<c-v>2jA\<left>x\<esc>"
|
||||||
|
call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
|
||||||
|
" Test 2 Move 2 chars left
|
||||||
|
sil %d
|
||||||
|
call setline(1, ['aaa', 'bbb', 'ccc'])
|
||||||
|
exe "norm! gg$\<c-v>2jA\<left>\<left>x\<esc>"
|
||||||
|
call assert_equal(['axaa', 'bxbb', 'cxcc'], getline(1, '$'))
|
||||||
|
" Test 3 Move 3 chars left (outside of the visual selection)
|
||||||
|
sil %d
|
||||||
|
call setline(1, ['aaa', 'bbb', 'ccc'])
|
||||||
|
exe "norm! ggl$\<c-v>2jA\<left>\<left>\<left>x\<esc>"
|
||||||
|
call assert_equal(['xaaa', 'bbb', 'ccc'], getline(1, '$'))
|
||||||
|
bw!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_blockappend_eol_cursor2()
|
||||||
|
new
|
||||||
|
" Test 1 Move 1 char left
|
||||||
|
call setline(1, ['aaaaa', 'bbb', 'ccccc'])
|
||||||
|
exe "norm! gg\<c-v>$2jA\<left>x\<esc>"
|
||||||
|
call assert_equal(['aaaaxa', 'bbbx', 'ccccxc'], getline(1, '$'))
|
||||||
|
" Test 2 Move 2 chars left
|
||||||
|
sil %d
|
||||||
|
call setline(1, ['aaaaa', 'bbb', 'ccccc'])
|
||||||
|
exe "norm! gg\<c-v>$2jA\<left>\<left>x\<esc>"
|
||||||
|
call assert_equal(['aaaxaa', 'bbbx', 'cccxcc'], getline(1, '$'))
|
||||||
|
" Test 3 Move 3 chars left (to the beginning of the visual selection)
|
||||||
|
sil %d
|
||||||
|
call setline(1, ['aaaaa', 'bbb', 'ccccc'])
|
||||||
|
exe "norm! gg\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
|
||||||
|
call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
|
||||||
|
" Test 4 Move 3 chars left (outside of the visual selection)
|
||||||
|
sil %d
|
||||||
|
call setline(1, ['aaaaa', 'bbb', 'ccccc'])
|
||||||
|
exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>x\<esc>"
|
||||||
|
call assert_equal(['aaxaaa', 'bbxb', 'ccxccc'], getline(1, '$'))
|
||||||
|
" Test 5 Move 4 chars left (outside of the visual selection)
|
||||||
|
sil %d
|
||||||
|
call setline(1, ['aaaaa', 'bbb', 'ccccc'])
|
||||||
|
exe "norm! ggl\<c-v>$2jA\<left>\<left>\<left>\<left>x\<esc>"
|
||||||
|
call assert_equal(['axaaaa', 'bxbb', 'cxcccc'], getline(1, '$'))
|
||||||
|
bw!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -807,11 +807,7 @@ func Test_visual_block_mode()
|
|||||||
%d _
|
%d _
|
||||||
call setline(1, ['aaa', 'bbb', 'ccc'])
|
call setline(1, ['aaa', 'bbb', 'ccc'])
|
||||||
exe "normal $\<C-V>2jA\<Left>x"
|
exe "normal $\<C-V>2jA\<Left>x"
|
||||||
" BUG: Instead of adding x as the third character in all the three lines,
|
call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
|
||||||
" 'a' is added in the second and third lines at the end. This bug is not
|
|
||||||
" reproducible if this operation is performed manually.
|
|
||||||
"call assert_equal(['aaxa', 'bbxb', 'ccxc'], getline(1, '$'))
|
|
||||||
call assert_equal(['aaxa', 'bbba', 'ccca'], getline(1, '$'))
|
|
||||||
" Repeat the previous test but use 'l' to move the cursor instead of '$'
|
" Repeat the previous test but use 'l' to move the cursor instead of '$'
|
||||||
call setline(1, ['aaa', 'bbb', 'ccc'])
|
call setline(1, ['aaa', 'bbb', 'ccc'])
|
||||||
exe "normal! gg2l\<C-V>2jA\<Left>x"
|
exe "normal! gg2l\<C-V>2jA\<Left>x"
|
||||||
|
@@ -755,6 +755,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 */
|
||||||
|
/**/
|
||||||
|
3073,
|
||||||
/**/
|
/**/
|
||||||
3072,
|
3072,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user