MCPcopy Create free account
hub / github.com/GCWing/BitFun / restoreWindowKeyboardFocus

Function restoreWindowKeyboardFocus

src/web-ui/src/app/hooks/windowKeyboardFocus.ts:62–93  ·  view source on GitHub ↗
(
  focusTarget: WindowKeyboardFocusTarget,
  snapshot: FocusSnapshot,
  delayMs: number
)

Source from the content-addressed store, hash-verified

60};
61
62export 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};

Callers 3

handleWindowRestoreFunction · 0.90
useWindowControlsFunction · 0.90

Calls 3

restoreFocusedEditableFunction · 0.85
focusMethod · 0.65

Tested by

no test coverage detected