aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorGeorge Marques2016-07-06 19:29:15 -0300
committerGeorge Marques2016-07-06 19:29:15 -0300
commit1bc8d1900fe68510e1e5a9cc08a7241d69690034 (patch)
tree6965a5d6c701126a93ada937abe5d01e1e2ce2db /tools
parent9238de4ea9fe444d2dcef8802f1a990b3c6a04b5 (diff)
downloadgodot-1bc8d1900fe68510e1e5a9cc08a7241d69690034.tar.gz
godot-1bc8d1900fe68510e1e5a9cc08a7241d69690034.tar.zst
godot-1bc8d1900fe68510e1e5a9cc08a7241d69690034.zip
Improve quick open sorting
Perfect matches and substrings will be shown first. Similar matches will be at the bottom. When they score is the same they're shown in the natural file system order.
Diffstat (limited to 'tools')
-rw-r--r--tools/editor/quick_open.cpp38
-rw-r--r--tools/editor/quick_open.h1
2 files changed, 25 insertions, 14 deletions
diff --git a/tools/editor/quick_open.cpp b/tools/editor/quick_open.cpp
index adb08b65d..e18dc584d 100644
--- a/tools/editor/quick_open.cpp
+++ b/tools/editor/quick_open.cpp
@@ -109,6 +109,17 @@ void EditorQuickOpen::_sbox_input(const InputEvent& p_ie) {
}
+float EditorQuickOpen::_path_cmp(String search, String path) const {
+
+ if (search == path) {
+ return 1.2f;
+ }
+ if (path.findn(search) != -1) {
+ return 1.1f;
+ }
+ return path.to_lower().similarity(search.to_lower());
+}
+
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< String, Ref<Texture> > > &list) {
if (!add_directories) {
@@ -130,17 +141,18 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< S
Pair< String, Ref<Texture> > pair;
pair.first = path;
pair.second = get_icon("folder", "FileDialog");
- if (list.size() > 0) {
- float this_sim = search_text.to_lower().similarity(path.to_lower());
- float other_sim = search_text.to_lower().similarity(list[0].first.to_lower());
+ if (search_text != String() && list.size() > 0) {
+
+ float this_sim = _path_cmp(search_text, path);
+ float other_sim = _path_cmp(list[0].first, path);
int pos = 1;
- while (pos < list.size() && this_sim < other_sim) {
- other_sim = search_text.to_lower().similarity(list[pos++].first.to_lower());
+ while (pos < list.size() && this_sim <= other_sim) {
+ other_sim = _path_cmp(list[pos++].first, path);
}
- pos = this_sim > other_sim ? pos - 1 : pos;
+ pos = this_sim >= other_sim ? pos - 1 : pos;
list.insert(pos, pair);
} else {
@@ -159,17 +171,17 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< S
pair.first = file;
pair.second = get_icon((has_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei);
- if (list.size() > 0) {
+ if (search_text != String() && list.size() > 0) {
- float this_sim = search_text.to_lower().similarity(file.to_lower());
- float other_sim = search_text.to_lower().similarity(list[0].first.to_lower());
+ float this_sim = _path_cmp(search_text, file);
+ float other_sim = _path_cmp(list[0].first, file);
int pos = 1;
- while (pos < list.size() && this_sim < other_sim) {
- other_sim = search_text.to_lower().similarity(list[pos++].first.to_lower());
+ while (pos < list.size() && this_sim <= other_sim) {
+ other_sim = _path_cmp(list[pos++].first, file);
}
- pos = this_sim > other_sim ? pos - 1 : pos;
+ pos = this_sim >= other_sim ? pos - 1 : pos;
list.insert(pos, pair);
} else {
@@ -198,8 +210,6 @@ void EditorQuickOpen::_update_search() {
_parse_fs(efsd, list);
- //String best_match = list[0];
-
for (int i = 0; i < list.size(); i++) {
TreeItem *ti = search_options->create_item(root);
ti->set_text(0, list[i].first);
diff --git a/tools/editor/quick_open.h b/tools/editor/quick_open.h
index 45527090b..c253f7606 100644
--- a/tools/editor/quick_open.h
+++ b/tools/editor/quick_open.h
@@ -49,6 +49,7 @@ class EditorQuickOpen : public ConfirmationDialog {
void _sbox_input(const InputEvent& p_ie);
void _parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< String,Ref <Texture> > > &list);
+ float _path_cmp(String search, String path) const;
void _confirmed();