]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.5013: after text formatting cursor may be in an invalid position v8.2.5013
authorBram Moolenaar <Bram@vim.org>
Tue, 24 May 2022 12:57:54 +0000 (13:57 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 24 May 2022 12:57:54 +0000 (13:57 +0100)
Problem:    After text formatting the cursor may be in an invalid position.
Solution:   Correct the cursor position after formatting.

src/testdir/test_textformat.vim
src/textformat.c
src/version.c

index d33e2508d2793e5f0acd0d1e1199721585bea1b4..c5f597580154bc7970da6f5d3d2920bffa377db7 100644 (file)
@@ -1291,4 +1291,16 @@ func Test_fo_2()
   close!
 endfunc
 
+" This was leaving the cursor after the end of a line.  Complicated way to
+" have the problem show up with valgrind.
+func Test_correct_cursor_position()
+  set encoding=iso8859
+  new
+  norm a000\93\14\14\14\14\14\14\14\14\140
+  sil! norm gggg0i0\ f\ f\ fgw0gg
+
+  bwipe!
+  set encoding=utf8
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 7e32c1ccc3cb2943eccc9f95ff83294d1ba81bee..5ba2f1798ddb93cb31db1e596377e17274d2025d 100644 (file)
@@ -870,6 +870,9 @@ op_format(
     {
        curwin->w_cursor = saved_cursor;
        saved_cursor.lnum = 0;
+
+       // formatting may have made the cursor position invalid
+       check_cursor();
     }
 
     if (oap->is_VIsual)
index dea37d6cdd0d569b20f4fb484b74b077a1b995ed..f737b1b7d1402ade8bbc091a77e651f5a07f0a55 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5013,
 /**/
     5012,
 /**/