diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-02 05:55:07 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-08-02 05:58:51 +0800 |
commit | 50672e3850ddd0ddacfcdcd536922440fb719093 (patch) | |
tree | 3adccf6e926d21361994e7e3b86a691bda70d0a5 /src | |
parent | 4f576be881a590172fa620214af6c9a42e98d132 (diff) | |
download | rneovim-50672e3850ddd0ddacfcdcd536922440fb719093.tar.gz rneovim-50672e3850ddd0ddacfcdcd536922440fb719093.tar.bz2 rneovim-50672e3850ddd0ddacfcdcd536922440fb719093.zip |
vim-patch:8.2.5013: after text formatting cursor may be in an invalid position
Problem: After text formatting the cursor may be in an invalid position.
Solution: Correct the cursor position after formatting.
https://github.com/vim/vim/commit/78d52883e10d71f23ab72a3d8b9733b00da8c9ad
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ops.c | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_textformat.vim | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index cc67b0d0c1..0bcc5ecd0e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4349,6 +4349,9 @@ static void op_format(oparg_T *oap, int keep_cursor) if (keep_cursor) { 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/nvim/testdir/test_textformat.vim b/src/nvim/testdir/test_textformat.vim index 1d1f20d91a..0fc56083aa 100644 --- a/src/nvim/testdir/test_textformat.vim +++ b/src/nvim/testdir/test_textformat.vim @@ -1534,4 +1534,16 @@ func Test_autoformat_comments() 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 a0000 + sil! norm gggg0i0gw0gg + + bwipe! + set encoding=utf8 +endfunc + " vim: shiftwidth=2 sts=2 expandtab |