Middle mouse button only moves the camera
Deploy web Studio / deploy (push) Successful in 3m9s

A press with the middle (or any other non-left) mouse button never reaches
the Studio's drag, place or select handlers: dragging pans the view even
on a selected object or while placing, and a click selects nothing. A
middle click no longer starts the browser's autoscroll.

check_studio covers a middle-drag on the selected truck (it stays put,
the view moves), a middle click on another object (the selection is
kept), and a middle-drag while placing (nothing is placed).
This commit is contained in:
grabowski committed 2026-10-24 17:52:23 +07:00
1 parent 95ea4a8512
commit 7962249191
3 files changed
+48 -4

No files matched your search

+10 -3
View File
@@ -286,10 +286,14 @@
var ptrs = {}, down = null, moved = false, pinch = null, hoverId = null, claimed = false;
function npt() { return Object.keys(ptrs).length; }
svg.addEventListener("pointerdown", function (e) {
// the middle (or any other non-left) mouse button only moves the camera: it never
// drags, places or selects an object, whatever is under the pointer
var cam = e.pointerType === "mouse" && e.button !== 0;
if (cam && e.button === 1) e.preventDefault();
ptrs[e.pointerId] = { x: e.clientX, y: e.clientY };
if (npt() === 1) {
down = { x: e.clientX, y: e.clientY, id: e.pointerId, t: e.target }; moved = false;
claimed = !!(opts.interact && call(opts.interact.down, e, { obj: targetObj(e.target), id: targetId(e.target), world: toWorld(e.clientX, e.clientY, 0) }));
down = { x: e.clientX, y: e.clientY, id: e.pointerId, t: e.target, cam: cam }; moved = false;
claimed = !cam && !!(opts.interact && call(opts.interact.down, e, { obj: targetObj(e.target), id: targetId(e.target), world: toWorld(e.clientX, e.clientY, 0) }));
if (claimed) { try { svg.setPointerCapture(e.pointerId); } catch (er) { /* ignore */ } }
}
if (npt() === 2) {
@@ -336,12 +340,15 @@
if (npt() < 2) pinch = null;
if (wasDown) {
if (claimed) call(opts.interact.up, e, { moved: moved, world: toWorld(e.clientX, e.clientY, 0), cancel: e.type !== "pointerup" });
else if (!moved && e.type === "pointerup") pick(e.target, e.clientX, e.clientY);
else if (!moved && !down.cam && e.type === "pointerup") pick(e.target, e.clientX, e.clientY);
}
if (npt() === 0) { down = null; claimed = false; wrap.classList.remove("iso-dragging"); }
}
svg.addEventListener("pointerup", up);
svg.addEventListener("pointercancel", up);
// no browser autoscroll or paste on a middle click
svg.addEventListener("mousedown", function (e) { if (e.button === 1) e.preventDefault(); });
svg.addEventListener("auxclick", function (e) { if (e.button === 1) e.preventDefault(); });
svg.addEventListener("pointerleave", function (e) { if (e.pointerType === "mouse" && hoverId) { setHover(hoverId, false); hoverId = null; if (!st.sel) hideTip(); } });
svg.addEventListener("wheel", function (e) {
if (!(e.ctrlKey || e.metaKey || opts.wheelZoom)) return;