From 5f00f624a647fbf7838a5ff1c8d72156ae0ad38f Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 17 Sep 2018 10:35:58 -0300 Subject: Allow shift-down/n to auto-queue next track See #1. Also fixed a bug where shift-up/p wouldn't queue a track at the top of the queue when the top was selected. --- ui.js | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index b0276c6..6965331 100644 --- a/ui.js +++ b/ui.js @@ -342,9 +342,9 @@ class AppElement extends FocusElement { } else if (telc.isEscape(keyBuf)) { this.clearPlayingTrack() } else if (telc.isShiftUp(keyBuf) || telc.isCaselessLetter(keyBuf, 'p')) { - this.playPreviousTrack(this.playingTrack) + this.playPreviousTrack(this.playingTrack, true) } else if (telc.isShiftDown(keyBuf) || telc.isCaselessLetter(keyBuf, 'n')) { - this.playNextTrack(this.playingTrack) + this.playNextTrack(this.playingTrack, true) } else if (telc.isCharacter(keyBuf, '1') && this.tabber.selectable) { this.root.select(this.tabber) } else if (telc.isCharacter(keyBuf, '2') && this.queueListingElement.selectable) { @@ -601,7 +601,7 @@ class AppElement extends FocusElement { } } - playNextTrack(track) { + playNextTrack(track, automaticallyQueueNextTrack = false) { if (!track) { return false } @@ -614,27 +614,28 @@ class AppElement extends FocusElement { queueIndex++ if (queueIndex >= queue.items.length) { - /* - const parent = track[parentSymbol] - if (!parent) { - return false - } - const index = parent.items.indexOf(track) - const nextItem = parent.items[index + 1] - if (!nextItem) { + if (automaticallyQueueNextTrack) { + const parent = track[parentSymbol] + if (!parent) { + return false + } + const index = parent.items.indexOf(track) + const nextItem = parent.items[index + 1] + if (!nextItem) { + return false + } + this.queueGrouplikeItem(nextItem, false) + queueIndex = queue.items.length - 1 + } else { return false } - this.queueGrouplikeItem(nextItem, false) - queueIndex = queue.items.length - 1 - */ - return false } this.playGrouplikeItem(queue.items[queueIndex], false) return true } - playPreviousTrack(track) { + playPreviousTrack(track, automaticallyQueuePreviousTrack = false) { if (!track) { return false } @@ -647,17 +648,21 @@ class AppElement extends FocusElement { queueIndex-- if (queueIndex < 0) { - const parent = track[parentSymbol] - if (!parent) { - return false - } - const index = parent.items.indexOf(track) - const previousItem = parent.items[index - 1] - if (!previousItem) { + if (automaticallyQueuePreviousTrack) { + const parent = track[parentSymbol] + if (!parent) { + return false + } + const index = parent.items.indexOf(track) + const previousItem = parent.items[index - 1] + if (!previousItem) { + return false + } + this.queueGrouplikeItem(previousItem, 'FRONT') + queueIndex = 0 + } else { return false } - this.queueGrouplikeItem(previousItem, false, 'FRONT') - queueIndex = 0 } this.playGrouplikeItem(queue.items[queueIndex], false) -- cgit 1.3.0-6-gf8a5