rust-lang / rust-lang/mdBook

Search shortcut "/" is unreachable on Firefix and on keyboard layouts where "/" requires Shift (AZERTY, QWERTZ, etc.)

Open Beginner friendly
#3,199 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement
Dominant language
Rust
Stars
22.2k
Forks
1.9k
PR merge metrics
PR metrics pending

Description

Problem

Same bug, two different manifestations:

Can't trigger '/' on AZERTY

The / search shortcut can't be triggered on any keyboard layout where / is a shifted character. On French AZERTY, for example, / is Shift + the : key. The moment you press it, e.shiftKey is true, and the global key handler in searcher.js returns on its guard clause before it ever checks for /:

function globalKeyHandler(e) {
    if (e.altKey ||
        e.ctrlKey ||
        e.metaKey ||
        e.shiftKey ||            // returns here on AZERTY '/'
        ...
    ) {
        return;
    }
    ...
    } else if (!hasFocus() && (e.key === 's' || e.key === '/')) {  // never reached

So the search box never opens.

This hits AZERTY, QWERTZ, and any other layout where / sits behind Shift, which is a large share of non-US users.

'/' Conflicts with default Firefox shortcuts

Because the handler returns without calling preventDefault(), the keystroke falls through to the browser. In Chrome nothing happens (Chrome has no page-level / binding).

In Firefox, / is bound to Quick Find, so Firefox's own find bar opens instead of the doc search. Same root cause, two different symptoms.

Reproduction

  1. Set your OS keyboard layout to French (AZERTY), or any layout where / needs Shift.
  2. Open any mdBook site and press /.
  3. Chrome: nothing opens. Firefox: the browser's Quick Find bar opens.

s still works on these layouts, since it's an unshifted key, which confirms the shift-guard is the cause.

Proposed Solution

Suggested fix

Let the / case run even when Shift is held, since on many layouts Shift is exactly how you type /. One approach is to check the search keys before the modifier bailout, and preventDefault() on match so Firefox stops stealing the keystroke:

if (!hasFocus() && !e.ctrlKey && !e.altKey && !e.metaKey &&
    (e.key === 's' || e.key === '/')) {
    e.preventDefault();
    showSearch(true);
    window.scrollTo(0, 0);
    searchbar.select();
    return;
}

(Keying off e.key rather than a keyCode already handles the layout mapping; the only real blocker is the blanket shiftKey return.)

Notes

Alongside the fix above, it'd be worth adding Ctrl/Cmd+K as a second binding.

It's what users now expect from Docusaurus, VitePress, and most modern doc sites, and K isn't shifted on common layouts, so it sidesteps this whole class of problem.

(will open a suggestion about this ! )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in searcher.js at globalKeyHandler and inspect the modifier guard and search-key handling described in the issue. Verify the search box opens for / on shifted layouts, Firefox does not open Quick Find, and the existing s shortcut still works; test with AZERTY or another layout where / requires Shift.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.