« get me outta code hell

Undo close tab - 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:
authorFlorrie <towerofnix@gmail.com>2018-07-06 12:41:47 -0300
committerFlorrie <towerofnix@gmail.com>2018-07-06 12:41:47 -0300
commit0d2a80095d5ffaf9479680c8e819eeda69587321 (patch)
treeecbec402b323a9f98b2a4ecb4dd77e1612603fe5 /ui.js
parent58be1516971a86fa6c9383cbe5bbf761a71e7c00 (diff)
Undo close tab
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()
   }