Add search result item types after their name
This commit is contained in:
parent
fabf929863
commit
741d210c44
2 changed files with 36 additions and 11 deletions
|
@ -213,7 +213,7 @@ a.anchor,
|
||||||
h1 a,
|
h1 a,
|
||||||
.search-results a,
|
.search-results a,
|
||||||
.stab,
|
.stab,
|
||||||
.result-name .primitive > i, .result-name .keyword > i {
|
.result-name i {
|
||||||
color: var(--main-color);
|
color: var(--main-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,7 +887,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
|
||||||
.search-results .result-name span.alias {
|
.search-results .result-name span.alias {
|
||||||
color: var(--search-results-alias-color);
|
color: var(--search-results-alias-color);
|
||||||
}
|
}
|
||||||
.search-results .result-name span.grey {
|
.search-results .result-name .grey {
|
||||||
color: var(--search-results-grey-color);
|
color: var(--search-results-grey-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,35 @@ const itemTypes = [
|
||||||
"traitalias",
|
"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
|
// used for special search precedence
|
||||||
const TY_PRIMITIVE = itemTypes.indexOf("primitive");
|
const TY_PRIMITIVE = itemTypes.indexOf("primitive");
|
||||||
const TY_KEYWORD = itemTypes.indexOf("keyword");
|
const TY_KEYWORD = itemTypes.indexOf("keyword");
|
||||||
|
@ -1836,16 +1865,11 @@ function initSearch(rawSearchIndex) {
|
||||||
array.forEach(item => {
|
array.forEach(item => {
|
||||||
const name = item.name;
|
const name = item.name;
|
||||||
const type = itemTypes[item.ty];
|
const type = itemTypes[item.ty];
|
||||||
|
const longType = longItemTypes[item.ty];
|
||||||
|
let extra = longType.length !== 0 ? ` <i>(${longType})</i>` : "";
|
||||||
|
|
||||||
length += 1;
|
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");
|
const link = document.createElement("a");
|
||||||
link.className = "result-" + type;
|
link.className = "result-" + type;
|
||||||
link.href = item.href;
|
link.href = item.href;
|
||||||
|
@ -1854,6 +1878,7 @@ function initSearch(rawSearchIndex) {
|
||||||
resultName.className = "result-name";
|
resultName.className = "result-name";
|
||||||
|
|
||||||
if (item.is_alias) {
|
if (item.is_alias) {
|
||||||
|
extra = "";
|
||||||
const alias = document.createElement("span");
|
const alias = document.createElement("span");
|
||||||
alias.className = "alias";
|
alias.className = "alias";
|
||||||
|
|
||||||
|
@ -1863,13 +1888,13 @@ function initSearch(rawSearchIndex) {
|
||||||
|
|
||||||
alias.insertAdjacentHTML(
|
alias.insertAdjacentHTML(
|
||||||
"beforeend",
|
"beforeend",
|
||||||
"<span class=\"grey\"><i> - see </i></span>");
|
"<i class=\"grey\"> - see </i>");
|
||||||
|
|
||||||
resultName.appendChild(alias);
|
resultName.appendChild(alias);
|
||||||
}
|
}
|
||||||
resultName.insertAdjacentHTML(
|
resultName.insertAdjacentHTML(
|
||||||
"beforeend",
|
"beforeend",
|
||||||
item.displayPath + "<span class=\"" + type + "\">" + name + extra + "</span>");
|
item.displayPath + "<span class=\"" + type + "\">" + name + "</span>" + extra);
|
||||||
link.appendChild(resultName);
|
link.appendChild(resultName);
|
||||||
|
|
||||||
const description = document.createElement("div");
|
const description = document.createElement("div");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue