3030
3131#include " input_event_editor_plugin.h"
3232
33+ #include " editor/editor_undo_redo_manager.h"
3334#include " editor/settings/event_listener_line_edit.h"
3435#include " editor/settings/input_event_configuration_dialog.h"
3536
@@ -51,8 +52,57 @@ void InputEventConfigContainer::_event_changed() {
5152
5253void InputEventConfigContainer::_config_dialog_confirmed () {
5354 Ref<InputEvent> ie = config_dialog->get_event ();
54- input_event->copy_from (ie);
55- _event_changed ();
55+
56+ EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
57+ undo_redo->create_action (TTR (" Event Configured" ));
58+
59+ // When command_or_control_autoremap is toggled to false, it should be set first;
60+ // and when it is toggled to true, it should be set last.
61+ bool will_toggle = false ;
62+ bool pending = false ;
63+ Ref<InputEventWithModifiers> iewm = input_event;
64+ if (iewm.is_valid ()) {
65+ Variant new_value = ie->get (" command_or_control_autoremap" );
66+ will_toggle = new_value != input_event->get (" command_or_control_autoremap" );
67+ if (will_toggle) {
68+ pending = new_value;
69+ if (pending) {
70+ undo_redo->add_undo_property (input_event.ptr (), " command_or_control_autoremap" , !pending);
71+ } else {
72+ undo_redo->add_do_property (input_event.ptr (), " command_or_control_autoremap" , pending);
73+ }
74+ }
75+ }
76+
77+ List<PropertyInfo> pi;
78+ ie->get_property_list (&pi);
79+ for (const PropertyInfo &E : pi) {
80+ if (E.name == " resource_path" ) {
81+ continue ; // Do not change path.
82+ }
83+ if (E.name == " command_or_control_autoremap" ) {
84+ continue ; // Handle it separately.
85+ }
86+ Variant old_value = input_event->get (E.name );
87+ Variant new_value = ie->get (E.name );
88+ if (old_value == new_value) {
89+ continue ;
90+ }
91+ undo_redo->add_do_property (input_event.ptr (), E.name , new_value);
92+ undo_redo->add_undo_property (input_event.ptr (), E.name , old_value);
93+ }
94+
95+ if (will_toggle) {
96+ if (pending) {
97+ undo_redo->add_do_property (input_event.ptr (), " command_or_control_autoremap" , pending);
98+ } else {
99+ undo_redo->add_undo_property (input_event.ptr (), " command_or_control_autoremap" , !pending);
100+ }
101+ }
102+
103+ undo_redo->add_do_property (input_event_text, " text" , ie->as_text ());
104+ undo_redo->add_undo_property (input_event_text, " text" , input_event->as_text ());
105+ undo_redo->commit_action ();
56106}
57107
58108void InputEventConfigContainer::set_event (const Ref<InputEvent> &p_event) {
0 commit comments