diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp index af3cdb5085a..60ee35a922d 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp @@ -27,6 +27,7 @@ #include "texteditorwidget.h" +#include #include #include #include @@ -160,8 +161,12 @@ void TextEditorView::selectedNodesChanged(const QList &/*selectedNode m_widget->jumpTextCursorToSelectedModelNode(); } -void TextEditorView::customNotification(const AbstractView * /*view*/, const QString &/*identifier*/, const QList &/*nodeList*/, const QList &/*data*/) +void TextEditorView::customNotification(const AbstractView * /*view*/, const QString &identifier, const QList &/*nodeList*/, const QList &/*data*/) { + if (identifier == StartRewriterApply) + m_widget->setBlockCurserSelectionSyncronisation(true); + else if (identifier == EndRewriterApply) + m_widget->setBlockCurserSelectionSyncronisation(false); } void TextEditorView::documentMessagesChanged(const QList &errors, const QList &) diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp index 461ff57753d..cfbea84800f 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp @@ -36,6 +36,9 @@ #include +#include +#include + #include #include @@ -73,7 +76,12 @@ void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor) QmlDesignerPlugin::instance()->emitCurrentTextEditorChanged(textEditor); connect(textEditor->editorWidget(), &QPlainTextEdit::cursorPositionChanged, - &m_updateSelectionTimer, static_cast(&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 overrideKeys = { Qt::Key_Delete, Qt::Key_Backspace, Qt::Key_Left, diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h index 46a65cdd24b..267f93a1837 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h @@ -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 m_textEditorView; QTimer m_updateSelectionTimer; TextEditorStatusBar *m_statusBar; + bool m_blockCurserSelectionSyncronisation = false; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/include/customnotifications.h b/src/plugins/qmldesigner/designercore/include/customnotifications.h index 58cc433e7fd..44c68e73a19 100644 --- a/src/plugins/qmldesigner/designercore/include/customnotifications.h +++ b/src/plugins/qmldesigner/designercore/include/customnotifications.h @@ -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__"); + } diff --git a/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp b/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp index 99cc83fe422..000d6b549d4 100644 --- a/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp @@ -28,6 +28,8 @@ #include "qmltextgenerator.h" #include "rewriteactioncompressor.h" +#include + #include #include #include @@ -217,6 +219,8 @@ void ModelToTextMerger::applyChanges() if (m_rewriteActions.isEmpty()) return; + m_rewriterView->emitCustomNotification(StartRewriterApply); + Document::MutablePtr tmpDocument(Document::create(QStringLiteral(""), 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 &dirtyAreas) const