From 7dc328761768596b7a13570c558602f336662e14 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 25 Sep 2021 12:01:41 -0700 Subject: [PATCH] UI: Handle newlines after ellipsis. --- Common/Data/Text/WrapText.cpp | 9 ++++++--- unittest/UnitTest.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Common/Data/Text/WrapText.cpp b/Common/Data/Text/WrapText.cpp index 6832389695..8d661d285e 100644 --- a/Common/Data/Text/WrapText.cpp +++ b/Common/Data/Text/WrapText.cpp @@ -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; } diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index 757b0e281b..50611ba241 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -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; }