\
-
\
+
\
+ \
+ \
+
\
\
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 1c61e73fae03c..df7204c1b42b9 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -967,7 +967,7 @@ themePicker.onblur = handleThemeButtonsBlur;
&[(minifier::js::Keyword::Null, "N")]),
&dst);
}
- try_err!(writeln!(&mut w, "initSearch(searchIndex);"), &dst);
+ try_err!(writeln!(&mut w, "initSearch(searchIndex);addSearchOptions(searchIndex);"), &dst);
// Update the list of all implementors for traits
let dst = cx.dst.join("implementors");
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 6307dda454da8..82c1d54ebc599 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -259,12 +259,14 @@
//
// So I guess you could say things are getting pretty interoperable.
function getVirtualKey(ev) {
- if ("key" in ev && typeof ev.key != "undefined")
+ if ("key" in ev && typeof ev.key != "undefined") {
return ev.key;
+ }
var c = ev.charCode || ev.keyCode;
- if (c == 27)
+ if (c == 27) {
return "Escape";
+ }
return String.fromCharCode(c);
}
@@ -472,12 +474,13 @@
/**
* Executes the query and builds an index of results
- * @param {[Object]} query [The user query]
- * @param {[type]} searchWords [The list of search words to query
- * against]
- * @return {[type]} [A search index of results]
+ * @param {[Object]} query [The user query]
+ * @param {[type]} searchWords [The list of search words to query
+ * against]
+ * @param {[type]} filterCrates [Crate to search in if defined]
+ * @return {[type]} [A search index of results]
*/
- function execQuery(query, searchWords) {
+ function execQuery(query, searchWords, filterCrates) {
function itemTypeFromName(typename) {
for (var i = 0; i < itemTypes.length; ++i) {
if (itemTypes[i] === typename) {
@@ -853,6 +856,9 @@
{
val = extractGenerics(val.substr(1, val.length - 2));
for (var i = 0; i < nSearchWords; ++i) {
+ if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
+ continue;
+ }
var in_args = findArg(searchIndex[i], val, true);
var returned = checkReturned(searchIndex[i], val, true);
var ty = searchIndex[i];
@@ -907,6 +913,9 @@
var output = extractGenerics(parts[1]);
for (var i = 0; i < nSearchWords; ++i) {
+ if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
+ continue;
+ }
var type = searchIndex[i].type;
var ty = searchIndex[i];
if (!type) {
@@ -978,11 +987,11 @@
var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);
for (j = 0; j < nSearchWords; ++j) {
- var lev_distance;
var ty = searchIndex[j];
- if (!ty) {
+ if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) {
continue;
}
+ var lev_distance;
var lev_add = 0;
if (paths.length > 1) {
var lev = checkPath(contains, paths[paths.length - 1], ty);
@@ -1358,7 +1367,7 @@
return '
' + text + '
(' + nbElems + ')
';
}
- function showResults(results) {
+ function showResults(results, filterCrates) {
if (results['others'].length === 1 &&
getCurrentValue('rustdoc-go-to-only-result') === "true") {
var elem = document.createElement('a');
@@ -1376,8 +1385,13 @@
var ret_in_args = addTab(results['in_args'], query, false);
var ret_returned = addTab(results['returned'], query, false);
+ var filter = "";
+ if (filterCrates !== undefined) {
+ filter = " (in
" + filterCrates + " crate)";
+ }
+
var output = '
Results for ' + escape(query.query) +
- (query.type ? ' (type: ' + escape(query.type) + ')' : '') + '
' +
+ (query.type ? ' (type: ' + escape(query.type) + ')' : '') + filter + '' +
'
' +
makeTabHeader(0, "In Names", ret_others[1]) +
makeTabHeader(1, "In Parameters", ret_in_args[1]) +
@@ -1406,7 +1420,7 @@
printTab(currentTab);
}
- function execSearch(query, searchWords) {
+ function execSearch(query, searchWords, filterCrates) {
var queries = query.raw.split(",");
var results = {
'in_args': [],
@@ -1417,7 +1431,7 @@
for (var i = 0; i < queries.length; ++i) {
var query = queries[i].trim();
if (query.length !== 0) {
- var tmp = execQuery(getQuery(query), searchWords);
+ var tmp = execQuery(getQuery(query), searchWords, filterCrates);
results['in_args'].push(tmp['in_args']);
results['returned'].push(tmp['returned']);
@@ -1479,7 +1493,16 @@
}
}
- function search(e) {
+ function getFilterCrates() {
+ var elem = document.getElementById("crate-search");
+
+ if (elem && elem.value !== "All crates" && rawSearchIndex.hasOwnProperty(elem.value)) {
+ return elem.value;
+ }
+ return undefined;
+ }
+
+ function search(e, forced) {
var params = getQueryStringParams();
var query = getQuery(search_input.value.trim());
@@ -1487,7 +1510,10 @@
e.preventDefault();
}
- if (query.query.length === 0 || query.id === currentResults) {
+ if (query.query.length === 0) {
+ return;
+ }
+ if (forced !== true && query.id === currentResults) {
if (query.query.length > 0) {
putBackSearch(search_input);
}
@@ -1507,7 +1533,8 @@
}
}
- showResults(execSearch(query, index));
+ var filterCrates = getFilterCrates();
+ showResults(execSearch(query, index, filterCrates), filterCrates);
}
function buildIndex(rawSearchIndex) {
@@ -1607,6 +1634,13 @@
};
search_input.onpaste = search_input.onchange;
+ var selectCrate = document.getElementById('crate-search');
+ if (selectCrate) {
+ selectCrate.onchange = function() {
+ search(undefined, true);
+ };
+ }
+
// Push and pop states are used to add search results to the browser
// history.
if (browserSupportsHistoryApi()) {
@@ -2283,6 +2317,39 @@
if (window.location.hash && window.location.hash.length > 0) {
expandSection(window.location.hash.replace(/^#/, ''));
}
+
+ function addSearchOptions(crates) {
+ var elem = document.getElementById('crate-search');
+
+ if (!elem) {
+ return;
+ }
+ var crates_text = [];
+ for (var crate in crates) {
+ if (crates.hasOwnProperty(crate)) {
+ crates_text.push(crate);
+ }
+ }
+ crates_text.sort(function(a, b) {
+ var lower_a = a.toLowerCase();
+ var lower_b = b.toLowerCase();
+
+ if (lower_a < lower_b) {
+ return -1;
+ } else if (lower_a > lower_b) {
+ return 1;
+ }
+ return 0;
+ });
+ for (var i = 0; i < crates_text.length; ++i) {
+ var option = document.createElement("option");
+ option.value = crates_text[i];
+ option.innerText = crates_text[i];
+ elem.appendChild(option);
+ }
+ }
+
+ window.addSearchOptions = addSearchOptions;
}());
// Sets the focus on the search bar at the top of the page
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index ee811f3379239..ac4a54b5219f1 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -588,13 +588,32 @@ a {
.search-container {
position: relative;
}
+.search-container > div {
+ display: inline-flex;
+ width: calc(100% - 34px);
+}
+#crate-search {
+ margin-top: 5px;
+ padding: 6px;
+ padding-right: 12px;
+ border: 0;
+ border-right: 0;
+ border-radius: 4px 0 0 4px;
+ outline: none;
+ cursor: pointer;
+ border-right: 1px solid;
+ -moz-appearance: none;
+ -webkit-appearance: none;
+ /* Removes default arrow from firefox */
+ text-indent: 0.01px;
+ text-overflow: "";
+}
.search-container > .top-button {
position: absolute;
right: 0;
top: 10px;
}
.search-input {
- width: calc(100% - 34px);
/* Override Normalize.css: we have margins and do
not want to overflow - the `moz` attribute is necessary
until Firefox 29, too early to drop at this point */
@@ -602,13 +621,14 @@ a {
box-sizing: border-box !important;
outline: none;
border: none;
- border-radius: 1px;
+ border-radius: 0 1px 1px 0;
margin-top: 5px;
padding: 10px 16px;
font-size: 17px;
transition: border-color 300ms ease;
transition: border-radius 300ms ease-in-out;
transition: box-shadow 300ms ease-in-out;
+ width: 100%;
}
.search-input:focus {
diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css
index 34a1d71beecfc..2ed1904b6d018 100644
--- a/src/librustdoc/html/static/themes/dark.css
+++ b/src/librustdoc/html/static/themes/dark.css
@@ -182,9 +182,15 @@ a.test-arrow {
color: #999;
}
+#crate-search {
+ color: #111;
+ background-color: #f0f0f0;
+ border-color: #000;
+}
+
.search-input {
color: #111;
- box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent;
+ box-shadow: 1px 0 0 1px #000, 0 0 0 2px transparent;
background-color: #f0f0f0;
}
diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css
index 8218b1b371ea7..167e65df821dc 100644
--- a/src/librustdoc/html/static/themes/light.css
+++ b/src/librustdoc/html/static/themes/light.css
@@ -182,9 +182,16 @@ a.test-arrow {
color: #999;
}
+#crate-search {
+ color: #555;
+ background-color: white;
+ border-color: #e0e0e0;
+ box-shadow: 0px 0 0 1px #e0e0e0, 0 0 0 2px transparent;
+}
+
.search-input {
color: #555;
- box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent;
+ box-shadow: 1px 0 0 1px #e0e0e0, 0 0 0 2px transparent;
background-color: white;
}
diff --git a/src/test/rustdoc-js/filter-crate.js b/src/test/rustdoc-js/filter-crate.js
new file mode 100644
index 0000000000000..69c959a6ef21c
--- /dev/null
+++ b/src/test/rustdoc-js/filter-crate.js
@@ -0,0 +1,20 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 or the MIT license
+// , at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// should-fail
+
+const QUERY = 'string';
+const FILTER_CRATE = 'core';
+
+const EXPECTED = {
+ 'others': [
+ { 'path': 'std::collections', 'name': 'VecDeque' },
+ ],
+};
diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js
index c8ce4cf8bb5be..f7c30df9f3ebb 100644
--- a/src/tools/rustdoc-js/tester.js
+++ b/src/tools/rustdoc-js/tester.js
@@ -259,6 +259,7 @@ function main(argv) {
'exports.QUERY = QUERY;exports.EXPECTED = EXPECTED;');
const expected = loadedFile.EXPECTED;
const query = loadedFile.QUERY;
+ const filter_crate = loadedFile.FILTER_CRATE;
const ignore_order = loadedFile.ignore_order;
const exact_check = loadedFile.exact_check;
const should_fail = loadedFile.should_fail;