Skip to content

Commit

Permalink
Rollup merge of rust-lang#49152 - GuillaumeGomez:rustdoc-event-handli…
Browse files Browse the repository at this point in the history
…ng, r=QuietMisdreavus

Fix events handling in rustdoc

Fixes rust-lang#49075.
  • Loading branch information
kennytm committed Mar 20, 2018
2 parents 1f5d31f + 5581aa8 commit 45de057
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
displayHelp(false, ev);
} else if (!hasClass(search, "hidden")) {
ev.preventDefault();
addClass(search, "hidden");
removeClass(document.getElementById("main"), "hidden");
if (document.activeElement.tagName === "INPUT") {
switch (getVirtualKey(ev)) {
case "Escape":
handleEscape(ev, help);
break;
}
defocusSearchBar();
break;
} else {
switch (getVirtualKey(ev)) {
case "Escape":
handleEscape(ev, help);
break;

case "s":
case "S":
displayHelp(false, ev);
hideModal();
ev.preventDefault();
focusSearchBar();
break;
case "s":
case "S":
displayHelp(false, ev);
hideModal();
ev.preventDefault();
focusSearchBar();
break;

case "+":
case "-":
ev.preventDefault();
toggleAllDocs();
break;
case "+":
case "-":
ev.preventDefault();
toggleAllDocs();
break;

case "?":
if (ev.shiftKey) {
hideModal();
displayHelp(true, ev);
case "?":
if (ev.shiftKey) {
hideModal();
displayHelp(true, ev);
}
break;
}
break;
}
}

Expand Down

0 comments on commit 45de057

Please sign in to comment.