From c168ba9f11318455eebfeaeba9595783f7897c03 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 28 Feb 2017 18:05:59 +0100 Subject: [PATCH] QmlDesigner: Fix indenting in embedded text editor We have to set the duplicated editor as the current editor. We avoid triggering a document change by using a flag. Change-Id: I22410ec2f3b24695b397525811940c8303e0ed87 Reviewed-by: Tim Jenssen --- .../components/texteditor/texteditorwidget.cpp | 4 ++++ src/plugins/qmldesigner/qmldesignerplugin.cpp | 11 +++++++++++ src/plugins/qmldesigner/qmldesignerplugin.h | 1 + 3 files changed, 16 insertions(+) diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp index 944fc34753b..461ff57753d 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -68,6 +70,8 @@ void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor) layout()->addWidget(m_statusBar); setFocusProxy(textEditor->editorWidget()); + QmlDesignerPlugin::instance()->emitCurrentTextEditorChanged(textEditor); + connect(textEditor->editorWidget(), &QPlainTextEdit::cursorPositionChanged, &m_updateSelectionTimer, static_cast(&QTimer::start)); textEditor->editorWidget()->installEventFilter(this); diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index aa0a48db097..2c90414fa65 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -82,6 +82,7 @@ public: DesignerSettings settings; Internal::DesignModeContext *context = nullptr; + bool blockEditorChange = false; }; QmlDesignerPlugin *QmlDesignerPlugin::m_instance = nullptr; @@ -345,6 +346,9 @@ void QmlDesignerPlugin::hideDesigner() void QmlDesignerPlugin::changeEditor() { + if (d->blockEditorChange) + return; + if (d->documentManager.hasCurrentDesignDocument()) { deactivateAutoSynchronization(); d->mainWidget->saveSettings(); @@ -472,6 +476,13 @@ void QmlDesignerPlugin::switchToTextModeDeferred() }); } +void QmlDesignerPlugin::emitCurrentTextEditorChanged(Core::IEditor *editor) +{ + d->blockEditorChange = true; + Core::EditorManager::instance()->currentEditorChanged(editor); + d->blockEditorChange = false; +} + QmlDesignerPlugin *QmlDesignerPlugin::instance() { return m_instance; diff --git a/src/plugins/qmldesigner/qmldesignerplugin.h b/src/plugins/qmldesigner/qmldesignerplugin.h index ee98e56cb12..6e4b8fb2dec 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.h +++ b/src/plugins/qmldesigner/qmldesignerplugin.h @@ -83,6 +83,7 @@ public: Internal::DesignModeWidget *mainWidget() const; void switchToTextModeDeferred(); + void emitCurrentTextEditorChanged(Core::IEditor *editor); private: // functions void integrateIntoQtCreator(QWidget *modeWidget);