forked from qt-creator/qt-creator
QmlDesigner: Do not move cursor when reformating
When saving a .ui.qml file the complete file is reformated. Without this patch the cursor is moved to the bottom. The cursor is still moved, but they line is kept. Since we reformat the complete file this should be fine. Change-Id: Ia1ef003e2e6ca7497dcad7e0e8044ffb99c80ea3 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -143,19 +143,8 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
|
||||
//Save
|
||||
Core::ActionManager::registerAction(&m_saveAction, Core::Constants::SAVE, qmlDesignerMainContext);
|
||||
connect(&m_saveAction, &QAction::triggered, em, [em] {
|
||||
DesignerSettings settings = QmlDesignerPlugin::instance()->settings();
|
||||
/* Reformat document if we have a .ui.qml file */
|
||||
if (settings.value(DesignerSettingsKey::REFORMAT_UI_QML_FILES).toBool()
|
||||
&& em->currentDocument()->filePath().toString().endsWith(".ui.qml"))
|
||||
if (QmlJSEditor::QmlJSEditorDocument *document
|
||||
= qobject_cast<QmlJSEditor::QmlJSEditorDocument *>(em->currentDocument())) {
|
||||
const QString &newText = QmlJS::reformat(document->semanticInfo().document);
|
||||
QTextCursor tc(document->document());
|
||||
tc.movePosition(QTextCursor::Start);
|
||||
tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
||||
tc.insertText(newText);
|
||||
}
|
||||
em->saveDocument();
|
||||
QmlDesignerPlugin::instance()->viewManager().reformatFileUsingTextEditorView();
|
||||
em->saveDocument();
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user