aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/diff.c14
-rw-r--r--src/nvim/move.c11
-rw-r--r--src/nvim/testdir/test_diffmode.vim24
3 files changed, 46 insertions, 3 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 26269a44d2..fd5b2c6599 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -639,12 +639,18 @@ static int diff_check_sanity(tabpage_T *tp, diff_T *dp)
/// @param dofold Also recompute the folds
void diff_redraw(bool dofold)
{
+ win_T *wp_other = NULL;
+ bool used_max_fill = false;
+
need_diff_redraw = false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (!wp->w_p_diff) {
continue;
}
redraw_later(wp, SOME_VALID);
+ if (wp != curwin) {
+ wp_other = wp;
+ }
if (dofold && foldmethodIsDiff(wp)) {
foldUpdateAll(wp);
}
@@ -658,10 +664,18 @@ void diff_redraw(bool dofold)
wp->w_topfill = (n < 0 ? 0 : n);
} else if ((n > 0) && (n > wp->w_topfill)) {
wp->w_topfill = n;
+ if (wp == curwin) {
+ used_max_fill = true;
+ }
}
check_topfill(wp, false);
}
}
+ if (wp_other != NULL && used_max_fill && curwin->w_p_scb) {
+ // The current window was set to used the maximum number of filler
+ // lines, may need to reduce them.
+ diff_set_topline(wp_other, curwin);
+ }
}
static void clear_diffin(diffin_T *din)
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 21cbac4d79..9fc434923f 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -453,13 +453,18 @@ void changed_window_setting_win(win_T *wp)
*/
void set_topline(win_T *wp, linenr_T lnum)
{
- /* go to first of folded lines */
+ linenr_T prev_topline = wp->w_topline;
+
+ // go to first of folded lines
(void)hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
- /* Approximate the value of w_botline */
+ // Approximate the value of w_botline
wp->w_botline += lnum - wp->w_topline;
wp->w_topline = lnum;
wp->w_topline_was_set = true;
- wp->w_topfill = 0;
+ if (lnum != prev_topline) {
+ // Keep the filler lines when the topline didn't change.
+ wp->w_topfill = 0;
+ }
wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_TOPLINE);
// Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked.
redraw_later(wp, VALID);
diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim
index efa7f552e0..32cee7ca56 100644
--- a/src/nvim/testdir/test_diffmode.vim
+++ b/src/nvim/testdir/test_diffmode.vim
@@ -965,6 +965,30 @@ func Test_diff_screen()
call delete('XdiffSetup')
endfunc
+func Test_diff_with_scroll_and_change()
+ CheckScreendump
+
+ let lines =<< trim END
+ call setline(1, range(1, 15))
+ vnew
+ call setline(1, range(9, 15))
+ windo diffthis
+ wincmd h
+ exe "normal Gl5\<C-E>"
+ END
+ call writefile(lines, 'Xtest_scroll_change')
+ let buf = RunVimInTerminal('-S Xtest_scroll_change', {})
+
+ call VerifyScreenDump(buf, 'Test_diff_scroll_change_01', {})
+
+ call term_sendkeys(buf, "ax\<Esc>")
+ call VerifyScreenDump(buf, 'Test_diff_scroll_change_02', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('Xtest_scroll_change')
+endfunc
+
func Test_diff_with_cursorline()
CheckScreendump