fix: Quick box selection causes units to be immediately deselected

This commit is contained in:
Davide Passoni
2025-03-26 09:48:12 +01:00
parent 41b4328eaf
commit 40aa6fcfdc
2 changed files with 26 additions and 17 deletions

View File

@@ -948,29 +948,25 @@ export class Map extends L.Map {
#onDragStart(e: any) { #onDragStart(e: any) {
this.#isDragging = true; this.#isDragging = true;
this.#mouseHandler.stopEvents();
} }
#onDragEnd(e: any) { #onDragEnd(e: any) {
/* Delay the drag end event so that any other event in the queue still sees the map in dragging mode */ this.#isDragging = false;
window.setTimeout(() => {
this.#isDragging = false;
}, SHORT_PRESS_MILLISECONDS + 100);
} }
#onSelectionStart(e: any) { #onSelectionStart(e: any) {
this.#isSelecting = true; this.#isSelecting = true;
this.#mouseHandler.stopEvents();
} }
#onSelectionEnd(e: any) { #onSelectionEnd(e: any) {
getApp().getUnitsManager().selectFromBounds(e.selectionBounds); getApp().getUnitsManager().selectFromBounds(e.selectionBounds);
// Autodisable the selection mode if touchscreen this.setSelectionEnabled(false);
if ("ontouchstart" in window) this.setSelectionEnabled(false); this.#isSelecting = 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);
} }
#onLeftMouseReleased(e: any) { #onLeftMouseReleased(e: any) {
@@ -981,12 +977,6 @@ export class Map extends L.Map {
} }
this.#isRotatingDestination = false; this.#isRotatingDestination = false;
this.setKeepRelativePositions(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) { #onMouseWheelReleased(e: any) {
@@ -1280,6 +1270,8 @@ export class Map extends L.Map {
this.#previousZoom = this.getZoom(); this.#previousZoom = this.getZoom();
if (this.#centeredUnit != null) this.#panToUnit(this.#centeredUnit); if (this.#centeredUnit != null) this.#panToUnit(this.#centeredUnit);
this.#isZooming = true; this.#isZooming = true;
this.#mouseHandler.stopEvents();
} }
#onZoom(e: any) { #onZoom(e: any) {

View File

@@ -69,6 +69,23 @@ export class MapMouseHandler {
this.#state = state; 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) => { #onMouseDown = (e: LeafletMouseEvent) => {
if (e.originalEvent.button === 0) { if (e.originalEvent.button === 0) {
this.leftMousePressed(e); this.leftMousePressed(e);