mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 02:21:51 +00:00
fix(vterm): handle split UTF-8 after ASCII properly (#37721)
Problem: libvterm doesn't handle split UTF-8 sequence after ASCII. Solution: Only use one UTF-8 encoding state per vterm state.
This commit is contained in:
@@ -660,21 +660,6 @@ static size_t on_channel_output(RStream *stream, Channel *chan, const char *buf,
|
||||
bool eof, CallbackReader *reader)
|
||||
{
|
||||
if (chan->term) {
|
||||
if (count) {
|
||||
const char *p = buf;
|
||||
const char *end = buf + count;
|
||||
while (p < end) {
|
||||
// Don't pass incomplete UTF-8 sequences to libvterm. #16245
|
||||
// Composing chars can be passed separately, so utf_ptr2len_len() is enough.
|
||||
int clen = utf_ptr2len_len(p, (int)(end - p));
|
||||
if (clen > end - p) {
|
||||
count = (size_t)(p - buf);
|
||||
break;
|
||||
}
|
||||
p += clen;
|
||||
}
|
||||
}
|
||||
|
||||
terminal_receive(chan->term, buf, count);
|
||||
}
|
||||
|
||||
|
||||
@@ -321,6 +321,9 @@ static int on_text(const char bytes[], size_t len, void *user)
|
||||
: state->vt->mode.utf8 ? &state->encoding_utf8
|
||||
: &state->encoding[state->
|
||||
gr_set];
|
||||
if (encoding->enc == state->encoding_utf8.enc) {
|
||||
encoding = &state->encoding_utf8; // Only use one UTF-8 encoding state.
|
||||
}
|
||||
|
||||
(*encoding->enc->decode)(encoding->enc, encoding->data,
|
||||
codepoints, &npoints, state->gsingle_set ? 1 : (int)maxpoints,
|
||||
|
||||
Reference in New Issue
Block a user