diff --git a/web/src/gestures.ts b/web/src/gestures.ts index 5275b9e..409d9e3 100644 --- a/web/src/gestures.ts +++ b/web/src/gestures.ts @@ -118,6 +118,7 @@ function beside(dx: number){ /// beside it with it. function slide(dx: number, ms = 160){ const d = $('#detail'); if(!d) return; + slidAt = Date.now(); dx = Math.round(dx); // whole pixels, or the seam between the reader and its neighbour blurs const w = d.clientWidth || 1, tr = ms ? `transform ${ms}ms ease-out, opacity ${ms}ms ease-out` : 'none'; d.style.transition = tr; @@ -205,7 +206,11 @@ document.addEventListener('touchcancel', () => { if(touch?.pane === 'list') pull /// way, after which it has not moved. Watched by where the finger is, not by what it landed on, /// so something lying over the reader is caught too, and named. Reported with what could hold it, /// since the cause of the one in #383 was never found. -let drag: {x: number, y: number, top: number, on: string} | null = null, shownAt = Date.now(); +// What #450's three reports could not say (#450): where the finger began, whether the page saw it +// move at all (none means the browser kept the drag for itself), whether the page cancelled the +// touch, and how long since the reader was last slid across, the one thing a swipe changes on it. +let drag: {x: number, y: number, top: number, on: string, moves: number, cancelled: boolean} | null = null, + shownAt = Date.now(), slidAt = 0; document.addEventListener('visibilitychange', () => { if(!document.hidden) shownAt = Date.now(); }); const named = (el: Element | null) => !el ? 'nothing' : el.id ? '#' + el.id : el.tagName.toLowerCase() + (typeof el.className === 'string' && el.className ? '.' + el.className.split(' ')[0] : ''); @@ -220,8 +225,11 @@ document.addEventListener('touchstart', ev => { if(ev.touches.length !== 1 || !d || !S.sel) return; const r = d.getBoundingClientRect(); if(t.clientX < r.left || t.clientX > r.right || t.clientY < r.top || t.clientY > r.bottom) return; - drag = {x: t.clientX, y: t.clientY, top: d.scrollTop, on: named(ev.target as Element)}; + drag = {x: t.clientX, y: t.clientY, top: d.scrollTop, on: named(ev.target as Element), moves: 0, cancelled: false}; + // After the swipe's own touchstart, which may cancel it, has run. + queueMicrotask(() => { if(drag) drag.cancelled = ev.defaultPrevented; }); }, {passive: true}); +document.addEventListener('touchmove', () => { if(drag) drag.moves++; }, {passive: true}); document.addEventListener('touchend', ev => { const d = $('#detail'), t = ev.changedTouches[0], g = drag; drag = null; @@ -235,5 +243,7 @@ document.addEventListener('touchend', ev => { `inert ${inert || 'none'}`, `dialog ${$('#modal')?.classList.contains('on') ? 'open' : 'closed'}`, `transform ${d.style.transform || 'none'}`, `peek ${$('#dpeek') ? 'left behind' : 'gone'}`, `overflow ${getComputedStyle(d).overflowY}`, `reading ${document.body.classList.contains('reading')}`, - `shown ${Math.round((Date.now() - shownAt) / 1000)}s ago`, `${S.entries.length} loaded`].join(', ')}); + `shown ${Math.round((Date.now() - shownAt) / 1000)}s ago`, `${S.entries.length} loaded`, + `from x ${Math.round(g.x)}`, `${g.moves} moves seen`, `touch ${g.cancelled ? 'cancelled' : 'left alone'}`, + `slid ${slidAt ? Math.round((Date.now() - slidAt) / 1000) + 's ago' : 'never'}`].join(', ')}); });