commit eab4cd7a66803809ca94a03adc8bbdefc87bd60b (tree)
parent 6f1336a50c6c2d9498bb9b3fb291cb305688c1b9
Author: r00ster91 <r00ster91@proton.me>
Date: Tue, 2 May 2023 04:43:06 +0200
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.
Diffstat:
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git 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);