Skip to content

Commit ecafcc1

Browse files
committed
patch 8.1.2308: deleting text before zero-width textprop removes it
Problem: Deleting text before zero-width textprop removes it. Solution: Keep zero-width textprop when deleting text.
1 parent a37cb55 commit ecafcc1

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/testdir/test_textprop.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,35 @@ func Test_prop_undo()
650650
call prop_type_delete('comment')
651651
endfunc
652652

653+
func Test_prop_delete_text()
654+
new
655+
call prop_type_add('comment', {'highlight': 'Directory'})
656+
call setline(1, ['oneone', 'twotwo', 'three'])
657+
658+
" zero length property
659+
call prop_add(1, 3, {'type': 'comment'})
660+
let expected = [{'col': 3, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
661+
call assert_equal(expected, prop_list(1))
662+
663+
" delete one char moves the property
664+
normal! x
665+
let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
666+
call assert_equal(expected, prop_list(1))
667+
668+
" delete char of the property has no effect
669+
normal! lx
670+
let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
671+
call assert_equal(expected, prop_list(1))
672+
673+
" delete more chars moves property to first column, is not deleted
674+
normal! 0xxxx
675+
let expected = [{'col': 1, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
676+
call assert_equal(expected, prop_list(1))
677+
678+
bwipe!
679+
call prop_type_delete('comment')
680+
endfunc
681+
653682
" screenshot test with textprop highlighting
654683
func Test_textprop_screenshot_various()
655684
CheckScreendump

src/textprop.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,18 +1075,21 @@ adjust_prop_columns(
10751075
}
10761076
else if (bytes_added <= 0 && (tmp_prop.tp_col > col + 1))
10771077
{
1078+
int len_changed = FALSE;
1079+
10781080
if (tmp_prop.tp_col + bytes_added < col + 1)
10791081
{
10801082
tmp_prop.tp_len += (tmp_prop.tp_col - 1 - col) + bytes_added;
10811083
tmp_prop.tp_col = col + 1;
1084+
len_changed = TRUE;
10821085
}
10831086
else
10841087
tmp_prop.tp_col += bytes_added;
10851088
// Save for undo if requested and not done yet.
10861089
if ((flags & APC_SAVE_FOR_UNDO) && !dirty)
10871090
u_savesub(lnum);
10881091
dirty = TRUE;
1089-
if (tmp_prop.tp_len <= 0)
1092+
if (len_changed && tmp_prop.tp_len <= 0)
10901093
continue; // drop this text property
10911094
}
10921095
else if (tmp_prop.tp_len > 0

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2308,
744746
/**/
745747
2307,
746748
/**/

0 commit comments

Comments
 (0)