mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.1.1351: text property wrong after :substitute
Problem: Text property wrong after :substitute. Solution: Save for undo before changing any text properties.
This commit is contained in:
parent
dc6855af97
commit
338dfdad38
@ -684,7 +684,7 @@ inserted_bytes(linenr_T lnum, colnr_T col, int added UNUSED)
|
|||||||
{
|
{
|
||||||
#ifdef FEAT_TEXT_PROP
|
#ifdef FEAT_TEXT_PROP
|
||||||
if (curbuf->b_has_textprop && added != 0)
|
if (curbuf->b_has_textprop && added != 0)
|
||||||
adjust_prop_columns(lnum, col, added);
|
adjust_prop_columns(lnum, col, added, FALSE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
changed_bytes(lnum, col);
|
changed_bytes(lnum, col);
|
||||||
|
@ -4104,7 +4104,7 @@ replace_do_bs(int limit_col)
|
|||||||
|
|
||||||
--text_prop_frozen;
|
--text_prop_frozen;
|
||||||
adjust_prop_columns(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
adjust_prop_columns(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
||||||
(int)(len_now - len_before));
|
(int)(len_now - len_before), FALSE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -5187,6 +5187,9 @@ do_sub(exarg_T *eap)
|
|||||||
int do_again; /* do it again after joining lines */
|
int do_again; /* do it again after joining lines */
|
||||||
int skip_match = FALSE;
|
int skip_match = FALSE;
|
||||||
linenr_T sub_firstlnum; /* nr of first sub line */
|
linenr_T sub_firstlnum; /* nr of first sub line */
|
||||||
|
#ifdef FEAT_TEXT_PROP
|
||||||
|
int save_for_undo = TRUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The new text is build up step by step, to avoid too much
|
* The new text is build up step by step, to avoid too much
|
||||||
@ -5603,9 +5606,14 @@ do_sub(exarg_T *eap)
|
|||||||
p1 = sub_firstline;
|
p1 = sub_firstline;
|
||||||
#ifdef FEAT_TEXT_PROP
|
#ifdef FEAT_TEXT_PROP
|
||||||
if (curbuf->b_has_textprop)
|
if (curbuf->b_has_textprop)
|
||||||
adjust_prop_columns(lnum, regmatch.startpos[0].col,
|
{
|
||||||
|
// When text properties are changed, need to save for
|
||||||
|
// undo first, unless done already.
|
||||||
|
if (adjust_prop_columns(lnum, regmatch.startpos[0].col,
|
||||||
sublen - 1 - (regmatch.endpos[0].col
|
sublen - 1 - (regmatch.endpos[0].col
|
||||||
- regmatch.startpos[0].col));
|
- regmatch.startpos[0].col), save_for_undo))
|
||||||
|
save_for_undo = FALSE;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -441,7 +441,7 @@ set_indent(
|
|||||||
// the old indent, when decreasing indent it behaves like spaces
|
// the old indent, when decreasing indent it behaves like spaces
|
||||||
// were deleted at the new indent.
|
// were deleted at the new indent.
|
||||||
adjust_prop_columns(curwin->w_cursor.lnum,
|
adjust_prop_columns(curwin->w_cursor.lnum,
|
||||||
(colnr_T)(added > 0 ? (p - oldline) : ind_len), added);
|
(colnr_T)(added > 0 ? (p - oldline) : ind_len), added, FALSE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
retval = TRUE;
|
retval = TRUE;
|
||||||
|
@ -1937,7 +1937,7 @@ op_delete(oparg_T *oap)
|
|||||||
|
|
||||||
#ifdef FEAT_TEXT_PROP
|
#ifdef FEAT_TEXT_PROP
|
||||||
if (curbuf->b_has_textprop && n != 0)
|
if (curbuf->b_has_textprop && n != 0)
|
||||||
adjust_prop_columns(lnum, bd.textcol, -n);
|
adjust_prop_columns(lnum, bd.textcol, -n, FALSE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ void f_prop_type_get(typval_T *argvars, typval_T *rettv);
|
|||||||
void f_prop_type_list(typval_T *argvars, typval_T *rettv);
|
void f_prop_type_list(typval_T *argvars, typval_T *rettv);
|
||||||
void clear_global_prop_types(void);
|
void clear_global_prop_types(void);
|
||||||
void clear_buf_prop_types(buf_T *buf);
|
void clear_buf_prop_types(buf_T *buf);
|
||||||
void adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added);
|
int adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added, int save_for_undo);
|
||||||
void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted);
|
void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted);
|
||||||
void adjust_props_for_join(linenr_T lnum, textprop_T **prop_line, int *prop_length, long col, int removed);
|
void adjust_props_for_join(linenr_T lnum, textprop_T **prop_line, int *prop_length, long col, int removed);
|
||||||
void join_prop_lines(linenr_T lnum, char_u *newp, textprop_T **prop_lines, int *prop_lengths, int count);
|
void join_prop_lines(linenr_T lnum, char_u *newp, textprop_T **prop_lines, int *prop_lengths, int count);
|
||||||
|
@ -608,6 +608,19 @@ func Test_prop_undo()
|
|||||||
let expected[0].length = 2
|
let expected[0].length = 2
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
|
" substitute a word, then undo
|
||||||
|
call setline(1, 'the number 123 is highlighted.')
|
||||||
|
call prop_add(1, 12, {'length': 3, 'type': 'comment'})
|
||||||
|
let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
||||||
|
call assert_equal(expected, prop_list(1))
|
||||||
|
set ul&
|
||||||
|
1s/number/foo
|
||||||
|
let expected[0].col = 9
|
||||||
|
call assert_equal(expected, prop_list(1))
|
||||||
|
undo
|
||||||
|
let expected[0].col = 12
|
||||||
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
call prop_type_delete('comment')
|
call prop_type_delete('comment')
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -957,13 +957,17 @@ clear_buf_prop_types(buf_T *buf)
|
|||||||
* shift by "bytes_added" (can be negative).
|
* shift by "bytes_added" (can be negative).
|
||||||
* Note that "col" is zero-based, while tp_col is one-based.
|
* Note that "col" is zero-based, while tp_col is one-based.
|
||||||
* Only for the current buffer.
|
* Only for the current buffer.
|
||||||
|
* When "save_for_undo" is TRUE then call u_savesub() before making changes to
|
||||||
|
* the line.
|
||||||
* Caller is expected to check b_has_textprop and "bytes_added" being non-zero.
|
* Caller is expected to check b_has_textprop and "bytes_added" being non-zero.
|
||||||
|
* Returns TRUE when props were changed.
|
||||||
*/
|
*/
|
||||||
void
|
int
|
||||||
adjust_prop_columns(
|
adjust_prop_columns(
|
||||||
linenr_T lnum,
|
linenr_T lnum,
|
||||||
colnr_T col,
|
colnr_T col,
|
||||||
int bytes_added)
|
int bytes_added,
|
||||||
|
int save_for_undo)
|
||||||
{
|
{
|
||||||
int proplen;
|
int proplen;
|
||||||
char_u *props;
|
char_u *props;
|
||||||
@ -974,11 +978,11 @@ adjust_prop_columns(
|
|||||||
size_t textlen;
|
size_t textlen;
|
||||||
|
|
||||||
if (text_prop_frozen > 0)
|
if (text_prop_frozen > 0)
|
||||||
return;
|
return FALSE;
|
||||||
|
|
||||||
proplen = get_text_props(curbuf, lnum, &props, TRUE);
|
proplen = get_text_props(curbuf, lnum, &props, TRUE);
|
||||||
if (proplen == 0)
|
if (proplen == 0)
|
||||||
return;
|
return FALSE;
|
||||||
textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
|
textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
|
||||||
|
|
||||||
wi = 0; // write index
|
wi = 0; // write index
|
||||||
@ -1001,6 +1005,9 @@ adjust_prop_columns(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
tmp_prop.tp_col += bytes_added;
|
tmp_prop.tp_col += bytes_added;
|
||||||
|
// Save for undo if requested and not done yet.
|
||||||
|
if (save_for_undo && !dirty)
|
||||||
|
u_savesub(lnum);
|
||||||
dirty = TRUE;
|
dirty = TRUE;
|
||||||
if (tmp_prop.tp_len <= 0)
|
if (tmp_prop.tp_len <= 0)
|
||||||
continue; // drop this text property
|
continue; // drop this text property
|
||||||
@ -1016,6 +1023,9 @@ adjust_prop_columns(
|
|||||||
tmp_prop.tp_len += bytes_added + after;
|
tmp_prop.tp_len += bytes_added + after;
|
||||||
else
|
else
|
||||||
tmp_prop.tp_len += bytes_added;
|
tmp_prop.tp_len += bytes_added;
|
||||||
|
// Save for undo if requested and not done yet.
|
||||||
|
if (save_for_undo && !dirty)
|
||||||
|
u_savesub(lnum);
|
||||||
dirty = TRUE;
|
dirty = TRUE;
|
||||||
if (tmp_prop.tp_len <= 0)
|
if (tmp_prop.tp_len <= 0)
|
||||||
continue; // drop this text property
|
continue; // drop this text property
|
||||||
@ -1034,6 +1044,7 @@ adjust_prop_columns(
|
|||||||
curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
|
curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
|
||||||
curbuf->b_ml.ml_line_len = newlen;
|
curbuf->b_ml.ml_line_len = newlen;
|
||||||
}
|
}
|
||||||
|
return dirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -767,6 +767,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 */
|
||||||
|
/**/
|
||||||
|
1351,
|
||||||
/**/
|
/**/
|
||||||
1350,
|
1350,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user