From 0c1974f9b89c0526e135d2a6d2e57edec992f21e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 26 May 2023 10:01:51 +0200 Subject: [PATCH] CppEditor: Fix highlighting angle brackets The code assumed that all highlighting results come in at once, which is no longer true as of d6f5d07639c3d0313b758ba6fb7cc5eb57d188ef. Change-Id: I5ed6baf88956d64a30ee3fb236d4e2575a7f80c9 Reviewed-by: David Schulz Reviewed-by: --- src/plugins/cppeditor/semantichighlighter.cpp | 13 +++++++++---- src/plugins/cppeditor/semantichighlighter.h | 9 +++++++++ src/plugins/texteditor/textdocumentlayout.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/plugins/cppeditor/semantichighlighter.cpp b/src/plugins/cppeditor/semantichighlighter.cpp index 473991787d0..c04b9270aa9 100644 --- a/src/plugins/cppeditor/semantichighlighter.cpp +++ b/src/plugins/cppeditor/semantichighlighter.cpp @@ -63,15 +63,20 @@ void SemanticHighlighter::run() connectWatcher(); m_revision = documentRevision(); + m_seenBlocks.clear(); qCDebug(log) << "starting runner for document revision" << m_revision; m_watcher->setFuture(m_highlightingRunner()); } -static Parentheses getClearedParentheses(const QTextBlock &block) +Parentheses SemanticHighlighter::getClearedParentheses(const QTextBlock &block) { - return Utils::filtered(TextDocumentLayout::parentheses(block), [](const Parenthesis &p) { - return p.source != parenSource(); - }); + Parentheses parens = TextDocumentLayout::parentheses(block); + if (m_seenBlocks.insert(block.blockNumber()).second) { + parens = Utils::filtered(parens, [](const Parenthesis &p) { + return p.source != parenSource(); + }); + } + return parens; } void SemanticHighlighter::onHighlighterResultAvailable(int from, int to) diff --git a/src/plugins/cppeditor/semantichighlighter.h b/src/plugins/cppeditor/semantichighlighter.h index b34c49ce87a..fb1a704e6c3 100644 --- a/src/plugins/cppeditor/semantichighlighter.h +++ b/src/plugins/cppeditor/semantichighlighter.h @@ -8,14 +8,21 @@ #include #include #include +#include #include +#include namespace TextEditor { class HighlightingResult; +class Parenthesis; class TextDocument; } +QT_BEGIN_NAMESPACE +class QTextBlock; +QT_END_NAMESPACE + namespace CppEditor { class CPPEDITOR_EXPORT SemanticHighlighter : public QObject @@ -66,6 +73,7 @@ private: void disconnectWatcher(); unsigned documentRevision() const; + QVector getClearedParentheses(const QTextBlock &block); private: TextEditor::TextDocument *m_baseTextDocument; @@ -73,6 +81,7 @@ private: unsigned m_revision = 0; QScopedPointer> m_watcher; QHash m_formatMap; + std::set m_seenBlocks; HighlightingRunner m_highlightingRunner; }; diff --git a/src/plugins/texteditor/textdocumentlayout.h b/src/plugins/texteditor/textdocumentlayout.h index d6f847e4810..33387093da7 100644 --- a/src/plugins/texteditor/textdocumentlayout.h +++ b/src/plugins/texteditor/textdocumentlayout.h @@ -17,8 +17,9 @@ namespace TextEditor { -struct TEXTEDITOR_EXPORT Parenthesis +class TEXTEDITOR_EXPORT Parenthesis { +public: enum Type : char { Opened, Closed }; Parenthesis() = default;