@@ -445,6 +445,21 @@ if (!DOMTokenList.prototype.remove) {
445445 var OUTPUT_DATA = 1 ;
446446 var params = getQueryStringParams ( ) ;
447447
448+ // Set the crate filter from saved storage, if the current page has the saved crate filter.
449+ //
450+ // If not, ignore the crate filter -- we want to support filtering for crates on sites like
451+ // doc.rust-lang.org where the crates may differ from page to page while on the same domain.
452+ var savedCrate = getCurrentValue ( "rustdoc-saved-filter-crate" ) ;
453+ if ( savedCrate !== null ) {
454+ onEachLazy ( document . getElementById ( "crate-search" ) . getElementsByTagName ( "option" ) ,
455+ function ( e ) {
456+ if ( e . value === savedCrate ) {
457+ document . getElementById ( "crate-search" ) . value = e . value ;
458+ return true ;
459+ }
460+ } ) ;
461+ }
462+
448463 // Populate search bar with query string search term when provided,
449464 // but only if the input bar is empty. This avoid the obnoxious issue
450465 // where you start trying to do a search, and the index loads, and
@@ -1658,9 +1673,10 @@ if (!DOMTokenList.prototype.remove) {
16581673 } ;
16591674 search_input . onpaste = search_input . onchange ;
16601675
1661- var selectCrate = document . getElementById ( ' crate-search' ) ;
1676+ var selectCrate = document . getElementById ( " crate-search" ) ;
16621677 if ( selectCrate ) {
16631678 selectCrate . onchange = function ( ) {
1679+ updateLocalStorage ( "rustdoc-saved-filter-crate" , selectCrate . value ) ;
16641680 search ( undefined , true ) ;
16651681 } ;
16661682 }
@@ -2496,7 +2512,7 @@ if (!DOMTokenList.prototype.remove) {
24962512 }
24972513
24982514 function addSearchOptions ( crates ) {
2499- var elem = document . getElementById ( ' crate-search' ) ;
2515+ var elem = document . getElementById ( " crate-search" ) ;
25002516
25012517 if ( ! elem ) {
25022518 return ;
0 commit comments