Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: browser page zoom on desktop: zoom keys and clipping (#13401)

Michael Han3075b73d17e2
diff --git a/studio/frontend/src/features/browser/browser-panel.tsx b/studio/frontend/src/features/browser/browser-panel.tsx
index 0d21e8ab1e7..fca5c101cbc 100644
--- a/studio/frontend/src/features/browser/browser-panel.tsx
+++ b/studio/frontend/src/features/browser/browser-panel.tsx
@@ -137,6 +137,7 @@ import {
import {
hasNativeView,
nativeAction,
+ nativePageHasKeys,
returnToNativePage,
startNativeViews,
useNativeBrowser,
@@ -2405,6 +2406,7 @@ export const BrowserPanel = memo(function BrowserPanel({ active = true }: { acti
const tabId = useBrowserStore.getState().activeTabId;
if (tabId) zoomTab(tabId, direction);
},
+ holdsKeys: nativePageHasKeys,
});
}, [active]);
// Studio's find bar searches the page while focus is in here, or when switched to it.
diff --git a/studio/frontend/src/features/browser/native-view.ts b/studio/frontend/src/features/browser/native-view.ts
index 33b38e1a2b4..8410f131f65 100644
--- a/studio/frontend/src/features/browser/native-view.ts
+++ b/studio/frontend/src/features/browser/native-view.ts
@@ -9,6 +9,7 @@ import { getLocale, translate } from "@/i18n";
import type { TranslationKey } from "@/i18n";
import type { InterpolationValues } from "@/i18n";
import { openExternalLink } from "@/lib/open-link";
+import { getAppliedInterfaceZoom, subscribeAppliedInterfaceZoom } from "@/features/settings/lib/interface-scale-runtime";
import { toast } from "@/lib/toast";
import { BROWSER_PAGE_INSET_VAR, CHAT_SETTINGS_INSET_VAR, cornerInsets } from "@/lib/toast-offset";
import { hostOf } from "./address";
@@ -504,9 +505,13 @@ function openHole(tabId: string, bounds: Bounds): void {
}
// Per holed node, not the root: the vars don't inherit, so a move restyles only those nodes.
+// Under the desktop app's interface zoom (the webview's page zoom), WebKit scales a fixed
+// background's lengths by the zoom once more than the layout they were read from: undone here, or
+// a zoomed-out app covers the right and bottom of the page.
function placeHole(): void {
if (!holeBounds) return;
- const values = [holeBounds.x, holeBounds.y, holeBounds.width, holeBounds.height];
+ const zoom = getAppliedInterfaceZoom() || 1;
+ const values = [holeBounds.x, holeBounds.y, holeBounds.width, holeBounds.height].map((value) => value / zoom);
for (const node of holed) HOLE_VARS.forEach((name, index) => node.style.setProperty(name, `${values[index]}px`));
}
@@ -646,6 +651,11 @@ function pruneViews(shown: string | null): void {
}
}
+/** A page view on screen has the keys: the app's document lost focus to it, not to another window. */
+export function nativePageHasKeys(): boolean {
+ return shownView !== null && !document.hasFocus();
+}
+
function setShownView(tabId: string | null): void {
shownView = tabId;
for (const wake of [...shownWaiters]) wake();
@@ -923,6 +933,11 @@ export function startNativeViews(): () => void {
};
const unsubscribe = useBrowserStore.subscribe(schedule);
+ // The zoom lands after the resize it causes is measured, so the hole is placed again then.
+ const unzoom = subscribeAppliedInterfaceZoom(() => {
+ placeHole();
+ schedule();
+ });
const overlays = new MutationObserver(schedule);
overlays.observe(document.body, { childList: true });
overlays.observe(document.documentElement, { attributes: true, attributeFilter: ["class", "style", "data-palette"] });
@@ -950,6 +965,7 @@ export function startNativeViews(): () => void {
return () => {
cancelAnimationFrame(frame);
unsubscribe();
+ unzoom();
overlays.disconnect();
resizeObserver.disconnect();
window.removeEventListener("resize", schedule);
diff --git a/studio/frontend/src/features/interface-zoom/lib/zoom-actions.ts b/studio/frontend/src/features/interface-zoom/lib/zoom-actions.ts
index 5417ee5956e..e73b28918f5 100644
--- a/studio/frontend/src/features/interface-zoom/lib/zoom-actions.ts
+++ b/studio/frontend/src/features/interface-zoom/lib/zoom-actions.ts
@@ -35,6 +35,8 @@ export function zoomInterface(direction: ZoomDirection): void {
export type ZoomScope = {
contains: (element: Element) => boolean;
zoom: (direction: ZoomDirection) => void;
+ /** Holds the keys outside this document (a native page view), where activeElement can't show it. */
+ holdsKeys?: () => boolean;
};
const scopes = new Set<ZoomScope>();
@@ -75,7 +77,9 @@ export function zoomScopeFromChord(scope: ZoomScope, direction: ZoomDirection):
/** The View menu's zoom: the focused scope's, else the interface's. */
export function zoomInterfaceFromMenu(direction: ZoomDirection): void {
if (echoed("menu")) return;
- const scope = zoomScopeFor(document.activeElement);
+ // A click into a native page moves the keys there but leaves activeElement wherever it was, e.g.
+ // the composer, so that alone would zoom the app.
+ const scope = [...scopes].find((candidate) => candidate.holdsKeys?.()) ?? zoomScopeFor(document.activeElement);
if (scope) scope.zoom(direction);
else zoomInterface(direction);
}
diff --git a/studio/frontend/tests/browser-native-view-layered.test.ts b/studio/frontend/tests/browser-native-view-layered.test.ts
index 94d7cd02fbe..36e61ef0a4b 100644
--- a/studio/frontend/tests/browser-native-view-layered.test.ts
+++ b/studio/frontend/tests/browser-native-view-layered.test.ts
@@ -130,6 +130,17 @@ test("a menu over a layered page neither captures nor hides it, and owns its inp
assert.equal(placeholder.vars.get("--native-hole-y"), "100px");
assert.equal(wrapper.vars.has("--native-hole-x"), false);
+ // under the app's interface zoom the rect is divided by it: WebKit scales a fixed background's
+ // lengths by the zoom on top of the layout they came from
+ const zoomChanged = (globalThis as { nativeViewZoomChanged?: () => void }).nativeViewZoomChanged;
+ (globalThis as { nativeViewZoom?: number }).nativeViewZoom = 0.8;
+ zoomChanged?.();
+ assert.equal(html.vars.get("--native-hole-x"), "625px");
+ assert.equal(placeholder.vars.get("--native-hole-h"), "750px");
+ (globalThis as { nativeViewZoom?: number }).nativeViewZoom = 1;
+ zoomChanged?.();
+ assert.equal(html.vars.get("--native-hole-x"), "500px");
+
// a theme switch recolors them, though the page didn't move; read mid-switch, it tries again
html.className = "html dark";
for (const element of [html, section, placeholder]) element.background = "rgba(0, 0, 0, 0)";
diff --git a/studio/frontend/tests/browser-zoom-menu.test.ts b/studio/frontend/tests/browser-zoom-menu.test.ts
new file mode 100644
index 00000000000..236894d0975
--- /dev/null
+++ b/studio/frontend/tests/browser-zoom-menu.test.ts
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { readSrc } from "./helpers/kit.ts";
+
+test("the View menu zooms a native page that holds the keys, wherever activeElement is", () => {
+ // A click into a native page view leaves activeElement in the app (often the composer), so the
+ // menu asks the scopes first and only then falls back to activeElement.
+ const actions = readSrc("features/interface-zoom/lib/zoom-actions.ts");
+ assert.match(
+ actions,
+ /const scope = \[\.\.\.scopes\]\.find\(\(candidate\) => candidate\.holdsKeys\?\.\(\)\) \?\? zoomScopeFor\(document\.activeElement\);/,
+ );
+ // The browser panel's scope claims the keys while its page view has them.
+ assert.match(
+ readSrc("features/browser/browser-panel.tsx"),
+ /holdsKeys: nativePageHasKeys,/,
+ );
+ assert.match(
+ readSrc("features/browser/native-view.ts"),
+ /export function nativePageHasKeys\(\): boolean \{\s*return shownView !== null && !document\.hasFocus\(\);/,
+ );
+});
diff --git a/studio/frontend/tests/helpers/native-view-resolver.mjs b/studio/frontend/tests/helpers/native-view-resolver.mjs
index cbea62d30b6..9b25a436de3 100644
--- a/studio/frontend/tests/helpers/native-view-resolver.mjs
+++ b/studio/frontend/tests/helpers/native-view-resolver.mjs
@@ -13,6 +13,11 @@ const STUBS = {
"export const getLocale = () => 'en'; export const translate = (key) => key;",
),
"@/lib/open-link": stub("export const openExternalLink = () => {};"),
+ // globalThis.nativeViewZoom is the applied interface zoom; nativeViewZoomChanged announces a change.
+ "@/features/settings/lib/interface-scale-runtime": stub(
+ "export const getAppliedInterfaceZoom = () => globalThis.nativeViewZoom ?? 1;" +
+ " export const subscribeAppliedInterfaceZoom = (listener) => { globalThis.nativeViewZoomChanged = listener; return () => {}; };",
+ ),
"@/lib/toast": stub(`
const seen = (level) => (message) => void (globalThis.nativeViewSeen ??= []).push({ level, message });
export const toast = Object.assign(seen("info"), { success: seen("success"), error: seen("error"), warning: seen("warning") });