« get me outta code hell

addChild(child, afterIndex) - tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-07-05 09:56:37 -0300
committerFlorrie <towerofnix@gmail.com>2018-07-05 09:56:37 -0300
commit40431bcfd46c457a1cf271b5eae53a35aa1d0b6b (patch)
treeea358b43927b8382a2561126b720c758bae550af
parentde1c92141d2d4859cf869ec90e50e8eb0e5e8568 (diff)
addChild(child, afterIndex)
-rw-r--r--ui/DisplayElement.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/ui/DisplayElement.js b/ui/DisplayElement.js
index ca50672..1ba9852 100644
--- a/ui/DisplayElement.js
+++ b/ui/DisplayElement.js
@@ -77,7 +77,7 @@ module.exports = class DisplayElement extends EventEmitter {
     }
   }
 
-  addChild(child) {
+  addChild(child, afterIndex = this.children.length) {
     // TODO Don't let a direct ancestor of this be added as a child. Don't
     // let itself be one of its childs either!
 
@@ -87,7 +87,7 @@ module.exports = class DisplayElement extends EventEmitter {
     }
 
     child.parent = this
-    this.children.push(child)
+    this.children.splice(afterIndex, 0, child)
     child.fixLayout()
   }