Commit 129b53f6 authored by Leandro Melo's avatar Leandro Melo
Browse files

Profile editor: Add proper format to white spaces.

The generic highlighter already provided a method for this.
This method was then lifted to the base syntax highlighter
and it is now used by the profile highlighter.

Reviewed-by: Roberto Raggi
Task-number: QTCREATORBUG-2448
parent c9e819b5
......@@ -140,7 +140,8 @@ void ProFileEditor::setFontSettings(const TextEditor::FontSettings &fs)
if (categories.isEmpty()) {
categories << QLatin1String(TextEditor::Constants::C_TYPE)
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_COMMENT);
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
}
const QVector<QTextCharFormat> formats = fs.toTextCharFormats(categories);
......
......@@ -201,5 +201,6 @@ void ProFileHighlighter::highlightBlock(const QString &text)
if (i >= text.length())
break;
}
}
applyFormatToSpaces(text, m_formats[ProfileVisualWhitespaceFormat]);
}
......@@ -46,6 +46,7 @@ public:
ProfileVariableFormat,
ProfileFunctionFormat,
ProfileCommentFormat,
ProfileVisualWhitespaceFormat,
NumProfileFormats
};
......
......@@ -140,7 +140,7 @@ void Highlighter::highlightBlock(const QString &text)
}
}
applyVisualWhitespaceFormat(text);
applyFormatToSpaces(text, m_creatorFormats.value(VisualWhitespace));
}
void Highlighter::setupDataForBlock(const QString &text)
......@@ -408,22 +408,6 @@ void Highlighter::applyFormat(int offset,
}
}
void Highlighter::applyVisualWhitespaceFormat(const QString &text)
{
int offset = 0;
const int length = text.length();
while (offset < length) {
if (text.at(offset).isSpace()) {
int start = offset++;
while (offset < length && text.at(offset).isSpace())
++offset;
setFormat(start, offset - start, m_creatorFormats.value(VisualWhitespace));
} else {
++offset;
}
}
}
void Highlighter::createWillContinueBlock()
{
BlockData *data = blockData(currentBlockUserData());
......
......@@ -123,7 +123,6 @@ private:
int count,
const QString &itemDataName,
const QSharedPointer<HighlightDefinition> &definition);
void applyVisualWhitespaceFormat(const QString &text);
void applyRegionBasedFolding() const;
void applyIndentationBasedFolding(const QString &text) const;
......
......@@ -535,6 +535,22 @@ void SyntaxHighlighter::setFormat(int start, int count, const QFont &font)
setFormat(start, count, format);
}
void SyntaxHighlighter::applyFormatToSpaces(const QString &text, const QTextCharFormat &format)
{
int offset = 0;
const int length = text.length();
while (offset < length) {
if (text.at(offset).isSpace()) {
int start = offset++;
while (offset < length && text.at(offset).isSpace())
++offset;
setFormat(start, offset - start, format);
} else {
++offset;
}
}
}
/*!
\fn QTextCharFormat SyntaxHighlighter::format(int position) const
......
......@@ -89,6 +89,8 @@ protected:
void setFormat(int start, int count, const QFont &font);
QTextCharFormat format(int pos) const;
void applyFormatToSpaces(const QString &text, const QTextCharFormat &format);
int previousBlockState() const;
int currentBlockState() const;
void setCurrentBlockState(int newState);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment