From 65d165513442b6839d755c44b3fa5c81d2bf0160 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Fri, 4 Aug 2017 15:43:14 -0500 Subject: [PATCH] softwrap: don't push a straddling tab to the next chunk Tabs are of variable length depending on position, so allow them to be displayed partially on one chunk and partially on another. This fixes http://savannah.gnu.org/bugs/?51621. --- src/winio.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/winio.c b/src/winio.c index a66a4a31..650f93b5 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2982,8 +2982,8 @@ size_t get_softwrap_breakpoint(const char *text, size_t leftedge, while (*text != '\0' && column < leftedge) text += parse_mbchar(text, NULL, &column); - /* Use a full screen row for text. */ - goal_column = column + editwincols; + /* The intention is to use the entire available width. */ + goal_column = leftedge + editwincols; while (*text != '\0' && column <= goal_column) { /* When breaking at blanks, do it *before* the target column. */ @@ -3011,9 +3011,18 @@ size_t get_softwrap_breakpoint(const char *text, size_t leftedge, if (found_blank) { text = text - index + lastblank_index; parse_mbchar(text, NULL, &lastblank_column); + + /* If we've now overshot the screen's edge, then break there. */ + if (lastblank_column > goal_column) + return goal_column; + return lastblank_column; } + /* If a tab is split over two chunks, break at the screen's edge. */ + if (*(text - char_len) == '\t') + prev_column = goal_column; + /* Otherwise, return the column of the last character that doesn't * overshoot the target, since we can't break the text anywhere else. */ return (editwincols > 1) ? prev_column : column - 1;