summaryrefslogtreecommitdiffstats
path: root/src/popupwin.c
diff options
context:
space:
mode:
authorRalf Schandl <rakus@users.noreply.github.com>2021-05-28 14:12:14 +0200
committerBram Moolenaar <Bram@vim.org>2021-05-28 14:12:14 +0200
commitbc869874fedf094129831836f131c64f10d98854 (patch)
tree25f910004b20bbfd23fda1d1e55287ce768f1552 /src/popupwin.c
parent89dcb4dce369de22fba13b9c3c63f11f8d42650b (diff)
patch 8.2.2893: multi-byte text in popup title shows up wrongv8.2.2893
Problem: Multi-byte text in popup title shows up wrong. Solution: Use the character width instead of the byte length. (Ralf Schandl, closes #8267, closes #8264)
Diffstat (limited to 'src/popupwin.c')
-rw-r--r--src/popupwin.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/popupwin.c b/src/popupwin.c
index 335345f3a0..35c4b0af5e 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -3822,17 +3822,29 @@ update_popups(void (*win_update)(win_T *wp))
title_wincol = wp->w_wincol + 1;
if (wp->w_popup_title != NULL)
{
- char_u *title_text;
+ title_len = (int)MB_CHARLEN(wp->w_popup_title);
- title_len = (int)STRLEN(wp->w_popup_title);
- title_text = alloc(title_len + 1);
- trunc_string(wp->w_popup_title, title_text,
- total_width - 2, title_len + 1);
- screen_puts(title_text, wp->w_winrow, title_wincol,
- wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr);
- vim_free(title_text);
+ // truncate the title if too long
if (title_len > total_width - 2)
+ {
+ int title_byte_len = (int)STRLEN(wp->w_popup_title);
+ char_u *title_text = alloc(title_byte_len + 1);
+
+ if (title_text != NULL)
+ {
+ trunc_string(wp->w_popup_title, title_text,
+ total_width - 2, title_byte_len + 1);
+ screen_puts(title_text, wp->w_winrow, title_wincol,
+ wp->w_popup_border[0] > 0
+ ? border_attr[0] : popup_attr);
+ vim_free(title_text);
+ }
+
title_len = total_width - 2;
+ }
+ else
+ screen_puts(wp->w_popup_title, wp->w_winrow, title_wincol,
+ wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr);
}
wincol = wp->w_wincol - wp->w_popup_leftoff;