Skip to content

Commit b051735

Browse files
committed
rustdoc-search: let people easily make text selections
This is a GUI affordance that I basically copied from DuckDuckGo. You can make text selections starting in the description by dragging the mouse, even though clicking on the description opens the page.
1 parent 7a58dea commit b051735

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/librustdoc/html/static/js/search.js

+9
Original file line numberDiff line numberDiff line change
@@ -3194,6 +3194,15 @@ ${item.displayPath}<span class="${type}">${name}</span>\
31943194
li.appendChild(description);
31953195
li.tabIndex = -1;
31963196
li.onclick = () => {
3197+
// allow user to select the description text without navigating
3198+
// also, they can select the path itself by starting the selection here
3199+
// (a UI feature I got used to from DuckDuckGo)
3200+
if (window.getSelection) {
3201+
const selection = window.getSelection();
3202+
if (selection && !selection.isCollapsed) {
3203+
return;
3204+
}
3205+
}
31973206
// allow clicking anywhere on the list item to go to the page
31983207
// even though the link itself is only the name
31993208
resultName.click();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This test is to ensure that the codeblocks are correctly rendered in the search results.
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=some_more_function"
3+
show-text: true // can't select text without showing it
4+
// Waiting for the search results to appear...
5+
wait-for: "#search-tabs"
6+
assert: ".search-results .desc"
7+
store-position: (".search-results .desc", {"x": desc_x, "y": desc_y})
8+
// select text within the description
9+
// making sure nothing happens after doing so (other than the text select itself)
10+
drag-and-drop: ((|desc_x| + 8, |desc_y| + 8), (|desc_x| + 80, |desc_y| + 8))
11+
wait-for: 125
12+
assert: ".search-results .desc"

0 commit comments

Comments
 (0)