forked from qt-creator/qt-creator
		
	QmlDesigner: Block cursor updates by ModelToTextMerger
When we update the text we have to block the cursor selection synchronization. Change-Id: I79c3589482f2ca884bc4980b295b18b0a8e8ef2e Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
		@@ -27,6 +27,7 @@
 | 
			
		||||
 | 
			
		||||
#include "texteditorwidget.h"
 | 
			
		||||
 | 
			
		||||
#include <customnotifications.h>
 | 
			
		||||
#include <designmodecontext.h>
 | 
			
		||||
#include <designdocument.h>
 | 
			
		||||
#include <designersettings.h>
 | 
			
		||||
@@ -160,8 +161,12 @@ void TextEditorView::selectedNodesChanged(const QList<ModelNode> &/*selectedNode
 | 
			
		||||
    m_widget->jumpTextCursorToSelectedModelNode();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TextEditorView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/)
 | 
			
		||||
void TextEditorView::customNotification(const AbstractView * /*view*/, const QString &identifier, const QList<ModelNode> &/*nodeList*/, const QList<QVariant> &/*data*/)
 | 
			
		||||
{
 | 
			
		||||
    if (identifier == StartRewriterApply)
 | 
			
		||||
        m_widget->setBlockCurserSelectionSyncronisation(true);
 | 
			
		||||
    else if (identifier == EndRewriterApply)
 | 
			
		||||
        m_widget->setBlockCurserSelectionSyncronisation(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TextEditorView::documentMessagesChanged(const QList<DocumentMessage> &errors, const QList<DocumentMessage> &)
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,9 @@
 | 
			
		||||
 | 
			
		||||
#include <utils/fileutils.h>
 | 
			
		||||
 | 
			
		||||
#include <texteditor/textdocument.h>
 | 
			
		||||
#include <coreplugin/editormanager/editormanager.h>
 | 
			
		||||
 | 
			
		||||
#include <QEvent>
 | 
			
		||||
#include <QVBoxLayout>
 | 
			
		||||
 | 
			
		||||
@@ -73,7 +76,12 @@ void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor)
 | 
			
		||||
    QmlDesignerPlugin::instance()->emitCurrentTextEditorChanged(textEditor);
 | 
			
		||||
 | 
			
		||||
    connect(textEditor->editorWidget(), &QPlainTextEdit::cursorPositionChanged,
 | 
			
		||||
            &m_updateSelectionTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
 | 
			
		||||
            this, [this]() {
 | 
			
		||||
        /* Cursor position is changed by rewriter */
 | 
			
		||||
        if (!m_blockCurserSelectionSyncronisation)
 | 
			
		||||
            m_updateSelectionTimer.start();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    textEditor->editorWidget()->installEventFilter(this);
 | 
			
		||||
 | 
			
		||||
    if (oldEditor)
 | 
			
		||||
@@ -151,6 +159,11 @@ int TextEditorWidget::currentLine() const
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TextEditorWidget::setBlockCurserSelectionSyncronisation(bool b)
 | 
			
		||||
{
 | 
			
		||||
    m_blockCurserSelectionSyncronisation = b;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TextEditorWidget::eventFilter( QObject *, QEvent *event)
 | 
			
		||||
{
 | 
			
		||||
    static std::vector<int> overrideKeys = { Qt::Key_Delete, Qt::Key_Backspace, Qt::Key_Left,
 | 
			
		||||
 
 | 
			
		||||
@@ -58,6 +58,9 @@ public:
 | 
			
		||||
    void clearStatusBar();
 | 
			
		||||
 | 
			
		||||
    int currentLine() const;
 | 
			
		||||
 | 
			
		||||
    void setBlockCurserSelectionSyncronisation(bool b);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    bool eventFilter(QObject *object, QEvent *event) override;
 | 
			
		||||
 | 
			
		||||
@@ -68,6 +71,7 @@ private:
 | 
			
		||||
    QPointer<TextEditorView> m_textEditorView;
 | 
			
		||||
    QTimer m_updateSelectionTimer;
 | 
			
		||||
    TextEditorStatusBar *m_statusBar;
 | 
			
		||||
    bool m_blockCurserSelectionSyncronisation = false;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace QmlDesigner
 | 
			
		||||
 
 | 
			
		||||
@@ -31,5 +31,8 @@ namespace QmlDesigner {
 | 
			
		||||
 | 
			
		||||
const QString StartRewriterAmend = QStringLiteral("__start rewriter amend__");
 | 
			
		||||
const QString EndRewriterAmend = QStringLiteral("__end rewriter amend__");
 | 
			
		||||
const QString StartRewriterApply = QStringLiteral("start rewriter apply__");
 | 
			
		||||
const QString EndRewriterApply = QStringLiteral("__end rewriter apply__");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,8 @@
 | 
			
		||||
#include "qmltextgenerator.h"
 | 
			
		||||
#include "rewriteactioncompressor.h"
 | 
			
		||||
 | 
			
		||||
#include <customnotifications.h>
 | 
			
		||||
 | 
			
		||||
#include <rewriterview.h>
 | 
			
		||||
#include <abstractproperty.h>
 | 
			
		||||
#include <nodeproperty.h>
 | 
			
		||||
@@ -217,6 +219,8 @@ void ModelToTextMerger::applyChanges()
 | 
			
		||||
    if (m_rewriteActions.isEmpty())
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    m_rewriterView->emitCustomNotification(StartRewriterApply);
 | 
			
		||||
 | 
			
		||||
    Document::MutablePtr tmpDocument(Document::create(QStringLiteral("<ModelToTextMerger>"), Dialect::Qml));
 | 
			
		||||
    tmpDocument->setSource(m_rewriterView->textModifier()->text());
 | 
			
		||||
    if (!tmpDocument->parseQml()) {
 | 
			
		||||
@@ -297,6 +301,8 @@ void ModelToTextMerger::applyChanges()
 | 
			
		||||
        textModifier->commitGroup();
 | 
			
		||||
        textModifier->reactivateChangeSignals();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m_rewriterView->emitCustomNotification(EndRewriterApply);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModelToTextMerger::reindent(const QMap<int, int> &dirtyAreas) const
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user