@@ -654,7 +654,13 @@
No Results Found
-
Press escape to exit search and then '?' to see more options.
+
Here are some things you can try:
+
+ - Check out the Language Reference for the language itself.
+ - Check out the Learn page for other helpful resources for learning Zig.
+ - Use your search engine.
+
+
Press ? to see keyboard shortcuts and Esc to return.
Fields
@@ -716,11 +722,13 @@
Keyboard Shortcuts
- ?
- Show this help modal
-
- Esc
- Clear focus; close this modal
- s
- Focus the search field
-
- ↑
- Move up in search results
-
- ↓
- Move down in search results
-
- ⏎
- Go to active search result
+
+
- ↑
- Move up in search results
+
- ↓
- Move down in search results
+
- ⏎
- Go to active search result
+
+
- Esc
- Clear focus; close this modal
diff --git a/lib/docs/main.js b/lib/docs/main.js
index f171326b2e..e2b5162beb 100644
--- a/lib/docs/main.js
+++ b/lib/docs/main.js
@@ -41,7 +41,7 @@ var zigAnalysis;
const domSearch = document.getElementById("search");
const domSectSearchResults = document.getElementById("sectSearchResults");
const domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
-
+ const domDocs = document.getElementById("docs");
const domListSearchResults = document.getElementById("listSearchResults");
const domSectSearchNoResults = document.getElementById("sectSearchNoResults");
const domSectInfo = document.getElementById("sectInfo");
@@ -51,6 +51,7 @@ var zigAnalysis;
const domHdrName = document.getElementById("hdrName");
const domHelpModal = document.getElementById("helpModal");
const domSearchPlaceholder = document.getElementById("searchPlaceholder");
+ const domLangRefLink = document.getElementById("langRefLink");
let searchTimer = null;
let searchTrimResults = true;
@@ -116,10 +117,10 @@ var zigAnalysis;
});
domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
function onClickSearchShowAllResults(ev) {
- ev.preventDefault();
- ev.stopPropagation();
- searchTrimResults = false;
- onHashChange();
+ ev.preventDefault();
+ ev.stopPropagation();
+ searchTrimResults = false;
+ onHashChange();
}
domPrivDeclsBox.addEventListener(
@@ -161,6 +162,13 @@ var zigAnalysis;
window.addEventListener("keydown", onWindowKeyDown, false);
onHashChange();
+ let langRefVersion = zigAnalysis.params.zigVersion;
+ if (!/^\d+\.\d+\.\d+$/.test(langRefVersion)) {
+ // the version is probably not released yet
+ langRefVersion = "master";
+ }
+ domLangRefLink.href = `https://ziglang.org/documentation/${langRefVersion}/`;
+
function renderTitle() {
let list = curNav.pkgNames.concat(curNav.declNames);
let suffix = " - Zig";
@@ -3140,6 +3148,23 @@ var zigAnalysis;
domSearch.blur();
}
+ // hide the modal if it's visible or return to the previous result page and unfocus the search
+ function onEscape(ev) {
+ if (!domHelpModal.classList.contains("hidden")) {
+ domHelpModal.classList.add("hidden");
+ ev.preventDefault();
+ ev.stopPropagation();
+ } else {
+ domSearch.value = "";
+ domSearch.blur();
+ domSearchPlaceholder.classList.remove("hidden");
+ curSearchIndex = -1;
+ ev.preventDefault();
+ ev.stopPropagation();
+ startSearch();
+ }
+ }
+
function onSearchKeyDown(ev) {
switch (getKeyString(ev)) {
case "Enter":
@@ -3156,19 +3181,15 @@ var zigAnalysis;
ev.stopPropagation();
return;
case "Esc":
- domSearch.value = "";
- domSearch.blur();
- curSearchIndex = -1;
- ev.preventDefault();
- ev.stopPropagation();
- startSearch();
- return;
+ onEscape(ev);
+ return
case "Up":
moveSearchCursor(-1);
ev.preventDefault();
ev.stopPropagation();
return;
case "Down":
+ // TODO: make the page scroll down if the search cursor is out of the screen
moveSearchCursor(1);
ev.preventDefault();
ev.stopPropagation();
@@ -3237,18 +3258,17 @@ var zigAnalysis;
function onWindowKeyDown(ev) {
switch (getKeyString(ev)) {
case "Esc":
- if (!domHelpModal.classList.contains("hidden")) {
- domHelpModal.classList.add("hidden");
- ev.preventDefault();
- ev.stopPropagation();
- }
+ onEscape(ev);
break;
case "s":
- domSearch.focus();
- domSearch.select();
- ev.preventDefault();
- ev.stopPropagation();
- startAsyncSearch();
+ if (domHelpModal.classList.contains("hidden")) {
+ domSearch.focus();
+ domSearch.select();
+ domDocs.scrollTo(0, 0);
+ ev.preventDefault();
+ ev.stopPropagation();
+ startAsyncSearch();
+ }
break;
case "?":
ev.preventDefault();
@@ -3265,6 +3285,7 @@ var zigAnalysis;
domHelpModal.style.top =
window.innerHeight / 2 - domHelpModal.clientHeight / 2 + "px";
domHelpModal.focus();
+ domSearch.blur();
}
function clearAsyncSearch() {
@@ -3290,7 +3311,7 @@ var zigAnalysis;
list.sort();
return list;
}
-
+
function renderSearch() {
let matchedItems = [];
let ignoreCase = curNavSearch.toLowerCase() === curNavSearch;
@@ -3379,13 +3400,13 @@ var zigAnalysis;
const text = lastPkgName + "." + match.path.declNames.join(".");
const href = navLink(match.path.pkgNames, match.path.declNames);
- matchedItemsHTML += "
"+ text + "";
+ matchedItemsHTML += "
" + text + "";
}
// Replace the search results using our newly constructed HTML string
domListSearchResults.innerHTML = matchedItemsHTML;
if (searchTrimmed) {
- domSectSearchAllResultsLink.classList.remove("hidden");
+ domSectSearchAllResultsLink.classList.remove("hidden");
}
renderSearchCursor();