MCPcopy Create free account
hub / github.com/anomalyco/opencode / handleKey

Function handleKey

packages/opencode/src/cli/cmd/run/footer.command.tsx:127–191  ·  view source on GitHub ↗
(input: {
  event: KeyEvent
  menu: MenuState
  field: () => InputRenderable | undefined
  setQuery: (value: string) => void
  select: () => void
  close: () => void
})

Source from the content-addressed store, hash-verified

125}
126
127function handleKey(input: {
128 event: KeyEvent
129 menu: MenuState
130 field: () => InputRenderable | undefined
131 setQuery: (value: string) => void
132 select: () => void
133 close: () => void
134}) {
135 const name = input.event.name.toLowerCase()
136 const ctrl = input.event.ctrl && !input.event.meta && !input.event.shift && !input.event.super
137
138 if (name === "escape" || (ctrl && name === "c")) {
139 input.event.preventDefault()
140 input.close()
141 return
142 }
143
144 if (name === "up" || (ctrl && name === "p")) {
145 input.event.preventDefault()
146 input.menu.move(-1)
147 return
148 }
149
150 if (name === "down" || (ctrl && name === "n")) {
151 input.event.preventDefault()
152 input.menu.move(1)
153 return
154 }
155
156 if (name === "pageup") {
157 input.event.preventDefault()
158 input.menu.reveal(input.menu.selected() - PANEL_PAGE)
159 return
160 }
161
162 if (name === "pagedown") {
163 input.event.preventDefault()
164 input.menu.reveal(input.menu.selected() + PANEL_PAGE)
165 return
166 }
167
168 if (name === "home") {
169 input.event.preventDefault()
170 input.menu.reveal(0)
171 return
172 }
173
174 if (name === "end") {
175 input.event.preventDefault()
176 input.menu.reveal(Number.POSITIVE_INFINITY)
177 return
178 }
179
180 if (name === "return") {
181 input.event.preventDefault()
182 input.select()
183 return
184 }

Callers 6

RunCommandMenuBodyFunction · 0.70
RunSubagentSelectBodyFunction · 0.70
RunSkillSelectBodyFunction · 0.70
RunVariantSelectBodyFunction · 0.70
RunModelSelectBodyFunction · 0.70

Calls 2

closeMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected