diff --git a/app/javascript/controllers/games/current/board/desktop_controller.js b/app/javascript/controllers/games/current/board/desktop_controller.js index 3c5a4c17..fc467d77 100644 --- a/app/javascript/controllers/games/current/board/desktop_controller.js +++ b/app/javascript/controllers/games/current/board/desktop_controller.js @@ -20,12 +20,18 @@ export default class extends Controller { revealNeighborsUrl: String, } - static cellIdRegex = /cells\/(\d+)\// + static highlightNeighborsDelay = 100 // ms dispatchMousedown(event) { if (!mouse(event).actsAsLeftClick()) return - cell(event.target).highlightNeighbors(this.highlightNeighborsUrlValue) + this.highlightNeighborsTimer = setTimeout(() => { + cell(event.target).highlightNeighbors(this.highlightNeighborsUrlValue) + }, this.constructor.highlightNeighborsDelay) + } + + dispatchMouseup() { + clearTimeout(this.highlightNeighborsTimer) } dispatchContextmenu(event) { diff --git a/app/views/games/current/board/_content.html.erb b/app/views/games/current/board/_content.html.erb index bf0950b6..bc68bd10 100644 --- a/app/views/games/current/board/_content.html.erb +++ b/app/views/games/current/board/_content.html.erb @@ -31,6 +31,7 @@ data-<%= controller %>-reveal-neighbors-url-value="<%= content.reveal_neighbors_url %>" data-action=" mousedown-><%= controller %>#dispatchMousedown + mouseup-><%= controller %>#dispatchMouseup contextmenu-><%= controller %>#dispatchContextmenu:prevent click-><%= controller %>#dispatchClick "