about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-11-14 20:45:15 +0100
committerGitHub <noreply@github.com>2024-11-14 20:45:15 +0100
commit8912909b98ef0ac835142cc7753cfdeefab3e259 (patch)
tree1c9884f7a6adc599b0d1a2b3f469d8e09035a057 /src/librustdoc/html
parentdd61213be45c127a3031bce131a3b5a819079338 (diff)
parent32500aa8e0f23029c0fa69235d19f770106c016f (diff)
downloadrust-8912909b98ef0ac835142cc7753cfdeefab3e259.tar.gz
rust-8912909b98ef0ac835142cc7753cfdeefab3e259.zip
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 https://github.com/rust-lang/rust/issues/133017
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/static/js/search.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 4e1bbbbf59d..a95a13aac47 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -2500,6 +2500,7 @@ class DocSearch {
         const sortResults = async(results, typeInfo, preferredCrate) => {
             const userQuery = parsedQuery.userQuery;
             const normalizedUserQuery = parsedQuery.userQuery.toLowerCase();
+            const isMixedCase = normalizedUserQuery !== userQuery;
             const result_list = [];
             for (const result of results.values()) {
                 result.item = this.searchIndex[result.id];
@@ -2511,10 +2512,12 @@ class DocSearch {
                 let a, b;
 
                 // sort by exact case-sensitive match
-                a = (aaa.item.name !== userQuery);
-                b = (bbb.item.name !== userQuery);
-                if (a !== b) {
-                    return a - b;
+                if (isMixedCase) {
+                    a = (aaa.item.name !== userQuery);
+                    b = (bbb.item.name !== userQuery);
+                    if (a !== b) {
+                        return a - b;
+                    }
                 }
 
                 // sort by exact match with regard to the last word (mismatch goes later)