diff options
Diffstat (limited to 'ui.js')
-rw-r--r-- | ui.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/ui.js b/ui.js index 47270bd..47c50a8 100644 --- a/ui.js +++ b/ui.js @@ -1,6 +1,7 @@ const { getDownloaderFor } = require('./downloaders') const { getPlayer } = require('./players') const { parentSymbol, isGroup, isTrack, getItemPath } = require('./playlist-utils') +const { shuffleArray } = require('./general-util') const ansi = require('./tui-lib/util/ansi') const Button = require('./tui-lib/ui/form/Button') const DisplayElement = require('./tui-lib/ui/DisplayElement') @@ -143,11 +144,23 @@ class AppElement extends FocusElement { } else if (telc.isCharacter(keyBuf, '2') && this.queueListingElement.selectable) { this.form.curIndex = this.form.inputs.indexOf(this.queueListingElement) this.form.updateSelectedElement() + } else if (telc.isCaselessLetter(keyBuf, 's')) { + this.shuffleQueue() } else { super.keyPressed(keyBuf) } } + shuffleQueue() { + const queue = this.queueGrouplike + const index = queue.items.indexOf(this.playingTrack) + 1 // This is 0 if no track is playing + const initialItems = queue.items.slice(0, index) + const remainingItems = queue.items.slice(index) + const newItems = initialItems.concat(shuffleArray(remainingItems)) + queue.items = newItems + this.queueListingElement.buildItems() + } + handleSpacePressed(callback) { // Pauses/resumes if a track is currently playing; otherwise, calls the // callback function. |