diff --git a/crates/mdbook-html/front-end/searcher/searcher.js b/crates/mdbook-html/front-end/searcher/searcher.js index c715201205..a2e0488001 100644 --- a/crates/mdbook-html/front-end/searcher/searcher.js +++ b/crates/mdbook-html/front-end/searcher/searcher.js @@ -351,6 +351,16 @@ window.search = window.search || {}; // Eventhandler for keyevents on `document` function globalKeyHandler(e) { + const metaIsCtrl = navigator.platform && + (navigator.platform.startsWith('Mac') || navigator.platform === 'iPhone'); + if ((metaIsCtrl ? e.metaKey : e.ctrlKey) && e.key === 'k') { + e.preventDefault(); + showSearch(true); + window.scrollTo(0, 0); + searchbar.select(); + return; + } + if (e.altKey || e.ctrlKey || e.metaKey || diff --git a/crates/mdbook-html/front-end/templates/index.hbs b/crates/mdbook-html/front-end/templates/index.hbs index b1834189f9..06272d83e5 100644 --- a/crates/mdbook-html/front-end/templates/index.hbs +++ b/crates/mdbook-html/front-end/templates/index.hbs @@ -69,7 +69,12 @@

Press or to navigate between chapters

{{#if search_enabled}} -

Press S or / to search in the book

+

Press S, /, or Ctrl+K to search in the book

+ {{/if}}

Press ? to show this help

Press Esc to hide this help

diff --git a/guide/src/guide/reading.md b/guide/src/guide/reading.md index 64624bd300..5b8f8c29bb 100644 --- a/guide/src/guide/reading.md +++ b/guide/src/guide/reading.md @@ -42,7 +42,7 @@ Tapping the menu bar will scroll the page to the top. ## Search Each book has a built-in search system. -Pressing the search icon in the menu bar, or pressing the / or S key on the keyboard will open an input box for entering search terms. +Pressing the search icon in the menu bar, Ctrl+K (+K on macOS), or pressing the / or S key on the keyboard will open an input box for entering search terms. Typing some terms will show matching chapters and sections in real time. Clicking any of the results will jump to that section.