Skip to content

Commit 21b5038

Browse files
committed
patch 8.1.0690: setline() and setbufline() do not clear text properties
Problem: setline() and setbufline() do not clear text properties. Solution: Clear text properties when setting the text.
1 parent 7f1664e commit 21b5038

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/evalfunc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,10 @@ set_buffer_lines(
13571357

13581358
if (!append && lnum <= curbuf->b_ml.ml_line_count)
13591359
{
1360-
/* existing line, replace it */
1361-
if (u_savesub(lnum) == OK && ml_replace(lnum, line, TRUE) == OK)
1360+
// Existing line, replace it.
1361+
// Removes any existing text properties.
1362+
if (u_savesub(lnum) == OK && ml_replace_len(
1363+
lnum, line, (colnr_T)STRLEN(line) + 1, TRUE, TRUE) == OK)
13621364
{
13631365
changed_bytes(lnum, 0);
13641366
if (is_curbuf && lnum == curwin->w_cursor.lnum)

src/testdir/test_textprop.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,35 @@ func Test_prop_clear_buf()
261261
bwipe!
262262
endfunc
263263

264+
func Test_prop_setline()
265+
new
266+
call AddPropTypes()
267+
call SetupPropsInFirstLine()
268+
call assert_equal(s:expected_props, prop_list(1))
269+
270+
call setline(1, 'foobar')
271+
call assert_equal([], prop_list(1))
272+
273+
call DeletePropTypes()
274+
bwipe!
275+
endfunc
276+
277+
func Test_prop_setbufline()
278+
new
279+
call AddPropTypes()
280+
call SetupPropsInFirstLine()
281+
let bufnr = bufnr('')
282+
wincmd w
283+
call assert_equal(s:expected_props, prop_list(1, {'bufnr': bufnr}))
284+
285+
call setbufline(bufnr, 1, 'foobar')
286+
call assert_equal([], prop_list(1, {'bufnr': bufnr}))
287+
288+
wincmd w
289+
call DeletePropTypes()
290+
bwipe!
291+
endfunc
292+
264293
" Setup a three line prop in lines 2 - 4.
265294
" Add short props in line 1 and 5.
266295
func Setup_three_line_prop()

src/version.c

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

800800
static int included_patches[] =
801801
{ /* Add new patch number below this line */
802+
/**/
803+
690,
802804
/**/
803805
689,
804806
/**/

0 commit comments

Comments
 (0)