Skip to content

Commit bd2d68c

Browse files
committed
patch 8.1.1347: fractional scroll position not restored after closing window
Problem: Fractional scroll position not restored after closing window. Solution: Do restore fraction if topline is not one.
1 parent 7f3a284 commit bd2d68c

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/testdir/test_window_cmd.vim

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -745,16 +745,8 @@ endfunc
745745

746746
func Test_split_noscroll()
747747
let so_save = &so
748-
new
749-
only
750-
751-
" Make sure windows can hold all content after split.
752-
for i in range(1, 20)
753-
wincmd +
754-
redraw!
755-
endfor
756-
757-
call setline (1, range(1, 8))
748+
enew
749+
call setline(1, range(1, 8))
758750
normal 100%
759751
split
760752

@@ -769,12 +761,20 @@ func Test_split_noscroll()
769761
call assert_equal(1, info1.topline)
770762
call assert_equal(1, info2.topline)
771763

772-
" Restore original state.
773-
for i in range(1, 20)
774-
wincmd -
775-
redraw!
776-
endfor
764+
" window that fits all lines by itself, but not when split: closing other
765+
" window should restore fraction.
777766
only!
767+
call setline(1, range(1, &lines - 10))
768+
exe &lines / 4
769+
let winid1 = win_getid()
770+
let info1 = getwininfo(winid1)[0]
771+
call assert_equal(1, info1.topline)
772+
new
773+
redraw
774+
close
775+
let info1 = getwininfo(winid1)[0]
776+
call assert_equal(1, info1.topline)
777+
778778
bwipe!
779779
let &so = so_save
780780
endfunc

src/version.c

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

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1347,
770772
/**/
771773
1346,
772774
/**/

src/window.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5830,10 +5830,11 @@ scroll_to_fraction(win_T *wp, int prev_height)
58305830
// Don't change w_topline in any of these cases:
58315831
// - window height is 0
58325832
// - 'scrollbind' is set and this isn't the current window
5833-
// - window height is sufficient to display the whole buffer
5833+
// - window height is sufficient to display the whole buffer and first line
5834+
// is visible.
58345835
if (height > 0
58355836
&& (!wp->w_p_scb || wp == curwin)
5836-
&& (height < wp->w_buffer->b_ml.ml_line_count))
5837+
&& (height < wp->w_buffer->b_ml.ml_line_count || wp->w_topline > 1))
58375838
{
58385839
/*
58395840
* Find a value for w_topline that shows the cursor at the same

0 commit comments

Comments
 (0)