diff options
| author | bors <bors@rust-lang.org> | 2023-06-16 15:02:22 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-16 15:02:22 +0000 | 
| commit | 6a94e87a54ecf2df307c65af2dbc2effb3a525b8 (patch) | |
| tree | 041edb9c881311512c705a2c27e48b50e10a9eba /src/librustdoc/html/static/js/search.js | |
| parent | 2304917aad2f18ee9a1c6969e1197c96dee907b6 (diff) | |
| parent | de85f7ff363a80ab0eefc6909edc24b5c99880c4 (diff) | |
| download | rust-6a94e87a54ecf2df307c65af2dbc2effb3a525b8.tar.gz rust-6a94e87a54ecf2df307c65af2dbc2effb3a525b8.zip | |
Auto merge of #110688 - GuillaumeGomez:result-search-type, r=notriddle,jsha
rustdoc: Add search result item types after their name Here what it looks like:  The idea is to improve accessibility by providing this information directly in the text and not only in the text color. Currently we already use it for doc aliases and for primitive types, so I extended it to all types. r? `@notriddle`
Diffstat (limited to 'src/librustdoc/html/static/js/search.js')
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 43 | 
1 files changed, 34 insertions, 9 deletions
| diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 25259971eff..e724bf1601a 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -35,6 +35,35 @@ const itemTypes = [ "traitalias", ]; +const longItemTypes = [ + "module", + "extern crate", + "re-export", + "struct", + "enum", + "function", + "type alias", + "static", + "trait", + "", + "trait method", + "method", + "struct field", + "enum variant", + "macro", + "primitive type", + "associated type", + "constant", + "associated constant", + "union", + "foreign type", + "keyword", + "existential type", + "attribute macro", + "derive macro", + "trait alias", +]; + // used for special search precedence const TY_PRIMITIVE = itemTypes.indexOf("primitive"); const TY_KEYWORD = itemTypes.indexOf("keyword"); @@ -1966,16 +1995,11 @@ function initSearch(rawSearchIndex) { array.forEach(item => { const name = item.name; const type = itemTypes[item.ty]; + const longType = longItemTypes[item.ty]; + const typeName = longType.length !== 0 ? `${longType}` : "?"; length += 1; - let extra = ""; - if (type === "primitive") { - extra = " <i>(primitive type)</i>"; - } else if (type === "keyword") { - extra = " <i>(keyword)</i>"; - } - const link = document.createElement("a"); link.className = "result-" + type; link.href = item.href; @@ -1993,13 +2017,14 @@ function initSearch(rawSearchIndex) { alias.insertAdjacentHTML( "beforeend", - "<span class=\"grey\"><i> - see </i></span>"); + "<i class=\"grey\"> - see </i>"); resultName.appendChild(alias); } + resultName.insertAdjacentHTML( "beforeend", - item.displayPath + "<span class=\"" + type + "\">" + name + extra + "</span>"); + `${typeName} ${item.displayPath}<span class="${type}">${name}</span>`); link.appendChild(resultName); const description = document.createElement("div"); | 
