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
@@ -1,3 +1,5 @@
.vscode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind that this is added, but note that you can use a global gitignore file for things that are personal (i.e. editor/workflow specific things). See e.g. https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer.


*.jl.cov
*.jl.*.cov
*.jl.mem
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* The `target` keyword of `deploydocs` is now required to point to a subdirectory of `root` (usually the directory where `make.jl` is located). (#2019)

* Added keyboard shortcuts for search box (`Ctrl + /` or `Cmd + /` to focus into the search box, `Esc` to focus out of it). (#1536), (#2027)

### Fixed

* 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)
Expand Down Expand Up @@ -1076,4 +1078,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* The at-blocks that execute code can now handle `include` statements. (#793), (#794)

* At-docs blocks no longer give an error when containing empty lines. (#823), (#824)
* At-docs blocks no longer give an error when containing empty lines. (#823), (#824)
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 (Ctrl + /)",
],
)
)
Expand Down