summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-24 13:57:54 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-24 13:57:54 +0100
commit78d52883e10d71f23ab72a3d8b9733b00da8c9ad (patch)
tree0b655f17192cb51e4bf2b411b6a42111b1cdf042
parent53737b5eeeab1f95964f78b055d6094fab559533 (diff)
downloadvim-git-8.2.5013.tar.gz
patch 8.2.5013: after text formatting cursor may be in an invalid positionv8.2.5013
Problem: After text formatting the cursor may be in an invalid position. Solution: Correct the cursor position after formatting.
-rw-r--r--src/testdir/test_textformat.vim12
-rw-r--r--src/textformat.c3
-rw-r--r--src/version.c2
3 files changed, 17 insertions, 0 deletions
diff --git a/src/testdir/test_textformat.vim b/src/testdir/test_textformat.vim
index d33e2508d..c5f597580 100644
--- a/src/testdir/test_textformat.vim
+++ b/src/testdir/test_textformat.vim
@@ -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“0
+ sil! norm gggg0i0gw0gg
+
+ bwipe!
+ set encoding=utf8
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/textformat.c b/src/textformat.c
index 7e32c1ccc..5ba2f1798 100644
--- a/src/textformat.c
+++ b/src/textformat.c
@@ -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)
diff --git a/src/version.c b/src/version.c
index dea37d6cd..f737b1b7d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 5013,
+/**/
5012,
/**/
5011,