diff options
Diffstat (limited to 'src/nvim/screen.c')
-rw-r--r-- | src/nvim/screen.c | 126 |
1 files changed, 65 insertions, 61 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 32eb28e761..63e904079e 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -65,6 +65,7 @@ #include <stdbool.h> #include <string.h> +#include "nvim/api/extmark.h" #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" #include "nvim/arabic.h" @@ -694,7 +695,7 @@ void conceal_check_cursor_line(void) if (curwin->w_p_cole > 0 && (conceal_cursor_used != should_conceal)) { redrawWinline(curwin, curwin->w_cursor.lnum); // Need to recompute cursor column, e.g., when starting Visual mode - // without concealing. */ + // without concealing. curs_columns(curwin, true); } } @@ -1951,7 +1952,7 @@ static size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_ first_level = 1; } - for (i = 0; i < MIN(fdc, level); i++) { + for (i = 0; i < MIN(fdc, level); i++) { if (foldinfo.fi_lnum == lnum && first_level + i >= foldinfo.fi_low_level) { symbol = wp->w_p_fcs_chars.foldopen; @@ -2372,11 +2373,12 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc filler_lines = 0; area_highlighting = true; } - int virtual_lines = decor_virtual_lines(wp, lnum); - filler_lines += virtual_lines; + VirtLines virt_lines = KV_INITIAL_VALUE; + int n_virt_lines = decor_virt_lines(wp, lnum, &virt_lines); + filler_lines += n_virt_lines; if (lnum == wp->w_topline) { filler_lines = wp->w_topfill; - virtual_lines = MIN(virtual_lines, filler_lines); + n_virt_lines = MIN(n_virt_lines, filler_lines); } filler_todo = filler_lines; @@ -2669,7 +2671,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // Highlight one character for an empty match. if (shl->startcol == shl->endcol) { if (line[shl->endcol] != NUL) { - shl->endcol += (*mb_ptr2len)(line + shl->endcol); + shl->endcol += utfc_ptr2len(line + shl->endcol); } else { ++shl->endcol; } @@ -2904,7 +2906,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (draw_state == WL_SBR - 1 && n_extra == 0) { draw_state = WL_SBR; - if (filler_todo > filler_lines - virtual_lines) { + if (filler_todo > filler_lines - n_virt_lines) { // TODO(bfredl): check this doesn't inhibit TUI-style // clear-to-end-of-line. c_extra = ' '; @@ -2942,7 +2944,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (wp->w_skipcol == 0 || !wp->w_p_wrap) { need_showbreak = false; } - vcol_sbr = vcol + MB_CHARLEN(sbr); + vcol_sbr = vcol + mb_charlen(sbr); // Correct end of highlighted area for 'showbreak', // required when 'linebreak' is also set. if (tocol == vcol) { @@ -3143,7 +3145,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (shl->startcol == shl->endcol) { // highlight empty match, try again after it - shl->endcol += (*mb_ptr2len)(line + shl->endcol); + shl->endcol += utfc_ptr2len(line + shl->endcol); } // Loop to check if the match starts at the @@ -3242,7 +3244,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // represent special characters (non-printable stuff) and other // things. When all characters are the same, c_extra is used. // If c_final is set, it will compulsorily be used at the end. - // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past + // "p_extra" must end in a NUL to avoid utfc_ptr2len() reads past // "p_extra[n_extra]". // For the '$' of the 'list' option, n_extra == 1, p_extra == "". if (n_extra > 0) { @@ -3277,7 +3279,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)) - && (*mb_char2cells)(mb_c) == 2) { + && utf_char2cells(mb_c) == 2) { c = '>'; mb_c = c; mb_l = 1; @@ -3391,7 +3393,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // next line. if ((wp->w_p_rl ? (col <= 0) : (col >= grid->Columns - 1)) - && (*mb_char2cells)(mb_c) == 2) { + && utf_char2cells(mb_c) == 2) { c = '>'; mb_c = c; mb_utf8 = false; @@ -3580,7 +3582,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // We have just drawn the showbreak value, no need to add // space for it again. if (vcol == vcol_sbr) { - n_extra -= MB_CHARLEN(get_showbreak_value(wp)); + n_extra -= mb_charlen(get_showbreak_value(wp)); if (n_extra < 0) { n_extra = 0; } @@ -3676,7 +3678,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // Only adjust the tab_len, when at the first column after the // showbreak value was drawn. if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) { - vcol_adjusted = vcol - MB_CHARLEN(sbr); + vcol_adjusted = vcol - mb_charlen(sbr); } // tab amount depends on current column tab_len = tabstop_padding(vcol_adjusted, @@ -3703,7 +3705,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // if n_extra > 0, it gives the number of chars // to use for a tab, else we need to calculate the width // for a tab - int len = (tab_len * mb_char2len(wp->w_p_lcs_chars.tab2)); + int len = (tab_len * utf_char2len(wp->w_p_lcs_chars.tab2)); if (n_extra > 0) { len += n_extra - tab_len; } @@ -3726,8 +3728,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc lcs = wp->w_p_lcs_chars.tab3; } utf_char2bytes(lcs, p); - p += mb_char2len(lcs); - n_extra += mb_char2len(lcs) - (saved_nextra > 0 ? 1 : 0); + p += utf_char2len(lcs); + n_extra += utf_char2len(lcs) - (saved_nextra > 0 ? 1 : 0); } p_extra = p_extra_free; @@ -3962,7 +3964,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc && c != NUL) { c = wp->w_p_lcs_chars.prec; lcs_prec_todo = NUL; - if ((*mb_char2cells)(mb_c) > 1) { + if (utf_char2cells(mb_c) > 1) { // Double-width character being overwritten by the "precedes" // character, need to fill up half the character. c_extra = MB_FILLER_CHAR; @@ -4273,7 +4275,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc // // Store the character. // - if (wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) { + if (wp->w_p_rl && utf_char2cells(mb_c) > 1) { // A double-wide character is: put first halve in left cell. off--; col--; @@ -4290,7 +4292,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc linebuf_attr[off] = char_attr; } - if ((*mb_char2cells)(mb_c) > 1) { + if (utf_char2cells(mb_c) > 1) { // Need to fill two screen columns. off++; col++; @@ -4351,7 +4353,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc } - if ((*mb_char2cells)(mb_c) > 1) { + if (utf_char2cells(mb_c) > 1) { // Need to fill two screen columns. if (wp->w_p_rl) { --boguscols; @@ -4423,12 +4425,12 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc int draw_col = col - boguscols; if (filler_todo > 0) { - int index = filler_todo - (filler_lines - virtual_lines); + int index = filler_todo - (filler_lines - n_virt_lines); if (index > 0) { - int fpos = kv_size(buf->b_virt_lines) - index; - assert(fpos >= 0); - int offset = buf->b_virt_line_leftcol ? 0 : win_col_offset; - draw_virt_text_item(buf, offset, kv_A(buf->b_virt_lines, fpos), + int i = kv_size(virt_lines) - index; + 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); } } else { @@ -4506,6 +4508,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc cap_col = 0; } + kv_destroy(virt_lines); xfree(p_extra_free); return row; } @@ -4827,8 +4830,8 @@ static void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, } if (clear_next) { - /* Clear the second half of a double-wide character of which the left - * half was overwritten with a single-wide character. */ + // Clear the second half of a double-wide character of which the left + // half was overwritten with a single-wide character. schar_from_ascii(grid->chars[off_to], ' '); end_dirty++; } @@ -5131,7 +5134,7 @@ void win_redr_status_matches(expand_T *xp, int num_matches, char_u **matches, in for (; *s != NUL; ++s) { s += skip_status_match_char(xp, s); clen += ptr2cells(s); - if ((l = (*mb_ptr2len)(s)) > 1) { + if ((l = utfc_ptr2len(s)) > 1) { STRNCPY(buf + len, s, l); // NOLINT(runtime/printf) s += l - 1; len += l; @@ -5175,9 +5178,9 @@ void win_redr_status_matches(expand_T *xp, int num_matches, char_u **matches, in } wild_menu_showing = WM_SCROLLED; } else { - /* Create status line if needed by setting 'laststatus' to 2. - * Set 'winminheight' to zero to avoid that the window is - * resized. */ + // Create status line if needed by setting 'laststatus' to 2. + // Set 'winminheight' to zero to avoid that the window is + // resized. if (lastwin->w_status_height == 0) { save_p_ls = p_ls; save_p_wmh = p_wmh; @@ -5652,7 +5655,9 @@ static void win_redr_border(win_T *wp) int ic = (i == 0 && !adj[3] && chars[6][0]) ? 6 : 5; grid_put_schar(grid, irow+adj[0], i+adj[3], chars[ic], attrs[ic]); } - grid_put_schar(grid, irow+adj[0], icol+adj[3], chars[4], attrs[4]); + if (adj[1]) { + grid_put_schar(grid, irow+adj[0], icol+adj[3], chars[4], attrs[4]); + } grid_puts_line_flush(false); } } @@ -6078,7 +6083,7 @@ static void prepare_search_hl(win_T *wp, linenr_T lnum) || (cur != NULL && pos_inprogress))) { next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, shl == &search_hl ? NULL : cur); - pos_inprogress = !(cur == NULL || cur->pos.cur == 0); + pos_inprogress = !(cur == NULL || cur->pos.cur == 0); if (shl->lnum != 0) { shl->first_lnum = shl->lnum + shl->rm.endpos[0].lnum @@ -6164,7 +6169,7 @@ static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T minc shl->lnum = 0; break; } - matchcol += mb_ptr2len(ml); + matchcol += utfc_ptr2len(ml); } else { matchcol = shl->rm.endpos[0].col; } @@ -6722,7 +6727,6 @@ bool grid_invalid_row(ScreenGrid *grid, int row) } - /// Copy part of a grid line for vertically split window. static void linecopy(ScreenGrid *grid, int to, int from, int col, int width) { @@ -6959,7 +6963,7 @@ int showmode(void) lines_left = 0; if (do_mode) { - MSG_PUTS_ATTR("--", attr); + msg_puts_attr("--", attr); // CTRL-X in Insert mode if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) { // These messages can get long, avoid a wrap in a narrow window. @@ -6984,7 +6988,7 @@ int showmode(void) msg_puts_attr((const char *)edit_submode, attr); } if (edit_submode_extra != NULL) { - MSG_PUTS_ATTR(" ", attr); // Add a space in between. + msg_puts_attr(" ", attr); // Add a space in between. if ((int)edit_submode_highl < HLF_COUNT) { sub_attr = win_hl_attr(curwin, edit_submode_highl); } else { @@ -6995,37 +6999,37 @@ int showmode(void) } } else { if (State & TERM_FOCUS) { - MSG_PUTS_ATTR(_(" TERMINAL"), attr); + msg_puts_attr(_(" TERMINAL"), attr); } else if (State & VREPLACE_FLAG) { - MSG_PUTS_ATTR(_(" VREPLACE"), attr); + msg_puts_attr(_(" VREPLACE"), attr); } else if (State & REPLACE_FLAG) { - MSG_PUTS_ATTR(_(" REPLACE"), attr); + msg_puts_attr(_(" REPLACE"), attr); } else if (State & INSERT) { if (p_ri) { - MSG_PUTS_ATTR(_(" REVERSE"), attr); + msg_puts_attr(_(" REVERSE"), attr); } - MSG_PUTS_ATTR(_(" INSERT"), attr); + msg_puts_attr(_(" INSERT"), attr); } else if (restart_edit == 'I' || restart_edit == 'i' || restart_edit == 'a') { - MSG_PUTS_ATTR(_(" (insert)"), attr); + msg_puts_attr(_(" (insert)"), attr); } else if (restart_edit == 'R') { - MSG_PUTS_ATTR(_(" (replace)"), attr); + msg_puts_attr(_(" (replace)"), attr); } else if (restart_edit == 'V') { - MSG_PUTS_ATTR(_(" (vreplace)"), attr); + msg_puts_attr(_(" (vreplace)"), attr); } if (p_hkmap) { - MSG_PUTS_ATTR(_(" Hebrew"), attr); + msg_puts_attr(_(" Hebrew"), attr); } if (State & LANGMAP) { if (curwin->w_p_arab) { - MSG_PUTS_ATTR(_(" Arabic"), attr); + msg_puts_attr(_(" Arabic"), attr); } else if (get_keymap_str(curwin, (char_u *)" (%s)", NameBuff, MAXPATHL)) { - MSG_PUTS_ATTR(NameBuff, attr); + msg_puts_attr((char *)NameBuff, attr); } } if ((State & INSERT) && p_paste) { - MSG_PUTS_ATTR(_(" (paste)"), attr); + msg_puts_attr(_(" (paste)"), attr); } if (VIsual_active) { @@ -7049,9 +7053,9 @@ int showmode(void) default: p = N_(" SELECT BLOCK"); break; } - MSG_PUTS_ATTR(_(p), attr); + msg_puts_attr(_(p), attr); } - MSG_PUTS_ATTR(" --", attr); + msg_puts_attr(" --", attr); } need_clear = TRUE; @@ -7140,11 +7144,11 @@ void clearmode(void) static void recording_mode(int attr) { - MSG_PUTS_ATTR(_("recording"), attr); + msg_puts_attr(_("recording"), attr); if (!shortmess(SHM_RECORDING)) { - char_u s[4]; - snprintf((char *)s, ARRAY_SIZE(s), " @%c", reg_recording); - MSG_PUTS_ATTR(s, attr); + char s[4]; + snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording); + msg_puts_attr(s, attr); } } @@ -7324,8 +7328,8 @@ void draw_tabline(void) } } - /* Reset the flag here again, in case evaluating 'tabline' causes it to be - * set. */ + // Reset the flag here again, in case evaluating 'tabline' causes it to be + // set. redraw_tabline = false; } @@ -7390,9 +7394,9 @@ int fillchar_status(int *attr, win_T *wp) *attr = win_hl_attr(wp, HLF_SNC); fill = wp->w_p_fcs_chars.stlnc; } - /* Use fill when there is highlighting, and highlighting of current - * window differs, or the fillchars differ, or this is not the - * current window */ + // Use fill when there is highlighting, and highlighting of current + // window differs, or the fillchars differ, or this is not the + // current window if (*attr != 0 && ((win_hl_attr(wp, HLF_S) != win_hl_attr(wp, HLF_SNC) || !is_curwin || ONE_WINDOW) || (wp->w_p_fcs_chars.stl != wp->w_p_fcs_chars.stlnc))) { |