@@ -30,6 +30,9 @@ void BraveBookmarkProvider::Start(const AutocompleteInput& input,
30
30
// We need to bump the relevance of the bookmark if we ever want it to rank
31
31
// high enough to be the default match.
32
32
constexpr int kContainsQueryBump = 350 ;
33
+ // Note: This is in addition to the kContainsQueryBump.
34
+ constexpr int kExactTitleBump = 200 ;
35
+
33
36
bool modified = false ;
34
37
35
38
auto lower_text = base::ToLowerASCII (input.text ());
@@ -40,14 +43,40 @@ void BraveBookmarkProvider::Start(const AutocompleteInput& input,
40
43
41
44
// We only allow the bookmark to be the default match if the input is
42
45
// literally contained in the title or URL.
43
- auto lower_contents = base::ToLowerASCII (match.contents );
46
+ auto lower_description = base::ToLowerASCII (match.description );
44
47
auto bump_match =
45
- base::Contains (lower_contents , lower_text) ||
46
- base::Contains (base::ToLowerASCII (match. description ) , lower_text);
48
+ base::Contains (base::ToLowerASCII (match. contents ) , lower_text) ||
49
+ base::Contains (lower_description , lower_text);
47
50
if (!bump_match) {
48
51
continue ;
49
52
}
50
53
54
+ // By default |contents| is the folder the bookmark is in if there are no
55
+ // matches in the URL. Instead, we want to should show the URL that will be
56
+ // opened so the user knows what will happen when they select the result.
57
+ // Note: Bookmark paths are prefixed with a "/" to indicate they are
58
+ // relative to the bookmark root.
59
+ if (match.contents .starts_with (u" /" )) {
60
+ // This is the same formatting used on Bookmark URLs normally.
61
+ match.contents = url_formatter::FormatUrl (
62
+ match.destination_url ,
63
+ url_formatter::kFormatUrlOmitHTTPS |
64
+ url_formatter::kFormatUrlOmitDefaults |
65
+ url_formatter::kFormatUrlOmitTrivialSubdomains ,
66
+ base::UnescapeRule::SPACES, nullptr , nullptr , nullptr );
67
+ // In this scenario we're matching the title, so its okay to display no
68
+ // matches on the URL.
69
+ match.contents_class = {
70
+ ACMatchClassification (0 , ACMatchClassification::URL)};
71
+ }
72
+
73
+ // Additional bump if the title is an exact match - this helps people with
74
+ // short bookmark titles for jumping to pages (like "sa" for
75
+ // "chrome://settings/appearance")
76
+ if (lower_description == lower_text) {
77
+ match.relevance += kExactTitleBump ;
78
+ }
79
+
51
80
match.SetAllowedToBeDefault (input);
52
81
53
82
modified = true ;
0 commit comments