diff options
author | Florrie <towerofnix@gmail.com> | 2018-07-06 12:31:10 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-07-06 12:31:10 -0300 |
commit | 58be1516971a86fa6c9383cbe5bbf761a71e7c00 (patch) | |
tree | 8a48941591ad0d37f207c1abb98ebf28127221e7 /ui.js | |
parent | 24e8ed61d6111d1d6c4a27e133fce9edd5f767cb (diff) |
Paste into empty group
Diffstat (limited to 'ui.js')
-rw-r--r-- | ui.js | 24 |
1 files changed, 15 insertions, 9 deletions
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)') } } } |