summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2024-07-25 21:24:32 +0200
committerChristian Brabandt <cb@256bit.org>2024-07-25 21:24:32 +0200
commitdc373d456b5919ed2b8f83e8642c115f646ca93d (patch)
treebe15488e5f9d377c39cdc71bcc57e4d734ee95ed
parenteb4b903c9b238ebcc1d14cfcb207129b4931a33d (diff)
patch 9.1.0617: Cursor moves beyond first line of folded end of bufferv9.1.0617
Problem: Cursor moves beyond start of a folded range at the end of a buffer. Solution: Move cursor to start of fold when going beyond end of buffer. Check that cursor moved to detect FAIL in outer cursor function. (Luuk van Baal) closes: #15344 Signed-off-by: Luuk van Baal <luukvbaal@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--src/edit.c8
-rw-r--r--src/testdir/test_fold.vim14
-rw-r--r--src/version.c2
3 files changed, 21 insertions, 3 deletions
diff --git a/src/edit.c b/src/edit.c
index e75a1cf118..8a37a61693 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -2849,7 +2849,6 @@ cursor_down_inner(win_T *wp, long n)
// count each sequence of folded lines as one logical line
while (n--)
{
- // Move to last line of fold, will fail if it's the end-of-file.
if (hasFoldingWin(wp, lnum, NULL, &last, TRUE, NULL))
lnum = last + 1;
else
@@ -2877,8 +2876,11 @@ cursor_down(
{
linenr_T lnum = curwin->w_cursor.lnum;
linenr_T line_count = curwin->w_buffer->b_ml.ml_line_count;
- // This fails if the cursor is already in the last line or would move
- // beyond the last line and '-' is in 'cpoptions'
+ // This fails if the cursor is already in the last (folded) line, or would
+ // move beyond the last line and '-' is in 'cpoptions'.
+#ifdef FEAT_FOLDING
+ hasFoldingWin(curwin, lnum, NULL, &lnum, TRUE, NULL);
+#endif
if (n > 0
&& (lnum >= line_count
|| (lnum + n > line_count
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim
index dedc4a2432..7fb0043311 100644
--- a/src/testdir/test_fold.vim
+++ b/src/testdir/test_fold.vim
@@ -1914,4 +1914,18 @@ func Test_foldexpr_end_fold()
bwipe!
endfunc
+" Test moving cursor down to or beyond start of folded end of buffer.
+func Test_cursor_down_fold_eob()
+ call setline(1, range(1, 4))
+ norm Gzf2kj
+ call assert_equal(2, line('.'))
+ norm zojzc
+ call assert_equal(3, line('.'))
+ norm j
+ call assert_equal(3, line('.'))
+ norm k2j
+ call assert_equal(4, line('.'))
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 9ee1592cf0..1a267fd3fd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 617,
+/**/
616,
/**/
615,