Skip to content
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
7 changes: 6 additions & 1 deletion src/frontend/GuacamoleDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -1085,7 +1090,7 @@ export const GuacamoleDisplay = forwardRef<
return (
<div
ref={containerRef}
className="absolute inset-0 overflow-auto"
className="absolute inset-0 overflow-hidden"
style={{ backgroundColor: "var(--bg-base)" }}
onDragEnter={handleDragEnter}
onDragOver={(event) => {
Expand Down
27 changes: 26 additions & 1 deletion tests/frontend/GuacamoleDisplay-resize.test.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<GuacamoleDisplayHandle>();
const { container } = render(
<GuacamoleDisplay
ref={ref}
connectionConfig={{ protocol: "rdp", token: "test-token" }}
isVisible
/>,
);
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 });
Expand Down