diff --git a/src/libs/qmljs/qmljsreformatter.cpp b/src/libs/qmljs/qmljsreformatter.cpp index e9d139dd2ba..a3d8481d582 100644 --- a/src/libs/qmljs/qmljsreformatter.cpp +++ b/src/libs/qmljs/qmljsreformatter.cpp @@ -102,6 +102,9 @@ public: { } + void setIndentSize(int size) { _formatter.setIndentSize(size); } + void setTabSize(int size) { _formatter.setTabSize(size); } + QString operator()(Node *node) { Q_ASSERT(node == _doc->ast()); // comment handling fails otherwise @@ -1309,3 +1312,11 @@ QString QmlJS::reformat(const Document::Ptr &doc) Rewriter rewriter(doc); return rewriter(doc->ast()); } + +QString QmlJS::reformat(const Document::Ptr &doc, int indentSize, int tabSize) +{ + Rewriter rewriter(doc); + rewriter.setIndentSize(indentSize); + rewriter.setTabSize(tabSize); + return rewriter(doc->ast()); +} diff --git a/src/libs/qmljs/qmljsreformatter.h b/src/libs/qmljs/qmljsreformatter.h index 18d5c6fd85c..7465a1a17f0 100644 --- a/src/libs/qmljs/qmljsreformatter.h +++ b/src/libs/qmljs/qmljsreformatter.h @@ -31,4 +31,5 @@ namespace QmlJS { QMLJS_EXPORT QString reformat(const Document::Ptr &doc); +QMLJS_EXPORT QString reformat(const Document::Ptr &doc, int indentSize, int tabSize); } diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 3b9a50866f5..34f2fa818a1 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -258,8 +259,10 @@ void QmlJSEditorPlugin::reformatFile() if (!document->isParsedCorrectly()) return; - - const QString &newText = QmlJS::reformat(document); + TextEditor::TabSettings tabSettings = m_currentDocument->tabSettings(); + const QString &newText = QmlJS::reformat(document, + tabSettings.m_indentSize, + tabSettings.m_tabSize); QmlJSEditorWidget *widget = EditorManager::currentEditor() ? qobject_cast(EditorManager::currentEditor()->widget()) : nullptr;