Fix long freeze when reloading files

The semantic highlighting and all the extra selections create
many cursors, this does cost time in setText().
Solution: remove all extra selections on reload.

Reviewed-by: Oswald Buddenhagen
Task-number: QTCREATORBUG-1720
This commit is contained in:
mae
2010-06-24 20:13:13 +02:00
parent 5554894724
commit 6f67360efe
2 changed files with 22 additions and 8 deletions

View File

@@ -1598,15 +1598,29 @@ void BaseTextEditor::setBaseTextDocument(BaseTextDocument *doc)
}
}
// called before reload
void BaseTextEditor::memorizeCursorPosition()
void BaseTextEditor::documentAboutToBeReloaded()
{
//memorize cursor position
d->m_tempState = saveState();
// remove extra selections (loads of QTextCursor objects)
for (int i = 0; i < NExtraSelectionKinds; ++i)
d->m_extraSelections[i].clear();
QPlainTextEdit::setExtraSelections(QList<QTextEdit::ExtraSelection>());
// clear all overlays
if (d->m_overlay)
d->m_overlay->clear();
if (d->m_snippetOverlay)
d->m_snippetOverlay->clear();
if (d->m_searchResultOverlay)
d->m_searchResultOverlay->clear();
}
// called after reload
void BaseTextEditor::restoreCursorPosition()
void BaseTextEditor::documentReloaded()
{
// restore cursor position
restoreState(d->m_tempState);
}
@@ -1914,8 +1928,8 @@ void BaseTextEditorPrivate::setupDocumentSignals(BaseTextDocument *document)
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
QObject::connect(document, SIGNAL(changed()), q, SIGNAL(changed()));
QObject::connect(document, SIGNAL(titleChanged(QString)), q, SLOT(setDisplayName(const QString &)));
QObject::connect(document, SIGNAL(aboutToReload()), q, SLOT(memorizeCursorPosition()));
QObject::connect(document, SIGNAL(reloaded()), q, SLOT(restoreCursorPosition()));
QObject::connect(document, SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded()));
QObject::connect(document, SIGNAL(reloaded()), q, SLOT(documentReloaded()));
q->slotUpdateExtraAreaWidth();
}