forked from qt-creator/qt-creator
TextEditor: Fix jump to search result
Change-Id: Ie570936b0b96290d95999b8b501c12610ebfc9a8 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3502,18 +3502,19 @@ 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] {
|
||||||
if (d->m_displaySettings.m_autoFoldFirstComment)
|
auto callFold = [this] {
|
||||||
d->foldLicenseHeader();
|
if (d->m_displaySettings.m_autoFoldFirstComment)
|
||||||
|
d->foldLicenseHeader();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!singleShotAfterHighlightingDone(callFold))
|
||||||
|
callFold();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (state.isEmpty()) {
|
if (state.isEmpty()) {
|
||||||
@@ -3536,21 +3537,25 @@ void TextEditorWidget::restoreState(const QByteArray &state)
|
|||||||
if (version >= 1) {
|
if (version >= 1) {
|
||||||
QList<int> collapsedBlocks;
|
QList<int> collapsedBlocks;
|
||||||
stream >> collapsedBlocks;
|
stream >> collapsedBlocks;
|
||||||
QTextDocument *doc = document();
|
auto foldingRestore = [this, collapsedBlocks] {
|
||||||
bool layoutChanged = false;
|
QTextDocument *doc = document();
|
||||||
for (const int blockNumber : std::as_const(collapsedBlocks)) {
|
bool layoutChanged = false;
|
||||||
QTextBlock block = doc->findBlockByNumber(qMax(0, blockNumber));
|
for (const int blockNumber : std::as_const(collapsedBlocks)) {
|
||||||
if (block.isValid()) {
|
QTextBlock block = doc->findBlockByNumber(qMax(0, blockNumber));
|
||||||
TextDocumentLayout::doFoldOrUnfold(block, false);
|
if (block.isValid()) {
|
||||||
layoutChanged = true;
|
TextDocumentLayout::doFoldOrUnfold(block, false);
|
||||||
|
layoutChanged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
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();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user