Skip to content

Commit 1fd30d7

Browse files
committed
patch 8.1.2216: text property in wrong place after :substitute
Problem: Text property in wrong place after :substitute. Solution: Pass the new column instead of the old one. (Christian Brabandt, closes #4427)
1 parent 7aee687 commit 1fd30d7

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/ex_cmds.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3856,6 +3856,7 @@ do_sub(exarg_T *eap)
38563856
colnr_T matchcol;
38573857
colnr_T prev_matchcol = MAXCOL;
38583858
char_u *new_end, *new_start = NULL;
3859+
colnr_T total_added = 0;
38593860
unsigned new_start_len = 0;
38603861
char_u *p1;
38613862
int did_sub = FALSE;
@@ -4279,13 +4280,18 @@ do_sub(exarg_T *eap)
42794280
#ifdef FEAT_TEXT_PROP
42804281
if (curbuf->b_has_textprop)
42814282
{
4283+
int bytes_added = sublen - 1 - (regmatch.endpos[0].col
4284+
- regmatch.startpos[0].col);
4285+
42824286
// When text properties are changed, need to save for
42834287
// undo first, unless done already.
4284-
if (adjust_prop_columns(lnum, regmatch.startpos[0].col,
4285-
sublen - 1 - (regmatch.endpos[0].col
4286-
- regmatch.startpos[0].col),
4287-
apc_flags))
4288+
if (adjust_prop_columns(lnum,
4289+
total_added + regmatch.startpos[0].col,
4290+
bytes_added, apc_flags))
42884291
apc_flags &= ~APC_SAVE_FOR_UNDO;
4292+
// Offset for column byte number of the text property
4293+
// in the resulting buffer afterwards.
4294+
total_added += bytes_added;
42894295
}
42904296
#endif
42914297
}

src/testdir/test_textprop.vim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,3 +866,31 @@ func Test_textprop_in_unloaded_buf()
866866
cal delete('Xaaa')
867867
cal delete('Xbbb')
868868
endfunc
869+
870+
func Test_proptype_substitute2()
871+
new
872+
" text_prop.vim
873+
call setline(1, [
874+
\ 'The num 123 is smaller than 4567.',
875+
\ '123 The number 123 is smaller than 4567.',
876+
\ '123 The number 123 is smaller than 4567.'])
877+
878+
call prop_type_add('number', {'highlight': 'ErrorMsg'})
879+
880+
call prop_add(1, 12, {'length': 3, 'type': 'number'})
881+
call prop_add(2, 1, {'length': 3, 'type': 'number'})
882+
call prop_add(3, 36, {'length': 4, 'type': 'number'})
883+
set ul&
884+
let expected = [{'id': 0, 'col': 13, 'end': 1, 'type': 'number', 'length': 3, 'start': 1},
885+
\ {'id': 0, 'col': 1, 'end': 1, 'type': 'number', 'length': 3, 'start': 1},
886+
\ {'id': 0, 'col': 50, 'end': 1, 'type': 'number', 'length': 4, 'start': 1}]
887+
" Add some text in between
888+
%s/\s\+/ /g
889+
call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
890+
891+
" remove some text
892+
:1s/[a-z]\{3\}//g
893+
let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
894+
call assert_equal(expected, prop_list(1))
895+
bwipe!
896+
endfunc

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+
2216,
744746
/**/
745747
2215,
746748
/**/

0 commit comments

Comments
 (0)