(event)
| 27 | } |
| 28 | |
| 29 | export function onKeyEvent(event) { |
| 30 | // Handle <Enter> on "keypress", and other events on "keydown"; this avoids interence with CJK |
| 31 | // translation (see #2915 and #2934). |
| 32 | let rawQuery; |
| 33 | if ((event.type === "keypress") && (event.key !== "Enter")) { |
| 34 | return null; |
| 35 | } |
| 36 | if ((event.type === "keydown") && (event.key === "Enter")) { |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | const inputEl = document.querySelector("#hud-find-input"); |
| 41 | // Don't do anything if we're not in find mode. |
| 42 | if (inputEl == null) return; |
| 43 | |
| 44 | if ( |
| 45 | (KeyboardUtils.isBackspace(event) && (inputEl.textContent.length === 0)) || |
| 46 | (event.key === "Enter") || KeyboardUtils.isEscape(event) |
| 47 | ) { |
| 48 | inputEl.blur(); |
| 49 | UIComponentMessenger.postMessage({ |
| 50 | name: "hideFindMode", |
| 51 | exitEventIsEnter: event.key === "Enter", |
| 52 | exitEventIsEscape: KeyboardUtils.isEscape(event), |
| 53 | }); |
| 54 | } else if (event.key === "ArrowUp") { |
| 55 | if (rawQuery = FindModeHistory.getQuery(findMode.historyIndex + 1)) { |
| 56 | findMode.historyIndex += 1; |
| 57 | if (findMode.historyIndex === 0) { |
| 58 | findMode.partialQuery = findMode.rawQuery; |
| 59 | } |
| 60 | setTextInInputElement(inputEl, rawQuery); |
| 61 | findMode.executeQuery(); |
| 62 | } |
| 63 | } else if (event.key === "ArrowDown") { |
| 64 | findMode.historyIndex = Math.max(-1, findMode.historyIndex - 1); |
| 65 | rawQuery = 0 <= findMode.historyIndex |
| 66 | ? FindModeHistory.getQuery(findMode.historyIndex) |
| 67 | : findMode.partialQuery; |
| 68 | setTextInInputElement(inputEl, rawQuery); |
| 69 | findMode.executeQuery(); |
| 70 | } else { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | DomUtils.suppressEvent(event); |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | // Navigator.clipboard is only available in secure contexts. Show a warning when clipboard actions |
| 79 | // fail on non-HTTPS sites. See #4572. |
nothing calls this directly
no test coverage detected