mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 9.1.0280: several issues with 'smoothscroll' support
Problem: Logic to make sure cursor is in visible part of the screen after scrolling the text with 'smoothscroll' is scattered, asymmetric and contains bugs. Solution: Adjust and create helper function for 'smoothscroll' cursor logic. (Luuk van Baal) closes: #14410 Signed-off-by: Luuk van Baal <luukvbaal@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
196b6678c5
commit
9148ba8a46
59
src/normal.c
59
src/normal.c
@@ -2473,65 +2473,6 @@ nv_scroll_line(cmdarg_T *cap)
|
||||
scroll_redraw(cap->arg, cap->count1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Scroll "count" lines up or down, and redraw.
|
||||
*/
|
||||
void
|
||||
scroll_redraw(int up, long count)
|
||||
{
|
||||
linenr_T prev_topline = curwin->w_topline;
|
||||
int prev_skipcol = curwin->w_skipcol;
|
||||
#ifdef FEAT_DIFF
|
||||
int prev_topfill = curwin->w_topfill;
|
||||
#endif
|
||||
linenr_T prev_lnum = curwin->w_cursor.lnum;
|
||||
|
||||
if (up)
|
||||
scrollup(count, TRUE);
|
||||
else
|
||||
scrolldown(count, TRUE);
|
||||
if (get_scrolloff_value() > 0)
|
||||
{
|
||||
// Adjust the cursor position for 'scrolloff'. Mark w_topline as
|
||||
// valid, otherwise the screen jumps back at the end of the file.
|
||||
cursor_correct();
|
||||
check_cursor_moved(curwin);
|
||||
curwin->w_valid |= VALID_TOPLINE;
|
||||
|
||||
// If moved back to where we were, at least move the cursor, otherwise
|
||||
// we get stuck at one position. Don't move the cursor up if the
|
||||
// first line of the buffer is already on the screen
|
||||
while (curwin->w_topline == prev_topline
|
||||
&& curwin->w_skipcol == prev_skipcol
|
||||
#ifdef FEAT_DIFF
|
||||
&& curwin->w_topfill == prev_topfill
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (up)
|
||||
{
|
||||
if (curwin->w_cursor.lnum > prev_lnum
|
||||
|| cursor_down(1L, FALSE) == FAIL)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curwin->w_cursor.lnum < prev_lnum
|
||||
|| prev_topline == 1L
|
||||
|| cursor_up(1L, FALSE) == FAIL)
|
||||
break;
|
||||
}
|
||||
// Mark w_topline as valid, otherwise the screen jumps back at the
|
||||
// end of the file.
|
||||
check_cursor_moved(curwin);
|
||||
curwin->w_valid |= VALID_TOPLINE;
|
||||
}
|
||||
}
|
||||
if (curwin->w_cursor.lnum != prev_lnum)
|
||||
coladvance(curwin->w_curswant);
|
||||
redraw_later(UPD_VALID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the count specified after a 'z' command. Only the 'z<CR>', 'zl', 'zh',
|
||||
* 'z<Left>', and 'z<Right>' commands accept a count after 'z'.
|
||||
|
Reference in New Issue
Block a user