fix(pum_redraw): use grid_puts_len() to truncate the text

Nvim already resizes grid to the required width, so there is no need to
truncate the text in pum_redraw(). What's more, truncation is currently
done incorrectly because Vim patch 8.2.1995 was ported incorrectly.

This nearly reverts the truncation part of Vim patch 8.2.1995, but not
the part that reduces unnecessary calls to pum_redraw(). The original PR
https://github.com/vim/vim/pull/7306 didn't explain much about which
part of it actually reduces redraws.
This commit is contained in:
zeertzjq
2021-12-24 08:06:27 +08:00
parent 28dadd5a54
commit e6d35b9e40
2 changed files with 132 additions and 11 deletions

View File

@@ -542,17 +542,8 @@ void pum_redraw(void)
xfree(st);
col -= width;
} else {
int size = (int)STRLEN(st);
int cells = (int)mb_string2cells(st);
// only draw the text that fits
while (size > 0 && col + cells > pum_width + pum_col) {
size--;
size -= utf_head_off(st, st + size);
cells -= utf_ptr2cells(st + size);
}
grid_puts_len(&pum_grid, st, size, row, col, attr);
// use grid_puts_len() to truncate the text
grid_puts(&pum_grid, st, row, col, attr);
xfree(st);
col += width;
}