diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 8569abeb09cc1..ba92ac7bd306e 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -454,12 +454,16 @@ var obj = searchIndex[results[i].id]; obj.lev = results[i].lev; if (isType !== true || obj.type) { + var res = buildHrefAndPath(obj); + obj.displayPath = pathSplitter(res[0]); + obj.fullPath = obj.displayPath + obj.name; + obj.href = res[1]; out.push(obj); + if (out.length >= MAX_RESULTS) { + break; + } } } - if (out.length >= MAX_RESULTS) { - break; - } } return out; } @@ -1017,6 +1021,12 @@ ALIASES[window.currentCrate][query.raw]) { var aliases = ALIASES[window.currentCrate][query.raw]; for (var i = 0; i < aliases.length; ++i) { + aliases[i].is_alias = true; + aliases[i].alias = query.raw; + var res = buildHrefAndPath(aliases[i]); + aliases[i].displayPath = pathSplitter(res[0]); + aliases[i].fullPath = aliases[i].displayPath + aliases[i].name; + aliases[i].href = res[1]; ret['others'].unshift(aliases[i]); if (ret['others'].length > MAX_RESULTS) { ret['others'].pop(); @@ -1179,16 +1189,6 @@ }; } - function escape(content) { - var h1 = document.createElement('h1'); - h1.textContent = content; - return h1.innerHTML; - } - - function pathSplitter(path) { - return '' + path.replace(/::/g, '::'); - } - function buildHrefAndPath(item) { var displayPath; var href; @@ -1227,6 +1227,16 @@ return [displayPath, href]; } + function escape(content) { + var h1 = document.createElement('h1'); + h1.textContent = content; + return h1.innerHTML; + } + + function pathSplitter(path) { + return '' + path.replace(/::/g, '::'); + } + function addTab(array, query, display) { var extraStyle = ''; if (display === false) { @@ -1234,12 +1244,13 @@ } var output = ''; + var duplicates = {}; if (array.length > 0) { output = ''; var shown = []; array.forEach(function(item) { - var name, type, href, displayPath; + var name, type; var id_ty = item.ty + item.path + item.name; if (shown.indexOf(id_ty) !== -1) { @@ -1250,15 +1261,23 @@ name = item.name; type = itemTypes[item.ty]; - var res = buildHrefAndPath(item); - var href = res[1]; - var displayPath = res[0]; + if (item.is_alias !== true) { + var fullPath = item.displayPath + name; + + if (duplicates[fullPath]) { + return; + } + duplicates[fullPath] = true; + } output += ''; }); @@ -1284,8 +1303,7 @@ if (results['others'].length === 1 && getCurrentValue('rustdoc-go-to-only-result') === "true") { var elem = document.createElement('a'); - var res = buildHrefAndPath(results['others'][0]); - elem.href = res[1]; + elem.href = results['others'][0].href; elem.style.display = 'none'; // For firefox, we need the element to be in the DOM so it can be clicked. document.body.appendChild(elem); @@ -1347,12 +1365,13 @@ } } if (queries.length > 1) { - function getSmallest(arrays, positions) { + function getSmallest(arrays, positions, notDuplicates) { var start = null; for (var it = 0; it < positions.length; ++it) { if (arrays[it].length > positions[it] && - (start === null || start > arrays[it][positions[it]].lev)) { + (start === null || start > arrays[it][positions[it]].lev) && + !notDuplicates[arrays[it][positions[it]].fullPath]) { start = arrays[it][positions[it]].lev; } } @@ -1362,19 +1381,23 @@ function mergeArrays(arrays) { var ret = []; var positions = []; + var notDuplicates = {}; for (var x = 0; x < arrays.length; ++x) { positions.push(0); } while (ret.length < MAX_RESULTS) { - var smallest = getSmallest(arrays, positions); + var smallest = getSmallest(arrays, positions, notDuplicates); + if (smallest === null) { break; } for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) { if (arrays[x].length > positions[x] && - arrays[x][positions[x]].lev === smallest) { + arrays[x][positions[x]].lev === smallest && + !notDuplicates[arrays[x][positions[x]].fullPath]) { ret.push(arrays[x][positions[x]]); + notDuplicates[arrays[x][positions[x]].fullPath] = true; positions[x] += 1; } } diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index d6b3ab26af8ae..08df4adf57d34 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1326,4 +1326,8 @@ kbd { } #all-types > p { margin: 5px 0; +} + +.search-results td span.grey { + color: #ccc; } \ No newline at end of file
' + - '' + - pathSplitter(displayPath) + '' + + '' + + (item.is_alias === true ? + ('' + item.alias + '  - see ') : '') + + item.displayPath + '' + name + '' + - '' + + '' + '' + escape(item.desc) + '