A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): UI zoom on ⌘+/−/0, applied by the shell instead of by CSS
esengine2772c15bf59e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fc94f1999..506b9cbd2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,32 @@ published separately; it ships inside the editor.## [Unreleased]+### Added++- **UI zoom, on Ctrl/Cmd +, − and 0.** On a 2K display the editor's numbers were too+ small to read, and the one setting that could fix it sat in a dialog with no menu row,+ no shortcut, and nothing on screen to say it existed. It is now a View-menu group and+ three rebindable commands walking a set of stops (80–200%), plus a status-bar chip that+ appears whenever the zoom is not 100% — click it to go back. Popped-out panel windows+ follow: Chromium keys zoom by origin, so they are born at the current one and change+ with it. Screenshot and MCP runs pin the zoom instead (`ESTELLA_SHOT_ZOOM=<percent>`+ to capture a zoomed shell), because Chromium persists per-origin zoom across restarts+ and one left behind by an ordinary session would silently rebase every later capture.++### Fixed++- **UI zoom no longer blurs the viewport or misplaces what you click.** It was applied as+ a CSS `zoom` on the body, which leaves `devicePixelRatio` at 1: every canvas — the+ viewport, the profiler graphs, the waveforms, the node graphs — kept its backing store+ at the unzoomed size and was upscaled to fit, and `getBoundingClientRect` drifted a+ whole zoom factor away from `clientWidth`, so viewport picking and gizmo dragging+ missed by more the further right and down you aimed (at 150% the right third of the+ viewport could not be hit at all). Chromium applies the zoom now, and raises the dpr+ with it: measured at 80/100/125/150/200%, canvases stay pixel-exact and a dragged gizmo+ lands under the cursor.+- **The viewport canvas is sized from its own layout box**, not `floor(clientWidth × dpr)`+ — which lost up to a pixel at fractional dpr, the case UI zoom makes ordinary.+## [0.39.0] - 2026-08-01The editor has an agent in it. You describe what you want done to the scene and it doesdiff --git a/desktop/electron/main.ts b/desktop/electron/main.tsindex 1252f40d9..0b98a60cd 100644--- a/desktop/electron/main.ts+++ b/desktop/electron/main.ts@@ -213,6 +213,9 @@ let win: BrowserWindow | null = null;* ESTELLA_SHOT_SAVE_FILE script what the user would have chosen (see shotDialogs.ts).* Unscripted, a dialog cancels rather than opening — a modal in a headless run is a* hang, not a failure.+ *+ * The run pins UI zoom (100%, or ESTELLA_SHOT_ZOOM=<percent>) so a zoom left behind+ * by an ordinary session can't rebase a capture — see the window:setZoom handler.*/async function runScreenshot(w: BrowserWindow, out: string): Promise<void> {const exec = (code: string): Promise<unknown> =>@@ -433,8 +436,14 @@ async function runScreenshot(w: BrowserWindow, out: string): Promise<void> {if (!at) {console.log('[editorDrag] selector not found:', spec.selector);} else {- const x0 = Math.round(at.x + (spec.ox ?? 0)), y0 = Math.round(at.y + (spec.oy ?? 0));- const x1 = x0 + Math.round(spec.dx ?? 0), y1 = y0 + Math.round(spec.dy ?? 0);+ // The spec (and getBoundingClientRect) speak page CSS pixels; sendInputEvent+ // speaks window DIPs. Under UI zoom those differ by exactly the zoom factor,+ // and aiming CSS coordinates at a zoomed window simply misses the target.+ const z = w.webContents.getZoomFactor();+ const dip = (v: number) => Math.round(v * z);+ const cx0 = at.x + (spec.ox ?? 0), cy0 = at.y + (spec.oy ?? 0);+ const x0 = dip(cx0), y0 = dip(cy0);+ const x1 = dip(cx0 + (spec.dx ?? 0)), y1 = dip(cy0 + (spec.dy ?? 0));const steps = Math.max(1, spec.steps ?? 8);w.webContents.sendInputEvent({ type: 'mouseDown', x: x0, y: y0, button: 'left', clickCount: 1 });for (let i = 1; i <= steps; i++) {@@ -564,6 +573,12 @@ function createWindow() {win.loadURL(`${appBaseUrl}index.html${automation}`);}+ // Chromium restores this origin's persisted zoom on navigation, so an automation+ // run inherits whatever the last ordinary session left. Stamp the pin back after+ // the page lands, where that restore has already happened.+ const pin = pinnedZoom();+ if (pin !== null) win.webContents.on('did-finish-load', () => win?.webContents.setZoomFactor(pin));+if (shotOut) void runScreenshot(win, shotOut);if (mcpMode()) void startMcpEndpoint(() => win);@@ -702,6 +717,28 @@ ipcMain.handle('window:toggleMaximize', () => {ipcMain.handle('window:close', () => win?.close());ipcMain.handle('window:isMaximized', () => win?.isMaximized() ?? false);+// — UI zoom. Lives in main because Chromium keys zoom by ORIGIN, not by frame:+// setting it on the main window's webContents carries every same-origin popped-out+// panel with it — including ones opened later, which are born at the current zoom.+// (The renderer-side `webFrame` API is per-frame and would leave popouts behind.)+//+// Screenshot / MCP runs pin a zoom and refuse writes: Chromium PERSISTS per-origin+// zoom across restarts, so one set in an ordinary session would otherwise silently+// rebase every later capture — the kind of drift that never fails loudly. The pin+// is 100% unless ESTELLA_SHOT_ZOOM asks for a percentage (mirrors SHOT_LOCALE /+// SHOT_BACKEND), which is what makes the zoomed shell itself capturable.+const clampZoom = (f: number): number => Math.min(2, Math.max(0.8, Number.isFinite(f) ? f : 1));++function pinnedZoom(): number | null {+ if (!process.env.ESTELLA_SHOT && !mcpMode()) return null;+ const pct = Number(process.env.ESTELLA_SHOT_ZOOM);+ return pct > 0 ? clampZoom(pct / 100) : 1;+}++ipcMain.handle('window:setZoom', (_e, factor: number) => {+ win?.webContents.setZoomFactor(pinnedZoom() ?? clampZoom(factor));+});+// — Project / filesystem (RC12 §E7). The open project root lives here in main;// every fs op is sandboxed to it (projectFs.resolveInRoot), so the renderer// can only touch files inside the project it opened. —diff --git a/desktop/electron/preload.ts b/desktop/electron/preload.tsindex 4bb45e5da..993a68466 100644--- a/desktop/electron/preload.ts+++ b/desktop/electron/preload.ts@@ -40,6 +40,8 @@ const api = {toggleMaximize: (): Promise<void> => ipcRenderer.invoke('window:toggleMaximize'),close: (): Promise<void> => ipcRenderer.invoke('window:close'),isMaximized: (): Promise<boolean> => ipcRenderer.invoke('window:isMaximized'),+ /** UI zoom, as a factor (1 = 100%). Applied in main so popped-out panels follow. */+ setZoom: (factor: number): Promise<void> => ipcRenderer.invoke('window:setZoom', factor),/** Subscribe to maximize/restore; returns an unsubscribe. */onMaximizeChange: (cb: (maximized: boolean) => void): (() => void) => {const h = (_e: unknown, maximized: boolean) => cb(maximized);diff --git a/desktop/src/commands/editorCommands.ts b/desktop/src/commands/editorCommands.tsindex c2d4c3967..0208766c4 100644--- a/desktop/src/commands/editorCommands.ts+++ b/desktop/src/commands/editorCommands.ts@@ -20,6 +20,7 @@ import { PerfMonitor } from '@/engine/PerfMonitor';import { applyFxPreview } from '@/engine/fxPreview';import { dockApi } from '@/layout/dockApi';import { resetLayout } from '@/layout/DockLayout';+import { stepUiZoom, setUiZoom, uiZoom, canZoomIn, canZoomOut, ZOOM_DEFAULT } from '@/layout/uiZoom';import { panelDirtySource } from '@/layout/panelDirty';import { DirtyRegistry } from '@/document/DirtyRegistry';import { MaterialDocument } from '@/material/MaterialDocument';@@ -392,6 +393,32 @@ commands.register({// command so it reaches the palette + is rebindable, not a one-off menu handler.run: () => void confirmDiscard(t('discard.resetLayout')).then((ok) => ok && resetLayout()),});+// — UI zoom. Three chords reach zoom-in because "the + key" is three different+// events: unshifted `=` (what the hint shows), the numpad's `+`, and shift-`=`.+commands.register({+ id: 'view.zoomIn',+ label: t('cmd.view.zoomIn'),+ category: t('cat.view'),+ keybinding: ['mod+=', 'mod+plus', 'mod+shift+plus'],+ isEnabled: canZoomIn,+ run: () => stepUiZoom(1),+});+commands.register({+ id: 'view.zoomOut',+ label: t('cmd.view.zoomOut'),+ category: t('cat.view'),+ keybinding: 'mod+-',+ isEnabled: canZoomOut,+ run: () => stepUiZoom(-1),+});+commands.register({+ id: 'view.zoomReset',+ label: t('cmd.view.zoomReset'),+ category: t('cat.view'),+ keybinding: 'mod+0',+ isEnabled: () => uiZoom() !== ZOOM_DEFAULT,+ run: () => setUiZoom(ZOOM_DEFAULT),+});commands.register({id: 'view.toggleGrid',label: t('cmd.view.toggleGrid'),diff --git a/desktop/src/commands/keybinding.ts b/desktop/src/commands/keybinding.tsindex 7196bce3c..787fbd902 100644--- a/desktop/src/commands/keybinding.ts+++ b/desktop/src/commands/keybinding.ts@@ -18,6 +18,9 @@ const IS_MAC =const SPECIAL_KEYS: Record<string, string> = {' ': 'space',spacebar: 'space',+ // The chord grammar joins on '+', so a literal '+' key can only be spelled by+ // name — both sides normalize to it (numpad + and shifted = both report '+').+ '+': 'plus',esc: 'escape',del: 'delete',arrowup: 'up',@@ -80,6 +83,7 @@ function displayKey(key: string): string {backspace: IS_MAC ? '⌫' : 'Backspace',escape: 'Esc',space: 'Space',+ plus: '+',up: '↑',down: '↓',left: '←',diff --git a/desktop/src/engine/EngineHost.ts b/desktop/src/engine/EngineHost.tsindex 6062e7e6f..f74ed5a43 100644--- a/desktop/src/engine/EngineHost.ts+++ b/desktop/src/engine/EngineHost.ts@@ -420,9 +420,14 @@ class EngineHostImpl {const canvas = this.canvas_;const parent = canvas?.parentElement;if (!canvas || !parent) return;+ // Measure the canvas' own layout box rather than `clientWidth * dpr`: UI zoom+ // makes the dpr fractional, and scaling an already-rounded integer CSS width+ // lands up to a pixel off what the compositor paints — enough to resample the+ // whole viewport, which is exactly the sharpness the zoom exists to preserve.const dpr = window.devicePixelRatio || 1;- const w = Math.max(1, Math.floor(parent.clientWidth * dpr));- const h = Math.max(1, Math.floor(parent.clientHeight * dpr));+ const rect = canvas.getBoundingClientRect();+ const w = Math.max(1, Math.round(rect.width * dpr));+ const h = Math.max(1, Math.round(rect.height * dpr));if (canvas.width !== w) canvas.width = w;if (canvas.height !== h) canvas.height = h;}diff --git a/desktop/src/i18n/messages/commands.ts b/desktop/src/i18n/messages/commands.tsindex 80fbd369c..92bf10a38 100644--- a/desktop/src/i18n/messages/commands.ts+++ b/desktop/src/i18n/messages/commands.ts@@ -60,6 +60,9 @@ export const commandMessages = defineMessages({'cmd.view.toggleMinimap': { en: 'Minimap', zh: '小地图' },'cmd.view.toggleStats': { en: 'Stats HUD', zh: '统计信息' },'cmd.view.toggleCoords': { en: 'Coordinates HUD', zh: '坐标信息' },+ 'cmd.view.zoomIn': { en: 'Zoom In', zh: '放大界面' },+ 'cmd.view.zoomOut': { en: 'Zoom Out', zh: '缩小界面' },+ 'cmd.view.zoomReset': { en: 'Reset Zoom', zh: '重置界面缩放' },// — Editor / play / build —'cmd.settings.open': { en: 'Settings…', zh: '设置…' },diff --git a/desktop/src/i18n/messages/layout.ts b/desktop/src/i18n/messages/layout.tsindex 4c8dd64b7..cc9463252 100644--- a/desktop/src/i18n/messages/layout.ts+++ b/desktop/src/i18n/messages/layout.ts@@ -67,6 +67,10 @@ export const layoutMessages = defineMessages({en: 'Resident texture memory / budget · {count} cached (evictable) texture(s)',zh: '驻留纹理内存 / 预算 · {count} 个已缓存(可逐出)纹理',},+ 'layout.status.zoomTooltip': {+ en: 'UI zoom. Click to reset to 100% (Ctrl/Cmd 0).',+ zh: '界面缩放。点击恢复 100%(Ctrl/Cmd 0)。',+ },'layout.status.backendTooltip': {en: 'Active GPU backend — the device actually rendering (reflects any WebGL2 fallback). Change it in Settings → Renderer.',zh: '当前使用的 GPU 后端——实际执行渲染的设备(反映 WebGL2 回退情况)。可在设置 → 渲染器中更改。',diff --git a/desktop/src/i18n/messages/settings.ts b/desktop/src/i18n/messages/settings.tsindex dcb97f8ab..9dabec017 100644--- a/desktop/src/i18n/messages/settings.ts+++ b/desktop/src/i18n/messages/settings.ts@@ -193,8 +193,8 @@ export const settingsMessages = defineMessages({},'set.appearance.uiScale': { en: 'UI scale', zh: '界面缩放' },'set.appearance.uiScale.desc': {- en: 'Scales every panel — fonts and controls.',- zh: '缩放所有面板——字体与控件。',+ en: 'Scales the whole editor — panels, fonts, controls, and popped-out panel windows. Also on Ctrl/Cmd +, − and 0.',+ zh: '缩放整个编辑器——面板、字体、控件,以及弹出的面板窗口。也可用 Ctrl/Cmd +、− 和 0 调节。',},'set.renderer.backend': { en: 'Graphics backend', zh: '图形后端' },'set.renderer.backend.desc': {diff --git a/desktop/src/layout/StatusBar.tsx b/desktop/src/layout/StatusBar.tsxindex a445cde89..6d382a1b6 100644--- a/desktop/src/layout/StatusBar.tsx+++ b/desktop/src/layout/StatusBar.tsx@@ -1,8 +1,10 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Teamimport { useSyncExternalStore } from 'react';-import { Gauge, MousePointer2, Boxes, FolderOpen, MemoryStick, Cpu, Sparkles, Square } from 'lucide-react';+import { Gauge, MousePointer2, Boxes, FolderOpen, MemoryStick, Cpu, Sparkles, Square, Scaling } from 'lucide-react';import { useEditorStore } from '@/store/editorStore';+import { useSettings } from '@/store/settingsStore';+import { UI_SCALE_SETTING, ZOOM_DEFAULT, setUiZoom } from './uiZoom';import { useSelection } from '@/store/selectionStore';import { useAgent, stopAgentTurn } from '@/store/AgentStore';import { StatsStore } from '@/engine/StatsStore';@@ -85,6 +87,25 @@ function AgentSegment() {);}+// A zoom other than 100% silently changes how much fits on screen, so it has to be+// visible somewhere — else a stray Ctrl+= reads as the editor's layout having broken,+// with nothing on screen to attribute it to. Click to return to 100%.+function ZoomReadout() {+ const zoom = useSettings((s) => s.getValue<number>(UI_SCALE_SETTING));+ if (zoom === ZOOM_DEFAULT) return null;+ return (+ <button+ type="button"+ className="sitem click mono"+ title={t('layout.status.zoomTooltip')}+ onClick={() => setUiZoom(ZOOM_DEFAULT)}+ >+ <Scaling size={11} strokeWidth={1.85} />+ {zoom}%+ </button>+ );+}+// Bottom status strip — live engine telemetry (real FPS / entity count / cursor// world position) reads in the mono face. Anchors the Content Drawer.export function StatusBar() {@@ -131,6 +152,7 @@ export function StatusBar() {<Boxes size={11} strokeWidth={1.85} /> <EntitiesValue /></span><VramReadout />+ <ZoomReadout /><spanclassName="sitem mono"title={t('layout.status.backendTooltip')}diff --git a/desktop/src/layout/menus.ts b/desktop/src/layout/menus.tsindex 6b171f116..ae4b72b57 100644--- a/desktop/src/layout/menus.ts+++ b/desktop/src/layout/menus.ts@@ -60,7 +60,7 @@ const MENUS: MenuBarMenu[] = [{ id: 'file', title: () => t('menu.file'), order: 10, groups: ['new', 'open', 'save', 'close'] },{ id: 'edit', title: () => t('menu.edit'), order: 20, groups: ['history', 'clipboard', 'selection'] },{ id: 'entity', title: () => t('menu.entity'), order: 30, groups: ['create', 'modify', 'selection'] },- { id: 'view', title: () => t('menu.view'), order: 40, groups: ['show', 'overlays', 'gizmo'] },+ { id: 'view', title: () => t('menu.view'), order: 40, groups: ['show', 'overlays', 'gizmo', 'zoom'] },{ id: 'build', title: () => t('menu.build'), order: 50, groups: ['package', 'scripts'] },// Where contributed commands land by default. Rendered only once something is in// it — an empty dropdown is broken UI, so the strip hides a menu with no rows.@@ -112,6 +112,9 @@ const BUILTIN_ITEMS: MenuContribution[] = [cmd('view', 'gizmo', 'view.toggleCoordSpace'),cmd('view', 'gizmo', 'view.togglePivotMode'),cmd('view', 'gizmo', 'view.toggleSnapping'),+ cmd('view', 'zoom', 'view.zoomIn'),+ cmd('view', 'zoom', 'view.zoomOut'),+ cmd('view', 'zoom', 'view.zoomReset'),cmd('build', 'package', 'project.export'),cmd('build', 'scripts', 'build.scripts'),diff --git a/desktop/src/layout/uiZoom.ts b/desktop/src/layout/uiZoom.tsnew file mode 100644index 000000000..6925fe773--- /dev/null+++ b/desktop/src/layout/uiZoom.ts@@ -0,0 +1,51 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file uiZoom.ts+ * @brief THE editor's UI zoom: one value, one way down to the shell. The settings+ * store owns it (persisted per user); the View menu commands, the settings+ * slider and the status-bar chip are all just writers of that one value.+ *+ * Chromium applies the zoom, not CSS — and that is the whole point. Chromium raises+ * devicePixelRatio along with it, so every dpr-aware canvas (viewport, profiler+ * graphs, waveforms, node graphs) keeps its backing store at native resolution and+ * pointer→canvas math stays in ONE coordinate space. A CSS `zoom` raises neither:+ * it upscales those canvases and splits `getBoundingClientRect` away from+ * `clientWidth`, which desynchronises viewport picking by exactly the zoom factor.+ */+import { useSettings } from '@/store/settingsStore';++export const UI_SCALE_SETTING = 'appearance.uiScale';++/** The stops the zoom commands walk. The slider stays free to land between them. */+export const ZOOM_STEPS = [80, 90, 100, 110, 125, 150, 175, 200];++export const ZOOM_MIN = ZOOM_STEPS[0];+export const ZOOM_MAX = ZOOM_STEPS[ZOOM_STEPS.length - 1];+export const ZOOM_DEFAULT = 100;++const clamp = (percent: number): number => Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, Math.round(percent)));++export function uiZoom(): number {+ return useSettings.getState().getValue<number>(UI_SCALE_SETTING);+}++export function setUiZoom(percent: number): void {+ useSettings.getState().setValue(UI_SCALE_SETTING, clamp(percent));+}++/** Walk to the neighbouring stop — from wherever the slider left the value. */+export function stepUiZoom(dir: 1 | -1): void {+ const cur = uiZoom();+ const next = dir > 0 ? ZOOM_STEPS.find((s) => s > cur) : ZOOM_STEPS.filter((s) => s < cur).pop();+ if (next !== undefined) setUiZoom(next);+}++export const canZoomIn = (): boolean => uiZoom() < ZOOM_MAX;+export const canZoomOut = (): boolean => uiZoom() > ZOOM_MIN;++/** The setting's `effect` — the single point where the value reaches the shell. */+export function applyUiZoom(percent: number): void {+ if (typeof window === 'undefined') return;+ void window.estella?.win?.setZoom?.(clamp(percent) / 100);+}diff --git a/desktop/src/settings/editorSettings.ts b/desktop/src/settings/editorSettings.tsindex 654009212..d05ae31ff 100644--- a/desktop/src/settings/editorSettings.ts+++ b/desktop/src/settings/editorSettings.ts@@ -21,6 +21,7 @@ import { mcpStatus, setMcpEnabled, subscribeMcp } from '@/store/McpStore';import { secretStatusLine, subscribeSecrets } from '@/store/SecretStore';import { syncAgentEndpoint } from '@/store/AgentStore';import { agentProviders, agentKeyId, CUSTOM_PROVIDER } from '@/agent/providers';+import { applyUiZoom, UI_SCALE_SETTING, ZOOM_DEFAULT, ZOOM_MIN, ZOOM_MAX } from '@/layout/uiZoom';import { t, editorLocale, systemDefaultLocale, EDITOR_LOCALES, LANGUAGE_SETTING_ID } from '@/i18n';const root = () => document.documentElement.style;@@ -103,22 +104,20 @@ settingsRegistry.register({});settingsRegistry.register({- id: 'appearance.uiScale',+ id: UI_SCALE_SETTING,type: 'number',scope: 'editor',section: 'appearance',group: t('set.group.appearance'),label: t('set.appearance.uiScale'),description: t('set.appearance.uiScale.desc'),- default: 100,- min: 80,- max: 150,+ default: ZOOM_DEFAULT,+ min: ZOOM_MIN,+ max: ZOOM_MAX,step: 5,slider: true,suffix: '%',- effect: (v) => {- document.body.style.setProperty('zoom', String(v / 100));- },+ effect: (v) => applyUiZoom(v),});// ── Renderer (read at engine boot; the GfxDevice backend seam) ──────────────diff --git a/desktop/tests/menu-registry.test.ts b/desktop/tests/menu-registry.test.tsindex 77d894c4a..58691ec1f 100644--- a/desktop/tests/menu-registry.test.ts+++ b/desktop/tests/menu-registry.test.ts@@ -44,7 +44,8 @@ describe('menu registry', () => {expect(layout('view')).toEqual(['view.toggleGrid', 'view.toggleGizmos', 'view.toggleColliders', 'view.toggleTileCollision', 'view.togglePreviewFx', null,'view.toggleMinimap', 'view.toggleStats', 'view.toggleCoords', 'view.togglePerf', null,- 'view.toggleCoordSpace', 'view.togglePivotMode', 'view.toggleSnapping',+ 'view.toggleCoordSpace', 'view.togglePivotMode', 'view.toggleSnapping', null,+ 'view.zoomIn', 'view.zoomOut', 'view.zoomReset',]);expect(layout('build')).toEqual(['project.export', null, 'build.scripts', 'project.extractSchemas']);// `plugins.open` joined the layout group after the migration — the Plugins paneldiff --git a/desktop/tests/ui-zoom.test.ts b/desktop/tests/ui-zoom.test.tsnew file mode 100644index 000000000..7373d243e--- /dev/null+++ b/desktop/tests/ui-zoom.test.ts@@ -0,0 +1,90 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file UI zoom: the settings value the View-menu commands and the settings slider+ * both write. The commands walk a fixed set of stops; the slider is free to+ * land between them, so stepping has to work from an off-stop value too.+ * The shell hand-off (window.estella.win.setZoom) is not reachable here — the+ * suite runs in node, where the bridge is absent and applyUiZoom no-ops.+ */+import { describe, it, expect, beforeEach } from 'vitest';+import '@/settings';+import { useSettings } from '@/store/settingsStore';+import {+ UI_SCALE_SETTING, ZOOM_STEPS, ZOOM_MIN, ZOOM_MAX, ZOOM_DEFAULT,+ uiZoom, setUiZoom, stepUiZoom, canZoomIn, canZoomOut,+} from '@/layout/uiZoom';+import { commands, formatKeybinding } from '@/commands';+import { chordMatches } from '@/commands/keybinding';++describe('ui zoom', () => {+ beforeEach(() => setUiZoom(ZOOM_DEFAULT));++ it('defaults to 100% and is the registered setting', () => {+ expect(uiZoom()).toBe(ZOOM_DEFAULT);+ expect(useSettings.getState().getValue(UI_SCALE_SETTING)).toBe(ZOOM_DEFAULT);+ });++ it('walks the stops in both directions', () => {+ stepUiZoom(1);+ expect(uiZoom()).toBe(110);+ stepUiZoom(1);+ expect(uiZoom()).toBe(125);+ stepUiZoom(-1);+ expect(uiZoom()).toBe(110);+ });++ it('steps to the neighbouring stop from a value the slider left between two', () => {+ setUiZoom(85);+ stepUiZoom(1);+ expect(uiZoom()).toBe(90);+ setUiZoom(85);+ stepUiZoom(-1);+ expect(uiZoom()).toBe(80);+ });++ it('clamps to the stop range and stops walking at the ends', () => {+ setUiZoom(999);+ expect(uiZoom()).toBe(ZOOM_MAX);+ expect(canZoomIn()).toBe(false);+ stepUiZoom(1);+ expect(uiZoom()).toBe(ZOOM_MAX);++ setUiZoom(10);+ expect(uiZoom()).toBe(ZOOM_MIN);+ expect(canZoomOut()).toBe(false);+ stepUiZoom(-1);+ expect(uiZoom()).toBe(ZOOM_MIN);+ });++ it('exposes zoom as commands, so the palette and rebinding get it for free', () => {+ const ids = commands.all().map((c) => c.id);+ expect(ids).toEqual(expect.arrayContaining(['view.zoomIn', 'view.zoomOut', 'view.zoomReset']));++ setUiZoom(150);+ commands.run('view.zoomReset');+ expect(uiZoom()).toBe(ZOOM_DEFAULT);+ // Reset is a no-op at 100%, so it reads disabled rather than doing nothing.+ expect(commands.get('view.zoomReset')?.isEnabled?.()).toBe(false);+ });++ it('keeps every stop reachable by the 5% slider step', () => {+ expect(ZOOM_STEPS.every((s) => s % 5 === 0)).toBe(true);+ });++ // "The + key" arrives as three different events, and the chord grammar joins on+ // '+' — so the literal key can only be spelled by name. All three must land.+ it('matches every way the zoom-in key arrives', () => {+ const kb = commands.get('view.zoomIn')!.keybinding!;+ const ev = (key: string, shiftKey = false) =>+ ({ key, ctrlKey: true, metaKey: false, altKey: false, shiftKey }) as KeyboardEvent;++ expect(chordMatches(ev('='), kb)).toBe(true); // unshifted =+ expect(chordMatches(ev('+'), kb)).toBe(true); // numpad ++ expect(chordMatches(ev('+', true), kb)).toBe(true); // shift-=+ expect(chordMatches(ev('-'), kb)).toBe(false);+ // The hint shows the unshifted key, not the spelled-out name.+ expect(formatKeybinding(kb)).toMatch(/=$/);+ expect(formatKeybinding('mod+plus')).toMatch(/\+$/);+ });+});