From fe4db4e4f093697b8b35cd63c80c16695fedb2ca Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 5 Jul 2018 10:01:17 -0300 Subject: Ctrl+T, ctrl+W; new tabs open adjacent to current tab --- ui.js | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 3e04f85..4228650 100644 --- a/ui.js +++ b/ui.js @@ -148,7 +148,7 @@ class AppElement extends FocusElement { grouplike = await processSmartPlaylist(grouplike) - if (newTab) { + if (newTab || !this.tabber.currentElement) { const grouplikeListing = this.newGrouplikeListing() grouplikeListing.loadGrouplike(grouplike) } else { @@ -242,6 +242,10 @@ class AppElement extends FocusElement { this.form.updateSelectedElement() } else if (keyBuf.equals(Buffer.from([15]))) { // ctrl-O this.openPlaylistDialog.open() + } 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) } else if (this.tabber.isSelected && keyBuf.equals(Buffer.from(['t'.charCodeAt(0)]))) { this.tabber.nextTab() } else if (this.tabber.isSelected && keyBuf.equals(Buffer.from(['T'.charCodeAt(0)]))) { @@ -251,6 +255,12 @@ class AppElement extends FocusElement { } } + cloneCurrentTab() { + const grouplike = this.tabber.currentElement.grouplike + const listing = this.newGrouplikeListing() + listing.loadGrouplike(grouplike) + } + shuffleQueue() { const queue = this.queueGrouplike const index = queue.items.indexOf(this.playingTrack) + 1 // This is 0 if no track is playing @@ -1092,8 +1102,8 @@ class Tabber extends FocusElement { } addTab(element) { - this.tabberElements.push(element) - this.addChild(element) + this.tabberElements.splice(this.currentElementIndex + 1, 0, element) + this.addChild(element, this.currentElementIndex + 1) this.listElement.buildItems() } @@ -1116,6 +1126,25 @@ class Tabber extends FocusElement { this.updateVisibleElement() } + closeTab(element) { + if (!this.tabberElements.includes(element)) { + return + } + + const index = this.tabberElements.indexOf(element) + this.tabberElements.splice(index, 1) + if (index <= this.currentElementIndex) { + this.currentElementIndex-- + } + + // Deliberately update the visible element before removing the child. If we + // remove the child first, the isSelected in updateVisibleElement will be + // false, so the new currentElement won't actually be root.select()'ed. + this.updateVisibleElement() + this.removeChild(element) + this.listElement.buildItems() + } + updateVisibleElement() { const len = this.tabberElements.length - 1 this.currentElementIndex = Math.min(len, Math.max(0, this.currentElementIndex)) @@ -1124,8 +1153,12 @@ class Tabber extends FocusElement { el.visible = (i === this.currentElementIndex) }) - if (this.isSelected && this.currentElement) { - this.root.select(this.currentElement) + if (this.isSelected) { + if (this.currentElement) { + this.root.select(this.currentElement) + } else { + this.root.select(this) + } } this.fixLayout() -- cgit 1.3.0-6-gf8a5