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

Function select

packages/opencode/src/cli/cmd/run/footer.prompt.tsx:842–948  ·  view source on GitHub ↗
(item?: PromptOption)

Source from the content-addressed store, hash-verified

840 }
841
842 const select = (item?: PromptOption) => {
843 const next = item ?? options()[menu.selected()]
844 if (!next || !area || area.isDestroyed) {
845 return
846 }
847
848 if (next.kind === "slash") {
849 if (next.action === "editor") {
850 void openEditor({
851 value: resolveEditorSlashValue(area.plainText),
852 })
853 return
854 }
855
856 if (next.action === "skill-menu") {
857 cancelAutocomplete()
858 input.onSkillMenu()
859 return
860 }
861
862 const cursor = area.cursorOffset
863 const head = slashHead(area.plainText)
864 const local = !shell() && (next.name === "new" || next.name === "exit")
865 const separator = !shell() && !local && head && /\s/.test(area.plainText[head.end] ?? "") ? "" : " "
866 const text = `/${next.name}${separator}`
867
868 area.cursorOffset = 0
869 const start = area.logicalCursor
870 area.cursorOffset =
871 shell() || !head
872 ? cursor
873 : local
874 ? Bun.stringWidth(area.plainText)
875 : Bun.stringWidth(area.plainText.slice(0, head.end))
876 const end = area.logicalCursor
877
878 area.deleteRange(start.row, start.col, end.row, end.col)
879 area.insertText(text)
880 area.cursorOffset = Bun.stringWidth(text)
881 hide()
882 syncDraft()
883 if (!shell()) {
884 submitPrompt(clonePrompt(draft))
885 return
886 }
887
888 scheduleRows()
889 area.focus()
890 return
891 }
892
893 const cursor = area.cursorOffset
894 const tail = displayCharAt(area.plainText, cursor)
895 const append = "@" + next.value + (tail === " " ? "" : " ")
896 area.cursorOffset = at()
897 const start = area.logicalCursor
898 area.cursorOffset = cursor
899 const end = area.logicalCursor

Callers 2

runFunction · 0.70
submitPromptFunction · 0.70

Calls 15

resolveEditorSlashValueFunction · 0.90
cancelAutocompleteFunction · 0.85
shellFunction · 0.85
syncDraftFunction · 0.85
submitPromptFunction · 0.85
scheduleRowsFunction · 0.85
displayCharAtFunction · 0.85
pushMethod · 0.80
openEditorFunction · 0.70
slashHeadFunction · 0.70
hideFunction · 0.70
clonePromptFunction · 0.70

Tested by

no test coverage detected