diff options
Diffstat (limited to 'src/nvim/screen.c')
-rw-r--r-- | src/nvim/screen.c | 489 |
1 files changed, 236 insertions, 253 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 4d0fde642d..86dbf532a7 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -132,10 +132,6 @@ static match_T search_hl; // used for 'hlsearch' highlight matching -StlClickDefinition *tab_page_click_defs = NULL; - -long tab_page_click_defs_size = 0; - // for line_putchar. Contains the state that needs to be remembered from // putting one character to the next. typedef struct { @@ -276,25 +272,25 @@ void redrawWinline(win_T *wp, linenr_T lnum) } } -/* - * update all windows that are editing the current buffer - */ -void update_curbuf(int type) -{ - redraw_curbuf_later(type); - update_screen(type); -} - /// called when the status bars for the buffer 'buf' need to be updated void redraw_buf_status_later(buf_T *buf) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (wp->w_buffer == buf - && (wp->w_status_height || (wp == curwin && global_stl_height()))) { + if (wp->w_buffer != buf) { + continue; + } + bool redraw = false; + + if (wp->w_status_height || (wp == curwin && global_stl_height())) { wp->w_redr_status = true; - if (must_redraw < VALID) { - must_redraw = VALID; - } + redraw = true; + } + if (wp->w_winbar_height) { + wp->w_redr_winbar = true; + redraw = true; + } + if (redraw && must_redraw < VALID) { + must_redraw = VALID; } } } @@ -382,9 +378,9 @@ int update_screen(int type) int valid = MAX(Rows - msg_scrollsize(), 0); if (msg_grid.chars) { // non-displayed part of msg_grid is considered invalid. - for (int i = 0; i < MIN(msg_scrollsize(), msg_grid.Rows); i++) { + for (int i = 0; i < MIN(msg_scrollsize(), msg_grid.rows); i++) { grid_clear_line(&msg_grid, msg_grid.line_offset[i], - msg_grid.Columns, false); + msg_grid.cols, false); } } if (msg_use_msgsep()) { @@ -400,6 +396,9 @@ int update_screen(int type) if (wp->w_floating) { continue; } + if (wp->w_winrow + wp->w_winbar_height > valid) { + wp->w_redr_winbar = true; + } if (W_ENDROW(wp) > valid) { wp->w_redr_type = MAX(wp->w_redr_type, NOT_VALID); } @@ -431,6 +430,9 @@ int update_screen(int type) wp->w_redr_type = REDRAW_TOP; } else { wp->w_redr_type = NOT_VALID; + if (wp->w_winrow + wp->w_winbar_height <= msg_scrolled) { + wp->w_redr_winbar = true; + } if (!is_stl_global && W_ENDROW(wp) + wp->w_status_height <= msg_scrolled) { wp->w_redr_status = true; } @@ -585,10 +587,13 @@ int update_screen(int type) win_update(wp, &providers); } - // redraw status line after the window to minimize cursor movement + // redraw status line and window bar after the window to minimize cursor movement if (wp->w_redr_status) { win_redr_status(wp); } + if (wp->w_redr_winbar) { + win_redr_winbar(wp); + } } end_search_hl(); @@ -598,8 +603,6 @@ int update_screen(int type) pum_redraw(); } - send_grid_resize = false; - /* Reset b_mod_set flags. Going through all windows is probably faster * than going through all buffers (there could be many buffers). */ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { @@ -639,18 +642,18 @@ bool conceal_cursor_line(const win_T *wp) if (*wp->w_p_cocu == NUL) { return false; } - if (get_real_state() & VISUAL) { + if (get_real_state() & MODE_VISUAL) { c = 'v'; - } else if (State & INSERT) { + } else if (State & MODE_INSERT) { c = 'i'; - } else if (State & NORMAL) { + } else if (State & MODE_NORMAL) { c = 'n'; - } else if (State & CMDLINE) { + } else if (State & MODE_CMDLINE) { c = 'c'; } else { return false; } - return vim_strchr(wp->w_p_cocu, c) != NULL; + return vim_strchr((char *)wp->w_p_cocu, c) != NULL; } // Check if the cursor line needs to be redrawn because of 'concealcursor'. @@ -743,11 +746,12 @@ static void win_update(win_T *wp, DecorProviders *providers) if (type >= NOT_VALID) { wp->w_redr_status = true; + wp->w_redr_winbar = true; wp->w_lines_valid = 0; } // Window is zero-height: Only need to draw the separator - if (wp->w_grid.Rows == 0) { + if (wp->w_grid.rows == 0) { // draw the horizontal separator below this window draw_hsep_win(wp); draw_sep_connectors_win(wp); @@ -756,7 +760,7 @@ static void win_update(win_T *wp, DecorProviders *providers) } // Window is zero-width: Only need to draw the separator. - if (wp->w_grid.Columns == 0) { + if (wp->w_grid.cols == 0) { // draw the vertical separator right of this window draw_vsep_win(wp); draw_sep_connectors_win(wp); @@ -955,7 +959,7 @@ static void win_update(win_T *wp, DecorProviders *providers) j = 0; for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ln++) { j++; - if (j >= wp->w_grid.Rows - 2) { + if (j >= wp->w_grid.rows - 2) { break; } (void)hasFoldingWin(wp, ln, NULL, &ln, true, NULL); @@ -963,13 +967,13 @@ static void win_update(win_T *wp, DecorProviders *providers) } else { j = wp->w_lines[0].wl_lnum - wp->w_topline; } - if (j < wp->w_grid.Rows - 2) { // not too far off + if (j < wp->w_grid.rows - 2) { // not too far off i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); // insert extra lines for previously invisible filler lines if (wp->w_lines[0].wl_lnum != wp->w_topline) { i += win_get_fill(wp, wp->w_lines[0].wl_lnum) - wp->w_old_topfill; } - if (i != 0 && i < wp->w_grid.Rows - 2) { // less than a screen off + if (i != 0 && i < wp->w_grid.rows - 2) { // less than a screen off // Try to insert the correct number of lines. // If not the last window, delete the lines at the bottom. // win_ins_lines may fail when the terminal can't do it. @@ -982,8 +986,8 @@ static void win_update(win_T *wp, DecorProviders *providers) // Move the entries that were scrolled, disable // the entries for the lines to be redrawn. - if ((wp->w_lines_valid += j) > wp->w_grid.Rows) { - wp->w_lines_valid = wp->w_grid.Rows; + if ((wp->w_lines_valid += j) > wp->w_grid.rows) { + wp->w_lines_valid = wp->w_grid.rows; } for (idx = wp->w_lines_valid; idx - j >= 0; idx--) { wp->w_lines[idx] = wp->w_lines[idx - j]; @@ -1036,7 +1040,7 @@ static void win_update(win_T *wp, DecorProviders *providers) row -= wp->w_topfill; if (row > 0) { win_scroll_lines(wp, 0, -row); - bot_start = wp->w_grid.Rows - row; + bot_start = wp->w_grid.rows - row; } if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) { /* @@ -1052,7 +1056,7 @@ static void win_update(win_T *wp, DecorProviders *providers) /* stop at line that didn't fit, unless it is still * valid (no lines deleted) */ if (row > 0 && bot_start + row - + (int)wp->w_lines[j].wl_size > wp->w_grid.Rows) { + + (int)wp->w_lines[j].wl_size > wp->w_grid.rows) { wp->w_lines_valid = idx + 1; break; } @@ -1077,18 +1081,18 @@ static void win_update(win_T *wp, DecorProviders *providers) // When starting redraw in the first line, redraw all lines. if (mid_start == 0) { - mid_end = wp->w_grid.Rows; + mid_end = wp->w_grid.rows; } } else { // Not VALID or INVERTED: redraw all lines. mid_start = 0; - mid_end = wp->w_grid.Rows; + mid_end = wp->w_grid.rows; } if (type == SOME_VALID) { // SOME_VALID: redraw all lines. mid_start = 0; - mid_end = wp->w_grid.Rows; + mid_end = wp->w_grid.rows; type = NOT_VALID; } @@ -1275,7 +1279,7 @@ static void win_update(win_T *wp, DecorProviders *providers) } } srow += mid_start; - mid_end = wp->w_grid.Rows; + mid_end = wp->w_grid.rows; for (; idx < wp->w_lines_valid; idx++) { // find end if (wp->w_lines[idx].wl_valid && wp->w_lines[idx].wl_lnum >= to + 1) { @@ -1328,7 +1332,7 @@ static void win_update(win_T *wp, DecorProviders *providers) for (;;) { /* stop updating when reached the end of the window (check for _past_ * the end of the window is at the end of the loop) */ - if (row == wp->w_grid.Rows) { + if (row == wp->w_grid.rows) { didline = true; break; } @@ -1433,7 +1437,7 @@ static void win_update(win_T *wp, DecorProviders *providers) new_rows += plines_win(wp, l, true); } j++; - if (new_rows > wp->w_grid.Rows - row - 2) { + if (new_rows > wp->w_grid.rows - row - 2) { // it's getting too much, must redraw the rest new_rows = 9999; break; @@ -1445,17 +1449,17 @@ static void win_update(win_T *wp, DecorProviders *providers) * remaining text or scrolling fails, must redraw the * rest. If scrolling works, must redraw the text * below the scrolled text. */ - if (row - xtra_rows >= wp->w_grid.Rows - 2) { + if (row - xtra_rows >= wp->w_grid.rows - 2) { mod_bot = MAXLNUM; } else { win_scroll_lines(wp, row, xtra_rows); - bot_start = wp->w_grid.Rows + xtra_rows; + bot_start = wp->w_grid.rows + xtra_rows; } } else if (xtra_rows > 0) { /* May scroll text down. If there is not enough * remaining text of scrolling fails, must redraw the * rest. */ - if (row + xtra_rows >= wp->w_grid.Rows - 2) { + if (row + xtra_rows >= wp->w_grid.rows - 2) { mod_bot = MAXLNUM; } else { win_scroll_lines(wp, row + old_rows, xtra_rows); @@ -1483,7 +1487,7 @@ static void win_update(win_T *wp, DecorProviders *providers) wp->w_lines[j] = wp->w_lines[i]; // stop at a line that won't fit if (x + (int)wp->w_lines[j].wl_size - > wp->w_grid.Rows) { + > wp->w_grid.rows) { wp->w_lines_valid = j + 1; break; } @@ -1497,8 +1501,8 @@ static void win_update(win_T *wp, DecorProviders *providers) // move entries in w_lines[] downwards j -= i; wp->w_lines_valid += j; - if (wp->w_lines_valid > wp->w_grid.Rows) { - wp->w_lines_valid = wp->w_grid.Rows; + if (wp->w_lines_valid > wp->w_grid.rows) { + 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]; @@ -1529,11 +1533,11 @@ static void win_update(win_T *wp, DecorProviders *providers) && wp->w_lines[idx].wl_lnum == lnum && lnum > wp->w_topline && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE)) - && srow + wp->w_lines[idx].wl_size > wp->w_grid.Rows + && srow + wp->w_lines[idx].wl_size > wp->w_grid.rows && win_get_fill(wp, lnum) == 0) { // This line is not going to fit. Don't draw anything here, // will draw "@ " lines below. - row = wp->w_grid.Rows + 1; + row = wp->w_grid.rows + 1; } else { prepare_search_hl(wp, &search_hl, lnum); // Let the syntax stuff know we skipped a few lines. @@ -1544,7 +1548,7 @@ static void win_update(win_T *wp, DecorProviders *providers) // Display one line row = win_line(wp, lnum, srow, - foldinfo.fi_lines ? srow : wp->w_grid.Rows, + foldinfo.fi_lines ? srow : wp->w_grid.rows, mod_top == 0, false, foldinfo, &line_providers); if (foldinfo.fi_lines == 0) { @@ -1563,7 +1567,7 @@ static void win_update(win_T *wp, DecorProviders *providers) wp->w_lines[idx].wl_lnum = lnum; wp->w_lines[idx].wl_valid = true; - if (row > wp->w_grid.Rows) { // past end of grid + if (row > wp->w_grid.rows) { // past end of grid // 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); @@ -1581,13 +1585,13 @@ static void win_update(win_T *wp, DecorProviders *providers) // 'relativenumber' set and cursor moved vertically: The // text doesn't need to be drawn, but the number column does. foldinfo_T info = fold_info(wp, lnum); - (void)win_line(wp, lnum, srow, wp->w_grid.Rows, true, true, + (void)win_line(wp, lnum, srow, wp->w_grid.rows, true, true, info, &line_providers); } // This line does not need to be drawn, advance to the next one. row += wp->w_lines[idx++].wl_size; - if (row > wp->w_grid.Rows) { // past end of screen + if (row > wp->w_grid.rows) { // past end of screen break; } lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; @@ -1635,41 +1639,41 @@ static void win_update(win_T *wp, DecorProviders *providers) * Don't overwrite it, it can be edited. */ wp->w_botline = lnum + 1; - } else if (win_get_fill(wp, lnum) >= wp->w_grid.Rows - srow) { + } else if (win_get_fill(wp, lnum) >= wp->w_grid.rows - srow) { // Window ends in filler lines. wp->w_botline = lnum; - wp->w_filler_rows = wp->w_grid.Rows - srow; + wp->w_filler_rows = wp->w_grid.rows - srow; } else if (dy_flags & DY_TRUNCATE) { // 'display' has "truncate" - int scr_row = wp->w_grid.Rows - 1; + int scr_row = wp->w_grid.rows - 1; // Last line isn't finished: Display "@@@" in the last screen line. - grid_puts_len(&wp->w_grid, (char_u *)"@@", MIN(wp->w_grid.Columns, 2), scr_row, 0, at_attr); + grid_puts_len(&wp->w_grid, (char_u *)"@@", MIN(wp->w_grid.cols, 2), scr_row, 0, at_attr); - grid_fill(&wp->w_grid, scr_row, scr_row + 1, 2, wp->w_grid.Columns, + grid_fill(&wp->w_grid, scr_row, scr_row + 1, 2, wp->w_grid.cols, '@', ' ', at_attr); set_empty_rows(wp, srow); wp->w_botline = lnum; } else if (dy_flags & DY_LASTLINE) { // 'display' has "lastline" - int start_col = wp->w_grid.Columns - 3; + int start_col = wp->w_grid.cols - 3; // Last line isn't finished: Display "@@@" at the end. - grid_fill(&wp->w_grid, wp->w_grid.Rows - 1, wp->w_grid.Rows, - MAX(start_col, 0), wp->w_grid.Columns, '@', '@', at_attr); + grid_fill(&wp->w_grid, wp->w_grid.rows - 1, wp->w_grid.rows, + MAX(start_col, 0), wp->w_grid.cols, '@', '@', at_attr); set_empty_rows(wp, srow); wp->w_botline = lnum; } else { - win_draw_end(wp, '@', ' ', true, srow, wp->w_grid.Rows, HLF_AT); + win_draw_end(wp, '@', ' ', true, srow, wp->w_grid.rows, HLF_AT); wp->w_botline = lnum; } } else { if (eof) { // we hit the end of the file wp->w_botline = buf->b_ml.ml_line_count + 1; j = win_get_fill(wp, wp->w_botline); - if (j > 0 && !wp->w_botfill && row < wp->w_grid.Rows) { + if (j > 0 && !wp->w_botfill && row < wp->w_grid.rows) { // Display filler text below last line. win_line() will check // for ml_line_count+1 and only draw filler lines foldinfo_T info = FOLDINFO_INIT; - row = win_line(wp, wp->w_botline, row, wp->w_grid.Rows, + row = win_line(wp, wp->w_botline, row, wp->w_grid.rows, false, false, info, &line_providers); } } else if (dollar_vcol == -1) { @@ -1678,7 +1682,7 @@ static void win_update(win_T *wp, DecorProviders *providers) // make sure the rest of the screen is blank // write the 'eob' character to rows that aren't part of the file. - win_draw_end(wp, wp->w_p_fcs_chars.eob, ' ', false, row, wp->w_grid.Rows, + win_draw_end(wp, wp->w_p_fcs_chars.eob, ' ', false, row, wp->w_grid.rows, HLF_EOB); } @@ -1763,8 +1767,8 @@ static int win_fill_end(win_T *wp, int c1, int c2, int off, int width, int row, { int nn = off + width; - if (nn > wp->w_grid.Columns) { - nn = wp->w_grid.Columns; + if (nn > wp->w_grid.cols) { + nn = wp->w_grid.cols; } if (wp->w_p_rl) { @@ -1813,7 +1817,7 @@ static void win_draw_end(win_T *wp, int c1, int c2, bool draw_margin, int row, i grid_fill(&wp->w_grid, row, endrow, W_ENDCOL(wp) - 1 - n, W_ENDCOL(wp) - n, c1, c2, attr); } else { - grid_fill(&wp->w_grid, row, endrow, n, wp->w_grid.Columns, c1, c2, attr); + grid_fill(&wp->w_grid, row, endrow, n, wp->w_grid.cols, c1, c2, attr); } set_empty_rows(wp, row); @@ -1837,7 +1841,7 @@ static int compute_foldcolumn(win_T *wp, int col) { int fdc = win_fdccol_count(wp); int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; - int wwidth = wp->w_grid.Columns; + int wwidth = wp->w_grid.cols; if (fdc > wwidth - (col + wmw)) { fdc = wwidth - (col + wmw); @@ -2384,7 +2388,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (ae.rgb_fg_color == -1 && ae.cterm_fg_color == 0) { line_attr_lowprio = cul_attr; } else { - if (!(State & INSERT) && bt_quickfix(wp->w_buffer) + if (!(State & MODE_INSERT) && bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) { line_attr = hl_combine_attr(cul_attr, line_attr); } else { @@ -2621,7 +2625,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // Rightleft window: process the text in the normal direction, but put // it in linebuf_char[off] from right to left. Start at the // rightmost column of the window. - col = grid->Columns - 1; + col = grid->cols - 1; off += col; } @@ -2803,7 +2807,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (wp->w_p_rl) { n_extra = col + 1; } else { - n_extra = grid->Columns - col; + n_extra = grid->cols - col; } char_attr = 0; } else if (filler_todo > 0) { @@ -2818,7 +2822,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (wp->w_p_rl) { n_extra = col + 1; } else { - n_extra = grid->Columns - col; + n_extra = grid->cols - col; } char_attr = win_hl_attr(wp, HLF_DED); } @@ -2876,7 +2880,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (ae.rgb_fg_color == -1 && ae.cterm_fg_color == 0) { line_attr_lowprio = cul_attr; } else { - if (!(State & INSERT) && bt_quickfix(wp->w_buffer) + if (!(State & MODE_INSERT) && bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) { line_attr = hl_combine_attr(cul_attr, line_attr); } else { @@ -2892,15 +2896,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc && vcol >= (long)wp->w_virtcol) || (number_only && draw_state > WL_NR)) && filler_todo <= 0) { - draw_virt_text(wp, buf, win_col_offset, &col, grid->Columns, row); - grid_put_linebuf(grid, row, 0, col, -grid->Columns, wp->w_p_rl, wp, + draw_virt_text(wp, buf, win_col_offset, &col, grid->cols, row); + grid_put_linebuf(grid, row, 0, col, -grid->cols, wp->w_p_rl, wp, wp->w_hl_attr_normal, false); // Pretend we have finished updating the window. Except when // 'cursorcolumn' is set. if (wp->w_p_cuc) { row = wp->w_cline_row + wp->w_cline_height; } else { - row = grid->Rows; + row = grid->rows; } break; } @@ -2928,19 +2932,19 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (draw_state == WL_LINE && has_fold - && col < grid->Columns + && col < grid->cols && n_extra == 0 && row == startrow) { // fill rest of line with 'fold' c_extra = wp->w_p_fcs_chars.fold; c_final = NUL; - n_extra = wp->w_p_rl ? (col + 1) : (grid->Columns - col); + n_extra = wp->w_p_rl ? (col + 1) : (grid->cols - col); } if (draw_state == WL_LINE && has_fold - && col >= grid->Columns + && col >= grid->cols && n_extra != 0 && row == startrow) { // Truncate the folding. @@ -3006,6 +3010,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (area_attr != 0) { char_attr = hl_combine_attr(line_attr, area_attr); + if (!highlight_match) { + // let search highlight show in Visual area if possible + char_attr = hl_combine_attr(search_attr, char_attr); + } } else if (search_attr != 0) { char_attr = hl_combine_attr(line_attr, search_attr); } @@ -3065,7 +3073,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc } // If a double-width char doesn't fit display a '>' in the last column. - if ((wp->w_p_rl ? (col <= 0) : (col >= grid->Columns - 1)) + if ((wp->w_p_rl ? (col <= 0) : (col >= grid->cols - 1)) && utf_char2cells(mb_c) == 2) { c = '>'; mb_c = c; @@ -3179,7 +3187,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // last column; the character is displayed at the start of the // next line. if ((wp->w_p_rl ? (col <= 0) : - (col >= grid->Columns - 1)) + (col >= grid->cols - 1)) && utf_char2cells(mb_c) == 2) { c = '>'; mb_c = c; @@ -3299,7 +3307,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc /* In Insert mode only highlight a word that * doesn't touch the cursor. */ if (spell_hlf != HLF_COUNT - && (State & INSERT) != 0 + && (State & MODE_INSERT) && wp->w_cursor.lnum == lnum && wp->w_cursor.col >= (colnr_T)(prev_ptr - line) @@ -3384,7 +3392,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc } } - if (c == TAB && n_extra + col > grid->Columns) { + if (c == TAB && n_extra + col > grid->cols) { n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts, wp->w_buffer->b_p_vts_array) - 1; } @@ -3587,7 +3595,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc || ((fromcol >= 0 || fromcol_prev >= 0) && tocol > vcol && VIsual_mode != Ctrl_V - && (wp->w_p_rl ? (col >= 0) : (col < grid->Columns)) + && (wp->w_p_rl ? (col >= 0) : (col < grid->cols)) && !(noinvcur && lnum == wp->w_cursor.lnum && (colnr_T)vcol == wp->w_virtcol))) @@ -3659,7 +3667,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc && virtual_active() && tocol != MAXCOL && vcol < tocol - && (wp->w_p_rl ? (col >= 0) : (col < grid->Columns))) { + && (wp->w_p_rl ? (col >= 0) : (col < grid->cols))) { c = ' '; ptr--; // put it back at the NUL } @@ -3668,7 +3676,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (wp->w_p_cole > 0 && (wp != curwin || lnum != wp->w_cursor.lnum || conceal_cursor_line(wp)) && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0 || decor_conceal > 0) - && !(lnum_in_visual_area && vim_strchr(wp->w_p_cocu, 'v') == NULL)) { + && !(lnum_in_visual_area && vim_strchr((char *)wp->w_p_cocu, 'v') == NULL)) { char_attr = conceal_attr; if (((prev_syntax_id != syntax_seqnr && (syntax_flags & HL_CONCEAL) != 0) || has_match_conc > 1 || decor_conceal > 1) @@ -3741,7 +3749,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc && conceal_cursor_line(wp) && (int)wp->w_virtcol <= vcol + n_skip) { if (wp->w_p_rl) { - wp->w_wcol = grid->Columns - col + boguscols - 1; + wp->w_wcol = grid->cols - col + boguscols - 1; } else { wp->w_wcol = col - boguscols; } @@ -3813,7 +3821,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc n = 1; } } else { - if (col >= grid->Columns) { + if (col >= grid->cols) { n = -1; } } @@ -3881,7 +3889,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (((wp->w_p_cuc && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off && (int)wp->w_virtcol < - (long)grid->Columns * (row - startrow + 1) + v + (long)grid->cols * (row - startrow + 1) + v && lnum != wp->w_cursor.lnum) || draw_color_col || line_attr_lowprio || line_attr || diff_hlf != (hlf_T)0 || has_virttext)) { @@ -3919,7 +3927,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc int col_stride = wp->w_p_rl ? -1 : 1; - while (wp->w_p_rl ? col >= 0 : col < grid->Columns) { + while (wp->w_p_rl ? col >= 0 : col < grid->cols) { schar_from_ascii(linebuf_char[off], ' '); col += col_stride; if (draw_color_col) { @@ -3952,7 +3960,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // terminal buffers may need to highlight beyond the end of the // logical line int n = wp->w_p_rl ? -1 : 1; - while (col >= 0 && col < grid->Columns) { + while (col >= 0 && col < grid->cols) { schar_from_ascii(linebuf_char[off], ' '); linebuf_attr[off] = vcol >= TERM_ATTRS_MAX ? 0 : term_attrs[vcol]; off += n; @@ -3961,8 +3969,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc } } - draw_virt_text(wp, buf, win_col_offset, &col, grid->Columns, row); - grid_put_linebuf(grid, row, 0, col, grid->Columns, wp->w_p_rl, wp, + draw_virt_text(wp, buf, win_col_offset, &col, grid->cols, row); + grid_put_linebuf(grid, row, 0, col, grid->cols, wp->w_p_rl, wp, wp->w_hl_attr_normal, false); row++; @@ -3987,7 +3995,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc && wp->w_p_list && !wp->w_p_wrap && filler_todo <= 0 - && (wp->w_p_rl ? col == 0 : col == grid->Columns - 1) + && (wp->w_p_rl ? col == 0 : col == grid->cols - 1) && !has_fold && (*ptr != NUL || lcs_eol_one > 0 @@ -4177,7 +4185,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc * At end of screen line and there is more to come: Display the line * so far. If there is no more to display it is caught above. */ - if ((wp->w_p_rl ? (col < 0) : (col >= grid->Columns)) + if ((wp->w_p_rl ? (col < 0) : (col >= grid->cols)) && foldinfo.fi_lines == 0 && (draw_state != WL_LINE || *ptr != NUL @@ -4190,7 +4198,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc && filler_todo <= 0 // Not drawing diff filler lines. && lcs_eol_one != -1 // Haven't printed the lcs_eol character. && row != endrow - 1 // Not the last line being displayed. - && (grid->Columns == Columns // Window spans the width of the screen, + && (grid->cols == Columns // Window spans the width of the screen, || ui_has(kUIMultigrid)) // or has dedicated grid. && !wp->w_p_rl; // Not right-to-left. @@ -4202,13 +4210,13 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc assert(i >= 0); int offset = kv_A(virt_lines, i).left_col ? 0 : win_col_offset; draw_virt_text_item(buf, offset, kv_A(virt_lines, i).line, - kHlModeReplace, grid->Columns, offset); + kHlModeReplace, grid->cols, offset); } } else { - draw_virt_text(wp, buf, win_col_offset, &draw_col, grid->Columns, row); + draw_virt_text(wp, buf, win_col_offset, &draw_col, grid->cols, row); } - grid_put_linebuf(grid, row, 0, draw_col, grid->Columns, wp->w_p_rl, + grid_put_linebuf(grid, row, 0, draw_col, grid->cols, wp->w_p_rl, wp, wp->w_hl_attr_normal, wrap); if (wrap) { ScreenGrid *current_grid = grid; @@ -4235,7 +4243,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // When the window is too narrow draw all "@" lines. if (draw_state != WL_LINE && filler_todo <= 0) { - win_draw_end(wp, '@', ' ', true, row, wp->w_grid.Rows, HLF_AT); + win_draw_end(wp, '@', ' ', true, row, wp->w_grid.rows, HLF_AT); row = endrow; } @@ -4248,7 +4256,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc col = 0; off = 0; if (wp->w_p_rl) { - col = grid->Columns - 1; // col is not used if breaking! + col = grid->cols - 1; // col is not used if breaking! off += col; } @@ -4524,42 +4532,55 @@ void rl_mirror(char_u *str) } } -/* - * mark all status lines for redraw; used after first :cd - */ +/// Mark all status lines and window bars for redraw; used after first :cd void status_redraw_all(void) { - if (global_stl_height()) { - curwin->w_redr_status = true; - redraw_later(curwin, VALID); - } else { - FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (wp->w_status_height) { - wp->w_redr_status = true; - redraw_later(wp, VALID); - } + bool is_stl_global = global_stl_height() != 0; + + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + bool redraw = false; + + if ((!is_stl_global && wp->w_status_height) || (is_stl_global && wp == curwin)) { + wp->w_redr_status = true; + redraw = true; + } + if (wp->w_winbar_height) { + wp->w_redr_winbar = true; + redraw = true; + } + if (redraw) { + redraw_later(wp, VALID); } } } -/// Marks all status lines of the current buffer for redraw. +/// Marks all status lines and window bars of the current buffer for redraw. void status_redraw_curbuf(void) { status_redraw_buf(curbuf); } -/// Marks all status lines of the specified buffer for redraw. +/// Marks all status lines and window bars of the given buffer for redraw. void status_redraw_buf(buf_T *buf) { - if (global_stl_height() != 0 && curwin->w_buffer == buf) { - curwin->w_redr_status = true; - redraw_later(curwin, VALID); - } else { - FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (wp->w_status_height != 0 && wp->w_buffer == buf) { - wp->w_redr_status = true; - redraw_later(wp, VALID); - } + bool is_stl_global = global_stl_height() != 0; + + FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { + if (wp->w_buffer != buf) { + continue; + } + bool redraw = false; + + if ((!is_stl_global && wp->w_status_height) || (is_stl_global && wp == curwin)) { + wp->w_redr_status = true; + redraw = true; + } + if (wp->w_winbar_height) { + wp->w_redr_winbar = true; + redraw = true; + } + if (redraw) { + redraw_later(wp, VALID); } } } @@ -4573,6 +4594,9 @@ void redraw_statuslines(void) if (wp->w_redr_status) { win_redr_status(wp); } + if (wp->w_redr_winbar) { + win_redr_winbar(wp); + } } if (redraw_tabline) { draw_tabline(); @@ -5071,7 +5095,7 @@ static void redraw_custom_statusline(win_T *wp) entered = true; did_emsg = false; - win_redr_custom(wp, false); + win_redr_custom(wp, false, false); if (did_emsg) { // When there is an error disable the statusline, otherwise the // display is messed up with errors and a redraw triggers the problem @@ -5084,6 +5108,41 @@ static void redraw_custom_statusline(win_T *wp) entered = false; } +static void win_redr_winbar(win_T *wp) +{ + static bool entered = false; + + // Return when called recursively. This can happen when the winbar contains an expression + // that triggers a redraw. + if (entered) { + return; + } + entered = true; + + wp->w_redr_winbar = false; + if (wp->w_winbar_height == 0) { + // No window bar, do nothing. + } else if (!redrawing()) { + // Don't redraw right now, do it later. + wp->w_redr_winbar = true; + } else if (*p_wbr != NUL || *wp->w_p_wbr != NUL) { + int saved_did_emsg = did_emsg; + + did_emsg = false; + win_redr_custom(wp, true, false); + if (did_emsg) { + // When there is an error disable the winbar, otherwise the + // display is messed up with errors and a redraw triggers the problem + // again and again. + set_string_option_direct("winbar", -1, (char_u *)"", + OPT_FREE | (*wp->w_p_stl != NUL + ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); + } + did_emsg |= saved_did_emsg; + } + entered = false; +} + /// Only call if (wp->w_vsep_width != 0). /// /// @return true if the status line of window "wp" is connected to the status @@ -5220,11 +5279,9 @@ bool get_keymap_str(win_T *wp, char_u *fmt, char_u *buf, int len) return buf[0] != NUL; } -/* - * Redraw the status line or ruler of window "wp". - * When "wp" is NULL redraw the tab pages line from 'tabline'. - */ -static void win_redr_custom(win_T *wp, bool draw_ruler) +/// Redraw the status line, window bar or ruler of window "wp". +/// When "wp" is NULL redraw the tab pages line from 'tabline'. +static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler) { static bool entered = false; int attr; @@ -5265,6 +5322,16 @@ static void win_redr_custom(win_T *wp, bool draw_ruler) attr = HL_ATTR(HLF_TPF); maxwidth = Columns; use_sandbox = was_set_insecurely(wp, "tabline", 0); + } else if (draw_winbar) { + stl = (char_u *)((*wp->w_p_wbr != NUL) ? wp->w_p_wbr : p_wbr); + row = -1; // row zero is first row of text + col = 0; + grid = &wp->w_grid; + grid_adjust(&grid, &row, &col); + fillchar = wp->w_p_fcs_chars.wbr; + attr = (wp == curwin) ? HL_ATTR(HLF_WBR) : HL_ATTR(HLF_WBRNC); + maxwidth = wp->w_width_inner; + use_sandbox = was_set_insecurely(wp, "winbar", 0); } else { row = is_stl_global ? (Rows - p_ch - 1) : W_ENDROW(wp); fillchar = fillchar_status(&attr, wp); @@ -5500,85 +5567,6 @@ void check_for_delay(bool check_msg_scroll) } } -/// (Re)allocates a window grid if size changed while in ext_multigrid mode. -/// Updates size, offsets and handle for the grid regardless. -/// -/// If "doclear" is true, don't try to copy from the old grid rather clear the -/// resized grid. -void win_grid_alloc(win_T *wp) -{ - ScreenGrid *grid = &wp->w_grid; - ScreenGrid *grid_allocated = &wp->w_grid_alloc; - - int rows = wp->w_height_inner; - int cols = wp->w_width_inner; - int total_rows = wp->w_height_outer; - int total_cols = wp->w_width_outer; - - bool want_allocation = ui_has(kUIMultigrid) || wp->w_floating; - bool has_allocation = (grid_allocated->chars != NULL); - - if (grid->Rows != rows) { - wp->w_lines_valid = 0; - xfree(wp->w_lines); - wp->w_lines = xcalloc(rows + 1, sizeof(wline_T)); - } - - int was_resized = false; - if (want_allocation && (!has_allocation - || grid_allocated->Rows != total_rows - || grid_allocated->Columns != total_cols)) { - grid_alloc(grid_allocated, total_rows, total_cols, - wp->w_grid_alloc.valid, false); - grid_allocated->valid = true; - if (wp->w_floating && wp->w_float_config.border) { - wp->w_redr_border = true; - } - was_resized = true; - } else if (!want_allocation && has_allocation) { - // Single grid mode, all rendering will be redirected to default_grid. - // Only keep track of the size and offset of the window. - grid_free(grid_allocated); - grid_allocated->valid = false; - was_resized = true; - } else if (want_allocation && has_allocation && !wp->w_grid_alloc.valid) { - grid_invalidate(grid_allocated); - grid_allocated->valid = true; - } - - grid->Rows = rows; - grid->Columns = cols; - - if (want_allocation) { - grid->target = grid_allocated; - grid->row_offset = wp->w_border_adj[0]; - grid->col_offset = wp->w_border_adj[3]; - } else { - grid->target = &default_grid; - grid->row_offset = wp->w_winrow; - grid->col_offset = wp->w_wincol; - } - - // send grid resize event if: - // - a grid was just resized - // - screen_resize was called and all grid sizes must be sent - // - the UI wants multigrid event (necessary) - if ((send_grid_resize || was_resized) && want_allocation) { - ui_call_grid_resize(grid_allocated->handle, - grid_allocated->Columns, grid_allocated->Rows); - } -} - -/// assign a handle to the grid. The grid need not be allocated. -void grid_assign_handle(ScreenGrid *grid) -{ - static int last_grid_handle = DEFAULT_GRID_HANDLE; - - // only assign a grid handle if not already - if (grid->handle == 0) { - grid->handle = ++last_grid_handle; - } -} /// Resize the screen to Rows and Columns. /// @@ -5586,7 +5574,7 @@ void grid_assign_handle(ScreenGrid *grid) /// /// There may be some time between setting Rows and Columns and (re)allocating /// default_grid arrays. This happens when starting up and when -/// (manually) changing the shell size. Always use default_grid.Rows and +/// (manually) changing the shell size. Always use default_grid.rows and /// default_grid.Columns to access items in default_grid.chars[]. Use Rows /// and Columns for positioning text etc. where the final size of the shell is /// needed. @@ -5607,8 +5595,8 @@ retry: // when Rows and Columns have been set and we have started doing full // screen stuff. if ((default_grid.chars != NULL - && Rows == default_grid.Rows - && Columns == default_grid.Columns + && Rows == default_grid.rows + && Columns == default_grid.cols ) || Rows == 0 || Columns == 0 @@ -5707,9 +5695,9 @@ void screenclear(void) } // blank out the default grid - for (i = 0; i < default_grid.Rows; i++) { + for (i = 0; i < default_grid.rows; i++) { grid_clear_line(&default_grid, default_grid.line_offset[i], - default_grid.Columns, true); + default_grid.cols, true); default_grid.line_wraps[i] = false; } @@ -5793,16 +5781,16 @@ void win_scroll_lines(win_T *wp, int row, int line_count) } // No lines are being moved, just draw over the entire area - if (row + abs(line_count) >= wp->w_grid.Rows) { + if (row + abs(line_count) >= wp->w_grid.rows) { return; } if (line_count < 0) { grid_del_lines(&wp->w_grid, row, -line_count, - wp->w_grid.Rows, 0, wp->w_grid.Columns); + wp->w_grid.rows, 0, wp->w_grid.cols); } else { grid_ins_lines(&wp->w_grid, row, line_count, - wp->w_grid.Rows, 0, wp->w_grid.Columns); + wp->w_grid.rows, 0, wp->w_grid.cols); } } @@ -5841,7 +5829,7 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, // Shift line_offset[] line_count down to reflect the inserted lines. // Clear the inserted lines. for (i = 0; i < line_count; i++) { - if (width != grid->Columns) { + if (width != grid->cols) { // need to copy part of a line j = end - 1 - i; while ((j -= line_count) >= row) { @@ -5859,7 +5847,7 @@ void grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col, } grid->line_offset[j + line_count] = temp; grid->line_wraps[j + line_count] = false; - grid_clear_line(grid, temp, grid->Columns, false); + grid_clear_line(grid, temp, grid->cols, false); } } @@ -5890,7 +5878,7 @@ void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, // Now shift line_offset[] line_count up to reflect the deleted lines. // Clear the inserted lines. for (i = 0; i < line_count; i++) { - if (width != grid->Columns) { + if (width != grid->cols) { // need to copy part of a line j = row + i; while ((j += line_count) <= end - 1) { @@ -5909,7 +5897,7 @@ void grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col, } grid->line_offset[j - line_count] = temp; grid->line_wraps[j - line_count] = false; - grid_clear_line(grid, temp, grid->Columns, false); + grid_clear_line(grid, temp, grid->cols, false); } } @@ -5943,8 +5931,8 @@ int showmode(void) msg_grid_validate(); do_mode = ((p_smd && msg_silent == 0) - && ((State & TERM_FOCUS) - || (State & INSERT) + && ((State & MODE_TERMINAL) + || (State & MODE_INSERT) || restart_edit != NUL || VIsual_active)); if (do_mode || reg_recording != 0) { @@ -6013,13 +6001,13 @@ int showmode(void) } } } else { - if (State & TERM_FOCUS) { + if (State & MODE_TERMINAL) { msg_puts_attr(_(" TERMINAL"), attr); } else if (State & VREPLACE_FLAG) { msg_puts_attr(_(" VREPLACE"), attr); } else if (State & REPLACE_FLAG) { msg_puts_attr(_(" REPLACE"), attr); - } else if (State & INSERT) { + } else if (State & MODE_INSERT) { if (p_ri) { msg_puts_attr(_(" REVERSE"), attr); } @@ -6035,7 +6023,7 @@ int showmode(void) if (p_hkmap) { msg_puts_attr(_(" Hebrew"), attr); } - if (State & LANGMAP) { + if (State & MODE_LANGMAP) { if (curwin->w_p_arab) { msg_puts_attr(_(" Arabic"), attr); } else if (get_keymap_str(curwin, (char_u *)" (%s)", @@ -6043,7 +6031,7 @@ int showmode(void) msg_puts_attr((char *)NameBuff, attr); } } - if ((State & INSERT) && p_paste) { + if ((State & MODE_INSERT) && p_paste) { msg_puts_attr(_(" (paste)"), attr); } @@ -6216,7 +6204,7 @@ void draw_tabline(void) // Check for an error. If there is one we would loop in redrawing the // screen. Avoid that by making 'tabline' empty. did_emsg = false; - win_redr_custom(NULL, false); + win_redr_custom(NULL, false, false); if (did_emsg) { set_string_option_direct("tabline", -1, (char_u *)"", OPT_FREE, SID_ERROR); @@ -6390,7 +6378,7 @@ void get_trans_bufname(buf_T *buf) if (buf_spname(buf) != NULL) { STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); } else { - home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); + home_replace(buf, (char_u *)buf->b_fname, NameBuff, MAXPATHL, true); } trans_characters(NameBuff, MAXPATHL); } @@ -6512,7 +6500,7 @@ static void win_redr_ruler(win_T *wp, bool always) int save_called_emsg = called_emsg; called_emsg = false; - win_redr_custom(wp, true); + win_redr_custom(wp, false, true); if (called_emsg) { set_string_option_direct("rulerformat", -1, (char_u *)"", OPT_FREE, SID_ERROR); @@ -6521,13 +6509,10 @@ static void win_redr_ruler(win_T *wp, bool always) return; } - /* - * Check if not in Insert mode and the line is empty (will show "0-1"). - */ - int empty_line = FALSE; - if (!(State & INSERT) - && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) { - empty_line = TRUE; + // Check if not in Insert mode and the line is empty (will show "0-1"). + int empty_line = false; + if ((State & MODE_INSERT) == 0 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, false) == NUL) { + empty_line = true; } /* @@ -6753,11 +6738,9 @@ static void margin_columns_win(win_T *wp, int *left_col, int *right_col) /// Set dimensions of the Nvim application "shell". void screen_resize(int width, int height) { - static bool recursive = false; - // Avoid recursiveness, can happen when setting the window size causes // another window-changed signal. - if (updating_screen || recursive) { + if (updating_screen || resizing_screen) { return; } @@ -6765,9 +6748,9 @@ void screen_resize(int width, int height) return; } - if (State == HITRETURN || State == SETWSIZE) { + if (State == MODE_HITRETURN || State == MODE_SETWSIZE) { // postpone the resizing - State = SETWSIZE; + State = MODE_SETWSIZE; return; } @@ -6779,7 +6762,7 @@ void screen_resize(int width, int height) return; } - recursive = true; + resizing_screen = true; Rows = height; Columns = width; @@ -6796,11 +6779,11 @@ void screen_resize(int width, int height) send_grid_resize = true; - /* The window layout used to be adjusted here, but it now happens in - * screenalloc() (also invoked from screenclear()). That is because the - * "recursive" check above may skip this, but not screenalloc(). */ + /// The window layout used to be adjusted here, but it now happens in + /// screenalloc() (also invoked from screenclear()). That is because the + /// recursize "resizing_screen" check above may skip this, but not screenalloc(). - if (State != ASKMORE && State != EXTERNCMD && State != CONFIRM) { + if (State != MODE_ASKMORE && State != MODE_EXTERNCMD && State != MODE_CONFIRM) { screenclear(); } @@ -6819,7 +6802,7 @@ void screen_resize(int width, int height) * Always need to call update_screen() or screenalloc(), to make * sure Rows/Columns and the size of the screen is correct! */ - if (State == ASKMORE || State == EXTERNCMD || State == CONFIRM + if (State == MODE_ASKMORE || State == MODE_EXTERNCMD || State == MODE_CONFIRM || exmode_active) { screenalloc(); if (msg_grid.chars) { @@ -6833,7 +6816,7 @@ void screen_resize(int width, int height) if (curwin->w_p_scb) { do_check_scrollbind(true); } - if (State & CMDLINE) { + if (State & MODE_CMDLINE) { redraw_popupmenu = false; update_screen(NOT_VALID); redrawcmdline(); @@ -6857,7 +6840,7 @@ void screen_resize(int width, int height) } ui_flush(); } - recursive = false; + resizing_screen = false; } /// Check if the new Nvim application "shell" dimensions are valid. |