mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(ui): don't show a scrollbar over content that fits after a resize (#5016)
A scroll range of one pixel or less is WebKit rounding after a resize (a splitter drag leaves scrollHeight 319 over clientHeight 318), not content: the overlay scrollbar and the editor scrollbar thumb no longer show for it.
This commit is contained in:
@@ -308,6 +308,8 @@ describe("error stripe", () => {
|
||||
it("finds the scrollbar thumb the marks must let through", () => {
|
||||
// Nothing to scroll: no thumb.
|
||||
expect(scrollbarThumb(0, 400, 400)).toBeNull();
|
||||
expect(scrollbarThumb(0, 401, 400)).toBeNull();
|
||||
expect(scrollbarThumb(0, 402, 400)).not.toBeNull();
|
||||
// A quarter of the document visible: a 100px thumb, at the top, then at the bottom.
|
||||
expect(scrollbarThumb(0, 1600, 400)).toEqual({ top: 0, bottom: 100 });
|
||||
expect(scrollbarThumb(1200, 1600, 400)).toEqual({ top: 300, bottom: 400 });
|
||||
|
||||
@@ -42,7 +42,8 @@ export function scrollbarThumb(
|
||||
minThumb = MIN_THUMB,
|
||||
): { top: number; bottom: number } | null {
|
||||
const max = scrollHeight - clientHeight;
|
||||
if (max <= 0 || clientHeight <= 0) return null;
|
||||
// A pixel of range is WebKit rounding after a resize, not content to scroll to.
|
||||
if (max <= 1 || clientHeight <= 0) return null;
|
||||
const length = Math.min(clientHeight, Math.max(minThumb, (clientHeight * clientHeight) / scrollHeight));
|
||||
const top = (Math.min(Math.max(scrollTop, 0), max) / max) * (clientHeight - length);
|
||||
return { top, bottom: top + length };
|
||||
|
||||
@@ -43,4 +43,25 @@ describe("Scrollbar", () => {
|
||||
expect(onScroll).toHaveBeenCalledTimes(1);
|
||||
expect(onScroll).toHaveBeenLastCalledWith(top);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[318, 318, false],
|
||||
// WebKit after a splitter drag: one commit row, scrollHeight a pixel over the viewport.
|
||||
[318, 319, false],
|
||||
[318, 320, true],
|
||||
[100, 1000, true],
|
||||
])("shows the track for clientHeight %i and scrollHeight %i: %s", (clientHeight, scrollHeight, shown) => {
|
||||
const { getByTestId, container } = render(<Harness onScroll={() => {}} />);
|
||||
const scroller = getByTestId("scroller");
|
||||
Object.defineProperties(scroller, {
|
||||
clientHeight: { value: clientHeight },
|
||||
scrollHeight: { value: scrollHeight },
|
||||
scrollTop: { value: 0 },
|
||||
});
|
||||
act(() => {
|
||||
scroller.dispatchEvent(new Event("scroll"));
|
||||
});
|
||||
const track = container.querySelector<HTMLElement>("[aria-hidden]")!;
|
||||
expect(track.style.display !== "none").toBe(shown);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,10 +88,13 @@ function layout(el: HTMLElement | null, t: HTMLElement | null, th: HTMLElement |
|
||||
if (!el || !t || !th) return null;
|
||||
const height = el.clientHeight;
|
||||
const max = el.scrollHeight - height;
|
||||
// WebKit can report scrollHeight a pixel over clientHeight after the scroller is resized to a
|
||||
// fractional height (dragging a splitter), with nothing overflowing: that is no scroll range.
|
||||
const scrolls = max > 1;
|
||||
t.style.top = `${el.offsetTop}px`;
|
||||
t.style.height = `${height}px`;
|
||||
t.style.display = max > 0 ? "" : "none";
|
||||
if (max <= 0) return null;
|
||||
t.style.display = scrolls ? "" : "none";
|
||||
if (!scrolls) return null;
|
||||
const size = Math.max(MIN_THUMB, (height * height) / el.scrollHeight);
|
||||
const range = height - size;
|
||||
th.style.height = `${size}px`;
|
||||
|
||||
Reference in New Issue
Block a user