From 1a49018bdcaa8c1704374ad568946a6ae89df231 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 3 Feb 2017 00:04:05 -0500 Subject: [PATCH] Fix moving items between collections `mozSourceNode` seems to no longer be set in `dataTransfer` objects during drags, so we now store it in `Zotero.DragDrop`. --- chrome/content/zotero/xpcom/itemTreeView.js | 12 ++++++ .../content/zotero/xpcom/libraryTreeView.js | 4 +- chrome/content/zotero/xpcom/zotero.js | 8 ++-- chrome/content/zotero/zoteroPane.xul | 3 +- test/tests/collectionTreeViewTest.js | 43 +++++++++++++++++-- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 922a4e87b..3126da6df 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -2518,6 +2518,12 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) { var itemIDs = this.getSelectedItems(true); event.dataTransfer.setData("zotero/item", itemIDs); + // dataTransfer.mozSourceNode doesn't seem to be properly set anymore (tested in 50), so store + // target separately + if (!event.dataTransfer.mozSourceNode) { + Zotero.debug("mozSourceNode not set -- storing source node"); + Zotero.DragDrop.currentSourceNode = event.target; + } var items = Zotero.Items.get(itemIDs); @@ -2609,6 +2615,12 @@ Zotero.ItemTreeView.prototype.onDragStart = function (event) { } }; +Zotero.ItemTreeView.prototype.onDragEnd = function (event) { + setTimeout(function () { + Zotero.DragDrop.currentDragSource = null; + }); +} + // Implements nsIFlavorDataProvider for dragging attachment files to OS // diff --git a/chrome/content/zotero/xpcom/libraryTreeView.js b/chrome/content/zotero/xpcom/libraryTreeView.js index b35309ff7..de4ce9485 100644 --- a/chrome/content/zotero/xpcom/libraryTreeView.js +++ b/chrome/content/zotero/xpcom/libraryTreeView.js @@ -310,10 +310,10 @@ Zotero.LibraryTreeView.prototype = { } if (event.dataTransfer.getData("zotero/item")) { - var sourceCollectionTreeRow = Zotero.DragDrop.getDragSource(); + var sourceCollectionTreeRow = Zotero.DragDrop.getDragSource(event.dataTransfer); if (sourceCollectionTreeRow) { if (this.type == 'collection') { - var targetCollectionTreeRow = Zotero.DragDrop.getDragTarget(); + var targetCollectionTreeRow = Zotero.DragDrop.getDragTarget(event); } else if (this.type == 'item') { var targetCollectionTreeRow = this.collectionTreeRow; diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index d176a13ec..fc5cb064a 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -2312,6 +2312,7 @@ Zotero.VersionHeader = { Zotero.DragDrop = { currentEvent: null, currentOrientation: 0, + currentSourceNode: null, getDataFromDataTransfer: function (dataTransfer, firstOnly) { var dt = dataTransfer; @@ -2374,7 +2375,7 @@ Zotero.DragDrop = { // For items, the drag source is the CollectionTreeRow of the parent window // of the source tree if (dataTransfer.types.contains("zotero/item")) { - var sourceNode = dataTransfer.mozSourceNode; + let sourceNode = dataTransfer.mozSourceNode || this.currentSourceNode; if (!sourceNode || sourceNode.tagName != 'treechildren' || sourceNode.parentElement.id != 'zotero-items-tree') { return false; @@ -2385,9 +2386,8 @@ Zotero.DragDrop = { } return win.ZoteroPane.collectionsView.selectedTreeRow; } - else { - return false; - } + + return false; }, diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul index 46992e531..a30f1a1d5 100644 --- a/chrome/content/zotero/zoteroPane.xul +++ b/chrome/content/zotero/zoteroPane.xul @@ -554,7 +554,8 @@ + ondrop="return ZoteroPane_Local.itemsView.onDrop(event)" + ondragend="ZoteroPane_Local.itemsView.onDragEnd(event)"/>