From 9192d23853256dcd5c3a352ebfcb693dc65d087b Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 10 Mar 2017 13:00:18 +0100 Subject: [PATCH] softwrap: shrink the screen by one column to keep wide characters visible Use the last column of the screen as an overflow area so that characters that in theory would need to be split between rows can be displayed as a whole. On the next row the missing half is displayed by a placeholder: an underscore. --- src/nano.c | 3 +++ src/winio.c | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/nano.c b/src/nano.c index a8c2a7fd..6c77ee2a 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2512,6 +2512,9 @@ int main(int argc, char **argv) editwincols = COLS; + if (ISSET(SOFTWRAP)) + editwincols--; + /* Set up the signal handlers. */ signal_init(); diff --git a/src/winio.c b/src/winio.c index 73fdcddf..8933b82d 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1826,9 +1826,18 @@ char *display_string(const char *buf, size_t start_col, size_t span, /* If the first character starts before the left edge, or would be * overwritten by a "$" token, then show spaces instead. */ - if (*buf != '\0' && *buf != '\t' && (column < start_col || - (column > 0 && isdata && !ISSET(SOFTWRAP)))) { - if (is_cntrl_mbchar(buf)) { + if (*buf != '\0' && *buf != '\t' && column > 0 && isdata) { + if (ISSET(SOFTWRAP)) { + /* If a double-width character straddles a boundary, it was shown + * on the previous row -- so: skip it here, show a placeholder, + * and shorten this row to keep things in balance. */ + if (column < start_col) { + buf += parse_mbchar(buf, NULL, NULL); + converted[index++] = '_'; + start_col++; + span--; + } + } else if (is_cntrl_mbchar(buf)) { if (column < start_col) { converted[index++] = control_mbrep(buf, isdata); start_col++; @@ -1930,11 +1939,13 @@ char *display_string(const char *buf, size_t start_col, size_t span, /* If there is more text than can be shown, make room for the $. */ if (*buf != '\0' && isdata && !ISSET(SOFTWRAP)) +{ span--; /* Make sure converted takes up no more than span columns. */ index = actual_x(converted, span); null_at(&converted, index); +} return converted; } -- 2.11.0