Merge pull request #48467 from EricEzaM/editor-settings-shortcut-crash-fix

This commit is contained in:
Rémi Verschelde 2021-05-05 11:17:05 +02:00 committed by GitHub
commit cb84d33137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 12 deletions

View File

@ -270,16 +270,17 @@ void EditorSettingsDialog::_update_shortcuts() {
Array events; // Need to get the list of events into an array so it can be set as metadata on the item.
Vector<String> event_strings;
List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins().find(action_name).value();
// Remove all non-key events from the defaults.
for (List<Ref<InputEvent>>::Element *I = defaults.front(); I; I = I->next()) {
List<Ref<InputEvent>> all_default_events = InputMap::get_singleton()->get_builtins().find(action_name).value();
List<Ref<InputEventKey>> key_default_events;
// Remove all non-key events from the defaults. Only check keys, since we are in the editor.
for (List<Ref<InputEvent>>::Element *I = all_default_events.front(); I; I = I->next()) {
Ref<InputEventKey> k = I->get();
if (k.is_null()) {
I->erase();
if (k.is_valid()) {
key_default_events.push_back(k);
}
}
bool same_as_defaults = defaults.size() == action.inputs.size(); // Initially this is set to just whether the arrays are equal. Later we check the events if needed.
bool same_as_defaults = key_default_events.size() == action.inputs.size(); // Initially this is set to just whether the arrays are equal. Later we check the events if needed.
int count = 0;
for (List<Ref<InputEvent>>::Element *I = action.inputs.front(); I; I = I->next()) {
@ -288,12 +289,8 @@ void EditorSettingsDialog::_update_shortcuts() {
event_strings.push_back(I->get()->as_text());
// Only check if the events have been the same so far - once one fails, we don't need to check any more.
if (same_as_defaults) {
Ref<InputEventKey> k = defaults[count];
// Only check keys, since we are in the editor.
if (k.is_valid() && !defaults[count]->shortcut_match(I->get())) {
same_as_defaults = false;
}
if (same_as_defaults && !key_default_events[count]->shortcut_match(I->get())) {
same_as_defaults = false;
}
count++;
}