« 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
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
parent04a9e6f780bb05d855507d9092170d873e18e229 (diff)
fix long-ignored crash interacting with empty form
-rw-r--r--package-lock.json2
-rw-r--r--package.json2
-rw-r--r--ui/form/Form.js21
3 files changed, 18 insertions, 7 deletions
diff --git a/package-lock.json b/package-lock.json
index 614b011..cb7226e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "tui-lib",
-  "version": "0.1.1",
+  "version": "0.2.2",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/package.json b/package.json
index b2d3cb2..a1d575d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "tui-lib",
-  "version": "0.2.1",
+  "version": "0.2.2",
   "description": "terminal ui library",
   "main": "index.js",
   "repository": "https://notabug.org/towerofnix/tui-lib.git",
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()
     }