Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat(editor): wheel-button zoom and "zoom with scroll wheel" preference (#12099)

David Luzar4e758db17e10
diff --git a/packages/excalidraw/CHANGELOG.md b/packages/excalidraw/CHANGELOG.md
index 91a4150f36..d453d86dde 100644
--- a/packages/excalidraw/CHANGELOG.md
+++ b/packages/excalidraw/CHANGELOG.md
@@ -13,6 +13,11 @@ Please add the latest change on the top under the correct section.
## Unreleased
+### Wheel navigation (2026-09-13) [#XXXX](https://github.com/excalidraw/excalidraw/pull/XXXX)
+
+- Scrolling while holding the wheel (middle) mouse button zooms the canvas around the pointer, the same as ctrl/cmd+wheel — a wheel-button pan can be zoomed one-handed, without reaching for a modifier.
+- New `appState.inputDevice` preference (`"auto" | "mouse" | "trackpad"`, default `"auto"`, persisted in browser storage) selecting the wheel mappings. With `"trackpad"` a plain wheel pans and ctrl/cmd+wheel (how a pinch is delivered) zooms, as before; with `"mouse"` a plain wheel zooms and ctrl/cmd+wheel pans vertically instead, while shift+wheel keeps panning horizontally and the wheel-button zoom above is unaffected. `"auto"` is reserved for detecting the device from the wheel events and resolves to `"trackpad"` until that is implemented (`resolveInputDevice()`). Set it from the new "Input device" radio in the main menu's preferences submenu, also exposed as `MainMenu.DefaultItems.Preferences.InputDevice`.
+
### Sticky notes (2026-09-06) [#XXXX](https://github.com/excalidraw/excalidraw/pull/XXXX)
- New `stickynote` element type and toolbar tool (`N`): an always-filled, flat-rendered note whose label auto-fits — the font shrinks from the user's size down to a minimum, and only then does the note grow in height (it never shrinks below the height the user gave it). Click to place a 250×250 note, drag to size it (previewed at the dragged size, snapped to a font-aware minimum on release); text editing starts right away.
diff --git a/packages/excalidraw/appState.ts b/packages/excalidraw/appState.ts
index 4686895299..703a077282 100644
--- a/packages/excalidraw/appState.ts
+++ b/packages/excalidraw/appState.ts
@@ -15,7 +15,7 @@ import {
DEFAULT_STICKY_NOTE_BG,
} from "@excalidraw/common";
-import type { AppState, NormalizedZoomValue } from "./types";
+import type { AppState, InputDevice, NormalizedZoomValue } from "./types";
const defaultExportScale = EXPORT_SCALES.includes(devicePixelRatio)
? devicePixelRatio
@@ -77,6 +77,7 @@ export const getDefaultAppState = (): Omit<
isBindingEnabled: true,
bindingPreference: "enabled",
isMidpointSnappingEnabled: true,
+ inputDevice: "auto",
defaultSidebarDockedPreference: false,
isLoading: false,
isResizing: false,
@@ -223,6 +224,7 @@ const APP_STATE_STORAGE_CONF = (<
boxSelectionMode: { browser: true, export: false, server: false },
bindingPreference: { browser: true, export: false, server: false },
isMidpointSnappingEnabled: { browser: true, export: false, server: false },
+ inputDevice: { browser: true, export: false, server: false },
defaultSidebarDockedPreference: {
browser: true,
export: false,
@@ -333,3 +335,17 @@ export const isHandToolActive = ({
}) => {
return activeTool.type === "hand";
};
+
+/**
+ * The device the wheel mappings follow for the given preference.
+ *
+ * `auto` is meant to detect the device from the wheel events themselves
+ * (line vs. pixel delta modes, whole vs. fractional deltas, one vs. two axes
+ * moving, event cadence and momentum tails). That is not implemented yet, so
+ * it resolves to `trackpad` — the mapping the editor has always had, and the
+ * default to keep until detection exists.
+ */
+export const resolveInputDevice = (
+ inputDevice: InputDevice,
+): Exclude<InputDevice, "auto"> =>
+ inputDevice === "auto" ? "trackpad" : inputDevice;
diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx
index caab87c90b..9d0826914f 100644
--- a/packages/excalidraw/components/App.tsx
+++ b/packages/excalidraw/components/App.tsx
@@ -50,8 +50,6 @@ import {
TOUCH_CTX_MENU_TIMEOUT,
VERTICAL_ALIGN,
YOUTUBE_STATES,
- ZOOM_STEP,
- MIN_ZOOM,
POINTER_EVENTS,
TOOL_TYPE,
DEFAULT_COLLISION_THRESHOLD,
@@ -452,6 +450,7 @@ import { AppCursor } from "./App.cursor";
import { AppDrawShape } from "./App.drawshape";
import { AppFlowchart } from "./App.flowchart";
import { AppViewport, RIGHT_SIDEBAR_WIDTH } from "./App.viewport";
+import { AppWheel } from "./App.wheel";
import BraveMeasureTextError from "./BraveMeasureTextError";
import { ContextMenu, CONTEXT_MENU_SEPARATOR } from "./ContextMenu";
import { activeEyeDropperAtom } from "./EyeDropper";
@@ -625,6 +624,9 @@ let IS_PLAIN_PASTE_TIMER = 0;
let PLAIN_PASTE_TOAST_SHOWN = false;
let lastPointerUp: (() => void) | null = null;
+/** applies the pointer movement the active drag-pan is holding back for its
+ * next frame, if any */
+let flushPanMove: (() => void) | null = null;
const gesture: Gesture = {
pointers: new Map(),
lastCenter: null,
@@ -721,6 +723,10 @@ class App extends React.Component<AppProps, AppState> {
getStylesPanelMode: () => this.stylesPanelMode,
isGestureActive: () => gesture.pointers.size >= 2 || isPanning,
});
+ public wheel: AppWheel = new AppWheel(this, {
+ isPanning: () => isPanning,
+ flushPanMove: () => flushPanMove?.(),
+ });
bindModeHandler: ReturnType<typeof setTimeout> | null = null;
private textWysiwygSubmitHandler: ReturnType<typeof textWysiwyg> | null =
@@ -2294,7 +2300,6 @@ class App extends React.Component<AppProps, AppState> {
: POINTER_EVENTS.enabled,
}}
onPointerDown={(event) => this.handleCanvasPointerDown(event)}
- onWheel={(event) => this.handleWheel(event)}
onContextMenu={this.handleCanvasContextMenu}
onDoubleClick={() => {
this.setState({
@@ -3205,15 +3210,6 @@ class App extends React.Component<AppProps, AppState> {
event.preventDefault();
};
- // prevent the browser's own zoom over the non-interactive editor while
- // letting regular scroll through (trackpad pinch is delivered as
- // ctrl+wheel)
- private preventBrowserZoomWheel = (event: WheelEvent) => {
- if (event[KEYS.CTRL_OR_CMD]) {
- event.preventDefault();
- }
- };
-
// handles only the navigation keyboard: page-scroll keys and
// `navigation`-flagged action shortcuts (canvas zoom & zoom-to-fit — see
// `ActionManager.handleKeyDown` gates); the rest of the keyboard handling
@@ -4000,7 +3996,7 @@ class App extends React.Component<AppProps, AppState> {
addEventListener(
this.excalidrawContainerRef.current,
EVENT.WHEEL,
- this.handleWheel,
+ this.wheel.handle,
{ passive: false },
),
// navigation action shortcuts (canvas zoom & zoom-to-fit)
@@ -4051,7 +4047,7 @@ class App extends React.Component<AppProps, AppState> {
addEventListener(
this.excalidrawContainerRef.current,
EVENT.WHEEL,
- this.preventBrowserZoomWheel,
+ this.wheel.preventBrowserZoom,
{ passive: false },
),
// Safari-only desktop pinch
@@ -4108,7 +4104,7 @@ class App extends React.Component<AppProps, AppState> {
addEventListener(
this.excalidrawContainerRef.current,
EVENT.WHEEL,
- this.handleWheel,
+ this.wheel.handle,
{ passive: false },
),
addEventListener(this.ownerDocument, EVENT.COPY, this.onCopy, {
@@ -4176,7 +4172,7 @@ class App extends React.Component<AppProps, AppState> {
addEventListener(
this.excalidrawContainerRef.current,
EVENT.WHEEL,
- this.handleWheel,
+ this.wheel.handle,
{ passive: false },
),
addEventListener(
@@ -9159,14 +9155,19 @@ class App extends React.Component<AppProps, AppState> {
this.ownerWindow.addEventListener(EVENT.POINTER_UP, enableNextPaste);
}
- this.viewport.translate({
- scrollX: this.state.scrollX - deltaX / this.state.zoom.value,
- scrollY: this.state.scrollY - deltaY / this.state.zoom.value,
- });
+ // an updater, not a snapshot of `this.state`: a wheel zoom queued in
+ // the same React flush would otherwise be overwritten by a pan
+ // computed from the pre-zoom state
+ this.viewport.translate((state) => ({
+ scrollX: state.scrollX - deltaX / state.zoom.value,
+ scrollY: state.scrollY - deltaY / state.zoom.value,
+ }));
});
+ flushPanMove = onPointerMove.flush;
const teardown = withBatchedUpdates(
(lastPointerUp = () => {
lastPointerUp = null;
+ flushPanMove = null;
isPanning = false;
if (!isHoldingSpace) {
this.cursor.reset();
@@ -13988,100 +13989,6 @@ class App extends React.Component<AppProps, AppState> {
];
};
- private handleWheel = withBatchedUpdates(
- (
- event: WheelEvent | React.WheelEvent<HTMLDivElement | HTMLCanvasElement>,
- ) => {
- // NOTE no preventDefault so the page can scroll over the editor
- if (!this.isNavigationEnabled()) {
- return;
- }
- if (
- !(
- event.target instanceof this.ownerWindow.HTMLCanvasElement ||
- event.target instanceof this.ownerWindow.HTMLTextAreaElement ||
- event.target instanceof this.ownerWindow.HTMLIFrameElement ||
- (event.target instanceof this.ownerWindow.HTMLElement &&
- event.target.classList.contains(CLASSES.FRAME_NAME))
- )
- ) {
- // prevent zooming the browser (but allow scrolling DOM)
- if (event[KEYS.CTRL_OR_CMD]) {
- event.preventDefault();
- }
-
- return;
- }
-
- event.preventDefault();
-
- if (isPanning) {
- return;
- }
-
- const { deltaX, deltaY } = event;
- // note that event.ctrlKey is necessary to handle pinch zooming
- if (event.metaKey || event.ctrlKey) {
- const sign = Math.sign(deltaY);
- const MAX_STEP = ZOOM_STEP * 100;
- const absDelta = Math.abs(deltaY);
- let delta = deltaY;
- if (absDelta > MAX_STEP) {
- delta = MAX_STEP * sign;
- }
-
- let newZoom = this.state.zoom.value - delta / 100;
- // increase zoom steps the more zoomed-in we are (applies to >100% only)
- newZoom +=
- Math.log10(Math.max(1, this.state.zoom.value)) *
- -sign *
- // reduced amplification for small deltas (small movements on a trackpad)
- Math.min(1, absDelta / 20);
-
- const minZoom = this.state.scrollConstraints?.lockZoom
- ? this.state.scrollConstraints.zoom
- : MIN_ZOOM;
- newZoom = Math.max(newZoom, minZoom);
-
- const didTranslate = this.viewport.translate(
- (state) => ({
- ...getViewportForZoomWithScrollConstraints(
- {
- viewportX: this.viewport.lastPosition.x,
- viewportY: this.viewport.lastPosition.y,
- nextZoom: getNormalizedZoom(newZoom),
- },
- state,
- ),
- shouldCacheIgnoreZoom: true,
- }),
- {
- zoomPreConstrained: true,
- preserveScrollConstraintsSnapBack: true,
- },
- );
- if (didTranslate) {
- this.resetShouldCacheIgnoreZoomDebounced();
- }
- return;
- }
-
- // scroll horizontally when shift pressed
- if (event.shiftKey) {
- this.viewport.translate(({ zoom, scrollX }) => ({
- // on Mac, shift+wheel tends to result in deltaX
- scrollX: scrollX - (deltaY || deltaX) / zoom.value,
- }));
- return;
- }
-
- this.viewport.translate(({ zoom, scrollX, scrollY }) => ({
- scrollX: scrollX - deltaX / zoom.value,
- scrollY: scrollY - deltaY / zoom.value,
- }));
- },
- );
-
getTextWysiwygSnappedToCenterPosition(
x: number,
y: number,
@@ -14152,7 +14059,7 @@ class App extends React.Component<AppProps, AppState> {
});
};
- private resetShouldCacheIgnoreZoomDebounced = debounce(() => {
+ public resetShouldCacheIgnoreZoomDebounced = debounce(() => {
if (!this.unmounted) {
this.setState({ shouldCacheIgnoreZoom: false });
}
diff --git a/packages/excalidraw/components/App.viewport.ts b/packages/excalidraw/components/App.viewport.ts
index 2c0257c8fb..301056e70f 100644
--- a/packages/excalidraw/components/App.viewport.ts
+++ b/packages/excalidraw/components/App.viewport.ts
@@ -744,27 +744,40 @@ export class AppViewport {
return false;
}
+ // a user gesture interrupting an animated `setViewport` takes over from
+ // frames that draw from zoom-scaled bitmaps, and the completion handler
+ // that would switch back to crisp ones no longer runs. Otherwise the
+ // flag is left alone: wheel and touch zoom set it and clear it on a
+ // debounce once the gesture is over, and a pan frame landing between two
+ // zoom ticks must not force every element to be re-rasterized at the
+ // in-progress zoom
+ if (this.activeTransition) {
+ this.app.setState({ shouldCacheIgnoreZoom: false });
+ }
this.cancelTransition();
if (!opts?.preserveScrollConstraintsSnapBack) {
AnimationController.cancel(SCROLL_CONSTRAINTS_SNAP_BACK_ANIMATION_KEY);
}
- this.app.setState({ shouldCacheIgnoreZoom: false });
this.app.requestUnfollow();
- const prevZoom = this.app.state.zoom.value;
- this.app.setState(state);
-
- this.app.setState((prevState) => {
- if (!prevState.scrollConstraints) {
+ this.app.setState((prevState, props) => {
+ const update =
+ typeof state === "function" ? state(prevState, props) : state;
+ if (!update) {
return null;
}
+ const nextState = { ...prevState, ...update };
+ if (!nextState.scrollConstraints) {
+ return update;
+ }
const zoomed =
- !opts?.zoomPreConstrained && prevState.zoom.value !== prevZoom;
- const overscroll = zoomed ? 0 : prevState.scrollConstraints.overscroll;
+ !opts?.zoomPreConstrained &&
+ nextState.zoom.value !== prevState.zoom.value;
+ const overscroll = zoomed ? 0 : nextState.scrollConstraints.overscroll;
if (overscroll > 0) {
this.snapBackDebounced();
}
- return constrainScrollState(prevState, overscroll);
+ return { ...nextState, ...constrainScrollState(nextState, overscroll) };
});
return true;
diff --git a/packages/excalidraw/components/App.wheel.ts b/packages/excalidraw/components/App.wheel.ts
new file mode 100644
index 0000000000..6d3a689848
--- /dev/null
+++ b/packages/excalidraw/components/App.wheel.ts
@@ -0,0 +1,184 @@
+import { CLASSES, KEYS, MIN_ZOOM, ZOOM_STEP } from "@excalidraw/common";
+
+import { resolveInputDevice } from "../appState";
+import { withBatchedUpdates } from "../reactUtils";
+import { getNormalizedZoom } from "../scene";
+import { getViewportForZoomWithScrollConstraints } from "../viewport";
+
+import type App from "./App";
+
+/** `MouseEvent.buttons` bit of the wheel (middle) button */
+const WHEEL_BUTTON_MASK = 4;
+
+/**
+ * Wheel input over the editor: pans the canvas, or zooms it around the
+ * pointer (`viewport.lastPosition`) — on ctrl/cmd+wheel (which is also how
+ * a trackpad pinch is delivered), while the wheel button itself is held
+ * down, or on a plain wheel when the input device is a mouse
+ * (`appState.inputDevice`; ctrl/cmd+wheel pans instead then).
+ */
+export class AppWheel {
+ constructor(
+ private app: App,
+ private dependencies: {
+ /** whether a drag-pan (wheel button, space+drag, hand tool) is in
+ * progress — wheel input is ignored meanwhile */
+ isPanning: () => boolean;
+ /** applies the pointer movement the drag-pan is holding back for its
+ * next frame, if any */
+ flushPanMove: () => void;
+ },
+ ) {}
+
+ /** the editor surfaces whose wheel input the editor consumes; everywhere
+ * else (menus, sidebars, …) the DOM keeps scrolling. The frame-name labels
+ * are DOM, but sit inside the container this listener is attached to */
+ private isOverEditorSurface = (event: WheelEvent) => {
+ const { ownerWindow } = this.app;
+ return (
+ event.target instanceof ownerWindow.HTMLCanvasElement ||
+ event.target instanceof ownerWindow.HTMLTextAreaElement ||
+ event.target instanceof ownerWindow.HTMLIFrameElement ||
+ (event.target instanceof ownerWindow.HTMLElement &&
+ event.target.classList.contains(CLASSES.FRAME_NAME))
+ );
+ };
+
+ handle = withBatchedUpdates((event: WheelEvent) => {
+ // NOTE no preventDefault so the page can scroll over the editor
+ if (!this.app.isNavigationEnabled()) {
+ return;
+ }
+ if (!this.isOverEditorSurface(event)) {
+ // prevent zooming the browser (but allow scrolling DOM)
+ if (event[KEYS.CTRL_OR_CMD]) {
+ event.preventDefault();
+ }
+
+ return;
+ }
+
+ event.preventDefault();
+
+ // scrolling with the wheel button held down zooms: the wheel sits under
+ // the same finger, so a wheel-button pan can be zoomed without reaching
+ // for a modifier — hence it wins over any modifier, and over the
+ // drag-pan the button itself started
+ const isWheelButtonHeld = !!(event.buttons & WHEEL_BUTTON_MASK);
+
+ if (this.dependencies.isPanning()) {
+ if (!isWheelButtonHeld) {
+ return;
+ }
+ // the drag-pan applies pointer movement once per frame; a move still
+ // waiting for its frame has to land before the zoom, or it lands after
+ // it — at the new zoom, on a viewport the zoom anchored without it —
+ // and the point grabbed by the pan drifts from under the cursor a
+ // little on every tick
+ this.dependencies.flushPanMove();
+ }
+
+ const { deltaX, deltaY } = event;
+ if (!deltaX && !deltaY) {
+ return;
+ }
+ // note that event.ctrlKey is necessary to handle pinch zooming
+ const hasZoomModifier = event.metaKey || event.ctrlKey;
+ const shouldZoom =
+ // a horizontal-only wheel (tilt wheel, sideways two-finger scroll)
+ // has nothing to zoom by; it pans sideways below instead
+ deltaY !== 0 &&
+ (isWheelButtonHeld ||
+ (resolveInputDevice(this.app.state.inputDevice) === "mouse"
+ ? // a mouse has no pinch: a plain wheel zooms, and any modifier
+ // pans instead (ctrl/cmd vertically, shift horizontally)
+ !hasZoomModifier && !event.shiftKey
+ : hasZoomModifier));
+ if (shouldZoom) {
+ this.zoomBy(deltaY);
+ return;
+ }
+
+ // scroll horizontally when shift pressed
+ if (event.shiftKey) {
+ this.app.viewport.translate(({ zoom, scrollX }) => ({
+ // on Mac, shift+wheel tends to result in deltaX
+ scrollX: scrollX - (deltaY || deltaX) / zoom.value,
+ }));
+ return;
+ }
+
+ this.app.viewport.translate(({ zoom, scrollX, scrollY }) => ({
+ scrollX: scrollX - deltaX / zoom.value,
+ scrollY: scrollY - deltaY / zoom.value,
+ }));
+ });
+
+ /**
+ * Prevents the browser's own zoom over the non-interactive editor while
+ * letting regular scroll through (trackpad pinch is delivered as
+ * ctrl+wheel).
+ */
+ preventBrowserZoom = (event: WheelEvent) => {
+ if (event[KEYS.CTRL_OR_CMD]) {
+ event.preventDefault();
+ }
+ };
+
+ /** zooms around the pointer by a wheel delta (positive = zoom out) */
+ private zoomBy = (deltaY: number) => {
+ const { viewport } = this.app;
+
+ const sign = Math.sign(deltaY);
+ const MAX_STEP = ZOOM_STEP * 100;
+ const absDelta = Math.abs(deltaY);
+ let delta = deltaY;
+ if (absDelta > MAX_STEP) {
+ delta = MAX_STEP * sign;
+ }
+
+ // where the pointer is now — the updater below runs when React flushes,
+ // by which time the pointer may have moved on (`lastPosition` is live)
+ const { x: viewportX, y: viewportY } = viewport.lastPosition;
+
+ const didTranslate = viewport.translate(
+ // computed from the state the zoom applies to, not `app.state`: wheel
+ // ticks arriving before React has flushed the previous one would
+ // otherwise all start from the same zoom and collapse into one step
+ (state) => {
+ let newZoom = state.zoom.value - delta / 100;
+ // increase zoom steps the more zoomed-in we are (applies to >100% only)
+ newZoom +=
+ Math.log10(Math.max(1, state.zoom.value)) *
+ -sign *
+ // reduced amplification for small deltas (small movements on a trackpad)
+ Math.min(1, absDelta / 20);
+
+ const minZoom = state.scrollConstraints?.lockZoom
+ ? state.scrollConstraints.zoom
+ : MIN_ZOOM;
+ const nextZoom = getNormalizedZoom(Math.max(newZoom, minZoom));
+ if (nextZoom === state.zoom.value) {
+ // at a zoom limit there is nothing to do; flipping the bitmap-cache
+ // flag would only redraw the scene on every tick
+ return null;
+ }
+
+ return {
+ ...getViewportForZoomWithScrollConstraints(
+ { viewportX, viewportY, nextZoom },
+ state,
+ ),
+ shouldCacheIgnoreZoom: true,
+ };
+ },
+ {
+ zoomPreConstrained: true,
+ preserveScrollConstraintsSnapBack: true,
+ },
+ );
+ if (didTranslate) {
+ this.app.resetShouldCacheIgnoreZoomDebounced();
+ }
+ };
+}
diff --git a/packages/excalidraw/components/main-menu/DefaultItems.tsx b/packages/excalidraw/components/main-menu/DefaultItems.tsx
index 57098f7704..9757d41d88 100644
--- a/packages/excalidraw/components/main-menu/DefaultItems.tsx
+++ b/packages/excalidraw/components/main-menu/DefaultItems.tsx
@@ -19,6 +19,8 @@ import {
actionToggleZenMode,
} from "../../actions";
import { actionToggleViewMode } from "../../actions/actionToggleViewMode";
+import { resolveInputDevice } from "../../appState";
+
import { getShortcutFromShortcutName } from "../../actions/shortcuts";
import { trackEvent } from "../../analytics";
import { useUIAppState } from "../../context/ui-appState";
@@ -63,6 +65,8 @@ import {
import "./DefaultItems.scss";
+import type { InputDevice } from "../../types";
+
export const LoadScene = () => {
const { t } = useI18n();
const actionManager = useExcalidrawActionManager();
@@ -473,6 +477,40 @@ const PreferencesBoxSelectionModeItem = () => {
);
};
+const PreferencesInputDeviceItem = () => {
+ const { t } = useI18n();
+ const appState = useUIAppState();
+ const setAppState = useExcalidrawSetAppState();
+
+ return (
+ <DropdownMenuItemContentRadio<Exclude<InputDevice, "auto">>
+ name="inputDevice"
+ icon={emptyIcon}
+ // `auto` isn't offered yet; the radio shows what it resolves to
+ value={resolveInputDevice(appState.inputDevice)}
+ onChange={(value) => {
+ setAppState({
+ inputDevice: value,
+ });
+ }}
+ choices={[
+ {
+ value: "trackpad",
+ label: t("labels.inputDeviceTrackpad"),
+ ariaLabel: t("labels.inputDeviceTrackpad"),
+ },
+ {
+ value: "mouse",
+ label: t("labels.inputDeviceMouse"),
+ ariaLabel: t("labels.inputDeviceMouse"),
+ },
+ ]}
+ >
+ {t("labels.inputDevice")}
+ </DropdownMenuItemContentRadio>
+ );
+};
+
const PreferencesToggleSnapModeItem = () => {
const { t } = useI18n();
const actionManager = useExcalidrawActionManager();
@@ -618,6 +656,7 @@ export const Preferences = ({
{children || (
<>
<PreferencesBoxSelectionModeItem />
+ <PreferencesInputDeviceItem />
<PreferencesToggleToolLockItem />
<PreferencesToggleSnapModeItem />
<PreferencesToggleGridModeItem />
@@ -636,6 +675,7 @@ export const Preferences = ({
Preferences.ToggleToolLock = PreferencesToggleToolLockItem;
Preferences.BoxSelectionMode = PreferencesBoxSelectionModeItem;
+Preferences.InputDevice = PreferencesInputDeviceItem;
Preferences.ToggleSnapMode = PreferencesToggleSnapModeItem;
Preferences.ToggleArrowBinding = PreferencesToggleArrowBindingItem;
Preferences.ToggleMidpointSnapping = PreferencesToggleMidpointSnappingItem;
diff --git a/packages/excalidraw/locales/en.json b/packages/excalidraw/locales/en.json
index 3c0733e2fc..f6d6d0ba50 100644
--- a/packages/excalidraw/locales/en.json
+++ b/packages/excalidraw/locales/en.json
@@ -196,7 +196,10 @@
"boxSelectionContain": "Wrap",
"boxSelectionOverlap": "Overlap",
"arrowBinding": "Arrow binding",
- "midpointSnapping": "Snap to midpoints"
+ "midpointSnapping": "Snap to midpoints",
+ "inputDevice": "Input",
+ "inputDeviceTrackpad": "Trackpad",
+ "inputDeviceMouse": "Mouse"
},
"elementLink": {
"title": "Link to object",
diff --git a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap
index 55066011c6..d3d4174534 100644
--- a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap
@@ -941,6 +941,7 @@ exports[`contextMenu element > right-clicking on a group should select whole gro
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -1152,6 +1153,7 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -1378,6 +1380,7 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -1723,6 +1726,7 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2068,6 +2072,7 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2294,6 +2299,7 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2547,6 +2553,7 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2859,6 +2866,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3245,6 +3253,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3779,6 +3788,7 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4116,6 +4126,7 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4453,6 +4464,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5752,6 +5764,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -6983,6 +6996,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -7954,6 +7968,7 @@ exports[`contextMenu element > shows context menu for canvas > [end of test] app
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8964,6 +8979,7 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9965,6 +9981,7 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
"height": 100,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
diff --git a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
index 2eb9478123..f5652ca24d 100644
--- a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
@@ -67,6 +67,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -717,6 +718,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -1294,6 +1296,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -1669,6 +1672,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2045,6 +2049,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2322,6 +2327,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2791,6 +2797,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3112,6 +3119,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3451,6 +3459,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3762,6 +3771,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4063,6 +4073,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4312,6 +4323,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4584,6 +4596,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4872,6 +4885,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5115,6 +5129,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5358,6 +5373,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5620,6 +5636,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5893,6 +5910,7 @@ exports[`history > multiplayer undo/redo > conflicts in frames and their childre
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -6164,6 +6182,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -6507,6 +6526,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -6950,6 +6970,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -7340,6 +7361,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -7666,6 +7688,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -7970,6 +7993,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8212,6 +8236,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8580,6 +8605,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8948,6 +8974,7 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9369,6 +9396,7 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9669,6 +9697,7 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9946,6 +9975,7 @@ exports[`history > multiplayer undo/redo > should not override remote changes on
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10224,6 +10254,7 @@ exports[`history > multiplayer undo/redo > should not override remote changes on
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10468,6 +10499,7 @@ exports[`history > multiplayer undo/redo > should override remotely added groups
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10779,6 +10811,7 @@ exports[`history > multiplayer undo/redo > should override remotely added points
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -11108,6 +11141,7 @@ exports[`history > multiplayer undo/redo > should redistribute deltas when eleme
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -11356,6 +11390,7 @@ exports[`history > multiplayer undo/redo > should redraw arrows on undo > [end o
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -12297,6 +12332,7 @@ exports[`history > multiplayer undo/redo > should update history entries after r
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -12569,6 +12605,7 @@ exports[`history > singleplayer undo/redo > remounting undo/redo buttons should
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -12817,6 +12854,7 @@ exports[`history > singleplayer undo/redo > should clear the redo stack on eleme
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -13067,6 +13105,7 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -13485,6 +13524,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -13707,6 +13747,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -13926,6 +13967,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
"height": 1000,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -14241,6 +14283,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
"height": 1000,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -14553,6 +14596,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on s
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -14811,6 +14855,7 @@ exports[`history > singleplayer undo/redo > should disable undo/redo buttons whe
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -15061,6 +15106,7 @@ exports[`history > singleplayer undo/redo > should end up with no history entry
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -15311,6 +15357,7 @@ exports[`history > singleplayer undo/redo > should iterate through the history w
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -15570,6 +15617,7 @@ exports[`history > singleplayer undo/redo > should not clear the redo stack on s
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -15915,6 +15963,7 @@ exports[`history > singleplayer undo/redo > should not collapse when applying co
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -16096,6 +16145,7 @@ exports[`history > singleplayer undo/redo > should not end up with history entry
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -16394,6 +16444,7 @@ exports[`history > singleplayer undo/redo > should not end up with history entry
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -16671,6 +16722,7 @@ exports[`history > singleplayer undo/redo > should not modify anything on unrela
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -16835,6 +16887,7 @@ exports[`history > singleplayer undo/redo > should not override appstate changes
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -17129,6 +17182,7 @@ exports[`history > singleplayer undo/redo > should support appstate name or view
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -17301,6 +17355,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -18071,6 +18126,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -18739,6 +18795,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -19407,6 +19464,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -20178,6 +20236,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -20968,6 +21027,7 @@ exports[`history > singleplayer undo/redo > should support changes in elements'
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -21464,6 +21524,7 @@ exports[`history > singleplayer undo/redo > should support duplication of groups
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -21995,6 +22056,7 @@ exports[`history > singleplayer undo/redo > should support element creation, del
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -22470,6 +22532,7 @@ exports[`history > singleplayer undo/redo > should support linear element creati
"height": 0,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
diff --git a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
index 220316f8dd..f425de3393 100644
--- a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
@@ -67,6 +67,7 @@ exports[`given element A and group of elements B and given both are selected whe
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -506,6 +507,7 @@ exports[`given element A and group of elements B and given both are selected whe
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -935,6 +937,7 @@ exports[`regression tests > Cmd/Ctrl-click exclusively select element under poin
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -1514,6 +1517,7 @@ exports[`regression tests > Drags selected element when hitting only bounding bo
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -1732,6 +1736,7 @@ exports[`regression tests > adjusts z order when grouping > [end of test] appSta
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2129,6 +2134,7 @@ exports[`regression tests > alt-drag duplicates an element > [end of test] appSt
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2386,6 +2392,7 @@ exports[`regression tests > arrow keys > [end of test] appState 1`] = `
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2577,6 +2584,7 @@ exports[`regression tests > can drag element that covers another element, while
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -2915,6 +2923,7 @@ exports[`regression tests > change the properties of a shape > [end of test] app
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3181,6 +3190,7 @@ exports[`regression tests > click on an element and drag it > [dragged] appState
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3434,6 +3444,7 @@ exports[`regression tests > click on an element and drag it > [end of test] appS
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3681,6 +3692,7 @@ exports[`regression tests > click to select a shape > [end of test] appState 1`]
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -3951,6 +3963,7 @@ exports[`regression tests > click-drag to select a group > [end of test] appStat
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4278,6 +4291,7 @@ exports[`regression tests > deleting last but one element in editing group shoul
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -4726,6 +4740,7 @@ exports[`regression tests > deselects group of selected elements on pointer down
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5022,6 +5037,7 @@ exports[`regression tests > deselects group of selected elements on pointer up w
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5310,6 +5326,7 @@ exports[`regression tests > deselects selected element on pointer down when poin
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5530,6 +5547,7 @@ exports[`regression tests > deselects selected element, on pointer up, when clic
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -5741,6 +5759,7 @@ exports[`regression tests > double click to edit a group > [end of test] appStat
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -6147,6 +6166,7 @@ exports[`regression tests > drags selected elements from point inside common bou
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -6456,6 +6476,7 @@ exports[`regression tests > draw every type of shape > [end of test] appState 1`
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -7266,6 +7287,7 @@ exports[`regression tests > given a group of selected elements with an element t
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -7613,6 +7635,7 @@ exports[`regression tests > given a selected element A and a not selected elemen
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -7904,6 +7927,7 @@ exports[`regression tests > given selected element A with lower z-index than uns
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8151,6 +8175,7 @@ exports[`regression tests > given selected element A with lower z-index than uns
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8403,6 +8428,7 @@ exports[`regression tests > key 2 selects rectangle tool > [end of test] appStat
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8594,6 +8620,7 @@ exports[`regression tests > key 3 selects diamond tool > [end of test] appState
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8785,6 +8812,7 @@ exports[`regression tests > key 4 selects ellipse tool > [end of test] appState
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -8976,6 +9004,7 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9220,6 +9249,7 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9462,6 +9492,7 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] appState
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9669,6 +9700,7 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -9913,6 +9945,7 @@ exports[`regression tests > key d selects diamond tool > [end of test] appState
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10104,6 +10137,7 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10346,6 +10380,7 @@ exports[`regression tests > key o selects ellipse tool > [end of test] appState
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10537,6 +10572,7 @@ exports[`regression tests > key p selects freedraw tool > [end of test] appState
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10744,6 +10780,7 @@ exports[`regression tests > key r selects rectangle tool > [end of test] appStat
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -10935,6 +10972,7 @@ exports[`regression tests > make a group and duplicate it > [end of test] appSta
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -11482,6 +11520,7 @@ exports[`regression tests > noop interaction after undo shouldn't create history
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -11774,6 +11813,7 @@ exports[`regression tests > pinch-to-zoom works > [end of test] appState 1`] = `
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -11907,6 +11947,7 @@ exports[`regression tests > shift click on selected element should deselect it o
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -12118,6 +12159,7 @@ exports[`regression tests > shift-click to multiselect, then drag > [end of test
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -12449,6 +12491,7 @@ exports[`regression tests > should group elements and ungroup them > [end of tes
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -12891,6 +12934,7 @@ exports[`regression tests > single-clicking on a subgroup of a selected group sh
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -13545,6 +13589,7 @@ exports[`regression tests > spacebar + drag scrolls the canvas > [end of test] a
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -13681,6 +13726,7 @@ exports[`regression tests > supports nested groups > [end of test] appState 1`]
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -14325,6 +14371,7 @@ exports[`regression tests > switches from group of selected elements to another
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -14678,6 +14725,7 @@ exports[`regression tests > switches selected element on pointer down > [end of
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -14955,6 +15003,7 @@ exports[`regression tests > two-finger scroll works > [end of test] appState 1`]
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -15088,6 +15137,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -15465,6 +15515,7 @@ exports[`regression tests > updates fontSize & fontFamily appState > [end of tes
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
@@ -15598,6 +15649,7 @@ exports[`regression tests > zoom hotkeys > [end of test] appState 1`] = `
"height": 768,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,
diff --git a/packages/excalidraw/tests/scrollConstraints.test.tsx b/packages/excalidraw/tests/scrollConstraints.test.tsx
index 814271abe7..abbdaaf1e7 100644
--- a/packages/excalidraw/tests/scrollConstraints.test.tsx
+++ b/packages/excalidraw/tests/scrollConstraints.test.tsx
@@ -683,7 +683,9 @@ describe("setViewport lock (integration)", () => {
React.act(() => {
h.app.viewport.setViewport({
target: [2000, 2000, 3000, 3000],
- animation: { duration: 1000 },
+ // long enough that it cannot complete on its own while the test
+ // waits for a frame below, even on a saturated CI machine
+ animation: { duration: 60_000 },
});
});
@@ -692,6 +694,11 @@ describe("setViewport lock (integration)", () => {
);
expect(h.app.viewport.isLockedTransitionPending).toBe(false);
+ // the animation's frames draw from zoom-scaled bitmaps
+ await waitFor(() => {
+ expect(h.state.shouldCacheIgnoreZoom).toBe(true);
+ });
+
React.act(() => {
h.app.viewport.translate({ scrollX: 123, scrollY: 456 });
});
@@ -701,6 +708,9 @@ describe("setViewport lock (integration)", () => {
);
expect(h.state.scrollX).toBe(123);
expect(h.state.scrollY).toBe(456);
+ // the interrupted animation's completion handler no longer runs, so the
+ // interrupting gesture switches back to crisp rasterization itself
+ expect(h.state.shouldCacheIgnoreZoom).toBe(false);
});
it("applies back-to-back lock updates in call order", async () => {
@@ -1192,6 +1202,43 @@ describe("rubberband overscroll (integration)", () => {
mouse.up();
});
+ it("keeps the rubberband overscroll when a pan lands in the same React flush as a wheel-zoom tick", async () => {
+ await render(<Excalidraw handleKeyboardGlobally={true} />);
+ await waitFor(() => expect(h.state.width).toBe(200));
+
+ React.act(() => {
+ h.app.viewport.setViewport({
+ target: [0, 0, 1000, 1000],
+ fit: "scale-down",
+ animation: false,
+ lock: { scroll: true, overscroll: 50 },
+ });
+ });
+
+ // rubberband past the top edge
+ for (let i = 0; i < 20; i++) {
+ Keyboard.keyPress(KEYS.PAGE_UP);
+ }
+ expect(h.state.scrollY).toBeGreaterThan(
+ constrainScrollState(h.state).scrollY,
+ );
+
+ // a zoom tick and a pan queued in one flush (a pan frame runs before
+ // React has flushed the zoom): the pan's constraint pass must not read
+ // the zoom change as its own and hard-clamp the overscroll to zero
+ React.act(() => {
+ fireEvent.wheel(GlobalTestState.interactiveCanvas, {
+ ctrlKey: true,
+ deltaY: -10,
+ });
+ fireEvent.wheel(GlobalTestState.interactiveCanvas, { deltaY: 1 });
+ });
+
+ expect(h.state.scrollY).toBeGreaterThan(
+ constrainScrollState(h.state).scrollY,
+ );
+ });
+
it("continues rubberband snap-back while wheel-zooming", async () => {
await render(<Excalidraw handleKeyboardGlobally={true} />);
await waitFor(() => expect(h.state.width).toBe(200));
diff --git a/packages/excalidraw/tests/wheel.test.tsx b/packages/excalidraw/tests/wheel.test.tsx
new file mode 100644
index 0000000000..fbb0361afd
--- /dev/null
+++ b/packages/excalidraw/tests/wheel.test.tsx
@@ -0,0 +1,354 @@
+import React from "react";
+import { fireEvent, waitFor } from "@testing-library/react";
+import { vi } from "vitest";
+
+import {
+ CLASSES,
+ MIN_ZOOM,
+ viewportCoordsToSceneCoords,
+} from "@excalidraw/common";
+
+import { resolveInputDevice } from "../appState";
+import { Excalidraw } from "../index";
+import { getNormalizedZoom } from "../scene";
+
+import { API } from "./helpers/api";
+import { GlobalTestState, mockBoundingClientRect, render } from "./test-utils";
+
+const { h } = window;
+
+// `withBatchedUpdatesThrottled` — which the drag-pan applies pointer movement
+// through, once per animation frame — is synchronous under the test setup;
+// this lets a test hold the throttled calls back until it releases the frame
+const throttle = vi.hoisted(() => {
+ const pending = new Set<() => void>();
+ return {
+ holding: false,
+ pending,
+ releaseFrame: () => {
+ const frames = [...pending];
+ pending.clear();
+ frames.forEach((frame) => frame());
+ },
+ };
+});
+
+vi.mock("../reactUtils", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("../reactUtils")>();
+ const withBatchedUpdatesThrottled = (fn: (event?: unknown) => void) => {
+ const batched = actual.withBatchedUpdates(fn);
+ let run: (() => void) | null = null;
+ const frame = () => {
+ const pendingRun = run;
+ run = null;
+ pendingRun?.();
+ };
+ const ret = (event?: unknown) => {
+ if (!throttle.holding) {
+ batched(event);
+ return;
+ }
+ run = () => batched(event);
+ throttle.pending.add(frame);
+ };
+ ret.flush = () => {
+ throttle.pending.delete(frame);
+ frame();
+ };
+ ret.cancel = () => {
+ throttle.pending.delete(frame);
+ run = null;
+ };
+ return ret;
+ };
+ return { ...actual, withBatchedUpdatesThrottled };
+});
+
+// the wheel listener is attached natively on the excalidraw container (not
+// via React), so we dispatch a bubbling wheel event from the canvas
+const wheel = (init: WheelEventInit) =>
+ fireEvent.wheel(GlobalTestState.interactiveCanvas, init);
+
+const getViewport = () => ({
+ scrollX: h.state.scrollX,
+ scrollY: h.state.scrollY,
+ zoom: h.state.zoom.value,
+});
+
+/** `MouseEvent.buttons` with only the wheel (middle) button pressed */
+const WHEEL_BUTTON = 4;
+
+const wheelButtonPointer = {
+ pointerId: 1,
+ pointerType: "mouse",
+ // `button` identifies the pressed button, `buttons` the held-down set
+ button: 1,
+ buttons: WHEEL_BUTTON,
+ clientX: 100,
+ clientY: 100,
+};
+
+describe("wheel navigation", () => {
+ beforeEach(async () => {
+ await render(<Excalidraw />);
+ });
+
+ it("pans on plain wheel, horizontally with shift, and zooms on ctrl/cmd+wheel", () => {
+ const start = getViewport();
+
+ wheel({ deltaX: 30, deltaY: 40 });
+ expect(getViewport()).toEqual({
+ ...start,
+ scrollX: start.scrollX - 30,
+ scrollY: start.scrollY - 40,
+ });
+
+ const beforeShift = getViewport();
+ wheel({ deltaY: 40, shiftKey: true });
+ expect(getViewport()).toEqual({
+ ...beforeShift,
+ scrollX: beforeShift.scrollX - 40,
+ });
+
+ const beforeZoom = getViewport();
+ wheel({ deltaY: -100, ctrlKey: true });
+ const zoomedIn = h.state.zoom.value;
+ expect(zoomedIn).toBeGreaterThan(beforeZoom.zoom);
+ wheel({ deltaY: 100, metaKey: true });
+ expect(h.state.zoom.value).toBeLessThan(zoomedIn);
+ });
+
+ it("does nothing on a zoom tick at the zoom limit", () => {
+ API.setAppState({ zoom: { value: getNormalizedZoom(MIN_ZOOM) } });
+ const start = getViewport();
+
+ wheel({ deltaY: 100, ctrlKey: true });
+
+ expect(getViewport()).toEqual(start);
+ // in particular no bitmap-cache flip, which would redraw the scene
+ expect(h.state.shouldCacheIgnoreZoom).toBe(false);
+ });
+
+ describe("wheel button held down", () => {
+ it("zooms instead of panning, whatever the modifiers", () => {
+ const start = getViewport();
+
+ wheel({ deltaY: -100, buttons: WHEEL_BUTTON });
+ const zoomedIn = h.state.zoom.value;
+ expect(zoomedIn).toBeGreaterThan(start.zoom);
+
+ wheel({ deltaY: 100, buttons: WHEEL_BUTTON });
+ const zoomedOut = h.state.zoom.value;
+ expect(zoomedOut).toBeLessThan(zoomedIn);
+
+ // shift would otherwise pan horizontally
+ wheel({ deltaY: -100, buttons: WHEEL_BUTTON, shiftKey: true });
+ expect(h.state.zoom.value).toBeGreaterThan(zoomedOut);
+ });
+
+ it("zooms during the wheel-button drag-pan the button started", () => {
+ fireEvent.pointerDown(
+ GlobalTestState.interactiveCanvas,
+ wheelButtonPointer,
+ );
+
+ // the drag-pan owns the viewport: wheel input without the button
+ // held is swallowed...
+ const start = getViewport();
+ wheel({ deltaY: 40 });
+ expect(getViewport()).toEqual(start);
+
+ // ...but with the button held, it zooms
+ wheel({ deltaY: -100, buttons: WHEEL_BUTTON });
+ expect(h.state.zoom.value).toBeGreaterThan(start.zoom);
+
+ fireEvent.pointerUp(window, { ...wheelButtonPointer, buttons: 0 });
+
+ // pan released — plain wheel pans again
+ const released = getViewport();
+ wheel({ deltaY: 40 });
+ expect(h.state.scrollY).toBeCloseTo(
+ released.scrollY - 40 / released.zoom,
+ );
+ });
+
+ describe("while moving the pointer between zooms", () => {
+ const moved = { ...wheelButtonPointer, clientX: 130, clientY: 120 };
+
+ /** starts a wheel-button drag-pan; returns the scene point grabbed */
+ const grab = () => {
+ fireEvent.pointerDown(
+ GlobalTestState.interactiveCanvas,
+ wheelButtonPointer,
+ );
+ // wheel zoom anchors on the last pointer position
+ fireEvent.pointerMove(
+ GlobalTestState.interactiveCanvas,
+ wheelButtonPointer,
+ );
+ return viewportCoordsToSceneCoords(wheelButtonPointer, h.state);
+ };
+
+ afterEach(() => {
+ // release the pan even when an assertion failed mid-way, so the
+ // module-level pan state doesn't leak into the next test
+ fireEvent.pointerUp(window, { ...moved, buttons: 0 });
+ });
+
+ const expectGrabbedUnderCursor = (grabbed: { x: number; y: number }) => {
+ const underCursor = viewportCoordsToSceneCoords(moved, h.state);
+ expect(underCursor.x).toBeCloseTo(grabbed.x);
+ expect(underCursor.y).toBeCloseTo(grabbed.y);
+ };
+
+ it("keeps the zoom when the pan lands in the same React flush", () => {
+ const grabbed = grab();
+ const startZoom = h.state.zoom.value;
+
+ // the drag-pan's frame runs before React has flushed the zoom the
+ // wheel queued, so both land in one flush — a pan written from the
+ // pre-zoom state would overwrite the zoom's scroll
+ React.act(() => {
+ wheel({ deltaY: -100, ...wheelButtonPointer });
+ fireEvent.pointerMove(GlobalTestState.interactiveCanvas, moved);
+ });
+
+ expect(h.state.zoom.value).toBeGreaterThan(startZoom);
+ expectGrabbedUnderCursor(grabbed);
+ });
+
+ it("applies a move still waiting for its frame before zooming", () => {
+ const grabbed = grab();
+ const start = getViewport();
+
+ throttle.holding = true;
+ try {
+ fireEvent.pointerMove(GlobalTestState.interactiveCanvas, moved);
+ expect(getViewport()).toEqual(start);
+
+ wheel({ deltaY: -100, ...moved });
+ React.act(() => {
+ throttle.releaseFrame();
+ });
+ } finally {
+ throttle.holding = false;
+ }
+
+ expect(h.state.zoom.value).toBeGreaterThan(start.zoom);
+ expectGrabbedUnderCursor(grabbed);
+ });
+
+ it("keeps drawing from zoom-scaled bitmaps until the gesture is over", async () => {
+ grab();
+
+ wheel({ deltaY: -100, ...wheelButtonPointer });
+ expect(h.state.shouldCacheIgnoreZoom).toBe(true);
+
+ // a pan frame between two ticks must not switch back to crisp
+ // rasterization — that re-rasterizes every element at a zoom the
+ // next tick is about to change again
+ fireEvent.pointerMove(GlobalTestState.interactiveCanvas, moved);
+ expect(h.state.shouldCacheIgnoreZoom).toBe(true);
+
+ wheel({ deltaY: -100, ...moved });
+ expect(h.state.shouldCacheIgnoreZoom).toBe(true);
+
+ // ...only once the zoom has been idle for a moment
+ await waitFor(() => {
+ expect(h.state.shouldCacheIgnoreZoom).toBe(false);
+ });
+ });
+ });
+ });
+
+ describe("inputDevice preference", () => {
+ it("defaults to auto, which resolves to trackpad until detection exists", () => {
+ expect(h.state.inputDevice).toBe("auto");
+ expect(resolveInputDevice(h.state.inputDevice)).toBe("trackpad");
+ });
+
+ describe("mouse", () => {
+ beforeEach(() => {
+ API.setAppState({ inputDevice: "mouse" });
+ });
+
+ it("zooms on plain wheel and pans vertically on ctrl/cmd+wheel", () => {
+ const start = getViewport();
+ wheel({ deltaY: -100 });
+ expect(h.state.zoom.value).toBeGreaterThan(start.zoom);
+
+ const zoomed = getViewport();
+ wheel({ deltaY: 40, ctrlKey: true });
+ expect(getViewport()).toEqual({
+ ...zoomed,
+ scrollY: zoomed.scrollY - 40 / zoomed.zoom,
+ });
+
+ const panned = getViewport();
+ wheel({ deltaY: 40, metaKey: true });
+ expect(getViewport()).toEqual({
+ ...panned,
+ scrollY: panned.scrollY - 40 / panned.zoom,
+ });
+ });
+
+ it("keeps shift+wheel panning horizontally", () => {
+ const start = getViewport();
+ wheel({ deltaY: 40, shiftKey: true });
+ expect(getViewport()).toEqual({
+ ...start,
+ scrollX: start.scrollX - 40 / start.zoom,
+ });
+ });
+
+ it("keeps zooming with the wheel button held", () => {
+ const start = getViewport();
+ wheel({ deltaY: -100, buttons: WHEEL_BUTTON, ctrlKey: true });
+ expect(h.state.zoom.value).toBeGreaterThan(start.zoom);
+ });
+
+ it("pans sideways on a horizontal-only wheel instead of zooming", () => {
+ // a tilt wheel or a sideways two-finger scroll
+ const start = getViewport();
+ wheel({ deltaX: 30 });
+ expect(getViewport()).toEqual({
+ ...start,
+ scrollX: start.scrollX - 30 / start.zoom,
+ });
+ expect(h.state.shouldCacheIgnoreZoom).toBe(false);
+ });
+ });
+ });
+});
+
+describe("wheel over a frame label", () => {
+ beforeEach(async () => {
+ // frame labels render only for frames inside the measured viewport
+ mockBoundingClientRect();
+ await render(<Excalidraw />);
+ await waitFor(() => expect(h.state.width).toBe(200));
+ });
+
+ it("is handled once", async () => {
+ const frame = API.createElement({
+ type: "frame",
+ x: 20,
+ y: 30,
+ width: 80,
+ height: 50,
+ });
+ API.setElements([frame]);
+ const label = await waitFor(() => {
+ const element = document.querySelector(`.${CLASSES.FRAME_NAME}`);
+ expect(element).not.toBe(null);
+ return element as HTMLElement;
+ });
+
+ // the label is DOM inside the editor container, whose wheel listener
+ // accepts it; a React `onWheel` on the label itself used to handle the
+ // same event a second time, panning and zooming twice per tick
+ const start = getViewport();
+ fireEvent.wheel(label, { deltaY: 40 });
+ expect(h.state.scrollY).toBeCloseTo(start.scrollY - 40 / start.zoom);
+ });
+});
diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts
index 44fcc9aa16..e24326a6d6 100644
--- a/packages/excalidraw/types.ts
+++ b/packages/excalidraw/types.ts
@@ -280,6 +280,12 @@ export type ObservedElementsAppState = {
export type BoxSelectionMode = "contain" | "overlap";
+/**
+ * The pointing device the wheel mappings are tuned for. `auto` is reserved
+ * for detecting it from the wheel events; see `resolveInputDevice`.
+ */
+export type InputDevice = "auto" | "mouse" | "trackpad";
+
/**
* A box, in scene coordinates, that pan & zoom are constrained to.
*
@@ -360,6 +366,13 @@ export interface AppState {
bindingPreference: "enabled" | "disabled";
/** user preference whether arrow snap to midpoints while binding */
isMidpointSnappingEnabled: boolean;
+ /**
+ * user preference for what the wheel does: with a `trackpad` a plain wheel
+ * pans and ctrl/cmd+wheel (how a pinch is delivered) zooms; with a `mouse`
+ * a plain wheel zooms and ctrl/cmd+wheel pans vertically. `auto` resolves
+ * to `trackpad` until device detection exists — see `resolveInputDevice`
+ */
+ inputDevice: InputDevice;
/**
* The bindable element the UI highlights for the user when an arrow is
* dragged or otherwise its endpoint being close to said element.
diff --git a/packages/utils/tests/__snapshots__/export.test.ts.snap b/packages/utils/tests/__snapshots__/export.test.ts.snap
index 4382fe84a6..10c35bd995 100644
--- a/packages/utils/tests/__snapshots__/export.test.ts.snap
+++ b/packages/utils/tests/__snapshots__/export.test.ts.snap
@@ -67,6 +67,7 @@ exports[`exportToSvg > with default arguments 1`] = `
"gridStep": 5,
"hoveredArrowTextAnchor": null,
"hoveredElementIds": {},
+ "inputDevice": "auto",
"isBindingEnabled": true,
"isCropping": false,
"isLoading": false,