Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't focus on notable trait parent when hiding it #104577

Merged
merged 4 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.1
0.13.2
20 changes: 11 additions & 9 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ function loadCss(cssUrl) {
// This means when the window is resized, we need to redo the layout.
const base = window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE;
const force_visible = base.NOTABLE_FORCE_VISIBLE;
hideNotable();
hideNotable(false);
if (force_visible) {
showNotable(base);
base.NOTABLE_FORCE_VISIBLE = true;
Expand Down Expand Up @@ -846,7 +846,7 @@ function loadCss(cssUrl) {
// Make this function idempotent.
return;
}
hideNotable();
hideNotable(false);
const ty = e.getAttribute("data-ty");
const wrapper = document.createElement("div");
wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
Expand Down Expand Up @@ -883,7 +883,7 @@ function loadCss(cssUrl) {
return;
}
if (!e.NOTABLE_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, e)) {
hideNotable();
hideNotable(true);
}
};
}
Expand All @@ -903,14 +903,16 @@ function loadCss(cssUrl) {
// To work around this, make sure the click finishes being dispatched before
// hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave
// consistently with the other two.
setTimeout(hideNotable, 0);
setTimeout(() => hideNotable(false), 0);
}
}

function hideNotable() {
function hideNotable(focus) {
if (window.CURRENT_NOTABLE_ELEMENT) {
if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) {
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
if (focus) {
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus();
}
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false;
}
const body = document.getElementsByTagName("body")[0];
Expand All @@ -923,7 +925,7 @@ function loadCss(cssUrl) {
e.onclick = function() {
this.NOTABLE_FORCE_VISIBLE = this.NOTABLE_FORCE_VISIBLE ? false : true;
if (window.CURRENT_NOTABLE_ELEMENT && !this.NOTABLE_FORCE_VISIBLE) {
hideNotable();
hideNotable(true);
} else {
showNotable(this);
window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0");
Expand All @@ -946,7 +948,7 @@ function loadCss(cssUrl) {
}
if (!this.NOTABLE_FORCE_VISIBLE &&
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT)) {
hideNotable();
hideNotable(true);
}
};
});
Expand Down Expand Up @@ -1057,7 +1059,7 @@ function loadCss(cssUrl) {
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
elem.style.display = "none";
});
hideNotable();
hideNotable(false);
};

/**
Expand Down
30 changes: 30 additions & 0 deletions src/test/rustdoc-gui/notable-trait.goml
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,33 @@ press-key: "Tab"
press-key: "Tab"
press-key: "Tab"
assert-count: ("//*[@class='notable popover']", 0)
assert: "#method\.create_an_iterator_from_read .notable-traits:focus"

// Now we check that the focus isn't given back to the wrong item when opening
// another popover.
store-window-property: (scroll, "scrollY")
click: "#method\.create_an_iterator_from_read .fnname"
// We ensure that the scroll position changed.
assert-window-property-false: {"scrollY": |scroll|}
// Store the new position.
store-window-property: (scroll, "scrollY")
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
wait-for: "//*[@class='notable popover']"
click: "#settings-menu a"
click: ".search-input"
// We ensure we didn't come back to the previous focused item.
assert-window-property-false: {"scrollY": |scroll|}

// Same but with Escape handling.
store-window-property: (scroll, "scrollY")
click: "#method\.create_an_iterator_from_read .fnname"
// We ensure that the scroll position changed.
assert-window-property-false: {"scrollY": |scroll|}
// Store the new position.
store-window-property: (scroll, "scrollY")
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
wait-for: "//*[@class='notable popover']"
click: "#settings-menu a"
press-key: "Escape"
// We ensure we didn't come back to the previous focused item.
assert-window-property-false: {"scrollY": |scroll|}