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: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2024-05-06 17:23:39 +02:00
parent 5e4281dafe
commit bb2d565ecc

View File

@@ -402,23 +402,32 @@ const QList<FormattedText> 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;
}