aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/syntaxhighlighter.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2019-06-12 13:43:05 +0200
committerDavid Schulz <david.schulz@qt.io>2019-06-19 11:56:49 +0000
commitaa94b6f0c823a21fbffe042cd12567851e710613 (patch)
tree1ae3006ba677c47f5530088c81ccc7f38808e43c /src/plugins/texteditor/syntaxhighlighter.cpp
parent514e3776a1417a63c6f2c254ed05e61eb0aa6abf (diff)
TextEditor: modernize SyntaxHighlighter::setExtraFormats
Change-Id: Iaebf30d56702ef90b610d2db03c7abb40d1d2bab Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/texteditor/syntaxhighlighter.cpp')
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp36
1 files changed, 5 insertions, 31 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp
index 791b2e4a68..bd153e2143 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -667,15 +667,6 @@ static bool byStartOfRange(const QTextLayout::FormatRange &range, const QTextLay
void SyntaxHighlighter::setExtraFormats(const QTextBlock &block,
QVector<QTextLayout::FormatRange> &formats)
{
-// qDebug() << "setFormats() on block" << block.blockNumber();
-// qDebug() << " is valid:" << (block.isValid() ? "Yes" : "No");
-// qDebug() << " has layout:" << (block.layout() ? "Yes" : "No");
-// if (block.layout()) qDebug() << " has text:" << (block.text().isEmpty() ? "No" : "Yes");
-
-// for (int i = 0; i < overrides.count(); ++i)
-// qDebug() << " from " << overrides.at(i).start << "length"
-// << overrides.at(i).length
-// << "color:" << overrides.at(i).format.foreground().color();
Q_D(SyntaxHighlighter);
const int blockLength = block.length();
@@ -687,34 +678,17 @@ void SyntaxHighlighter::setExtraFormats(const QTextBlock &block,
const QVector<QTextLayout::FormatRange> all = block.layout()->formats();
QVector<QTextLayout::FormatRange> previousSemanticFormats;
QVector<QTextLayout::FormatRange> formatsToApply;
- previousSemanticFormats.reserve(all.size());
- formatsToApply.reserve(all.size() + formats.size());
+ std::tie(previousSemanticFormats, formatsToApply)
+ = Utils::partition(all, [](const QTextLayout::FormatRange &r) {
+ return r.format.hasProperty(QTextFormat::UserProperty);
+ });
for (auto &format : formats)
format.format.setProperty(QTextFormat::UserProperty, true);
- foreach (const QTextLayout::FormatRange &r, all) {
- if (r.format.hasProperty(QTextFormat::UserProperty))
- previousSemanticFormats.append(r);
- else
- formatsToApply.append(r);
- }
-
if (formats.size() == previousSemanticFormats.size()) {
Utils::sort(previousSemanticFormats, byStartOfRange);
-
- int index = 0;
- for (; index != formats.size(); ++index) {
- const QTextLayout::FormatRange &range = formats.at(index);
- const QTextLayout::FormatRange &previousRange = previousSemanticFormats.at(index);
-
- if (range.start != previousRange.start ||
- range.length != previousRange.length ||
- range.format != previousRange.format)
- break;
- }
-
- if (index == formats.size())
+ if (formats == previousSemanticFormats)
return;
}