mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor: wrap common plines() usage in plines_win_full() #11141
This commit is contained in:
parent
f96d1e6bc4
commit
8d68a37c5a
@ -484,25 +484,39 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column)
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the number of screen lines lnum takes up. This takes care of
|
||||||
|
/// both folds and topfill, and limits to the current window height.
|
||||||
|
///
|
||||||
|
/// @param[in] wp window line is in
|
||||||
|
/// @param[in] lnum line number
|
||||||
|
/// @param[out] nextp if not NULL, the line after a fold
|
||||||
|
/// @param[out] foldedp if not NULL, whether lnum is on a fold
|
||||||
|
/// @param[in] cache whether to use the window's cache for folds
|
||||||
|
///
|
||||||
|
/// @return the total number of screen lines
|
||||||
|
int plines_win_full(win_T *wp, linenr_T lnum, linenr_T *const nextp,
|
||||||
|
bool *const foldedp, const bool cache)
|
||||||
|
{
|
||||||
|
bool folded = hasFoldingWin(wp, lnum, NULL, nextp, cache, NULL);
|
||||||
|
if (foldedp) {
|
||||||
|
*foldedp = folded;
|
||||||
|
}
|
||||||
|
if (folded) {
|
||||||
|
return 1;
|
||||||
|
} else if (lnum == wp->w_topline) {
|
||||||
|
return plines_win_nofill(wp, lnum, true) + wp->w_topfill;
|
||||||
|
}
|
||||||
|
return plines_win(wp, lnum, true);
|
||||||
|
}
|
||||||
|
|
||||||
int plines_m_win(win_T *wp, linenr_T first, linenr_T last)
|
int plines_m_win(win_T *wp, linenr_T first, linenr_T last)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (first <= last) {
|
while (first <= last) {
|
||||||
// Check if there are any really folded lines, but also included lines
|
linenr_T next = first;
|
||||||
// that are maybe folded.
|
count += plines_win_full(wp, first, &next, NULL, false);
|
||||||
linenr_T x = foldedCount(wp, first, NULL);
|
first = next + 1;
|
||||||
if (x > 0) {
|
|
||||||
++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++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -65,17 +65,10 @@ static void comp_botline(win_T *wp)
|
|||||||
done = 0;
|
done = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) {
|
for (; lnum <= wp->w_buffer->b_ml.ml_line_count; lnum++) {
|
||||||
int n;
|
|
||||||
linenr_T last = lnum;
|
linenr_T last = lnum;
|
||||||
bool folded = hasFoldingWin(wp, lnum, NULL, &last, true, NULL);
|
bool folded;
|
||||||
if (folded) {
|
int n = plines_win_full(wp, lnum, &last, &folded, true);
|
||||||
n = 1;
|
|
||||||
} else if (lnum == wp->w_topline) {
|
|
||||||
n = plines_win_nofill(wp, lnum, true) + wp->w_topfill;
|
|
||||||
} else {
|
|
||||||
n = plines_win(wp, lnum, true);
|
|
||||||
}
|
|
||||||
if (lnum <= wp->w_cursor.lnum && last >= wp->w_cursor.lnum) {
|
if (lnum <= wp->w_cursor.lnum && last >= wp->w_cursor.lnum) {
|
||||||
wp->w_cline_row = done;
|
wp->w_cline_row = done;
|
||||||
wp->w_cline_height = n;
|
wp->w_cline_height = n;
|
||||||
@ -571,18 +564,14 @@ static void curs_rows(win_T *wp)
|
|||||||
break;
|
break;
|
||||||
wp->w_cline_row += wp->w_lines[i].wl_size;
|
wp->w_cline_row += wp->w_lines[i].wl_size;
|
||||||
} else {
|
} else {
|
||||||
long fold_count = foldedCount(wp, lnum, NULL);
|
linenr_T last = lnum;
|
||||||
if (fold_count) {
|
bool folded;
|
||||||
lnum += fold_count;
|
int n = plines_win_full(wp, lnum, &last, &folded, false);
|
||||||
if (lnum > wp->w_cursor.lnum)
|
lnum = last + 1;
|
||||||
|
if (folded && lnum > wp->w_cursor.lnum) {
|
||||||
break;
|
break;
|
||||||
++wp->w_cline_row;
|
|
||||||
} else if (lnum == wp->w_topline) {
|
|
||||||
wp->w_cline_row += plines_win_nofill(wp, lnum++, true)
|
|
||||||
+ wp->w_topfill;
|
|
||||||
} else {
|
|
||||||
wp->w_cline_row += plines_win(wp, lnum++, true);
|
|
||||||
}
|
}
|
||||||
|
wp->w_cline_row += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,18 +582,13 @@ static void curs_rows(win_T *wp)
|
|||||||
|| (i < wp->w_lines_valid
|
|| (i < wp->w_lines_valid
|
||||||
&& (!wp->w_lines[i].wl_valid
|
&& (!wp->w_lines[i].wl_valid
|
||||||
|| wp->w_lines[i].wl_lnum != wp->w_cursor.lnum))) {
|
|| wp->w_lines[i].wl_lnum != wp->w_cursor.lnum))) {
|
||||||
if (wp->w_cursor.lnum == wp->w_topline)
|
wp->w_cline_height = plines_win_full(wp, wp->w_cursor.lnum, NULL,
|
||||||
wp->w_cline_height = plines_win_nofill(wp, wp->w_cursor.lnum,
|
&wp->w_cline_folded, true);
|
||||||
true) + wp->w_topfill;
|
|
||||||
else
|
|
||||||
wp->w_cline_height = plines_win(wp, wp->w_cursor.lnum, true);
|
|
||||||
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum,
|
|
||||||
NULL, NULL, true, NULL);
|
|
||||||
} else if (i > wp->w_lines_valid) {
|
} else if (i > wp->w_lines_valid) {
|
||||||
/* a line that is too long to fit on the last screen line */
|
/* a line that is too long to fit on the last screen line */
|
||||||
wp->w_cline_height = 0;
|
wp->w_cline_height = 0;
|
||||||
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum,
|
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, NULL,
|
||||||
NULL, NULL, true, NULL);
|
NULL, true, NULL);
|
||||||
} else {
|
} else {
|
||||||
wp->w_cline_height = wp->w_lines[i].wl_size;
|
wp->w_cline_height = wp->w_lines[i].wl_size;
|
||||||
wp->w_cline_folded = wp->w_lines[i].wl_folded;
|
wp->w_cline_folded = wp->w_lines[i].wl_folded;
|
||||||
@ -646,12 +630,9 @@ static void validate_cheight(void)
|
|||||||
{
|
{
|
||||||
check_cursor_moved(curwin);
|
check_cursor_moved(curwin);
|
||||||
if (!(curwin->w_valid & VALID_CHEIGHT)) {
|
if (!(curwin->w_valid & VALID_CHEIGHT)) {
|
||||||
if (curwin->w_cursor.lnum == curwin->w_topline)
|
curwin->w_cline_height = plines_win_full(curwin, curwin->w_cursor.lnum,
|
||||||
curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum)
|
NULL, &curwin->w_cline_folded,
|
||||||
+ curwin->w_topfill;
|
true);
|
||||||
else
|
|
||||||
curwin->w_cline_height = plines(curwin->w_cursor.lnum);
|
|
||||||
curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL);
|
|
||||||
curwin->w_valid |= VALID_CHEIGHT;
|
curwin->w_valid |= VALID_CHEIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user