decoration: split out "decoration" from "extmark" module

Decorations will only grow more complex. move the to a separate
file, so that extmark.c remains about extmarks.
This commit is contained in:
Björn Linse
2020-11-07 09:24:00 +01:00
parent da134270d3
commit 8497d4b3ea
15 changed files with 471 additions and 428 deletions

View File

@@ -88,6 +88,7 @@
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/extmark.h"
#include "nvim/decoration.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
@@ -124,7 +125,7 @@
#define MB_FILLER_CHAR '<' /* character used when a double-width character
* doesn't fit. */
typedef kvec_withinit_t(DecorationProvider *, 4) Providers;
typedef kvec_withinit_t(DecorProvider *, 4) Providers;
// temporary buffer for rendering a single screenline, so it can be
// compared with previous contents to calculate smallest delta.
@@ -473,8 +474,8 @@ int update_screen(int type)
Providers providers;
kvi_init(providers);
for (size_t i = 0; i < kv_size(decoration_providers); i++) {
DecorationProvider *p = &kv_A(decoration_providers, i);
for (size_t i = 0; i < kv_size(decor_providers); i++) {
DecorProvider *p = &kv_A(decor_providers, i);
if (!p->active) {
continue;
}
@@ -556,16 +557,16 @@ int update_screen(int type)
buf->b_mod_tick_syn = display_tick;
}
if (buf->b_mod_tick_deco < display_tick) {
if (buf->b_mod_tick_decor < display_tick) {
for (size_t i = 0; i < kv_size(providers); i++) {
DecorationProvider *p = kv_A(providers, i);
DecorProvider *p = kv_A(providers, i);
if (p && p->redraw_buf != LUA_NOREF) {
FIXED_TEMP_ARRAY(args, 1);
args.items[0] = BUFFER_OBJ(buf->handle);
provider_invoke(p->ns_id, "buf", p->redraw_buf, args, true);
}
}
buf->b_mod_tick_deco = display_tick;
buf->b_mod_tick_decor = display_tick;
}
}
}
@@ -579,8 +580,6 @@ int update_screen(int type)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
redrawn_win = wp;
if (wp->w_redr_type == CLEAR && wp->w_floating && wp->w_grid.chars) {
grid_invalidate(&wp->w_grid);
wp->w_redr_type = NOT_VALID;
@@ -598,8 +597,6 @@ int update_screen(int type)
if (wp->w_redr_status) {
win_redr_status(wp);
}
redrawn_win = NULL;
}
end_search_hl();
@@ -631,7 +628,7 @@ int update_screen(int type)
did_intro = TRUE;
for (size_t i = 0; i < kv_size(providers); i++) {
DecorationProvider *p = kv_A(providers, i);
DecorProvider *p = kv_A(providers, i);
if (!p->active) {
continue;
}
@@ -701,18 +698,6 @@ bool win_cursorline_standout(const win_T *wp)
|| (wp->w_p_cole > 0 && (VIsual_active || !conceal_cursor_line(wp)));
}
static DecorationRedrawState decorations;
void decorations_add_ephemeral(int attr_id,
int start_row, int start_col,
int end_row, int end_col, VirtText *virt_text)
{
kv_push(decorations.active,
((HlRange){ start_row, start_col,
end_row, end_col,
attr_id, virt_text, virt_text != NULL }));
}
/*
* Update a single window.
*
@@ -1306,7 +1291,7 @@ static void win_update(win_T *wp, Providers *providers)
srow = 0;
lnum = wp->w_topline; // first line shown in window
decorations_redraw_reset(buf, &decorations);
decor_redraw_reset(buf, &decor_state);
Providers line_providers;
kvi_init(line_providers);
@@ -1316,7 +1301,7 @@ static void win_update(win_T *wp, Providers *providers)
: (wp->w_topline + wp->w_height_inner));
for (size_t k = 0; k < kv_size(*providers); k++) {
DecorationProvider *p = kv_A(*providers, k);
DecorProvider *p = kv_A(*providers, k);
if (p && p->redraw_win != LUA_NOREF) {
FIXED_TEMP_ARRAY(args, 4);
args.items[0] = WINDOW_OBJ(wp->handle);
@@ -1755,6 +1740,7 @@ static void win_update(win_T *wp, Providers *providers)
}
}
/* restore got_int, unless CTRL-C was hit while redrawing */
if (!got_int)
got_int = save_got_int;
@@ -2102,7 +2088,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
int prev_c1 = 0; // first composing char for prev_c
bool search_attr_from_match = false; // if search_attr is from :match
bool has_decorations = false; // this buffer has decorations
bool has_decor = false; // this buffer has decoration
bool do_virttext = false; // draw virtual text for this line
char_u buf_fold[FOLD_TEXT_LEN + 1]; // Hold value returned by get_foldtext
@@ -2170,18 +2156,18 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
}
}
has_decorations = decorations_redraw_line(wp->w_buffer, lnum-1,
&decorations);
has_decor = decor_redraw_line(wp->w_buffer, lnum-1,
&decor_state);
for (size_t k = 0; k < kv_size(*providers); k++) {
DecorationProvider *p = kv_A(*providers, k);
DecorProvider *p = kv_A(*providers, k);
if (p && p->redraw_line != LUA_NOREF) {
FIXED_TEMP_ARRAY(args, 3);
args.items[0] = WINDOW_OBJ(wp->handle);
args.items[1] = BUFFER_OBJ(buf->handle);
args.items[2] = INTEGER_OBJ(lnum-1);
if (provider_invoke(p->ns_id, "line", p->redraw_line, args, true)) {
has_decorations = true;
has_decor = true;
} else {
// return 'false' or error: skip rest of this window
kv_A(*providers, k) = NULL;
@@ -2191,7 +2177,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
}
}
if (has_decorations) {
if (has_decor) {
extra_check = true;
}
@@ -2377,7 +2363,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
}
// If this line has a sign with line highlighting set line_attr.
// TODO(bfredl, vigoux): this should not take priority over decorations!
// TODO(bfredl, vigoux): this should not take priority over decoration!
v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL, 0, 1);
if (v != 0) {
line_attr = sign_get_attr((int)v, SIGN_LINEHL);
@@ -3402,9 +3388,9 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
char_attr = hl_combine_attr(spell_attr, char_attr);
}
if (has_decorations && v > 0) {
int extmark_attr = decorations_redraw_col(wp->w_buffer, (colnr_T)v-1,
&decorations);
if (has_decor && v > 0) {
int extmark_attr = decor_redraw_col(wp->w_buffer, (colnr_T)v-1,
&decor_state);
if (extmark_attr != 0) {
if (!attr_pri) {
char_attr = hl_combine_attr(char_attr, extmark_attr);
@@ -3906,8 +3892,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
kv_push(virt_text, ((VirtTextChunk){ .text = err_text,
.hl_id = hl_err }));
do_virttext = true;
} else if (has_decorations) {
VirtText *vp = decorations_redraw_virt_text(wp->w_buffer, &decorations);
} else if (has_decor) {
VirtText *vp = decor_redraw_virt_text(wp->w_buffer, &decor_state);
if (vp) {
virt_text = *vp;
do_virttext = true;