Fix undoing GridMap move operations resulting in deleted cells

This commit is contained in:
Michael Alexsander 2026-02-20 15:00:20 -03:00
parent be587f3a2d
commit 61f6005ca4
No known key found for this signature in database
GPG key ID: A9C91EE110F4EABA

View file

@ -705,7 +705,26 @@ void GridMapEditor::_do_paste() {
orm = rot * orm;
undo_redo->add_do_method(node, "set_cell_item", position, item.cell_item, node->get_orthogonal_index_from_basis(orm));
undo_redo->add_undo_method(node, "set_cell_item", position, node->get_cell_item(position), node->get_cell_item_orientation(position));
int prev_idx = node->get_cell_item(position);
bool used_for_preview = false;
if (clipboard_is_move && prev_idx == GridMap::INVALID_CELL_ITEM) {
// If no cell is present, it could be because it was removed to show it in the preview.
// Search through the clipboard to check if one of them was in that same position.
for (const ClipboardItem &prev_item : clipboard_items) {
Vector3 prev_position = paste_indicator.begin + prev_item.grid_offset;
if (position == prev_position) {
used_for_preview = true;
undo_redo->add_undo_method(node, "set_cell_item", position, prev_item.cell_item, prev_item.orientation);
break;
}
}
}
if (!used_for_preview) {
undo_redo->add_undo_method(node, "set_cell_item", position, prev_idx, node->get_cell_item_orientation(position));
}
}
if (reselect) {