diff --git a/src/plugins/haskell/haskellhighlighter.cpp b/src/plugins/haskell/haskellhighlighter.cpp index c89c4ae4805..a5061b4757d 100644 --- a/src/plugins/haskell/haskellhighlighter.cpp +++ b/src/plugins/haskell/haskellhighlighter.cpp @@ -26,7 +26,6 @@ namespace Internal { HaskellHighlighter::HaskellHighlighter() { setDefaultTextFormatCategories(); - updateFormats(TextEditorSettings::fontSettings()); } void HaskellHighlighter::highlightBlock(const QString &text) diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index 0d7b4d2ede9..36c3977c5ea 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -27,9 +27,7 @@ class SyntaxHighlighterPrivate SyntaxHighlighter *q_ptr = nullptr; Q_DECLARE_PUBLIC(SyntaxHighlighter) public: - SyntaxHighlighterPrivate() - : SyntaxHighlighterPrivate(TextEditorSettings::fontSettings()) - { } + SyntaxHighlighterPrivate() = default; SyntaxHighlighterPrivate(const FontSettings &fontSettings) { @@ -881,7 +879,7 @@ void SyntaxHighlighter::setTextFormatCategories(const QListformatCategories = categories; const int maxCategory = Utils::maxElementOr(categories, {-1, C_TEXT}).first; d->formats = QList(maxCategory + 1); - d->updateFormats(TextEditorSettings::fontSettings()); + d->updateFormats(d->fontSettings); } QTextCharFormat SyntaxHighlighter::formatForCategory(int category) const @@ -925,4 +923,3 @@ void SyntaxHighlighterPrivate::updateFormats(const FontSettings &fontSettings) } } // namespace TextEditor - diff --git a/src/plugins/texteditor/syntaxhighlighterrunner.cpp b/src/plugins/texteditor/syntaxhighlighterrunner.cpp index c992d1373e0..4001096b368 100644 --- a/src/plugins/texteditor/syntaxhighlighterrunner.cpp +++ b/src/plugins/texteditor/syntaxhighlighterrunner.cpp @@ -5,6 +5,7 @@ #include "fontsettings.h" #include "textdocumentlayout.h" +#include "texteditorsettings.h" #include @@ -19,13 +20,20 @@ class SyntaxHighlighterRunnerPrivate : public QObject { Q_OBJECT public: + void createHighlighter() + { + m_highlighter.reset(m_creator()); + m_highlighter->setFontSettings(m_fontSettings); + m_highlighter->setDocument(m_document); + } + SyntaxHighlighterRunnerPrivate(BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator creator, QTextDocument *document) : m_creator(creator) + , m_document(document) { m_highlighter.reset(m_creator()); - m_highlighter->setDocument(document); - m_document = document; + createHighlighter(); } void create() @@ -36,8 +44,7 @@ public: m_document = new QTextDocument(this); m_document->setDocumentLayout(new TextDocumentLayout(m_document)); - m_highlighter.reset(m_creator()); - m_highlighter->setDocument(m_document); + createHighlighter(); connect(m_highlighter.get(), &SyntaxHighlighter::resultsReady, @@ -102,6 +109,7 @@ private: BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator m_creator; std::unique_ptr m_highlighter; QTextDocument *m_document = nullptr; + const FontSettings m_fontSettings = TextEditorSettings::fontSettings(); }; // ----------------------------- BaseSyntaxHighlighterRunner --------------------------------------