Skip to content

Commit

Permalink
patch 8.2.5013: after text formatting cursor may be in an invalid pos…
Browse files Browse the repository at this point in the history
…ition

Problem:    After text formatting the cursor may be in an invalid position.
Solution:   Correct the cursor position after formatting.
  • Loading branch information
brammool committed May 24, 2022
1 parent 53737b5 commit 78d5288
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/testdir/test_textformat.vim
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/textformat.c
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -734,6 +734,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
5013,
/**/
5012,
/**/
Expand Down

0 comments on commit 78d5288

Please sign in to comment.