From 40aa6fcfdc4cc1edb91a8af13fcbae9084a41563 Mon Sep 17 00:00:00 2001 From: Davide Passoni Date: Wed, 26 Mar 2025 09:48:12 +0100 Subject: [PATCH] fix: Quick box selection causes units to be immediately deselected --- frontend/react/src/map/map.ts | 26 +++++++------------ ...{mapMouseHandler.ts => mapmousehandler.ts} | 17 ++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) rename frontend/react/src/map/{mapMouseHandler.ts => mapmousehandler.ts} (93%) diff --git a/frontend/react/src/map/map.ts b/frontend/react/src/map/map.ts index d3c9c4a8..13147d3d 100644 --- a/frontend/react/src/map/map.ts +++ b/frontend/react/src/map/map.ts @@ -948,29 +948,25 @@ export class Map extends L.Map { #onDragStart(e: any) { this.#isDragging = true; + + this.#mouseHandler.stopEvents(); } #onDragEnd(e: any) { - /* Delay the drag end event so that any other event in the queue still sees the map in dragging mode */ - window.setTimeout(() => { - this.#isDragging = false; - }, SHORT_PRESS_MILLISECONDS + 100); + this.#isDragging = false; } #onSelectionStart(e: any) { this.#isSelecting = true; + + this.#mouseHandler.stopEvents(); } #onSelectionEnd(e: any) { getApp().getUnitsManager().selectFromBounds(e.selectionBounds); - // Autodisable the selection mode if touchscreen - if ("ontouchstart" in window) this.setSelectionEnabled(false); - - /* Delay the event so that any other event in the queue still sees the map in selection mode */ - window.setTimeout(() => { - this.#isSelecting = false; - }, SHORT_PRESS_MILLISECONDS + 100); + this.setSelectionEnabled(false); + this.#isSelecting = false; } #onLeftMouseReleased(e: any) { @@ -981,12 +977,6 @@ export class Map extends L.Map { } this.#isRotatingDestination = false; this.setKeepRelativePositions(false); - - /* Delay the event so that any other event in the queue still sees the map in selection mode */ - window.setTimeout(() => { - this.setSelectionEnabled(false); - this.#isSelecting = false; - }, SHORT_PRESS_MILLISECONDS + 100); } #onMouseWheelReleased(e: any) { @@ -1280,6 +1270,8 @@ export class Map extends L.Map { this.#previousZoom = this.getZoom(); if (this.#centeredUnit != null) this.#panToUnit(this.#centeredUnit); this.#isZooming = true; + + this.#mouseHandler.stopEvents(); } #onZoom(e: any) { diff --git a/frontend/react/src/map/mapMouseHandler.ts b/frontend/react/src/map/mapmousehandler.ts similarity index 93% rename from frontend/react/src/map/mapMouseHandler.ts rename to frontend/react/src/map/mapmousehandler.ts index d99193ab..0b7246d3 100644 --- a/frontend/react/src/map/mapMouseHandler.ts +++ b/frontend/react/src/map/mapmousehandler.ts @@ -69,6 +69,23 @@ export class MapMouseHandler { this.#state = state; } + stopEvents() { + if (this.#leftMouseDownTimeout) { + clearTimeout(this.#leftMouseDownTimeout); + this.#leftMouseDownTimeout = null; + } + if (this.#rightMouseDownTimeout) { + clearTimeout(this.#rightMouseDownTimeout); + this.#rightMouseDownTimeout = null; + } + if (this.#debounceTimeout) { + clearTimeout(this.#debounceTimeout); + this.#debounceTimeout = null; + } + + this.setState(MapMouseHandlerState.IDLE); + } + #onMouseDown = (e: LeafletMouseEvent) => { if (e.originalEvent.button === 0) { this.leftMousePressed(e);