mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #18460 from bfredl/decor33
refactor(decor): use decor levels properly
This commit is contained in:
commit
eccb989689
@ -488,6 +488,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
||||
FUNC_API_SINCE(7)
|
||||
{
|
||||
Decoration decor = DECORATION_INIT;
|
||||
bool has_decor = false;
|
||||
|
||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||
if (!buf) {
|
||||
@ -577,6 +578,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
||||
if (ERROR_SET(err)) {
|
||||
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) {
|
||||
decor.conceal_char = utf_ptr2char((const char_u *)c.data);
|
||||
}
|
||||
has_decor = true;
|
||||
} else if (HAS_KEY(opts->conceal)) {
|
||||
api_set_error(err, kErrorTypeValidation, "conceal is not a String");
|
||||
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) {
|
||||
decor.virt_text = parse_virt_text(opts->virt_text.data.array, err,
|
||||
&decor.virt_text_width);
|
||||
has_decor = true;
|
||||
if (ERROR_SET(err)) {
|
||||
goto error;
|
||||
}
|
||||
@ -665,6 +669,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
||||
if (ERROR_SET(err)) {
|
||||
goto error;
|
||||
}
|
||||
has_decor = true;
|
||||
}
|
||||
} else if (HAS_KEY(opts->virt_lines)) {
|
||||
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");
|
||||
goto error;
|
||||
}
|
||||
has_decor = true;
|
||||
} else if (HAS_KEY(opts->sign_text)) {
|
||||
api_set_error(err, kErrorTypeValidation, "sign_text is not a String");
|
||||
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(decor.ui_watched, ui_watched, false);
|
||||
if (decor.ui_watched) {
|
||||
has_decor = true;
|
||||
}
|
||||
|
||||
if (line < 0) {
|
||||
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,
|
||||
&decor, right_gravity, end_right_gravity, kExtmarkNoUndo);
|
||||
has_decor ? &decor : NULL, right_gravity, end_right_gravity,
|
||||
kExtmarkNoUndo);
|
||||
}
|
||||
|
||||
return (Integer)id;
|
||||
|
@ -74,8 +74,7 @@ void decor_redraw(buf_T *buf, int row1, int row2, Decoration *decor)
|
||||
}
|
||||
}
|
||||
|
||||
if (decor && (kv_size(decor->virt_text)
|
||||
|| decor->ui_watched)) {
|
||||
if (decor && decor_virt_pos(*decor)) {
|
||||
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)
|
||||
{
|
||||
@ -196,22 +201,11 @@ bool decor_redraw_start(buf_T *buf, int top_row, DecorState *state)
|
||||
|
||||
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);
|
||||
|
||||
// Exclude start marks if the end mark position is above the top row
|
||||
// Exclude end marks if we have already added the start mark
|
||||
if ((mt_start(mark) && altpos.row < top_row
|
||||
&& !kv_size(decor.virt_text)
|
||||
&& !decor.ui_watched)
|
||||
if ((mt_start(mark) && altpos.row < top_row && !decor_virt_pos(decor))
|
||||
|| (mt_end(mark) && altpos.row >= top_row)) {
|
||||
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;
|
||||
}
|
||||
|
||||
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, false, mark.ns, mark.id);
|
||||
|
||||
@ -326,8 +313,7 @@ next_mark:
|
||||
bool active = false, keep = true;
|
||||
if (item.end_row < state->row
|
||||
|| (item.end_row == state->row && item.end_col <= col)) {
|
||||
if (!(item.start_row >= state->row
|
||||
&& (kv_size(item.decor.virt_text) || item.decor.ui_watched))) {
|
||||
if (!(item.start_row >= state->row && decor_virt_pos(item.decor))) {
|
||||
keep = false;
|
||||
}
|
||||
} else {
|
||||
@ -355,7 +341,7 @@ next_mark:
|
||||
}
|
||||
}
|
||||
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.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;
|
||||
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.ui_watched)) {
|
||||
if (item.start_row == state->row && decor_virt_pos(item.decor)) {
|
||||
has_virttext = true;
|
||||
}
|
||||
|
||||
|
@ -1704,12 +1704,10 @@ static void win_update(win_T *wp, DecorProviders *providers)
|
||||
wp->w_old_botfill = wp->w_botfill;
|
||||
|
||||
// Send win_extmarks if needed
|
||||
if (kv_size(win_extmark_arr) > 0) {
|
||||
for (size_t n = 0; n < kv_size(win_extmark_arr); n++) {
|
||||
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).win_row, kv_A(win_extmark_arr, n).win_col);
|
||||
}
|
||||
for (size_t n = 0; n < kv_size(win_extmark_arr); n++) {
|
||||
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).win_row, kv_A(win_extmark_arr, n).win_col);
|
||||
}
|
||||
|
||||
if (dollar_vcol == -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user