« get me outta code hell

tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/DisplayElement.js7
-rw-r--r--ui/form/Form.js2
2 files changed, 7 insertions, 2 deletions
diff --git a/ui/DisplayElement.js b/ui/DisplayElement.js
index 8a2aa71..9498487 100644
--- a/ui/DisplayElement.js
+++ b/ui/DisplayElement.js
@@ -87,7 +87,12 @@ module.exports = class DisplayElement extends EventEmitter {
     }
 
     child.parent = this
-    this.children.splice(afterIndex, 0, child)
+
+    if (afterIndex === this.children.length) {
+      this.children.push(child)
+    } else {
+      this.children.splice(afterIndex, 0, child)
+    }
 
     if (fixLayout) {
       child.fixLayout()
diff --git a/ui/form/Form.js b/ui/form/Form.js
index 7a82b31..3c59cf5 100644
--- a/ui/form/Form.js
+++ b/ui/form/Form.js
@@ -19,7 +19,7 @@ module.exports = class Form extends FocusElement {
     this.inputs.push(input)
 
     if (asChild) {
-      this.addChild(input, opts)
+      this.addChild(input, this.children.length, opts)
     }
   }