mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
misc: refactor plines_win{,_nofill}()
Add const to params and variables (declare and init on same line). winheight (param) is bool so replace TRUE/FALSE macros with true/false.
This commit is contained in:
parent
766683622a
commit
c51c2f5a65
@ -1203,16 +1203,15 @@ int get_last_leader_offset(char_u *line, char_u **flags)
|
||||
/*
|
||||
* Return the number of window lines occupied by buffer line "lnum".
|
||||
*/
|
||||
int plines(linenr_T lnum)
|
||||
int plines(const linenr_T lnum)
|
||||
{
|
||||
return plines_win(curwin, lnum, TRUE);
|
||||
return plines_win(curwin, lnum, true);
|
||||
}
|
||||
|
||||
int
|
||||
plines_win (
|
||||
win_T *wp,
|
||||
linenr_T lnum,
|
||||
int winheight /* when TRUE limit to window height */
|
||||
int plines_win(
|
||||
win_T *const wp,
|
||||
const linenr_T lnum,
|
||||
const bool winheight // when true limit to window height
|
||||
)
|
||||
{
|
||||
/* Check for filler lines above this buffer line. When folded the result
|
||||
@ -1220,34 +1219,34 @@ plines_win (
|
||||
return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum);
|
||||
}
|
||||
|
||||
int plines_nofill(linenr_T lnum)
|
||||
int plines_nofill(const linenr_T lnum)
|
||||
{
|
||||
return plines_win_nofill(curwin, lnum, TRUE);
|
||||
return plines_win_nofill(curwin, lnum, true);
|
||||
}
|
||||
|
||||
int
|
||||
plines_win_nofill (
|
||||
win_T *wp,
|
||||
linenr_T lnum,
|
||||
int winheight /* when TRUE limit to window height */
|
||||
int plines_win_nofill(
|
||||
win_T *const wp,
|
||||
const linenr_T lnum,
|
||||
const bool winheight // when true limit to window height
|
||||
)
|
||||
{
|
||||
int lines;
|
||||
|
||||
if (!wp->w_p_wrap)
|
||||
if (!wp->w_p_wrap) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (wp->w_width == 0)
|
||||
if (wp->w_width == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// A folded lines is handled just like an empty line.
|
||||
if (lineFolded(wp, lnum)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
lines = plines_win_nofold(wp, lnum);
|
||||
if (winheight > 0 && lines > wp->w_height)
|
||||
const int lines = plines_win_nofold(wp, lnum);
|
||||
if (winheight && lines > wp->w_height) {
|
||||
return wp->w_height;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@ -1347,11 +1346,12 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last)
|
||||
++count; /* count 1 for "+-- folded" line */
|
||||
first += x;
|
||||
} else {
|
||||
if (first == wp->w_topline)
|
||||
count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill;
|
||||
else
|
||||
count += plines_win(wp, first, TRUE);
|
||||
++first;
|
||||
if (first == wp->w_topline) {
|
||||
count += plines_win_nofill(wp, first, true) + wp->w_topfill;
|
||||
} else {
|
||||
count += plines_win(wp, first, true);
|
||||
}
|
||||
first++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
|
@ -990,7 +990,7 @@ static void win_update(win_T *wp)
|
||||
* when it won't get updated below. */
|
||||
if (wp->w_p_diff && bot_start > 0)
|
||||
wp->w_lines[0].wl_size =
|
||||
plines_win_nofill(wp, wp->w_topline, TRUE)
|
||||
plines_win_nofill(wp, wp->w_topline, true)
|
||||
+ wp->w_topfill;
|
||||
}
|
||||
}
|
||||
@ -1447,12 +1447,13 @@ static void win_update(win_T *wp)
|
||||
}
|
||||
|
||||
wp->w_lines[idx].wl_lnum = lnum;
|
||||
wp->w_lines[idx].wl_valid = TRUE;
|
||||
if (row > wp->w_height) { /* past end of screen */
|
||||
/* we may need the size of that too long line later on */
|
||||
if (dollar_vcol == -1)
|
||||
wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE);
|
||||
++idx;
|
||||
wp->w_lines[idx].wl_valid = true;
|
||||
if (row > wp->w_height) { // past end of screen
|
||||
// we may need the size of that too long line later on
|
||||
if (dollar_vcol == -1) {
|
||||
wp->w_lines[idx].wl_size = plines_win(wp, lnum, true);
|
||||
}
|
||||
idx++;
|
||||
break;
|
||||
}
|
||||
if (dollar_vcol == -1)
|
||||
|
@ -4848,8 +4848,8 @@ void scroll_to_fraction(win_T *wp, int prev_height)
|
||||
sline = wp->w_wrow - line_size;
|
||||
|
||||
if (sline >= 0) {
|
||||
/* Make sure the whole cursor line is visible, if possible. */
|
||||
int rows = plines_win(wp, lnum, FALSE);
|
||||
// Make sure the whole cursor line is visible, if possible.
|
||||
const int rows = plines_win(wp, lnum, false);
|
||||
|
||||
if (sline > wp->w_height - rows) {
|
||||
sline = wp->w_height - rows;
|
||||
@ -4884,12 +4884,13 @@ void scroll_to_fraction(win_T *wp, int prev_height)
|
||||
--sline;
|
||||
break;
|
||||
}
|
||||
--lnum;
|
||||
if (lnum == wp->w_topline)
|
||||
line_size = plines_win_nofill(wp, lnum, TRUE)
|
||||
lnum--;
|
||||
if (lnum == wp->w_topline) {
|
||||
line_size = plines_win_nofill(wp, lnum, true)
|
||||
+ wp->w_topfill;
|
||||
else
|
||||
line_size = plines_win(wp, lnum, TRUE);
|
||||
} else {
|
||||
line_size = plines_win(wp, lnum, true);
|
||||
}
|
||||
sline -= line_size;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user