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;
|
||||
|
||||
void BaseSyntaxHighlighterRunner::applyFormatRanges(const SyntaxHighlighter::Result &result)
|
||||
void BaseSyntaxHighlighterRunner::applyFormatRanges(const QList<SyntaxHighlighter::Result> &results)
|
||||
{
|
||||
m_syntaxInfoUpdated = result.m_state;
|
||||
if (m_syntaxInfoUpdated == SyntaxHighlighter::State::Done) {
|
||||
emit highlightingFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
QTextBlock docBlock = m_document->findBlock(result.m_blockNumber);
|
||||
if (!docBlock.isValid())
|
||||
if (m_document == nullptr)
|
||||
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()) {
|
||||
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);
|
||||
QTextBlock docBlock = m_document->findBlock(result.m_blockNumber);
|
||||
if (!docBlock.isValid())
|
||||
return;
|
||||
|
||||
result.copyToBlock(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;
|
||||
connect(d.get(),
|
||||
&SyntaxHighlighterRunnerPrivate::resultsReady,
|
||||
document,
|
||||
[this](const QList<SyntaxHighlighter::Result> &result) {
|
||||
for (const SyntaxHighlighter::Result &res : result)
|
||||
applyFormatRanges(res);
|
||||
});
|
||||
this,
|
||||
&ThreadedSyntaxHighlighterRunner::applyFormatRanges);
|
||||
|
||||
changeDocument(0, 0, document->characterCount());
|
||||
connect(document,
|
||||
|
@@ -58,7 +58,7 @@ signals:
|
||||
protected:
|
||||
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
||||
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);
|
||||
|
||||
SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
||||
|
Reference in New Issue
Block a user