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 --- README.md | 4 +++- tui-lib | 2 +- ui.js | 43 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 55f5e82..ae072ac 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ playlist.json file (usually generated by http-music or downloaded from online). * Tab and Shift+Tab - switch between UI elements * 1 - focus the main track/group listing * 2 - focus the queue listing -* t and T (shift+T) - switch between playlist tabs * Enter - play the selected track * Shift+Up or p - play previous track * Shift+Down or n - play next track @@ -32,6 +31,9 @@ playlist.json file (usually generated by http-music or downloaded from online). * Right - seek ahead * Left - seek back * Ctrl+O - open a playlist from a source (like a /path/to/a/folder or a YouTube playlist URL) (you can also just pass this source to `mtui`) +* t and T (shift+T) - switch between playlist tabs +* Ctrl+T - open the current playlist in a new tab (so, clone the current tab) +* Ctrl+W - close the current tab * **In the main listing:** * Enter - if the selected item is a group, enter it; otherwise play it * Backspace - leave the current group (if in one) diff --git a/tui-lib b/tui-lib index de1c921..40431bc 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit de1c92141d2d4859cf869ec90e50e8eb0e5e8568 +Subproject commit 40431bcfd46c457a1cf271b5eae53a35aa1d0b6b 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