From 62e98b1fd8ed5e501b1807933fca9c33cb2c098a Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 29 Nov 2023 16:50:53 +0100 Subject: [PATCH] Fixes #585 --- web/editor_state.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/web/editor_state.ts b/web/editor_state.ts index bb4aad96..352cb0d9 100644 --- a/web/editor_state.ts +++ b/web/editor_state.ts @@ -224,17 +224,30 @@ export function createEditorState( } } - const clickEvent: ClickEvent = { + const pos = view.posAtCoords({ + x: touch.clientX, + y: touch.clientY, + })!; + + const potentialClickEvent: ClickEvent = { page: pageName, ctrlKey: event.ctrlKey, metaKey: event.metaKey, altKey: event.altKey, - pos: view.posAtCoords({ - x: touch.clientX, - y: touch.clientY, - })!, + pos: pos, }; - await client.dispatchAppEvent("page:click", clickEvent); + + const distanceX = touch.clientX - view.coordsAtPos(pos)!.left; + // What we're trying to determine here is if the tap occured anywhere near the looked up position + // this may not be the case with locations that expand signifcantly based on live preview (such as links), we don't want any accidental clicks + // Fixes #585 + // + if (distanceX <= view.defaultCharacterWidth) { + await client.dispatchAppEvent( + "page:click", + potentialClickEvent, + ); + } }); } touchCount = 0;