C++: do not set any highlighting ranges on empty lines.

This can happen when the semantic highlighter (which runs in a future)
calculates a range for a document that has been changed in the meantime.

Task-number: QTCREATORBUG-7995
Change-Id: Ibcd1a6ae840e08570a6b6ea4caf411e799ec26c8
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Erik Verbruggen
2012-10-15 14:11:42 +02:00
parent dcbc4d8255
commit fe55485109

View File

@@ -695,15 +695,18 @@ static bool byStartOfRange(const QTextLayout::FormatRange &range, const QTextLay
void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block, void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block,
const QList<QTextLayout::FormatRange> &fmts) const QList<QTextLayout::FormatRange> &fmts)
{ {
// qDebug() << "setAdditionalFormats() on block" << block.blockNumber(); // qDebug() << "setAdditionalFormats() on block" << block.blockNumber();
// qDebug() << " is valid:" << (block.isValid() ? "Yes" : "No");
// qDebug() << " has layout:" << (block.layout() ? "Yes" : "No");
// if (block.layout()) qDebug() << " has text:" << (block.text().isEmpty() ? "No" : "Yes");
// for (int i = 0; i < overrides.count(); ++i) // for (int i = 0; i < overrides.count(); ++i)
// qDebug() << " from " << overrides.at(i).start << "length" // qDebug() << " from " << overrides.at(i).start << "length"
// << overrides.at(i).length // << overrides.at(i).length
// << "color:" << overrides.at(i).format.foreground().color(); // << "color:" << overrides.at(i).format.foreground().color();
Q_D(SyntaxHighlighter); Q_D(SyntaxHighlighter);
if (block.layout() == 0) if (block.layout() == 0 || block.text().isEmpty())
return; return;
QList<QTextLayout::FormatRange> formats; QList<QTextLayout::FormatRange> formats;