QmlJS: Introduce a new indenter that works similarly to the new C++ one.

Done-with: Thomas Hartmann
This commit is contained in:
Christian Kamm
2010-07-07 11:45:18 +02:00
parent f6232260c2
commit 822de6c17a
10 changed files with 2587 additions and 12 deletions

View File

@@ -33,8 +33,8 @@
#include "qmljseditorplugin.h"
#include "qmljsmodelmanager.h"
#include "qmloutlinemodel.h"
#include "qmljseditorcodeformatter.h"
#include <qmljs/qmljsindenter.h>
#include <qmljs/qmljsbind.h>
#include <qmljs/qmljscheck.h>
#include <qmljs/qmljsdocument.h>
@@ -1276,15 +1276,25 @@ bool QmlJSTextEditor::isClosingBrace(const QList<Token> &tokens) const
return false;
}
static QmlJSEditor::QtStyleCodeFormatter setupCodeFormatter(const TextEditor::TabSettings &ts)
{
QmlJSEditor::QtStyleCodeFormatter codeFormatter;
codeFormatter.setIndentSize(ts.m_indentSize);
codeFormatter.setTabSize(ts.m_tabSize);
return codeFormatter;
}
void QmlJSTextEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
{
TextEditor::TabSettings ts = tabSettings();
QmlJSIndenter indenter;
indenter.setTabSize(ts.m_tabSize);
indenter.setIndentSize(ts.m_indentSize);
Q_UNUSED(doc)
Q_UNUSED(typedChar)
const int indent = indenter.indentForBottomLine(doc->begin(), block.next(), typedChar);
ts.indentLine(block, indent);
const TextEditor::TabSettings &ts = tabSettings();
QmlJSEditor::QtStyleCodeFormatter codeFormatter = setupCodeFormatter(ts);
codeFormatter.updateStateUntil(block);
const int depth = codeFormatter.indentFor(block);
ts.indentLine(block, depth);
}
TextEditor::BaseTextEditorEditable *QmlJSTextEditor::createEditableInterface()