From 64ddd43be943f0247dd8823a2564387dcb1aa622 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 24 Apr 2019 10:53:33 +0100 Subject: [PATCH] Only wrap before words that are shorter than the wrapping length Closes #2820 --- src/highlighters.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 14587429..2d9d39a4 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -868,9 +868,19 @@ struct WrapHighlighter : Highlighter } } - if (m_word_wrap and pos.byte < content.length()) // find a word boundary before current position - if (last_boundary.byte > 0) - pos = last_boundary; + if (m_word_wrap and pos.byte < content.length() and last_boundary.byte > 0) + { + // split at last word boundary if the word is shorter than our wrapping width + ColumnCount word_length = pos.column - last_boundary.column; + const char* it = &content[pos.byte]; + while (it != content.end() and word_length <= wrap_column) + { + const Codepoint cp = utf8::read_codepoint(it, content.end()); + if (not is_word(cp)) + return last_boundary; + word_length += codepoint_width(cp); + } + } return pos; };