diff options
-rw-r--r-- | src/nvim/drawline.c | 208 | ||||
-rw-r--r-- | src/nvim/plines.h | 1 |
2 files changed, 109 insertions, 100 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 17d23020fa..f065cf5ef4 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -98,6 +98,7 @@ typedef struct { int char_attr; ///< attributes for next character int n_extra; ///< number of extra bytes + int n_attr; ///< chars with special attr char *p_extra; ///< string of extra chars, plus NUL, only used ///< when c_extra and c_final are NUL char *p_extra_free; ///< p_extra buffer that needs to be freed @@ -123,6 +124,14 @@ typedef struct { int filler_lines; ///< nr of filler lines to be drawn int filler_todo; ///< nr of filler lines still to do + 1 SignTextAttrs sattrs[SIGN_SHOW_MAX]; ///< sign attributes for the sign column + + VirtText virt_inline; + size_t virt_inline_i; + + bool reset_extra_attr; + + int skip_cells; // nr of cells to skip for virtual text + int skipped_cells; // nr of skipped virtual text cells } winlinevars_T; /// for line_putchar. Contains the state that needs to be remembered from @@ -846,6 +855,73 @@ static void apply_cursorline_highlight(win_T *wp, winlinevars_T *wlv) } } +static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t v, bool *do_save) +{ + while (true) { + // we could already be inside an existing inline text with multiple chunks + if (!(wlv->virt_inline_i < kv_size(wlv->virt_inline))) { + DecorState *state = &decor_state; + for (size_t i = 0; i < kv_size(state->active); i++) { + DecorRange *item = &kv_A(state->active, i); + if (item->start_row != state->row + || !kv_size(item->decor.virt_text) + || item->decor.virt_text_pos != kVTInline) { + continue; + } + if (item->win_col >= -1 && item->start_col == v) { + wlv->virt_inline = item->decor.virt_text; + wlv->virt_inline_i = 0; + item->win_col = -2; + break; + } + } + } + + if (wlv->n_extra == 0 || !wlv->extra_for_extmark) { + wlv->reset_extra_attr = false; + } + + if (wlv->n_extra <= 0 && wlv->virt_inline_i < kv_size(wlv->virt_inline)) { + VirtTextChunk vtc = kv_A(wlv->virt_inline, wlv->virt_inline_i); + wlv->p_extra = vtc.text; + wlv->n_extra = (int)strlen(wlv->p_extra); + wlv->extra_for_extmark = true; + wlv->c_extra = NUL; + wlv->c_final = NUL; + wlv->extra_attr = vtc.hl_id ? syn_id2attr(vtc.hl_id) : 0; + wlv->n_attr = mb_charlen(vtc.text); + wlv->virt_inline_i++; + *do_save = true; + // If the text didn't reach until the first window + // column we need to skip cells. + if (wlv->skip_cells > 0) { + int virt_text_len = wlv->n_attr; + if (virt_text_len > wlv->skip_cells) { + int len = mb_charlen2bytelen(wlv->p_extra, wlv->skip_cells); + wlv->n_extra -= len; + wlv->p_extra += len; + wlv->n_attr -= wlv->skip_cells; + // Skipped cells needed to be accounted for in vcol. + wlv->skipped_cells += wlv->skip_cells; + wlv->skip_cells = 0; + } else { + // the whole text is left of the window, drop + // it and advance to the next one + wlv->skip_cells -= virt_text_len; + // Skipped cells needed to be accounted for in vcol. + wlv->skipped_cells += virt_text_len; + wlv->n_attr = 0; + wlv->n_extra = 0; + + // go to the start so the next virtual text chunk can be selected. + continue; + } + } + } + break; + } +} + static bool check_mb_utf8(int *c, int *u8cc) { if (utf_char2len(*c) > 1) { @@ -967,15 +1043,12 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // at end-of-line bool has_fold = foldinfo.fi_level != 0 && foldinfo.fi_lines > 0; - int n_attr = 0; // chars with special attr int saved_attr2 = 0; // char_attr saved for n_attr int n_attr3 = 0; // chars with overruling special attr int saved_attr3 = 0; // char_attr saved for n_attr3 int n_skip = 0; // nr of chars to skip for 'nowrap' or // concealing - int skip_cells = 0; // nr of cells to skip for virtual text - int skipped_cells = 0; // nr of skipped virtual text cells int fromcol_prev = -2; // start of inverting after cursor bool noinvcur = false; // don't invert the cursor @@ -991,8 +1064,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, int search_attr = 0; // attributes desired by 'hlsearch' int saved_search_attr = 0; // search_attr to be used when n_extra // goes to zero - bool reset_extra_attr = false; - int vcol_save_attr = 0; // saved attr for 'cursorcolumn' int syntax_attr = 0; // attributes desired by syntax bool has_syntax = false; // this buffer has syntax highl. @@ -1045,9 +1116,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, int left_curline_col = 0; int right_curline_col = 0; - VirtText virt_inline = KV_INITIAL_VALUE; - size_t virt_inline_i = 0; - int match_conc = 0; ///< cchar for match functions bool on_last_col = false; int syntax_flags = 0; @@ -1449,7 +1517,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // If there the text doesn't reach to the desired column, need to skip // "skip_cells" cells when virtual text follows. if (!wp->w_p_wrap && v > wlv.vcol) { - skip_cells = (int)(v - wlv.vcol); + wlv.skip_cells = (int)(v - wlv.vcol); } // Adjust for when the inverted text is before the screen, @@ -1756,77 +1824,19 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, extmark_attr = decor_redraw_col(wp, (colnr_T)v, wlv.off, selected, &decor_state); - while (true) { - // we could already be inside an existing inline text with multiple chunks - if (!(virt_inline_i < kv_size(virt_inline))) { - DecorState *state = &decor_state; - for (size_t i = 0; i < kv_size(state->active); i++) { - DecorRange *item = &kv_A(state->active, i); - if (item->start_row != state->row - || !kv_size(item->decor.virt_text) - || item->decor.virt_text_pos != kVTInline) { - continue; - } - if (item->win_col >= -1 && item->start_col == v) { - virt_inline = item->decor.virt_text; - virt_inline_i = 0; - item->win_col = -2; - break; - } - } - } - - if (wlv.n_extra == 0 || !wlv.extra_for_extmark) { - reset_extra_attr = false; - } - - if (wlv.n_extra <= 0 && virt_inline_i < kv_size(virt_inline)) { - VirtTextChunk vtc = kv_A(virt_inline, virt_inline_i); - wlv.p_extra = vtc.text; - wlv.n_extra = (int)strlen(wlv.p_extra); - wlv.extra_for_extmark = true; - wlv.c_extra = NUL; - wlv.c_final = NUL; - wlv.extra_attr = vtc.hl_id ? syn_id2attr(vtc.hl_id) : 0; - n_attr = mb_charlen(vtc.text); - // restore search_attr and area_attr when n_extra - // is down to zero - saved_search_attr = search_attr; - saved_area_attr = area_attr; - saved_search_attr_from_match = search_attr_from_match; - search_attr_from_match = false; - search_attr = 0; - area_attr = 0; - extmark_attr = 0; - virt_inline_i++; - n_skip = 0; - // If the text didn't reach until the first window - // column we need to skip cells. - if (skip_cells > 0) { - int virt_text_len = n_attr; - if (virt_text_len > skip_cells) { - int len = mb_charlen2bytelen(wlv.p_extra, skip_cells); - wlv.n_extra -= len; - wlv.p_extra += len; - n_attr -= skip_cells; - // Skipped cells needed to be accounted for in vcol. - skipped_cells += skip_cells; - skip_cells = 0; - } else { - // the whole text is left of the window, drop - // it and advance to the next one - skip_cells -= virt_text_len; - // Skipped cells needed to be accounted for in vcol. - skipped_cells += virt_text_len; - n_attr = 0; - wlv.n_extra = 0; - - // go to the start so the next virtual text chunk can be selected. - continue; - } - } - } - break; + bool do_save = false; + handle_inline_virtual_text(wp, &wlv, v, &do_save); + if (do_save) { + // restore search_attr and area_attr when n_extra is down to zero + // TODO(bfredl): this is ugly as fuck. look if we can do this some other way. + saved_search_attr = search_attr; + saved_area_attr = area_attr; + saved_search_attr_from_match = search_attr_from_match; + search_attr_from_match = false; + search_attr = 0; + area_attr = 0; + extmark_attr = 0; + n_skip = 0; } } @@ -1971,7 +1981,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (wlv.extra_for_extmark) { // wlv.extra_attr should be used at this position but not // any further. - reset_extra_attr = true; + wlv.reset_extra_attr = true; } } wlv.extra_for_extmark = false; @@ -2027,7 +2037,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, wlv.c_extra = NUL; wlv.c_final = NUL; if (area_attr == 0 && search_attr == 0) { - n_attr = wlv.n_extra + 1; + wlv.n_attr = wlv.n_extra + 1; wlv.extra_attr = win_hl_attr(wp, HLF_8); saved_attr2 = wlv.char_attr; // save current attr } @@ -2082,7 +2092,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, wlv.c_final = NUL; c = ' '; if (area_attr == 0 && search_attr == 0) { - n_attr = wlv.n_extra + 1; + wlv.n_attr = wlv.n_extra + 1; wlv.extra_attr = win_hl_attr(wp, HLF_AT); saved_attr2 = wlv.char_attr; // save current attr } @@ -2316,7 +2326,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } else { c = (c == ' ') ? wp->w_p_lcs_chars.space : wp->w_p_lcs_chars.nbsp; } - n_attr = 1; + wlv.n_attr = 1; wlv.extra_attr = win_hl_attr(wp, HLF_0); saved_attr2 = wlv.char_attr; // save current attr mb_c = c; @@ -2339,7 +2349,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, c = wp->w_p_lcs_chars.space; } - n_attr = 1; + wlv.n_attr = 1; wlv.extra_attr = win_hl_attr(wp, HLF_0); saved_attr2 = wlv.char_attr; // save current attr mb_c = c; @@ -2455,7 +2465,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, wlv.c_extra = wp->w_p_lcs_chars.tab2; } wlv.c_final = wp->w_p_lcs_chars.tab3; - n_attr = tab_len + 1; + wlv.n_attr = tab_len + 1; wlv.extra_attr = win_hl_attr(wp, HLF_0); saved_attr2 = wlv.char_attr; // save current attr mb_c = c; @@ -2496,7 +2506,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, lcs_eol_one = -1; ptr--; // put it back at the NUL wlv.extra_attr = win_hl_attr(wp, HLF_AT); - n_attr = 1; + wlv.n_attr = 1; mb_c = c; mb_utf8 = check_mb_utf8(&c, u8cc); } else if (c != NUL) { @@ -2525,7 +2535,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, wlv.n_extra = byte2cells(c) - 1; c = (uint8_t)(*wlv.p_extra++); } - n_attr = wlv.n_extra + 1; + wlv.n_attr = wlv.n_extra + 1; wlv.extra_attr = win_hl_attr(wp, HLF_8); saved_attr2 = wlv.char_attr; // save current attr mb_utf8 = false; // don't draw as UTF-8 @@ -2585,7 +2595,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } } wlv.n_extra = 0; - n_attr = 0; + wlv.n_attr = 0; } else if (n_skip == 0) { is_concealing = true; n_skip = 1; @@ -2620,10 +2630,10 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } // Don't override visual selection highlighting. - if (n_attr > 0 && wlv.draw_state == WL_LINE && !search_attr_from_match) { + if (wlv.n_attr > 0 && wlv.draw_state == WL_LINE && !search_attr_from_match) { wlv.char_attr = hl_combine_attr(wlv.char_attr, wlv.extra_attr); - if (reset_extra_attr) { - reset_extra_attr = false; + if (wlv.reset_extra_attr) { + wlv.reset_extra_attr = false; wlv.extra_attr = 0; // search_attr_from_match can be restored now that the extra_attr has been applied search_attr_from_match = saved_search_attr_from_match; @@ -2647,7 +2657,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, wlv.c_extra = MB_FILLER_CHAR; wlv.c_final = NUL; wlv.n_extra = 1; - n_attr = 2; + wlv.n_attr = 2; wlv.extra_attr = win_hl_attr(wp, HLF_AT); } mb_c = c; @@ -2983,7 +2993,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, wlv.boguscols += wlv.n_extra; } wlv.n_extra = 0; - n_attr = 0; + wlv.n_attr = 0; } if (utf_char2cells(mb_c) > 1) { @@ -3008,7 +3018,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (wlv.n_extra > 0) { wlv.vcol += wlv.n_extra; wlv.n_extra = 0; - n_attr = 0; + wlv.n_attr = 0; } } } else { @@ -3016,9 +3026,9 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } // The skipped cells need to be accounted for in vcol. - if (wlv.draw_state > WL_STC && skipped_cells > 0) { - wlv.vcol += skipped_cells; - skipped_cells = 0; + if (wlv.draw_state > WL_STC && wlv.skipped_cells > 0) { + wlv.vcol += wlv.skipped_cells; + wlv.skipped_cells = 0; } // Only advance the "wlv.vcol" when after the 'number' or @@ -3038,7 +3048,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, } // restore attributes after last 'listchars' or 'number' char - if (n_attr > 0 && wlv.draw_state == WL_LINE && --n_attr == 0) { + if (wlv.n_attr > 0 && wlv.draw_state == WL_LINE && --wlv.n_attr == 0) { wlv.char_attr = saved_attr2; } diff --git a/src/nvim/plines.h b/src/nvim/plines.h index fa55357193..2ce7133705 100644 --- a/src/nvim/plines.h +++ b/src/nvim/plines.h @@ -17,7 +17,6 @@ typedef struct { int cts_cur_text_width_left; // width of virtual text left of cursor int cts_cur_text_width_right; // width of virtual text right of cursor MarkTreeIter cts_iter[1]; - // TODO(bfredl): iterator in to the marktree for scanning virt text int cts_vcol; // virtual column at current position } chartabsize_T; |