TextEditor: add convenience function to clear additional highlights

Change-Id: Ie3cf6e7f9fb37f3e2270abaf5fca412e7a4a40da
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
David Schulz
2019-06-12 13:15:48 +02:00
parent aa94b6f0c8
commit cea75f3ac4
4 changed files with 24 additions and 6 deletions

View File

@@ -701,6 +701,26 @@ void SyntaxHighlighter::setExtraFormats(const QTextBlock &block,
d->inReformatBlocks = wasInReformatBlocks;
}
void SyntaxHighlighter::clearExtraFormats(const QTextBlock &block)
{
Q_D(SyntaxHighlighter);
const int blockLength = block.length();
if (block.layout() == nullptr || blockLength == 0)
return;
const QVector<QTextLayout::FormatRange> formatsToApply
= Utils::filtered(block.layout()->formats(), [](const QTextLayout::FormatRange &r) {
return !r.format.hasProperty(QTextFormat::UserProperty);
});
bool wasInReformatBlocks = d->inReformatBlocks;
d->inReformatBlocks = true;
block.layout()->setFormats(formatsToApply);
document()->markContentsDirty(block.position(), blockLength - 1);
d->inReformatBlocks = wasInReformatBlocks;
}
/* Generate at least n different colors for highlighting, excluding background
* color. */