Skip to content

Commit

Permalink
rustdoc-search: let people easily make text selections
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
notriddle committed Jul 1, 2024
1 parent 7a58dea commit b051735
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3194,6 +3194,15 @@ ${item.displayPath}<span class="${type}">${name}</span>\
li.appendChild(description);
li.tabIndex = -1;
li.onclick = () => {
// allow user to select the description text without navigating
// also, they can select the path itself by starting the selection here
// (a UI feature I got used to from DuckDuckGo)
if (window.getSelection) {
const selection = window.getSelection();
if (selection && !selection.isCollapsed) {
return;
}
}
// allow clicking anywhere on the list item to go to the page
// even though the link itself is only the name
resultName.click();
Expand Down
12 changes: 12 additions & 0 deletions tests/rustdoc-gui/search-result-description-selection.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This test is to ensure that the codeblocks are correctly rendered in the search results.
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=some_more_function"
show-text: true // can't select text without showing it
// Waiting for the search results to appear...
wait-for: "#search-tabs"
assert: ".search-results .desc"
store-position: (".search-results .desc", {"x": desc_x, "y": desc_y})
// select text within the description
// making sure nothing happens after doing so (other than the text select itself)
drag-and-drop: ((|desc_x| + 8, |desc_y| + 8), (|desc_x| + 80, |desc_y| + 8))
wait-for: 125
assert: ".search-results .desc"

0 comments on commit b051735

Please sign in to comment.