CppEditor: Fix highlighting angle brackets

The code assumed that all highlighting results come in at once, which is
no longer true as of d6f5d07639.

Change-Id: I5ed6baf88956d64a30ee3fb236d4e2575a7f80c9
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2023-05-26 10:01:51 +02:00
parent 2cce367906
commit 0c1974f9b8
3 changed files with 20 additions and 5 deletions

View File

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

View File

@@ -8,14 +8,21 @@
#include <QFutureWatcher>
#include <QScopedPointer>
#include <QTextCharFormat>
#include <QVector>
#include <functional>
#include <set>
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<TextEditor::Parenthesis> getClearedParentheses(const QTextBlock &block);
private:
TextEditor::TextDocument *m_baseTextDocument;
@@ -73,6 +81,7 @@ private:
unsigned m_revision = 0;
QScopedPointer<QFutureWatcher<TextEditor::HighlightingResult>> m_watcher;
QHash<int, QTextCharFormat> m_formatMap;
std::set<int> m_seenBlocks;
HighlightingRunner m_highlightingRunner;
};

View File

@@ -17,8 +17,9 @@
namespace TextEditor {
struct TEXTEDITOR_EXPORT Parenthesis
class TEXTEDITOR_EXPORT Parenthesis
{
public:
enum Type : char { Opened, Closed };
Parenthesis() = default;