Skip to content

Commit 35e802e

Browse files
committed
patch 8.0.1779: deleting in a block selection causes problems
Problem: Deleting in a block selection causes problems. Solution: Check the length of the line before adding bd.textcol and bd.textlen. (Christian Brabandt, closes #2825)
1 parent b07bbb0 commit 35e802e

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/ops.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,8 @@ op_insert(oparg_T *oap, long count1)
27032703
{
27042704
struct block_def bd2;
27052705
int did_indent = FALSE;
2706+
size_t len;
2707+
int add;
27062708

27072709
/* If indent kicked in, the firstline might have changed
27082710
* but only do that, if the indent actually increased. */
@@ -2781,9 +2783,15 @@ op_insert(oparg_T *oap, long count1)
27812783
* Subsequent calls to ml_get() flush the firstline data - take a
27822784
* copy of the required string.
27832785
*/
2784-
firstline = ml_get(oap->start.lnum) + bd.textcol;
2786+
firstline = ml_get(oap->start.lnum);
2787+
len = STRLEN(firstline);
2788+
add = bd.textcol;
27852789
if (oap->op_type == OP_APPEND)
2786-
firstline += bd.textlen;
2790+
add += bd.textlen;
2791+
if ((size_t)add > len)
2792+
firstline += len; // short line, point to the NUL
2793+
else
2794+
firstline += add;
27872795
if (pre_textlen >= 0
27882796
&& (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0)
27892797
{

src/testdir/test_blockedit.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,18 @@ func Test_blockinsert_indent()
1616
bwipe!
1717
endfunc
1818

19+
func Test_blockinsert_delete()
20+
new
21+
let _bs = &bs
22+
set bs=2
23+
call setline(1, ['case Arg is ', ' when Name_Async,', ' when Name_Num_Gangs,', 'end if;'])
24+
exe "norm! ggjVj\<c-v>$o$A\<bs>\<esc>"
25+
"call feedkeys("Vj\<c-v>$o$A\<bs>\<esc>", 'ti')
26+
call assert_equal(["case Arg is ", " when Name_Async", " when Name_Num_Gangs,", "end if;"],
27+
\ getline(1,'$'))
28+
" reset to sane state
29+
let &bs = _bs
30+
bwipe!
31+
endfunc
1932

2033
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1779,
764766
/**/
765767
1778,
766768
/**/

0 commit comments

Comments
 (0)