diff --git a/src/frontend/GuacamoleDisplay.tsx b/src/frontend/GuacamoleDisplay.tsx index d535331..131b9a1 100644 --- a/src/frontend/GuacamoleDisplay.tsx +++ b/src/frontend/GuacamoleDisplay.tsx @@ -265,6 +265,11 @@ export const GuacamoleDisplay = forwardRef< displayRef.current.style.width = `${Math.floor(display.getWidth() * scale)}px`; displayRef.current.style.height = `${Math.floor(display.getHeight() * scale)}px`; } + // Only a zoomed in display needs scrolling. Fitted, a pixel of rounding + // shows a scrollbar, which shrinks the fit, which hides it: a loop. + if (containerRef.current) { + containerRef.current.style.overflow = zoom > 1 ? "auto" : "hidden"; + } onZoomChange?.(zoom); return zoom; }, @@ -1085,7 +1090,7 @@ export const GuacamoleDisplay = forwardRef< return (
{ diff --git a/tests/frontend/GuacamoleDisplay-resize.test.tsx b/tests/frontend/GuacamoleDisplay-resize.test.tsx index 5394407..99dd0ac 100644 --- a/tests/frontend/GuacamoleDisplay-resize.test.tsx +++ b/tests/frontend/GuacamoleDisplay-resize.test.tsx @@ -1,5 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { act, cleanup, render } from "@testing-library/react"; +import { createRef } from "react"; // guacd's VNC client segfaults if it gets a display `size` while it is still // dialing the VNC server, so the resize observer must stay quiet until the @@ -87,7 +88,10 @@ vi.mock("@termix-ssh/plugin-sdk/ui", async (importOriginal) => ({ resolveConnectionOrigin: async () => "remote", })); -import { GuacamoleDisplay } from "../../src/frontend/GuacamoleDisplay"; +import { + GuacamoleDisplay, + type GuacamoleDisplayHandle, +} from "../../src/frontend/GuacamoleDisplay"; const RESIZE_DEBOUNCE_MS = 150; @@ -264,6 +268,27 @@ describe("RDP automatic resizing", () => { }); }); +describe("GuacamoleDisplay scrolling", () => { + it("scrolls only a zoomed in display, so a fitted one cannot loop", async () => { + const ref = createRef(); + const { container } = render( + , + ); + await vi.waitFor(() => expect(mocks.client).not.toBeNull()); + const box = container.firstElementChild as HTMLElement; + const overflow = () => getComputedStyle(box).overflow; + + act(() => void ref.current!.zoomIn()); + expect(overflow()).toBe("auto"); + act(() => void ref.current!.zoomOut()); + expect(overflow()).toBe("hidden"); + }); +}); + describe("GuacamoleDisplay paste modifiers", () => { function paste(element: HTMLElement) { const event = new Event("paste", { bubbles: true, cancelable: true });