57a9aba03e
Move canvas wheel zoom off the React onWheel prop into a manually attached non-passive listener so preventDefault reliably suppresses page scroll, and read the viewport from the ref to keep the handler referentially stable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
30 lines
962 B
JavaScript
30 lines
962 B
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { installCanvasWheelListener } from "../src/ui/pages/CanvasWorkspace/canvas/canvasWheel.ts";
|
|
|
|
test("installs the canvas wheel handler as non-passive and removes it cleanly", () => {
|
|
const calls = [];
|
|
const target = {
|
|
addEventListener(type, listener, options) {
|
|
calls.push({ action: "add", type, listener, options });
|
|
},
|
|
removeEventListener(type, listener) {
|
|
calls.push({ action: "remove", type, listener });
|
|
}
|
|
};
|
|
const listener = () => {};
|
|
|
|
const cleanup = installCanvasWheelListener(target, listener);
|
|
|
|
assert.equal(calls[0].action, "add");
|
|
assert.equal(calls[0].type, "wheel");
|
|
assert.strictEqual(calls[0].listener, listener);
|
|
assert.deepEqual(calls[0].options, { passive: false });
|
|
|
|
cleanup();
|
|
assert.equal(calls[1].action, "remove");
|
|
assert.equal(calls[1].type, "wheel");
|
|
assert.strictEqual(calls[1].listener, listener);
|
|
});
|