From 6ed20ff25cd738ab2b9e79af8e3a9c37ba52dbcf Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 12 May 2019 09:08:31 -0400 Subject: vim-patch:8.1.1327: unnecessary scroll after horizontal split Problem: Unnecessary scroll after horizontal split. Solution: Don't adjust to fraction if all the text fits in the window. (Martin Kunev, closes vim/vim#4367) https://github.com/vim/vim/commit/a9b2535f44f3265940a18d08520a9ad4ef7bda82 --- src/nvim/testdir/test_window_cmd.vim | 36 ++++++++++++++++++++++++++++++++++++ src/nvim/window.c | 7 +++++-- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 72f1baf39e..c41f4f9412 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -756,6 +756,42 @@ func Test_relative_cursor_second_line_after_resize() let &so = so_save endfunc +func Test_split_noscroll() + let so_save = &so + new + only + + " Make sure windows can hold all content after split. + for i in range(1, 20) + wincmd + + redraw! + endfor + + call setline (1, range(1, 8)) + normal 100% + split + + 1wincmd w + let winid1 = win_getid() + let info1 = getwininfo(winid1)[0] + + 2wincmd w + let winid2 = win_getid() + let info2 = getwininfo(winid2)[0] + + call assert_equal(1, info1.topline) + call assert_equal(1, info2.topline) + + " Restore original state. + for i in range(1, 20) + wincmd - + redraw! + endfor + only! + bwipe! + let &so = so_save +endfunc + " Tests for the winnr() function func Test_winnr() only | tabonly diff --git a/src/nvim/window.c b/src/nvim/window.c index d7df048588..1f23646bdf 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5610,10 +5610,13 @@ void scroll_to_fraction(win_T *wp, int prev_height) int sline, line_size; int height = wp->w_height_inner; - // Don't change w_topline when height is zero. Don't set w_topline when - // 'scrollbind' is set and this isn't the current window. + // Don't change w_topline in any of these cases: + // - window height is 0 + // - 'scrollbind' is set and this isn't the current window + // - window height is sufficient to display the whole buffer if (height > 0 && (!wp->w_p_scb || wp == curwin) + && (height < wp->w_buffer->b_ml.ml_line_count) ) { /* * Find a value for w_topline that shows the cursor at the same -- cgit