vim-patch:9.0.1783: Display issues with virt text smoothscroll and showbreak

Problem:  Wrong display with wrapping virtual text or unprintable chars,
          'showbreak' and 'smoothscroll'.
Solution: Don't skip cells taken by 'showbreak' in screen lines before
          "w_skipcol". Combined "n_skip" and "skip_cells".

closes: vim/vim#12597

b557f48982
This commit is contained in:
zeertzjq
2023-08-23 10:12:00 +08:00
parent 3e80b39a8e
commit a1d71ad55e
8 changed files with 557 additions and 88 deletions

View File

@@ -369,16 +369,19 @@ int lbr_chartabsize_adv(chartabsize_T *cts)
return retval;
}
/// Get the number of characters taken up on the screen indicated by "cts".
/// "cts->cts_cur_text_width_left" and "cts->cts_cur_text_width_right" are set
/// to the extra size for inline virtual text.
/// This function is used very often, keep it fast!!!!
///
/// If "headp" not NULL, set *headp to the size of what we for 'showbreak'
/// string at start of line. Warning: *headp is only set if it's a non-zero
/// value, init to 0 before calling.
/// If "headp" not NULL, set "*headp" to the size of 'showbreak'/'breakindent'
/// included in the return value.
/// When "cts->cts_max_head_vcol" is positive, only count in "*headp" the size
/// of 'showbreak'/'breakindent' before "cts->cts_max_head_vcol".
/// When "cts->cts_max_head_vcol" is negative, only count in "*headp" the size
/// of 'showbreak'/'breakindent' before where cursor should be placed.
///
/// @param cts
/// @param headp
///
/// @return The number of characters taken up on the screen.
/// Warning: "*headp" may not be set if it's 0, init to 0 before calling.
int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
{
win_T *wp = cts->cts_win;
@@ -388,7 +391,6 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
colnr_T col_adj = 0; // vcol + screen size of tab
int mb_added = 0;
int numberextra;
cts->cts_cur_text_width_left = 0;
cts->cts_cur_text_width_right = 0;
@@ -449,7 +451,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
&& (wp->w_width_inner != 0)) {
// Count all characters from first non-blank after a blank up to next
// non-blank after a blank.
numberextra = win_col_off(wp);
int numberextra = win_col_off(wp);
colnr_T col2 = vcol;
colnr_T colmax = (colnr_T)(wp->w_width_inner - numberextra - col_adj);
@@ -490,72 +492,92 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
// May have to add something for 'breakindent' and/or 'showbreak'
// string at start of line.
// Set *headp to the size of what we add.
// Do not use 'showbreak' at the NUL after the text.
int added = 0;
int head = mb_added;
char *const sbr = c == NUL ? empty_option : get_showbreak_value(wp);
if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && vcol != 0) {
colnr_T sbrlen = 0;
int numberwidth = win_col_off(wp);
numberextra = numberwidth;
vcol += numberextra + mb_added;
if (vcol >= (colnr_T)wp->w_width_inner) {
vcol -= wp->w_width_inner;
numberextra = wp->w_width_inner - (numberextra - win_col_off2(wp));
if (vcol >= numberextra && numberextra > 0) {
vcol %= numberextra;
if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap) {
int col_off_prev = win_col_off(wp);
int width2 = wp->w_width_inner - col_off_prev + win_col_off2(wp);
colnr_T wcol = vcol + col_off_prev;
// cells taken by 'showbreak'/'breakindent' before current char
int head_prev = 0;
if (wcol >= wp->w_width_inner) {
wcol -= wp->w_width_inner;
col_off_prev = wp->w_width_inner - width2;
if (wcol >= width2 && width2 > 0) {
wcol %= width2;
}
if (*sbr != NUL) {
sbrlen = (colnr_T)mb_charlen(sbr);
if (vcol >= sbrlen) {
vcol -= sbrlen;
}
head_prev += vim_strsize(sbr);
}
if (vcol >= numberextra && numberextra > 0) {
vcol %= numberextra;
} else if (vcol > 0 && numberextra > 0) {
vcol += numberwidth - win_col_off2(wp);
if (wp->w_p_bri) {
head_prev += get_breakindent_win(wp, line);
}
numberwidth -= win_col_off2(wp);
if (wcol < head_prev) {
wcol = head_prev;
}
wcol += col_off_prev;
}
if (vcol == 0 || (vcol + size + sbrlen > (colnr_T)wp->w_width_inner)) {
if ((vcol > 0 && wcol == col_off_prev + head_prev)
|| wcol + size > wp->w_width_inner) {
int added = 0;
colnr_T max_head_vcol = cts->cts_max_head_vcol;
if (vcol > 0 && wcol == col_off_prev + head_prev) {
added += head_prev;
if (max_head_vcol <= 0 || vcol < max_head_vcol) {
head += head_prev;
}
}
// cells taken by 'showbreak'/'breakindent' halfway current char
int head_mid = 0;
if (*sbr != NUL) {
if (size + sbrlen + numberwidth > (colnr_T)wp->w_width_inner) {
head_mid += vim_strsize(sbr);
}
if (wp->w_p_bri) {
head_mid += get_breakindent_win(wp, line);
}
if (head_mid > 0) {
if (wcol + size > wp->w_width_inner) {
// Calculate effective window width.
int width = (colnr_T)wp->w_width_inner - sbrlen - numberwidth;
int prev_width = vcol ? ((colnr_T)wp->w_width_inner - (sbrlen + vcol))
: 0;
int prev_rem = wp->w_width_inner - wcol;
int width = width2 - head_mid;
if (width <= 0) {
width = 1;
}
added += ((size - prev_width) / width) * vim_strsize(sbr);
if ((size - prev_width) % width) {
// Wrapped, add another length of 'sbr'.
added += vim_strsize(sbr);
// divide "size - prev_width" by "width", rounding up
int cnt = (size - prev_rem + width - 1) / width;
added += cnt * head_mid;
if (max_head_vcol == 0 || vcol + size + added < max_head_vcol) {
head += cnt * head_mid;
} else if (max_head_vcol > vcol + head_prev + prev_rem) {
head += (max_head_vcol - (vcol + head_prev + prev_rem)
+ width2 - 1) / width2 * head_mid;
} else if (max_head_vcol < 0) {
int off = 0;
if (c != NUL || !(State & MODE_NORMAL)) {
off += cts->cts_cur_text_width_left;
}
if (c != NUL && (State & MODE_NORMAL)) {
off += cts->cts_cur_text_width_right;
}
if (off >= prev_rem) {
head += (1 + (off - prev_rem) / width) * head_mid;
}
}
} else {
added += vim_strsize(sbr);
}
}
if (wp->w_p_bri) {
added += get_breakindent_win(wp, line);
}
size += added;
if (vcol != 0) {
added = 0;
}
}
}
if (headp != NULL) {
*headp = added + mb_added;
*headp = head;
}
return size;
}