From 0d2a80095d5ffaf9479680c8e819eeda69587321 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 6 Jul 2018 12:41:47 -0300 Subject: Undo close tab --- ui.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'ui.js') 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() } -- cgit 1.3.0-6-gf8a5