fix: reordering between / across section break fails

* since the indices become stale after reorder
* we need to splice instead of swap
This commit is contained in:
Hussain Nagaria 2026-03-14 06:20:30 +05:30
parent 7feb58a6b6
commit 777d663cd0

View file

@ -141,15 +141,15 @@ export class SidebarEditor {
me.sorting = true;
},
onEnd: function (event) {
if (event.from !== event.to) return; // onAdd handles this case
if (me.new_sidebar_items.length == 0) {
me.new_sidebar_items = Array.from(me.workspace_sidebar_items);
}
let old_index = event.oldIndex;
let new_index = event.newIndex;
me.new_sidebar_items[old_index];
let b = me.new_sidebar_items[old_index];
me.new_sidebar_items[old_index] = me.new_sidebar_items[new_index];
me.new_sidebar_items[new_index] = b;
let [item] = me.new_sidebar_items.splice(old_index, 1);
me.new_sidebar_items.splice(new_index, 0, item);
},
});
@ -198,21 +198,16 @@ export class SidebarEditor {
);
},
onEnd: function (event) {
if (event.from !== event.to) return; // onAdd handles this case
let new_index = event.newIndex;
let old_index = event.oldIndex;
let item_label = $(event.item).data("id");
me.new_sidebar_items.forEach((item) => {
if (item.nested_items.length) {
let child = item.nested_items.find(
(child) => child.label === item_label
);
if (child) {
let b = item.nested_items[old_index];
item.nested_items[old_index] = item.nested_items[new_index];
item.nested_items[new_index] = b;
}
}
});
let section_name = $(event.to).parent().attr("item-name");
let section_data = me.get_item_data(section_name);
if (section_data && section_data.nested_items) {
let [item] = section_data.nested_items.splice(old_index, 1);
section_data.nested_items.splice(new_index, 0, item);
}
},
});
});