summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-10-15 14:40:40 +0200
committerGitHub <noreply@github.com>2021-10-15 14:40:40 +0200
commit5bc0e4081bbfa077567e1d94b760f81c63eb3392 (patch)
treecc47866bf0d6c8b07036b5c19f16b1a63e0b3b54
parente53e897b8c70cef11a2a0b13edbad9f038f26e58 (diff)
parent7e435fa84195e18b72abf8a06d7fc014275cbd7d (diff)
Merge pull request #53753 from EricEzaM/fix-shortcut-saving
-rw-r--r--editor/editor_settings.cpp33
-rw-r--r--editor/settings_config_dialog.cpp2
2 files changed, 20 insertions, 15 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 43d458c58e..223cc6650c 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -140,32 +140,37 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name == "shortcuts") {
Array save_array;
+ const OrderedHashMap<String, List<Ref<InputEvent>>> &builtin_list = InputMap::get_singleton()->get_builtins();
for (const KeyValue<String, Ref<Shortcut>> &shortcut_definition : shortcuts) {
Ref<Shortcut> sc = shortcut_definition.value;
- if (builtin_action_overrides.has(shortcut_definition.key)) {
+ if (builtin_list.has(shortcut_definition.key)) {
// This shortcut was auto-generated from built in actions: don't save.
+ // If the builtin is overriden, it will be saved in the "builtin_action_overrides" section below.
continue;
}
- if (optimize_save) {
- if (!sc->has_meta("original")) {
- continue; //this came from settings but is not any longer used
- }
+ Array shortcut_events = sc->get_events();
+
+ Dictionary dict;
+ dict["name"] = shortcut_definition.key;
+ dict["shortcuts"] = shortcut_events;
+
+ if (!sc->has_meta("original")) {
+ // Getting the meta when it doesn't exist will return an empty array. If the 'shortcut_events' have been cleared,
+ // we still want save the shortcut in this case so that shortcuts that the user has customised are not reset,
+ // even if the 'original' has not been populated yet. This can happen when calling save() from the Project Manager.
+ save_array.push_back(dict);
+ continue;
}
Array original_events = sc->get_meta("original");
- Array shortcut_events = sc->get_events();
bool is_same = Shortcut::is_event_array_equal(original_events, shortcut_events);
if (is_same) {
continue; // Not changed from default; don't save.
}
- Dictionary dict;
- dict["name"] = shortcut_definition.key;
- dict["shortcuts"] = shortcut_events;
-
save_array.push_back(dict);
}
r_ret = save_array;
@@ -1511,7 +1516,7 @@ void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, c
// Directly override the existing shortcut.
sc->set_events(events);
- sc->set_meta("original", events);
+ sc->set_meta("original", events.duplicate(true));
}
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode) {
@@ -1545,21 +1550,21 @@ Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, cons
sc.instantiate();
sc->set_name(p_name);
sc->set_events(events);
- sc->set_meta("original", events);
+ sc->set_meta("original", events.duplicate(true));
return sc;
}
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
if (sc.is_valid()) {
sc->set_name(p_name); //keep name (the ones that come from disk have no name)
- sc->set_meta("original", events); //to compare against changes
+ sc->set_meta("original", events.duplicate(true)); //to compare against changes
return sc;
}
sc.instantiate();
sc->set_name(p_name);
sc->set_events(events);
- sc->set_meta("original", events); //to compare against changes
+ sc->set_meta("original", events.duplicate(true)); //to compare against changes
EditorSettings::get_singleton()->add_shortcut(p_path, sc);
return sc;
diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp
index 9062169e06..78dc85aa7d 100644
--- a/editor/settings_config_dialog.cpp
+++ b/editor/settings_config_dialog.cpp
@@ -433,7 +433,7 @@ void EditorSettingsDialog::_update_shortcuts() {
}
Array original = sc->get_meta("original");
- Array shortcuts_array = sc->get_events();
+ Array shortcuts_array = sc->get_events().duplicate(true);
bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);
bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);