({
candidates,
selectedIndex,
scrollRef,
onSelect,
onExecute,
}: FileMentionMenuProps)
| 206 | }; |
| 207 | |
| 208 | function FileMentionMenu({ |
| 209 | candidates, |
| 210 | selectedIndex, |
| 211 | scrollRef, |
| 212 | onSelect, |
| 213 | onExecute, |
| 214 | }: FileMentionMenuProps) { |
| 215 | const { colors } = useTheme(); |
| 216 | const visibleHeight = Math.min(candidates.length, MAX_VISIBLE_MENTIONS); |
| 217 | |
| 218 | if (candidates.length === 0) { |
| 219 | return ( |
| 220 | <box paddingX={1}> |
| 221 | <text attributes={TextAttributes.DIM}>No matching files or folders</text> |
| 222 | </box> |
| 223 | ); |
| 224 | } |
| 225 | |
| 226 | return ( |
| 227 | <scrollbox ref={scrollRef} height={visibleHeight}> |
| 228 | {candidates.map((candidate, index) => { |
| 229 | const isSelected = index === selectedIndex; |
| 230 | |
| 231 | return ( |
| 232 | <box |
| 233 | key={candidate.path} |
| 234 | flexDirection="row" |
| 235 | paddingX={1} |
| 236 | height={1} |
| 237 | overflow="hidden" |
| 238 | backgroundColor={isSelected ? colors.selection : undefined} |
| 239 | onMouseMove={() => onSelect(index)} |
| 240 | onMouseDown={() => onExecute(index)} |
| 241 | > |
| 242 | <box flexGrow={1} flexShrink={1} overflow="hidden"> |
| 243 | <text selectable={false} fg={isSelected ? "black" : "white"}> |
| 244 | {candidate.path} |
| 245 | </text> |
| 246 | </box> |
| 247 | |
| 248 | <box width={8} alignItems="flex-end" flexShrink={0}> |
| 249 | <text selectable={false} fg={isSelected ? "black" : "gray"}> |
| 250 | {candidate.kind === "directory" ? "Folder" : "File"} |
| 251 | </text> |
| 252 | </box> |
| 253 | </box> |
| 254 | ); |
| 255 | })} |
| 256 | </scrollbox> |
| 257 | ); |
| 258 | }; |
| 259 | |
| 260 | type Props = { |
| 261 | onSubmit: (text: string) => void; |
nothing calls this directly
no test coverage detected