« 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/form/Form.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/form/Form.js')
-rw-r--r--ui/form/Form.js29
1 files changed, 21 insertions, 8 deletions
diff --git a/ui/form/Form.js b/ui/form/Form.js
index 9274da4..cf94978 100644
--- a/ui/form/Form.js
+++ b/ui/form/Form.js
@@ -30,20 +30,33 @@ module.exports = class Form extends FocusElement {
       }
 
       if (telc.isTab(keyBuf)) {
-        this.curIndex = (this.curIndex + 1) % this.inputs.length
+        this.nextInput()
       } else {
-        this.curIndex = (this.curIndex - 1)
-        if (this.curIndex < 0) {
-          this.curIndex = (this.inputs.length - 1)
-        }
+        this.previousInput()
       }
 
-      const nextInput = this.inputs[this.curIndex]
-      this.root.select(nextInput)
-
       return false
     }
   }
+
+  updateSelectedElement() {
+    this.root.select(this.inputs[this.curIndex])
+  }
+
+  previousInput() {
+    this.curIndex = (this.curIndex - 1)
+    if (this.curIndex < 0) {
+      this.curIndex = (this.inputs.length - 1)
+    }
+
+    this.updateSelectedElement()
+  }
+
+  nextInput() {
+    this.curIndex = (this.curIndex + 1) % this.inputs.length
+
+    this.updateSelectedElement()
+  }
   
   focused() {
     this.root.select(this.inputs[this.curIndex])