aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/drawscreen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/drawscreen.c')
-rw-r--r--src/nvim/drawscreen.c178
1 files changed, 68 insertions, 110 deletions
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index bda0ccc870..aa5c66465b 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -65,6 +65,7 @@
#include "nvim/autocmd.h"
#include "nvim/autocmd_defs.h"
#include "nvim/buffer.h"
+#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/cursor.h"
@@ -394,18 +395,9 @@ void screen_resize(int width, int height)
void check_screensize(void)
{
// Limit Rows and Columns to avoid an overflow in Rows * Columns.
- if (Rows < min_rows()) {
- // need room for one window and command line
- Rows = min_rows();
- } else if (Rows > 1000) {
- Rows = 1000;
- }
-
- if (Columns < MIN_COLUMNS) {
- Columns = MIN_COLUMNS;
- } else if (Columns > 10000) {
- Columns = 10000;
- }
+ // need room for one window and command line
+ Rows = MIN(MAX(Rows, min_rows()), 1000);
+ Columns = MIN(MAX(Columns, MIN_COLUMNS), 10000);
}
/// Return true if redrawing should currently be done.
@@ -715,14 +707,17 @@ void end_search_hl(void)
screen_search_hl.rm.regprog = NULL;
}
-static void win_redr_bordertext(win_T *wp, VirtText vt, int col)
+static void win_redr_bordertext(win_T *wp, VirtText vt, int col, BorderTextType bt)
{
for (size_t i = 0; i < kv_size(vt);) {
- int attr = 0;
+ int attr = -1;
char *text = next_virt_text_chunk(vt, &i, &attr);
if (text == NULL) {
break;
}
+ if (attr == -1) { // No highlight specified.
+ attr = wp->w_ns_hl_attr[bt == kBorderTextTitle ? HLF_BTITLE : HLF_BFOOTER];
+ }
attr = hl_apply_winblend(wp, attr);
col += grid_line_puts(col, text, -1, attr);
}
@@ -773,7 +768,7 @@ static void win_redr_border(win_T *wp)
if (wp->w_config.title) {
int title_col = win_get_bordertext_col(icol, wp->w_config.title_width,
wp->w_config.title_pos);
- win_redr_bordertext(wp, wp->w_config.title_chunks, title_col);
+ win_redr_bordertext(wp, wp->w_config.title_chunks, title_col, kBorderTextTitle);
}
if (adj[1]) {
grid_line_put_schar(icol + adj[3], chars[2], attrs[2]);
@@ -809,7 +804,7 @@ static void win_redr_border(win_T *wp)
if (wp->w_config.footer) {
int footer_col = win_get_bordertext_col(icol, wp->w_config.footer_width,
wp->w_config.footer_pos);
- win_redr_bordertext(wp, wp->w_config.footer_chunks, footer_col);
+ win_redr_bordertext(wp, wp->w_config.footer_chunks, footer_col, kBorderTextFooter);
}
if (adj[1]) {
grid_line_put_schar(icol + adj[3], chars[4], attrs[4]);
@@ -927,13 +922,7 @@ int showmode(void)
msg_ext_clear(true);
}
- // Don't make non-flushed message part of the showmode and reset global
- // variables before flushing to to avoid recursiveness.
- bool draw_mode = redraw_mode;
- bool clear_cmd = clear_cmdline;
- redraw_cmdline = false;
- redraw_mode = false;
- clear_cmdline = false;
+ // Don't make non-flushed message part of the showmode.
msg_ext_ui_flush();
msg_grid_validate();
@@ -956,8 +945,8 @@ int showmode(void)
msg_check_for_delay(false);
// if the cmdline is more than one line high, erase top lines
- bool need_clear = clear_cmd;
- if (clear_cmd && cmdline_row < Rows - 1) {
+ bool need_clear = clear_cmdline;
+ if (clear_cmdline && cmdline_row < Rows - 1) {
msg_clr_cmdline(); // will reset clear_cmdline
}
@@ -998,12 +987,9 @@ int showmode(void)
}
if (edit_submode_extra != NULL) {
msg_puts_attr(" ", attr); // Add a space in between.
- int sub_attr;
- if (edit_submode_highl < HLF_COUNT) {
- sub_attr = win_hl_attr(curwin, (int)edit_submode_highl);
- } else {
- sub_attr = attr;
- }
+ int sub_attr = edit_submode_highl < HLF_COUNT
+ ? win_hl_attr(curwin, (int)edit_submode_highl)
+ : attr;
msg_puts_attr(edit_submode_extra, sub_attr);
}
}
@@ -1079,7 +1065,7 @@ int showmode(void)
}
mode_displayed = true;
- if (need_clear || clear_cmd || draw_mode) {
+ if (need_clear || clear_cmdline || redraw_mode) {
msg_clr_eos();
}
msg_didout = false; // overwrite this message
@@ -1088,10 +1074,10 @@ int showmode(void)
msg_no_more = false;
lines_left = save_lines_left;
need_wait_return = nwr_save; // never ask for hit-return for this
- } else if (clear_cmd && msg_silent == 0) {
+ } else if (clear_cmdline && msg_silent == 0) {
// Clear the whole command line. Will reset "clear_cmdline".
msg_clr_cmdline();
- } else if (draw_mode) {
+ } else if (redraw_mode) {
msg_pos_mode();
msg_clr_eos();
}
@@ -1114,6 +1100,10 @@ int showmode(void)
grid_line_flush();
}
+ redraw_cmdline = false;
+ redraw_mode = false;
+ clear_cmdline = false;
+
return length;
}
@@ -1544,6 +1534,7 @@ static void win_update(win_T *wp)
// Force redraw when width of 'number' or 'relativenumber' column changes.
if (wp->w_nrwidth != nrwidth_new) {
type = UPD_NOT_VALID;
+ changed_line_abv_curs_win(wp);
wp->w_nrwidth = nrwidth_new;
} else {
// Set mod_top to the first line that needs displaying because of
@@ -1561,9 +1552,7 @@ static void win_update(win_T *wp)
// in a pattern match.
if (syntax_present(wp)) {
mod_top -= buf->b_s.b_syn_sync_linebreaks;
- if (mod_top < 1) {
- mod_top = 1;
- }
+ mod_top = MAX(mod_top, 1);
}
}
if (mod_bot == 0 || mod_bot < buf->b_mod_bot) {
@@ -1590,6 +1579,18 @@ static void win_update(win_T *wp)
}
}
}
+
+ if (search_hl_has_cursor_lnum > 0) {
+ // CurSearch was used last time, need to redraw the line with it to
+ // avoid having two matches highlighted with CurSearch.
+ if (mod_top == 0 || mod_top > search_hl_has_cursor_lnum) {
+ mod_top = search_hl_has_cursor_lnum;
+ }
+ if (mod_bot == 0 || mod_bot < search_hl_has_cursor_lnum + 1) {
+ mod_bot = search_hl_has_cursor_lnum + 1;
+ }
+ }
+
if (mod_top != 0 && hasAnyFolding(wp)) {
// A change in a line can cause lines above it to become folded or
// unfolded. Find the top most buffer line that may be affected.
@@ -1620,17 +1621,13 @@ static void win_update(win_T *wp)
}
hasFolding(wp, mod_top, &mod_top, NULL);
- if (mod_top > lnumt) {
- mod_top = lnumt;
- }
+ mod_top = MIN(mod_top, lnumt);
// Now do the same for the bottom line (one above mod_bot).
mod_bot--;
hasFolding(wp, mod_bot, NULL, &mod_bot);
mod_bot++;
- if (mod_bot < lnumb) {
- mod_bot = lnumb;
- }
+ mod_bot = MAX(mod_bot, lnumb);
}
// When a change starts above w_topline and the end is below
@@ -1648,6 +1645,7 @@ static void win_update(win_T *wp)
wp->w_redraw_top = 0; // reset for next time
wp->w_redraw_bot = 0;
+ search_hl_has_cursor_lnum = 0;
// When only displaying the lines at the top, set top_end. Used when
// window has scrolled down for msg_scrolled.
@@ -1807,8 +1805,10 @@ static void win_update(win_T *wp)
// Correct the first entry for filler lines at the top
// when it won't get updated below.
if (win_may_fill(wp) && bot_start > 0) {
- wp->w_lines[0].wl_size = (uint16_t)(plines_win_nofill(wp, wp->w_topline, true)
- + wp->w_topfill);
+ int n = plines_win_nofill(wp, wp->w_topline, false) + wp->w_topfill
+ - adjust_plines_for_skipcol(wp);
+ n = MIN(n, wp->w_height_inner);
+ wp->w_lines[0].wl_size = (uint16_t)n;
}
}
}
@@ -1849,18 +1849,8 @@ static void win_update(win_T *wp)
to = curwin->w_cursor.lnum;
}
// redraw more when the cursor moved as well
- if (wp->w_old_cursor_lnum < from) {
- from = wp->w_old_cursor_lnum;
- }
- if (wp->w_old_cursor_lnum > to) {
- to = wp->w_old_cursor_lnum;
- }
- if (wp->w_old_visual_lnum < from) {
- from = wp->w_old_visual_lnum;
- }
- if (wp->w_old_visual_lnum > to) {
- to = wp->w_old_visual_lnum;
- }
+ from = MIN(MIN(from, wp->w_old_cursor_lnum), wp->w_old_visual_lnum);
+ to = MAX(MAX(to, wp->w_old_cursor_lnum), wp->w_old_visual_lnum);
} else {
// Find the line numbers that need to be updated: The lines
// between the old cursor position and the current cursor
@@ -1882,15 +1872,8 @@ static void win_update(win_T *wp)
&& wp->w_old_visual_lnum != 0) {
from = wp->w_old_visual_lnum;
}
- if (wp->w_old_visual_lnum > to) {
- to = wp->w_old_visual_lnum;
- }
- if (VIsual.lnum < from) {
- from = VIsual.lnum;
- }
- if (VIsual.lnum > to) {
- to = VIsual.lnum;
- }
+ to = MAX(MAX(to, wp->w_old_visual_lnum), VIsual.lnum);
+ from = MIN(from, VIsual.lnum);
}
}
@@ -1925,9 +1908,7 @@ static void win_update(win_T *wp)
pos.col = (colnr_T)strlen(ml_get_buf(wp->w_buffer, pos.lnum));
getvvcol(wp, &pos, NULL, NULL, &t);
- if (toc < t) {
- toc = t;
- }
+ toc = MAX(toc, t);
}
toc++;
} else {
@@ -1937,12 +1918,8 @@ static void win_update(win_T *wp)
if (fromc != wp->w_old_cursor_fcol
|| toc != wp->w_old_cursor_lcol) {
- if (from > VIsual.lnum) {
- from = VIsual.lnum;
- }
- if (to < VIsual.lnum) {
- to = VIsual.lnum;
- }
+ from = MIN(from, VIsual.lnum);
+ to = MAX(to, VIsual.lnum);
}
wp->w_old_cursor_fcol = fromc;
wp->w_old_cursor_lcol = toc;
@@ -1959,19 +1936,13 @@ static void win_update(win_T *wp)
}
// There is no need to update lines above the top of the window.
- if (from < wp->w_topline) {
- from = wp->w_topline;
- }
+ from = MAX(from, wp->w_topline);
// If we know the value of w_botline, use it to restrict the update to
// the lines that are visible in the window.
if (wp->w_valid & VALID_BOTLINE) {
- if (from >= wp->w_botline) {
- from = wp->w_botline - 1;
- }
- if (to >= wp->w_botline) {
- to = wp->w_botline - 1;
- }
+ from = MIN(from, wp->w_botline - 1);
+ to = MIN(to, wp->w_botline - 1);
}
// Find the minimal part to be updated.
@@ -2159,11 +2130,9 @@ static void win_update(win_T *wp)
if (hasFolding(wp, l, NULL, &l)) {
new_rows++;
} else if (l == wp->w_topline) {
- int n = plines_win_nofill(wp, l, false) + wp->w_topfill;
- n -= adjust_plines_for_skipcol(wp);
- if (n > wp->w_height_inner) {
- n = wp->w_height_inner;
- }
+ int n = plines_win_nofill(wp, l, false) + wp->w_topfill
+ - adjust_plines_for_skipcol(wp);
+ n = MIN(n, wp->w_height_inner);
new_rows += n;
} else {
new_rows += plines_win(wp, l, true);
@@ -2228,16 +2197,12 @@ static void win_update(win_T *wp)
x += wp->w_lines[j++].wl_size;
i++;
}
- if (bot_start > x) {
- bot_start = x;
- }
+ bot_start = MIN(bot_start, x);
} else { // j > i
// move entries in w_lines[] downwards
j -= i;
wp->w_lines_valid += (linenr_T)j;
- if (wp->w_lines_valid > wp->w_grid.rows) {
- wp->w_lines_valid = wp->w_grid.rows;
- }
+ wp->w_lines_valid = MIN(wp->w_lines_valid, wp->w_grid.rows);
for (i = wp->w_lines_valid; i - j >= idx; i--) {
wp->w_lines[i] = wp->w_lines[i - j];
}
@@ -2369,9 +2334,7 @@ redr_statuscol:
wp->w_last_cursor_lnum_rnu = wp->w_p_rnu ? wp->w_cursor.lnum : 0;
- if (idx > wp->w_lines_valid) {
- wp->w_lines_valid = idx;
- }
+ wp->w_lines_valid = MAX(wp->w_lines_valid, idx);
// Let the syntax stuff know we stop parsing here.
if (syntax_last_parsed != 0 && syntax_present(wp)) {
@@ -2492,10 +2455,12 @@ redr_statuscol:
recursive = true;
curwin->w_valid &= ~VALID_TOPLINE;
update_topline(curwin); // may invalidate w_botline again
+ // New redraw either due to updated topline or reset skipcol.
if (must_redraw != 0) {
// Don't update for changes in buffer again.
int mod_set = curbuf->b_mod_set;
curbuf->b_mod_set = false;
+ curs_columns(curwin, true);
win_update(curwin);
must_redraw = 0;
curbuf->b_mod_set = mod_set;
@@ -2586,10 +2551,7 @@ int compute_foldcolumn(win_T *wp, int col)
int wmw = wp == curwin && p_wmw == 0 ? 1 : (int)p_wmw;
int wwidth = wp->w_grid.cols;
- if (fdc > wwidth - (col + wmw)) {
- fdc = wwidth - (col + wmw);
- }
- return fdc;
+ return MIN(fdc, wwidth - (col + wmw));
}
/// Return the width of the 'number' and 'relativenumber' column.
@@ -2626,9 +2588,7 @@ int number_width(win_T *wp)
} while (lnum > 0);
// 'numberwidth' gives the minimal width plus one
- if (n < wp->w_p_nuw - 1) {
- n = (int)wp->w_p_nuw - 1;
- }
+ n = MAX(n, (int)wp->w_p_nuw - 1);
// If 'signcolumn' is set to 'number' and there is a sign to display, then
// the minimal width for the number column is 2.
@@ -2653,9 +2613,7 @@ void redraw_later(win_T *wp, int type)
if (type >= UPD_NOT_VALID) {
wp->w_lines_valid = 0;
}
- if (must_redraw < type) { // must_redraw is the maximum of all windows
- must_redraw = type;
- }
+ must_redraw = MAX(must_redraw, type); // must_redraw is the maximum of all windows
}
}
@@ -2673,8 +2631,8 @@ void redraw_all_later(int type)
/// or it is currently not allowed.
void set_must_redraw(int type)
{
- if (!redraw_not_allowed && must_redraw < type) {
- must_redraw = type;
+ if (!redraw_not_allowed) {
+ must_redraw = MAX(must_redraw, type);
}
}