aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/move.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/move.c')
-rw-r--r--src/nvim/move.c799
1 files changed, 388 insertions, 411 deletions
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 551aa1bd4d..3c4da7f8ac 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -182,7 +182,7 @@ static void redraw_for_cursorcolumn(win_T *wp)
// When current buffer's cursor moves in Visual mode, redraw it with UPD_INVERTED.
if (VIsual_active && wp->w_buffer == curbuf) {
- redraw_curbuf_later(UPD_INVERTED);
+ redraw_buf_later(curbuf, UPD_INVERTED);
}
}
@@ -239,7 +239,7 @@ static void reset_skipcol(win_T *wp)
redraw_later(wp, UPD_SOME_VALID);
}
-// Update curwin->w_topline to move the cursor onto the screen.
+// Update wp->w_topline to move the cursor onto the screen.
void update_topline(win_T *wp)
{
bool check_botline = false;
@@ -332,7 +332,7 @@ void update_topline(win_T *wp)
if (lnum >= wp->w_buffer->b_ml.ml_line_count || n >= halfheight) {
break;
}
- hasFoldingWin(wp, lnum, NULL, &lnum, true, NULL);
+ hasFolding(wp, lnum, NULL, &lnum);
}
} else {
n = wp->w_topline + *so_ptr - wp->w_cursor.lnum;
@@ -342,14 +342,14 @@ void update_topline(win_T *wp)
// cursor in the middle of the window. Otherwise put the cursor
// near the top of the window.
if (n >= halfheight) {
- scroll_cursor_halfway(false, false);
+ scroll_cursor_halfway(wp, false, false);
} else {
- scroll_cursor_top(scrolljump_value(), false);
+ scroll_cursor_top(wp, scrolljump_value(), false);
check_botline = true;
}
} else {
// Make sure topline is the first line of a fold.
- hasFoldingWin(wp, wp->w_topline, &wp->w_topline, NULL, true, NULL);
+ hasFolding(wp, wp->w_topline, &wp->w_topline, NULL);
check_botline = true;
}
}
@@ -377,7 +377,7 @@ void update_topline(win_T *wp)
int n = wp->w_empty_rows;
loff.lnum = wp->w_cursor.lnum;
// In a fold go to its last line.
- hasFoldingWin(wp, loff.lnum, NULL, &loff.lnum, true, NULL);
+ hasFolding(wp, loff.lnum, NULL, &loff.lnum);
loff.fill = 0;
n += wp->w_filler_rows;
loff.height = 0;
@@ -411,15 +411,15 @@ void update_topline(win_T *wp)
if (lnum <= 0 || line_count > wp->w_height_inner + 1) {
break;
}
- hasFolding(lnum, &lnum, NULL);
+ hasFolding(wp, lnum, &lnum, NULL);
}
} else {
line_count = wp->w_cursor.lnum - wp->w_botline + 1 + (int)(*so_ptr);
}
if (line_count <= wp->w_height_inner + 1) {
- scroll_cursor_bot(scrolljump_value(), false);
+ scroll_cursor_bot(wp, scrolljump_value(), false);
} else {
- scroll_cursor_halfway(false, false);
+ scroll_cursor_halfway(wp, false, false);
}
}
}
@@ -443,7 +443,7 @@ void update_topline(win_T *wp)
// May need to set w_skipcol when cursor in w_topline.
if (wp->w_cursor.lnum == wp->w_topline) {
- validate_cursor();
+ validate_cursor(wp);
}
}
@@ -491,7 +491,7 @@ static bool check_top_offset(void)
/// Update w_curswant.
void update_curswant_force(void)
{
- validate_virtcol();
+ validate_virtcol(curwin);
curwin->w_curswant = curwin->w_virtcol;
curwin->w_set_curswant = false;
}
@@ -536,12 +536,7 @@ void check_cursor_moved(win_T *wp)
// Call this function when some window settings have changed, which require
// the cursor position, botline and topline to be recomputed and the window to
// be redrawn. E.g, when changing the 'wrap' option or folding.
-void changed_window_setting(void)
-{
- changed_window_setting_win(curwin);
-}
-
-void changed_window_setting_win(win_T *wp)
+void changed_window_setting(win_T *wp)
{
wp->w_lines_valid = 0;
changed_line_abv_curs_win(wp);
@@ -555,7 +550,7 @@ void set_topline(win_T *wp, linenr_T lnum)
linenr_T prev_topline = wp->w_topline;
// go to first of folded lines
- hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
+ hasFolding(wp, lnum, &lnum, NULL);
// Approximate the value of w_botline
wp->w_botline += lnum - wp->w_topline;
wp->w_topline = lnum;
@@ -595,7 +590,7 @@ void changed_line_abv_curs_win(win_T *wp)
|VALID_CHEIGHT|VALID_TOPLINE);
}
-// Make sure the value of curwin->w_botline is valid.
+// Make sure the value of wp->w_botline is valid.
void validate_botline(win_T *wp)
{
if (!(wp->w_valid & VALID_BOTLINE)) {
@@ -614,21 +609,21 @@ void approximate_botline_win(win_T *wp)
wp->w_valid &= ~VALID_BOTLINE;
}
-// Return true if curwin->w_wrow and curwin->w_wcol are valid.
-int cursor_valid(void)
+// Return true if wp->w_wrow and wp->w_wcol are valid.
+int cursor_valid(win_T *wp)
{
- check_cursor_moved(curwin);
- return (curwin->w_valid & (VALID_WROW|VALID_WCOL)) == (VALID_WROW|VALID_WCOL);
+ check_cursor_moved(wp);
+ return (wp->w_valid & (VALID_WROW|VALID_WCOL)) == (VALID_WROW|VALID_WCOL);
}
// Validate cursor position. Makes sure w_wrow and w_wcol are valid.
// w_topline must be valid, you may need to call update_topline() first!
-void validate_cursor(void)
+void validate_cursor(win_T *wp)
{
- check_cursor();
- check_cursor_moved(curwin);
- if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW)) {
- curs_columns(curwin, true);
+ check_cursor(wp);
+ check_cursor_moved(wp);
+ if ((wp->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW)) {
+ curs_columns(wp, true);
}
}
@@ -692,26 +687,19 @@ static void curs_rows(win_T *wp)
} else if (i > wp->w_lines_valid) {
// a line that is too long to fit on the last screen line
wp->w_cline_height = 0;
- wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, NULL,
- NULL, true, NULL);
+ wp->w_cline_folded = hasFolding(wp, wp->w_cursor.lnum, NULL, NULL);
} else {
wp->w_cline_height = wp->w_lines[i].wl_size;
wp->w_cline_folded = wp->w_lines[i].wl_folded;
}
}
- redraw_for_cursorline(curwin);
+ redraw_for_cursorline(wp);
wp->w_valid |= VALID_CROW|VALID_CHEIGHT;
}
-// Validate curwin->w_virtcol only.
-void validate_virtcol(void)
-{
- validate_virtcol_win(curwin);
-}
-
// Validate wp->w_virtcol only.
-void validate_virtcol_win(win_T *wp)
+void validate_virtcol(win_T *wp)
{
check_cursor_moved(wp);
@@ -724,49 +712,48 @@ void validate_virtcol_win(win_T *wp)
wp->w_valid |= VALID_VIRTCOL;
}
-// Validate curwin->w_cline_height only.
-void validate_cheight(void)
+// Validate wp->w_cline_height only.
+void validate_cheight(win_T *wp)
{
- check_cursor_moved(curwin);
+ check_cursor_moved(wp);
- if (curwin->w_valid & VALID_CHEIGHT) {
+ if (wp->w_valid & VALID_CHEIGHT) {
return;
}
- curwin->w_cline_height = plines_win_full(curwin, curwin->w_cursor.lnum,
- NULL, &curwin->w_cline_folded,
- true, true);
- curwin->w_valid |= VALID_CHEIGHT;
+ wp->w_cline_height = plines_win_full(wp, wp->w_cursor.lnum,
+ NULL, &wp->w_cline_folded,
+ true, true);
+ wp->w_valid |= VALID_CHEIGHT;
}
// Validate w_wcol and w_virtcol only.
-void validate_cursor_col(void)
+void validate_cursor_col(win_T *wp)
{
- validate_virtcol();
+ validate_virtcol(wp);
- if (curwin->w_valid & VALID_WCOL) {
+ if (wp->w_valid & VALID_WCOL) {
return;
}
- colnr_T col = curwin->w_virtcol;
- colnr_T off = curwin_col_off();
+ colnr_T col = wp->w_virtcol;
+ colnr_T off = win_col_off(wp);
col += off;
- int width = curwin->w_width_inner - off + curwin_col_off2();
+ int width = wp->w_width_inner - off + win_col_off2(wp);
- // long line wrapping, adjust curwin->w_wrow
- if (curwin->w_p_wrap && col >= (colnr_T)curwin->w_width_inner
- && width > 0) {
+ // long line wrapping, adjust wp->w_wrow
+ if (wp->w_p_wrap && col >= (colnr_T)wp->w_width_inner && width > 0) {
// use same formula as what is used in curs_columns()
- col -= ((col - curwin->w_width_inner) / width + 1) * width;
+ col -= ((col - wp->w_width_inner) / width + 1) * width;
}
- if (col > (int)curwin->w_leftcol) {
- col -= curwin->w_leftcol;
+ if (col > (int)wp->w_leftcol) {
+ col -= wp->w_leftcol;
} else {
col = 0;
}
- curwin->w_wcol = col;
+ wp->w_wcol = col;
- curwin->w_valid |= VALID_WCOL;
+ wp->w_valid |= VALID_WCOL;
}
// Compute offset of a window, occupied by absolute or relative line number,
@@ -779,11 +766,6 @@ int win_col_off(win_T *wp)
+ win_fdccol_count(wp) + (wp->w_scwidth * SIGN_WIDTH);
}
-int curwin_col_off(void)
-{
- return win_col_off(curwin);
-}
-
// Return the difference in column offset for the second screen line of a
// wrapped line. It's positive if 'number' or 'relativenumber' is on and 'n'
// is in 'cpoptions'.
@@ -796,11 +778,6 @@ int win_col_off2(win_T *wp)
return 0;
}
-int curwin_col_off2(void)
-{
- return win_col_off2(curwin);
-}
-
// Compute wp->w_wcol and wp->w_virtcol.
// Also updates wp->w_wrow and wp->w_cline_row.
// Also updates wp->w_leftcol.
@@ -896,7 +873,7 @@ void curs_columns(win_T *wp, int may_scroll)
// middle of window.
int new_leftcol;
if (p_ss == 0 || diff >= width1 / 2 || off_right >= off_left) {
- new_leftcol = curwin->w_wcol - extra - width1 / 2;
+ new_leftcol = wp->w_wcol - extra - width1 / 2;
} else {
if (diff < p_ss) {
assert(p_ss <= INT_MAX);
@@ -984,9 +961,9 @@ void curs_columns(win_T *wp, int may_scroll)
n = plines - wp->w_height_inner + 1;
}
if (n > 0) {
- curwin->w_skipcol = width1 + (n - 1) * width2;
+ wp->w_skipcol = width1 + (n - 1) * width2;
} else {
- curwin->w_skipcol = 0;
+ wp->w_skipcol = 0;
}
} else if (extra == 1) {
// less than 'scrolloff' lines above, decrease skipcol
@@ -1063,7 +1040,7 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
linenr_T lnum = pos->lnum;
if (lnum >= wp->w_topline && lnum <= wp->w_botline) {
- is_folded = hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
+ is_folded = hasFolding(wp, lnum, &lnum, NULL);
row = plines_m_win(wp, wp->w_topline, lnum - 1, false);
// "row" should be the screen line where line "lnum" begins, which can
// be negative if "lnum" is "w_topline" and "w_skipcol" is non-zero.
@@ -1207,128 +1184,128 @@ void f_virtcol2col(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
rettv->vval.v_number = virtcol2col(wp, lnum, screencol);
}
-/// Scroll the current window down by "line_count" logical lines. "CTRL-Y"
+/// Scroll a window down by "line_count" logical lines. "CTRL-Y"
///
/// @param line_count number of lines to scroll
/// @param byfold if true, count a closed fold as one line
-bool scrolldown(linenr_T line_count, int byfold)
+bool scrolldown(win_T *wp, linenr_T line_count, int byfold)
{
int done = 0; // total # of physical lines done
int width1 = 0;
int width2 = 0;
- bool do_sms = curwin->w_p_wrap && curwin->w_p_sms;
+ bool do_sms = wp->w_p_wrap && wp->w_p_sms;
if (do_sms) {
- width1 = curwin->w_width_inner - curwin_col_off();
- width2 = width1 + curwin_col_off2();
+ width1 = wp->w_width_inner - win_col_off(wp);
+ width2 = width1 + win_col_off2(wp);
}
// Make sure w_topline is at the first of a sequence of folded lines.
- hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
- validate_cursor(); // w_wrow needs to be valid
+ hasFolding(wp, wp->w_topline, &wp->w_topline, NULL);
+ validate_cursor(wp); // w_wrow needs to be valid
for (int todo = line_count; todo > 0; todo--) {
- if (curwin->w_topfill < win_get_fill(curwin, curwin->w_topline)
- && curwin->w_topfill < curwin->w_height_inner - 1) {
- curwin->w_topfill++;
+ if (wp->w_topfill < win_get_fill(wp, wp->w_topline)
+ && wp->w_topfill < wp->w_height_inner - 1) {
+ wp->w_topfill++;
done++;
} else {
// break when at the very top
- if (curwin->w_topline == 1 && (!do_sms || curwin->w_skipcol < width1)) {
+ if (wp->w_topline == 1 && (!do_sms || wp->w_skipcol < width1)) {
break;
}
- if (do_sms && curwin->w_skipcol >= width1) {
+ if (do_sms && wp->w_skipcol >= width1) {
// scroll a screen line down
- if (curwin->w_skipcol >= width1 + width2) {
- curwin->w_skipcol -= width2;
+ if (wp->w_skipcol >= width1 + width2) {
+ wp->w_skipcol -= width2;
} else {
- curwin->w_skipcol -= width1;
+ wp->w_skipcol -= width1;
}
- redraw_later(curwin, UPD_NOT_VALID);
+ redraw_later(wp, UPD_NOT_VALID);
done++;
} else {
// scroll a text line down
- curwin->w_topline--;
- curwin->w_skipcol = 0;
- curwin->w_topfill = 0;
+ wp->w_topline--;
+ wp->w_skipcol = 0;
+ wp->w_topfill = 0;
// A sequence of folded lines only counts for one logical line
linenr_T first;
- if (hasFolding(curwin->w_topline, &first, NULL)) {
+ if (hasFolding(wp, wp->w_topline, &first, NULL)) {
done++;
if (!byfold) {
- todo -= curwin->w_topline - first - 1;
+ todo -= wp->w_topline - first - 1;
}
- curwin->w_botline -= curwin->w_topline - first;
- curwin->w_topline = first;
+ wp->w_botline -= wp->w_topline - first;
+ wp->w_topline = first;
} else {
if (do_sms) {
- int size = win_linetabsize(curwin, curwin->w_topline,
- ml_get(curwin->w_topline), MAXCOL);
+ int size = win_linetabsize(wp, wp->w_topline,
+ ml_get(wp->w_topline), MAXCOL);
if (size > width1) {
- curwin->w_skipcol = width1;
+ wp->w_skipcol = width1;
size -= width1;
- redraw_later(curwin, UPD_NOT_VALID);
+ redraw_later(wp, UPD_NOT_VALID);
}
while (size > width2) {
- curwin->w_skipcol += width2;
+ wp->w_skipcol += width2;
size -= width2;
}
done++;
} else {
- done += plines_win_nofill(curwin, curwin->w_topline, true);
+ done += plines_win_nofill(wp, wp->w_topline, true);
}
}
}
}
- curwin->w_botline--; // approximate w_botline
- invalidate_botline(curwin);
+ wp->w_botline--; // approximate w_botline
+ invalidate_botline(wp);
}
- curwin->w_wrow += done; // keep w_wrow updated
- curwin->w_cline_row += done; // keep w_cline_row updated
+ wp->w_wrow += done; // keep w_wrow updated
+ wp->w_cline_row += done; // keep w_cline_row updated
- if (curwin->w_cursor.lnum == curwin->w_topline) {
- curwin->w_cline_row = 0;
+ if (wp->w_cursor.lnum == wp->w_topline) {
+ wp->w_cline_row = 0;
}
- check_topfill(curwin, true);
+ check_topfill(wp, true);
// Compute the row number of the last row of the cursor line
// and move the cursor onto the displayed part of the window.
- int wrow = curwin->w_wrow;
- if (curwin->w_p_wrap && curwin->w_width_inner != 0) {
- validate_virtcol();
- validate_cheight();
- wrow += curwin->w_cline_height - 1 -
- curwin->w_virtcol / curwin->w_width_inner;
+ int wrow = wp->w_wrow;
+ if (wp->w_p_wrap && wp->w_width_inner != 0) {
+ validate_virtcol(wp);
+ validate_cheight(wp);
+ wrow += wp->w_cline_height - 1 -
+ wp->w_virtcol / wp->w_width_inner;
}
bool moved = false;
- while (wrow >= curwin->w_height_inner && curwin->w_cursor.lnum > 1) {
+ while (wrow >= wp->w_height_inner && wp->w_cursor.lnum > 1) {
linenr_T first;
- if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) {
+ if (hasFolding(wp, wp->w_cursor.lnum, &first, NULL)) {
wrow--;
if (first == 1) {
- curwin->w_cursor.lnum = 1;
+ wp->w_cursor.lnum = 1;
} else {
- curwin->w_cursor.lnum = first - 1;
+ wp->w_cursor.lnum = first - 1;
}
} else {
- wrow -= plines_win(curwin, curwin->w_cursor.lnum--, true);
+ wrow -= plines_win(wp, wp->w_cursor.lnum--, true);
}
- curwin->w_valid &=
+ wp->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
moved = true;
}
if (moved) {
// Move cursor to first line of closed fold.
- foldAdjustCursor();
- coladvance(curwin->w_curswant);
+ foldAdjustCursor(wp);
+ coladvance(wp, wp->w_curswant);
}
- if (curwin->w_cursor.lnum == curwin->w_topline && do_sms) {
- int so = get_scrolloff_value(curwin);
+ if (wp->w_cursor.lnum == wp->w_topline && do_sms) {
+ int so = get_scrolloff_value(wp);
colnr_T scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
// make sure the cursor is in the visible text
- validate_virtcol();
- colnr_T col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols;
+ validate_virtcol(wp);
+ colnr_T col = wp->w_virtcol - wp->w_skipcol + scrolloff_cols;
int row = 0;
if (col >= width1) {
col -= width1;
@@ -1337,32 +1314,32 @@ bool scrolldown(linenr_T line_count, int byfold)
if (col > width2 && width2 > 0) {
row += (int)col / width2;
}
- if (row >= curwin->w_height_inner) {
- curwin->w_curswant = curwin->w_virtcol - (row - curwin->w_height_inner + 1) * width2;
- coladvance(curwin->w_curswant);
+ if (row >= wp->w_height_inner) {
+ wp->w_curswant = wp->w_virtcol - (row - wp->w_height_inner + 1) * width2;
+ coladvance(wp, wp->w_curswant);
}
}
return moved;
}
-/// Scroll the current window up by "line_count" logical lines. "CTRL-E"
+/// Scroll a window up by "line_count" logical lines. "CTRL-E"
///
/// @param line_count number of lines to scroll
/// @param byfold if true, count a closed fold as one line
-bool scrollup(linenr_T line_count, bool byfold)
+bool scrollup(win_T *wp, linenr_T line_count, bool byfold)
{
- linenr_T topline = curwin->w_topline;
- linenr_T botline = curwin->w_botline;
- bool do_sms = curwin->w_p_wrap && curwin->w_p_sms;
+ linenr_T topline = wp->w_topline;
+ linenr_T botline = wp->w_botline;
+ bool do_sms = wp->w_p_wrap && wp->w_p_sms;
- if (do_sms || (byfold && hasAnyFolding(curwin)) || win_may_fill(curwin)) {
- int width1 = curwin->w_width_inner - curwin_col_off();
- int width2 = width1 + curwin_col_off2();
+ if (do_sms || (byfold && hasAnyFolding(wp)) || win_may_fill(wp)) {
+ int width1 = wp->w_width_inner - win_col_off(wp);
+ int width2 = width1 + win_col_off2(wp);
int size = 0;
- const colnr_T prev_skipcol = curwin->w_skipcol;
+ const colnr_T prev_skipcol = wp->w_skipcol;
if (do_sms) {
- size = linetabsize(curwin, curwin->w_topline);
+ size = linetabsize(wp, wp->w_topline);
}
// diff mode: first consume "topfill"
@@ -1370,93 +1347,93 @@ bool scrollup(linenr_T line_count, bool byfold)
// the line, then advance to the next line.
// folding: count each sequence of folded lines as one logical line.
for (int todo = line_count; todo > 0; todo--) {
- if (curwin->w_topfill > 0) {
- curwin->w_topfill--;
+ if (wp->w_topfill > 0) {
+ wp->w_topfill--;
} else {
- linenr_T lnum = curwin->w_topline;
+ linenr_T lnum = wp->w_topline;
if (byfold) {
// for a closed fold: go to the last line in the fold
- hasFolding(lnum, NULL, &lnum);
+ hasFolding(wp, lnum, NULL, &lnum);
}
- if (lnum == curwin->w_topline && do_sms) {
+ if (lnum == wp->w_topline && do_sms) {
// 'smoothscroll': increase "w_skipcol" until it goes over
// the end of the line, then advance to the next line.
- int add = curwin->w_skipcol > 0 ? width2 : width1;
- curwin->w_skipcol += add;
- if (curwin->w_skipcol >= size) {
- if (lnum == curbuf->b_ml.ml_line_count) {
+ int add = wp->w_skipcol > 0 ? width2 : width1;
+ wp->w_skipcol += add;
+ if (wp->w_skipcol >= size) {
+ if (lnum == wp->w_buffer->b_ml.ml_line_count) {
// at the last screen line, can't scroll further
- curwin->w_skipcol -= add;
+ wp->w_skipcol -= add;
break;
}
lnum++;
}
} else {
- if (lnum >= curbuf->b_ml.ml_line_count) {
+ if (lnum >= wp->w_buffer->b_ml.ml_line_count) {
break;
}
lnum++;
}
- if (lnum > curwin->w_topline) {
+ if (lnum > wp->w_topline) {
// approximate w_botline
- curwin->w_botline += lnum - curwin->w_topline;
- curwin->w_topline = lnum;
- curwin->w_topfill = win_get_fill(curwin, lnum);
- curwin->w_skipcol = 0;
+ wp->w_botline += lnum - wp->w_topline;
+ wp->w_topline = lnum;
+ wp->w_topfill = win_get_fill(wp, lnum);
+ wp->w_skipcol = 0;
if (todo > 1 && do_sms) {
- size = linetabsize(curwin, curwin->w_topline);
+ size = linetabsize(wp, wp->w_topline);
}
}
}
}
- if (prev_skipcol > 0 || curwin->w_skipcol > 0) {
+ if (prev_skipcol > 0 || wp->w_skipcol > 0) {
// need to redraw more, because wl_size of the (new) topline may
// now be invalid
- redraw_later(curwin, UPD_NOT_VALID);
+ redraw_later(wp, UPD_NOT_VALID);
}
} else {
- curwin->w_topline += line_count;
- curwin->w_botline += line_count; // approximate w_botline
+ wp->w_topline += line_count;
+ wp->w_botline += line_count; // approximate w_botline
}
- if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
- curwin->w_topline = curbuf->b_ml.ml_line_count;
+ if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) {
+ wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
}
- if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) {
- curwin->w_botline = curbuf->b_ml.ml_line_count + 1;
+ if (wp->w_botline > wp->w_buffer->b_ml.ml_line_count + 1) {
+ wp->w_botline = wp->w_buffer->b_ml.ml_line_count + 1;
}
- check_topfill(curwin, false);
+ check_topfill(wp, false);
- if (hasAnyFolding(curwin)) {
+ if (hasAnyFolding(wp)) {
// Make sure w_topline is at the first of a sequence of folded lines.
- hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+ hasFolding(wp, wp->w_topline, &wp->w_topline, NULL);
}
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
- if (curwin->w_cursor.lnum < curwin->w_topline) {
- curwin->w_cursor.lnum = curwin->w_topline;
- curwin->w_valid &=
+ wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
+ if (wp->w_cursor.lnum < wp->w_topline) {
+ wp->w_cursor.lnum = wp->w_topline;
+ wp->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
- coladvance(curwin->w_curswant);
+ coladvance(wp, wp->w_curswant);
}
- if (curwin->w_cursor.lnum == curwin->w_topline && do_sms && curwin->w_skipcol > 0) {
- int col_off = curwin_col_off();
- int col_off2 = curwin_col_off2();
+ if (wp->w_cursor.lnum == wp->w_topline && do_sms && wp->w_skipcol > 0) {
+ int col_off = win_col_off(wp);
+ int col_off2 = win_col_off2(wp);
- int width1 = curwin->w_width_inner - col_off;
+ int width1 = wp->w_width_inner - col_off;
int width2 = width1 + col_off2;
int extra2 = col_off - col_off2;
- int so = get_scrolloff_value(curwin);
+ int so = get_scrolloff_value(wp);
colnr_T scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
- int space_cols = (curwin->w_height_inner - 1) * width2;
+ int space_cols = (wp->w_height_inner - 1) * width2;
// If we have non-zero scrolloff, just ignore the marker as we are
// going past it anyway.
- int overlap = scrolloff_cols != 0 ? 0 : sms_marker_overlap(curwin, extra2);
+ int overlap = scrolloff_cols != 0 ? 0 : sms_marker_overlap(wp, extra2);
// Make sure the cursor is in a visible part of the line, taking
// 'scrolloff' into account, but using screen lines.
@@ -1464,26 +1441,26 @@ bool scrollup(linenr_T line_count, bool byfold)
if (scrolloff_cols > space_cols / 2) {
scrolloff_cols = space_cols / 2;
}
- validate_virtcol();
- if (curwin->w_virtcol < curwin->w_skipcol + overlap + scrolloff_cols) {
- colnr_T col = curwin->w_virtcol;
+ validate_virtcol(wp);
+ if (wp->w_virtcol < wp->w_skipcol + overlap + scrolloff_cols) {
+ colnr_T col = wp->w_virtcol;
if (col < width1) {
col += width1;
}
- while (col < curwin->w_skipcol + overlap + scrolloff_cols) {
+ while (col < wp->w_skipcol + overlap + scrolloff_cols) {
col += width2;
}
- curwin->w_curswant = col;
- coladvance(curwin->w_curswant);
+ wp->w_curswant = col;
+ coladvance(wp, wp->w_curswant);
// validate_virtcol() marked various things as valid, but after
// moving the cursor they need to be recomputed
- curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
+ wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL);
}
}
- bool moved = topline != curwin->w_topline || botline != curwin->w_botline;
+ bool moved = topline != wp->w_topline || botline != wp->w_botline;
return moved;
}
@@ -1496,16 +1473,16 @@ void adjust_skipcol(void)
return;
}
- int width1 = curwin->w_width_inner - curwin_col_off();
+ int width1 = curwin->w_width_inner - win_col_off(curwin);
if (width1 <= 0) {
return; // no text will be displayed
}
- int width2 = width1 + curwin_col_off2();
+ int width2 = width1 + win_col_off2(curwin);
int so = get_scrolloff_value(curwin);
colnr_T scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
bool scrolled = false;
- validate_cheight();
+ validate_cheight(curwin);
if (curwin->w_cline_height == curwin->w_height_inner
// w_cline_height may be capped at w_height_inner, check there aren't
// actually more lines.
@@ -1515,8 +1492,8 @@ void adjust_skipcol(void)
return;
}
- validate_virtcol();
- int overlap = sms_marker_overlap(curwin, curwin_col_off() - curwin_col_off2());
+ validate_virtcol(curwin);
+ int overlap = sms_marker_overlap(curwin, win_col_off(curwin) - win_col_off2(curwin));
while (curwin->w_skipcol > 0
&& curwin->w_virtcol < curwin->w_skipcol + overlap + scrolloff_cols) {
// scroll a screen line down
@@ -1528,7 +1505,7 @@ void adjust_skipcol(void)
scrolled = true;
}
if (scrolled) {
- validate_virtcol();
+ validate_virtcol(curwin);
redraw_later(curwin, UPD_NOT_VALID);
return; // don't scroll in the other direction now
}
@@ -1572,7 +1549,7 @@ void check_topfill(win_T *wp, bool down)
}
}
}
- win_check_anchored_floats(curwin);
+ win_check_anchored_floats(wp);
}
// Use as many filler lines as possible for w_topline. Make sure w_topline
@@ -1601,7 +1578,7 @@ void scrolldown_clamp(void)
return;
}
- validate_cursor(); // w_wrow needs to be valid
+ validate_cursor(curwin); // w_wrow needs to be valid
// Compute the row number of the last row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor
@@ -1613,8 +1590,8 @@ void scrolldown_clamp(void)
end_row += plines_win_nofill(curwin, curwin->w_topline - 1, true);
}
if (curwin->w_p_wrap && curwin->w_width_inner != 0) {
- validate_cheight();
- validate_virtcol();
+ validate_cheight(curwin);
+ validate_virtcol(curwin);
end_row += curwin->w_cline_height - 1 -
curwin->w_virtcol / curwin->w_width_inner;
}
@@ -1626,7 +1603,7 @@ void scrolldown_clamp(void)
curwin->w_topline--;
curwin->w_topfill = 0;
}
- hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+ hasFolding(curwin, curwin->w_topline, &curwin->w_topline, NULL);
curwin->w_botline--; // approximate w_botline
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
}
@@ -1641,7 +1618,7 @@ void scrollup_clamp(void)
return;
}
- validate_cursor(); // w_wrow needs to be valid
+ validate_cursor(curwin); // w_wrow needs to be valid
// Compute the row number of the first row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor
@@ -1650,14 +1627,14 @@ void scrollup_clamp(void)
- plines_win_nofill(curwin, curwin->w_topline, true)
- curwin->w_topfill);
if (curwin->w_p_wrap && curwin->w_width_inner != 0) {
- validate_virtcol();
+ validate_virtcol(curwin);
start_row -= curwin->w_virtcol / curwin->w_width_inner;
}
if (start_row >= get_scrolloff_value(curwin)) {
if (curwin->w_topfill > 0) {
curwin->w_topfill--;
} else {
- hasFolding(curwin->w_topline, NULL, &curwin->w_topline);
+ hasFolding(curwin, curwin->w_topline, NULL, &curwin->w_topline);
curwin->w_topline++;
}
curwin->w_botline++; // approximate w_botline
@@ -1681,7 +1658,7 @@ static void topline_back_winheight(win_T *wp, lineoff_T *lp, int winheight)
lp->fill = 0;
if (lp->lnum < 1) {
lp->height = MAXCOL;
- } else if (hasFolding(lp->lnum, &lp->lnum, NULL)) {
+ } else if (hasFolding(wp, lp->lnum, &lp->lnum, NULL)) {
// Add a closed fold
lp->height = 1;
} else {
@@ -1711,7 +1688,7 @@ static void botline_forw(win_T *wp, lineoff_T *lp)
assert(wp->w_buffer != 0);
if (lp->lnum > wp->w_buffer->b_ml.ml_line_count) {
lp->height = MAXCOL;
- } else if (hasFoldingWin(wp, lp->lnum, NULL, &lp->lnum, true, NULL)) {
+ } else if (hasFolding(wp, lp->lnum, NULL, &lp->lnum)) {
// Add a closed fold
lp->height = 1;
} else {
@@ -1745,12 +1722,12 @@ static void topline_botline(lineoff_T *lp)
// Recompute topline to put the cursor at the top of the window.
// Scroll at least "min_scroll" lines.
// If "always" is true, always set topline (for "zt").
-void scroll_cursor_top(int min_scroll, int always)
+void scroll_cursor_top(win_T *wp, int min_scroll, int always)
{
- linenr_T old_topline = curwin->w_topline;
- int old_skipcol = curwin->w_skipcol;
- linenr_T old_topfill = curwin->w_topfill;
- int off = get_scrolloff_value(curwin);
+ linenr_T old_topline = wp->w_topline;
+ int old_skipcol = wp->w_skipcol;
+ linenr_T old_topfill = wp->w_topfill;
+ int off = get_scrolloff_value(wp);
if (mouse_dragging > 0) {
off = mouse_dragging - 1;
@@ -1761,54 +1738,54 @@ void scroll_cursor_top(int min_scroll, int always)
// - (part of) the cursor line is moved off the screen or
// - moved at least 'scrolljump' lines and
// - at least 'scrolloff' lines above and below the cursor
- validate_cheight();
+ validate_cheight(wp);
int scrolled = 0;
- int used = curwin->w_cline_height; // includes filler lines above
- if (curwin->w_cursor.lnum < curwin->w_topline) {
+ int used = wp->w_cline_height; // includes filler lines above
+ if (wp->w_cursor.lnum < wp->w_topline) {
scrolled = used;
}
linenr_T top; // just above displayed lines
linenr_T bot; // just below displayed lines
- if (hasFolding(curwin->w_cursor.lnum, &top, &bot)) {
+ if (hasFolding(wp, wp->w_cursor.lnum, &top, &bot)) {
top--;
bot++;
} else {
- top = curwin->w_cursor.lnum - 1;
- bot = curwin->w_cursor.lnum + 1;
+ top = wp->w_cursor.lnum - 1;
+ bot = wp->w_cursor.lnum + 1;
}
linenr_T new_topline = top + 1;
// "used" already contains the number of filler lines above, don't add it
// again.
// Hide filler lines above cursor line by adding them to "extra".
- int extra = win_get_fill(curwin, curwin->w_cursor.lnum);
+ int extra = win_get_fill(wp, wp->w_cursor.lnum);
// Check if the lines from "top" to "bot" fit in the window. If they do,
// set new_topline and advance "top" and "bot" to include more lines.
while (top > 0) {
- int i = hasFolding(top, &top, NULL)
+ int i = hasFolding(wp, top, &top, NULL)
? 1 // count one logical line for a sequence of folded lines
- : plines_win_nofill(curwin, top, true);
- if (top < curwin->w_topline) {
+ : plines_win_nofill(wp, top, true);
+ if (top < wp->w_topline) {
scrolled += i;
}
// If scrolling is needed, scroll at least 'sj' lines.
- if ((new_topline >= curwin->w_topline || scrolled > min_scroll) && extra >= off) {
+ if ((new_topline >= wp->w_topline || scrolled > min_scroll) && extra >= off) {
break;
}
used += i;
- if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) {
- if (hasFolding(bot, NULL, &bot)) {
+ if (extra + i <= off && bot < wp->w_buffer->b_ml.ml_line_count) {
+ if (hasFolding(wp, bot, NULL, &bot)) {
// count one logical line for a sequence of folded lines
used++;
} else {
- used += plines_win(curwin, bot, true);
+ used += plines_win(wp, bot, true);
}
}
- if (used > curwin->w_height_inner) {
+ if (used > wp->w_height_inner) {
break;
}
@@ -1821,43 +1798,43 @@ void scroll_cursor_top(int min_scroll, int always)
// If we don't have enough space, put cursor in the middle.
// This makes sure we get the same position when using "k" and "j"
// in a small window.
- if (used > curwin->w_height_inner) {
- scroll_cursor_halfway(false, false);
+ if (used > wp->w_height_inner) {
+ scroll_cursor_halfway(wp, false, false);
} else {
// If "always" is false, only adjust topline to a lower value, higher
// value may happen with wrapping lines.
- if (new_topline < curwin->w_topline || always) {
- curwin->w_topline = new_topline;
+ if (new_topline < wp->w_topline || always) {
+ wp->w_topline = new_topline;
}
- if (curwin->w_topline > curwin->w_cursor.lnum) {
- curwin->w_topline = curwin->w_cursor.lnum;
+ if (wp->w_topline > wp->w_cursor.lnum) {
+ wp->w_topline = wp->w_cursor.lnum;
}
- curwin->w_topfill = win_get_fill(curwin, curwin->w_topline);
- if (curwin->w_topfill > 0 && extra > off) {
- curwin->w_topfill -= extra - off;
- if (curwin->w_topfill < 0) {
- curwin->w_topfill = 0;
+ wp->w_topfill = win_get_fill(wp, wp->w_topline);
+ if (wp->w_topfill > 0 && extra > off) {
+ wp->w_topfill -= extra - off;
+ if (wp->w_topfill < 0) {
+ wp->w_topfill = 0;
}
}
- check_topfill(curwin, false);
- if (curwin->w_topline != old_topline) {
- reset_skipcol(curwin);
- } else if (curwin->w_topline == curwin->w_cursor.lnum) {
- validate_virtcol();
- if (curwin->w_skipcol >= curwin->w_virtcol) {
+ check_topfill(wp, false);
+ if (wp->w_topline != old_topline) {
+ reset_skipcol(wp);
+ } else if (wp->w_topline == wp->w_cursor.lnum) {
+ validate_virtcol(wp);
+ if (wp->w_skipcol >= wp->w_virtcol) {
// TODO(vim): if the line doesn't fit may optimize w_skipcol instead
// of making it zero
- reset_skipcol(curwin);
+ reset_skipcol(wp);
}
}
- if (curwin->w_topline != old_topline
- || curwin->w_skipcol != old_skipcol
- || curwin->w_topfill != old_topfill) {
- curwin->w_valid &=
+ if (wp->w_topline != old_topline
+ || wp->w_skipcol != old_skipcol
+ || wp->w_topfill != old_topfill) {
+ wp->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
}
- curwin->w_valid |= VALID_TOPLINE;
- curwin->w_viewport_invalid = true;
+ wp->w_valid |= VALID_TOPLINE;
+ wp->w_viewport_invalid = true;
}
}
@@ -1886,79 +1863,79 @@ void set_empty_rows(win_T *wp, int used)
/// When scrolling scroll at least "min_scroll" lines.
/// If "set_topbot" is true, set topline and botline first (for "zb").
/// This is messy stuff!!!
-void scroll_cursor_bot(int min_scroll, bool set_topbot)
+void scroll_cursor_bot(win_T *wp, int min_scroll, bool set_topbot)
{
lineoff_T loff;
- linenr_T old_topline = curwin->w_topline;
- int old_skipcol = curwin->w_skipcol;
- int old_topfill = curwin->w_topfill;
- linenr_T old_botline = curwin->w_botline;
- int old_valid = curwin->w_valid;
- int old_empty_rows = curwin->w_empty_rows;
- linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number
- bool do_sms = curwin->w_p_wrap && curwin->w_p_sms;
+ linenr_T old_topline = wp->w_topline;
+ int old_skipcol = wp->w_skipcol;
+ int old_topfill = wp->w_topfill;
+ linenr_T old_botline = wp->w_botline;
+ int old_valid = wp->w_valid;
+ int old_empty_rows = wp->w_empty_rows;
+ linenr_T cln = wp->w_cursor.lnum; // Cursor Line Number
+ bool do_sms = wp->w_p_wrap && wp->w_p_sms;
if (set_topbot) {
bool set_skipcol = false;
int used = 0;
- curwin->w_botline = cln + 1;
+ wp->w_botline = cln + 1;
loff.fill = 0;
- for (curwin->w_topline = curwin->w_botline;
- curwin->w_topline > 1;
- curwin->w_topline = loff.lnum) {
- loff.lnum = curwin->w_topline;
- topline_back_winheight(curwin, &loff, false);
+ for (wp->w_topline = wp->w_botline;
+ wp->w_topline > 1;
+ wp->w_topline = loff.lnum) {
+ loff.lnum = wp->w_topline;
+ topline_back_winheight(wp, &loff, false);
if (loff.height == MAXCOL) {
break;
}
- if (used + loff.height > curwin->w_height_inner) {
+ if (used + loff.height > wp->w_height_inner) {
if (do_sms) {
// 'smoothscroll' and 'wrap' are set. The above line is
// too long to show in its entirety, so we show just a part
// of it.
- if (used < curwin->w_height_inner) {
- int plines_offset = used + loff.height - curwin->w_height_inner;
- used = curwin->w_height_inner;
- curwin->w_topfill = loff.fill;
- curwin->w_topline = loff.lnum;
- curwin->w_skipcol = skipcol_from_plines(curwin, plines_offset);
+ if (used < wp->w_height_inner) {
+ int plines_offset = used + loff.height - wp->w_height_inner;
+ used = wp->w_height_inner;
+ wp->w_topfill = loff.fill;
+ wp->w_topline = loff.lnum;
+ wp->w_skipcol = skipcol_from_plines(wp, plines_offset);
set_skipcol = true;
}
}
break;
}
used += loff.height;
- curwin->w_topfill = loff.fill;
+ wp->w_topfill = loff.fill;
}
- set_empty_rows(curwin, used);
- curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
- if (curwin->w_topline != old_topline
- || curwin->w_topfill != old_topfill
+ set_empty_rows(wp, used);
+ wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
+ if (wp->w_topline != old_topline
+ || wp->w_topfill != old_topfill
|| set_skipcol
- || curwin->w_skipcol != 0) {
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
+ || wp->w_skipcol != 0) {
+ wp->w_valid &= ~(VALID_WROW|VALID_CROW);
if (set_skipcol) {
- redraw_later(curwin, UPD_NOT_VALID);
+ redraw_later(wp, UPD_NOT_VALID);
} else {
- reset_skipcol(curwin);
+ reset_skipcol(wp);
}
}
} else {
- validate_botline(curwin);
+ validate_botline(wp);
}
// The lines of the cursor line itself are always used.
- int used = plines_win_nofill(curwin, cln, true);
+ int used = plines_win_nofill(wp, cln, true);
int scrolled = 0;
// If the cursor is on or below botline, we will at least scroll by the
// height of the cursor line, which is "used". Correct for empty lines,
// which are really part of botline.
- if (cln >= curwin->w_botline) {
+ if (cln >= wp->w_botline) {
scrolled = used;
- if (cln == curwin->w_botline) {
- scrolled -= curwin->w_empty_rows;
+ if (cln == wp->w_botline) {
+ scrolled -= wp->w_empty_rows;
}
if (do_sms) {
// 'smoothscroll' and 'wrap' are set.
@@ -1966,21 +1943,21 @@ void scroll_cursor_bot(int min_scroll, bool set_topbot)
// occupies. If it is occupying more than the entire window, we
// need to scroll the additional clipped lines to scroll past the
// top line before we can move on to the other lines.
- int top_plines = plines_win_nofill(curwin, curwin->w_topline, false);
+ int top_plines = plines_win_nofill(wp, wp->w_topline, false);
int skip_lines = 0;
- int width1 = curwin->w_width_inner - curwin_col_off();
+ int width1 = wp->w_width_inner - win_col_off(wp);
if (width1 > 0) {
- int width2 = width1 + curwin_col_off2();
+ int width2 = width1 + win_col_off2(wp);
// similar formula is used in curs_columns()
- if (curwin->w_skipcol > width1) {
- skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
- } else if (curwin->w_skipcol > 0) {
+ if (wp->w_skipcol > width1) {
+ skip_lines += (wp->w_skipcol - width1) / width2 + 1;
+ } else if (wp->w_skipcol > 0) {
skip_lines = 1;
}
top_plines -= skip_lines;
- if (top_plines > curwin->w_height_inner) {
- scrolled += (top_plines - curwin->w_height_inner);
+ if (top_plines > wp->w_height_inner) {
+ scrolled += (top_plines - wp->w_height_inner);
}
}
}
@@ -1992,67 +1969,67 @@ void scroll_cursor_bot(int min_scroll, bool set_topbot)
// - scrolled nothing or at least 'sj' lines
// - at least 'so' lines below the cursor
// - lines between botline and cursor have been counted
- if (!hasFolding(curwin->w_cursor.lnum, &loff.lnum, &boff.lnum)) {
+ if (!hasFolding(wp, wp->w_cursor.lnum, &loff.lnum, &boff.lnum)) {
loff.lnum = cln;
boff.lnum = cln;
}
loff.fill = 0;
boff.fill = 0;
- int fill_below_window = win_get_fill(curwin, curwin->w_botline) - curwin->w_filler_rows;
+ int fill_below_window = win_get_fill(wp, wp->w_botline) - wp->w_filler_rows;
int extra = 0;
- int so = get_scrolloff_value(curwin);
+ int so = get_scrolloff_value(wp);
while (loff.lnum > 1) {
// Stop when scrolled nothing or at least "min_scroll", found "extra"
// context for 'scrolloff' and counted all lines below the window.
if ((((scrolled <= 0 || scrolled >= min_scroll)
&& extra >= (mouse_dragging > 0 ? mouse_dragging - 1 : so))
- || boff.lnum + 1 > curbuf->b_ml.ml_line_count)
- && loff.lnum <= curwin->w_botline
- && (loff.lnum < curwin->w_botline
+ || boff.lnum + 1 > wp->w_buffer->b_ml.ml_line_count)
+ && loff.lnum <= wp->w_botline
+ && (loff.lnum < wp->w_botline
|| loff.fill >= fill_below_window)) {
break;
}
// Add one line above
- topline_back(curwin, &loff);
+ topline_back(wp, &loff);
if (loff.height == MAXCOL) {
used = MAXCOL;
} else {
used += loff.height;
}
- if (used > curwin->w_height_inner) {
+ if (used > wp->w_height_inner) {
break;
}
- if (loff.lnum >= curwin->w_botline
- && (loff.lnum > curwin->w_botline
+ if (loff.lnum >= wp->w_botline
+ && (loff.lnum > wp->w_botline
|| loff.fill <= fill_below_window)) {
// Count screen lines that are below the window.
scrolled += loff.height;
- if (loff.lnum == curwin->w_botline
+ if (loff.lnum == wp->w_botline
&& loff.fill == 0) {
- scrolled -= curwin->w_empty_rows;
+ scrolled -= wp->w_empty_rows;
}
}
- if (boff.lnum < curbuf->b_ml.ml_line_count) {
+ if (boff.lnum < wp->w_buffer->b_ml.ml_line_count) {
// Add one line below
- botline_forw(curwin, &boff);
+ botline_forw(wp, &boff);
used += boff.height;
- if (used > curwin->w_height_inner) {
+ if (used > wp->w_height_inner) {
break;
}
if (extra < (mouse_dragging > 0 ? mouse_dragging - 1 : so)
|| scrolled < min_scroll) {
extra += boff.height;
- if (boff.lnum >= curwin->w_botline
- || (boff.lnum + 1 == curwin->w_botline
- && boff.fill > curwin->w_filler_rows)) {
+ if (boff.lnum >= wp->w_botline
+ || (boff.lnum + 1 == wp->w_botline
+ && boff.fill > wp->w_filler_rows)) {
// Count screen lines that are below the window.
scrolled += boff.height;
- if (boff.lnum == curwin->w_botline
+ if (boff.lnum == wp->w_botline
&& boff.fill == 0) {
- scrolled -= curwin->w_empty_rows;
+ scrolled -= wp->w_empty_rows;
}
}
}
@@ -2060,77 +2037,77 @@ void scroll_cursor_bot(int min_scroll, bool set_topbot)
}
linenr_T line_count;
- // curwin->w_empty_rows is larger, no need to scroll
+ // wp->w_empty_rows is larger, no need to scroll
if (scrolled <= 0) {
line_count = 0;
// more than a screenfull, don't scroll but redraw
- } else if (used > curwin->w_height_inner) {
+ } else if (used > wp->w_height_inner) {
line_count = used;
// scroll minimal number of lines
} else {
line_count = 0;
- boff.fill = curwin->w_topfill;
- boff.lnum = curwin->w_topline - 1;
+ boff.fill = wp->w_topfill;
+ boff.lnum = wp->w_topline - 1;
int i;
- for (i = 0; i < scrolled && boff.lnum < curwin->w_botline;) {
- botline_forw(curwin, &boff);
+ for (i = 0; i < scrolled && boff.lnum < wp->w_botline;) {
+ botline_forw(wp, &boff);
i += boff.height;
line_count++;
}
- if (i < scrolled) { // below curwin->w_botline, don't scroll
+ if (i < scrolled) { // below wp->w_botline, don't scroll
line_count = 9999;
}
}
// Scroll up if the cursor is off the bottom of the screen a bit.
// Otherwise put it at 1/2 of the screen.
- if (line_count >= curwin->w_height_inner && line_count > min_scroll) {
- scroll_cursor_halfway(false, true);
+ if (line_count >= wp->w_height_inner && line_count > min_scroll) {
+ scroll_cursor_halfway(wp, false, true);
} else if (line_count > 0) {
if (do_sms) {
- scrollup(scrolled, true); // TODO(vim):
+ scrollup(wp, scrolled, true); // TODO(vim):
} else {
- scrollup(line_count, true);
+ scrollup(wp, line_count, true);
}
}
// If topline didn't change we need to restore w_botline and w_empty_rows
// (we changed them).
// If topline did change, update_screen() will set botline.
- if (curwin->w_topline == old_topline && curwin->w_skipcol == old_skipcol && set_topbot) {
- curwin->w_botline = old_botline;
- curwin->w_empty_rows = old_empty_rows;
- curwin->w_valid = old_valid;
+ if (wp->w_topline == old_topline && wp->w_skipcol == old_skipcol && set_topbot) {
+ wp->w_botline = old_botline;
+ wp->w_empty_rows = old_empty_rows;
+ wp->w_valid = old_valid;
}
- curwin->w_valid |= VALID_TOPLINE;
- curwin->w_viewport_invalid = true;
+ wp->w_valid |= VALID_TOPLINE;
+ wp->w_viewport_invalid = true;
}
/// Recompute topline to put the cursor halfway across the window
///
/// @param atend if true, also put the cursor halfway to the end of the file.
///
-void scroll_cursor_halfway(bool atend, bool prefer_above)
+void scroll_cursor_halfway(win_T *wp, bool atend, bool prefer_above)
{
- linenr_T old_topline = curwin->w_topline;
- lineoff_T loff = { .lnum = curwin->w_cursor.lnum };
- lineoff_T boff = { .lnum = curwin->w_cursor.lnum };
- hasFolding(loff.lnum, &loff.lnum, &boff.lnum);
- int used = plines_win_nofill(curwin, loff.lnum, true);
+ linenr_T old_topline = wp->w_topline;
+ lineoff_T loff = { .lnum = wp->w_cursor.lnum };
+ lineoff_T boff = { .lnum = wp->w_cursor.lnum };
+ hasFolding(wp, loff.lnum, &loff.lnum, &boff.lnum);
+ int used = plines_win_nofill(wp, loff.lnum, true);
loff.fill = 0;
boff.fill = 0;
linenr_T topline = loff.lnum;
colnr_T skipcol = 0;
int want_height;
- bool do_sms = curwin->w_p_wrap && curwin->w_p_sms;
+ bool do_sms = wp->w_p_wrap && wp->w_p_sms;
if (do_sms) {
// 'smoothscroll' and 'wrap' are set
if (atend) {
- want_height = (curwin->w_height_inner - used) / 2;
+ want_height = (wp->w_height_inner - used) / 2;
used = 0;
} else {
- want_height = curwin->w_height_inner;
+ want_height = wp->w_height_inner;
}
}
@@ -2139,20 +2116,20 @@ void scroll_cursor_halfway(bool atend, bool prefer_above)
// If using smoothscroll, we can precisely scroll to the
// exact point where the cursor is halfway down the screen.
if (do_sms) {
- topline_back_winheight(curwin, &loff, false);
+ topline_back_winheight(wp, &loff, false);
if (loff.height == MAXCOL) {
break;
}
used += loff.height;
- if (!atend && boff.lnum < curbuf->b_ml.ml_line_count) {
- botline_forw(curwin, &boff);
+ if (!atend && boff.lnum < wp->w_buffer->b_ml.ml_line_count) {
+ botline_forw(wp, &boff);
used += boff.height;
}
if (used > want_height) {
if (used - loff.height < want_height) {
topline = loff.lnum;
topfill = loff.fill;
- skipcol = skipcol_from_plines(curwin, used - want_height);
+ skipcol = skipcol_from_plines(wp, used - want_height);
}
break;
}
@@ -2176,10 +2153,10 @@ void scroll_cursor_halfway(bool atend, bool prefer_above)
? (round == 2 && below < above)
: (round == 1 && below <= above)) {
// add a line below the cursor
- if (boff.lnum < curbuf->b_ml.ml_line_count) {
- botline_forw(curwin, &boff);
+ if (boff.lnum < wp->w_buffer->b_ml.ml_line_count) {
+ botline_forw(wp, &boff);
used += boff.height;
- if (used > curwin->w_height_inner) {
+ if (used > wp->w_height_inner) {
done = true;
break;
}
@@ -2196,13 +2173,13 @@ void scroll_cursor_halfway(bool atend, bool prefer_above)
? (round == 1 && below >= above)
: (round == 1 && below > above)) {
// add a line above the cursor
- topline_back(curwin, &loff);
+ topline_back(wp, &loff);
if (loff.height == MAXCOL) {
used = MAXCOL;
} else {
used += loff.height;
}
- if (used > curwin->w_height_inner) {
+ if (used > wp->w_height_inner) {
done = true;
break;
}
@@ -2216,51 +2193,51 @@ void scroll_cursor_halfway(bool atend, bool prefer_above)
}
}
- if (!hasFolding(topline, &curwin->w_topline, NULL)
- && (curwin->w_topline != topline || skipcol != 0 || curwin->w_skipcol != 0)) {
- curwin->w_topline = topline;
+ if (!hasFolding(wp, topline, &wp->w_topline, NULL)
+ && (wp->w_topline != topline || skipcol != 0 || wp->w_skipcol != 0)) {
+ wp->w_topline = topline;
if (skipcol != 0) {
- curwin->w_skipcol = skipcol;
- redraw_later(curwin, UPD_NOT_VALID);
+ wp->w_skipcol = skipcol;
+ redraw_later(wp, UPD_NOT_VALID);
} else if (do_sms) {
- reset_skipcol(curwin);
+ reset_skipcol(wp);
}
}
- curwin->w_topfill = topfill;
- if (old_topline > curwin->w_topline + curwin->w_height_inner) {
- curwin->w_botfill = false;
+ wp->w_topfill = topfill;
+ if (old_topline > wp->w_topline + wp->w_height_inner) {
+ wp->w_botfill = false;
}
- check_topfill(curwin, false);
- curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
- curwin->w_valid |= VALID_TOPLINE;
+ check_topfill(wp, false);
+ wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
+ wp->w_valid |= VALID_TOPLINE;
}
// Correct the cursor position so that it is in a part of the screen at least
// 'so' lines from the top and bottom, if possible.
// If not possible, put it at the same position as scroll_cursor_halfway().
// When called topline must be valid!
-void cursor_correct(void)
+void cursor_correct(win_T *wp)
{
// 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.
- int above_wanted = get_scrolloff_value(curwin);
- int below_wanted = get_scrolloff_value(curwin);
+ int above_wanted = get_scrolloff_value(wp);
+ int below_wanted = get_scrolloff_value(wp);
if (mouse_dragging > 0) {
above_wanted = mouse_dragging - 1;
below_wanted = mouse_dragging - 1;
}
- if (curwin->w_topline == 1) {
+ if (wp->w_topline == 1) {
above_wanted = 0;
- int max_off = curwin->w_height_inner / 2;
+ int max_off = wp->w_height_inner / 2;
if (below_wanted > max_off) {
below_wanted = max_off;
}
}
- validate_botline(curwin);
- if (curwin->w_botline == curbuf->b_ml.ml_line_count + 1
+ validate_botline(wp);
+ if (wp->w_botline == wp->w_buffer->b_ml.ml_line_count + 1
&& mouse_dragging == 0) {
below_wanted = 0;
- int max_off = (curwin->w_height_inner - 1) / 2;
+ int max_off = (wp->w_height_inner - 1) / 2;
if (above_wanted > max_off) {
above_wanted = max_off;
}
@@ -2268,18 +2245,18 @@ void cursor_correct(void)
// If there are sufficient file-lines above and below the cursor, we can
// return now.
- linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number
- if (cln >= curwin->w_topline + above_wanted
- && cln < curwin->w_botline - below_wanted
- && !hasAnyFolding(curwin)) {
+ linenr_T cln = wp->w_cursor.lnum; // Cursor Line Number
+ if (cln >= wp->w_topline + above_wanted
+ && cln < wp->w_botline - below_wanted
+ && !hasAnyFolding(wp)) {
return;
}
- if (curwin->w_p_sms && !curwin->w_p_wrap) {
+ if (wp->w_p_sms && !wp->w_p_wrap) {
// 'smoothscroll' is active
- if (curwin->w_cline_height == curwin->w_height_inner) {
+ if (wp->w_cline_height == wp->w_height_inner) {
// The cursor line just fits in the window, don't scroll.
- reset_skipcol(curwin);
+ reset_skipcol(wp);
return;
}
// TODO(vim): If the cursor line doesn't fit in the window then only adjust w_skipcol.
@@ -2289,52 +2266,52 @@ void cursor_correct(void)
// the top and the bottom until:
// - the desired context lines are found
// - the lines from the top is past the lines from the bottom
- linenr_T topline = curwin->w_topline;
- linenr_T botline = curwin->w_botline - 1;
+ linenr_T topline = wp->w_topline;
+ linenr_T botline = wp->w_botline - 1;
// count filler lines as context
- int above = curwin->w_topfill; // screen lines above topline
- int below = curwin->w_filler_rows; // screen lines below botline
+ int above = wp->w_topfill; // screen lines above topline
+ int below = wp->w_filler_rows; // screen lines below botline
while ((above < above_wanted || below < below_wanted) && topline < botline) {
if (below < below_wanted && (below <= above || above >= above_wanted)) {
- if (hasFolding(botline, &botline, NULL)) {
+ if (hasFolding(wp, botline, &botline, NULL)) {
below++;
} else {
- below += plines_win(curwin, botline, true);
+ below += plines_win(wp, botline, true);
}
botline--;
}
if (above < above_wanted && (above < below || below >= below_wanted)) {
- if (hasFolding(topline, NULL, &topline)) {
+ if (hasFolding(wp, topline, NULL, &topline)) {
above++;
} else {
- above += plines_win_nofill(curwin, topline, true);
+ above += plines_win_nofill(wp, topline, true);
}
// Count filler lines below this line as context.
if (topline < botline) {
- above += win_get_fill(curwin, topline + 1);
+ above += win_get_fill(wp, topline + 1);
}
topline++;
}
}
if (topline == botline || botline == 0) {
- curwin->w_cursor.lnum = topline;
+ wp->w_cursor.lnum = topline;
} else if (topline > botline) {
- curwin->w_cursor.lnum = botline;
+ wp->w_cursor.lnum = botline;
} else {
- if (cln < topline && curwin->w_topline > 1) {
- curwin->w_cursor.lnum = topline;
- curwin->w_valid &=
+ if (cln < topline && wp->w_topline > 1) {
+ wp->w_cursor.lnum = topline;
+ wp->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW);
}
- if (cln > botline && curwin->w_botline <= curbuf->b_ml.ml_line_count) {
- curwin->w_cursor.lnum = botline;
- curwin->w_valid &=
+ if (cln > botline && wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) {
+ wp->w_cursor.lnum = botline;
+ wp->w_valid &=
~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW);
}
}
- curwin->w_valid |= VALID_TOPLINE;
- curwin->w_viewport_invalid = true;
+ wp->w_valid |= VALID_TOPLINE;
+ wp->w_viewport_invalid = true;
}
/// Move screen "count" pages up ("dir" is BACKWARD) or down ("dir" is FORWARD)
@@ -2461,7 +2438,7 @@ int onepage(Direction dir, int count)
botline_forw(curwin, &loff);
botline_topline(&loff);
// We're at the wrong end of a fold now.
- hasFoldingWin(curwin, loff.lnum, &loff.lnum, NULL, true, NULL);
+ hasFolding(curwin, loff.lnum, &loff.lnum, NULL);
// Always scroll at least one line. Avoid getting stuck on
// very long lines.
@@ -2491,9 +2468,9 @@ int onepage(Direction dir, int count)
}
}
}
- foldAdjustCursor();
- cursor_correct();
- check_cursor_col();
+ foldAdjustCursor(curwin);
+ cursor_correct(curwin);
+ check_cursor_col(curwin);
if (retval == OK) {
beginline(BL_SOL | BL_FIX);
}
@@ -2504,14 +2481,14 @@ int onepage(Direction dir, int count)
// But make sure we scroll at least one line (happens with mix of long
// wrapping lines and non-wrapping line).
if (check_top_offset()) {
- scroll_cursor_top(1, false);
+ scroll_cursor_top(curwin, 1, false);
if (curwin->w_topline <= old_topline
&& old_topline < curbuf->b_ml.ml_line_count) {
curwin->w_topline = old_topline + 1;
- hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+ hasFolding(curwin, curwin->w_topline, &curwin->w_topline, NULL);
}
} else if (curwin->w_botline > curbuf->b_ml.ml_line_count) {
- hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+ hasFolding(curwin, curwin->w_topline, &curwin->w_topline, NULL);
}
}
@@ -2610,7 +2587,7 @@ void halfpage(bool flag, linenr_T Prenum)
if (n < 0 && scrolled > 0) {
break;
}
- hasFolding(curwin->w_topline, NULL, &curwin->w_topline);
+ hasFolding(curwin, curwin->w_topline, NULL, &curwin->w_topline);
curwin->w_topline++;
curwin->w_topfill = win_get_fill(curwin, curwin->w_topline);
@@ -2634,7 +2611,7 @@ void halfpage(bool flag, linenr_T Prenum)
if (i > room) {
break;
}
- hasFolding(curwin->w_botline, NULL, &curwin->w_botline);
+ hasFolding(curwin, curwin->w_botline, NULL, &curwin->w_botline);
curwin->w_botline++;
room -= i;
} while (curwin->w_botline <= curbuf->b_ml.ml_line_count);
@@ -2646,7 +2623,7 @@ void halfpage(bool flag, linenr_T Prenum)
if (hasAnyFolding(curwin)) {
while (--n >= 0
&& curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) {
- hasFolding(curwin->w_cursor.lnum, NULL,
+ hasFolding(curwin, curwin->w_cursor.lnum, NULL,
&curwin->w_cursor.lnum);
curwin->w_cursor.lnum++;
}
@@ -2669,7 +2646,7 @@ void halfpage(bool flag, linenr_T Prenum)
break;
}
curwin->w_topline--;
- hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
+ hasFolding(curwin, curwin->w_topline, &curwin->w_topline, NULL);
curwin->w_topfill = 0;
}
curwin->w_valid &= ~(VALID_CROW|VALID_WROW|
@@ -2688,7 +2665,7 @@ void halfpage(bool flag, linenr_T Prenum)
} else if (hasAnyFolding(curwin)) {
while (--n >= 0 && curwin->w_cursor.lnum > 1) {
curwin->w_cursor.lnum--;
- hasFolding(curwin->w_cursor.lnum,
+ hasFolding(curwin, curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
}
} else {
@@ -2697,9 +2674,9 @@ void halfpage(bool flag, linenr_T Prenum)
}
}
// Move cursor to first line of closed fold.
- foldAdjustCursor();
+ foldAdjustCursor(curwin);
check_topfill(curwin, !flag);
- cursor_correct();
+ cursor_correct(curwin);
beginline(BL_SOL | BL_FIX);
redraw_later(curwin, UPD_VALID);
}
@@ -2748,12 +2725,12 @@ void do_check_cursorbind(void)
{
int restart_edit_save = restart_edit;
restart_edit = true;
- check_cursor();
+ check_cursor(curwin);
// Avoid a scroll here for the cursor position, 'scrollbind' is
// more important.
if (!curwin->w_p_scb) {
- validate_cursor();
+ validate_cursor(curwin);
}
restart_edit = restart_edit_save;