fix(move): fix using the wrong window (#28312)

This commit is contained in:
zeertzjq
2024-04-13 10:32:49 +08:00
committed by GitHub
parent 355c149ba0
commit 780509aedf
2 changed files with 18 additions and 21 deletions

View File

@ -299,7 +299,7 @@ void update_topline(win_T *wp)
// scrolling down is never needed. // scrolling down is never needed.
if (wp->w_cursor.lnum < wp->w_topline) { if (wp->w_cursor.lnum < wp->w_topline) {
check_topline = true; check_topline = true;
} else if (check_top_offset()) { } else if (check_top_offset(wp)) {
check_topline = true; check_topline = true;
} else if (wp->w_skipcol > 0 && wp->w_cursor.lnum == wp->w_topline) { } else if (wp->w_skipcol > 0 && wp->w_cursor.lnum == wp->w_topline) {
colnr_T vcol; colnr_T vcol;
@ -349,7 +349,7 @@ void update_topline(win_T *wp)
if (n >= halfheight) { if (n >= halfheight) {
scroll_cursor_halfway(wp, false, false); scroll_cursor_halfway(wp, false, false);
} else { } else {
scroll_cursor_top(wp, scrolljump_value(), false); scroll_cursor_top(wp, scrolljump_value(wp), false);
check_botline = true; check_botline = true;
} }
} else { } else {
@ -422,7 +422,7 @@ void update_topline(win_T *wp)
line_count = wp->w_cursor.lnum - wp->w_botline + 1 + (int)(*so_ptr); line_count = wp->w_cursor.lnum - wp->w_botline + 1 + (int)(*so_ptr);
} }
if (line_count <= wp->w_height_inner + 1) { if (line_count <= wp->w_height_inner + 1) {
scroll_cursor_bot(wp, scrolljump_value(), false); scroll_cursor_bot(wp, scrolljump_value(wp), false);
} else { } else {
scroll_cursor_halfway(wp, false, false); scroll_cursor_halfway(wp, false, false);
} }
@ -455,33 +455,30 @@ void update_topline(win_T *wp)
*so_ptr = save_so; *so_ptr = save_so;
} }
// Return the scrolljump value to use for the current window. /// Return the scrolljump value to use for the window "wp".
// When 'scrolljump' is positive use it as-is. /// When 'scrolljump' is positive use it as-is.
// When 'scrolljump' is negative use it as a percentage of the window height. /// When 'scrolljump' is negative use it as a percentage of the window height.
static int scrolljump_value(void) static int scrolljump_value(win_T *wp)
{ {
int result = p_sj >= 0 ? (int)p_sj : (curwin->w_height_inner * (int)(-p_sj)) / 100; int result = p_sj >= 0 ? (int)p_sj : (wp->w_height_inner * (int)(-p_sj)) / 100;
return result; return result;
} }
// Return true when there are not 'scrolloff' lines above the cursor for the /// Return true when there are not 'scrolloff' lines above the cursor for window "wp".
// current window. static bool check_top_offset(win_T *wp)
static bool check_top_offset(void)
{ {
int so = get_scrolloff_value(curwin); int so = get_scrolloff_value(wp);
if (curwin->w_cursor.lnum < curwin->w_topline + so if (wp->w_cursor.lnum < wp->w_topline + so || hasAnyFolding(wp)) {
|| hasAnyFolding(curwin)) {
lineoff_T loff; lineoff_T loff;
loff.lnum = curwin->w_cursor.lnum; loff.lnum = wp->w_cursor.lnum;
loff.fill = 0; loff.fill = 0;
int n = curwin->w_topfill; // always have this context int n = wp->w_topfill; // always have this context
// Count the visible screen lines above the cursor line. // Count the visible screen lines above the cursor line.
while (n < so) { while (n < so) {
topline_back(curwin, &loff); topline_back(wp, &loff);
// Stop when included a line above the window. // Stop when included a line above the window.
if (loff.lnum < curwin->w_topline if (loff.lnum < wp->w_topline
|| (loff.lnum == curwin->w_topline || (loff.lnum == wp->w_topline && loff.fill > 0)) {
&& loff.fill > 0)) {
break; break;
} }
n += loff.height; n += loff.height;

View File

@ -4895,7 +4895,7 @@ if (h->n_buckets < new_n_buckets) { // expand
]]) ]])
end) end)
it('works with full page scrolling #28390', function() it('works with full page scrolling #28290', function()
screen:try_resize(20, 8) screen:try_resize(20, 8)
command('call setline(1, range(20))') command('call setline(1, range(20))')
api.nvim_buf_set_extmark(0, ns, 10, 0, { virt_lines = {{{'VIRT1'}}, {{'VIRT2'}}} }) api.nvim_buf_set_extmark(0, ns, 10, 0, { virt_lines = {{{'VIRT1'}}, {{'VIRT2'}}} })