(event: KeyboardEvent)
| 913 | } |
| 914 | |
| 915 | const handleKeyDown = (event: KeyboardEvent) => { |
| 916 | const path = event.composedPath() |
| 917 | const target = path.find((item): item is HTMLElement => item instanceof HTMLElement) |
| 918 | const activeElement = deepActiveElement() |
| 919 | |
| 920 | const protectedTarget = path.some( |
| 921 | (item) => item instanceof HTMLElement && item.closest("[data-prevent-autofocus]") !== null, |
| 922 | ) |
| 923 | if (protectedTarget || isEditableTarget(target)) return |
| 924 | |
| 925 | if (activeElement) { |
| 926 | const isProtected = activeElement.closest("[data-prevent-autofocus]") |
| 927 | const isInput = isEditableTarget(activeElement) |
| 928 | if (isProtected || isInput) return |
| 929 | } |
| 930 | if (dialog.active) return |
| 931 | |
| 932 | if (activeElement === inputRef) { |
| 933 | if (event.key === "Escape") inputRef?.blur() |
| 934 | return |
| 935 | } |
| 936 | |
| 937 | // Prefer the open terminal over the composer when it can take focus |
| 938 | if (view().terminal.opened()) { |
| 939 | const id = terminal.active() |
| 940 | if (id && shouldFocusTerminalOnKeyDown(event) && focusTerminalById(id)) return |
| 941 | } |
| 942 | |
| 943 | // Only treat explicit scroll keys as potential "user scroll" gestures. |
| 944 | if (event.key === "PageUp" || event.key === "PageDown" || event.key === "Home" || event.key === "End") { |
| 945 | markScrollGesture() |
| 946 | return |
| 947 | } |
| 948 | |
| 949 | if (event.key.length === 1 && event.key !== "Unidentified" && !(event.ctrlKey || event.metaKey)) { |
| 950 | if (composer.blocked() || isChildSession()) return |
| 951 | inputRef?.focus() |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | createEffect(() => { |
| 956 | if (!sync().project) return |
nothing calls this directly
no test coverage detected