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 @@...@@ -875,7 +875,7 @@
875 <div class="help-modal">875 <div class="help-modal">
876 <div class="modal">876 <div class="modal">
877 <h1>Keyboard Shortcuts</h1>877 <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>
879 <dl><dt><kbd>s</kbd></dt><dd>Focus the search field</dd></dl>879 <dl><dt><kbd>s</kbd></dt><dd>Focus the search field</dd></dl>
880 <div style="margin-left: 1em">880 <div style="margin-left: 1em">
881 <dl><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd></dl>881 <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 = {...@@ -127,16 +127,20 @@ const NAV_MODES = {
127 window.guideSearch = guidesSearchIndex;127 window.guideSearch = guidesSearchIndex;
128 parseGuides();128 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
132 domSearch.disabled = false;134 domSearch.disabled = false;
133 domSearch.addEventListener("keydown", onSearchKeyDown, false);135 domSearch.addEventListener("keydown", onSearchKeyDown, false);
134 domSearch.addEventListener("focus", ev => {136 domSearch.addEventListener("focus", ev => {
135 domSearchPlaceholder.classList.add("hidden");137 domSearchPlaceholder.classList.add("hidden");
138 canToggleHelpModal = false;
136 });139 });
137 domSearch.addEventListener("blur", ev => {140 domSearch.addEventListener("blur", ev => {
138 if (domSearch.value.length == 0)141 if (domSearch.value.length == 0)
139 domSearchPlaceholder.classList.remove("hidden");142 domSearchPlaceholder.classList.remove("hidden");
143 canToggleHelpModal = true;
140 });144 });
141 domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);145 domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
142 function onClickSearchShowAllResults(ev) {146 function onClickSearchShowAllResults(ev) {
...@@ -4045,9 +4049,16 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {...@@ -4045,9 +4049,16 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
4045 }4049 }
4046 break;4050 break;
4047 case "?":4051 case "?":
4048 ev.preventDefault();4052 if (!canToggleHelpModal) break;
4049 ev.stopPropagation();4053
4050 showHelpModal();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 }
4051 break;4062 break;
4052 }4063 }
4053 }4064 }
...@@ -4852,4 +4863,4 @@ function RadixTree() {...@@ -4852,4 +4863,4 @@ function RadixTree() {
48524863
4853// BUT!4864// 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!