« get me outta code hell

Page up/down controls in ListScrollForm - 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>2018-06-03 20:05:37 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-03 20:05:37 -0300
commiteae9716c237ad7c9602cc05f6babc6c2714e258c (patch)
tree9203707683cfe24167afa74ae98b10f3f5a4aa38 /ui
parenteb82bbfef19343a154a77663426292c1e25f06e9 (diff)
Page up/down controls in ListScrollForm
Diffstat (limited to 'ui')
-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.