From 5581aa8eebba270cde4e95d2e2b7f08163ae7319 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 18 Mar 2018 16:32:41 +0100 Subject: [PATCH] Fix events handling in rustdoc --- src/librustdoc/html/static/main.js | 77 ++++++++++++++++-------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 28d39cb174a..21c1d9d670d 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -239,52 +239,59 @@ } } - function handleShortcut(ev) { - if (document.activeElement.tagName === "INPUT" && - hasClass(document.getElementById('main'), "hidden")) { - return; + function handleEscape(ev, help) { + hideModal(); + var search = document.getElementById("search"); + if (!hasClass(help, "hidden")) { + displayHelp(false, ev); + } else if (!hasClass(search, "hidden")) { + ev.preventDefault(); + addClass(search, "hidden"); + removeClass(document.getElementById("main"), "hidden"); } + defocusSearchBar(); + } + function handleShortcut(ev) { // Don't interfere with browser shortcuts if (ev.ctrlKey || ev.altKey || ev.metaKey) { return; } var help = document.getElementById("help"); - switch (getVirtualKey(ev)) { - case "Escape": - hideModal(); - var search = document.getElementById("search"); - if (!hasClass(help, "hidden")) { + if (document.activeElement.tagName === "INPUT") { + switch (getVirtualKey(ev)) { + case "Escape": + handleEscape(ev, help); + break; + } + } else { + switch (getVirtualKey(ev)) { + case "Escape": + handleEscape(ev, help); + break; + + case "s": + case "S": displayHelp(false, ev); - } else if (!hasClass(search, "hidden")) { - ev.preventDefault(); - addClass(search, "hidden"); - removeClass(document.getElementById("main"), "hidden"); - } - defocusSearchBar(); - break; - - case "s": - case "S": - displayHelp(false, ev); - hideModal(); - ev.preventDefault(); - focusSearchBar(); - break; - - case "+": - case "-": - ev.preventDefault(); - toggleAllDocs(); - break; - - case "?": - if (ev.shiftKey) { hideModal(); - displayHelp(true, ev); + ev.preventDefault(); + focusSearchBar(); + break; + + case "+": + case "-": + ev.preventDefault(); + toggleAllDocs(); + break; + + case "?": + if (ev.shiftKey) { + hideModal(); + displayHelp(true, ev); + } + break; } - break; } }