authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-05-11 17:44:55+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-05-11 17:44:55+02:00
log8ece99083f1c9af33c3240f31ab849a617547817
tree0f19790a1c352b55c281c55541c92fbc8451a8db
parent3bb3d39fb4158ba4b811bcae7e7a897febf07e17
parenteab4cd7a66803809ca94a03adc8bbdefc87bd60b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #15545 from r00ster91/autodocthing

autodoc: make help modal toggleable and allow entering "?" in search

2 files changed, 17 insertions(+), 6 deletions(-)

lib/docs/index.html+1-1
......@@ -875,7 +875,7 @@
875875 <div class="help-modal">
876876 <div class="modal">
877877 <h1>Keyboard Shortcuts</h1>
878 <dl><dt><kbd>?</kbd></dt><dd>Show this help modal</dd></dl>
878 <dl><dt><kbd>?</kbd></dt><dd>Toggle this help modal</dd></dl>
879879 <dl><dt><kbd>s</kbd></dt><dd>Focus the search field</dd></dl>
880880 <div style="margin-left: 1em">
881881 <dl><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd></dl>
lib/docs/main.js+16-5
......@@ -127,16 +127,20 @@ const NAV_MODES = {
127127 window.guideSearch = guidesSearchIndex;
128128 parseGuides();
129129
130
130 // identifiers can contain '?' so we want to allow typing
131 // the question mark when the search is focused instead of toggling the help modal
132 let canToggleHelpModal = true;
131133
132134 domSearch.disabled = false;
133135 domSearch.addEventListener("keydown", onSearchKeyDown, false);
134136 domSearch.addEventListener("focus", ev => {
135137 domSearchPlaceholder.classList.add("hidden");
138 canToggleHelpModal = false;
136139 });
137140 domSearch.addEventListener("blur", ev => {
138141 if (domSearch.value.length == 0)
139142 domSearchPlaceholder.classList.remove("hidden");
143 canToggleHelpModal = true;
140144 });
141145 domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
142146 function onClickSearchShowAllResults(ev) {
......@@ -4045,9 +4049,16 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
40454049 }
40464050 break;
40474051 case "?":
4048 ev.preventDefault();
4049 ev.stopPropagation();
4050 showHelpModal();
4052 if (!canToggleHelpModal) break;
4053
4054 // toggle the help modal
4055 if (!domHelpModal.classList.contains("hidden")) {
4056 onEscape(ev);
4057 } else {
4058 ev.preventDefault();
4059 ev.stopPropagation();
4060 showHelpModal();
4061 }
40514062 break;
40524063 }
40534064 }
......@@ -4852,4 +4863,4 @@ function RadixTree() {
48524863
48534864// BUT!
48544865
4855// We want to be able to search "Hash", for example!
\ No newline at end of file
4866// We want to be able to search "Hash", for example!