Skip to content

Commit

Permalink
update for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
a-johnston committed Oct 24, 2024
1 parent bd54249 commit 00703df
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 48 deletions.
9 changes: 4 additions & 5 deletions core/string/fuzzy_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@

#include "fuzzy_search.h"

#include "core/string/ustring.h"
#include "core/variant/variant.h"

const float cull_factor = 0.1f;
const float cull_cutoff = 30.0f;
constexpr float cull_factor = 0.1f;
constexpr float cull_cutoff = 30.0f;
const String boundary_chars = "/\\-_.";

bool is_valid_interval(const Vector2i &p_interval) {
Expand Down Expand Up @@ -201,7 +200,7 @@ void FuzzySearchResult::add_token_match(const FuzzyTokenMatch &p_match) {
token_matches.append(p_match);
}

void remove_low_scores(Vector<FuzzySearchResult> &p_results, const float p_cull_score) {
void remove_low_scores(Vector<FuzzySearchResult> &p_results, float p_cull_score) {
// Removes all results with score < p_cull_score in-place.
int i = 0;
int j = p_results.size() - 1;
Expand Down Expand Up @@ -266,7 +265,7 @@ void FuzzySearch::sort_and_filter(Vector<FuzzySearchResult> &p_results) const {
void FuzzySearch::set_query(const String &p_query) {
tokens.clear();
for (const String &string : p_query.split(" ", false)) {
tokens.append({ (int)tokens.size(), string });
tokens.append({ static_cast<int>(tokens.size()), string });
}

case_sensitive = !p_query.is_lowercase();
Expand Down
2 changes: 1 addition & 1 deletion core/string/fuzzy_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class FuzzyTokenMatch;

struct FuzzySearchToken {
int idx;
int idx = -1;
String string;

bool try_exact_match(FuzzyTokenMatch &p_match, const String &p_target, int p_offset) const;
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
If [code]true[/code], results will include files located in the [code]addons[/code] folder.
</member>
<member name="filesystem/quick_open_dialog/max_fuzzy_misses" type="int" setter="" getter="">
The number of allowed character misses in a match, if fuzzy matching is enabled.
The number of allowed missed query characters in a match, if fuzzy matching is enabled. For example, with the default value of 2, [code]foobar[/code] would match [code]foobur[/code] and [code]foob[/code] but not [code]foo[/code].
</member>
<member name="filesystem/quick_open_dialog/max_results" type="int" setter="" getter="">
Maximum number of matches to show in dialog.
Expand Down
75 changes: 34 additions & 41 deletions editor/gui/editor_quick_open_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,52 +183,45 @@ QuickOpenResultContainer::QuickOpenResultContainer() {
}

{
// Bottom bar
HBoxContainer *bottom_bar = memnew(HBoxContainer);
bottom_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_child(bottom_bar);

// Selected filepath
file_details_path = memnew(Label);
file_details_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
file_details_path->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
file_details_path->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
bottom_bar->add_child(file_details_path);
add_child(file_details_path);
}

{
HBoxContainer *hbc = memnew(HBoxContainer);
hbc->add_theme_constant_override("separation", 3);
bottom_bar->add_child(hbc);

Label *fuzzy_search_label = memnew(Label);
fuzzy_search_label->set_text(TTR("Fuzzy Search"));
hbc->add_child(fuzzy_search_label);

fuzzy_search_toggle = memnew(CheckButton);
style_button(fuzzy_search_toggle);
fuzzy_search_toggle->set_tooltip_text(TTR("Enable fuzzy matching"));
fuzzy_search_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_fuzzy_search));
hbc->add_child(fuzzy_search_toggle);

Label *include_addons_label = memnew(Label);
include_addons_label->set_text(TTR("Addons"));
hbc->add_child(include_addons_label);

include_addons_toggle = memnew(CheckButton);
style_button(include_addons_toggle);
include_addons_toggle->set_tooltip_text(TTR("Include files from addons"));
include_addons_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_include_addons));
hbc->add_child(include_addons_toggle);

VSeparator *vsep = memnew(VSeparator);
vsep->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
vsep->set_custom_minimum_size(Size2i(0, 14 * EDSCALE));
hbc->add_child(vsep);

display_mode_toggle = memnew(Button);
style_button(display_mode_toggle);
display_mode_toggle->connect(SceneStringName(pressed), callable_mp(this, &QuickOpenResultContainer::_toggle_display_mode));
hbc->add_child(display_mode_toggle);
}
{
// Bottom bar
HBoxContainer *bottom_bar = memnew(HBoxContainer);
bottom_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
bottom_bar->set_alignment(ALIGNMENT_END);
bottom_bar->add_theme_constant_override("separation", 3);
add_child(bottom_bar);

fuzzy_search_toggle = memnew(CheckButton);
style_button(fuzzy_search_toggle);
fuzzy_search_toggle->set_text(TTR("Fuzzy Search"));
fuzzy_search_toggle->set_tooltip_text(TTR("Enable fuzzy matching"));
fuzzy_search_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_fuzzy_search));
bottom_bar->add_child(fuzzy_search_toggle);

include_addons_toggle = memnew(CheckButton);
style_button(include_addons_toggle);
include_addons_toggle->set_text(TTR("Addons"));
include_addons_toggle->set_tooltip_text(TTR("Include files from addons"));
include_addons_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_include_addons));
bottom_bar->add_child(include_addons_toggle);

VSeparator *vsep = memnew(VSeparator);
vsep->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
vsep->set_custom_minimum_size(Size2i(0, 14 * EDSCALE));
bottom_bar->add_child(vsep);

display_mode_toggle = memnew(Button);
style_button(display_mode_toggle);
display_mode_toggle->connect(SceneStringName(pressed), callable_mp(this, &QuickOpenResultContainer::_toggle_display_mode));
bottom_bar->add_child(display_mode_toggle);
}
}

Expand Down

0 comments on commit 00703df

Please sign in to comment.