about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js
AgeCommit message (Collapse)AuthorLines
2023-06-11rustdoc-search: build args, return, and generics on one unifierMichael Howell-138/+105
This enhances generics with the "unboxing" behavior where A<T> matches T. It makes this unboxing transitive over generics.
2023-06-11rustdoc-search: simplify JS in `checkGenerics`Michael Howell-68/+68
2023-06-10rustdoc: add note about slice/array searches to help popupMichael Howell-0/+4
2023-06-10rustdoc: search for slices and arrays by type with `[]`Michael Howell-82/+151
Part of #60485
2023-05-31rustdoc: add jsdoc comments for complex functionsMichael Howell-1/+34
2023-05-23rustdoc: add interaction delays for tooltip popoversMichael Howell-9/+104
Designing a good hover microinteraction is a matter of guessing user intent from what are, literally, vague gestures. In this case, guessing if hovering in our out of the tooltip base is intentional or not. To figure this out, a few different techniques are used: * When the mouse pointer enters a tooltip anchor point, its hitbox is grown on the bottom, where the popover is/will appear. This was already there before this commit: search "hover tunnel" in rustdoc.css for the implementation. * This commit adds a delay when the mouse pointer enters the base anchor, in case the mouse pointer was just passing through and the user didn't want to open it. * This commit also adds a delay when the mouse pointer exits the tooltip's base anchor or its popover, before hiding it. * A fade-out animation is layered onto the pointer exit delay to immediately inform the user that they successfully dismissed the popover, while still providing a way for them to cancel it if it was a mistake and they still wanted to interact with it. * No animation is used for revealing it, because we don't want people to try to interact with an element while it's in the middle of fading in: either they're allowed to interact with it while it's fading in, meaning it can't serve as mistake- proofing for opening the popover, or they can't, but they might try and be frustrated. See also: * https://www.nngroup.com/articles/timing-exposing-content/ * https://www.nngroup.com/articles/tooltip-guidelines/ * https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown
2023-05-03Rollup merge of #110371 - notriddle:notriddle/search-corrections, ↵Manish Goregaokar-197/+228
r=GuillaumeGomez rustdoc: restructure type search engine to pick-and-use IDs Fixes #110029 Preview: https://notriddle.com/rustdoc-demo-html-3/search-corrections/std/index.html?search=-%3E%20streaming ![image](https://user-images.githubusercontent.com/1593513/233494900-ae77d5b4-e395-41f8-bbac-53ee55bb4a76.png) This change makes it so, instead of mixing string distance with type unification, function signature search works by mapping names to IDs at the start, reporting to the user any cases where it had to make corrections, and then matches with IDs when going through the items. This only changes function searches. Name searches are left alone, and corrections are only done when there's a single item in the search query.
2023-04-23Rollup merge of #110661 - notriddle:notriddle/settings-js-handlekey, ↵Matthias Krüger-18/+1
r=GuillaumeGomez rustdoc: clean up settings.css and settings.js `handleKey` was added in 9dc5dfb97504c538bc72f367a77bb9f714c30097 and 704050da2334c465784954d81c8990c4bc7a92c5 because the browser-native checkbox was `display: none`, breaking native keyboard accessibility. The native checkbox is now merely `appearance: none`, which does not turn off [behavior semantics], so JavaScript to reimplement it isn't needed any more. [behavior semantics]: https://w3c.github.io/csswg-drafts/css-ui/#appearance-semantics The other, one line change to settings.css is follow-up to #110205
2023-04-21rustdoc: remove unneeded handleKey from settings.jsMichael Howell-18/+1
This code was added in 9dc5dfb97504c538bc72f367a77bb9f714c30097 and 704050da2334c465784954d81c8990c4bc7a92c5 because the browser- native checkbox was `display: none`, breaking native keyboard accessibility. The native checkbox is now merely `appearance: none`, which does not turn off [behavior semantics], so JavaScript to reimplement it isn't needed any more. [behavior semantics]: https://w3c.github.io/csswg-drafts/css-ui/#appearance-semantics
2023-04-21rustdoc: clean up redundant search hiding results codeMichael Howell-8/+1
* There's no need to call `history.replaceState` right before calling `searchState.hideResults`, which already does it. * There's no need to implement hiding search results when that is already implemented.
2023-04-21rustdoc: lift constant string manipulation out of loopMichael Howell-1/+1
2023-04-21rustdoc: use Set for ignored crates, instead of string matchingMichael Howell-2/+4
2023-04-20rustdoc-search: use more descriptive "x not found; y instead" messageMichael Howell-1/+1
2023-04-20rustdoc-search: make type name correction choice deterministicMichael Howell-0/+3
2023-04-20rustdoc-search: clean up `checkIfInGenerics` call at end of `checkType`Michael Howell-5/+1
2023-04-19rustdoc-search: give longer notification for type correctionsMichael Howell-2/+7
2023-04-17rustdoc: restructure type search engine to pick-and-use IDsMichael Howell-196/+223
This change makes it so, instead of mixing string distance with type unification, function signature search works by mapping names to IDs at the start, reporting to the user any cases where it had to make corrections, and then matches with IDs when going through the items. This only changes function searches. Name searches are left alone, and corrections are only done when there's a single item in the search query.
2023-04-17rustdoc-search: fix incorrect doc commentMichael Howell-1/+1
2023-04-17Rollup merge of #110341 - notriddle:notriddle/main-js-replacestate, ↵Matthias Krüger-4/+2
r=GuillaumeGomez rustdoc: stop passing a title to `replaceState` second argument As described on [MDN's replaceState page], this parameter is not currently used, and the empty string is "safe against future changes to the method." [MDN's replaceState page]: https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
2023-04-15rustdoc: stop passing a title to `replaceState` second argumentMichael Howell-4/+2
As described on [MDN's replaceState page], this parameter is not currently used, and the empty string is "safe against future changes to the method." [MDN's replaceState page]: https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
2023-04-14rustdoc-search: add support for nested genericsMichael Howell-11/+10
2023-04-13rustdoc-search: use ES6 Map for `Result` instead of ObjectMichael Howell-21/+40
2023-04-13rustdoc-search: use ES6 `Set` for deduplication instead of `Object`Michael Howell-3/+3
2023-04-13rustdoc-search: use ES6 `Map` for generic matching instead of `Object`Michael Howell-23/+14
2023-04-13rustdoc-search: use ES6 `Map` for aliases instead of `Object`Michael Howell-11/+16
2023-04-12rustdoc: use CSS `overscroll-behavior` instead of JavaScriptMichael Howell-55/+6
Fixes the desktop scrolling weirdness mentioned in https://github.com/rust-lang/rust/pull/98775#issuecomment-1182575603 As described in the MDN page for this property: * The current Firefox ESR is 102, and the first Firefox version to support this feature is 59. * The current Chrome version 112, and the first version to support this is 63. * Edge is described as having a minor bug in `none` mode, but we use `contain` mode anyway, so it doesn't matter. * Safari 16, released September 2022, is the last browser to add this feature, and is also the oldest version we officially support.
2023-04-10rustdoc: remove redundant expandSection code from main.jsMichael Howell-14/+5
This functionality is already tested in `hash-item-expansion.goml`, and was implemented twice: * First, in code that ran at load time and at hash change: 917cdd295d2eed213c135d6f984c650f016ee3d6 * Later, the hash change event handler was itself run at load time, and the code handling both cases diverged in implementation, though their behavior still matches pretty well: f66a331335f3ac931afabca6f927a9d7dc17db3e
2023-04-08Rollup merge of #110037 - notriddle:notriddle/theme-default, r=GuillaumeGomezNilstrieb-0/+1
rustdoc: add test and bug fix for theme defaults Part of https://github.com/rust-lang/rust/issues/66181
2023-04-06rustdoc: add test and bug fix for theme defaultsMichael Howell-0/+1
2023-04-06rustdoc: clean up JSMichael Howell-28/+9
* Stop checking `func` in `onEach`. It's always hard-coded right at the call site, so there's no point. * Use the ternary operator in a few spots where it makes sense. * No point in making `onEach` store `arr.length` in a variable if it's only used once anyway.
2023-03-31rustdoc-search: update docs for comma in `?` help popoverMichael Howell-3/+1
2023-03-27Rollup merge of #109633 - GuillaumeGomez:fix-go-to-only-setting, r=notriddleMatthias Krüger-5/+1
Fix "Directly go to item in search if there is only one result" setting Part of #66181. The setting was actually broken, so I fixed it when I added the GUI test. r? `@notriddle`
2023-03-26Fix "Directly go to item in search if there is only one result" settingGuillaume Gomez-5/+1
2023-03-25Rollup merge of #109542 - notriddle:notriddle/storage-js, r=GuillaumeGomezMatthias Krüger-61/+18
rustdoc: clean up `storage.js`
2023-03-23rustdoc: remove old `content` hack for theme switchingMichael Howell-32/+5
This is based on the compatibility data for `window.matchMedia` and `MediaQueryList`'s `EventTarget` implementation. https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#browser_compatibility https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia#browser_compatibility * EventTarget would require us to drop support for all Chrome versions before 39. However, we already require Chrome 49, because rustdoc requires [CSS variables]. * EventTarget would also limit us to Firefox 55, but since #106502 rustdoc only supports Firefox > 68. * EventTarget limits us to Mobile Safari version 14, but #102404 shows that our CSS is broken in Safari versions before 15.5. [CSS variables]: https://developer.mozilla.org/en-US/docs/Web/CSS/--*#browser_compatibility
2023-03-23rustdoc: clean up `storage.js`Michael Howell-29/+13
This converts a few functions to more compact versions of themselves, and moves `RUSTDOC_MOBILE_BREAKPOINT` to main.js where it's actually used.
2023-03-20rustdoc: add support for type filters in arguments and genericsMichael Howell-53/+111
This makes sense, since the search index has the information in it, and it's more useful for function signature searches since a function signature search's item type is, by definition, some type of function (there's more than one, but not very many).
2023-03-19rustdoc: implement bag semantics for function parameter searchMichael Howell-26/+70
This tweak to the function signature search engine makes things so that, if a type is repeated in the search query, it'll only match if the function actually includes it that many times.
2023-03-12Rollup merge of #109009 - notriddle:notriddle/edit-distance, r=GuillaumeGomezMatthias Krüger-149/+223
rustdoc: use restricted Damerau-Levenshtein distance for search Based on https://github.com/rust-lang/rust/pull/108200, for the same rationale. > This replaces the existing Levenshtein algorithm with the Damerau-Levenshtein algorithm. This means that "ab" to "ba" is one change (a transposition) instead of two (a deletion and insertion). More specifically, this is a restricted implementation, in that "ca" to "abc" cannot be performed as "ca" → "ac" → "abc", as there is an insertion in the middle of a transposition. I believe that errors like that are sufficiently rare that it's not worth taking into account. Before this change, searching [`prinltn!`] listed `print!` first, followed by `println!`. With this change, `println!` matches more closely. [`prinltn!`]: https://doc.rust-lang.org/nightly/std/?search=prinltn!
2023-03-11rustdoc: collapse edit distance state into an objectMichael Howell-80/+86
2023-03-11Rollup merge of #107629 - pitaj:rustdoc-search-deprecated, r=jshaMatthias Krüger-4/+21
rustdoc: sort deprecated items lower in search closes #98759 ### Screenshots `i32::MAX` show sup above `std::i32::MAX` and `core::i32::MAX` ![image](https://user-images.githubusercontent.com/803701/216725619-40afb7b0-e984-4a2e-ab5b-a95b24736b0e.png) If just searching for `min`, the deprecated results show up far below other things: ![image](https://user-images.githubusercontent.com/803701/216725672-e4325d37-9bfe-47eb-a1fe-0e57092aa811.png) one page later ![image](https://user-images.githubusercontent.com/803701/216725932-cd1c4a42-d527-44fb-a4ab-5a6d243659cc.png) ~~And, as you can see, the "Deprecation planned" message shows up in the search results. The same is true for fully-deprecated items like `mem::uninitialized`: ![image](https://user-images.githubusercontent.com/803701/216726268-1657e77a-563f-45a0-85a7-3a0cf4d66d6f.png)~~ Edit: the deprecation message change was removed from this PR. Only the sorting is changed.
2023-03-10rustdoc: use restricted Damerau-Levenshtein distance for searchMichael Howell-147/+215
Based on https://github.com/rust-lang/rust/pull/108200, for the same rationale. > This replaces the existing Levenshtein algorithm with the > Damerau-Levenshtein algorithm. This means that "ab" to "ba" is one change > (a transposition) instead of two (a deletion and insertion). More > specifically, this is a restricted implementation, in that "ca" to "abc" > cannot be performed as "ca" → "ac" → "abc", as there is an insertion in the > middle of a transposition. I believe that errors like that are sufficiently > rare that it's not worth taking into account. Before this change, searching `prinltn!` listed `print!` first, followed by `println!`. With this change, `println!` matches more closely.
2023-03-10rustdoc: sort deprecated items lower in searchPeter Jaszkowiak-4/+21
serialize `q` (`itemPaths`) sparsely overall 4% reduction in search index size
2023-03-08Update src/librustdoc/html/static/js/storage.jsMichael Howell-1/+1
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2023-03-08Fix eslint errorsGuillaume Gomez-0/+1
2023-03-08Only load one CSS theme by defaultMichael Howell-33/+52
To avoid generating a FOUC at startup, this commit uses `document.write` to load the stylesheet initially. Co-Authored-By: Guillaume Gomez <guillaume1.gomez@gmail.com>
2023-03-03Emit an error for unclosed genericGuillaume Gomez-1/+13
2023-03-02Put backtick content from rustdoc search errors into a <code> elementsGuillaume Gomez-39/+91
2023-03-01Rollup merge of #108143 - notriddle:notriddle/filter-exclamation-macro, ↵Dylan DPC-6/+26
r=GuillaumeGomez rustdoc: search by macro when query ends with `!` Related to #96399 Note: the `never` type alias is tested in [`/tests/rustdoc-js-std/alias-3.js`](https://github.com/notriddle/rust/blob/08ad401633037cc226b3806a3c5f48c2f34703bf/tests/rustdoc-js-std/alias-3.js) ## Before ![image](https://user-images.githubusercontent.com/1593513/219504192-54cc0753-ff97-4a37-ad4a-8ae915181325.png) ## After ![image](https://user-images.githubusercontent.com/1593513/219504251-589a7e11-1e7b-4b7b-879d-1b564080017c.png)
2023-02-26Clean up JS files code a bitGuillaume Gomez-13/+7