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

Function handleKeyDown

packages/app/src/components/prompt-input.tsx:1296–1459  ·  view source on GitHub ↗
(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

1294 })
1295
1296 const handleKeyDown = (event: KeyboardEvent) => {
1297 if ((event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && event.key.toLowerCase() === "u") {
1298 event.preventDefault()
1299 if (store.mode !== "normal") return
1300 pick()
1301 return
1302 }
1303
1304 if (event.key === "Backspace") {
1305 const selection = window.getSelection()
1306 if (selection && selection.isCollapsed) {
1307 const node = selection.anchorNode
1308 const offset = selection.anchorOffset
1309 if (node && node.nodeType === Node.TEXT_NODE) {
1310 const text = node.textContent ?? ""
1311 if (/^\u200B+$/.test(text) && offset > 0) {
1312 const range = document.createRange()
1313 range.setStart(node, 0)
1314 range.collapse(true)
1315 selection.removeAllRanges()
1316 selection.addRange(range)
1317 }
1318 }
1319 }
1320 }
1321
1322 if (event.key === "!" && store.mode === "normal") {
1323 const cursorPosition = getCursorPosition(editorRef)
1324 if (cursorPosition === 0) {
1325 setStore("mode", "shell")
1326 setStore("popover", null)
1327 event.preventDefault()
1328 return
1329 }
1330 }
1331
1332 if (event.key === "Escape") {
1333 if (store.popover) {
1334 closePopover()
1335 event.preventDefault()
1336 event.stopPropagation()
1337 return
1338 }
1339
1340 if (store.mode === "shell") {
1341 setStore("mode", "normal")
1342 event.preventDefault()
1343 event.stopPropagation()
1344 return
1345 }
1346
1347 if (working()) {
1348 void abort()
1349 event.preventDefault()
1350 event.stopPropagation()
1351 return
1352 }
1353

Callers

nothing calls this directly

Calls 15

getCursorPositionFunction · 0.90
setStoreFunction · 0.85
closePopoverFunction · 0.85
escBlurFunction · 0.85
getCaretStateFunction · 0.85
addPartFunction · 0.85
isImeComposingFunction · 0.85
selectPopoverActiveFunction · 0.85
navigateHistoryFunction · 0.85
pickFunction · 0.70

Tested by

no test coverage detected