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. --- ui.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'ui.js') 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