mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Stop layout shifts when clicking on commits in patch
scrollToFilesTop scrolled the port down to hide the patch chrome, with a smooth animation. Clicking a commit while already at the top of the diff pulled the header off screen for no reason. Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
committed by
Rūdolfs Ošiņš
co-authored by
Rūdolfs Ošiņš
parent
7dc1d4d94d
commit
039c0d49d5
@@ -407,7 +407,13 @@
|
||||
// auto-selects its only commit — so an effect could not tell "the reader
|
||||
// picked a commit" from "the revision changed underneath them", and scrolled
|
||||
// on both.
|
||||
//
|
||||
// The tick comes first so that the selection has reached the effect that
|
||||
// loads the diff: `diffReady` is read the moment it is awaited, and reading
|
||||
// it any earlier gets the promise for the diff being navigated away from.
|
||||
async function scrollToDiff() {
|
||||
await tick();
|
||||
await diffReady;
|
||||
await tick();
|
||||
diffView?.scrollToFilesTop();
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@
|
||||
// Scroll to a logical position in the scroll content, where 0 is the top of
|
||||
// the `header`. Pierre reuses a paged scroll scaffold, so the logical position
|
||||
// is not the container's `scrollTop` and has to go through `scrollTo`.
|
||||
export function scrollToPosition(
|
||||
function scrollToPosition(
|
||||
position: number,
|
||||
behavior: "smooth" | "instant" = "smooth",
|
||||
): void {
|
||||
@@ -392,12 +392,24 @@
|
||||
return headerEl.getBoundingClientRect().height - reserve;
|
||||
}
|
||||
|
||||
// Scroll the chrome out of the way.
|
||||
// Bring the top of the files column into view, and only ever come back up to
|
||||
// it: a caller asking for the files top wants the diff's first lines on
|
||||
// screen, and they already are whenever the port sits above that point.
|
||||
// Scrolling down from there would pull the chrome off screen on the reader's
|
||||
// behalf, which nothing about picking a commit asks for. Instantly, too — an
|
||||
// animated correction runs for half a second against a diff that may still be
|
||||
// loading underneath it, and each adjustment it makes on the way reads as the
|
||||
// view jumping again.
|
||||
export function scrollToFilesTop(): void {
|
||||
const position = filesTopPosition();
|
||||
if (position !== undefined) {
|
||||
scrollToPosition(position);
|
||||
if (position === undefined) {
|
||||
return;
|
||||
}
|
||||
const current = view?.getScrollTop();
|
||||
if (current !== undefined && current <= position) {
|
||||
return;
|
||||
}
|
||||
scrollToPosition(position, "instant");
|
||||
}
|
||||
|
||||
// Nothing that targets a file should scroll the chrome back into view: the
|
||||
|
||||
Reference in New Issue
Block a user