From 313d5aef9955a7f546e368d40be8169dcd7fd76f Mon Sep 17 00:00:00 2001 From: Jonathan Sykes Date: Thu, 15 Oct 2026 11:37:40 +0800 Subject: [PATCH] Recent searches open only after a real tap/click/key; close when the app is backgrounded --- frontend/app.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/app.js b/frontend/app.js index 64ca8ef..2f3f7c0 100755 --- a/frontend/app.js +++ b/frontend/app.js @@ -7961,8 +7961,18 @@ function wireUI() { els.searchRecent.classList.remove('hidden'); } function hideRecentSearches() { els.searchRecent.classList.add('hidden'); } - // Only a user's own focus opens the list, never the start-up focus below. - els.searchInput.addEventListener('focus', () => { if (!els.searchInput._bootFocus) showRecentSearches(); }); + // Only a user's own focus opens the list: never the start-up focus below, nor + // a focus iOS restores when the app is reopened. A real tap/click/key must + // have happened just before. + let lastGestureAt = 0; + for (const n of ['pointerdown', 'keydown', 'touchstart']) addEventListener(n, () => { lastGestureAt = Date.now(); }, { capture: true, passive: true }); + els.searchInput.addEventListener('focus', () => { + if (!els.searchInput._bootFocus && Date.now() - lastGestureAt < 1000) showRecentSearches(); + }); + // Leaving the app closes the list, so it is not still open on return. + document.addEventListener('visibilitychange', () => { if (document.visibilityState !== 'visible') hideRecentSearches(); }); + addEventListener('pagehide', hideRecentSearches); + addEventListener('pageshow', () => { if (Date.now() - lastGestureAt > 1000) hideRecentSearches(); }); // Already focused (start-up) — a click or tap on the box still opens it. els.searchInput.addEventListener('pointerdown', () => { if (document.activeElement === els.searchInput) showRecentSearches(); }); els.searchInput.addEventListener('input', () => {