Refactor event type checks for xypanzoom filter

This commit is contained in:
Moritz Klack
2025-08-26 18:31:27 +02:00
committed by GitHub
parent 61bb5da528
commit 12d9e4ace4
+7 -6
View File
@@ -31,6 +31,7 @@ export function createFilter({
return (event: any): boolean => { return (event: any): boolean => {
const zoomScroll = zoomActivationKeyPressed || zoomOnScroll; const zoomScroll = zoomActivationKeyPressed || zoomOnScroll;
const pinchZoom = zoomOnPinch && event.ctrlKey; const pinchZoom = zoomOnPinch && event.ctrlKey;
const isWheelEvent = event.type === 'wheel';
if ( if (
event.button === 1 && event.button === 1 &&
@@ -51,24 +52,24 @@ export function createFilter({
} }
// we want to disable pinch-zooming while making a connection // we want to disable pinch-zooming while making a connection
if (connectionInProgress && !(event.type === 'wheel')) { if (connectionInProgress && !isWheelEvent) {
return false; return false;
} }
// if the target element is inside an element with the nowheel class, we prevent zooming // if the target element is inside an element with the nowheel class, we prevent zooming
if (isWrappedWithClass(event, noWheelClassName) && event.type === 'wheel') { if (isWrappedWithClass(event, noWheelClassName) && isWheelEvent) {
return false; return false;
} }
// if the target element is inside an element with the nopan class, we prevent panning // if the target element is inside an element with the nopan class, we prevent panning
if ( if (
isWrappedWithClass(event, noPanClassName) && isWrappedWithClass(event, noPanClassName) &&
(event.type !== 'wheel' || (panOnScroll && event.type === 'wheel' && !zoomActivationKeyPressed)) (!isWheelEvent || (panOnScroll && isWheelEvent && !zoomActivationKeyPressed))
) { ) {
return false; return false;
} }
if (!zoomOnPinch && event.ctrlKey && event.type === 'wheel') { if (!zoomOnPinch && event.ctrlKey && isWheelEvent) {
return false; return false;
} }
@@ -78,7 +79,7 @@ export function createFilter({
} }
// when there is no scroll handling enabled, we prevent all wheel events // when there is no scroll handling enabled, we prevent all wheel events
if (!zoomScroll && !panOnScroll && !pinchZoom && event.type === 'wheel') { if (!zoomScroll && !panOnScroll && !pinchZoom && isWheelEvent) {
return false; return false;
} }
@@ -97,6 +98,6 @@ export function createFilter({
(Array.isArray(panOnDrag) && panOnDrag.includes(event.button)) || !event.button || event.button <= 1; (Array.isArray(panOnDrag) && panOnDrag.includes(event.button)) || !event.button || event.button <= 1;
// default filter for d3-zoom // default filter for d3-zoom
return (!event.ctrlKey || event.type === 'wheel') && buttonAllowed; return (!event.ctrlKey || isWheelEvent) && buttonAllowed;
}; };
} }