fix: layer index edits will reorder as expected

This commit is contained in:
Sara Gerretsen 2025-12-08 16:00:05 +01:00
parent 59b5237342
commit e0f8057993

View file

@ -44,10 +44,13 @@ void PrimitiveLayerList::regenerate_tree(Array array) {
}
void PrimitiveLayerList::switch_index(size_t from, size_t to) {
if (to == from) {
return;
}
Array primitives = this->terrain->get_primitives();
Ref<TerrainPrimitive> primitive{ primitives.get(from) };
primitives.remove_at(from);
if (primitives.size() <= to) {
if (to > primitives.size()) {
primitives.push_back(primitive);
} else {
primitives.insert(to, primitive);
@ -75,7 +78,7 @@ void PrimitiveLayerList::item_edited() {
case IDX_COLUMN: { // index
Callable switch_index_c{ callable_mp(this, &self_type::switch_index) };
int64_t from{ edited->get_index() },
to{ edited->get_text(0).to_int() };
to{ edited->get_text(IDX_COLUMN).to_int() };
EditHistory::get_singleton()->push_action(switch_index_c.bind(from, to), switch_index_c.bind(to, from));
return;
}