diff options
author | David Schulz <david.schulz@qt.io> | 2019-06-13 09:56:39 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-06-19 11:57:47 +0000 |
commit | 2eddd65596d8a10e4f3778a974e1939a9e1ca9f9 (patch) | |
tree | 6cffce5f512fe24e140ba18bef15e58b3e80ddd0 | |
parent | c05ec2833e91af55a8fc93546e2577860039bdbb (diff) | |
download | qt-creator-2eddd65596d8a10e4f3778a974e1939a9e1ca9f9.tar.gz |
TextEditor: add convenience function to clear all extra highlights
Change-Id: Id3a3c45041a23ba100447d926ed6ab829abbc92b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
-rw-r--r-- | src/plugins/cppeditor/cppeditordocument.cpp | 10 | ||||
-rw-r--r-- | src/plugins/texteditor/syntaxhighlighter.cpp | 9 | ||||
-rw-r--r-- | src/plugins/texteditor/syntaxhighlighter.h | 1 |
3 files changed, 12 insertions, 8 deletions
diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp index c4af4b1559..9574ed0e8d 100644 --- a/src/plugins/cppeditor/cppeditordocument.cpp +++ b/src/plugins/cppeditor/cppeditordocument.cpp @@ -176,14 +176,8 @@ QByteArray CppEditorDocument::contentsText() const void CppEditorDocument::applyFontSettings() { - if (TextEditor::SyntaxHighlighter *highlighter = syntaxHighlighter()) { - // Clear all additional formats since they may have changed - QTextBlock b = document()->firstBlock(); - while (b.isValid()) { - highlighter->clearExtraFormats(b); - b = b.next(); - } - } + if (TextEditor::SyntaxHighlighter *highlighter = syntaxHighlighter()) + highlighter->clearAllExtraFormats(); // Clear all additional formats since they may have changed TextDocument::applyFontSettings(); // rehighlights and updates additional formats if (m_processor) m_processor->semanticRehighlight(); diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index 8f7f1f153e..b28ac1ee18 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -721,6 +721,15 @@ void SyntaxHighlighter::clearExtraFormats(const QTextBlock &block) d->inReformatBlocks = wasInReformatBlocks; } +void SyntaxHighlighter::clearAllExtraFormats() +{ + QTextBlock b = document()->firstBlock(); + while (b.isValid()) { + clearExtraFormats(b); + b = b.next(); + } +} + /* Generate at least n different colors for highlighting, excluding background * color. */ diff --git a/src/plugins/texteditor/syntaxhighlighter.h b/src/plugins/texteditor/syntaxhighlighter.h index bbd23a77d4..05ff38908f 100644 --- a/src/plugins/texteditor/syntaxhighlighter.h +++ b/src/plugins/texteditor/syntaxhighlighter.h @@ -65,6 +65,7 @@ public: void setExtraFormats(const QTextBlock &block, QVector<QTextLayout::FormatRange> &&formats); void clearExtraFormats(const QTextBlock &block); + void clearAllExtraFormats(); static QList<QColor> generateColors(int n, const QColor &background); |