about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-05-24 18:53:35 +0200
committerGitHub <noreply@github.com>2021-05-24 18:53:35 +0200
commit30f4486ee425936ac6bd3c5af8ed3c6455a49c94 (patch)
tree9d7439e707cd2f25830efe5c1a472727dc1d9319
parent2a8eeafa9df6c04e21cdc6b31b798977c68253c3 (diff)
parent8968c0e48f460d042f20d79aa0ff8ef6b317f086 (diff)
downloadrust-30f4486ee425936ac6bd3c5af8ed3c6455a49c94.tar.gz
rust-30f4486ee425936ac6bd3c5af8ed3c6455a49c94.zip
Rollup merge of #85551 - GuillaumeGomez:fix-search-result-overflow, r=jsha
Fix search results display

Fixes https://github.com/rust-lang/rust/issues/85544.

cc `@dns2utf8`

r? `@jsha`
-rw-r--r--src/librustdoc/html/static/rustdoc.css37
-rw-r--r--src/librustdoc/html/static/search.js4
-rw-r--r--src/test/rustdoc-gui/search-result-display.goml12
3 files changed, 46 insertions, 7 deletions
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index 9c5e3e8bfb2..5ee92cce655 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -759,25 +759,40 @@ a {
 
 .search-results.active {
 	display: block;
+	/* prevent overhanging tabs from moving the first result */
+	clear: both;
 }
 
-.search-results .desc {
+.search-results .desc > span {
 	white-space: nowrap;
 	text-overflow: ellipsis;
 	overflow: hidden;
 	display: block;
 }
 
-.search-results a {
+.search-results > a {
+	display: block;
+	width: 100%;
 	/* A little margin ensures the browser's outlining of focused links has room to display. */
 	margin-left: 2px;
 	margin-right: 2px;
-	display: block;
+	border-bottom: 1px solid #aaa3;
+}
+
+.search-results > a > div {
+	display: flex;
+	flex-flow: row wrap;
 }
 
-.result-name {
+.search-results .result-name, .search-results div.desc, .search-results .result-description {
 	width: 50%;
-	float: left;
+}
+.search-results .result-name {
+	padding-right: 1em;
+}
+
+.search-results .result-name > span {
+	display: inline-block;
 }
 
 .result-name span.primitive::after {
@@ -1733,6 +1748,18 @@ details.undocumented[open] > summary::before {
 	.search-container > div {
 		width: calc(100% - 32px);
 	}
+
+	/* Display an alternating layout on tablets and phones */
+	.search-results > a {
+		border-bottom: 1px solid #aaa9;
+		padding: 5px 0px;
+	}
+	.search-results .result-name, .search-results div.desc, .search-results .result-description {
+		width: 100%;
+	}
+	.search-results div.desc, .search-results .result-description {
+		padding-left: 2em;
+	}
 }
 
 @media print {
diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js
index c95136d40d3..634e5fa5787 100644
--- a/src/librustdoc/html/static/search.js
+++ b/src/librustdoc/html/static/search.js
@@ -994,8 +994,8 @@ window.initSearch = function(rawSearchIndex) {
                            ("<span class=\"alias\"><b>" + item.alias + " </b></span><span " +
                               "class=\"grey\"><i>&nbsp;- see&nbsp;</i></span>") : "") +
                           item.displayPath + "<span class=\"" + type + "\">" +
-                          name + "</span></div><div>" +
-                          "<span class=\"desc\">" + item.desc +
+                          name + "</span></div><div class=\"desc\">" +
+                          "<span>" + item.desc +
                           "&nbsp;</span></div></div></a>";
             });
             output += "</div>";
diff --git a/src/test/rustdoc-gui/search-result-display.goml b/src/test/rustdoc-gui/search-result-display.goml
new file mode 100644
index 00000000000..96d15c624f1
--- /dev/null
+++ b/src/test/rustdoc-gui/search-result-display.goml
@@ -0,0 +1,12 @@
+goto: file://|DOC_PATH|/test_docs/index.html
+size: (900, 1000)
+write: (".search-input", "test")
+// Waiting for the search results to appear...
+wait-for: "#titles"
+// The width is returned by "getComputedStyle" which returns the exact number instead of the
+// CSS rule which is "50%"...
+assert: (".search-results div.desc", {"width": "320px"})
+size: (600, 100)
+// As counter-intuitive as it may seem, in this width, the width is "100%", which is why
+// when computed it's larger.
+assert: (".search-results div.desc", {"width": "570px"})