refactor(decor): use decor levels properly

This commit is contained in:
bfredl
2022-04-24 09:28:04 +02:00
parent d306210641
commit 5e2346178c
3 changed files with 26 additions and 33 deletions

View File

@@ -488,6 +488,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
FUNC_API_SINCE(7) FUNC_API_SINCE(7)
{ {
Decoration decor = DECORATION_INIT; Decoration decor = DECORATION_INIT;
bool has_decor = false;
buf_T *buf = find_buffer_by_handle(buffer, err); buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) { if (!buf) {
@@ -577,6 +578,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
if (ERROR_SET(err)) { if (ERROR_SET(err)) {
goto error; goto error;
} }
has_decor = true;
} }
} }
@@ -586,6 +588,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
if (c.size) { if (c.size) {
decor.conceal_char = utf_ptr2char((const char_u *)c.data); decor.conceal_char = utf_ptr2char((const char_u *)c.data);
} }
has_decor = true;
} else if (HAS_KEY(opts->conceal)) { } else if (HAS_KEY(opts->conceal)) {
api_set_error(err, kErrorTypeValidation, "conceal is not a String"); api_set_error(err, kErrorTypeValidation, "conceal is not a String");
goto error; goto error;
@@ -594,6 +597,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
if (opts->virt_text.type == kObjectTypeArray) { if (opts->virt_text.type == kObjectTypeArray) {
decor.virt_text = parse_virt_text(opts->virt_text.data.array, err, decor.virt_text = parse_virt_text(opts->virt_text.data.array, err,
&decor.virt_text_width); &decor.virt_text_width);
has_decor = true;
if (ERROR_SET(err)) { if (ERROR_SET(err)) {
goto error; goto error;
} }
@@ -665,6 +669,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
if (ERROR_SET(err)) { if (ERROR_SET(err)) {
goto error; goto error;
} }
has_decor = true;
} }
} else if (HAS_KEY(opts->virt_lines)) { } else if (HAS_KEY(opts->virt_lines)) {
api_set_error(err, kErrorTypeValidation, "virt_lines is not an Array"); api_set_error(err, kErrorTypeValidation, "virt_lines is not an Array");
@@ -693,6 +698,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
api_set_error(err, kErrorTypeValidation, "sign_text is not a valid value"); api_set_error(err, kErrorTypeValidation, "sign_text is not a valid value");
goto error; goto error;
} }
has_decor = true;
} else if (HAS_KEY(opts->sign_text)) { } else if (HAS_KEY(opts->sign_text)) {
api_set_error(err, kErrorTypeValidation, "sign_text is not a String"); api_set_error(err, kErrorTypeValidation, "sign_text is not a String");
goto error; goto error;
@@ -718,6 +724,9 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
OPTION_TO_BOOL(ephemeral, ephemeral, false); OPTION_TO_BOOL(ephemeral, ephemeral, false);
OPTION_TO_BOOL(decor.ui_watched, ui_watched, false); OPTION_TO_BOOL(decor.ui_watched, ui_watched, false);
if (decor.ui_watched) {
has_decor = true;
}
if (line < 0) { if (line < 0) {
api_set_error(err, kErrorTypeValidation, "line value outside range"); api_set_error(err, kErrorTypeValidation, "line value outside range");
@@ -780,7 +789,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
} }
extmark_set(buf, (uint32_t)ns_id, &id, (int)line, (colnr_T)col, line2, col2, extmark_set(buf, (uint32_t)ns_id, &id, (int)line, (colnr_T)col, line2, col2,
&decor, right_gravity, end_right_gravity, kExtmarkNoUndo); has_decor ? &decor : NULL, right_gravity, end_right_gravity,
kExtmarkNoUndo);
} }
return (Integer)id; return (Integer)id;

View File

@@ -74,8 +74,7 @@ void decor_redraw(buf_T *buf, int row1, int row2, Decoration *decor)
} }
} }
if (decor && (kv_size(decor->virt_text) if (decor && decor_virt_pos(*decor)) {
|| decor->ui_watched)) {
redraw_buf_line_later(buf, row1 + 1); redraw_buf_line_later(buf, row1 + 1);
} }
@@ -175,6 +174,12 @@ Decoration get_decor(mtkey_t mark)
} }
} }
/// @return true if decor has a virtual position (virtual text or ui_watched)
static bool decor_virt_pos(Decoration decor)
{
return kv_size(decor.virt_text) || decor.ui_watched;
}
bool decor_redraw_start(buf_T *buf, int top_row, DecorState *state) bool decor_redraw_start(buf_T *buf, int top_row, DecorState *state)
{ {
@@ -196,22 +201,11 @@ bool decor_redraw_start(buf_T *buf, int top_row, DecorState *state)
Decoration decor = get_decor(mark); Decoration decor = get_decor(mark);
// Exclude non-paired marks unless they contain virt_text or a sign
// or they are ui-watched
if (!mt_paired(mark)
&& !kv_size(decor.virt_text)
&& !decor_has_sign(&decor)
&& !decor.ui_watched) {
goto next_mark;
}
mtpos_t altpos = marktree_get_altpos(buf->b_marktree, mark, NULL); mtpos_t altpos = marktree_get_altpos(buf->b_marktree, mark, NULL);
// Exclude start marks if the end mark position is above the top row // Exclude start marks if the end mark position is above the top row
// Exclude end marks if we have already added the start mark // Exclude end marks if we have already added the start mark
if ((mt_start(mark) && altpos.row < top_row if ((mt_start(mark) && altpos.row < top_row && !decor_virt_pos(decor))
&& !kv_size(decor.virt_text)
&& !decor.ui_watched)
|| (mt_end(mark) && altpos.row >= top_row)) { || (mt_end(mark) && altpos.row >= top_row)) {
goto next_mark; goto next_mark;
} }
@@ -301,13 +295,6 @@ int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, DecorState *
endpos = mark.pos; endpos = mark.pos;
} }
if (endpos.row < mark.pos.row
|| (endpos.row == mark.pos.row && endpos.col <= mark.pos.col)) {
if (!kv_size(decor.virt_text) && !decor.ui_watched) {
goto next_mark;
}
}
decor_add(state, mark.pos.row, mark.pos.col, endpos.row, endpos.col, decor_add(state, mark.pos.row, mark.pos.col, endpos.row, endpos.col,
&decor, false, mark.ns, mark.id); &decor, false, mark.ns, mark.id);
@@ -326,8 +313,7 @@ next_mark:
bool active = false, keep = true; bool active = false, keep = true;
if (item.end_row < state->row if (item.end_row < state->row
|| (item.end_row == state->row && item.end_col <= col)) { || (item.end_row == state->row && item.end_col <= col)) {
if (!(item.start_row >= state->row if (!(item.start_row >= state->row && decor_virt_pos(item.decor))) {
&& (kv_size(item.decor.virt_text) || item.decor.ui_watched))) {
keep = false; keep = false;
} }
} else { } else {
@@ -355,7 +341,7 @@ next_mark:
} }
} }
if ((item.start_row == state->row && item.start_col <= col) if ((item.start_row == state->row && item.start_col <= col)
&& (kv_size(item.decor.virt_text) || item.decor.ui_watched) && decor_virt_pos(item.decor)
&& item.decor.virt_text_pos == kVTOverlay && item.win_col == -1) { && item.decor.virt_text_pos == kVTOverlay && item.win_col == -1) {
item.win_col = (item.decor.virt_text_hide && hidden) ? -2 : win_col; item.win_col = (item.decor.virt_text_hide && hidden) ? -2 : win_col;
} }
@@ -523,8 +509,7 @@ bool decor_redraw_eol(buf_T *buf, DecorState *state, int *eol_attr, int eol_col)
bool has_virttext = false; bool has_virttext = false;
for (size_t i = 0; i < kv_size(state->active); i++) { for (size_t i = 0; i < kv_size(state->active); i++) {
DecorRange item = kv_A(state->active, i); DecorRange item = kv_A(state->active, i);
if (item.start_row == state->row if (item.start_row == state->row && decor_virt_pos(item.decor)) {
&& (kv_size(item.decor.virt_text) || item.decor.ui_watched)) {
has_virttext = true; has_virttext = true;
} }

View File

@@ -1704,13 +1704,11 @@ static void win_update(win_T *wp, DecorProviders *providers)
wp->w_old_botfill = wp->w_botfill; wp->w_old_botfill = wp->w_botfill;
// Send win_extmarks if needed // Send win_extmarks if needed
if (kv_size(win_extmark_arr) > 0) {
for (size_t n = 0; n < kv_size(win_extmark_arr); n++) { for (size_t n = 0; n < kv_size(win_extmark_arr); n++) {
ui_call_win_extmark(wp->w_grid_alloc.handle, wp->handle, ui_call_win_extmark(wp->w_grid_alloc.handle, wp->handle,
kv_A(win_extmark_arr, n).ns_id, kv_A(win_extmark_arr, n).mark_id, kv_A(win_extmark_arr, n).ns_id, kv_A(win_extmark_arr, n).mark_id,
kv_A(win_extmark_arr, n).win_row, kv_A(win_extmark_arr, n).win_col); kv_A(win_extmark_arr, n).win_row, kv_A(win_extmark_arr, n).win_col);
} }
}
if (dollar_vcol == -1) { if (dollar_vcol == -1) {
/* /*