Skip to content

add new panel to rustdoc search that shows up when the search bar is focused #129769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ table,
}
/* pseudo-element for holding the dropdown-arrow image; needs to be a separate thing
so that we can apply CSS-filters to change the arrow color in themes */
#crate-search-div::after {
#crate-search::after {
/* lets clicks through! */
pointer-events: none;
/* completely covers the underlying div */
Expand Down Expand Up @@ -1669,6 +1669,28 @@ a.tooltip:hover::after {
font-weight: normal;
}

/* panel that only shows up during searches */
#search-focus-panel {
position: absolute;
display: none;
background-color: var(--main-background-color);
border-width: 1px;
border-color: var(--border-color);
border-style: solid;
padding: 3px;
text-wrap: nowrap;
z-index: 1;
top: 0;
}

rustdoc-search {
position: relative;
}

rustdoc-search:focus-within #search-focus-panel {
display: block;
}

#src-sidebar {
width: 100%;
overflow: auto;
Expand Down
29 changes: 17 additions & 12 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
* @param {boolean} go_to_first
* @param {string} filterCrates
*/
async function showResults(results, go_to_first, filterCrates) {
async function showResults(results, go_to_first, _filterCrates) {
const search = searchState.outputElement();
if (go_to_first || (results.others.length === 1
&& getSettingValue("go-to-only-result") === "true")
Expand Down Expand Up @@ -2815,17 +2815,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
}
}

let crates = "";
if (rawSearchIndex.size > 1) {
crates = " in&nbsp;<div id=\"crate-search-div\"><select id=\"crate-search\">" +
"<option value=\"all crates\">all crates</option>";
for (const c of rawSearchIndex.keys()) {
crates += `<option value="${c}" ${c === filterCrates && "selected"}>${c}</option>`;
}
crates += "</select></div>";
}

let output = `<h1 class="search-results-title">Results${crates}</h1>`;
let output = "<h1 class=\"search-results-title\">Results</h1>";
if (results.query.error !== null) {
const error = results.query.error;
error.forEach((value, index) => {
Expand Down Expand Up @@ -3885,6 +3875,21 @@ ${item.displayPath}<span class="${type}">${name}</span>\
exports.execQuery = execQuery;
exports.parseQuery = parseQuery;
}


let crates = "Searching in ";
if (rawSearchIndex.size > 1) {
crates += "<select id=\"crate-search\">" +
"<option value=\"all crates\" selected>all crates</option>";
for (const c of rawSearchIndex.keys()) {
console.log(c);
crates += `<option value="${c}">${c}</option>`;
}
crates += "</select>";
} else {
crates += rawSearchIndex.keys().next().value;
}
document.getElementById("crate-search-div").innerHTML = crates;
}

if (typeof window !== "undefined") {
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ class RustdocSearchElement extends HTMLElement {
</a>
</div>
</form>
</nav>`;
</nav>
<div id="search-focus-panel"><div id="crate-search-div">loading crate list...</div></div>`;
}
}
window.customElements.define("rustdoc-search", RustdocSearchElement);
Loading