Merge branch 'dtw-waleee-fix-help-modal'

closes #3455
This commit is contained in:
Andrew Kelley 2019-10-15 18:38:12 -04:00
commit c7f994890c
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -1141,10 +1141,8 @@
} }
function onSearchKeyDown(ev) { function onSearchKeyDown(ev) {
switch (ev.which) { switch (getKeyString(ev)) {
case 13: case "Enter":
if (ev.shiftKey || ev.ctrlKey || ev.altKey) return;
// detect if this search changes anything // detect if this search changes anything
var terms1 = getSearchTerms(); var terms1 = getSearchTerms();
startSearch(); startSearch();
@ -1157,9 +1155,7 @@
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
return; return;
case 27: case "Esc":
if (ev.shiftKey || ev.ctrlKey || ev.altKey) return;
domSearch.value = ""; domSearch.value = "";
domSearch.blur(); domSearch.blur();
curSearchIndex = -1; curSearchIndex = -1;
@ -1167,16 +1163,12 @@
ev.stopPropagation(); ev.stopPropagation();
startSearch(); startSearch();
return; return;
case 38: case "Up":
if (ev.shiftKey || ev.ctrlKey || ev.altKey) return;
moveSearchCursor(-1); moveSearchCursor(-1);
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
return; return;
case 40: case "Down":
if (ev.shiftKey || ev.ctrlKey || ev.altKey) return;
moveSearchCursor(1); moveSearchCursor(1);
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
@ -1210,26 +1202,49 @@
renderSearchCursor(); renderSearchCursor();
} }
function onWindowKeyDown(ev) { function getKeyString(ev) {
var name;
var ignoreShift = false;
switch (ev.which) { switch (ev.which) {
case 13:
name = "Enter";
break;
case 27: case 27:
if (ev.shiftKey || ev.ctrlKey || ev.altKey) return; name = "Esc";
break;
case 38:
name = "Up";
break;
case 40:
name = "Down";
break;
default:
ignoreShift = true;
name = (ev.key != null) ? ev.key : String.fromCharCode(ev.charCode || ev.keyCode);
}
if (!ignoreShift && ev.shiftKey) name = "Shift+" + name;
if (ev.altKey) name = "Alt+" + name;
if (ev.ctrlKey) name = "Ctrl+" + name;
return name;
}
function onWindowKeyDown(ev) {
switch (getKeyString(ev)) {
case "Esc":
if (!domHelpModal.classList.contains("hidden")) { if (!domHelpModal.classList.contains("hidden")) {
domHelpModal.classList.add("hidden"); domHelpModal.classList.add("hidden");
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
} }
break; break;
case 83: case "s":
if (ev.shiftKey || ev.ctrlKey || ev.altKey) return;
domSearch.focus(); domSearch.focus();
domSearch.select(); domSearch.select();
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
startAsyncSearch(); startAsyncSearch();
break; break;
case 191: case "?":
if (!ev.shiftKey || ev.ctrlKey || ev.altKey) return;
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
showHelpModal(); showHelpModal();