UI: Handle newlines after ellipsis.

This commit is contained in:
Unknown W. Brackets 2021-09-25 12:01:41 -07:00
parent 2f570481b7
commit 7dc3287617
2 changed files with 12 additions and 3 deletions

View File

@ -153,9 +153,9 @@ void WordWrapper::AppendWord(int endIndex, int lastChar, bool addNewline) {
x_ = 0.0f;
} else {
// We may have appended a newline - check.
size_t pos = out_.substr(lastLineStart_).find_last_of("\n");
size_t pos = out_.find_last_of("\n");
if (pos != out_.npos) {
lastLineStart_ += pos;
lastLineStart_ = pos + 1;
}
if (lastChar == -1 && !out_.empty()) {
@ -202,12 +202,15 @@ void WordWrapper::Wrap() {
// Is this a newline character, hard wrapping?
if (c == '\n') {
if (skipNextWord_) {
lastIndex_ = beforeIndex;
skipNextWord_ = false;
}
// This will include the newline character.
AppendWord(afterIndex, c, false);
// We wrapped once, so stop forcing.
forceEarlyWrap_ = false;
scanForNewline_ = false;
skipNextWord_ = false;
continue;
}

View File

@ -731,6 +731,12 @@ static bool TestWrapText() {
EXPECT_WORDWRAP_EQ_STR(shyTestString.c_str(), 10, FLAG_ELLIPSIZE_TEXT, "Very...");
EXPECT_WORDWRAP_EQ_STR(shyTestString.c_str(), 10, FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT, "Very-\nlong");
// Newlines should not be removed and should influence wrapping.
EXPECT_WORDWRAP_EQ_STR("Hello\ngoodbye yes\nno", 14, 0, "Hello\ngoodbye ");
EXPECT_WORDWRAP_EQ_STR("Hello\ngoodbye yes\nno", 14, FLAG_WRAP_TEXT, "Hello\ngoodbye \nyes\nno");
EXPECT_WORDWRAP_EQ_STR("Hello\ngoodbye yes\nno", 14, FLAG_ELLIPSIZE_TEXT, "Hello\ngoodb...\nno");
EXPECT_WORDWRAP_EQ_STR("Hello\ngoodbye yes\nno", 14, FLAG_WRAP_TEXT | FLAG_ELLIPSIZE_TEXT, "Hello\ngoodbye \nyes\nno");
return true;
}