({ active, slashCommands, onSubmit }: InputBoxProps)
| 46 | } |
| 47 | |
| 48 | export function InputBox({ active, slashCommands, onSubmit }: InputBoxProps) { |
| 49 | const [value, setValue] = useState("") |
| 50 | const [cursor, setCursor] = useState(0) |
| 51 | // Terminal-style prompt history: persisted across sessions in ~/.orbcode. |
| 52 | const [history, setHistory] = useState<string[]>(() => loadPromptHistory()) |
| 53 | const [historyIndex, setHistoryIndex] = useState(-1) |
| 54 | const [fileIndex, setFileIndex] = useState(0) |
| 55 | const [slashIndex, setSlashIndex] = useState(0) |
| 56 | const [dismissedValue, setDismissedValue] = useState<string | null>(null) |
| 57 | |
| 58 | // Workspace file list for @-references, computed once per session. |
| 59 | const files = useMemo( |
| 60 | () => walkFiles(process.cwd(), true, 3000).filter((f) => !f.endsWith("/")), |
| 61 | [], |
| 62 | ) |
| 63 | |
| 64 | const showSlashMenu = active && value.startsWith("/") && !value.includes(" ") |
| 65 | const slashMatches = showSlashMenu |
| 66 | ? slashCommands.filter((c) => c.name.startsWith(value)).slice(0, 8) |
| 67 | : [] |
| 68 | |
| 69 | const atToken = active ? findAtToken(value, cursor) : null |
| 70 | const fileMatches = useMemo(() => { |
| 71 | if (!atToken || value === dismissedValue) return [] |
| 72 | return files |
| 73 | .map((file) => ({ file, score: fuzzyScore(file, atToken.query) })) |
| 74 | .filter((m) => m.score >= 0) |
| 75 | .sort((a, b) => b.score - a.score) |
| 76 | .slice(0, MAX_FILE_MATCHES) |
| 77 | .map((m) => m.file) |
| 78 | }, [files, atToken?.query, atToken?.start, value, dismissedValue]) |
| 79 | |
| 80 | useEffect(() => { |
| 81 | setFileIndex(0) |
| 82 | }, [atToken?.query]) |
| 83 | |
| 84 | useEffect(() => { |
| 85 | setSlashIndex(0) |
| 86 | }, [value]) |
| 87 | |
| 88 | const submit = (text: string) => { |
| 89 | const trimmed = text.trim() |
| 90 | if (!trimmed) return |
| 91 | setHistory((h) => (h[h.length - 1] === trimmed ? h : [...h, trimmed])) |
| 92 | appendPromptHistory(trimmed) |
| 93 | setHistoryIndex(-1) |
| 94 | setValue("") |
| 95 | setCursor(0) |
| 96 | onSubmit(trimmed) |
| 97 | } |
| 98 | |
| 99 | const recallHistory = (index: number) => { |
| 100 | setHistoryIndex(index) |
| 101 | const entry = index === -1 ? "" : history[index] |
| 102 | setValue(entry) |
| 103 | setCursor(entry.length) |
| 104 | } |
| 105 |
nothing calls this directly
no test coverage detected