Merge pull request #116814 from YeldhamDev/gridmap_selection_paste_fixes

Fix problems with undoing selection and pasting in `GridMap` editor
This commit is contained in:
Thaddeus Crews 2026-03-06 12:40:31 -06:00
commit 363de27105
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
2 changed files with 26 additions and 15 deletions

View file

@ -312,7 +312,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();
}
}
@ -559,15 +559,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() {
@ -591,6 +592,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()) {
@ -811,7 +823,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;
@ -888,12 +900,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

@ -256,6 +256,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);