Skip to content

Commit 6815b4f

Browse files
committed
Improve Editor shortcut searching
1 parent 08e6cd1 commit 6815b4f

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

editor/settings/editor_settings_dialog.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ TreeItem *EditorSettingsDialog::_create_shortcut_treeitem(TreeItem *p_parent, co
486486
return shortcut_item;
487487
}
488488

489-
bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const {
489+
bool EditorSettingsDialog::_should_display_shortcut(const String &p_section, const String &p_section_tr, const String &p_name, const Array &p_events, bool p_match_localized_name) const {
490490
const Ref<InputEvent> search_ev = shortcut_search_bar->get_event();
491491
if (search_ev.is_valid()) {
492492
bool event_match = false;
@@ -509,9 +509,14 @@ bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const
509509
if (search_text.is_subsequence_ofn(p_name)) {
510510
return true;
511511
}
512+
// print_line("Got ", p_section, " and ", p_section_tr);
512513
if (p_match_localized_name && search_text.is_subsequence_ofn(TTR(p_name))) {
513514
return true;
514515
}
516+
// Always match translated section name.
517+
if (search_text.is_subsequence_ofn(p_section) || search_text.is_subsequence_ofn(p_section_tr)) {
518+
return true;
519+
}
515520

516521
return false;
517522
}
@@ -557,10 +562,15 @@ void EditorSettingsDialog::_update_shortcuts() {
557562
TreeItem *root = shortcuts->create_item();
558563
HashMap<String, TreeItem *> sections;
559564

565+
const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
566+
const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
567+
560568
// Set up section for Common/Built-in actions
561569
TreeItem *common_section = shortcuts->create_item(root);
562570
sections["Common"] = common_section;
563-
common_section->set_text(0, TTRC("Common"));
571+
common_section->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // Already translated manually.
572+
common_section->set_text(0, EditorPropertyNameProcessor::get_singleton()->process_name("Common", name_style));
573+
common_section->set_tooltip_text(0, EditorPropertyNameProcessor::get_singleton()->process_name("Common", tooltip_style));
564574
common_section->set_selectable(0, false);
565575
common_section->set_selectable(1, false);
566576
if (collapsed.has("Common")) {
@@ -581,7 +591,7 @@ void EditorSettingsDialog::_update_shortcuts() {
581591

582592
const List<Ref<InputEvent>> &all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name)->value;
583593
Array action_events = _event_list_to_array_helper(action.inputs);
584-
if (!_should_display_shortcut(action_name, action_events, false)) {
594+
if (!_should_display_shortcut(common_section->get_text(0), common_section->get_tooltip_text(0), action_name, action_events, false)) {
585595
continue;
586596
}
587597

@@ -602,9 +612,6 @@ void EditorSettingsDialog::_update_shortcuts() {
602612
EditorSettings::get_singleton()->get_shortcut_list(&slist);
603613
slist.sort(); // Sort alphabetically.
604614

605-
const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
606-
const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
607-
608615
// Create all sections first.
609616
for (const String &E : slist) {
610617
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
@@ -644,7 +651,7 @@ void EditorSettingsDialog::_update_shortcuts() {
644651
String section_name = E.get_slicec('/', 0);
645652
TreeItem *section = sections[section_name];
646653

647-
if (!_should_display_shortcut(sc->get_name(), sc->get_events(), true)) {
654+
if (!_should_display_shortcut(section->get_text(0), section->get_tooltip_text(0), sc->get_name(), sc->get_events(), true)) {
648655
continue;
649656
}
650657

editor/settings/editor_settings_dialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class EditorSettingsDialog : public AcceptDialog {
107107
PropertyInfo _create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name);
108108
String _get_shortcut_button_string(const String &p_shortcut_name);
109109

110-
bool _should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const;
110+
bool _should_display_shortcut(const String &p_section, const String &p_section_tr, const String &p_name, const Array &p_events, bool p_match_localized_name) const;
111111

112112
void _update_shortcuts();
113113
void _shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button = MouseButton::LEFT);

0 commit comments

Comments
 (0)