SyntaxHighlighter: Add rerun if highlighting was interrupted

Added mechanism of highlighting restart when the previous
highlighting was interrupted.

Change-Id: Ic44c06442fd9f0002fed760472d5d39903e7ef50
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Artem Sokolovskii
2024-02-12 11:10:04 +01:00
parent e31a06a0f4
commit bb87db09e2
4 changed files with 136 additions and 29 deletions

View File

@@ -206,8 +206,11 @@ void SyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int ch
vecRes << resStart;
while (block.isValid() && (block.position() < endPosition || forceHighlightOfNextBlock)) {
if (QThread::currentThread()->isInterruptionRequested())
break;
if (QThread::currentThread()->isInterruptionRequested() || q->isInterrupted()) {
inReformatBlocks = false;
emit q->resultsReady({});
return;
}
const int stateBeforeHighlight = block.userState();
@@ -767,9 +770,7 @@ void SyntaxHighlighter::setExtraFormats(const QTextBlock &block,
res.m_formatRanges = block.layout()->formats();
res.fillByBlock(block);
res.m_state = SyntaxHighlighter::State::Extras;
SyntaxHighlighter::Result resDone;
resDone.m_state = SyntaxHighlighter::State::Done;
emit resultsReady({res, resDone});
emit resultsReady({std::move(res)});
document()->markContentsDirty(block.position(), blockLength - 1);
d->inReformatBlocks = wasInReformatBlocks;
@@ -796,9 +797,7 @@ void SyntaxHighlighter::clearExtraFormats(const QTextBlock &block)
res.m_formatRanges = block.layout()->formats();
res.fillByBlock(block);
res.m_state = SyntaxHighlighter::State::Extras;
SyntaxHighlighter::Result resDone;
resDone.m_state = SyntaxHighlighter::State::Done;
emit resultsReady({res, resDone});
emit resultsReady({std::move(res)});
document()->markContentsDirty(block.position(), blockLength - 1);
d->inReformatBlocks = wasInReformatBlocks;