Skip to content

Commit 907dad7

Browse files
committed
patch 8.1.0174: after paging up and down fold line is wrong
Problem: After paging up and down fold line is wrong. Solution: Correct the computation of w_topline and w_botline. (Hirohito Higashi)
1 parent 6259e57 commit 907dad7

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

src/move.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,22 +2457,27 @@ onepage(int dir, long count)
24572457
beginline(BL_SOL | BL_FIX);
24582458
curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL);
24592459

2460-
/*
2461-
* Avoid the screen jumping up and down when 'scrolloff' is non-zero.
2462-
* But make sure we scroll at least one line (happens with mix of long
2463-
* wrapping lines and non-wrapping line).
2464-
*/
2465-
if (retval == OK && dir == FORWARD && check_top_offset())
2460+
if (retval == OK && dir == FORWARD)
24662461
{
2467-
scroll_cursor_top(1, FALSE);
2468-
if (curwin->w_topline <= old_topline
2469-
&& old_topline < curbuf->b_ml.ml_line_count)
2462+
// Avoid the screen jumping up and down when 'scrolloff' is non-zero.
2463+
// But make sure we scroll at least one line (happens with mix of long
2464+
// wrapping lines and non-wrapping line).
2465+
if (check_top_offset())
24702466
{
2471-
curwin->w_topline = old_topline + 1;
2467+
scroll_cursor_top(1, FALSE);
2468+
if (curwin->w_topline <= old_topline
2469+
&& old_topline < curbuf->b_ml.ml_line_count)
2470+
{
2471+
curwin->w_topline = old_topline + 1;
24722472
#ifdef FEAT_FOLDING
2473-
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
2473+
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
24742474
#endif
2475+
}
24752476
}
2477+
#ifdef FEAT_FOLDING
2478+
else if (curwin->w_botline > curbuf->b_ml.ml_line_count)
2479+
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
2480+
#endif
24762481
}
24772482

24782483
redraw_later(VALID);

src/testdir/test_fold.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Test for folding
22

3+
source view_util.vim
4+
35
func PrepIndent(arg)
46
return [a:arg] + repeat(["\t".a:arg], 5)
57
endfu
@@ -648,3 +650,27 @@ func Test_foldopen_exception()
648650
endtry
649651
call assert_match('E492:', a)
650652
endfunc
653+
654+
func Test_fold_last_line_with_pagedown()
655+
enew!
656+
set fdm=manual
657+
658+
let expect = '+-- 11 lines: 9---'
659+
let content = range(1,19)
660+
call append(0, content)
661+
normal dd9G
662+
normal zfG
663+
normal zt
664+
call assert_equal('9', getline(foldclosed('.')))
665+
call assert_equal('19', getline(foldclosedend('.')))
666+
call assert_equal(expect, ScreenLines(1, len(expect))[0])
667+
call feedkeys("\<C-F>", 'xt')
668+
call assert_equal(expect, ScreenLines(1, len(expect))[0])
669+
call feedkeys("\<C-F>", 'xt')
670+
call assert_equal(expect, ScreenLines(1, len(expect))[0])
671+
call feedkeys("\<C-B>\<C-F>\<C-F>", 'xt')
672+
call assert_equal(expect, ScreenLines(1, len(expect))[0])
673+
674+
set fdm&
675+
enew!
676+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
174,
792794
/**/
793795
173,
794796
/**/

0 commit comments

Comments
 (0)