From b89f230581e7a921f74fa9f6c40aa5da14a81859 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 2 Jun 2018 12:51:55 -0300 Subject: Shift-up/down to skip tracks --- ui.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 1a583ab..57b2d9f 100644 --- a/ui.js +++ b/ui.js @@ -106,6 +106,10 @@ class AppElement extends FocusElement { this.seekBack(10) } else if (telc.isCaselessLetter(keyBuf, 'p') || telc.isCaselessLetter(keyBuf, 'k')) { this.togglePause() + } else if (telc.isShiftUp(keyBuf)) { + this.playPreviousTrack(this.playingTrack) + } else if (telc.isShiftDown(keyBuf)) { + this.playNextTrack(this.playingTrack) } else { super.keyPressed(keyBuf) } @@ -159,7 +163,9 @@ class AppElement extends FocusElement { items.splice(items.indexOf(item), 1) } - if (afterItem && items.includes(afterItem)) { + if (afterItem === 'FRONT') { + items.unshift(item) + } else if (afterItem && items.includes(afterItem)) { items.splice(items.indexOf(afterItem) + 1, 0, item) } else { items.push(item) @@ -266,6 +272,31 @@ class AppElement extends FocusElement { this.playGrouplikeItem(queue.items[queueIndex], false) } + + playPreviousTrack(track) { + const queue = this.queueGrouplike + let queueIndex = queue.items.indexOf(track) + if (queueIndex === -1) { + queueIndex = queue.items.length + } + queueIndex-- + + if (queueIndex < 0) { + const parent = track[parentSymbol] + if (!parent) { + return + } + const index = parent.items.indexOf(track) + const previousItem = parent.items[index - 1] + if (!previousItem) { + return + } + this.queueGrouplikeItem(previousItem, false, 'FRONT') + queueIndex = 0 + } + + this.playGrouplikeItem(queue.items[queueIndex], false) + } } class GrouplikeListingElement extends ListScrollForm { -- cgit 1.3.0-6-gf8a5