Fix problems with undoing selection and pasting in GridMap editor

This commit is contained in:
Michael Alexsander 2026-02-26 14:25:26 -03:00
parent 95535167b3
commit 4d012fe73c
No known key found for this signature in database
GPG key ID: A9C91EE110F4EABA
2 changed files with 26 additions and 15 deletions

View file

@ -303,7 +303,7 @@ void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const
selection.click = p_begin;
selection.current = p_end;
if (is_visible_in_tree()) {
if (is_inside_tree()) {
_update_selection_transform();
}
}
@ -550,15 +550,16 @@ void GridMapEditor::_delete_selection_with_undo() {
undo_redo->commit_action();
}
void GridMapEditor::_setup_paste_mode() {
input_action = INPUT_PASTE;
paste_indicator.click = selection.click;
paste_indicator.current = cursor_gridpos;
paste_indicator.begin = selection.begin;
paste_indicator.end = selection.end;
paste_indicator.distance_from_cursor = cursor_gridpos - paste_indicator.begin;
paste_indicator.orientation = 0;
_update_paste_indicator();
void GridMapEditor::_clear_selection_with_undo() {
if (!selection.active) {
return;
}
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("GridMap Clear Selection"));
undo_redo->add_do_method(this, "_set_selection", false, Vector3(), Vector3());
undo_redo->add_undo_method(this, "_set_selection", true, selection.begin, selection.end);
undo_redo->commit_action();
}
void GridMapEditor::_fill_selection() {
@ -582,6 +583,17 @@ void GridMapEditor::_fill_selection() {
undo_redo->commit_action();
}
void GridMapEditor::_setup_paste_mode() {
input_action = INPUT_PASTE;
paste_indicator.click = selection.click;
paste_indicator.current = cursor_gridpos;
paste_indicator.begin = selection.begin;
paste_indicator.end = selection.end;
paste_indicator.distance_from_cursor = cursor_gridpos - paste_indicator.begin;
paste_indicator.orientation = 0;
_update_paste_indicator();
}
void GridMapEditor::_clear_clipboard_data() {
for (const ClipboardItem &E : clipboard_items) {
if (E.instance.is_null()) {
@ -783,7 +795,7 @@ EditorPlugin::AfterGUIInput GridMapEditor::forward_spatial_input_event(Camera3D
_cancel_pending_move();
return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (selection.active) {
_set_selection(false);
_clear_selection_with_undo();
return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else {
input_action = INPUT_NONE;
@ -860,12 +872,10 @@ EditorPlugin::AfterGUIInput GridMapEditor::forward_spatial_input_event(Camera3D
}
} else if (mb->get_button_index() == MouseButton::RIGHT) {
if (input_action == INPUT_PASTE) {
_clear_clipboard_data();
input_action = INPUT_NONE;
_update_paste_indicator();
_cancel_pending_move();
return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (selection.active) {
_set_selection(false);
_clear_selection_with_undo();
if (input_action == INPUT_SELECT) {
input_action = INPUT_NONE;
}

View file

@ -255,6 +255,7 @@ class GridMapEditor : public EditorDock {
void _delete_selection();
void _delete_selection_with_undo();
void _fill_selection();
void _clear_selection_with_undo();
void _setup_paste_mode();
bool do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click);