diff --git a/src/plugins/texteditor/semantichighlighter.cpp b/src/plugins/texteditor/semantichighlighter.cpp index 4a9e9b9dd4c..be0e66065ae 100644 --- a/src/plugins/texteditor/semantichighlighter.cpp +++ b/src/plugins/texteditor/semantichighlighter.cpp @@ -117,6 +117,32 @@ void SemanticHighlighter::incrementalApplyExtraAdditionalFormats( } } +void SemanticHighlighter::setExtraAdditionalFormats(SyntaxHighlighter *highlighter, + const QList &results, + const QHash &kindToFormat) +{ + highlighter->clearAllExtraFormats(); + + QTextDocument *doc = highlighter->document(); + QTC_ASSERT(doc, return ); + + QVector> ranges(doc->blockCount()); + + for (auto result : results) { + const QTextLayout::FormatRange formatRange = rangeForResult(result, kindToFormat); + if (formatRange.format.isValid()) + ranges[int(result.line) - 1].append(formatRange); + } + + for (int blockNumber = 0; blockNumber < ranges.count(); ++blockNumber) { + if (!ranges[blockNumber].isEmpty()) { + QTextBlock b = doc->findBlockByNumber(blockNumber); + QTC_ASSERT(b.isValid(), return ); + highlighter->setExtraFormats(b, std::move(ranges[blockNumber])); + } + } +} + void SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd( SyntaxHighlighter *highlighter, const QFuture &future) diff --git a/src/plugins/texteditor/semantichighlighter.h b/src/plugins/texteditor/semantichighlighter.h index f57b037957c..d39ba7b80d0 100644 --- a/src/plugins/texteditor/semantichighlighter.h +++ b/src/plugins/texteditor/semantichighlighter.h @@ -86,6 +86,15 @@ void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats( int from, int to, const QHash &kindToFormat); +// Clears all extra highlights and applies the extra formats +// indicated by Result::kind and kindToFormat to the correct location using +// SyntaxHighlighter::setExtraFormats. In contrast to +// incrementalApplyExtraAdditionalFormats the results do not have to be ordered by line. +void TEXTEDITOR_EXPORT setExtraAdditionalFormats( + SyntaxHighlighter *highlighter, + const QList &results, + const QHash &kindToFormat); + // Cleans the extra additional formats after the last result of the Future // until the end of the document. // Requires that results of the Future are ordered by line.