From 615df6541531e63dda198db6448e31ec14ec52cf Mon Sep 17 00:00:00 2001 From: George Brocklehurst Date: Sat, 19 Jul 2025 18:04:28 +0100 Subject: [PATCH] Fix ctrl+clicking on a downtime action on macOS (#378) * Refactor: handle button data attrs the same. A small refactor to handle `button.dataset.move` (which was assigned to a local const) and `button.dataset.category` (which was accessed directly) in the same way by assigning them both to local consts. * Fix right-click on downtime activities on macOS. On macOS with a single-button mouse (e.g. a laptop trackpad) it's common to trigger a right-click with ctrl+click. In Chrome, this triggers both a `contextmenu` event and a regular `click` event. In the context of downtime actions, this meant that we were deselecting an action in the `contextmenu` handler but then immediately re-selecting it again in the `click` handler. This commit works around the problem by stopping the event from propagating further. This fixes the bug, but also stops Foundry's default `contextmenu` handler from firing and preventing the browser context menu from appearing, so we also have prevent the event's default behaviour from firing. --- module/applications/dialogs/downtime.mjs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/module/applications/dialogs/downtime.mjs b/module/applications/dialogs/downtime.mjs index 15add3ad..4922b4ed 100644 --- a/module/applications/dialogs/downtime.mjs +++ b/module/applications/dialogs/downtime.mjs @@ -113,13 +113,24 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV deselectMove(event) { const button = event.target.closest('.activity-container'); - const move = button.dataset.move; - this.moveData[button.dataset.category].moves[move].selected = this.moveData[button.dataset.category].moves[move] - .selected - ? this.moveData[button.dataset.category].moves[move].selected - 1 + const { move, category } = button.dataset; + this.moveData[category].moves[move].selected = this.moveData[category].moves[move].selected + ? this.moveData[category].moves[move].selected - 1 : 0; this.render(); + + // On macOS with a single-button mouse (e.g. a laptop trackpad), + // right-click is triggered with ctrl+click, which triggers both a + // `contextmenu` event and a regular click event. We need to stop + // event propagation to prevent the click event from triggering the + // `selectMove` function and undoing the change we just made. + event.stopPropagation(); + + // Having stopped propagation, we're no longer subject to Foundry's + // default `contextmenu` handler, so we also have to prevent the + // default behaviour to prevent a context menu from appearing. + event.preventDefault(); } static async takeDowntime() {