diff options
Diffstat (limited to 'src/static/js')
| -rw-r--r-- | src/static/js/client/index.js | 7 | ||||
| -rw-r--r-- | src/static/js/client/sidebar-search.js | 28 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/static/js/client/index.js b/src/static/js/client/index.js index cd617bea..9296dff1 100644 --- a/src/static/js/client/index.js +++ b/src/static/js/client/index.js @@ -60,6 +60,7 @@ const clientInfo = window.hsmusicClientInfo = Object.create(null); // So for example, all modules' getPageReferences steps are evaluated, then // all modules' addInternalListeners steps are evaluated, and so on. const setupSteps = { + bindSessionStorage: [], getPageReferences: [], addInternalListeners: [], mutatePageContent: [], @@ -322,7 +323,11 @@ function evaluateBindSessionStorageStep(bindSessionStorage) { function evaluateStep(stepsObject, key) { for (const step of stepsObject[key]) { try { - step(); + if (key === 'bindSessionStorage') { + evaluateBindSessionStorageStep(step); + } else { + step(); + } } catch (error) { console.error(`During ${key}, failed to run ${step.name}`); console.error(error); diff --git a/src/static/js/client/sidebar-search.js b/src/static/js/client/sidebar-search.js index c39c38bc..386bf477 100644 --- a/src/static/js/client/sidebar-search.js +++ b/src/static/js/client/sidebar-search.js @@ -106,6 +106,8 @@ export const info = { recallingRecentSearch: null, recallingRecentSearchFromMouse: null, + justPerformedActiveQuery: false, + currentValue: null, workerStatus: null, @@ -585,7 +587,6 @@ export function addPageListeners() { clearSidebarSearch(); clearSidebarFilter(); possiblyHideSearchSidebarColumn(); - restoreSidebarSearchColumn(); }); forEachFilter((type, filterLink) => { @@ -614,7 +615,7 @@ export function addPageListeners() { return; } - if (event.shiftKey && event.code === 'Slash') { + if (domEvent.shiftKey && domEvent.code === 'Slash') { domEvent.preventDefault(); info.searchLabel.click(); } @@ -731,6 +732,7 @@ async function activateSidebarSearch(query) { return; } + state.justPerformedActiveQuery = true; state.searchStage = 'complete'; updateSidebarSearchStatus(); @@ -783,7 +785,7 @@ function recordActiveQueryContext() { } function clearSidebarSearch() { - const {session, state} = info; + const {state} = info; if (state.stoppedTypingTimeout) { clearTimeout(state.stoppedTypingTimeout); @@ -796,6 +798,7 @@ function clearSidebarSearch() { info.searchInput.value = ''; state.searchStage = null; + state.justPerformedActiveQuery = false; clearActiveQuery(); @@ -1383,6 +1386,8 @@ function hideSidebarSearchResults() { cssProp(info.endSearchRule, 'display', 'none'); cssProp(info.endSearchLine, 'display', 'none'); + + restoreSidebarSearchColumn(); } function focusFirstSidebarSearchResult() { @@ -1466,7 +1471,7 @@ function possiblyHideSearchSidebarColumn() { // This should be called after results are shown, since it checks the // elements added to understand the current search state. function tidySidebarSearchColumn() { - const {state} = info; + const {session, state} = info; // Don't *re-tidy* the sidebar if we've already tidied it to display // some results. This flag will get cleared if the search is dismissed @@ -1475,17 +1480,24 @@ function tidySidebarSearchColumn() { return; } - const here = location.href.replace(/\/$/, ''); + const hrefHere = location.href.replace(/\/$/, ''); const currentPageIsResult = Array.from(info.results.querySelectorAll('a')) .some(link => { - const there = link.href.replace(/\/$/, ''); - return here === there; + const hrefThere = link.href.replace(/\/$/, ''); + return hrefHere === hrefThere; }); + const currentPageIsContext = + location.pathname === session.activeQueryContextPagePathname; + // Don't tidy the sidebar if you've navigated to some other page than // what's in the current result list. - if (!currentPageIsResult) { + if ( + !state.justPerformedActiveQuery && + !currentPageIsResult && + !currentPageIsContext + ) { return; } |