From a72157c45620b55baefbcfec83c5d169de30e3a0 Mon Sep 17 00:00:00 2001 From: Kasper Arnklit Frandsen Date: Wed, 20 Nov 2024 15:46:51 +0000 Subject: [PATCH] Fix undo redo for the texture region editor --- .../plugins/texture_region_editor_plugin.cpp | 22 +++++++++++++++++++ editor/plugins/texture_region_editor_plugin.h | 1 + 2 files changed, 23 insertions(+) diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index bd653e4eedaa..0dcc89f6c3df 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -1107,12 +1107,34 @@ Vector2 TextureRegionEditor::snap_point(Vector2 p_target) const { return p_target; } +void TextureRegionEditor::shortcut_input(const Ref &p_event) { + const Ref k = p_event; + if (k.is_valid() && k->is_pressed()) { + bool handled = false; + + if (ED_IS_SHORTCUT("ui_undo", p_event)) { + EditorNode::get_singleton()->undo(); + handled = true; + } + + if (ED_IS_SHORTCUT("ui_redo", p_event)) { + EditorNode::get_singleton()->redo(); + handled = true; + } + + if (handled) { + set_input_as_handled(); + } + } +} + void TextureRegionEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_rect"), &TextureRegionEditor::_update_rect); } TextureRegionEditor::TextureRegionEditor() { set_title(TTR("Region Editor")); + set_process_shortcut_input(true); set_ok_button_text(TTR("Close")); // A power-of-two value works better as a default grid size. diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h index 0e71ec16e0c5..33650e08515e 100644 --- a/editor/plugins/texture_region_editor_plugin.h +++ b/editor/plugins/texture_region_editor_plugin.h @@ -141,6 +141,7 @@ class TextureRegionEditor : public AcceptDialog { protected: void _notification(int p_what); + virtual void shortcut_input(const Ref &p_event) override; static void _bind_methods(); void _texture_preview_draw();