@@ -228,7 +228,7 @@ void ProjectSettingsEditor::_device_input_add() {
228
228
int idx = edit_idx;
229
229
Dictionary old_val = ProjectSettings::get_singleton ()->get (name);
230
230
Dictionary action = old_val.duplicate ();
231
- Array events = action[" events" ];
231
+ Array events = action[" events" ]. duplicate () ;
232
232
233
233
switch (add_type) {
234
234
@@ -349,18 +349,34 @@ void ProjectSettingsEditor::_press_a_key_confirm() {
349
349
350
350
Dictionary old_val = ProjectSettings::get_singleton ()->get (name);
351
351
Dictionary action = old_val.duplicate ();
352
- Array events = action[" events" ];
352
+ Array old_events = action[" events" ];
353
353
354
- for (int i = 0 ; i < events .size (); i++) {
354
+ for (int i = 0 ; i < old_events .size (); i++) {
355
355
356
- Ref<InputEventKey> aie = events [i];
356
+ Ref<InputEventKey> aie = old_events [i];
357
357
if (aie.is_null ())
358
358
continue ;
359
359
if (aie->get_scancode_with_modifiers () == ie->get_scancode_with_modifiers ()) {
360
360
return ;
361
361
}
362
362
}
363
363
364
+ Dictionary init_val = ProjectSettings::get_singleton ()->property_get_revert (name);
365
+ Array init_events = init_val[" events" ];
366
+
367
+ // Re-use input from default values if possible
368
+ for (int i = 0 ; i < init_events.size (); i++) {
369
+
370
+ Ref<InputEventKey> aie = init_events[i];
371
+ if (aie.is_null ())
372
+ continue ;
373
+ if (aie->get_scancode_with_modifiers () == ie->get_scancode_with_modifiers ()) {
374
+ ie = aie;
375
+ break ;
376
+ }
377
+ }
378
+
379
+ Array events = old_events.duplicate ();
364
380
if (idx < 0 || idx >= events.size ()) {
365
381
events.push_back (ie);
366
382
} else {
@@ -613,7 +629,7 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column,
613
629
Dictionary action = old_val.duplicate ();
614
630
int idx = ti->get_metadata (0 );
615
631
616
- Array events = action[" events" ];
632
+ Array events = action[" events" ]. duplicate () ;
617
633
ERR_FAIL_INDEX (idx, events.size ());
618
634
events.remove (idx);
619
635
action[" events" ] = events;
0 commit comments