Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace QuickOpenDialog navigation keys with actions #103476

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions editor/gui/editor_quick_open_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,35 +538,32 @@ void QuickOpenResultContainer::handle_search_box_input(const Ref<InputEvent> &p_
}

Ref<InputEventKey> key_event = p_ie;
if (key_event.is_valid() && key_event->is_pressed()) {
bool move_selection = false;

switch (key_event->get_keycode()) {
case Key::UP:
case Key::DOWN:
case Key::PAGEUP:
case Key::PAGEDOWN: {
move_selection = true;
} break;
case Key::LEFT:
case Key::RIGHT: {
if (content_display_mode == QuickOpenDisplayMode::GRID) {
// Maybe strip off the shift modifier to allow non-selecting navigation by character?
if (key_event->get_modifiers_mask() == 0) {
move_selection = true;
}
}
} break;
default:
break; // Let the event through so it will reach the search box.
}
if (key_event.is_null() || !key_event->is_pressed()) {
return;
}

if (move_selection) {
_move_selection_index(key_event->get_keycode());
queue_redraw();
accept_event();
Key move_selection = Key::NONE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move_selection can be a bool here, like before, since there is not really any benefit to save the Key here, unless I miss something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_move_selection_index() takes Key argument. It's simpler this way than rewriting its logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but should we replace key_event->get_keycode() with move_selection then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the Key here is used as navigation enum, not actual key code. _move_selection_index() still somehow needs to decide what movement it should perform.

if (p_ie->is_action("ui_up", true)) {
move_selection = Key::UP;
} else if (p_ie->is_action("ui_down", true)) {
move_selection = Key::DOWN;
} else if (p_ie->is_action("ui_page_up")) {
move_selection = Key::PAGEUP;
} else if (p_ie->is_action("ui_page_down")) {
move_selection = Key::PAGEDOWN;
} else if (content_display_mode == QuickOpenDisplayMode::GRID) {
if (p_ie->is_action("ui_left", true)) {
move_selection = Key::LEFT;
} else if (p_ie->is_action("ui_right", true)) {
move_selection = Key::RIGHT;
}
}

if (move_selection != Key::NONE) {
_move_selection_index(key_event->get_keycode());
queue_redraw();
accept_event();
}
}

void QuickOpenResultContainer::_move_selection_index(Key p_key) {
Expand Down