forked from qt-creator/qt-creator
QmlJS.QtQuickToolBar: Using proper indenter
Task-number: QTCREATORBUG-11334 Change-Id: I65b3f95bdc5a57971854fb8bce620a275f646ff5 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
#include <qmljs/qmljsdocument.h>
|
#include <qmljs/qmljsdocument.h>
|
||||||
#include <qmljs/qmljspropertyreader.h>
|
#include <qmljs/qmljspropertyreader.h>
|
||||||
#include <qmljs/qmljsrewriter.h>
|
#include <qmljs/qmljsrewriter.h>
|
||||||
#include <qmljs/qmljsindenter.h>
|
#include <qmljstools/qmljsindenter.h>
|
||||||
#include <qmljs/qmljscontext.h>
|
#include <qmljs/qmljscontext.h>
|
||||||
#include <qmljs/qmljsbind.h>
|
#include <qmljs/qmljsbind.h>
|
||||||
#include <qmljs/qmljsscopebuilder.h>
|
#include <qmljs/qmljsscopebuilder.h>
|
||||||
@@ -327,24 +327,7 @@ void QuickToolBar::setProperty(const QString &propertyName, const QVariant &valu
|
|||||||
m_editor->convertPosition(changeSetPos, &line, &column); //get line
|
m_editor->convertPosition(changeSetPos, &line, &column); //get line
|
||||||
m_editor->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line
|
m_editor->convertPosition(changeSetPos + changeSetLength, &endLine, &column); //get line
|
||||||
|
|
||||||
if (line > 0) {
|
indentLines(line, endLine);
|
||||||
TextEditor::TabSettings ts = m_editor->baseTextDocument()->tabSettings();
|
|
||||||
QmlJSIndenter indenter;
|
|
||||||
indenter.setTabSize(ts.m_tabSize);
|
|
||||||
indenter.setIndentSize(ts.m_indentSize);
|
|
||||||
|
|
||||||
for (int i=line;i<=endLine;i++) {
|
|
||||||
QTextBlock start = m_editor->baseTextDocument()->document()->findBlockByNumber(i);
|
|
||||||
QTextBlock end = m_editor->baseTextDocument()->document()->findBlockByNumber(i);
|
|
||||||
|
|
||||||
if (end.isValid()) {
|
|
||||||
const int indent = indenter.indentForBottomLine(m_editor->baseTextDocument()
|
|
||||||
->document()->begin(),
|
|
||||||
end.next(), QChar::Null);
|
|
||||||
ts.indentLine(start, indent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tc.endEditBlock();
|
tc.endEditBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -439,6 +422,21 @@ void QuickToolBar::onEnabledChanged(bool b)
|
|||||||
settings.set();
|
settings.set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QuickToolBar::indentLines(int startLine, int endLine)
|
||||||
|
{
|
||||||
|
if (startLine > 0) {
|
||||||
|
TextEditor::TabSettings tabSettings = m_editor->baseTextDocument()->tabSettings();
|
||||||
|
for (int i = startLine; i <= endLine; i++) {
|
||||||
|
QTextBlock start = m_editor->editorWidget()->document()->findBlockByNumber(i);
|
||||||
|
|
||||||
|
if (start.isValid()) {
|
||||||
|
QmlJSEditor::Internal::Indenter indenterMy;
|
||||||
|
indenterMy.indentBlock(m_editor->editorWidget()->document(), start, QChar::Null, tabSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ContextPaneWidget* QuickToolBar::contextWidget()
|
ContextPaneWidget* QuickToolBar::contextWidget()
|
||||||
{
|
{
|
||||||
if (m_widget.isNull()) { //lazily recreate widget
|
if (m_widget.isNull()) { //lazily recreate widget
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ public slots:
|
|||||||
void onEnabledChanged(bool);
|
void onEnabledChanged(bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void indentLines(int startLine, int endLine);
|
||||||
|
|
||||||
QmlEditorWidgets::ContextPaneWidget* contextWidget();
|
QmlEditorWidgets::ContextPaneWidget* contextWidget();
|
||||||
QPointer<QmlEditorWidgets::ContextPaneWidget> m_widget;
|
QPointer<QmlEditorWidgets::ContextPaneWidget> m_widget;
|
||||||
QmlJS::Document::Ptr m_doc;
|
QmlJS::Document::Ptr m_doc;
|
||||||
|
|||||||
Reference in New Issue
Block a user