Recent searches open only after a real tap/click/key; close when the app is backgrounded

This commit is contained in:
Jonathan Sykes
2026-10-15 11:37:40 +08:00
parent d45fa49a46
commit 313d5aef99

View File

@@ -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', () => {