@@ -103,31 +103,31 @@ document.onkeydown = function (e) {
103
103
}
104
104
} else if ( current_elem ) ae = current_elem ;
105
105
106
- if ( key === "ArrowDown" && resultsAvailable && inbox ) {
106
+ if ( key === "Escape" ) {
107
+ reset ( )
108
+ } else if ( ! resultsAvailable || ! inbox ) {
109
+ return
110
+ } else if ( key === "ArrowDown" ) {
107
111
e . preventDefault ( ) ;
108
112
if ( ae == sInput ) {
109
113
// if the currently focused element is the search input, focus the <a> of first <li>
110
114
activeToggle ( resList . firstChild . lastChild ) ;
111
- } else if ( ae . parentElement = = last ) {
115
+ } else if ( ae . parentElement ! = last ) {
112
116
// if the currently focused element's parent is last, do nothing
113
- } else {
114
117
// otherwise select the next search result
115
118
activeToggle ( ae . parentElement . nextSibling . lastChild ) ;
116
119
}
117
- } else if ( key === "ArrowUp" && resultsAvailable && inbox ) {
120
+ } else if ( key === "ArrowUp" ) {
118
121
e . preventDefault ( ) ;
119
- if ( ae == sInput ) {
120
- // if the currently focused element is input box, do nothing
121
- } else if ( ae . parentElement == first ) {
122
+ if ( ae . parentElement == first ) {
122
123
// if the currently focused element is first item, go to input box
123
124
activeToggle ( sInput ) ;
124
- } else {
125
+ } else if ( ae != sInput ) {
126
+ // if the currently focused element is input box, do nothing
125
127
// otherwise select the previous search result
126
128
activeToggle ( ae . parentElement . previousSibling . lastChild ) ;
127
129
}
128
- } else if ( key === "ArrowRight" && resultsAvailable && inbox ) {
130
+ } else if ( key === "ArrowRight" ) {
129
131
ae . click ( ) ; // click on active link
130
- } else if ( key === "Escape" ) {
131
- reset ( )
132
132
}
133
133
}
0 commit comments