Skip to content

Commit 6fc9408

Browse files
committed
Show closest matches first
1 parent 9819b31 commit 6fc9408

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

plugins/fuzzy-search/file-item.vala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
*/
88

99
public class FileItem : Gtk.ListBoxRow {
10-
public SearchResult result { get; private set; }
10+
public SearchResult result { get; private set; }
1111

1212
public string filepath {
1313
get {
1414
return result.full_path;
1515
}
1616
}
17+
1718
public FileItem (SearchResult res, bool should_distinguish_project = false) {
1819
this.get_style_context ().add_class ("fuzzy-item");
1920
this.get_style_context ().add_class ("flat");

plugins/fuzzy-search/fuzzy-search-popover.vala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,19 @@ public class Scratch.FuzzySearchPopover : Gtk.Popover {
266266
scrolled.set_max_content_height (45 /* height */ * max_items);
267267

268268
current_doc_project = get_current_project (); // This will not change while popover is showing
269-
search_result_container.set_sort_func ((a ,b) => {
270-
var project_a_is_current = ((FileItem)a).result.project == current_doc_project;
271-
var project_b_is_current = ((FileItem)b).result.project == current_doc_project;
269+
search_result_container.set_sort_func ((a , b) => {
270+
var result_a = ((FileItem)a).result;
271+
var result_b = ((FileItem)b).result;
272+
var project_a_is_current = result_a.project == current_doc_project;
273+
var project_b_is_current = result_b.project == current_doc_project;
272274
if (project_a_is_current && !project_b_is_current) {
273275
return 1;
274276
} else if (project_b_is_current && !project_a_is_current) {
275277
return -1;
278+
} else if (result_a.score > result_b.score) {
279+
return -1;
280+
} else if (result_b.score > result_a.score) {
281+
return 1;
276282
} else {
277283
return strcmp (((FileItem)a).result.full_path, ((FileItem)b).result.full_path);
278284
}

0 commit comments

Comments
 (0)