Repository: rust-lang/mdBook (language: rust)

Issue:
Typing s opens search 
When you type s, it opens search. Is there a way to disable this?


Discussion / hints:
I want to have a form in the about page of my website, and this makes `s` challenging to enter... currently only workaround I've found is to disable search entirely, which seems a bit extreme.

I propose to enable user to override the keycode activating search (including disabling keyboard activation) by:
- Add a field of "search keycode" to [output.html.search]
- Write it out to the html with a node id (somewhere in hbs_rendererer.rs?)
- getElementById for that node in searcher.js, use it to initialize the SEARCH_HOTKEY_KEYCODE (or not).

I've never written js in my life, but this doesn't look too challenging (actually, a [sketch](https://github.com/rust-lang/mdBook/pull/1558/files) of the js part). PR welcome? if so, happy to hear any improvements to the plan above.
I would prefer to avoid adding configuration here if possible.  Is there a reason that the [check](https://github.com/rust-lang/mdBook/blob/8201b411aba2f4957f19c4e146ceb54d3682ce39/src/theme/searcher/searcher.js#L319) to avoid conflict isn't working for your form?

Ah, I hadn't understood that mechanism. It is because the fields's type is not one of the excluded types, it is "email". I can make the trivial PR to also include email, though this does seem a bit of a whack-a-mole (I might find myself using a different new field type tomorrow). Perhaps it would be better to instead enumerate the types that mdbook uses in normal operation, and apply the s behavior only to them?
@ehuss ^ ? the trivial PR does work for me, for now I am using a fork that excludes the "email" field.


Edit: now known as https://github.com/rust-lang/mdBook/pull/1569 
> Perhaps it would be better to instead enumerate the types that mdbook uses in normal operation, and apply the s behavior only to them?

If you know of a way to do that, feel free to open a PR!  I'm not sure if it is possible to check for an "allowed" list, though.
@briantliao any reason this was closed? The PR https://github.com/rust-lang/mdBook/pull/1569 was unfortunately not merged yet. I added a comment there; the comment from @ehuss worked perfectly fine. 

I would love to get this merged so others do not have the same problem when adding a simple sign-up form from a newsletter or similar.
It was old… yes would like to have it merged please.

Fix patch:
diff --git a/src/theme/searcher/searcher.js b/src/theme/searcher/searcher.js
index d2b0aeed38..dc03e0a02d 100644
--- a/src/theme/searcher/searcher.js
+++ b/src/theme/searcher/searcher.js
@@ -316,7 +316,7 @@ window.search = window.search || {};
     
     // Eventhandler for keyevents on `document`
     function globalKeyHandler(e) {
-        if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.target.type === 'textarea' || e.target.type === 'text') { return; }
+        if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.target.type === 'textarea' || e.target.type === 'text' || !hasFocus() && /^(?:input|select|textarea)$/i.test(e.target.nodeName)) { return; }
 
         if (e.keyCode === ESCAPE_KEYCODE) {
             e.preventDefault();


Test patch: