#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Mon, 12 Dec 2016 23:27:57 +0100
changeset 3360 b7f7e48455dd
parent 3359 258a64461215
child 3361 4bd3866a0f40
#BUGFIX by cg class: UIPainterView changed: #replaceSelectionBy: preserve position in child list.
UIPainterView.st
--- a/UIPainterView.st	Tue Dec 06 12:52:05 2016 +0100
+++ b/UIPainterView.st	Mon Dec 12 23:27:57 2016 +0100
@@ -640,11 +640,12 @@
 replaceSelectionBy:aNewSpec
     "replace the selected widget by another one."
 
-    |oldSelection treeModel newView oldView container specs|
+    |oldSelection treeModel newView oldView container specs index|
 
     (self singleSelection notNil and:[treeView askForSelectionChangeAllowed]) ifFalse:[
         ^ self
     ].
+    
     treeModel    := treeView model.
     oldSelection := treeModel selectedNodes at:1 ifAbsent: nil.
     oldSelection isNil ifTrue:[^ self].
@@ -652,9 +653,10 @@
     oldView := oldSelection contents view.
 
     (oldSelection hasChildren and:[aNewSpec class supportsSubComponents]) ifTrue:[
-        specs := oldSelection children collect:[:each|
-            self fullSpecWithAbsolutePositionFor:(each contents view)
-        ].
+        specs := 
+            oldSelection children collect:[:each|
+                self fullSpecWithAbsolutePositionFor:(each contents view)
+            ].
     ].
 
     aNewSpec
@@ -665,14 +667,15 @@
                 at:#absOrigin put:(oldView originRelativeTo:self);
                 yourself).
 
+    index := oldSelection parent children identityIndexOf:oldSelection.
     container := self singleSelection container.
-
+    
     self withinTransaction:#replaceBy objects:(Array with:oldView) do:[
         self withSelectionHiddenDo:[
             newView := self 
                     pasteSpecifications:(Array with:aNewSpec)
                     into:container
-                    beforeIndex:1
+                    beforeIndex:index
                     keepLayout:true
                     keepPosition:true
                     at:#keep.
@@ -684,7 +687,7 @@
                             into:newView
                             keepLayout:(aNewSpec class canResizeSubComponents)
                             keepPosition:(aNewSpec class isLayoutContainer not)
-                            at:nil.
+                            at:index.
             ].
             self select:newView.
        ].