This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 61b5f86  addItem to TreeList should modify the data
61b5f86 is described below

commit 61b5f863f4b49799e06730d741735259d91e55b2
Author: Harbs <[email protected]>
AuthorDate: Thu Nov 28 15:26:09 2019 +0200

    addItem to TreeList should modify the data
---
 .../org/apache/royale/collections/FlattenedList.as | 39 ++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git 
a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
 
b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
index 8edd35d..13766e5 100644
--- 
a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
+++ 
b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
@@ -132,7 +132,7 @@ package org.apache.royale.collections
                                addChildren(node, arr);
                                var i:int = getItemIndex(node);
                                while (arr.length) {
-                                       addItemAt(arr.shift(), ++i);
+                                       super.addItemAt(arr.shift(), ++i);
                                }
                        }
                        updateNode(node);
@@ -164,7 +164,7 @@ package org.apache.royale.collections
                                addChildren(node, arr);
                                i = getItemIndex(node) + 1;
                                while (arr.length) {
-                                       removeItemAt(i);
+                                       super.removeItemAt(i);
                                        arr.shift();
                                }
                        }
@@ -212,6 +212,41 @@ package org.apache.royale.collections
                        
                        return -1;
                }
+               /**
+                * When adding items from outside FlattenedList, it needs to be 
added to the data structure as well.
+                */
+               override public function addItemAt(item:Object, index:int):void{
+                       super.addItemAt(item,index);
+                       var topLevel:Array = hdata.source.children;
+                       var len:int = topLevel.length;
+                       if (index < len && index > 0)
+                               topLevel.splice(index, 0, item);
+
+                       else if (index == len)
+                               topLevel.push(item);
+
+                       else if (index == 0)
+                               topLevel.unshift(item);
+               }
+
+               override public function removeItemAt(index:int):Object{
+                       var topLevel:Array = hdata.source.children;
+                       var upperIdx:int = topLevel.length - 1;
+                       if (index > 0 && index < upperIdx)
+                       {
+                               topLevel.splice(index, 1);
+                       }
+                       else if (index == upperIdx)
+                       {
+                               topLevel.pop();
+                       }
+                       else if (index == 0)
+                       {
+                               topLevel.shift();
+                       }
+                       
+                       return super.removeItemAt(index);
+               }
 
        }
 }

Reply via email to