forked from qt-creator/qt-creator
QmlJSEditor: Simplify usages highlighting
There is no need to fire a timer over and over again if semantic info is not up to date. Instead, update usages whenever cursor position changes and semantic info is up to date, and whenever semantic info is updated. Change-Id: If2d8fe2a0211b9d659bea5c747704380a64cc1ca Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -130,10 +130,8 @@ void QmlJSTextEditorWidget::ctor()
|
|||||||
m_updateUsesTimer = new QTimer(this);
|
m_updateUsesTimer = new QTimer(this);
|
||||||
m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL);
|
m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL);
|
||||||
m_updateUsesTimer->setSingleShot(true);
|
m_updateUsesTimer->setSingleShot(true);
|
||||||
connect(m_updateUsesTimer, SIGNAL(timeout()), this, SLOT(updateUsesNow()));
|
connect(m_updateUsesTimer, SIGNAL(timeout()), this, SLOT(updateUses()));
|
||||||
|
connect(this, SIGNAL(cursorPositionChanged()), m_updateUsesTimer, SLOT(start()));
|
||||||
connect(this, SIGNAL(textChanged()), this, SLOT(updateUses()));
|
|
||||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateUses()));
|
|
||||||
|
|
||||||
m_updateOutlineTimer = new QTimer(this);
|
m_updateOutlineTimer = new QTimer(this);
|
||||||
m_updateOutlineTimer->setInterval(UPDATE_OUTLINE_INTERVAL);
|
m_updateOutlineTimer->setInterval(UPDATE_OUTLINE_INTERVAL);
|
||||||
@@ -424,20 +422,8 @@ void QmlJSTextEditorWidget::showTextMarker()
|
|||||||
|
|
||||||
void QmlJSTextEditorWidget::updateUses()
|
void QmlJSTextEditorWidget::updateUses()
|
||||||
{
|
{
|
||||||
if (m_semanticHighlighter->startRevision() != editorRevision())
|
if (m_qmlJsEditorDocument->isSemanticInfoOutdated()) // will be updated when info is updated
|
||||||
m_semanticHighlighter->cancel();
|
|
||||||
m_updateUsesTimer->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void QmlJSTextEditorWidget::updateUsesNow()
|
|
||||||
{
|
|
||||||
if (m_qmlJsEditorDocument->isSemanticInfoOutdated()) {
|
|
||||||
updateUses();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
m_updateUsesTimer->stop();
|
|
||||||
|
|
||||||
QList<QTextEdit::ExtraSelection> selections;
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
foreach (const AST::SourceLocation &loc,
|
foreach (const AST::SourceLocation &loc,
|
||||||
@@ -886,6 +872,8 @@ void QmlJSTextEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateUses();
|
||||||
|
|
||||||
// update outline
|
// update outline
|
||||||
m_updateOutlineTimer->start();
|
m_updateOutlineTimer->start();
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ private slots:
|
|||||||
void showTextMarker();
|
void showTextMarker();
|
||||||
|
|
||||||
void updateUses();
|
void updateUses();
|
||||||
void updateUsesNow();
|
|
||||||
|
|
||||||
void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo);
|
void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo);
|
||||||
void onCursorPositionChanged();
|
void onCursorPositionChanged();
|
||||||
@@ -174,7 +173,7 @@ private:
|
|||||||
bool hideContextPane();
|
bool hideContextPane();
|
||||||
|
|
||||||
Internal::QmlJSEditorDocument *m_qmlJsEditorDocument;
|
Internal::QmlJSEditorDocument *m_qmlJsEditorDocument;
|
||||||
QTimer *m_updateUsesTimer;
|
QTimer *m_updateUsesTimer; // to wait for multiple text cursor position changes
|
||||||
QTimer *m_updateOutlineTimer;
|
QTimer *m_updateOutlineTimer;
|
||||||
QTimer *m_updateOutlineIndexTimer;
|
QTimer *m_updateOutlineIndexTimer;
|
||||||
QTimer *m_cursorPositionTimer;
|
QTimer *m_cursorPositionTimer;
|
||||||
|
|||||||
Reference in New Issue
Block a user