diff --git a/CHANGELOG.md b/CHANGELOG.md
index f86485c1d..81cb27f1f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,10 @@ changes.
### Added
+- `Ctrl+K` now focuses search alongside the existing `/` shortcut, prioritizing
+ the options filter when present. The header search field shows a `Ctrl+K`
+ keycap, and the search page lists both shortcuts in its keyboard hints.
+
- Document sidebars now support explicit sub-chapters through `parent` in
`[[sidebar.matches]]`. Parents remain clickable, integer positions order
siblings, and numbering follows the hierarchy, such as `4.1` and `4.1.1`.
diff --git a/crates/ndg-templates/templates/default.css b/crates/ndg-templates/templates/default.css
index 98c1b9374..20ff8aa99 100644
--- a/crates/ndg-templates/templates/default.css
+++ b/crates/ndg-templates/templates/default.css
@@ -853,6 +853,7 @@ img {
#search-input {
padding: var(--space-2) var(--space-3);
padding-left: 2.5rem;
+ padding-right: 5rem;
border: 1px solid var(--border-color);
border-radius: var(--radius-lg);
width: 240px;
@@ -871,6 +872,18 @@ img {
cursor: text;
}
+.search-shortcut {
+ position: absolute;
+ top: 50%;
+ right: var(--space-3);
+ transform: translateY(-50%);
+ pointer-events: none;
+}
+
+.search-container:focus-within .search-shortcut {
+ visibility: hidden;
+}
+
#search-input::placeholder {
color: var(--text-muted);
}
@@ -1137,6 +1150,7 @@ img {
gap: var(--space-1);
}
+.search-shortcut,
.search-keyboard-hints kbd {
display: inline-block;
padding: 0.125rem 0.375rem;
@@ -1767,6 +1781,10 @@ h6:hover .copy-link {
margin-top: var(--space-2);
}
+ .search-shortcut {
+ display: none;
+ }
+
/* Mobile search styles */
.search-container {
position: relative;
diff --git a/crates/ndg-templates/templates/default.html b/crates/ndg-templates/templates/default.html
index c1768114c..21f03c972 100644
--- a/crates/ndg-templates/templates/default.html
+++ b/crates/ndg-templates/templates/default.html
@@ -50,6 +50,7 @@
{% if generate_search %}
{% endif %}
diff --git a/crates/ndg-templates/templates/lib.html b/crates/ndg-templates/templates/lib.html
index 4f1599583..5f0cdadae 100644
--- a/crates/ndg-templates/templates/lib.html
+++ b/crates/ndg-templates/templates/lib.html
@@ -54,6 +54,7 @@
{{ navbar_html|safe }} {% if generate_search %}
{% endif %}
diff --git a/crates/ndg-templates/templates/main.js b/crates/ndg-templates/templates/main.js
index 43c05ae85..bb26ec836 100644
--- a/crates/ndg-templates/templates/main.js
+++ b/crates/ndg-templates/templates/main.js
@@ -364,17 +364,25 @@ function isEditableTarget(target) {
);
}
+function isSearchShortcut(event) {
+ if (
+ event.defaultPrevented ||
+ event.isComposing ||
+ event.metaKey ||
+ event.altKey
+ )
+ return false;
+
+ if (event.ctrlKey) {
+ return event.key.toLowerCase() === "k" && !event.shiftKey;
+ }
+
+ return event.key === "/" && !isEditableTarget(event.target);
+}
+
function setupGlobalShortcuts() {
document.addEventListener("keydown", (event) => {
- if (
- event.key !== "/" ||
- event.ctrlKey ||
- event.metaKey ||
- event.altKey ||
- isEditableTarget(event.target)
- ) {
- return;
- }
+ if (!isSearchShortcut(event)) return;
const input =
document.getElementById("options-filter") ??
diff --git a/crates/ndg-templates/templates/options.html b/crates/ndg-templates/templates/options.html
index 434ce79ae..129501543 100644
--- a/crates/ndg-templates/templates/options.html
+++ b/crates/ndg-templates/templates/options.html
@@ -48,6 +48,7 @@
{{ navbar_html|safe }} {% if generate_search %}
{% endif %}
diff --git a/crates/ndg-templates/templates/search.html b/crates/ndg-templates/templates/search.html
index bf73697c7..e30f50a1f 100644
--- a/crates/ndg-templates/templates/search.html
+++ b/crates/ndg-templates/templates/search.html
@@ -52,6 +52,7 @@
aria-label="Search"
autocomplete="off"
/>
+ Ctrl+K
Search
/>
- / to focus search
+ Ctrl+K or / to focus search
↑ ↓ to navigate
Enter to select
Esc to leave search