forked from qt-creator/qt-creator
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 <thomas.hartmann@qt.io>
This commit is contained in:
@@ -102,6 +102,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setIndentSize(int size) { _formatter.setIndentSize(size); }
|
||||||
|
void setTabSize(int size) { _formatter.setTabSize(size); }
|
||||||
|
|
||||||
QString operator()(Node *node)
|
QString operator()(Node *node)
|
||||||
{
|
{
|
||||||
Q_ASSERT(node == _doc->ast()); // comment handling fails otherwise
|
Q_ASSERT(node == _doc->ast()); // comment handling fails otherwise
|
||||||
@@ -1309,3 +1312,11 @@ QString QmlJS::reformat(const Document::Ptr &doc)
|
|||||||
Rewriter rewriter(doc);
|
Rewriter rewriter(doc);
|
||||||
return rewriter(doc->ast());
|
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 {
|
namespace QmlJS {
|
||||||
QMLJS_EXPORT QString reformat(const Document::Ptr &doc);
|
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 <projectexplorer/projectexplorerconstants.h>
|
||||||
#include <texteditor/snippets/snippetprovider.h>
|
#include <texteditor/snippets/snippetprovider.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
#include <texteditor/tabsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/json.h>
|
#include <utils/json.h>
|
||||||
|
|
||||||
@@ -258,8 +259,10 @@ void QmlJSEditorPlugin::reformatFile()
|
|||||||
|
|
||||||
if (!document->isParsedCorrectly())
|
if (!document->isParsedCorrectly())
|
||||||
return;
|
return;
|
||||||
|
TextEditor::TabSettings tabSettings = m_currentDocument->tabSettings();
|
||||||
const QString &newText = QmlJS::reformat(document);
|
const QString &newText = QmlJS::reformat(document,
|
||||||
|
tabSettings.m_indentSize,
|
||||||
|
tabSettings.m_tabSize);
|
||||||
QmlJSEditorWidget *widget = EditorManager::currentEditor()
|
QmlJSEditorWidget *widget = EditorManager::currentEditor()
|
||||||
? qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget())
|
? qobject_cast<QmlJSEditorWidget*>(EditorManager::currentEditor()->widget())
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
Reference in New Issue
Block a user