aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/normal.c17
-rw-r--r--src/nvim/testdir/test_fold.vim29
2 files changed, 27 insertions, 19 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 3b40689f3e..f016ef6813 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -3971,7 +3971,8 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
while (dist--) {
if (dir == BACKWARD) {
- if (curwin->w_curswant >= width1) {
+ if (curwin->w_curswant >= width1
+ && !hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
// Move back within the line. This can give a negative value
// for w_curswant if width1 < width2 (with cpoptions+=n),
// which will get clipped to column 0.
@@ -4003,14 +4004,16 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
else
n = width1;
- if (curwin->w_curswant + width2 < (colnr_T)n)
- /* move forward within line */
+ if (curwin->w_curswant + width2 < (colnr_T)n
+ && !hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
+ // move forward within line
curwin->w_curswant += width2;
- else {
- /* to next line */
- /* Move to the end of a closed fold. */
+ } else {
+ // to next line
+
+ // Move to the end of a closed fold.
(void)hasFolding(curwin->w_cursor.lnum, NULL,
- &curwin->w_cursor.lnum);
+ &curwin->w_cursor.lnum);
if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) {
retval = false;
break;
diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim
index 2d058e8e32..fcdf888b96 100644
--- a/src/nvim/testdir/test_fold.vim
+++ b/src/nvim/testdir/test_fold.vim
@@ -823,31 +823,36 @@ func Test_fold_create_delete()
endfunc
func Test_fold_relative_move()
- enew!
+ new
set fdm=indent sw=2 wrap tw=80
- let content = [ ' foo', ' bar', ' baz',
- \ repeat('x', &columns + 1),
- \ ' foo', ' bar', ' baz'
+ let longtext = repeat('x', &columns + 1)
+ let content = [ ' foo', ' ' .. longtext, ' baz',
+ \ longtext,
+ \ ' foo', ' ' .. longtext, ' baz'
\ ]
call append(0, content)
normal zM
- call cursor(3, 1)
- call assert_true(foldclosed(line('.')))
- normal gj
- call assert_equal(2, winline())
+ for lnum in range(1, 3)
+ call cursor(lnum, 1)
+ call assert_true(foldclosed(line('.')))
+ normal gj
+ call assert_equal(2, winline())
+ endfor
call cursor(2, 1)
call assert_true(foldclosed(line('.')))
normal 2gj
call assert_equal(3, winline())
- call cursor(5, 1)
- call assert_true(foldclosed(line('.')))
- normal gk
- call assert_equal(3, winline())
+ for lnum in range(5, 7)
+ call cursor(lnum, 1)
+ call assert_true(foldclosed(line('.')))
+ normal gk
+ call assert_equal(3, winline())
+ endfor
call cursor(6, 1)
call assert_true(foldclosed(line('.')))