]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4944: text properties are wrong after "cc" v8.2.4944
authorLemonBoy <thatlemon@gmail.com>
Thu, 12 May 2022 17:45:18 +0000 (18:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 12 May 2022 17:45:18 +0000 (18:45 +0100)
Problem:    Text properties are wrong after "cc". (Axel Forsman)
Solution:   Pass the deleted byte count to inserted_bytes(). (closes #10412,
            closes #7737, closes #5763)

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

index 1facaededa38dde51e135b9665c6aaa084290be6..8ba0a54f4ad215195980ee0b1e4248ad37e9edf5 100644 (file)
@@ -2349,11 +2349,15 @@ truncate_line(int fixpos)
     char_u     *newp;
     linenr_T   lnum = curwin->w_cursor.lnum;
     colnr_T    col = curwin->w_cursor.col;
+    char_u     *old_line;
+    int                deleted;
 
+    old_line = ml_get(lnum);
     if (col == 0)
        newp = vim_strsave((char_u *)"");
     else
-       newp = vim_strnsave(ml_get(lnum), col);
+       newp = vim_strnsave(old_line, col);
+    deleted = (int)STRLEN(old_line) - col;
 
     if (newp == NULL)
        return FAIL;
@@ -2361,7 +2365,7 @@ truncate_line(int fixpos)
     ml_replace(lnum, newp, FALSE);
 
     // mark the buffer as changed and prepare for displaying
-    changed_bytes(lnum, curwin->w_cursor.col);
+    inserted_bytes(lnum, curwin->w_cursor.col, -deleted);
 
     // If "fixpos" is TRUE we don't want to end up positioned at the NUL.
     if (fixpos && curwin->w_cursor.col > 0)
index 3dd676efc0de008f3fa5b202ad282e1243e970f1..fee3bdb6bb88b634c4cf85122c7fbb42f9523108 100644 (file)
@@ -534,6 +534,24 @@ func Test_prop_backspace()
   set bs&
 endfunc
 
+func Test_prop_change()
+  new
+  let expected = SetupOneLine() " 'xonex xtwoxx'
+
+  " Characterwise.
+  exe "normal 7|c$\<Esc>"
+  call assert_equal('xonex ', getline(1))
+  call assert_equal(expected[:0], prop_list(1))
+  " Linewise.
+  exe "normal cc\<Esc>"
+  call assert_equal('', getline(1))
+  call assert_equal([], prop_list(1))
+
+  call DeletePropTypes()
+  bwipe!
+  set bs&
+endfunc
+
 func Test_prop_replace()
   new
   set bs=2
index 0ebc9cbe92c8cb468f15b3ebf32b36a2def34c33..e2b8c348f98b7606c7cc51b3273ddae9ad54ff2e 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4944,
 /**/
     4943,
 /**/