This commit is contained in:
2025-12-03 09:59:51 +01:00
parent 9ad6cae249
commit 0a93942771

View File

@@ -4,18 +4,17 @@
let container: HTMLDivElement; let container: HTMLDivElement;
let isPanning = false; let isPanning = false;
let hasPanned = false;
let lastX = 0; let lastX = 0;
let lastY = 0; let lastY = 0;
function handleMouseDown(e: MouseEvent) { function handleMouseDown(e: MouseEvent) {
if (e.button === 1 || (e.button === 0 && e.shiftKey)) { if (e.button === 1 || (e.button === 0 && (e.shiftKey || e.target === container))) {
isPanning = true; isPanning = true;
hasPanned = false;
lastX = e.clientX; lastX = e.clientX;
lastY = e.clientY; lastY = e.clientY;
e.preventDefault(); e.preventDefault();
} else if (e.button === 0 && e.target === container) {
state.select(null);
state.focus(null);
} }
} }
@@ -23,12 +22,17 @@
if (!isPanning) return; if (!isPanning) return;
const dx = e.clientX - lastX; const dx = e.clientX - lastX;
const dy = e.clientY - lastY; const dy = e.clientY - lastY;
if (dx !== 0 || dy !== 0) hasPanned = true;
lastX = e.clientX; lastX = e.clientX;
lastY = e.clientY; lastY = e.clientY;
state.pan(dx, dy); state.pan(dx, dy);
} }
function handleMouseUp() { function handleMouseUp(e: MouseEvent) {
if (isPanning && !hasPanned && e.target === container) {
state.select(null);
state.focus(null);
}
isPanning = false; isPanning = false;
} }