Skip to content

Commit 11b679a

Browse files
authored
Merge pull request #13577 from PolygonalSun/exclusive-double-click-fix
InputManager: Fix scenario where click can occur when ExclusiveDoubleClickMode = true
2 parents b3fb7e9 + 1e23f03 commit 11b679a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/dev/core/src/Inputs/scene.inputManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ export class InputManager {
518518

519519
if (!clickInfo.hasSwiped && !this._skipPointerTap && !this._isMultiTouchGesture) {
520520
let type = 0;
521-
if (clickInfo.singleClick) {
521+
if (clickInfo.singleClick && !InputManager.ExclusiveDoubleClickMode) {
522522
type = PointerEventTypes.POINTERTAP;
523523
} else if (clickInfo.doubleClick) {
524524
type = PointerEventTypes.POINTERDOUBLETAP;

packages/dev/core/test/unit/DeviceInput/babylon.inputManager.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { NullEngine } from "core/Engines";
1010
import type { Engine } from "core/Engines/engine";
1111
import type { IPointerEvent, IUIEvent } from "core/Events";
1212
import { PointerEventTypes } from "core/Events";
13+
import { InputManager } from "core/Inputs/scene.inputManager";
1314
import { Vector3 } from "core/Maths/math.vector";
1415
import { MeshBuilder } from "core/Meshes/meshBuilder";
1516
import { UtilityLayerRenderer } from "core/Rendering/utilityLayerRenderer";
@@ -526,6 +527,39 @@ describe("InputManager", () => {
526527
expect(tapCt).toBe(1);
527528
});
528529

530+
it("Doesn't fire onPointerOberservable for POINTERTAP when ExclusiveDoubleClickMode is enabled", () => {
531+
let tapCt = 0;
532+
let dblTapCt = 0;
533+
534+
scene!.onPointerObservable.add(() => {
535+
tapCt++;
536+
}, PointerEventTypes.POINTERTAP);
537+
538+
scene!.onPointerObservable.add(() => {
539+
dblTapCt++;
540+
}, PointerEventTypes.POINTERDOUBLETAP);
541+
542+
if (deviceInputSystem) {
543+
// Expect a single tap and double tap
544+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 1);
545+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 0);
546+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 1);
547+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 0);
548+
549+
// Expect only a double tap
550+
InputManager.ExclusiveDoubleClickMode = true;
551+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 1);
552+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 0);
553+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 1);
554+
deviceInputSystem.changeInput(DeviceType.Mouse, 0, PointerInput.LeftClick, 0);
555+
}
556+
// Since this is static, we should reset it to false for other tests
557+
InputManager.ExclusiveDoubleClickMode = false;
558+
559+
expect(tapCt).toBe(1);
560+
expect(dblTapCt).toBe(2);
561+
});
562+
529563
it("can fire onViewMatrixObservable on camera.update", () => {
530564
let viewMatrixChangedCt = 0;
531565

0 commit comments

Comments
 (0)