refactor: pass the window to get_(side)scrolloff_value

to less rely on curwin
This commit is contained in:
Matthieu Coudron
2020-12-23 16:21:10 +01:00
parent 5ce328df40
commit 4d9520ec86
7 changed files with 22 additions and 20 deletions

View File

@@ -594,7 +594,7 @@ static int insert_check(VimState *state)
if (curwin->w_wcol < s->mincol - curbuf->b_p_ts if (curwin->w_wcol < s->mincol - curbuf->b_p_ts
&& curwin->w_wrow == curwin->w_winrow && curwin->w_wrow == curwin->w_winrow
+ curwin->w_height_inner - 1 - get_scrolloff_value() + curwin->w_height_inner - 1 - get_scrolloff_value(curwin)
&& (curwin->w_cursor.lnum != curwin->w_topline && (curwin->w_cursor.lnum != curwin->w_topline
|| curwin->w_topfill > 0)) { || curwin->w_topfill > 0)) {
if (curwin->w_topfill > 0) { if (curwin->w_topfill > 0) {

View File

@@ -7362,7 +7362,7 @@ static void ex_syncbind(exarg_T *eap)
topline = curwin->w_topline; topline = curwin->w_topline;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_p_scb && wp->w_buffer) { if (wp->w_p_scb && wp->w_buffer) {
y = wp->w_buffer->b_ml.ml_line_count - get_scrolloff_value(); y = wp->w_buffer->b_ml.ml_line_count - get_scrolloff_value(curwin);
if (topline > y) { if (topline > y) {
topline = y; topline = y;
} }

View File

@@ -368,7 +368,7 @@ static int scrolljump_value(void)
*/ */
static bool check_top_offset(void) static bool check_top_offset(void)
{ {
long so = get_scrolloff_value(); long so = get_scrolloff_value(curwin);
if (curwin->w_cursor.lnum < curwin->w_topline + so if (curwin->w_cursor.lnum < curwin->w_topline + so
|| hasAnyFolding(curwin) || hasAnyFolding(curwin)
) { ) {
@@ -729,8 +729,8 @@ void curs_columns(
colnr_T startcol; colnr_T startcol;
colnr_T endcol; colnr_T endcol;
colnr_T prev_skipcol; colnr_T prev_skipcol;
long so = get_scrolloff_value(); long so = get_scrolloff_value(curwin);
long siso = get_sidescrolloff_value(); long siso = get_sidescrolloff_value(curwin);
/* /*
* First make sure that w_topline is valid (after moving the cursor). * First make sure that w_topline is valid (after moving the cursor).
@@ -1231,7 +1231,7 @@ void scrolldown_clamp(void)
end_row += curwin->w_cline_height - 1 - end_row += curwin->w_cline_height - 1 -
curwin->w_virtcol / curwin->w_width_inner; curwin->w_virtcol / curwin->w_width_inner;
} }
if (end_row < curwin->w_height_inner - get_scrolloff_value()) { if (end_row < curwin->w_height_inner - get_scrolloff_value(curwin)) {
if (can_fill) { if (can_fill) {
++curwin->w_topfill; ++curwin->w_topfill;
check_topfill(curwin, true); check_topfill(curwin, true);
@@ -1271,7 +1271,7 @@ void scrollup_clamp(void)
validate_virtcol(); validate_virtcol();
start_row -= curwin->w_virtcol / curwin->w_width_inner; start_row -= curwin->w_virtcol / curwin->w_width_inner;
} }
if (start_row >= get_scrolloff_value()) { if (start_row >= get_scrolloff_value(curwin)) {
if (curwin->w_topfill > 0) { if (curwin->w_topfill > 0) {
curwin->w_topfill--; curwin->w_topfill--;
} else { } else {
@@ -1374,7 +1374,7 @@ void scroll_cursor_top(int min_scroll, int always)
linenr_T old_topline = curwin->w_topline; linenr_T old_topline = curwin->w_topline;
linenr_T old_topfill = curwin->w_topfill; linenr_T old_topfill = curwin->w_topfill;
linenr_T new_topline; linenr_T new_topline;
int off = (int)get_scrolloff_value(); int off = (int)get_scrolloff_value(curwin);
if (mouse_dragging > 0) if (mouse_dragging > 0)
off = mouse_dragging - 1; off = mouse_dragging - 1;
@@ -1518,7 +1518,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
int old_valid = curwin->w_valid; int old_valid = curwin->w_valid;
int old_empty_rows = curwin->w_empty_rows; int old_empty_rows = curwin->w_empty_rows;
linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number
long so = get_scrolloff_value(); long so = get_scrolloff_value(curwin);
if (set_topbot) { if (set_topbot) {
used = 0; used = 0;
@@ -1751,8 +1751,8 @@ void cursor_correct(void)
* How many lines we would like to have above/below the cursor depends on * How many lines we would like to have above/below the cursor depends on
* whether the first/last line of the file is on screen. * whether the first/last line of the file is on screen.
*/ */
int above_wanted = (int)get_scrolloff_value(); int above_wanted = (int)get_scrolloff_value(curwin);
int below_wanted = (int)get_scrolloff_value(); int below_wanted = (int)get_scrolloff_value(curwin);
if (mouse_dragging > 0) { if (mouse_dragging > 0) {
above_wanted = mouse_dragging - 1; above_wanted = mouse_dragging - 1;
below_wanted = mouse_dragging - 1; below_wanted = mouse_dragging - 1;
@@ -1848,7 +1848,7 @@ int onepage(Direction dir, long count)
int retval = OK; int retval = OK;
lineoff_T loff; lineoff_T loff;
linenr_T old_topline = curwin->w_topline; linenr_T old_topline = curwin->w_topline;
long so = get_scrolloff_value(); long so = get_scrolloff_value(curwin);
if (curbuf->b_ml.ml_line_count == 1) { /* nothing to do */ if (curbuf->b_ml.ml_line_count == 1) { /* nothing to do */
beep_flush(); beep_flush();

View File

@@ -2629,7 +2629,7 @@ do_mouse (
/* Set global flag that we are extending the Visual area with mouse /* Set global flag that we are extending the Visual area with mouse
* dragging; temporarily minimize 'scrolloff'. */ * dragging; temporarily minimize 'scrolloff'. */
if (VIsual_active && is_drag && get_scrolloff_value()) { if (VIsual_active && is_drag && get_scrolloff_value(curwin)) {
// In the very first line, allow scrolling one line // In the very first line, allow scrolling one line
if (mouse_row == 0) { if (mouse_row == 0) {
mouse_dragging = 2; mouse_dragging = 2;
@@ -4135,7 +4135,7 @@ void scroll_redraw(int up, long count)
scrollup(count, true) : scrollup(count, true) :
scrolldown(count, true); scrolldown(count, true);
if (get_scrolloff_value()) { if (get_scrolloff_value(curwin)) {
// Adjust the cursor position for 'scrolloff'. Mark w_topline as // Adjust the cursor position for 'scrolloff'. Mark w_topline as
// valid, otherwise the screen jumps back at the end of the file. // valid, otherwise the screen jumps back at the end of the file.
cursor_correct(); cursor_correct();
@@ -4185,7 +4185,7 @@ static void nv_zet(cmdarg_T *cap)
int old_fen = curwin->w_p_fen; int old_fen = curwin->w_p_fen;
bool undo = false; bool undo = false;
int l_p_siso = (int)get_sidescrolloff_value(); int l_p_siso = (int)get_sidescrolloff_value(curwin);
assert(l_p_siso <= INT_MAX); assert(l_p_siso <= INT_MAX);
if (ascii_isdigit(nchar)) { if (ascii_isdigit(nchar)) {

View File

@@ -7159,20 +7159,20 @@ dict_T *get_winbuf_options(const int bufopt)
/// Return the effective 'scrolloff' value for the current window, using the /// Return the effective 'scrolloff' value for the current window, using the
/// global value when appropriate. /// global value when appropriate.
long get_scrolloff_value(void) long get_scrolloff_value(win_T *wp)
{ {
// Disallow scrolloff in terminal-mode. #11915 // Disallow scrolloff in terminal-mode. #11915
if (State & TERM_FOCUS) { if (State & TERM_FOCUS) {
return 0; return 0;
} }
return curwin->w_p_so < 0 ? p_so : curwin->w_p_so; return wp->w_p_so < 0 ? p_so : wp->w_p_so;
} }
/// Return the effective 'sidescrolloff' value for the current window, using the /// Return the effective 'sidescrolloff' value for the current window, using the
/// global value when appropriate. /// global value when appropriate.
long get_sidescrolloff_value(void) long get_sidescrolloff_value(win_T *wp)
{ {
return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso; return wp->w_p_siso < 0 ? p_siso : wp->w_p_siso;
} }
Dictionary get_vimoption(String name, Error *err) Dictionary get_vimoption(String name, Error *err)

View File

@@ -2820,10 +2820,12 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
n_extra = col + 1; n_extra = col + 1;
} else { } else {
n_extra = grid->Columns - col; n_extra = grid->Columns - col;
ILOG("n_extra %d vs total widht %d", grid->Columns, col);
} }
char_attr = win_hl_attr(wp, HLF_DED); char_attr = win_hl_attr(wp, HLF_DED);
} }
if (*p_sbr != NUL && need_showbreak) { if (*p_sbr != NUL && need_showbreak) {
ILOG("need showbreak %d", need_showbreak);
/* Draw 'showbreak' at the start of each broken line. */ /* Draw 'showbreak' at the start of each broken line. */
p_extra = p_sbr; p_extra = p_sbr;
c_extra = NUL; c_extra = NUL;

View File

@@ -5859,7 +5859,7 @@ void scroll_to_fraction(win_T *wp, int prev_height)
} }
if (wp == curwin) { if (wp == curwin) {
if (get_scrolloff_value()) { if (get_scrolloff_value(wp)) {
update_topline(); update_topline();
} }
curs_columns(false); // validate w_wrow curs_columns(false); // validate w_wrow