MCPcopy
hub / github.com/anomalyco/opencode / handleKeyDown

Function handleKeyDown

packages/app/src/pages/session.tsx:915–953  ·  view source on GitHub ↗
(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

focusTerminalByIdFunction · 0.90
deepActiveElementFunction · 0.85
viewFunction · 0.85
markScrollGestureFunction · 0.85
activeMethod · 0.80
isEditableTargetFunction · 0.70
findMethod · 0.65

Tested by

no test coverage detected