From 876159cea9791912f7d2b9d0c838e321b4a96975 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 7 Mar 2024 07:30:30 +0100 Subject: [PATCH] Revert "Revert "TextEditor: Use synchronous highlighter by default"" The crash in the syntax highlighter was resolved so we can switch the default back to synchronous highlighter. This reverts commit 0539e2a0f63c25d24c78c4e12f8554714a7b1855. Change-Id: I2e9cdb818420a14d01565d58def14f88cf5e895d Reviewed-by: Artem Sokolovskii --- src/plugins/texteditor/textdocument.cpp | 16 ++++++++++------ src/plugins/texteditor/textdocument.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index cb421f2bf7c..2636ad46e23 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -914,19 +914,23 @@ bool TextDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type void TextDocument::resetSyntaxHighlighter(const std::function &creator, bool threaded) { - if (d->m_highlighterRunner) - delete d->m_highlighterRunner; + delete d->m_highlighterRunner; - static const bool envValue - = qtcEnvironmentVariable("QTC_USE_THREADED_HIGHLIGHTER", "TRUE").toUpper() - == QLatin1String("TRUE"); + static const std::optional envValue = []() -> std::optional { + const QString key("QTC_USE_THREADED_HIGHLIGHTER"); + if (qtcEnvironmentVariableIsSet(key)) { + const QString value = qtcEnvironmentVariable(key).toUpper(); + return value != "FALSE" && value != "0"; + } + return {}; + }(); SyntaxHighlighter *highlighter = creator(); highlighter->setFontSettings(TextEditorSettings::fontSettings()); highlighter->setMimeType(mimeType()); d->m_highlighterRunner = new SyntaxHighlighterRunner(highlighter, document(), - threaded && envValue); + envValue.value_or(threaded)); } void TextDocument::cleanWhitespace(const QTextCursor &cursor) diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h index ad3fe262e24..5879d9e9ec2 100644 --- a/src/plugins/texteditor/textdocument.h +++ b/src/plugins/texteditor/textdocument.h @@ -127,7 +127,7 @@ public: QTextDocument *document() const; using SyntaxHighLighterCreator = std::function; - void resetSyntaxHighlighter(const SyntaxHighLighterCreator &creator, bool threaded = true); + void resetSyntaxHighlighter(const SyntaxHighLighterCreator &creator, bool threaded = false); SyntaxHighlighterRunner *syntaxHighlighterRunner() const; bool reload(QString *errorString, QTextCodec *codec);