From 4c42c7eef43ff0f58fa574f7a900c8a3313f372e Mon Sep 17 00:00:00 2001 From: h-east Date: Mon, 17 Apr 2023 21:44:57 +0100 Subject: patch 9.0.1463: virtual text truncation only works with Unicode 'encoding' Problem: Virtual text truncation only works with Unicode 'encoding'. Solution: Convert the ellipsis character to 'encoding' if needed. (Hirohito Higashi, closes #12233) --- src/drawline.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/drawline.c') diff --git a/src/drawline.c b/src/drawline.c index 5c647507d8..c7510a65a2 100644 --- a/src/drawline.c +++ b/src/drawline.c @@ -739,10 +739,37 @@ text_prop_position( if (has_mbyte) { - // change last character to '…' + char_u buf[MB_MAXBYTES + 1]; + char_u *cp = buf; + + // change the last character to '…', converted to the + // current 'encoding' + STRCPY(buf, "…"); + if (!enc_utf8) + { + vimconv_T vc; + + vc.vc_type = CONV_NONE; + convert_setup(&vc, (char_u *)"utf-8", p_enc); + if (vc.vc_type != CONV_NONE) + { + cp = string_convert(&vc, buf, NULL); + if (cp == NULL) + { + // when conversion fails use '>' + cp = buf; + STRCPY(buf, ">"); + } + convert_setup(&vc, NULL, NULL); + } + } + + lp -= (*mb_ptr2cells)(cp) - 1; lp -= (*mb_head_off)(l, lp); - STRCPY(lp, "…"); + STRCPY(lp, cp); n_used = lp - l + 3 - before - padding; + if (cp != buf) + vim_free(cp); } else // change last character to '>' -- cgit v1.2.3