commit 93ee0a8a65fa93d78ebf4de5358945706e5f731e
parent 15959346fb92d5e62b643a944edcc4988a9076fe
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Thu, 14 Mar 2019 10:44:55 -0500
display: show the guide stripe for double-width/multi-byte characters
Determine the actual number of bytes the striped character consists of,
instead of assuming it's simply one, and determine the real column that
the character starts in, instead of assuming it's the stripe column.
This fixes https://savannah.gnu.org/bugs/?55917
and fixes https://savannah.gnu.org/bugs/?55922.
Condensed-by: Benno Schulenberg <bensberg@telfort.nl>
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/winio.c b/src/winio.c
@@ -2687,12 +2687,19 @@ void edit_draw(filestruct *fileptr, const char *converted,
#ifndef NANO_TINY
if (stripe_column > from_col && !inhelp) {
- const ssize_t target_column = stripe_column - from_col - 1;
- const char *text = converted + actual_x(converted, target_column);
- const char *striped_char = (*text == '\0') ? " " : text;
+ ssize_t target_column = stripe_column - from_col - 1;
+ size_t target_x = actual_x(converted, target_column);
+ char striped_char[MAXCHARLEN];
+ size_t charlen = 1;
+
+ if (*(converted + target_x) != '\0') {
+ charlen = parse_mbchar(converted + target_x, striped_char, NULL);
+ target_column = strnlenpt(converted, target_x);
+ } else
+ striped_char[0] = ' ';
wattron(edit, interface_color_pair[GUIDE_STRIPE]);
- mvwaddnstr(edit, row, margin + target_column, striped_char, 1);
+ mvwaddnstr(edit, row, margin + target_column, striped_char, charlen);
wattroff(edit, interface_color_pair[GUIDE_STRIPE]);
}