forked from qt-creator/qt-creator
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:
@@ -63,15 +63,20 @@ void SemanticHighlighter::run()
|
|||||||
connectWatcher();
|
connectWatcher();
|
||||||
|
|
||||||
m_revision = documentRevision();
|
m_revision = documentRevision();
|
||||||
|
m_seenBlocks.clear();
|
||||||
qCDebug(log) << "starting runner for document revision" << m_revision;
|
qCDebug(log) << "starting runner for document revision" << m_revision;
|
||||||
m_watcher->setFuture(m_highlightingRunner());
|
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 p.source != parenSource();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
return parens;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticHighlighter::onHighlighterResultAvailable(int from, int to)
|
void SemanticHighlighter::onHighlighterResultAvailable(int from, int to)
|
||||||
|
|||||||
@@ -8,14 +8,21 @@
|
|||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
class HighlightingResult;
|
class HighlightingResult;
|
||||||
|
class Parenthesis;
|
||||||
class TextDocument;
|
class TextDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QTextBlock;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
|
|
||||||
class CPPEDITOR_EXPORT SemanticHighlighter : public QObject
|
class CPPEDITOR_EXPORT SemanticHighlighter : public QObject
|
||||||
@@ -66,6 +73,7 @@ private:
|
|||||||
void disconnectWatcher();
|
void disconnectWatcher();
|
||||||
|
|
||||||
unsigned documentRevision() const;
|
unsigned documentRevision() const;
|
||||||
|
QVector<TextEditor::Parenthesis> getClearedParentheses(const QTextBlock &block);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::TextDocument *m_baseTextDocument;
|
TextEditor::TextDocument *m_baseTextDocument;
|
||||||
@@ -73,6 +81,7 @@ private:
|
|||||||
unsigned m_revision = 0;
|
unsigned m_revision = 0;
|
||||||
QScopedPointer<QFutureWatcher<TextEditor::HighlightingResult>> m_watcher;
|
QScopedPointer<QFutureWatcher<TextEditor::HighlightingResult>> m_watcher;
|
||||||
QHash<int, QTextCharFormat> m_formatMap;
|
QHash<int, QTextCharFormat> m_formatMap;
|
||||||
|
std::set<int> m_seenBlocks;
|
||||||
|
|
||||||
HighlightingRunner m_highlightingRunner;
|
HighlightingRunner m_highlightingRunner;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
struct TEXTEDITOR_EXPORT Parenthesis
|
class TEXTEDITOR_EXPORT Parenthesis
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
enum Type : char { Opened, Closed };
|
enum Type : char { Opened, Closed };
|
||||||
|
|
||||||
Parenthesis() = default;
|
Parenthesis() = default;
|
||||||
|
|||||||
Reference in New Issue
Block a user