TextEditor: add convenience function to clear all extra highlights

Change-Id: Id3a3c45041a23ba100447d926ed6ab829abbc92b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
David Schulz
2019-06-13 09:56:39 +02:00
parent c05ec2833e
commit 2eddd65596
3 changed files with 12 additions and 8 deletions

View File

@@ -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();

View File

@@ -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. */

View File

@@ -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);