summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Benelli <marco.benelli@qt.io>2017-06-22 14:59:53 +0200
committerMarco Benelli <marco.benelli@qt.io>2017-06-26 07:09:48 +0000
commit2123aebf652212d962a8bb57db4ea6ac20f7f840 (patch)
tree8bcd9e55b802258946a67db485c24dc102ca4893
parent29cf39bfd6424364eeefd07e65cc0c613848ced2 (diff)
downloadqt-creator-2123aebf652212d962a8bb57db4ea6ac20f7f840.tar.gz
QmlJS: keep track of cursor position in reformatting
Task-number: QTCREATORBUG-18416 Change-Id: I30c07e0bff1b3f3933ff0e4aee8f1f2c81bd5ef6 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmljseditor/qmljseditorplugin.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp
index 9a427a1b08..3faeda4512 100644
--- a/src/plugins/qmljseditor/qmljseditorplugin.cpp
+++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp
@@ -258,10 +258,16 @@ void QmlJSEditorPlugin::reformatFile()
return;
const QString &newText = QmlJS::reformat(document);
- QTextCursor tc(m_currentDocument->document());
- tc.movePosition(QTextCursor::Start);
- tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
- tc.insertText(newText);
+ QmlJSEditorWidget *widget = EditorManager::currentEditor()
+ ? qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget())
+ : nullptr;
+ if (widget) {
+ const int position = widget->position();
+ m_currentDocument->document()->setPlainText(newText);
+ widget->setCursorPosition(position);
+ } else {
+ m_currentDocument->document()->setPlainText(newText);
+ }
}
}