From 6e6cebedfbb0376514a05625e3c2c3cc29faa180 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen <erik.verbruggen@nokia.com> Date: Thu, 4 Mar 2010 17:41:27 +0100 Subject: [PATCH] Fixed incorrect indentation when reparenting nodes. --- .../model/modelnodepositionrecalculator.cpp | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/plugins/qmldesigner/core/model/modelnodepositionrecalculator.cpp b/src/plugins/qmldesigner/core/model/modelnodepositionrecalculator.cpp index 172409b06a..ef95ace99a 100644 --- a/src/plugins/qmldesigner/core/model/modelnodepositionrecalculator.cpp +++ b/src/plugins/qmldesigner/core/model/modelnodepositionrecalculator.cpp @@ -55,24 +55,32 @@ void ModelNodePositionRecalculator::moved(const TextModifier::MoveInfo &moveInfo if (nodeLocation == ModelNodePositionStorage::INVALID_LOCATION) continue; + int newLocation = nodeLocation; if (from <= nodeLocation && moveInfo.objectEnd > nodeLocation) { if (to > from) if (length == (to - from)) - m_positionStore->setNodeOffset(node, nodeLocation + prefixLength - moveInfo.leadingCharsToRemove); + newLocation = nodeLocation + prefixLength - moveInfo.leadingCharsToRemove; else - m_positionStore->setNodeOffset(node, to - length + nodeLocation - from + prefixLength - moveInfo.leadingCharsToRemove - moveInfo.trailingCharsToRemove); + newLocation = to - length + nodeLocation - from + prefixLength - moveInfo.leadingCharsToRemove - moveInfo.trailingCharsToRemove; else - m_positionStore->setNodeOffset(node, to + nodeLocation - from + prefixLength); + newLocation = to + nodeLocation - from + prefixLength; } else if (from < nodeLocation && to > nodeLocation) { - m_positionStore->setNodeOffset(node, nodeLocation - length - moveInfo.leadingCharsToRemove - moveInfo.trailingCharsToRemove); + newLocation = nodeLocation - length - moveInfo.leadingCharsToRemove - moveInfo.trailingCharsToRemove; } else if (from > nodeLocation && to <= nodeLocation) { - m_positionStore->setNodeOffset(node, nodeLocation + length + prefixLength + suffixLength); + newLocation = nodeLocation + length + prefixLength + suffixLength; } else if (from < nodeLocation && to <= nodeLocation) { - m_positionStore->setNodeOffset(node, nodeLocation + prefixLength + suffixLength - moveInfo.leadingCharsToRemove - moveInfo.trailingCharsToRemove); + newLocation = nodeLocation + prefixLength + suffixLength - moveInfo.leadingCharsToRemove - moveInfo.trailingCharsToRemove; } + m_positionStore->setNodeOffset(node, newLocation); } - m_dirtyAreas.insert(to - prefixLength, length + prefixLength + suffixLength); + const int indentLength = length + prefixLength + suffixLength; + int indentOffset; + if (to - prefixLength <= from - moveInfo.leadingCharsToRemove) + indentOffset = to - prefixLength; + else + indentOffset = to - length - prefixLength - moveInfo.leadingCharsToRemove - moveInfo.trailingCharsToRemove; + m_dirtyAreas.insert(indentOffset, indentLength); } void ModelNodePositionRecalculator::replaced(int offset, int oldLength, int newLength) -- GitLab