Commit e3c941e2 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Thomas Hartmann

Fix indentation for reparenting

If nodes are reparented this can have side effecs on otherwise
untouched nodes. Before this patch untouched lines were not indented
and the indentation was messed up.

With this patch we indent the complete file if nodes get reparented.

Task-number: QTCREATORBUG-14014
Change-Id: Ib6e20bb9e31444e81428d25d39c431de2dc632de
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@theqtcompany.com>
parent d66e0631
......@@ -241,6 +241,8 @@ void ModelToTextMerger::applyChanges()
TextModifier *textModifier = m_rewriterView->textModifier();
try {
bool reindentAllFlag = false;
ModelNodePositionRecalculator positionRecalculator(m_rewriterView->positionStorage(), m_rewriterView->positionStorage()->modelNodes());
positionRecalculator.connectTo(textModifier);
......@@ -254,6 +256,13 @@ void ModelToTextMerger::applyChanges()
if (DebugRewriteActions)
qDebug() << "Next rewrite action:" << qPrintable(action->info());
if (action->asReparentNodeRewriteAction())
reindentAllFlag = true; /*If a node is reparented we indent all,
because reparenting can have side effects
regarding indentation
to otherwise untouched nodes.
*/
ModelNodePositionStorage *positionStore = m_rewriterView->positionStorage();
bool success = action->execute(refactoring, *positionStore);
......@@ -279,7 +288,10 @@ void ModelToTextMerger::applyChanges()
qDeleteAll(m_rewriteActions);
m_rewriteActions.clear();
reindent(positionRecalculator.dirtyAreas());
if (reindentAllFlag)
reindentAll();
else
reindent(positionRecalculator.dirtyAreas());
textModifier->commitGroup();
......@@ -306,6 +318,12 @@ void ModelToTextMerger::reindent(const QMap<int, int> &dirtyAreas) const
}
}
void ModelToTextMerger::reindentAll() const
{
TextModifier *textModifier = m_rewriterView->textModifier();
textModifier->indent(0, textModifier->text().length() - 1);
}
void ModelToTextMerger::schedule(RewriteAction *action)
{
Q_ASSERT(action);
......
......@@ -81,6 +81,7 @@ protected:
RewriterView *view();
void reindent(const QMap<int,int> &dirtyAreas) const;
void reindentAll() const;
void schedule(RewriteAction *action);
QList<RewriteAction *> scheduledRewriteActions() const
......
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