Skip to content

Commit

Permalink
rustdoc: fix janky behavior on iPadOS
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Sep 11, 2023
1 parent 32b9253 commit 800dab0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ img {
}

.sidebar-resizer {
touch-action: none;
width: 9px;
cursor: col-resize;
z-index: 10;
Expand All @@ -417,12 +418,14 @@ img {
}

.rustdoc.src .sidebar-resizer {
/* when closed, place resizer glow on top of the normal src sidebar border (no need to worry about sidebar) */
/* when closed, place resizer glow on top of the normal src sidebar border (no need to worry
about sidebar) */
left: 49px;
}

.src-sidebar-expanded .rustdoc.src .sidebar-resizer {
/* for src sidebar, gap is already provided by 1px border on sidebar itself, so place resizer to right of it */
/* for src sidebar, gap is already provided by 1px border on sidebar itself, so place resizer
to right of it */
left: var(--src-sidebar-width, 300px);
}

Expand All @@ -443,7 +446,8 @@ img {
.sidebar-resizer.active {
width: 10px;
margin: 0;
/* when active or hovered, place resizer glow on top of the sidebar (right next to, or even on top of, the scrollbar) */
/* when active or hovered, place resizer glow on top of the sidebar (right next to, or even
on top of, the scrollbar) */
left: var(--desktop-sidebar-width, 200px);
border-left: solid 1px var(--sidebar-resizer-hover);
}
Expand All @@ -457,7 +461,8 @@ img {
}

.sidebar-resizer.active {
/* make the resize tool bigger when actually resizing, to avoid :hover styles on other stuff while resizing */
/* make the resize tool bigger when actually resizing, to avoid :hover styles on other stuff
while resizing */
padding: 0 140px;
width: 2px;
margin-left: -140px;
Expand Down
16 changes: 10 additions & 6 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
hasClass(document.documentElement, "hide-sidebar");
};
const resize = e => {
e.preventDefault();
const pos = e.clientX - sidebar.offsetLeft - 3;
if (pos < 50) {
hideSidebar();
Expand All @@ -1292,22 +1293,25 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/how-to-read-rustdoc.html\
changeSidebarSize(Math.min(pos, window.innerWidth - 100));
}
};
const stopResize = () => {
const stopResize = e => {
e.preventDefault();
removeClass(resizer, "active");
window.removeEventListener("mousemove", resize, false);
window.removeEventListener("mouseup", stopResize, false);
window.removeEventListener("pointermove", resize, false);
window.removeEventListener("pointerup", stopResize, false);
removeClass(document.documentElement, "sidebar-resizing");
};
const initResize = e => {
e.preventDefault();
if (e.altKey || e.ctrlKey || e.metaKey || e.button !== 0) {
return;
}
window.addEventListener("mousemove", resize, false);
window.addEventListener("mouseup", stopResize, false);
window.addEventListener("pointermove", resize, false);
window.addEventListener("pointercancel", stopResize, false);
window.addEventListener("pointerup", stopResize, false);
addClass(resizer, "active");
addClass(document.documentElement, "sidebar-resizing");
};
resizer.addEventListener("mousedown", initResize, false);
resizer.addEventListener("pointerdown", initResize, false);
}());

(function() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ if (getSettingValue("hide-sidebar") === "true") {

function updateSidebarWidth() {
const desktopSidebarWidth = getSettingValue("desktop-sidebar-width");
if (desktopSidebarWidth) {
if (desktopSidebarWidth && desktopSidebarWidth !== "null") {
document.documentElement.style.setProperty(
"--desktop-sidebar-width",
desktopSidebarWidth + "px"
);
}
const srcSidebarWidth = getSettingValue("src-sidebar-width");
if (srcSidebarWidth) {
if (srcSidebarWidth && srcSidebarWidth !== "null") {
document.documentElement.style.setProperty(
"--src-sidebar-width",
srcSidebarWidth + "px"
Expand Down

0 comments on commit 800dab0

Please sign in to comment.