Commit 6f7aa1f9 authored by Marco Benelli's avatar Marco Benelli

QmlJS: user defined style in reformatting file

The size of tabs and indentation used to be ignored when reformatting
a file.

Task-number: QTCREATORBUG-12849
Change-Id: I0b522b526a199c6397b78b5e193159ec52fc941a
Reviewed-by: Thomas Hartmann's avatarThomas Hartmann <thomas.hartmann@qt.io>
parent adae0c3a
......@@ -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());
}
......@@ -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);
}
......@@ -54,6 +54,7 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <texteditor/snippets/snippetprovider.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/tabsettings.h>
#include <utils/qtcassert.h>
#include <utils/json.h>
......@@ -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<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget())
: nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment