(event)
| 184 | } |
| 185 | |
| 186 | async onKeyEvent(event) { |
| 187 | const action = this.actionFromKeyEvent(event); |
| 188 | if (!action) { |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | if (action === "dismiss") { |
| 193 | this.hide(); |
| 194 | } else if (["tab", "down"].includes(action)) { |
| 195 | if ( |
| 196 | (action === "tab") && |
| 197 | (this.completerName === "omni") && |
| 198 | !this.seenTabToOpenCompletionList && |
| 199 | (this.input.value.trim().length === 0) |
| 200 | ) { |
| 201 | this.seenTabToOpenCompletionList = true; |
| 202 | this.update(); |
| 203 | } else if (this.completions.length > 0) { |
| 204 | this.selection += 1; |
| 205 | if (this.selection === this.completions.length) { |
| 206 | this.selection = this.initialSelectionValue; |
| 207 | } |
| 208 | this.updateSelection(); |
| 209 | } |
| 210 | } else if (action === "up") { |
| 211 | this.selection -= 1; |
| 212 | if (this.selection < this.initialSelectionValue) { |
| 213 | this.selection = this.completions.length - 1; |
| 214 | } |
| 215 | this.updateSelection(); |
| 216 | } else if (action === "enter") { |
| 217 | await this.handleEnterKey(event); |
| 218 | } else if (action === "ctrl-enter") { |
| 219 | // Populate the vomnibar with the current selection's URL. |
| 220 | if (!this.isUserSearchEngineActive() && (this.selection >= 0)) { |
| 221 | if (this.previousInputValue == null) { |
| 222 | this.previousInputValue = this.input.value; |
| 223 | } |
| 224 | this.input.value = this.completions[this.selection]?.url; |
| 225 | this.input.scrollLeft = this.input.scrollWidth; |
| 226 | } |
| 227 | } else if (action === "delete") { |
| 228 | if (this.isUserSearchEngineActive() && (this.input.selectionEnd === 0)) { |
| 229 | // Normally, with custom search engines, the keyword (e.g. the "w" of "w query terms") is |
| 230 | // suppressed. If the cursor is at the start of the input, then reinstate the keyword (the |
| 231 | // "w"). |
| 232 | const keyword = this.activeUserSearchEngine.keyword; |
| 233 | this.input.value = keyword + this.input.value.trimStart(); |
| 234 | this.input.selectionStart = this.input.selectionEnd = keyword.length; |
| 235 | this.activeUserSearchEngine = null; |
| 236 | this.update(); |
| 237 | } else if (this.seenTabToOpenCompletionList && (this.input.value.trim().length === 0)) { |
| 238 | this.seenTabToOpenCompletionList = false; |
| 239 | this.update(); |
| 240 | } else { |
| 241 | return; // Do not suppress event. |
| 242 | } |
| 243 | } else if ((action === "remove") && (this.selection >= 0)) { |
no test coverage detected