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.
This commit is contained in:
r00ster91 2023-05-02 04:43:06 +02:00
parent 6f1336a50c
commit eab4cd7a66

View File

@ -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);