Only wrap before words that are shorter than the wrapping length

Closes #2820
This commit is contained in:
Maxime Coste 2019-04-24 10:53:33 +01:00
parent c05da4bfd9
commit 64ddd43be9

View File

@ -868,9 +868,19 @@ struct WrapHighlighter : Highlighter
} }
} }
if (m_word_wrap and pos.byte < content.length()) // find a word boundary before current position if (m_word_wrap and pos.byte < content.length() and last_boundary.byte > 0)
if (last_boundary.byte > 0) {
pos = last_boundary; // 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<WORD>(cp))
return last_boundary;
word_length += codepoint_width(cp);
}
}
return pos; return pos;
}; };