From e2fb719501c41356f632e6f8838c91d888239037 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 28 Aug 2024 11:57:29 +0200 Subject: Fixed handling of consecutive text formatting markers If a text contained for example "##3##B", expected behavior was to switch to blue color and bold font. Instead, due to there being no actual text in between the markers, the layouting code was aborting prematurely here: if (mMode == AUTO_WRAP && partWidth == 0) break; As far as I could judge, this check is actually not necessary anyway, but I've kept it for now since the wrapping code looks so problematic. Instead, a while loop now makes sure we process all consecutive formatting markers. Closes #75 --- src/gui/widgets/browserbox.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 64b494db..7b77721c 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -336,17 +336,13 @@ void BrowserBox::layoutTextRow(TextRow &row, LayoutContext &context) wrapped = false; } - // "Tokenize" the string at control sequences - if (mUseLinksAndUserColors) - end = row.text.find("##", start + 1); - - if (mUseLinksAndUserColors || - (!mUseLinksAndUserColors && (start == 0))) + if (mUseLinksAndUserColors || start == 0) { // Check for color or font change in format "##x", x = [<,>,B,p,0..9] - if (row.text.find("##", start) == start && row.text.size() > start + 2) + while (row.text.size() > start + 2 && row.text.find("##", start) == start) { const char c = row.text.at(start + 2); + start += 3; bool valid; const gcn::Color &col = Theme::getThemeColor(c, valid); @@ -401,16 +397,16 @@ void BrowserBox::layoutTextRow(TextRow &row, LayoutContext &context) linkIndex++; } - start += 3; - - if (start == row.text.size()) - break; } } if (start >= row.text.length()) break; + // "Tokenize" the string at control sequences + if (mUseLinksAndUserColors) + end = row.text.find("##", start + 1); + std::string::size_type len = end == std::string::npos ? end : end - start; -- cgit v1.2.3-70-g09d2