diff options
author | David Schulz <david.schulz@qt.io> | 2019-06-12 13:15:48 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-06-19 11:57:12 +0000 |
commit | cea75f3ac4359d9ea90fe682e20adca2619a6320 (patch) | |
tree | 3737d11d0259bb60fb13f99c9d4e978d616cfa08 /src/plugins/texteditor/syntaxhighlighter.cpp | |
parent | aa94b6f0c823a21fbffe042cd12567851e710613 (diff) |
TextEditor: add convenience function to clear additional highlights
Change-Id: Ie3cf6e7f9fb37f3e2270abaf5fca412e7a4a40da
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/texteditor/syntaxhighlighter.cpp')
-rw-r--r-- | src/plugins/texteditor/syntaxhighlighter.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index bd153e2143..0680246135 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -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. */ |