From 3fcfbcf8335cd25870359a81eae6366880f4e0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 8 May 2018 12:02:21 +0200 Subject: [PATCH] [poincare] Fix DynamicLayoutHierarchy::mergeChildrenAtIndex Change-Id: I579d3daf9791e06474a66071b2b2be0908a8cf02 --- poincare/src/layout/dynamic_layout_hierarchy.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/poincare/src/layout/dynamic_layout_hierarchy.cpp b/poincare/src/layout/dynamic_layout_hierarchy.cpp index 848bd3fa3..39f48e64f 100644 --- a/poincare/src/layout/dynamic_layout_hierarchy.cpp +++ b/poincare/src/layout/dynamic_layout_hierarchy.cpp @@ -37,11 +37,15 @@ DynamicLayoutHierarchy::~DynamicLayoutHierarchy() { } void DynamicLayoutHierarchy::mergeChildrenAtIndex(DynamicLayoutHierarchy * eL, int index, bool removeEmptyChildren) { + int indexForInsertion = index; int indexOfEL = indexOfChild(eL); if (indexOfEL >= 0) { removeChildAtIndex(indexOfEL, false); + if (indexOfEL < index) { + indexForInsertion--; + } } - addChildrenAtIndex(eL->children(), eL->numberOfChildren(), index, removeEmptyChildren); + addChildrenAtIndex(eL->children(), eL->numberOfChildren(), indexForInsertion, removeEmptyChildren); eL->detachChildren(); delete eL; }