mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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)
This commit is contained in:
@@ -3856,6 +3856,7 @@ do_sub(exarg_T *eap)
|
|||||||
colnr_T matchcol;
|
colnr_T matchcol;
|
||||||
colnr_T prev_matchcol = MAXCOL;
|
colnr_T prev_matchcol = MAXCOL;
|
||||||
char_u *new_end, *new_start = NULL;
|
char_u *new_end, *new_start = NULL;
|
||||||
|
colnr_T total_added = 0;
|
||||||
unsigned new_start_len = 0;
|
unsigned new_start_len = 0;
|
||||||
char_u *p1;
|
char_u *p1;
|
||||||
int did_sub = FALSE;
|
int did_sub = FALSE;
|
||||||
@@ -4279,13 +4280,18 @@ do_sub(exarg_T *eap)
|
|||||||
#ifdef FEAT_TEXT_PROP
|
#ifdef FEAT_TEXT_PROP
|
||||||
if (curbuf->b_has_textprop)
|
if (curbuf->b_has_textprop)
|
||||||
{
|
{
|
||||||
|
int bytes_added = sublen - 1 - (regmatch.endpos[0].col
|
||||||
|
- regmatch.startpos[0].col);
|
||||||
|
|
||||||
// When text properties are changed, need to save for
|
// When text properties are changed, need to save for
|
||||||
// undo first, unless done already.
|
// undo first, unless done already.
|
||||||
if (adjust_prop_columns(lnum, regmatch.startpos[0].col,
|
if (adjust_prop_columns(lnum,
|
||||||
sublen - 1 - (regmatch.endpos[0].col
|
total_added + regmatch.startpos[0].col,
|
||||||
- regmatch.startpos[0].col),
|
bytes_added, apc_flags))
|
||||||
apc_flags))
|
|
||||||
apc_flags &= ~APC_SAVE_FOR_UNDO;
|
apc_flags &= ~APC_SAVE_FOR_UNDO;
|
||||||
|
// Offset for column byte number of the text property
|
||||||
|
// in the resulting buffer afterwards.
|
||||||
|
total_added += bytes_added;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -866,3 +866,31 @@ func Test_textprop_in_unloaded_buf()
|
|||||||
cal delete('Xaaa')
|
cal delete('Xaaa')
|
||||||
cal delete('Xbbb')
|
cal delete('Xbbb')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_proptype_substitute2()
|
||||||
|
new
|
||||||
|
" text_prop.vim
|
||||||
|
call setline(1, [
|
||||||
|
\ 'The num 123 is smaller than 4567.',
|
||||||
|
\ '123 The number 123 is smaller than 4567.',
|
||||||
|
\ '123 The number 123 is smaller than 4567.'])
|
||||||
|
|
||||||
|
call prop_type_add('number', {'highlight': 'ErrorMsg'})
|
||||||
|
|
||||||
|
call prop_add(1, 12, {'length': 3, 'type': 'number'})
|
||||||
|
call prop_add(2, 1, {'length': 3, 'type': 'number'})
|
||||||
|
call prop_add(3, 36, {'length': 4, 'type': 'number'})
|
||||||
|
set ul&
|
||||||
|
let expected = [{'id': 0, 'col': 13, 'end': 1, 'type': 'number', 'length': 3, 'start': 1},
|
||||||
|
\ {'id': 0, 'col': 1, 'end': 1, 'type': 'number', 'length': 3, 'start': 1},
|
||||||
|
\ {'id': 0, 'col': 50, 'end': 1, 'type': 'number', 'length': 4, 'start': 1}]
|
||||||
|
" Add some text in between
|
||||||
|
%s/\s\+/ /g
|
||||||
|
call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
|
||||||
|
|
||||||
|
" remove some text
|
||||||
|
:1s/[a-z]\{3\}//g
|
||||||
|
let expected = [{'id': 0, 'col': 10, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}]
|
||||||
|
call assert_equal(expected, prop_list(1))
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
@@ -741,6 +741,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 */
|
||||||
|
/**/
|
||||||
|
2216,
|
||||||
/**/
|
/**/
|
||||||
2215,
|
2215,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user