« 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/CancelDialog.js2
-rw-r--r--ui/form/ConfirmDialog.js2
-rw-r--r--ui/form/FocusElement.js8
-rw-r--r--ui/form/Form.js6
4 files changed, 10 insertions, 8 deletions
diff --git a/ui/form/CancelDialog.js b/ui/form/CancelDialog.js
index c5eb7d3..21ff6df 100644
--- a/ui/form/CancelDialog.js
+++ b/ui/form/CancelDialog.js
@@ -47,7 +47,7 @@ module.exports = class ConfirmDialog extends FocusElement {
     this.cancelBtn.y = this.pane.contentH - 2
   }
 
-  focused() {
+  selected() {
     this.root.select(this.cancelBtn)
   }
 
diff --git a/ui/form/ConfirmDialog.js b/ui/form/ConfirmDialog.js
index 3614cf9..230230d 100644
--- a/ui/form/ConfirmDialog.js
+++ b/ui/form/ConfirmDialog.js
@@ -59,7 +59,7 @@ module.exports = class ConfirmDialog extends FocusElement {
     this.cancelBtn.y = this.form.contentH - 2
   }
 
-  focused() {
+  selected() {
     this.root.select(this.form)
   }
 
diff --git a/ui/form/FocusElement.js b/ui/form/FocusElement.js
index 9061838..23c2e02 100644
--- a/ui/form/FocusElement.js
+++ b/ui/form/FocusElement.js
@@ -11,11 +11,11 @@ module.exports = class FocusElement extends DisplayElement {
     this.cursorY = 0
   }
 
-  focused() {
+  selected() {
     // Should be overridden in subclasses.
   }
 
-  unfocused() {
+  unselected() {
     // Should be overridden in subclasses.
   }
 
@@ -36,8 +36,8 @@ module.exports = class FocusElement extends DisplayElement {
   }
 
   get isSelected() {
-    const selected = this.root.selected
-    return selected && [selected, ...selected.directAncestors].includes(this)
+    const selected = this.root.selectedElement
+    return !!(selected && [selected, ...selected.directAncestors].includes(this))
   }
 
   get absCursorX() { return this.absX + this.cursorX }
diff --git a/ui/form/Form.js b/ui/form/Form.js
index 87763bb..ac9f1e4 100644
--- a/ui/form/Form.js
+++ b/ui/form/Form.js
@@ -117,7 +117,9 @@ module.exports = class Form extends FocusElement {
     }
   }
 
-  focused() {
-    this.updateSelectedElement()
+  selected() {
+    if (this.root.selectedElement === this) {
+      this.updateSelectedElement()
+    }
   }
 }