From 6f67360efeb01dc314c742df8489d63674b5308a Mon Sep 17 00:00:00 2001 From: mae <qt-info@nokia.com> Date: Thu, 24 Jun 2010 20:13:13 +0200 Subject: [PATCH] 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 --- src/plugins/texteditor/basetexteditor.cpp | 26 +++++++++++++++++------ src/plugins/texteditor/basetexteditor.h | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 249666b2ac7..a543d85d484 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -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(); } diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 60bf11d8296..1bab6597a77 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -304,8 +304,8 @@ protected: private slots: void editorContentsChange(int position, int charsRemoved, int charsAdded); - void memorizeCursorPosition(); - void restoreCursorPosition(); + void documentAboutToBeReloaded(); + void documentReloaded(); void highlightSearchResults(const QString &txt, Find::IFindSupport::FindFlags findFlags); void setFindScope(const QTextCursor &start, const QTextCursor &end, int); void currentEditorChanged(Core::IEditor *editor); -- GitLab