TextEditor: Fix jump to search result

Change-Id: Ie570936b0b96290d95999b8b501c12610ebfc9a8
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Artem Sokolovskii
2024-02-28 16:42:24 +01:00
parent a2be1e9692
commit 49ab0c4109

View File

@@ -3502,20 +3502,21 @@ bool TextEditorWidget::singleShotAfterHighlightingDone(std::function<void()> &&f
[f = std::move(f)] { f(); }, Qt::SingleShotConnection); [f = std::move(f)] { f(); }, Qt::SingleShotConnection);
return true; return true;
} }
return false; return false;
} }
void TextEditorWidget::restoreState(const QByteArray &state) void TextEditorWidget::restoreState(const QByteArray &state)
{ {
if (singleShotAfterHighlightingDone([this, state] { restoreState(state); }))
return;
const auto callFoldLicenseHeader = [this] { const auto callFoldLicenseHeader = [this] {
auto callFold = [this] {
if (d->m_displaySettings.m_autoFoldFirstComment) if (d->m_displaySettings.m_autoFoldFirstComment)
d->foldLicenseHeader(); d->foldLicenseHeader();
}; };
if (!singleShotAfterHighlightingDone(callFold))
callFold();
};
if (state.isEmpty()) { if (state.isEmpty()) {
callFoldLicenseHeader(); callFoldLicenseHeader();
return; return;
@@ -3536,6 +3537,7 @@ void TextEditorWidget::restoreState(const QByteArray &state)
if (version >= 1) { if (version >= 1) {
QList<int> collapsedBlocks; QList<int> collapsedBlocks;
stream >> collapsedBlocks; stream >> collapsedBlocks;
auto foldingRestore = [this, collapsedBlocks] {
QTextDocument *doc = document(); QTextDocument *doc = document();
bool layoutChanged = false; bool layoutChanged = false;
for (const int blockNumber : std::as_const(collapsedBlocks)) { for (const int blockNumber : std::as_const(collapsedBlocks)) {
@@ -3546,11 +3548,14 @@ void TextEditorWidget::restoreState(const QByteArray &state)
} }
} }
if (layoutChanged) { if (layoutChanged) {
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout()); auto documentLayout = qobject_cast<TextDocumentLayout *>(doc->documentLayout());
QTC_ASSERT(documentLayout, return ); QTC_ASSERT(documentLayout, return);
documentLayout->requestUpdate(); documentLayout->requestUpdate();
documentLayout->emitDocumentSizeChanged(); documentLayout->emitDocumentSizeChanged();
} }
};
if (!singleShotAfterHighlightingDone(foldingRestore))
foldingRestore();
} else { } else {
callFoldLicenseHeader(); callFoldLicenseHeader();
} }