forked from qt-creator/qt-creator
TextEditor: Fix clearing of semantic highlights
This was broken for multi-line results, potentially erasing the formatting of continuation lines. This is particularly relevant for raw string literals. Change-Id: I68092f57024422137ca5483d1be17e02294f7a9f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -167,26 +167,19 @@ void SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd(
|
|||||||
SyntaxHighlighter *highlighter,
|
SyntaxHighlighter *highlighter,
|
||||||
const QFuture<HighlightingResult> &future)
|
const QFuture<HighlightingResult> &future)
|
||||||
{
|
{
|
||||||
// find block number of last result
|
const QTextDocument * const doc = highlighter->document();
|
||||||
int lastBlockNumber = 0;
|
QTextBlock firstBlockToClear = doc->begin();
|
||||||
for (int i = future.resultCount() - 1; i >= 0; --i) {
|
for (int i = future.resultCount() - 1; i >= 0; --i) {
|
||||||
const HighlightingResult &result = future.resultAt(i);
|
const HighlightingResult &result = future.resultAt(i);
|
||||||
if (result.line) {
|
if (result.line) {
|
||||||
lastBlockNumber = int(result.line) - 1;
|
const QTextBlock blockForLine = doc->findBlockByNumber(result.line - 1);
|
||||||
|
const QTextBlock lastBlockWithResults = doc->findBlock(
|
||||||
|
blockForLine.position() + result.column - 1 + result.length);
|
||||||
|
firstBlockToClear = lastBlockWithResults.next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextDocument *doc = highlighter->document();
|
for (QTextBlock b = firstBlockToClear; b.isValid(); b = b.next())
|
||||||
|
|
||||||
const int firstBlockToClear = lastBlockNumber + 1;
|
|
||||||
if (firstBlockToClear >= doc->blockCount())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QTextBlock b = doc->findBlockByNumber(firstBlockToClear);
|
|
||||||
|
|
||||||
while (b.isValid()) {
|
|
||||||
highlighter->clearExtraFormats(b);
|
highlighter->clearExtraFormats(b);
|
||||||
b = b.next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user