« 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.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/ui.js b/ui.js
index 762914e..3bd62b5 100644
--- a/ui.js
+++ b/ui.js
@@ -342,7 +342,7 @@ class AppElement extends FocusElement {
     } else if (keyBuf.equals(Buffer.from([20]))) { // ctrl-T
       this.cloneCurrentTab()
     } else if (keyBuf.equals(Buffer.from([23]))) { // ctrl-W
-      this.tabber.closeTab(this.tabber.currentElement)
+      this.closeCurrentTab()
     } else if (telc.isCharacter(keyBuf, 'u')) {
       this.undoManager.undoLastAction()
     } else if (telc.isCharacter(keyBuf, 'U')) {
@@ -370,6 +370,21 @@ class AppElement extends FocusElement {
     listing.loadGrouplike(grouplike)
   }
 
+  closeCurrentTab() {
+    const listing = this.tabber.currentElement
+    let index
+    this.undoManager.pushAction({
+      activate: () => {
+        index = this.tabber.currentElementIndex
+        this.tabber.closeTab(this.tabber.currentElement)
+      },
+      undo: () => {
+        this.tabber.addTab(listing, index)
+        this.tabber.selectTab(listing)
+      }
+    })
+  }
+
   shuffleQueue() {
     const queue = this.queueGrouplike
     const index = queue.items.indexOf(this.playingTrack) + 1 // This is 0 if no track is playing
@@ -1235,9 +1250,10 @@ class Tabber extends FocusElement {
     }
   }
 
-  addTab(element) {
-    this.tabberElements.splice(this.currentElementIndex + 1, 0, element)
-    this.addChild(element, this.currentElementIndex + 1)
+  addTab(element, index = this.currentElementIndex) {
+    element.visible = false
+    this.tabberElements.splice(index + 1, 0, element)
+    this.addChild(element, index + 1)
     this.listElement.buildItems()
   }