Skip to content

Commit

Permalink
Fix drag behavior being lost in compendiums & containers
Browse files Browse the repository at this point in the history
In a few cases the drop handling was awaiting something before
fetching the drop behavior, causing the `_handleDragEnd` to be
called first which erases the stored drag behavior. Moving the
calls to `_dragBehavior` to the first thing in those drop methods
prevents this problem.
  • Loading branch information
arbron committed Feb 23, 2025
1 parent 3845850 commit 5875add
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion module/applications/item/container-sheet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ export default class ContainerSheet extends ItemSheet5e {
* @protected
*/
async _onDropItem(event, data) {
const item = await Item.implementation.fromDropData(data);
const behavior = this._dropBehavior(event, data);
const item = await Item.implementation.fromDropData(data);
if ( !this.item.isOwner || !item || (behavior === "none") ) return false;

// If item already exists in this container, just adjust its sorting
Expand Down
4 changes: 2 additions & 2 deletions module/applications/item/item-compendium.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class ItemCompendium5eV13 extends DragDropApplicationMixin(foundry.applications.
/** @inheritDoc */
async _handleDroppedEntry(target, data) {
// Obtain the dropped Document
let item = await Item.fromDropData(data);
const behavior = this._dropBehavior(event, data);
let item = await Item.fromDropData(data);
if ( !item || (behavior === "none") ) return;

// Create item and its contents if it doesn't already exist here
Expand Down Expand Up @@ -140,8 +140,8 @@ class ItemCompendium5eV12 extends DragDropApplicationMixin(
/** @inheritDoc */
async _handleDroppedEntry(target, data) {
// Obtain the dropped Document
let item = await Item.fromDropData(data);
const behavior = this._dropBehavior(event, data);
let item = await Item.fromDropData(data);
if ( !item || (behavior === "none") ) return;

// Create item and its contents if it doesn't already exist here
Expand Down
3 changes: 2 additions & 1 deletion module/applications/mixins/drag-drop-mixin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default function DragDropApplicationMixin(Base) {
/* -------------------------------------------- */

/**
* The behavior for the dropped data.
* The behavior for the dropped data. When called during the drop event, ensure this is called before awaiting
* anything or the drop behavior will be lost.
* @param {DragEvent} event The drag event.
* @param {object} data The drag payload.
* @returns {DropEffectValue}
Expand Down

0 comments on commit 5875add

Please sign in to comment.