]> granicus.if.org Git - vim/commitdiff
patch 8.1.0707: text property columns are not adjusted for changed indent v8.1.0707
authorBram Moolenaar <Bram@vim.org>
Tue, 8 Jan 2019 22:07:24 +0000 (23:07 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 8 Jan 2019 22:07:24 +0000 (23:07 +0100)
Problem:    Text property columns are not adjusted for changed indent.
Solution:   Adjust text properties.

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

index c2d2d19d2f3c564f2eed084ae3da111cac7d99a2..f8b726a93ba65aa59be8201dddfeb6149670bf90 100644 (file)
@@ -411,24 +411,29 @@ set_indent(
     }
     mch_memmove(s, p, (size_t)line_len);
 
-    /* Replace the line (unless undo fails). */
+    // Replace the line (unless undo fails).
     if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
     {
        ml_replace(curwin->w_cursor.lnum, newline, FALSE);
        if (flags & SIN_CHANGED)
            changed_bytes(curwin->w_cursor.lnum, 0);
-       /* Correct saved cursor position if it is in this line. */
+
+       // Correct saved cursor position if it is in this line.
        if (saved_cursor.lnum == curwin->w_cursor.lnum)
        {
            if (saved_cursor.col >= (colnr_T)(p - oldline))
-               /* cursor was after the indent, adjust for the number of
-                * bytes added/removed */
+               // cursor was after the indent, adjust for the number of
+               // bytes added/removed
                saved_cursor.col += ind_len - (colnr_T)(p - oldline);
            else if (saved_cursor.col >= (colnr_T)(s - newline))
-               /* cursor was in the indent, and is now after it, put it back
-                * at the start of the indent (replacing spaces with TAB) */
+               // cursor was in the indent, and is now after it, put it back
+               // at the start of the indent (replacing spaces with TAB)
                saved_cursor.col = (colnr_T)(s - newline);
        }
+#ifdef FEAT_TEXT_PROP
+       adjust_prop_columns(curwin->w_cursor.lnum, (colnr_T)(p - oldline),
+                                            ind_len - (colnr_T)(p - oldline));
+#endif
        retval = TRUE;
     }
     else
index 6f75521220c0c21b96463c98b84a7aec9d1ae049..311f30fbf3cf4a5659cd6f4f786ddcc46b69682b 100644 (file)
@@ -342,6 +342,40 @@ func Test_prop_substitute()
   bwipe!
 endfunc
 
+func Test_prop_change_indent()
+  call prop_type_add('comment', {'highlight': 'Directory'})
+  new
+  call setline(1, ['    xxx', 'yyyyy'])
+  call prop_add(2, 2, {'length': 2, 'type': 'comment'})
+  let expect = {'col': 2, 'length': 2, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0}
+  call assert_equal([expect], prop_list(2))
+
+  set shiftwidth=3
+  normal 2G>>
+  call assert_equal('   yyyyy', getline(2))
+  let expect.col += 3
+  call assert_equal([expect], prop_list(2))
+
+  normal 2G==
+  call assert_equal('    yyyyy', getline(2))
+  let expect.col = 6
+  call assert_equal([expect], prop_list(2))
+
+  call prop_clear(2)
+  call prop_add(2, 2, {'length': 5, 'type': 'comment'})
+  let expect.col = 2
+  let expect.length = 5
+  call assert_equal([expect], prop_list(2))
+
+  normal 2G<<
+  call assert_equal(' yyyyy', getline(2))
+  let expect.length = 2
+  call assert_equal([expect], prop_list(2))
+
+  set shiftwidth&
+  call prop_type_delete('comment')
+endfunc
+
 " Setup a three line prop in lines 2 - 4.
 " Add short props in line 1 and 5.
 func Setup_three_line_prop()
index 768c384c645dcb69898220ddf53cc26ba3eb6fd7..e9a5a43b7716088a5a61bfa38d0d6a9ba8c9882b 100644 (file)
@@ -799,6 +799,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    707,
 /**/
     706,
 /**/