From eab4cd7a66803809ca94a03adc8bbdefc87bd60b Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Tue, 2 May 2023 04:43:06 +0200 Subject: [PATCH] autodoc: type "?" instead of opening help modal if search selected The question mark character can appear in identifiers as part of the `@"syntax"` so we should allow typing it. Now, when the search is selected, "?" is entered instead. It also shouldn't be that common in general for the user to want to open the help modal. --- lib/docs/main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/docs/main.js b/lib/docs/main.js index 504c708b45..bca4d6c84e 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -127,16 +127,20 @@ const NAV_MODES = { window.guideSearch = guidesSearchIndex; parseGuides(); - + // identifiers can contain '?' so we want to allow typing + // the question mark when the search is focused instead of toggling the help modal + let canToggleHelpModal = true; domSearch.disabled = false; domSearch.addEventListener("keydown", onSearchKeyDown, false); domSearch.addEventListener("focus", ev => { domSearchPlaceholder.classList.add("hidden"); + canToggleHelpModal = false; }); domSearch.addEventListener("blur", ev => { if (domSearch.value.length == 0) domSearchPlaceholder.classList.remove("hidden"); + canToggleHelpModal = true; }); domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false); function onClickSearchShowAllResults(ev) { @@ -4044,6 +4048,8 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) { } break; case "?": + if (!canToggleHelpModal) break; + // toggle the help modal if (!domHelpModal.classList.contains("hidden")) { onEscape(ev);