From 32c050228813f1c2c0eab03f53cff63d3d1d2a47 Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Wed, 7 Oct 2026 17:19:19 +0200 Subject: [PATCH 1/2] ndg-templates: add Ctrl+K search shortcut and keycap hint --- crates/ndg-templates/templates/default.css | 18 ++++++++++++++ crates/ndg-templates/templates/default.html | 1 + crates/ndg-templates/templates/lib.html | 1 + crates/ndg-templates/templates/main.js | 26 ++++++++++++++------- crates/ndg-templates/templates/options.html | 1 + crates/ndg-templates/templates/search.html | 3 ++- 6 files changed, 40 insertions(+), 10 deletions(-) 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" /> +
Search

/>
- / to focus search + Ctrl+K or / to focus search ↑ ↓ to navigate Enter to select Esc to leave search From eca68607114c02c15492f75dbb8a3c4296d79cf1 Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Wed, 7 Oct 2026 18:27:25 +0200 Subject: [PATCH 2/2] docs: document Ctrl+K search shortcut --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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`.