From d0b710c26dc1795c37d94b70b14b81c39b52f5ea Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Mon, 31 Jul 2023 15:14:25 -0400 Subject: [PATCH] clear search index and other cache with cmd+shift+r --- docs/assets/scripts/search.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/assets/scripts/search.js b/docs/assets/scripts/search.js index efcfa957..049ab30a 100644 --- a/docs/assets/scripts/search.js +++ b/docs/assets/scripts/search.js @@ -58,15 +58,15 @@ const clearButton = siteSearch.querySelector('.search__clear-button'); const results = siteSearch.querySelector('.search__results'); const version = document.documentElement.getAttribute('data-shoelace-version'); - const animationDuration = 150; + const key = `search_${version}`; const searchDebounce = 50; + const animationDuration = 150; let isShowing = false; let searchTimeout; let searchIndex; let map; const loadSearchIndex = new Promise(resolve => { - const key = `search_${version}`; const cache = localStorage.getItem(key); const wait = 'requestIdleCallback' in window ? requestIdleCallback : requestAnimationFrame; @@ -357,6 +357,13 @@ } }); + // Purge cache when we press CMD+CTRL+R + document.addEventListener('keydown', event => { + if ((event.metaKey || event.ctrlKey) && event.shiftKey && event.key === 'r') { + localStorage.clear(); + } + }); + input.addEventListener('input', handleInput); clearButton.addEventListener('click', handleClear);