forked from qt-creator/qt-creator
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:
@@ -1598,15 +1598,29 @@ void BaseTextEditor::setBaseTextDocument(BaseTextDocument *doc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// called before reload
|
void BaseTextEditor::documentAboutToBeReloaded()
|
||||||
void BaseTextEditor::memorizeCursorPosition()
|
|
||||||
{
|
{
|
||||||
|
//memorize cursor position
|
||||||
d->m_tempState = saveState();
|
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::documentReloaded()
|
||||||
void BaseTextEditor::restoreCursorPosition()
|
|
||||||
{
|
{
|
||||||
|
// restore cursor position
|
||||||
restoreState(d->m_tempState);
|
restoreState(d->m_tempState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1914,8 +1928,8 @@ void BaseTextEditorPrivate::setupDocumentSignals(BaseTextDocument *document)
|
|||||||
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
|
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
|
||||||
QObject::connect(document, SIGNAL(changed()), q, SIGNAL(changed()));
|
QObject::connect(document, SIGNAL(changed()), q, SIGNAL(changed()));
|
||||||
QObject::connect(document, SIGNAL(titleChanged(QString)), q, SLOT(setDisplayName(const QString &)));
|
QObject::connect(document, SIGNAL(titleChanged(QString)), q, SLOT(setDisplayName(const QString &)));
|
||||||
QObject::connect(document, SIGNAL(aboutToReload()), q, SLOT(memorizeCursorPosition()));
|
QObject::connect(document, SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded()));
|
||||||
QObject::connect(document, SIGNAL(reloaded()), q, SLOT(restoreCursorPosition()));
|
QObject::connect(document, SIGNAL(reloaded()), q, SLOT(documentReloaded()));
|
||||||
q->slotUpdateExtraAreaWidth();
|
q->slotUpdateExtraAreaWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -304,8 +304,8 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void editorContentsChange(int position, int charsRemoved, int charsAdded);
|
void editorContentsChange(int position, int charsRemoved, int charsAdded);
|
||||||
void memorizeCursorPosition();
|
void documentAboutToBeReloaded();
|
||||||
void restoreCursorPosition();
|
void documentReloaded();
|
||||||
void highlightSearchResults(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
void highlightSearchResults(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
||||||
void setFindScope(const QTextCursor &start, const QTextCursor &end, int);
|
void setFindScope(const QTextCursor &start, const QTextCursor &end, int);
|
||||||
void currentEditorChanged(Core::IEditor *editor);
|
void currentEditorChanged(Core::IEditor *editor);
|
||||||
|
|||||||
Reference in New Issue
Block a user