« get me outta code hell

fix long-ignored crash interacting with empty form - 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:
authorFlorrie <towerofnix@gmail.com>2020-05-03 14:57:01 -0300
committerFlorrie <towerofnix@gmail.com>2020-05-03 14:57:01 -0300
commitbe0919ac31b1048248941ed0c290c03824732297 (patch)
tree1d81c019bc60529e753132287dec3c60bd8e84b9 /ui
parent04a9e6f780bb05d855507d9092170d873e18e229 (diff)
fix long-ignored crash interacting with empty form
Diffstat (limited to 'ui')
-rw-r--r--ui/form/Form.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/ui/form/Form.js b/ui/form/Form.js
index 451baa4..f61c7b6 100644
--- a/ui/form/Form.js
+++ b/ui/form/Form.js
@@ -81,8 +81,10 @@ module.exports = class Form extends FocusElement {
   }
 
   previousInput() {
-    // TODO: Forms currently assume there is at least one selectable input,
-    // but this isn't necessarily always the case.
+    if (this.inputs.length === 0) {
+      return
+    }
+
     do {
       this.curIndex = (this.curIndex - 1)
       if (this.curIndex < 0) {
@@ -94,7 +96,10 @@ module.exports = class Form extends FocusElement {
   }
 
   nextInput() {
-    // TODO: See previousInput
+    if (this.inputs.length === 0) {
+      return
+    }
+
     do {
       this.curIndex = (this.curIndex + 1) % this.inputs.length
     } while (!this.inputs[this.curIndex].selectable)
@@ -103,9 +108,12 @@ module.exports = class Form extends FocusElement {
   }
 
   firstInput(selectForm = true) {
+    if (this.inputs.length === 0) {
+      return
+    }
+
     this.curIndex = 0
 
-    // TODO: See previousInput
     if (!this.inputs[this.curIndex].selectable) {
       this.nextInput()
     }
@@ -118,9 +126,12 @@ module.exports = class Form extends FocusElement {
   }
 
   lastInput(selectForm = true) {
+    if (this.inputs.length === 0) {
+      return
+    }
+
     this.curIndex = this.inputs.length - 1
 
-    // TODO: See previousInput
     if (!this.inputs[this.curIndex].selectable) {
       this.previousInput()
     }