Skip to content

Commit

Permalink
Add keyboard shortcut for search box, close #1536 (#2027)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hetarth02 authored Feb 12, 2023
1 parent a6c97e9 commit 735eee7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode

*.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

0 comments on commit 735eee7

Please sign in to comment.