Skip to content
Snippets Groups Projects
Commit 6c56fcf5 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Nicer implementation of setExtraAdditionalFormats()

parent 6021a889
No related branches found
No related tags found
No related merge requests found
...@@ -684,7 +684,12 @@ void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block, ...@@ -684,7 +684,12 @@ void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block,
if (block.layout() == 0) if (block.layout() == 0)
return; return;
QList<QTextLayout::FormatRange> formats = fmts; QList<QTextLayout::FormatRange> formats;
formats.reserve(fmts.size());
foreach (QTextLayout::FormatRange r, fmts) {
r.format.setProperty(QTextFormat::UserProperty, true);
formats.append(r);
}
qSort(formats.begin(), formats.end(), byStartOfRange); qSort(formats.begin(), formats.end(), byStartOfRange);
QList<QTextLayout::FormatRange> previousSemanticFormats; QList<QTextLayout::FormatRange> previousSemanticFormats;
...@@ -698,19 +703,12 @@ void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block, ...@@ -698,19 +703,12 @@ void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block,
formatsToApply.append(r); formatsToApply.append(r);
} }
qSort(previousSemanticFormats.begin(), previousSemanticFormats.end(), byStartOfRange);
foreach (QTextLayout::FormatRange r, formats) {
r.format.setProperty(QTextFormat::UserProperty, true);
formatsToApply.append(r);
}
if (formats.size() == previousSemanticFormats.size()) { if (formats.size() == previousSemanticFormats.size()) {
qSort(previousSemanticFormats.begin(), previousSemanticFormats.end(), byStartOfRange);
int index = 0; int index = 0;
for (; index != formats.size(); ++index) { for (; index != formats.size(); ++index) {
QTextLayout::FormatRange range = formats.at(index); const QTextLayout::FormatRange &range = formats.at(index);
range.format.setProperty(QTextFormat::UserProperty, true);
const QTextLayout::FormatRange &previousRange = previousSemanticFormats.at(index); const QTextLayout::FormatRange &previousRange = previousSemanticFormats.at(index);
if (range.start != previousRange.start || if (range.start != previousRange.start ||
...@@ -723,6 +721,8 @@ void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block, ...@@ -723,6 +721,8 @@ void SyntaxHighlighter::setExtraAdditionalFormats(const QTextBlock& block,
return; return;
} }
formatsToApply += formats;
bool wasInReformatBlocks = d->inReformatBlocks; bool wasInReformatBlocks = d->inReformatBlocks;
d->inReformatBlocks = true; d->inReformatBlocks = true;
block.layout()->setAdditionalFormats(formatsToApply); block.layout()->setAdditionalFormats(formatsToApply);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment