From fe5548510953e1bef13a8538a9c5b2e115a31f9f Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@digia.com>
Date: Mon, 15 Oct 2012 14:11:42 +0200
Subject: [PATCH] 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>
---
 src/plugins/texteditor/syntaxhighlighter.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp
index 8c81bda4805..f39e8c6d2fc 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -695,15 +695,18 @@ static bool byStartOfRange(const QTextLayout::FormatRange &range, const QTextLay
 void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block,
                                                   const QList<QTextLayout::FormatRange> &fmts)
 {
-
 //    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)
 //        qDebug() << "   from " << overrides.at(i).start << "length"
 //                 << overrides.at(i).length
 //                 << "color:" << overrides.at(i).format.foreground().color();
     Q_D(SyntaxHighlighter);
 
-    if (block.layout() == 0)
+    if (block.layout() == 0 || block.text().isEmpty())
         return;
 
     QList<QTextLayout::FormatRange> formats;
-- 
GitLab