MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / trySelectAtIndex

Function trySelectAtIndex

cli/src/chat.tsx:1027–1050  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

1025 if (mentionContext.startIndex < 0) return
1026
1027 const trySelectAtIndex = (index: number): boolean => {
1028 let replacement: string
1029 if (index < agentMatches.length) {
1030 const selected = agentMatches[index]
1031 if (!selected) return false
1032 replacement = `@${selected.id} `
1033 } else {
1034 const fileIndex = index - agentMatches.length
1035 const selectedFile = fileMatches[fileIndex]
1036 if (!selectedFile) return false
1037 replacement = `@${selectedFile.filePath} `
1038 }
1039 const before = inputValue.slice(0, mentionContext.startIndex)
1040 const after = inputValue.slice(
1041 mentionContext.startIndex + 1 + mentionContext.query.length,
1042 )
1043 setInputValue({
1044 text: before + replacement + after,
1045 cursorPosition: before.length + replacement.length,
1046 lastEditDueToNav: false,
1047 })
1048 setAgentSelectedIndex(0)
1049 return true
1050 }
1051
1052 // Try current selection, fall back to first item
1053 trySelectAtIndex(agentSelectedIndex) || trySelectAtIndex(0)

Callers 1

ChatFunction · 0.85

Calls 1

setInputValueFunction · 0.85

Tested by

no test coverage detected