From 5e2055fc84eadcc45a6c7f3d8c47b9985d34ba66 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 18 Jan 2019 15:09:12 -0500 Subject: [PATCH 1/2] Revert "Merge pull request #4354 from paulkaplan/fix-backpack-sprite" This reverts commit 97f8eb63b45e269d0e1d3e522980ff313c207fc7, reversing changes made to 2e017f060fbef580173c020731c066c6aae01ae3. --- src/containers/costume-tab.jsx | 2 +- src/containers/sound-tab.jsx | 2 +- src/containers/target-pane.jsx | 2 +- src/lib/sortable-hoc.jsx | 7 ++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/containers/costume-tab.jsx b/src/containers/costume-tab.jsx index 8f2717e96..5df459150 100644 --- a/src/containers/costume-tab.jsx +++ b/src/containers/costume-tab.jsx @@ -206,7 +206,7 @@ class CostumeTab extends React.Component { this.fileInput.click(); } handleDrop (dropInfo) { - if (dropInfo.dragType === DragConstants.COSTUME && dropInfo.newIndex !== null) { + if (dropInfo.dragType === DragConstants.COSTUME) { const sprite = this.props.vm.editingTarget.sprite; const activeCostume = sprite.costumes[this.state.selectedCostumeIndex]; this.props.vm.reorderCostume(this.props.vm.editingTarget.id, diff --git a/src/containers/sound-tab.jsx b/src/containers/sound-tab.jsx index d8731b4c3..3df93b1f6 100644 --- a/src/containers/sound-tab.jsx +++ b/src/containers/sound-tab.jsx @@ -130,7 +130,7 @@ class SoundTab extends React.Component { } handleDrop (dropInfo) { - if (dropInfo.dragType === DragConstants.SOUND && dropInfo.newIndex !== null) { + if (dropInfo.dragType === DragConstants.SOUND) { const sprite = this.props.vm.editingTarget.sprite; const activeSound = sprite.sounds[this.state.selectedSoundIndex]; diff --git a/src/containers/target-pane.jsx b/src/containers/target-pane.jsx index b63a72a36..eb4100969 100644 --- a/src/containers/target-pane.jsx +++ b/src/containers/target-pane.jsx @@ -163,7 +163,7 @@ class TargetPane extends React.Component { } handleDrop (dragInfo) { const {sprite: targetId} = this.props.hoveredTarget; - if (dragInfo.dragType === DragConstants.SPRITE && dragInfo.newIndex !== null) { + if (dragInfo.dragType === DragConstants.SPRITE) { // Add one to both new and target index because we are not counting/moving the stage this.props.vm.reorderTarget(dragInfo.index + 1, dragInfo.newIndex + 1); } else if (dragInfo.dragType === DragConstants.BACKPACK_SPRITE) { diff --git a/src/lib/sortable-hoc.jsx b/src/lib/sortable-hoc.jsx index 57087867b..d3f9c59e1 100644 --- a/src/lib/sortable-hoc.jsx +++ b/src/lib/sortable-hoc.jsx @@ -33,9 +33,10 @@ const SortableHOC = function (WrappedComponent) { } this.containerBox = this.ref.getBoundingClientRect(); } else if (!newProps.dragInfo.dragging && this.props.dragInfo.dragging) { - this.props.onDrop(Object.assign({}, this.props.dragInfo, { - newIndex: this.getMouseOverIndex() - })); + const newIndex = this.getMouseOverIndex(); + if (newIndex !== null) { + this.props.onDrop(Object.assign({}, this.props.dragInfo, {newIndex})); + } } } From 1146689f42b511f35adb0475ef3deb0910f1900e Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 18 Jan 2019 15:14:06 -0500 Subject: [PATCH 2/2] Fix sound reorder bug. We were emitting drops when getMouseOverIndex was null, which could happen either when the drop is outside the container, or there were zero boxes to check for ordering. Treat these two cases separately, and continue to not emit drops when outside the container. --- src/lib/sortable-hoc.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/sortable-hoc.jsx b/src/lib/sortable-hoc.jsx index d3f9c59e1..eb971d0c0 100644 --- a/src/lib/sortable-hoc.jsx +++ b/src/lib/sortable-hoc.jsx @@ -68,16 +68,22 @@ const SortableHOC = function (WrappedComponent) { } return ordering; } + getMouseOverIndex () { // MouseOverIndex is the index that the current drag wants to place the // the dragging object. Obviously only exists if there is a drag (i.e. currentOffset). + // Return null if outside the container, zero if there are no boxes. let mouseOverIndex = null; if (this.props.dragInfo.currentOffset) { const {x, y} = this.props.dragInfo.currentOffset; const {top, left, bottom, right} = this.containerBox; if (x >= left && x <= right && y >= top && y <= bottom) { - mouseOverIndex = indexForPositionOnList( - this.props.dragInfo.currentOffset, this.boxes); + if (this.boxes.length === 0) { + mouseOverIndex = 0; + } else { + mouseOverIndex = indexForPositionOnList( + this.props.dragInfo.currentOffset, this.boxes); + } } } return mouseOverIndex;