diff options
author | Shivansh Anand <shivansh586@gmail.com> | 2019-11-13 00:15:14 +0530 |
---|---|---|
committer | Shivansh Anand <shivansh586@gmail.com> | 2020-04-29 10:12:32 +0200 |
commit | 8c66d800993e6c5884123fbb8ca868727830f717 (patch) | |
tree | 4557db3a60b6946d7d7ff3e6b308182ae9b14d53 | |
parent | 5cae0f3402a2cc8b336fc6669e553a8b419c3564 (diff) |
Make Quick Open substring match more specific.
When finding a substring, the rating is biased towards substrings
at the end of the path.
Fixes #33504.
-rw-r--r-- | editor/quick_open.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp index 1b4439f0a8..b872bc3dd4 100644 --- a/editor/quick_open.cpp +++ b/editor/quick_open.cpp @@ -113,12 +113,18 @@ void EditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) { float EditorQuickOpen::_path_cmp(String search, String path) const { + // Exact match. if (search == path) { return 1.2f; } - if (path.findn(search) != -1) { - return 1.1f; + + // Substring match, with positive bias for matches close to the end of the path. + int pos = path.rfindn(search); + if (pos != -1) { + return 1.1f + 0.09 / (path.length() - pos + 1); } + + // Similarity. return path.to_lower().similarity(search.to_lower()); } |