diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp index 928e664f746..16a6d7213d7 100644 --- a/src/plugins/cppeditor/cpphighlighter.cpp +++ b/src/plugins/cppeditor/cpphighlighter.cpp @@ -29,10 +29,11 @@ **************************************************************************/ #include "cpphighlighter.h" -#include #include #include +#include +#include #include #include @@ -79,10 +80,12 @@ void CppHighlighter::highlightBlock(const QString &text) setCurrentBlockState(previousState); BaseTextDocumentLayout::clearParentheses(currentBlock()); if (text.length()) {// the empty line can still contain whitespace - if (!initialState) - setFormat(0, text.length(), m_formats[CppVisualWhitespace]); + if (initialState == Lexer::State_MultiLineComment) + highlightLine(text, 0, text.length(), m_formats[CppCommentFormat]); + else if (initialState == Lexer::State_MultiLineDoxyComment) + highlightLine(text, 0, text.length(), m_formats[CppDoxygenCommentFormat]); else - setFormat(0, text.length(), m_formats[CppCommentFormat]); + setFormat(0, text.length(), m_formats[CppVisualWhitespace]); } BaseTextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent); return; @@ -106,12 +109,8 @@ void CppHighlighter::highlightBlock(const QString &text) tokens.at(i - 1).length(); } - if (previousTokenEnd != tk.begin()) { - if (initialState && tk.isComment()) - setFormat(previousTokenEnd, tk.begin() - previousTokenEnd, m_formats[CppCommentFormat]); - else - setFormat(previousTokenEnd, tk.begin() - previousTokenEnd, m_formats[CppVisualWhitespace]); - } + if (previousTokenEnd != tk.begin()) + setFormat(previousTokenEnd, tk.begin() - previousTokenEnd, m_formats[CppVisualWhitespace]); if (tk.is(T_LPAREN) || tk.is(T_LBRACE) || tk.is(T_LBRACKET)) { const QChar c = text.at(tk.begin()); @@ -166,14 +165,15 @@ void CppHighlighter::highlightBlock(const QString &text) setFormat(tk.begin(), tk.length(), m_formats[CppNumberFormat]); else if (tk.isStringLiteral() || tk.isCharLiteral()) - setFormat(tk.begin(), tk.length(), m_formats[CppStringFormat]); + highlightLine(text, tk.begin(), tk.length(), m_formats[CppStringFormat]); else if (tk.isComment()) { + const int startPosition = initialState ? previousTokenEnd : tk.begin(); if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)) - setFormat(tk.begin(), tk.length(), m_formats[CppCommentFormat]); + highlightLine(text, startPosition, tk.end() - startPosition, m_formats[CppCommentFormat]); else // a doxygen comment - highlightDoxygenComment(text, tk.begin(), tk.length()); + highlightDoxygenComment(text, startPosition, tk.end() - startPosition); // we need to insert a close comment parenthesis, if // - the line starts in a C Comment (initalState != 0) @@ -208,12 +208,9 @@ void CppHighlighter::highlightBlock(const QString &text) } // mark the trailing white spaces - { - const Token tk = tokens.last(); - const int lastTokenEnd = tk.begin() + tk.length(); - if (text.length() > lastTokenEnd) - highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, QTextCharFormat()); - } + const int lastTokenEnd = tokens.last().end(); + if (text.length() > lastTokenEnd) + highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, m_formats[CppVisualWhitespace]); if (! initialState && state && ! tokens.isEmpty()) { parentheses.append(Parenthesis(Parenthesis::Opened, QLatin1Char('+'), @@ -335,7 +332,8 @@ bool CppHighlighter::isPPKeyword(const QStringRef &text) const void CppHighlighter::highlightLine(const QString &text, int position, int length, const QTextCharFormat &format) { - const QTextCharFormat visualSpaceFormat = m_formats[CppVisualWhitespace]; + QTextCharFormat visualSpaceFormat = m_formats[CppVisualWhitespace]; + visualSpaceFormat.setBackground(format.background()); const int end = position + length; int index = position;