diff --git a/src/plugins/texteditor/syntaxhighlighterrunner.cpp b/src/plugins/texteditor/syntaxhighlighterrunner.cpp index 99ff3564941..3780ff47e61 100644 --- a/src/plugins/texteditor/syntaxhighlighterrunner.cpp +++ b/src/plugins/texteditor/syntaxhighlighterrunner.cpp @@ -42,10 +42,10 @@ public: &SyntaxHighlighterRunnerPrivate::resultsReady); } - void cloneDocument(int from, - int charsRemoved, - const QString textAdded, - const QMap &blocksPreedit) + void changeDocument(int from, + int charsRemoved, + const QString textAdded, + const QMap &blocksPreedit) { QTextCursor cursor(m_document); cursor.setPosition(qMin(m_document->characterCount() - 1, from + charsRemoved)); @@ -156,8 +156,9 @@ void BaseSyntaxHighlighterRunner::applyFormatRanges(const SyntaxHighlighter::Res } } -void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved, int charsAdded) +void BaseSyntaxHighlighterRunner::changeDocument(int from, int charsRemoved, int charsAdded) { + QTC_ASSERT(m_document, return); m_syntaxInfoUpdated = SyntaxHighlighter::State::InProgress; QMap blocksPreedit; QTextBlock block = m_document->findBlock(from); @@ -170,16 +171,8 @@ void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved, block = block.next(); } const QString text = Utils::Text::textAt(QTextCursor(m_document), from, charsAdded); - cloneDocument(from, charsRemoved, text, blocksPreedit); -} - -void BaseSyntaxHighlighterRunner::cloneDocument(int from, - int charsRemoved, - const QString textAdded, - const QMap &blocksPreedit) -{ - QMetaObject::invokeMethod(d.get(), [this, from, charsRemoved, textAdded, blocksPreedit] { - d->cloneDocument(from, charsRemoved, textAdded, blocksPreedit); + QMetaObject::invokeMethod(d.get(), [this, from, charsRemoved, text, blocksPreedit] { + d->changeDocument(from, charsRemoved, text, blocksPreedit); }); } @@ -254,16 +247,11 @@ ThreadedSyntaxHighlighterRunner::ThreadedSyntaxHighlighterRunner(SyntaxHighLight applyFormatRanges(res); }); - cloneDocumentData(0, 0, document->characterCount()); + changeDocument(0, 0, document->characterCount()); connect(document, &QTextDocument::contentsChange, this, - [this](int from, int charsRemoved, int charsAdded) { - if (!this->document()) - return; - - cloneDocumentData(from, charsRemoved, charsAdded); - }); + &ThreadedSyntaxHighlighterRunner::changeDocument); } ThreadedSyntaxHighlighterRunner::~ThreadedSyntaxHighlighterRunner() diff --git a/src/plugins/texteditor/syntaxhighlighterrunner.h b/src/plugins/texteditor/syntaxhighlighterrunner.h index 6336c27a823..b01c23df6b8 100644 --- a/src/plugins/texteditor/syntaxhighlighterrunner.h +++ b/src/plugins/texteditor/syntaxhighlighterrunner.h @@ -58,11 +58,7 @@ protected: std::unique_ptr d; QPointer m_document = nullptr; void applyFormatRanges(const SyntaxHighlighter::Result &result); - void cloneDocumentData(int from, int charsRemoved, int charsAdded); - void cloneDocument(int from, - int charsRemoved, - const QString textAdded, - const QMap &blocksPreedit); + void changeDocument(int from, int charsRemoved, int charsAdded); SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;