diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 28df8d3f011fe..531c20a4f7b5f 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -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 */ @@ -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; diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index be0ec425946c2..4e8bc6d5047f4 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -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") @@ -2815,17 +2815,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\ } } - let crates = ""; - if (rawSearchIndex.size > 1) { - crates = " in <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) => { @@ -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") { diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js index 4a27ca92fff38..18c67c3bf6e47 100644 --- a/src/librustdoc/html/static/js/storage.js +++ b/src/librustdoc/html/static/js/storage.js @@ -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);