TextEditor: add additional formats setter to semantic highlighter

The old setter incremental applies formats to the semantic highlighter,
in contrast to the new setter, which removes all old additional formats
and then applies all passed formats.

Change-Id: If8569c180d8eaef7aee99509c84a03ba362c9e4a
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
David Schulz
2019-06-13 12:21:30 +02:00
parent 76046ee865
commit ea727e6c82
2 changed files with 35 additions and 0 deletions

View File

@@ -117,6 +117,32 @@ void SemanticHighlighter::incrementalApplyExtraAdditionalFormats(
} }
} }
void SemanticHighlighter::setExtraAdditionalFormats(SyntaxHighlighter *highlighter,
const QList<HighlightingResult> &results,
const QHash<int, QTextCharFormat> &kindToFormat)
{
highlighter->clearAllExtraFormats();
QTextDocument *doc = highlighter->document();
QTC_ASSERT(doc, return );
QVector<QVector<QTextLayout::FormatRange>> 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( void SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
SyntaxHighlighter *highlighter, SyntaxHighlighter *highlighter,
const QFuture<HighlightingResult> &future) const QFuture<HighlightingResult> &future)

View File

@@ -86,6 +86,15 @@ void TEXTEDITOR_EXPORT incrementalApplyExtraAdditionalFormats(
int from, int to, int from, int to,
const QHash<int, QTextCharFormat> &kindToFormat); const QHash<int, QTextCharFormat> &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<HighlightingResult> &results,
const QHash<int, QTextCharFormat> &kindToFormat);
// Cleans the extra additional formats after the last result of the Future // Cleans the extra additional formats after the last result of the Future
// until the end of the document. // until the end of the document.
// Requires that results of the Future are ordered by line. // Requires that results of the Future are ordered by line.