Disable itemTree row drop between child rows (#5258)

Fixes: #5257
This commit is contained in:
abaevbog 2025-05-06 23:00:22 -07:00 • committed by GitHub
parent f8a517d286
commit 971c57fedd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2345,6 +2345,7 @@ var ItemTree = class ItemTree extends LibraryTree {
// In library, allow children to be dragged out of parent
else if (collectionTreeRow.isLibrary(true) || collectionTreeRow.isCollection()) {
let targetRow = row != -1 ? this.getRow(row) : null;
for (let item of items) {
// Don't allow drag if any top-level items
if (item.isTopLevelItem()) {
@ -2365,24 +2366,17 @@ var ItemTree = class ItemTree extends LibraryTree {
return false;
}
// Don't allow children to be dragged within their own parents
var parentItemID = item.parentItemID;
var parentIndex = this._rowMap[parentItemID];
if (row != -1 && this.getLevel(row) > 0) {
if (this.getRow(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
// Can always drop into empty space
if (!targetRow) continue;
// Can only drop before or after a top-level item
if (!targetRow.ref.isTopLevelItem()) return false;
// Cannot drop between an opened container and the first child row
if (orient == 1 && targetRow.isOpen) return false;
// Cannot drop after the last child of a parent container
if (orient == -1) {
var nextParentIndex = null;
for (var i = parentIndex + 1; i < this.rowCount; i++) {
let parentIndex = this._rowMap[item.parentItemID];
let nextParentIndex = null;
for (let i = parentIndex + 1; i < this.rowCount; i++) {
if (this.getLevel(i) == 0) {
nextParentIndex = i;
break;