« get me outta code hell

add ListScrollForm.wheelMode - 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-04-23 16:17:58 -0300
committerFlorrie <towerofnix@gmail.com>2020-04-23 16:17:58 -0300
commit04a9e6f780bb05d855507d9092170d873e18e229 (patch)
tree39f3bfa8979db19c0d57681b31002729ba7f133b /ui
parenta7f8734a33d1ffe549f83ea7186c56b831e933f0 (diff)
add ListScrollForm.wheelMode
Diffstat (limited to 'ui')
-rw-r--r--ui/form/ListScrollForm.js38
1 files changed, 19 insertions, 19 deletions
diff --git a/ui/form/ListScrollForm.js b/ui/form/ListScrollForm.js
index 72e79df..e4f4249 100644
--- a/ui/form/ListScrollForm.js
+++ b/ui/form/ListScrollForm.js
@@ -15,6 +15,7 @@ module.exports = class ListScrollForm extends Form {
     super()
 
     this.layoutType = layoutType
+    this.wheelMode = 'scroll' // scroll, selection
 
     this.scrollItems = 0
 
@@ -122,27 +123,26 @@ module.exports = class ListScrollForm extends Form {
   }
 
   clicked(button) {
-    // Old code for changing the actual selected item...maybe an interesting
-    // functionality to explore later?
-    /*
-    if (button === 'scroll-up') {
-      this.previousInput()
-      this.scrollSelectedElementIntoView()
-    } else if (button === 'scroll-down') {
-      this.nextInput()
-      this.scrollSelectedElementIntoView()
-    }
-    */
-
-    // Scrolling is typically pretty slow with a mouse wheel when it's by
-    // a single line, so scroll at 3x that speed.
-    for (let i = 0; i < 3; i++) {
+    if (this.wheelMode === 'selection') {
+      // Change the actual selected item.
       if (button === 'scroll-up') {
-        this.scrollItems--
+        this.previousInput()
+        this.scrollSelectedElementIntoView()
       } else if (button === 'scroll-down') {
-        this.scrollItems++
-      } else {
-        return
+        this.nextInput()
+        this.scrollSelectedElementIntoView()
+      }
+    } else if (this.wheelMode === 'scroll') {
+      // Scrolling is typically pretty slow with a mouse wheel when it's by
+      // a single line, so scroll at 3x that speed.
+      for (let i = 0; i < 3; i++) {
+        if (button === 'scroll-up') {
+          this.scrollItems--
+        } else if (button === 'scroll-down') {
+          this.scrollItems++
+        } else {
+          return
+        }
       }
     }