forked from qt-creator/qt-creator
TextEditor: add convenience function to clear additional highlights
Change-Id: Ie3cf6e7f9fb37f3e2270abaf5fca412e7a4a40da Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -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. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user