From 020e7f5739119178be9bb6e58b4e636ce96cfb3c Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Fri, 29 Jan 2010 10:32:00 +0100
Subject: [PATCH] Mark also the whitespaces inside comments and string
 literals.

---
 src/libs/qmljs/qmljshighlighter.cpp | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/libs/qmljs/qmljshighlighter.cpp b/src/libs/qmljs/qmljshighlighter.cpp
index 492a717abbb..b994963de77 100644
--- a/src/libs/qmljs/qmljshighlighter.cpp
+++ b/src/libs/qmljs/qmljshighlighter.cpp
@@ -160,9 +160,32 @@ void QScriptHighlighter::highlightBlock(const QString &text)
     }
 
     int previousTokenEnd = 0;
-    for (int i = 0; i < tokens.size(); ++i) {
-        const Token &token = tokens.at(i);
+    for (int index = 0; index < tokens.size(); ++index) {
+        const Token &token = tokens.at(index);
         setFormat(previousTokenEnd, token.begin() - previousTokenEnd, m_formats[VisualWhitespace]);
+
+        switch (token.kind) {
+        case Token::Comment:
+        case Token::String: {
+            int i = token.begin(), e = token.end();
+            while (i < e) {
+                const QChar ch = text.at(i);
+                if (ch.isSpace()) {
+                    const int start = i;
+                    do {
+                        ++i;
+                    } while (i < e && text.at(i).isSpace());
+                    setFormat(start, i - start, m_formats[VisualWhitespace]);
+                } else {
+                    ++i;
+                }
+            }
+        } break;
+
+        default:
+            break;
+        } // end of switch
+
         previousTokenEnd = token.end();
     }
 
-- 
GitLab