« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/ui.js b/ui.js
index 5c586dd..0172fc2 100644
--- a/ui.js
+++ b/ui.js
@@ -3751,6 +3751,7 @@ class ContextMenu extends FocusElement {
         button.keyboardIdentifier = item.keyboardIdentifier || item.label
         if (item.action) {
           button.on('pressed', async () => {
+            this.restoreSelection()
             if (await item.action() === 'reload') {
               this.reload()
             } else {
@@ -3797,6 +3798,7 @@ class ContextMenu extends FocusElement {
 
   keyPressed(keyBuf) {
     if (telc.isEscape(keyBuf) || telc.isBackspace(keyBuf)) {
+      this.restoreSelection()
       this.close()
       return false
     } else if (this.keyboardSelector.keyPressed(keyBuf)) {
@@ -3819,24 +3821,25 @@ class ContextMenu extends FocusElement {
     }
 
     if (this.visible) {
-      const newlySelected = this.root.selectedElement
       this.close()
-      newlySelected.root.select(newlySelected)
     }
   }
 
   close(remove = true) {
     this.clearItems()
     this.visible = false
-    if (this.selectedBefore.root.select) {
-      this.selectedBefore.root.select(this.selectedBefore)
-    }
     if (remove && this.parent) {
       this.parent.removeChild(this)
       this.emit('closed')
     }
   }
 
+  restoreSelection() {
+    if (this.selectedBefore.root.select) {
+      this.selectedBefore.root.select(this.selectedBefore)
+    }
+  }
+
   clearItems() {
     // Abhorrent hack - just erases children from memory. Leaves children
     // thinking they've still got a parent, though. (Necessary to avoid crazy