aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/syntaxhighlighter.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-05-07 11:12:37 +0200
committerEike Ziller <eike.ziller@qt.io>2017-05-23 08:34:53 +0000
commitf51fbd68e1de6f317719d5985f9a2e184c92ff99 (patch)
treec3b3974ae779046f6aba16173f43c26b396e1d41 /src/plugins/texteditor/syntaxhighlighter.cpp
parentcf57965ebc8ec913a2b2fafe352ddae3f7706b98 (diff)
SyntaxHighligher: Remove the need to specify format for spaces
It has all means to know itself. Change-Id: I464c195c5ee47e5fc58414a280c166e4a332c588 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/syntaxhighlighter.cpp')
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp
index 05c7ee453c..7479c4a0a8 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -48,7 +48,9 @@ class SyntaxHighlighterPrivate
public:
inline SyntaxHighlighterPrivate()
: q_ptr(0), rehighlightPending(false), inReformatBlocks(false)
- {}
+ {
+ updateFormats(TextEditorSettings::fontSettings());
+ }
QPointer<QTextDocument> doc;
@@ -64,7 +66,7 @@ public:
}
void applyFormatChanges(int from, int charsRemoved, int charsAdded);
- void updateFormatsForCategories(const FontSettings &fontSettings);
+ void updateFormats(const FontSettings &fontSettings);
QVector<QTextCharFormat> formatChanges;
QTextBlock currentBlock;
@@ -73,6 +75,7 @@ public:
TextDocumentLayout::FoldValidator foldValidator;
QVector<QTextCharFormat> formats;
QVector<std::pair<int,TextStyle>> formatCategories;
+ QTextCharFormat whitespaceFormat;
};
static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsRemoved, int charsAdded) {
@@ -474,8 +477,9 @@ void SyntaxHighlighter::setFormat(int start, int count, const QFont &font)
setFormat(start, count, format);
}
-void SyntaxHighlighter::applyFormatToSpaces(const QString &text, const QTextCharFormat &format)
+void SyntaxHighlighter::formatSpaces(const QString &text)
{
+ Q_D(const SyntaxHighlighter);
int offset = 0;
const int length = text.length();
while (offset < length) {
@@ -483,7 +487,7 @@ void SyntaxHighlighter::applyFormatToSpaces(const QString &text, const QTextChar
int start = offset++;
while (offset < length && text.at(offset).isSpace())
++offset;
- setFormat(start, offset - start, format);
+ setFormat(start, offset - start, d->whitespaceFormat);
} else {
++offset;
}
@@ -725,7 +729,7 @@ QList<QColor> SyntaxHighlighter::generateColors(int n, const QColor &background)
void SyntaxHighlighter::setFontSettings(const FontSettings &fontSettings)
{
Q_D(SyntaxHighlighter);
- d->updateFormatsForCategories(fontSettings);
+ d->updateFormats(fontSettings);
}
/*!
@@ -771,7 +775,7 @@ void SyntaxHighlighter::setTextFormatCategories(const QVector<std::pair<int, Tex
d->formatCategories = categories;
const int maxCategory = Utils::maxElementOr(categories, {-1, C_TEXT}).first;
d->formats = QVector<QTextCharFormat>(maxCategory + 1);
- d->updateFormatsForCategories(TextEditorSettings::fontSettings());
+ d->updateFormats(TextEditorSettings::fontSettings());
}
QTextCharFormat SyntaxHighlighter::formatForCategory(int category) const
@@ -782,10 +786,11 @@ QTextCharFormat SyntaxHighlighter::formatForCategory(int category) const
return d->formats.at(category);
}
-void SyntaxHighlighterPrivate::updateFormatsForCategories(const FontSettings &fontSettings)
+void SyntaxHighlighterPrivate::updateFormats(const FontSettings &fontSettings)
{
for (const auto &pair : Utils::asConst(formatCategories))
formats[pair.first] = fontSettings.toTextCharFormat(pair.second);
+ whitespaceFormat = fontSettings.toTextCharFormat(C_VISUAL_WHITESPACE);
}
} // namespace TextEditor