Dispatch a synthetic click on quick taps

touchstart's preventDefault suppresses the click events that
foliate's link handling and the overlayer's highlight hit-testing
depend on; dispatch one at the tapped element so internal links
and the highlight edit popover work on touch as on desktop.
This commit is contained in:
John O'Keefe
2026-09-15 12:43:24 -04:00
parent 914ade8a79
commit f872a01d53
+7 -4
View File
@@ -733,10 +733,13 @@ export class Paginator extends HTMLElement {
if (wasSelecting || e.changedTouches.length !== 1) return
const touch = e.changedTouches[0]
// touchstart's preventDefault suppresses click
// events; follow links directly
const link = doc.elementFromPoint(touch.clientX, touch.clientY)
?.closest('a')
link?.click()
// events; dispatch one so foliate's link handling and
// the overlayer's highlight hit-testing (the edit
// popover) behave as on desktop
const el = doc.elementFromPoint(touch.clientX, touch.clientY)
el?.dispatchEvent(new (doc.defaultView ?? window).MouseEvent(
'click', { clientX: touch.clientX, clientY: touch.clientY,
bubbles: true, cancelable: true }))
})
doc.addEventListener('touchcancel', clearGesture)
doc.addEventListener('contextmenu', e => e.preventDefault())