Skip to content

Commit ee66c27

Browse files
committed
Click debouncing for context menu
1 parent a645b54 commit ee66c27

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

scripts/communityScripts/contextMenu.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const CLICK_FUNC_CHANNEL = "org.overte.context-menu.click";
2929
const ACTIONS_CHANNEL = "org.overte.context-menu.actions";
3030
const MAIN_CHANNEL = "org.overte.context-menu";
3131

32+
const DEBOUNCE_THRESHOLD_MS = 50;
33+
3234
const SENSOR_TO_WORLD_MATRIX_INDEX = 65534;
3335
const CAMERA_MATRIX_INDEX = 65529;
3436

@@ -178,6 +180,7 @@ let currentMenuInSubmenu = false;
178180
let currentMenuTargetLine = Uuid.NULL;
179181
let mouseWasCaptured = false;
180182
let disableCounter = 0;
183+
let prevClickTime = Date.now();
181184

182185
function ContextMenu_DeleteMenu() {
183186
currentMenuEntities.forEach((_, e) => Entities.deleteEntity(e));
@@ -194,7 +197,9 @@ function ContextMenu_DeleteMenu() {
194197
function ContextMenu_EntityClick(eid, event) {
195198
if (!event.isPrimaryButton) { return; }
196199
if (!currentMenuEntities.has(eid)) { return; }
200+
if (Date.now() < prevClickTime + DEBOUNCE_THRESHOLD_MS) { return; }
197201

202+
prevClickTime = Date.now();
198203
currentMenuInSubmenu = false;
199204

200205
try {

0 commit comments

Comments
 (0)