forked from qt-creator/qt-creator
QmlDesigner: Delay and compress text changes from editor
This is required to avoid blocking the ui while typing, because the model is updated. It will take 400ms without changes to the text until the model gets updated. Change-Id: Id428a52c15aeb8f0b802ee0448be8e6777a7402a Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include "rewritererror.h"
|
#include "rewritererror.h"
|
||||||
|
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
namespace QmlJS {
|
namespace QmlJS {
|
||||||
@@ -170,6 +171,7 @@ protected: // functions
|
|||||||
void setModificationGroupActive(bool active);
|
void setModificationGroupActive(bool active);
|
||||||
void applyModificationGroupChanges();
|
void applyModificationGroupChanges();
|
||||||
void applyChanges();
|
void applyChanges();
|
||||||
|
void amendQmlText();
|
||||||
|
|
||||||
private: //variables
|
private: //variables
|
||||||
TextModifier *m_textModifier = nullptr;
|
TextModifier *m_textModifier = nullptr;
|
||||||
@@ -185,7 +187,8 @@ private: //variables
|
|||||||
QList<RewriterError> m_warnings;
|
QList<RewriterError> m_warnings;
|
||||||
RewriterTransaction m_removeDefaultPropertyTransaction;
|
RewriterTransaction m_removeDefaultPropertyTransaction;
|
||||||
QString m_rewritingErrorMessage;
|
QString m_rewritingErrorMessage;
|
||||||
QString lastCorrectQmlSource;
|
QString m_lastCorrectQmlSource;
|
||||||
|
QTimer m_amendTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //QmlDesigner
|
} //QmlDesigner
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ RewriterView::RewriterView(DifferenceHandling differenceHandling, QObject *paren
|
|||||||
m_modelToTextMerger(new Internal::ModelToTextMerger(this)),
|
m_modelToTextMerger(new Internal::ModelToTextMerger(this)),
|
||||||
m_textToModelMerger(new Internal::TextToModelMerger(this))
|
m_textToModelMerger(new Internal::TextToModelMerger(this))
|
||||||
{
|
{
|
||||||
|
m_amendTimer.setSingleShot(true);
|
||||||
|
connect(&m_amendTimer, &QTimer::timeout, this, &RewriterView::amendQmlText);
|
||||||
}
|
}
|
||||||
|
|
||||||
RewriterView::~RewriterView()
|
RewriterView::~RewriterView()
|
||||||
@@ -79,7 +81,7 @@ void RewriterView::modelAttached(Model *model)
|
|||||||
ModelAmender differenceHandler(m_textToModelMerger.data());
|
ModelAmender differenceHandler(m_textToModelMerger.data());
|
||||||
const QString qmlSource = m_textModifier->text();
|
const QString qmlSource = m_textModifier->text();
|
||||||
if (m_textToModelMerger->load(qmlSource, differenceHandler))
|
if (m_textToModelMerger->load(qmlSource, differenceHandler))
|
||||||
lastCorrectQmlSource = qmlSource;
|
m_lastCorrectQmlSource = qmlSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RewriterView::modelAboutToBeDetached(Model * /*model*/)
|
void RewriterView::modelAboutToBeDetached(Model * /*model*/)
|
||||||
@@ -411,6 +413,18 @@ void RewriterView::applyChanges()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RewriterView::amendQmlText()
|
||||||
|
{
|
||||||
|
emitCustomNotification(StartRewriterAmend);
|
||||||
|
|
||||||
|
const QString newQmlText = m_textModifier->text();
|
||||||
|
|
||||||
|
ModelAmender differenceHandler(m_textToModelMerger.data());
|
||||||
|
if (m_textToModelMerger->load(newQmlText, differenceHandler))
|
||||||
|
m_lastCorrectQmlSource = newQmlText;
|
||||||
|
emitCustomNotification(EndRewriterAmend);
|
||||||
|
}
|
||||||
|
|
||||||
Internal::ModelNodePositionStorage *RewriterView::positionStorage() const
|
Internal::ModelNodePositionStorage *RewriterView::positionStorage() const
|
||||||
{
|
{
|
||||||
return m_positionStorage.data();
|
return m_positionStorage.data();
|
||||||
@@ -714,22 +728,17 @@ void RewriterView::qmlTextChanged()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (m_differenceHandling) {
|
switch (m_differenceHandling) {
|
||||||
case Validate: {
|
case Validate: {
|
||||||
ModelValidator differenceHandler(m_textToModelMerger.data());
|
ModelValidator differenceHandler(m_textToModelMerger.data());
|
||||||
if (m_textToModelMerger->load(newQmlText, differenceHandler))
|
if (m_textToModelMerger->load(newQmlText, differenceHandler))
|
||||||
lastCorrectQmlSource = newQmlText;
|
m_lastCorrectQmlSource = newQmlText;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Amend:
|
case Amend: {
|
||||||
default: {
|
m_amendTimer.start(400);
|
||||||
emitCustomNotification(StartRewriterAmend);
|
break;
|
||||||
ModelAmender differenceHandler(m_textToModelMerger.data());
|
}
|
||||||
if (m_textToModelMerger->load(newQmlText, differenceHandler))
|
|
||||||
lastCorrectQmlSource = newQmlText;
|
|
||||||
emitCustomNotification(EndRewriterAmend);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user