From 2eddd65596d8a10e4f3778a974e1939a9e1ca9f9 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 13 Jun 2019 09:56:39 +0200 Subject: TextEditor: add convenience function to clear all extra highlights Change-Id: Id3a3c45041a23ba100447d926ed6ab829abbc92b Reviewed-by: Nikolai Kosjar --- src/plugins/cppeditor/cppeditordocument.cpp | 10 ++-------- src/plugins/texteditor/syntaxhighlighter.cpp | 9 +++++++++ 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 &&formats); void clearExtraFormats(const QTextBlock &block); + void clearAllExtraFormats(); static QList generateColors(int n, const QColor &background); -- cgit v1.2.1