Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): stop scroll zoom sticking at each zoom preset

joshistoasta4ef20c21dad
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.json
index 07204f34aa..583ec98184 100644
--- a/invokeai/frontend/webv2/performance/architecture-baseline.json
+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json
@@ -807,9 +807,7 @@
"src/features/models/ui/ModelManagerView.tsx",
"src/features/nodes/ui/NodeManagerView.tsx"
],
- "editorForbiddenInitialChunkNames": [
- "ag-psd"
- ],
+ "editorForbiddenInitialChunkNames": ["ag-psd"],
"inactiveWidgetGateOwner": "deepen-widget-registry-loading"
}
}
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
index 8907038760..1f6ae88135 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/capabilities.ts
@@ -466,7 +466,7 @@ export { canMergeVisibleRasters } from './document/mergeVisible';
export { documentToExportLocalSamPoint } from './samCoordinates';
export { bboxEquals, constrainBboxToRatio, roundBbox } from './tools/bboxHitTest';
export { isEmpty, union } from './math/rect';
-export { ZOOM_SNAP_CANDIDATES } from './math/snapping';
+export { ZOOM_PRESETS } from './math/snapping';
export { isLayerPixelEditEligible } from './editing/controlPixelEdit';
export { type HideableLayer, isHideableLayer, isLayerHidden } from './document/sources';
export {
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.test.ts
index e6c6202012..87006be129 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.test.ts
@@ -8,42 +8,14 @@ import {
snapMovedPoint,
snapRectToGrid,
snapToGrid,
- snapZoom,
ZOOM_MAX,
ZOOM_MIN,
- ZOOM_SNAP_CANDIDATES,
+ ZOOM_PRESETS,
} from './snapping';
-describe('snapZoom', () => {
- it('snaps to an exact candidate', () => {
- expect(snapZoom(1)).toBe(1);
- expect(snapZoom(0.25)).toBe(0.25);
- });
-
- it('snaps a value within tolerance of a candidate', () => {
- expect(snapZoom(1.02)).toBe(1);
- expect(snapZoom(0.98)).toBe(1);
- });
-
- it('passes through a value outside tolerance of any candidate', () => {
- expect(snapZoom(1.2)).toBe(1.2);
- expect(snapZoom(0.6)).toBe(0.6);
- });
-
- it('snaps at the tolerance boundary and passes through just beyond it', () => {
- const candidate = 2;
- const tolerance = candidate * 0.03;
- expect(snapZoom(candidate + tolerance * 0.99)).toBe(candidate);
- expect(snapZoom(candidate + tolerance * 1.5)).toBeCloseTo(candidate + tolerance * 1.5, 10);
- });
-
- it('supports custom candidates', () => {
- expect(snapZoom(1.01, [1, 10])).toBe(1);
- expect(snapZoom(5, [1, 10])).toBe(5);
- });
-
+describe('ZOOM_PRESETS', () => {
it('exports the default candidates as a stable list', () => {
- expect(ZOOM_SNAP_CANDIDATES).toEqual([0.25, 0.33, 0.5, 0.67, 0.75, 1, 1.25, 1.5, 2, 3, 4, 5]);
+ expect(ZOOM_PRESETS).toEqual([0.25, 0.33, 0.5, 0.67, 0.75, 1, 1.25, 1.5, 2, 3, 4, 5]);
});
});
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.ts
index cef4531427..97bcbab04f 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/math/snapping.ts
@@ -6,11 +6,13 @@
import type { Rect, Vec2 } from '@workbench/canvas-engine/types';
-/** Zoom levels the viewport snaps to when close enough. Single source of truth for the HUD. */
-export const ZOOM_SNAP_CANDIDATES: readonly number[] = [0.25, 0.33, 0.5, 0.67, 0.75, 1, 1.25, 1.5, 2, 3, 4, 5];
-
-/** Relative tolerance (fraction of the candidate value) used by `snapZoom`. */
-export const ZOOM_SNAP_TOLERANCE = 0.03;
+/**
+ * The zoom levels the HUD dropdown offers. Presets only — wheel zoom is
+ * continuous and deliberately does NOT snap to these: a ~3% capture band around
+ * every level meant a slow scroll stalled at each one and had to be pushed out,
+ * which reads as the zoom sticking rather than as a helpful detent.
+ */
+export const ZOOM_PRESETS: readonly number[] = [0.25, 0.33, 0.5, 0.67, 0.75, 1, 1.25, 1.5, 2, 3, 4, 5];
/** Minimum allowed zoom, used by `clampZoom`. */
export const ZOOM_MIN = 0.1;
@@ -18,27 +20,6 @@ export const ZOOM_MIN = 0.1;
/** Maximum allowed zoom, used by `clampZoom`. */
export const ZOOM_MAX = 20;
-/**
- * Snaps `zoom` to the nearest of `candidates` if it's within a ~3% relative
- * tolerance of that candidate; otherwise returns `zoom` unchanged.
- */
-export const snapZoom = (zoom: number, candidates: readonly number[] = ZOOM_SNAP_CANDIDATES): number => {
- let closest: number | null = null;
- let closestDelta = Infinity;
- for (const candidate of candidates) {
- const delta = Math.abs(zoom - candidate);
- if (delta < closestDelta) {
- closestDelta = delta;
- closest = candidate;
- }
- }
- if (closest === null) {
- return zoom;
- }
- const tolerance = closest * ZOOM_SNAP_TOLERANCE;
- return closestDelta <= tolerance ? closest : zoom;
-};
-
/** Clamps `zoom` to `[ZOOM_MIN, ZOOM_MAX]`. */
export const clampZoom = (zoom: number): number => Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, zoom));
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.test.ts
index 6558f61a7f..6780a14d2a 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.test.ts
@@ -1,7 +1,7 @@
import type { Vec2 } from '@workbench/canvas-engine/types';
import { applyToPoint } from '@workbench/canvas-engine/math/mat2d';
-import { ZOOM_SNAP_CANDIDATES } from '@workbench/canvas-engine/math/snapping';
+import { ZOOM_PRESETS } from '@workbench/canvas-engine/math/snapping';
import { describe, expect, it, vi } from 'vitest';
import { createViewport } from './viewport';
@@ -42,13 +42,25 @@ describe('createViewport', () => {
closeTo(vp.documentToScreen(docUnderAnchorBefore), anchor);
});
- it('wheelZoom snaps to a candidate when the exponential step lands near one', () => {
+ it('wheelZoom is continuous and does not snap to a preset', () => {
+ // Zoom used to be captured by a ~3% band around every preset, so a slow
+ // scroll stalled at each one; a small step must now actually move.
const vp = createViewport({ pan: { x: 0, y: 0 }, zoom: 1 });
const anchor: Vec2 = { x: 0, y: 0 };
- // A tiny negative deltaY nudges zoom just above 1; it should snap back to 1.
+
vp.wheelZoom(-1, anchor);
- expect(vp.getZoom()).toBe(1);
- expect(ZOOM_SNAP_CANDIDATES).toContain(vp.getZoom());
+ expect(vp.getZoom()).toBeGreaterThan(1);
+ expect(ZOOM_PRESETS).not.toContain(vp.getZoom());
+ });
+
+ it('wheelZoom crosses a preset instead of parking on it', () => {
+ // 0.99 sits inside the old ~3% capture band around 1, so a notch used to
+ // land exactly on the preset. It must now pass straight through.
+ const vp = createViewport({ pan: { x: 0, y: 0 }, zoom: 0.99 });
+
+ vp.wheelZoom(-100, { x: 0, y: 0 });
+
+ expect(vp.getZoom()).toBeGreaterThan(1);
});
it('wheelZoom zooms out on positive deltaY and in on negative deltaY', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.ts
index 4a76ec1159..49ed368045 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/viewport.ts
@@ -29,7 +29,7 @@
import type { Mat2d, Rect, Vec2 } from '@workbench/canvas-engine/types';
-import { clampZoom, snapZoom } from '@workbench/canvas-engine/math/snapping';
+import { clampZoom } from '@workbench/canvas-engine/math/snapping';
import {
panBy as calculatePanBy,
wheelZoomAtPoint as calculateWheelZoomAtPoint,
@@ -71,7 +71,7 @@ export interface Viewport {
documentToScreen(p: Vec2): Vec2;
/** Sets zoom while keeping the document point under `screenAnchor` fixed. */
zoomAtPoint(newZoom: number, screenAnchor: Vec2): void;
- /** Exponential wheel zoom about `screenAnchor`, snapping near common zoom levels. */
+ /** Exponential wheel zoom about `screenAnchor`. Continuous — never snaps to a preset. */
wheelZoom(deltaY: number, screenAnchor: Vec2): void;
/** Pans by a CSS-pixel screen delta. */
panBy(screenDelta: Vec2): void;
@@ -122,10 +122,7 @@ export const createViewport = (initial?: Partial<ViewState>): Viewport => {
};
const wheelZoom = (deltaY: number, screenAnchor: Vec2): void => {
- const next = calculateWheelZoomAtPoint({ pan, zoom }, deltaY, screenAnchor, {
- constrainZoom: clampZoom,
- snapZoom,
- });
+ const next = calculateWheelZoomAtPoint({ pan, zoom }, deltaY, screenAnchor, { constrainZoom: clampZoom });
zoom = next.zoom;
pan = next.pan;
emit();
diff --git a/invokeai/frontend/webv2/src/workbench/panZoom.test.ts b/invokeai/frontend/webv2/src/workbench/panZoom.test.ts
index 0e4573f327..72cfa56a4b 100644
--- a/invokeai/frontend/webv2/src/workbench/panZoom.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/panZoom.test.ts
@@ -28,18 +28,19 @@ describe('panZoom', () => {
expect(next).toBe(atMaximum);
});
- it('applies wheel sensitivity and optional snapping through the same constrained transition', () => {
+ it('applies wheel sensitivity through the constrained transition', () => {
const next = wheelZoomAtPoint(
{ pan: { x: 0, y: 0 }, zoom: 1 },
-1,
{ x: 100, y: 50 },
{
constrainZoom: clamp(0.1, 20),
- snapZoom: () => 1,
}
);
- expect(next).toEqual({ pan: { x: 0, y: 0 }, zoom: 1 });
+ // A one-unit wheel delta is a small continuous step, not a jump to a preset.
+ expect(next.zoom).toBeGreaterThan(1);
+ expect(next.zoom).toBeLessThan(1.01);
});
it('pans in screen space without changing zoom', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/panZoom.ts b/invokeai/frontend/webv2/src/workbench/panZoom.ts
index 67c731ce1a..a3807279b3 100644
--- a/invokeai/frontend/webv2/src/workbench/panZoom.ts
+++ b/invokeai/frontend/webv2/src/workbench/panZoom.ts
@@ -55,19 +55,11 @@ export const wheelZoomAtPoint = (
transform: PanZoomTransform,
deltaY: number,
screenAnchor: PanZoomPoint,
- {
- constrainZoom,
- snapZoom = (zoom) => zoom,
- step = WHEEL_ZOOM_STEP,
- }: {
- constrainZoom: ConstrainZoom;
- snapZoom?: (zoom: number) => number;
- step?: number;
- }
+ { constrainZoom, step = WHEEL_ZOOM_STEP }: { constrainZoom: ConstrainZoom; step?: number }
): PanZoomTransform => {
const target = constrainZoom(transform.zoom * Math.exp(-deltaY * step));
- return zoomAtPoint(transform, snapZoom(target), screenAnchor, constrainZoom);
+ return zoomAtPoint(transform, target, screenAnchor, constrainZoom);
};
/** Pans by a screen-space delta. */
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.test.ts
index 7736f79034..3f98afa6fb 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.test.ts
@@ -1,4 +1,4 @@
-import { ZOOM_SNAP_CANDIDATES } from '@workbench/canvas-engine/math/snapping';
+import { ZOOM_PRESETS } from '@workbench/canvas-engine/math/snapping';
import { describe, expect, it } from 'vitest';
import { formatZoomPercent, zoomMenuOptions } from './zoomOptions';
@@ -19,14 +19,14 @@ describe('formatZoomPercent', () => {
describe('zoomMenuOptions', () => {
it('covers every snap candidate', () => {
const options = zoomMenuOptions();
- expect(options).toHaveLength(ZOOM_SNAP_CANDIDATES.length);
- expect(new Set(options.map((option) => option.value))).toEqual(new Set(ZOOM_SNAP_CANDIDATES));
+ expect(options).toHaveLength(ZOOM_PRESETS.length);
+ expect(new Set(options.map((option) => option.value))).toEqual(new Set(ZOOM_PRESETS));
});
it('is ordered from largest to smallest zoom', () => {
const values = zoomMenuOptions().map((option) => option.value);
expect(values).toEqual([...values].sort((a, b) => b - a));
- expect(values[0]).toBe(Math.max(...ZOOM_SNAP_CANDIDATES));
+ expect(values[0]).toBe(Math.max(...ZOOM_PRESETS));
});
it('pairs each value with its formatted label', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.ts
index e3bce05911..6f8b6c3b04 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/zoomOptions.ts
@@ -2,11 +2,11 @@
* Pure zoom-menu helpers for the canvas HUD.
*
* The option set is derived from the engine's single source of truth for zoom
- * snap points (`ZOOM_SNAP_CANDIDATES`), so the HUD and the viewport's wheel
+ * snap points (`ZOOM_PRESETS`), so the HUD and the viewport's wheel
* snapping always agree. No React, no side effects — unit-testable in node.
*/
-import { ZOOM_SNAP_CANDIDATES } from '@workbench/canvas-engine/api';
+import { ZOOM_PRESETS } from '@workbench/canvas-engine/api';
/** Formats a zoom factor as a rounded whole-percent label (e.g. `1` → `"100%"`). */
export const formatZoomPercent = (zoom: number): string => `${Math.round(zoom * 100)}%`;
@@ -19,4 +19,4 @@ export interface ZoomMenuOption {
/** The selectable zoom levels for the HUD menu, largest first (matches snap points top-down). */
export const zoomMenuOptions = (): ZoomMenuOption[] =>
- [...ZOOM_SNAP_CANDIDATES].sort((a, b) => b - a).map((value) => ({ label: formatZoomPercent(value), value }));
+ [...ZOOM_PRESETS].sort((a, b) => b - a).map((value) => ({ label: formatZoomPercent(value), value }));