From 58be1516971a86fa6c9383cbe5bbf761a71e7c00 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 6 Jul 2018 12:31:10 -0300 Subject: Paste into empty group --- ui.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 89801d7..762914e 100644 --- a/ui.js +++ b/ui.js @@ -175,8 +175,8 @@ class AppElement extends FocusElement { const handlePaste = offset => item => { if (this.editMode) { if (this.markGrouplike.items.length) { - const parent = item[parentSymbol] - const index = parent.items.indexOf(item) + offset + const parent = offset === 'TOP' ? item : item[parentSymbol] + const index = offset === 'TOP' ? 0 : (parent.items.indexOf(item) + offset) this.undoManager.pushAction({ activate: () => { // TODO: More "proper" way of cloning a grouplike. (The purpose of updateGroupFormat @@ -199,6 +199,7 @@ class AppElement extends FocusElement { grouplikeListing.on('paste (below)', handlePaste(+1)) grouplikeListing.on('paste (above)', handlePaste(0)) + grouplikeListing.on('paste (top)', handlePaste('TOP')) const handleSelectFromPathElement = item => { this.form.selectInput(grouplikeListing) @@ -707,6 +708,12 @@ class GrouplikeListingElement extends FocusElement { keyPressed(keyBuf) { if (telc.isBackspace(keyBuf)) { this.loadParentGrouplike() + } else if (this.currentItem && telc.isCharacter(keyBuf, 'p')) { + this.emit('paste (below)', this.currentItem) + } else if (this.currentItem && telc.isCharacter(keyBuf, 'P')) { + this.emit('paste (above)', this.currentItem) + } else if (!this.currentItem && telc.isCaselessLetter(keyBuf, 'p')) { + this.emit('paste (top)', this.grouplike) } else { return super.keyPressed(keyBuf) } @@ -741,7 +748,7 @@ class GrouplikeListingElement extends FocusElement { if (this.grouplike.items.length) { for (const item of this.grouplike.items) { const itemElement = new GrouplikeItemElement(item, this.recordStore) - for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'paste (above)', 'paste (below)', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)']) { + for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)']) { itemElement.on(evtName, () => this.emit(evtName, item)) } form.addInput(itemElement) @@ -800,6 +807,11 @@ class GrouplikeListingElement extends FocusElement { return 'No group open' } } + + get currentItem() { + const element = this.form.inputs[this.form.curIndex] || null + return element && element.item + } } class GrouplikeListingForm extends ListScrollForm { @@ -916,14 +928,8 @@ class GrouplikeItemElement extends Button { this.emit('remove (backspace)') } else if (telc.isCaselessLetter(keyBuf, 'x')) { this.emit('remove (x)') - - // Edit-mode things } else if (telc.isCaselessLetter(keyBuf, 'm')) { this.emit('mark') - } else if (telc.isCharacter(keyBuf, 'p')) { - this.emit('paste (below)') - } else if (telc.isCharacter(keyBuf, 'P')) { - this.emit('paste (above)') } } } -- cgit 1.3.0-6-gf8a5