]> granicus.if.org Git - vim/commitdiff
patch 8.1.0690: setline() and setbufline() do not clear text properties v8.1.0690
authorBram Moolenaar <Bram@vim.org>
Fri, 4 Jan 2019 17:07:24 +0000 (18:07 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 4 Jan 2019 17:07:24 +0000 (18:07 +0100)
Problem:    setline() and setbufline() do not clear text properties.
Solution:   Clear text properties when setting the text.

src/evalfunc.c
src/testdir/test_textprop.vim
src/version.c

index 8e530f43e1364e0040bb3fb6f012090167e5f4fc..58f58060ef78556f0f95a2963c2cb632d190e5de 100644 (file)
@@ -1357,8 +1357,10 @@ set_buffer_lines(
 
        if (!append && lnum <= curbuf->b_ml.ml_line_count)
        {
-           /* existing line, replace it */
-           if (u_savesub(lnum) == OK && ml_replace(lnum, line, TRUE) == OK)
+           // Existing line, replace it.
+           // Removes any existing text properties.
+           if (u_savesub(lnum) == OK && ml_replace_len(
+                     lnum, line, (colnr_T)STRLEN(line) + 1, TRUE, TRUE) == OK)
            {
                changed_bytes(lnum, 0);
                if (is_curbuf && lnum == curwin->w_cursor.lnum)
index ac9967e9498c65777696a1d4fb2e3daa25f97988..d5069d4a70f73004a25c2fd97e6fda78c8bc708c 100644 (file)
@@ -261,6 +261,35 @@ func Test_prop_clear_buf()
   bwipe!
 endfunc
 
+func Test_prop_setline()
+  new
+  call AddPropTypes()
+  call SetupPropsInFirstLine()
+  call assert_equal(s:expected_props, prop_list(1))
+
+  call setline(1, 'foobar')
+  call assert_equal([], prop_list(1))
+
+  call DeletePropTypes()
+  bwipe!
+endfunc
+
+func Test_prop_setbufline()
+  new
+  call AddPropTypes()
+  call SetupPropsInFirstLine()
+  let bufnr = bufnr('')
+  wincmd w
+  call assert_equal(s:expected_props, prop_list(1, {'bufnr': bufnr}))
+
+  call setbufline(bufnr, 1, 'foobar')
+  call assert_equal([], prop_list(1, {'bufnr': bufnr}))
+
+  wincmd w
+  call DeletePropTypes()
+  bwipe!
+endfunc
+
 " Setup a three line prop in lines 2 - 4.
 " Add short props in line 1 and 5.
 func Setup_three_line_prop()
index 4b7c9ae355a865eba642c6a07b313cba0cfbfcca..8e14a2e29efc4d0da9c455ba26d8fff62a3b9a87 100644 (file)
@@ -799,6 +799,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    690,
 /**/
     689,
 /**/