fix(ui): handle virtual text with multiple hl in more cases (#25304)

This commit is contained in:
zeertzjq
2023-09-22 15:36:24 +08:00
committed by GitHub
parent 34a786bc49
commit 64e8a3c4d1
7 changed files with 69 additions and 53 deletions

View File

@@ -1188,8 +1188,7 @@ VirtText parse_virt_text(Array chunks, Error *err, int *width)
goto free_exit;
}
if (j < arr.size - 1) {
kv_push(virt_text, ((VirtTextChunk){ .text = NULL,
.hl_id = hl_id }));
kv_push(virt_text, ((VirtTextChunk){ .text = NULL, .hl_id = hl_id }));
}
}
} else {

View File

@@ -153,6 +153,24 @@ void clear_virttext(VirtText *text)
*text = (VirtText)KV_INITIAL_VALUE;
}
/// Get the next chunk of a virtual text item.
///
/// @param[in] vt The virtual text item
/// @param[in,out] pos Position in the virtual text item
/// @param[in,out] attr Highlight attribute
///
/// @return The text of the chunk, or NULL if there are no more chunks
char *next_virt_text_chunk(VirtText vt, size_t *pos, int *attr)
{
char *text = NULL;
for (; text == NULL && *pos < kv_size(vt); (*pos)++) {
text = kv_A(vt, *pos).text;
int hl_id = kv_A(vt, *pos).hl_id;
*attr = hl_combine_attr(*attr, hl_id > 0 ? syn_id2attr(hl_id) : 0);
}
return text;
}
Decoration *decor_find_virttext(buf_T *buf, int row, uint64_t ns_id)
{
MarkTreeIter itr[1] = { 0 };

View File

@@ -324,24 +324,6 @@ static void draw_virt_text(win_T *wp, buf_T *buf, int col_off, int *end_col, int
}
}
/// Get the next chunk of a virtual text item.
///
/// @param[in] vt The virtual text item
/// @param[in,out] pos Position in the virtual text item
/// @param[in,out] attr Highlight attribute
///
/// @return The text of the chunk, or NULL if there are no more chunks
static char *next_virt_text_chunk(VirtText vt, size_t *pos, int *attr)
{
char *text = NULL;
for (; text == NULL && *pos < kv_size(vt); (*pos)++) {
text = kv_A(vt, *pos).text;
int hl_id = kv_A(vt, *pos).hl_id;
*attr = hl_combine_attr(*attr, hl_id > 0 ? syn_id2attr(hl_id) : 0);
}
return text;
}
static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode, int max_col,
int vcol, bool rl)
{

View File

@@ -709,13 +709,15 @@ void end_search_hl(void)
screen_search_hl.rm.regprog = NULL;
}
static void win_redr_bordertext(win_T *wp, ScreenGrid *grid, VirtText text_chunks, int row, int col)
static void win_redr_bordertext(win_T *wp, ScreenGrid *grid, VirtText vt, int row, int col)
{
for (size_t i = 0; i < text_chunks.size; i++) {
char *text = text_chunks.items[i].text;
for (size_t i = 0; i < kv_size(vt);) {
int attr = 0;
char *text = next_virt_text_chunk(vt, &i, &attr);
if (text == NULL) {
break;
}
int cell = (int)mb_string2cells(text);
int hl_id = text_chunks.items[i].hl_id;
int attr = hl_id ? syn_id2attr(hl_id) : 0;
grid_puts(grid, text, row, col, attr);
col += cell;
}

View File

@@ -3344,8 +3344,13 @@ void f_foldtextresult(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
if (kv_size(vt) > 0) {
assert(*text == NUL);
for (size_t i = 0; i < kv_size(vt); i++) {
char *new_text = concat_str(text, kv_A(vt, i).text);
for (size_t i = 0; i < kv_size(vt);) {
int attr = 0;
char *new_text = next_virt_text_chunk(vt, &i, &attr);
if (new_text == NULL) {
break;
}
new_text = concat_str(text, new_text);
xfree(text);
text = new_text;
}