From bb2d565eccd27f3a6b2b8e09b6ac13b6ce477d6e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 6 May 2024 17:23:39 +0200 Subject: Utils: Fix output linkification The case where links are combined with other formatting was not correctly implemented. Fixes: QTCREATORBUG-30774 Change-Id: Ie56a7f4c9a1f8a9b23848cc6fd4b7749bb6cecd7 Reviewed-by: Reviewed-by: Christian Stenger --- src/libs/utils/outputformatter.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libs/utils/outputformatter.cpp b/src/libs/utils/outputformatter.cpp index f8b3d8cec79..a318bb1cca6 100644 --- a/src/libs/utils/outputformatter.cpp +++ b/src/libs/utils/outputformatter.cpp @@ -402,23 +402,32 @@ const QList OutputFormatter::linkifiedText( } for (int nextLocalTextPos = 0; nextLocalTextPos < t.text.size(); ) { - - // There are no more links in this part, so copy the rest of the text as-is. - if (nextLinkSpecIndex >= linkSpecs.size()) { + const auto copyRestOfSegmentAsIs = [&] { linkified << FormattedText(t.text.mid(nextLocalTextPos), t.format); totalTextLengthSoFar += t.text.length() - nextLocalTextPos; + }; + + // We are out of links. + if (nextLinkSpecIndex >= linkSpecs.size()) { + copyRestOfSegmentAsIs(); break; } const OutputLineParser::LinkSpec &linkSpec = linkSpecs.at(nextLinkSpecIndex); const int localLinkStartPos = linkSpec.startPos - totalPreviousTextLength; + + // There are more links, but not in this segment. + if (localLinkStartPos >= t.text.size()) { + copyRestOfSegmentAsIs(); + break; + } + ++nextLinkSpecIndex; // We ignore links that would cross format boundaries. if (localLinkStartPos < nextLocalTextPos || localLinkStartPos + linkSpec.length > t.text.length()) { - linkified << FormattedText(t.text.mid(nextLocalTextPos), t.format); - totalTextLengthSoFar += t.text.length() - nextLocalTextPos; + copyRestOfSegmentAsIs(); break; } -- cgit v1.2.3