From 44d9f4e95bf9590d1f933f769c75798486372ad7 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sun, 11 May 2025 08:59:58 +0000 Subject: [PATCH] Use `/` (or `s`) to open search box We allow for using `s` to open the search box, but it's more common to use `/` (forward slash) for this. E.g., MDN's documentation uses `/` for search. Rustdoc and GitHub accept either. Let's allow either key to be used, and let's switch to "advertising" `/` rather than `s` in the hover text for the search button. In making that switch, let's also simplify that hover text a bit. Previously it had said "Search. (Shortkey: s)". This was the only top button on which we had included a period in the hover text. Let's remove that, and let's remove the "shortkey" bit of jargon. It's enough to just put `/` in a parenthetical, i.e. "Search (`/`)". People will gleam from that what we mean. We've also updated the guide accordingly. --- guide/src/guide/reading.md | 2 +- src/front-end/searcher/searcher.js | 4 ++-- src/front-end/templates/index.hbs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/guide/src/guide/reading.md b/guide/src/guide/reading.md index cab3a865..704f4bcc 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 `S` key on the keyboard will open an input box for entering search terms. +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. Typing some terms will show matching chapters and sections in real time. Clicking any of the results will jump to that section. diff --git a/src/front-end/searcher/searcher.js b/src/front-end/searcher/searcher.js index 2ecba880..a29883c0 100644 --- a/src/front-end/searcher/searcher.js +++ b/src/front-end/searcher/searcher.js @@ -35,7 +35,7 @@ window.search = window.search || {}; URL_SEARCH_PARAM = 'search', URL_MARK_PARAM = 'highlight', - SEARCH_HOTKEY_KEYCODE = 83, + SEARCH_HOTKEY_KEYCODES = [83, 191], // `s` or `/`. ESCAPE_KEYCODE = 27, DOWN_KEYCODE = 40, UP_KEYCODE = 38, @@ -362,7 +362,7 @@ window.search = window.search || {}; } showSearch(false); marker.unmark(); - } else if (!hasFocus() && e.keyCode === SEARCH_HOTKEY_KEYCODE) { + } else if (!hasFocus() && SEARCH_HOTKEY_KEYCODES.includes(e.keyCode)) { e.preventDefault(); showSearch(true); window.scrollTo(0, 0); diff --git a/src/front-end/templates/index.hbs b/src/front-end/templates/index.hbs index 98f3b886..ca3c73fb 100644 --- a/src/front-end/templates/index.hbs +++ b/src/front-end/templates/index.hbs @@ -142,7 +142,7 @@
  • {{#if search_enabled}} - {{/if}}