Add enter and escape shortcuts in input map editor

This commit is contained in:
Goldenlion5648 2026-03-10 18:54:11 -04:00
parent ca77be8d0a
commit a71749c884
2 changed files with 19 additions and 4 deletions

View file

@ -190,7 +190,7 @@ void EventListenerLineEdit::gui_input(const Ref<InputEvent> &p_event) {
}
accept_event();
if (!event_to_check->is_pressed() || event_to_check->is_echo() || event_to_check->is_match(event) || !_is_event_allowed(event_to_check)) {
if (event_to_check.is_null() || !event_to_check->is_pressed() || event_to_check->is_echo() || event_to_check->is_match(event) || !_is_event_allowed(event_to_check)) {
return;
}

View file

@ -44,8 +44,22 @@
void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection) {
if (p_event.is_valid()) {
event = p_event;
original_event = p_original_event;
// If there is already a binding set, let enter or escape confirm/cancel the popup.
if (event.is_valid()) {
Ref<InputEventKey> current_key = p_event;
// Without this is_visible() check, the gui would not open if the already bound
// keybind was escape.
if (is_visible()) {
if (current_key->get_physical_keycode() == Key::ENTER) {
_ok_pressed();
return;
}
if (current_key->get_physical_keycode() == Key::ESCAPE) {
_cancel_pressed();
return;
}
}
}
// If the event is changed to something which is not the same as the listener,
// clear out the event from the listener text box to avoid confusion.
@ -53,7 +67,8 @@ void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event, c
if (listener_event.is_valid() && !listener_event->is_match(p_event)) {
event_listener->clear_event();
}
event = p_event;
original_event = p_original_event;
// Update Label
event_as_text->set_text(EventListenerLineEdit::get_event_text(event, true));