forked from qt-creator/qt-creator
SyntaxHighlighter: Add signal that highlighting is finished
Added function syntaxInfoUpdated shows whether highlighting inProgress or Done and signal highlightingFinished. Change-Id: I4cf2b5cfa97d73c882e69ee1df81497ec50a81f7 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -221,6 +221,9 @@ void SyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int ch
|
|||||||
formatChanges.clear();
|
formatChanges.clear();
|
||||||
|
|
||||||
foldValidator.finalize();
|
foldValidator.finalize();
|
||||||
|
SyntaxHighlighter::Result res;
|
||||||
|
res.m_state = SyntaxHighlighter::State::Done;
|
||||||
|
vecRes << res;
|
||||||
emit q->resultsReady(vecRes);
|
emit q->resultsReady(vecRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,6 +52,11 @@ public:
|
|||||||
|
|
||||||
void setNoAutomaticHighlighting(bool noAutomatic);
|
void setNoAutomaticHighlighting(bool noAutomatic);
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
InProgress,
|
||||||
|
Done
|
||||||
|
};
|
||||||
|
|
||||||
struct Result
|
struct Result
|
||||||
{
|
{
|
||||||
void fillByBlock(const QTextBlock &block)
|
void fillByBlock(const QTextBlock &block)
|
||||||
@@ -107,6 +112,8 @@ public:
|
|||||||
QByteArray m_expectedRawStringSuffix;
|
QByteArray m_expectedRawStringSuffix;
|
||||||
int m_userState = -1;
|
int m_userState = -1;
|
||||||
QList<QTextLayout::FormatRange> m_formatRanges;
|
QList<QTextLayout::FormatRange> m_formatRanges;
|
||||||
|
|
||||||
|
State m_state = InProgress;
|
||||||
};
|
};
|
||||||
|
|
||||||
void setExtraFormats(const QTextBlock &block, const QList<QTextLayout::FormatRange> &formats);
|
void setExtraFormats(const QTextBlock &block, const QList<QTextLayout::FormatRange> &formats);
|
||||||
|
@@ -25,6 +25,11 @@ public:
|
|||||||
m_highlighter.reset(m_creator());
|
m_highlighter.reset(m_creator());
|
||||||
m_highlighter->setFontSettings(m_fontSettings);
|
m_highlighter->setFontSettings(m_fontSettings);
|
||||||
m_highlighter->setDocument(m_document);
|
m_highlighter->setDocument(m_document);
|
||||||
|
|
||||||
|
connect(m_highlighter.get(),
|
||||||
|
&SyntaxHighlighter::resultsReady,
|
||||||
|
this,
|
||||||
|
&SyntaxHighlighterRunnerPrivate::resultsReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
SyntaxHighlighterRunnerPrivate(BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator creator,
|
SyntaxHighlighterRunnerPrivate(BaseSyntaxHighlighterRunner::SyntaxHighLighterCreator creator,
|
||||||
@@ -46,11 +51,6 @@ public:
|
|||||||
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
m_document->setDocumentLayout(new TextDocumentLayout(m_document));
|
||||||
|
|
||||||
createHighlighter();
|
createHighlighter();
|
||||||
|
|
||||||
connect(m_highlighter.get(),
|
|
||||||
&SyntaxHighlighter::resultsReady,
|
|
||||||
this,
|
|
||||||
&SyntaxHighlighterRunnerPrivate::resultsReady);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cloneDocument(int from,
|
void cloneDocument(int from,
|
||||||
@@ -86,7 +86,7 @@ public:
|
|||||||
void setFontSettings(const TextEditor::FontSettings &fontSettings)
|
void setFontSettings(const TextEditor::FontSettings &fontSettings)
|
||||||
{
|
{
|
||||||
m_highlighter->setFontSettings(fontSettings);
|
m_highlighter->setFontSettings(fontSettings);
|
||||||
m_highlighter->rehighlight();
|
rehighlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefinitionName(const QString &name)
|
void setDefinitionName(const QString &name)
|
||||||
@@ -120,14 +120,39 @@ BaseSyntaxHighlighterRunner::BaseSyntaxHighlighterRunner(
|
|||||||
QTextDocument *document,
|
QTextDocument *document,
|
||||||
const TextEditor::FontSettings &fontSettings)
|
const TextEditor::FontSettings &fontSettings)
|
||||||
: d(new SyntaxHighlighterRunnerPrivate(creator, document, fontSettings))
|
: d(new SyntaxHighlighterRunnerPrivate(creator, document, fontSettings))
|
||||||
|
, m_document(document)
|
||||||
{
|
{
|
||||||
m_document = document;
|
if (document == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect(d.get(),
|
||||||
|
&SyntaxHighlighterRunnerPrivate::resultsReady,
|
||||||
|
this,
|
||||||
|
[this](const QList<SyntaxHighlighter::Result> &result) {
|
||||||
|
auto done = std::find_if(result.cbegin(),
|
||||||
|
result.cend(),
|
||||||
|
[](const SyntaxHighlighter::Result &res) {
|
||||||
|
return res.m_state == SyntaxHighlighter::State::Done;
|
||||||
|
});
|
||||||
|
if (done != result.cend()) {
|
||||||
|
m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
||||||
|
emit highlightingFinished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_syntaxInfoUpdated = SyntaxHighlighter::State::InProgress;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseSyntaxHighlighterRunner::~BaseSyntaxHighlighterRunner() = default;
|
BaseSyntaxHighlighterRunner::~BaseSyntaxHighlighterRunner() = default;
|
||||||
|
|
||||||
void BaseSyntaxHighlighterRunner::applyFormatRanges(const SyntaxHighlighter::Result &result)
|
void BaseSyntaxHighlighterRunner::applyFormatRanges(const SyntaxHighlighter::Result &result)
|
||||||
{
|
{
|
||||||
|
m_syntaxInfoUpdated = result.m_state;
|
||||||
|
if (m_syntaxInfoUpdated == SyntaxHighlighter::State::Done) {
|
||||||
|
emit highlightingFinished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QTextBlock docBlock = m_document->findBlock(result.m_blockNumber);
|
QTextBlock docBlock = m_document->findBlock(result.m_blockNumber);
|
||||||
if (!docBlock.isValid())
|
if (!docBlock.isValid())
|
||||||
return;
|
return;
|
||||||
@@ -145,6 +170,7 @@ void BaseSyntaxHighlighterRunner::applyFormatRanges(const SyntaxHighlighter::Res
|
|||||||
|
|
||||||
void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved, int charsAdded)
|
void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved, int charsAdded)
|
||||||
{
|
{
|
||||||
|
m_syntaxInfoUpdated = SyntaxHighlighter::State::InProgress;
|
||||||
QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> blocksPreedit;
|
QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> blocksPreedit;
|
||||||
QTextBlock firstBlock = m_document->findBlock(from);
|
QTextBlock firstBlock = m_document->findBlock(from);
|
||||||
QTextBlock endBlock = m_document->findBlock(from + charsAdded);
|
QTextBlock endBlock = m_document->findBlock(from + charsAdded);
|
||||||
@@ -245,6 +271,7 @@ ThreadedSyntaxHighlighterRunner::ThreadedSyntaxHighlighterRunner(SyntaxHighLight
|
|||||||
for (const SyntaxHighlighter::Result &res : result)
|
for (const SyntaxHighlighter::Result &res : result)
|
||||||
applyFormatRanges(res);
|
applyFormatRanges(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
cloneDocumentData(0, 0, document->characterCount());
|
cloneDocumentData(0, 0, document->characterCount());
|
||||||
connect(document,
|
connect(document,
|
||||||
&QTextDocument::contentsChange,
|
&QTextDocument::contentsChange,
|
||||||
|
@@ -50,6 +50,10 @@ public:
|
|||||||
QTextDocument *document() const { return m_document; }
|
QTextDocument *document() const { return m_document; }
|
||||||
SyntaxHighLighterCreator creator() const { return m_creator; }
|
SyntaxHighLighterCreator creator() const { return m_creator; }
|
||||||
|
|
||||||
|
bool syntaxInfoUpdated() const { return m_syntaxInfoUpdated == SyntaxHighlighter::State::Done; }
|
||||||
|
signals:
|
||||||
|
void highlightingFinished();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
||||||
QPointer<QTextDocument> m_document = nullptr;
|
QPointer<QTextDocument> m_document = nullptr;
|
||||||
@@ -60,6 +64,8 @@ protected:
|
|||||||
const QString textAdded,
|
const QString textAdded,
|
||||||
const QMap<int, BlockPreeditData> &blocksPreedit);
|
const QMap<int, BlockPreeditData> &blocksPreedit);
|
||||||
|
|
||||||
|
SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SyntaxHighLighterCreator m_creator;
|
SyntaxHighLighterCreator m_creator;
|
||||||
QString m_definitionName;
|
QString m_definitionName;
|
||||||
|
Reference in New Issue
Block a user