From f5ec52beb8afd5490ed854fddf6f5744dc31fe83 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 25 Aug 2019 14:01:02 -0300 Subject: Shift+up/down to select multiple items at once Dragging works too, as implemented earlier. --- README.md | 3 ++- ui.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b410956..b760230 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,13 @@ You're also welcome to share any ideas, suggestions, and questions through there * Enter - play the selected track * Ctrl+Up or p - play previous track * Ctrl+Down or n - play next track +* Shift+Up/Down or drag - select multiple items at once * Space - toggle pause * Escape - stop playing the current track * l - toggle track loop * Right - seek ahead * Left - seek back -* m or f - open a menu of actions related to the selected track or group +* m or f - open a menu of actions related to the selected track/group/item(s) * v and V - increase and decrease playback volume * Ctrl+F or / - jump to a track or group by entering (part of) its name * 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`) diff --git a/ui.js b/ui.js index 13f115b..0d17fb8 100644 --- a/ui.js +++ b/ui.js @@ -79,6 +79,8 @@ const keyBindings = [ ['isClearQueue', 'c'], ['isFocusMenubar', ';'], ['isFocusLabels', 'l'], // *** conflicts with isToggleLoop!!! must change this + ['isSelectUp', telc.isShiftUp], + ['isSelectDown', telc.isShiftDown], // Number pad ['isUp', '8'], @@ -1204,6 +1206,8 @@ class GrouplikeListingElement extends Form { } selectNone() { + // nb: this is unrelated to the actual track selection system! + // just clears the form selection this.pathElement.showItem(null) this.form.curIndex = 0 this.form.scrollItems = 0 @@ -1413,9 +1417,24 @@ class GrouplikeListingForm extends ListScrollForm { this.app = app this.dragInputs = [] + this.selectMode = null + this.keyboardDragDirection = null this.captureTab = false } + keyPressed(keyBuf) { + if (input.isSelectUp(keyBuf)) { + this.selectUp() + } else if (input.isSelectDown(keyBuf)) { + this.selectDown() + } else { + if (telc.isUp(keyBuf) || telc.isDown(keyBuf)) { + this.keyboardDragDirection = null + } + return super.keyPressed(keyBuf) + } + } + set curIndex(newIndex) { this._curIndex = newIndex this.emit('selected input', this.inputs[this.curIndex]) @@ -1521,6 +1540,64 @@ class GrouplikeListingForm extends ListScrollForm { } } } + + selectUp() { + this.handleKeyboardSelect(-1) + } + + selectDown() { + this.handleKeyboardSelect(+1) + } + + handleKeyboardSelect(direction) { + const move = () => { + if (direction === +1) { + this.nextInput() + } else { + this.previousInput() + } + } + + const getItem = () => { + const input = this.inputs[this.curIndex] + if (input instanceof InteractiveGrouplikeItemElement) { + return input.item + } else { + return null + } + } + + if (!this.keyboardDragDirection) { + const item = getItem() + if (!item) { + return + } + this.keyboardDragDirection = direction + this.oldMarkedItems = this.app.markGrouplike.items.slice() + if (this.app.markGrouplike.items.includes(item)) { + this.selectMode = 'deselect' + } else { + this.selectMode = 'select' + } + this.dragEnteredRange(item) + } + + if (direction === this.keyboardDragDirection) { + move() + const item = getItem() + if (!item) { + return + } + this.dragEnteredRange(item) + } else { + const item = getItem() + if (!item) { + return + } + this.dragLeftRange(item) + move() + } + } } class BasicGrouplikeItemElement extends Button { -- cgit 1.3.0-6-gf8a5