forked from qt-creator/qt-creator
Fix highlighting of C/C++ line continuation backslashes
The backslash itself is not a token, so we must make sure to only format
the trailing whitespace characters as visual whitespace, instead of
everything trailing.
Broke in a92694596e
Task-number: QTCREATORBUG-987
Change-Id: I4e9e84d29513ea317d7e3bde6c6b4c43749cb649
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -214,7 +214,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
// mark the trailing white spaces
|
// mark the trailing white spaces
|
||||||
const int lastTokenEnd = tokens.last().utf16charsEnd();
|
const int lastTokenEnd = tokens.last().utf16charsEnd();
|
||||||
if (text.length() > lastTokenEnd)
|
if (text.length() > lastTokenEnd)
|
||||||
setFormatWithSpaces(text, lastTokenEnd, text.length() - lastTokenEnd, formatForCategory(C_VISUAL_WHITESPACE));
|
formatSpaces(text, lastTokenEnd, text.length() - lastTokenEnd);
|
||||||
|
|
||||||
if (!initialLexerState && lexerState && !tokens.isEmpty()) {
|
if (!initialLexerState && lexerState && !tokens.isEmpty()) {
|
||||||
const Token &lastToken = tokens.last();
|
const Token &lastToken = tokens.last();
|
||||||
|
|||||||
@@ -477,15 +477,15 @@ void SyntaxHighlighter::setFormat(int start, int count, const QFont &font)
|
|||||||
setFormat(start, count, format);
|
setFormat(start, count, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyntaxHighlighter::formatSpaces(const QString &text)
|
void SyntaxHighlighter::formatSpaces(const QString &text, int start, int count)
|
||||||
{
|
{
|
||||||
Q_D(const SyntaxHighlighter);
|
Q_D(const SyntaxHighlighter);
|
||||||
int offset = 0;
|
int offset = start;
|
||||||
const int length = text.length();
|
const int end = std::min(start + count, text.length());
|
||||||
while (offset < length) {
|
while (offset < end) {
|
||||||
if (text.at(offset).isSpace()) {
|
if (text.at(offset).isSpace()) {
|
||||||
int start = offset++;
|
int start = offset++;
|
||||||
while (offset < length && text.at(offset).isSpace())
|
while (offset < end && text.at(offset).isSpace())
|
||||||
++offset;
|
++offset;
|
||||||
setFormat(start, offset - start, d->whitespaceFormat);
|
setFormat(start, offset - start, d->whitespaceFormat);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
@@ -84,7 +85,7 @@ protected:
|
|||||||
void setFormat(int start, int count, const QFont &font);
|
void setFormat(int start, int count, const QFont &font);
|
||||||
QTextCharFormat format(int pos) const;
|
QTextCharFormat format(int pos) const;
|
||||||
|
|
||||||
void formatSpaces(const QString &text);
|
void formatSpaces(const QString &text, int start = 0, int count = INT_MAX);
|
||||||
void setFormatWithSpaces(const QString &text, int start, int count,
|
void setFormatWithSpaces(const QString &text, int start, int count,
|
||||||
const QTextCharFormat &format);
|
const QTextCharFormat &format);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user