( focusTarget: WindowKeyboardFocusTarget, snapshot: FocusSnapshot, delayMs: number )
| 60 | }; |
| 61 | |
| 62 | export const restoreWindowKeyboardFocus = ( |
| 63 | focusTarget: WindowKeyboardFocusTarget, |
| 64 | snapshot: FocusSnapshot, |
| 65 | delayMs: number |
| 66 | ) => { |
| 67 | setTimeout(() => { |
| 68 | void (async () => { |
| 69 | try { |
| 70 | await focusTarget?.setFocus?.(); |
| 71 | } catch { |
| 72 | // Ignore focus failures during native window transitions. |
| 73 | } |
| 74 | |
| 75 | try { |
| 76 | // Hidden fullscreen relayouts show the native window before the WebView |
| 77 | // reliably owns keyboard focus. The DOM F11 listener only receives the |
| 78 | // next keydown after the WebView, not just the native window, is focused. |
| 79 | await focusTarget?.setWebviewFocus?.(); |
| 80 | } catch { |
| 81 | // Ignore focus failures during native webview transitions. |
| 82 | } |
| 83 | |
| 84 | window.focus(); |
| 85 | |
| 86 | if (snapshot.wasInputFocused) { |
| 87 | restoreFocusedEditable(snapshot); |
| 88 | } else { |
| 89 | focusAppRootForKeyboardShortcuts(); |
| 90 | } |
| 91 | })(); |
| 92 | }, delayMs); |
| 93 | }; |
no test coverage detected