Skip to content

Commit 8912909

Browse files
authored
Rollup merge of #133043 - notriddle:master, r=fmease
rustdoc-search: case-sensitive only when capitals are used This is the "smartcase" behavior, described by vim and dtolnay. Fixes#133017
2 parents dd61213 + 32500aa commit 8912909

4 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎src/librustdoc/html/static/js/search.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,7 @@ class DocSearch {
25002500
constsortResults=async(results,typeInfo,preferredCrate)=>{
25012501
constuserQuery=parsedQuery.userQuery;
25022502
constnormalizedUserQuery=parsedQuery.userQuery.toLowerCase();
2503+
constisMixedCase=normalizedUserQuery!==userQuery;
25032504
constresult_list=[];
25042505
for(constresultofresults.values()){
25052506
result.item=this.searchIndex[result.id];
@@ -2511,10 +2512,12 @@ class DocSearch {
25112512
leta,b;
25122513

25132514
// sort by exact case-sensitive match
2514-
a=(aaa.item.name!==userQuery);
2515-
b=(bbb.item.name!==userQuery);
2516-
if(a!==b){
2517-
returna-b;
2515+
if(isMixedCase){
2516+
a=(aaa.item.name!==userQuery);
2517+
b=(bbb.item.name!==userQuery);
2518+
if(a!==b){
2519+
returna-b;
2520+
}
25182521
}
25192522

25202523
// sort by exact match with regard to the last word (mismatch goes later)

‎tests/rustdoc-js-std/write.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
constEXPECTED=[
2+
{
3+
'query': 'write',
4+
'others': [
5+
{'path': 'std::fmt','name': 'write'},
6+
{'path': 'std::fs','name': 'write'},
7+
{'path': 'std::ptr','name': 'write'},
8+
{'path': 'std::fmt','name': 'Write'},
9+
{'path': 'std::io','name': 'Write'},
10+
{'path': 'std::hash::Hasher','name': 'write'},
11+
],
12+
},
13+
{
14+
'query': 'Write',
15+
'others': [
16+
{'path': 'std::fmt','name': 'Write'},
17+
{'path': 'std::io','name': 'Write'},
18+
{'path': 'std::fmt','name': 'write'},
19+
{'path': 'std::fs','name': 'write'},
20+
{'path': 'std::ptr','name': 'write'},
21+
{'path': 'std::hash::Hasher','name': 'write'},
22+
],
23+
},
24+
];

‎tests/rustdoc-js/case.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
constEXPECTED=[
2+
{
3+
'query': 'Foo',
4+
'others': [
5+
{'path': 'case','name': 'Foo','desc': 'Docs for Foo'},
6+
{'path': 'case','name': 'foo','desc': 'Docs for foo'},
7+
],
8+
},
9+
{
10+
'query': 'foo',
11+
'others': [
12+
// https://github.com/rust-lang/rust/issues/133017
13+
{'path': 'case','name': 'Foo','desc': 'Docs for Foo'},
14+
{'path': 'case','name': 'foo','desc': 'Docs for foo'},
15+
],
16+
},
17+
];

‎tests/rustdoc-js/case.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![allow(nonstandard_style)]
2+
3+
/// Docs for Foo
4+
pubstructFoo;
5+
6+
/// Docs for foo
7+
pubstructfoo;

0 commit comments

Comments
 (0)