Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keyboard shortcut for search box #2027

Merged
merged 11 commits into from
Feb 12, 2023
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ docs/dev/
docs/build/
docs/build-pdf/
docs/site/

.vscode
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* ![Enhancement][badge-enhancement] Search engine and social media link previews are now supported, with Documenter generating the relevant HTML `meta` tags. ([#1321][github-1321], [#1991][github-1991])
* ![Enhancement][badge-enhancement] `deploydocs` now supports custom tag prefixes; see section "Deploying from a monorepo" in the docs. ([#1291][github-1291], [#1792][github-1792], [#1993][github-1993])
* ![Enhancement][badge-enhancement] The `target` keyword of `deploydocs` is now required to point to a subdirectory of `root` (usually the directory where `make.jl` is located). ([#2019][github-2019])
* ![Enhancement][badge-enhancement] Added keyboard shortcuts for search box (To focus into search box use `ctrl + /` or `cmd + /`, `Esc` to focus out of it). ([#2027][github-2027])
mortenpi marked this conversation as resolved.
Show resolved Hide resolved
* ![Bugfix][badge-bugfix] Documenter now generates the correct source URLs for docstrings from other packages when the `repo` argument to `makedocs` is set (note: the source links to such docstrings only work if the external package is cloned from GitHub and added as a dev-dependency). However, this change **breaks** the case where the `repo` argument is used to override the main package/repository URL, assuming the repository is cloned from GitHub. ([#1808][github-1808])
* ![Bugfix][badge-bugfix] Documenter no longer uses the `TRAVIS_REPO_SLUG` environment variable to determine the Git remote of non-main repositories (when inferring it from the Git repository configuration has failed), which could previously lead to bad source links. ([#1881][github-1881])
* ![Bugfix][badge-bugfix] Line endings in Markdown source files are now normalized to `LF` before parsing, to work around [a bug in the Julia Markdown parser][julia-29344] where parsing is sensitive to line endings, and can therefore cause platform-dependent behavior. ([#1906][github-1906])
Expand Down Expand Up @@ -1192,6 +1193,7 @@
[github-2012]: https://github.com/JuliaDocs/Documenter.jl/pull/2012
[github-2018]: https://github.com/JuliaDocs/Documenter.jl/pull/2018
[github-2019]: https://github.com/JuliaDocs/Documenter.jl/pull/2019
[github-2027]: https://github.com/JuliaDocs/Documenter.jl/pull/2027
<!-- end of issue link definitions -->

[julia-29344]: https://github.com/JuliaLang/julia/issues/29344
Expand Down
18 changes: 18 additions & 0 deletions assets/html/js/shortcut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let searchbox = document.querySelector("#documenter-search-query");
let sidebar = document.querySelector(".docs-sidebar");

document.addEventListener("keydown", (event) => {
if ((event.ctrlKey || event.metaKey) && event.key === "/") {
if (!sidebar.classList.contains("visible")) {
sidebar.classList.add("visible");
}
searchbox.focus();
return false;
} else if (event.key === "Escape") {
if (sidebar.classList.contains("visible")) {
sidebar.classList.remove("visible");
}
searchbox.blur();
return false;
}
});
2 changes: 1 addition & 1 deletion src/html/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ function render_sidebar(ctx, navnode)
"#documenter-search-query.docs-search-query",
:name => "q",
:type => "text",
:placeholder => "Search docs",
:placeholder => "Search Docs (Press 'ctrl + /')",
mortenpi marked this conversation as resolved.
Show resolved Hide resolved
],
)
)
Expand Down