summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2019-06-13 09:56:39 +0200
committerDavid Schulz <david.schulz@qt.io>2019-06-19 11:57:47 +0000
commit2eddd65596d8a10e4f3778a974e1939a9e1ca9f9 (patch)
tree6cffce5f512fe24e140ba18bef15e58b3e80ddd0
parentc05ec2833e91af55a8fc93546e2577860039bdbb (diff)
downloadqt-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.cpp10
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp9
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.h1
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);