refactor(canvas): install wheel zoom via a passive-safe native listener

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>
This commit is contained in:
2026-07-16 16:40:39 +08:00
parent f36222c6c6
commit 57a9aba03e
3 changed files with 46 additions and 6 deletions
+29
View File
@@ -0,0 +1,29 @@
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);
});