From fee2c5928ea4d702c7bf78d177ed573601956728 Mon Sep 17 00:00:00 2001 From: Ian Shehadeh Date: Wed, 28 Jun 2023 13:36:22 -0400 Subject: [PATCH] Prevent duplicate tap events (#436) * prevent duplicate click events on mobile * prevent duplicate mouse events on mobile safari * only prevent default event on links I think I misunderstood what was going on originally, mouse and click weren't both triggering it was the default event from the a reference. So, only prevent default behavior on a e;ements, since default handlers are needed on navigation. Oddly, this I've only noticed this fixing navigation on firefox simulator. It wasn't needed on firefox. --- web/editor.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/web/editor.tsx b/web/editor.tsx index db9083f..25f76bb 100644 --- a/web/editor.tsx +++ b/web/editor.tsx @@ -971,6 +971,14 @@ export class Editor { if (touchCount === 0) { safeRun(async () => { const touch = event.changedTouches.item(0)!; + if (!event.altKey && event.target instanceof Element) { + // prevent the browser from opening the link twice + const parentA = event.target.closest("a"); + if (parentA) { + event.preventDefault(); + } + } + const clickEvent: ClickEvent = { page: pageName, ctrlKey: event.ctrlKey, @@ -986,6 +994,7 @@ export class Editor { } touchCount = 0; }, + mousedown: (event: MouseEvent, view: EditorView) => { safeRun(async () => { const pos = view.posAtCoords(event);