« 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
diff options
context:
space:
mode:
Diffstat (limited to 'ui/form')
-rw-r--r--ui/form/ListScrollForm.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/ui/form/ListScrollForm.js b/ui/form/ListScrollForm.js
index ae267c6..dcdb562 100644
--- a/ui/form/ListScrollForm.js
+++ b/ui/form/ListScrollForm.js
@@ -71,6 +71,14 @@ module.exports = class ListScrollForm extends Form {
         }
       }
 
+      if (telc.isPageUp(keyBuf)) {
+        this.previousPage()
+        break handleKeyPress
+      } else if (telc.isPageDown(keyBuf)) {
+        this.nextPage()
+        break handleKeyPress
+      }
+
       super.keyPressed(keyBuf)
     }
 
@@ -116,6 +124,26 @@ module.exports = class ListScrollForm extends Form {
     super.firstInput(...args)
   }
 
+  previousPage() {
+    this.curIndex -= this.h
+    this.scrollItems -= this.h
+    if (this.curIndex < 0) {
+      this.curIndex = 0
+      this.scrollItems = 0
+    }
+    this.updateSelectedElement()
+  }
+
+  nextPage() {
+    this.curIndex += this.h
+    this.scrollItems += this.h
+    if (this.curIndex >= this.inputs.length) {
+      this.curIndex = this.inputs.length - 1
+      this.scrollItems = Math.max(0, this.inputs.length - this.h)
+    }
+    this.updateSelectedElement()
+  }
+
   getItemPos(item) {
     // Gets the position of the item in an unscrolled view.