forked from qt-creator/qt-creator
SyntaxHighlighter: Connect signal to this not to document
Change-Id: I4e76c4e06f385075d64b9fee1eb71d6d5212935b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -136,26 +136,31 @@ BaseSyntaxHighlighterRunner::BaseSyntaxHighlighterRunner(
|
|||||||
|
|
||||||
BaseSyntaxHighlighterRunner::~BaseSyntaxHighlighterRunner() = default;
|
BaseSyntaxHighlighterRunner::~BaseSyntaxHighlighterRunner() = default;
|
||||||
|
|
||||||
void BaseSyntaxHighlighterRunner::applyFormatRanges(const SyntaxHighlighter::Result &result)
|
void BaseSyntaxHighlighterRunner::applyFormatRanges(const QList<SyntaxHighlighter::Result> &results)
|
||||||
{
|
{
|
||||||
m_syntaxInfoUpdated = result.m_state;
|
if (m_document == nullptr)
|
||||||
if (m_syntaxInfoUpdated == SyntaxHighlighter::State::Done) {
|
|
||||||
emit highlightingFinished();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTextBlock docBlock = m_document->findBlock(result.m_blockNumber);
|
|
||||||
if (!docBlock.isValid())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
result.copyToBlock(docBlock);
|
for (const SyntaxHighlighter::Result &result : results) {
|
||||||
|
m_syntaxInfoUpdated = result.m_state;
|
||||||
|
if (m_syntaxInfoUpdated == SyntaxHighlighter::State::Done) {
|
||||||
|
emit highlightingFinished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!result.m_formatRanges.empty()) {
|
QTextBlock docBlock = m_document->findBlock(result.m_blockNumber);
|
||||||
TextDocumentLayout::FoldValidator foldValidator;
|
if (!docBlock.isValid())
|
||||||
foldValidator.setup(qobject_cast<TextDocumentLayout *>(m_document->documentLayout()));
|
return;
|
||||||
docBlock.layout()->setFormats(result.m_formatRanges);
|
|
||||||
m_document->markContentsDirty(docBlock.position(), docBlock.length());
|
result.copyToBlock(docBlock);
|
||||||
foldValidator.process(docBlock);
|
|
||||||
|
if (!result.m_formatRanges.empty()) {
|
||||||
|
TextDocumentLayout::FoldValidator foldValidator;
|
||||||
|
foldValidator.setup(qobject_cast<TextDocumentLayout *>(m_document->documentLayout()));
|
||||||
|
docBlock.layout()->setFormats(result.m_formatRanges);
|
||||||
|
m_document->markContentsDirty(docBlock.position(), docBlock.length());
|
||||||
|
foldValidator.process(docBlock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,11 +254,8 @@ ThreadedSyntaxHighlighterRunner::ThreadedSyntaxHighlighterRunner(SyntaxHighLight
|
|||||||
m_document = document;
|
m_document = document;
|
||||||
connect(d.get(),
|
connect(d.get(),
|
||||||
&SyntaxHighlighterRunnerPrivate::resultsReady,
|
&SyntaxHighlighterRunnerPrivate::resultsReady,
|
||||||
document,
|
this,
|
||||||
[this](const QList<SyntaxHighlighter::Result> &result) {
|
&ThreadedSyntaxHighlighterRunner::applyFormatRanges);
|
||||||
for (const SyntaxHighlighter::Result &res : result)
|
|
||||||
applyFormatRanges(res);
|
|
||||||
});
|
|
||||||
|
|
||||||
changeDocument(0, 0, document->characterCount());
|
changeDocument(0, 0, document->characterCount());
|
||||||
connect(document,
|
connect(document,
|
||||||
|
@@ -58,7 +58,7 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
||||||
QPointer<QTextDocument> m_document = nullptr;
|
QPointer<QTextDocument> m_document = nullptr;
|
||||||
void applyFormatRanges(const SyntaxHighlighter::Result &result);
|
void applyFormatRanges(const QList<SyntaxHighlighter::Result> &results);
|
||||||
void changeDocument(int from, int charsRemoved, int charsAdded);
|
void changeDocument(int from, int charsRemoved, int charsAdded);
|
||||||
|
|
||||||
SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
||||||
|
Reference in New Issue
Block a user