fix(redraw): overwrite double-width char with virt_text properly (#23708)

This commit is contained in:
zeertzjq
2023-05-22 18:22:47 +08:00
committed by GitHub
parent b11a8c1b5d
commit cb34d0ddd0
3 changed files with 85 additions and 9 deletions

View File

@@ -342,12 +342,20 @@ static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode,
schar_T dummy[2];
int cells = line_putchar(buf, &s, through ? dummy : &linebuf_char[col],
max_col - col, false, vcol);
// if we failed to emit a char, we still need to advance
cells = MAX(cells, 1);
// If we failed to emit a char, we still need to put a space and advance.
if (cells < 1) {
schar_from_ascii(linebuf_char[col], ' ');
cells = 1;
}
for (int c = 0; c < cells; c++) {
linebuf_attr[col++] = attr;
}
if (col < max_col && linebuf_char[col][0] == 0) {
// If the left half of a double-width char is overwritten,
// change the right half to a space so that grid redraws properly,
// but don't advance the current column.
schar_from_ascii(linebuf_char[col], ' ');
}
vcol += cells;
}
return col;
@@ -2806,6 +2814,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
wlv.col++;
// UTF-8: Put a 0 in the second screen char.
linebuf_char[wlv.off][0] = 0;
linebuf_attr[wlv.off] = linebuf_attr[wlv.off - 1];
if (wlv.draw_state > WL_STC && wlv.filler_todo <= 0) {
wlv.vcol++;
}

View File

@@ -316,8 +316,7 @@ int grid_puts_len(ScreenGrid *grid, const char *text, int textlen, int row, int
// When at the start of the text and overwriting the right half of a
// two-cell character in the same grid, truncate that into a '>'.
if (ptr == text && col > 0 && grid->chars[off][0] == 0) {
grid->chars[off - 1][0] = '>';
grid->chars[off - 1][1] = 0;
schar_from_ascii(grid->chars[off - 1], '>');
}
schar_copy(grid->chars[off], buf);