From 315d9ecbcb7076476d8e747e24abe267d3b2676c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 25 Feb 2012 18:26:59 -0500 Subject: [PATCH] Don't allow child items to be dragged within their own parents This caused child notes and PDFs to be moved out of their parents with the slightest drag. --- chrome/content/zotero/xpcom/itemTreeView.js | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 5a3c5f10a..239db0734 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -2387,6 +2387,34 @@ Zotero.ItemTreeView.prototype.canDrop = function(row, orient, dragData) return false; } + // Don't allow children to be dragged within their own parents + var parentItemID = item.getSource(); + var parentIndex = this._itemRowMap[parentItemID]; + if (this.getLevel(row) > 0) { + if (this._getItemAtRow(this.getParentIndex(row)).ref.id == parentItemID) { + return false; + } + } + // Including immediately after the parent + if (orient == 1) { + if (row == parentIndex) { + return false; + } + } + // And immediately before the next parent + if (orient == -1) { + var nextParentIndex = null; + for (var i = parentIndex + 1; i < this.rowCount; i++) { + if (this.getLevel(i) == 0) { + nextParentIndex = i; + break; + } + } + if (row === nextParentIndex) { + return false; + } + } + // Disallow cross-library child drag if (item.libraryID != itemGroup.ref.libraryID) { return false;