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

Function addNextWords

web/src/components/IDEDemo.tsx:245–277  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

243 let currentText = ''
244
245 const addNextWords = () => {
246 if (currentWordIndex >= words.length) {
247 onComplete()
248 return
249 }
250
251 const wordsToAdd = Math.min(
252 Math.floor(Math.random() * 4) + 1,
253 words.length - currentWordIndex,
254 )
255
256 const nextSegment = words
257 .slice(currentWordIndex, currentWordIndex + wordsToAdd)
258 .join(' ')
259 currentText += (currentText ? ' ' : '') + nextSegment
260 currentWordIndex += wordsToAdd
261
262 setTerminalLines((prev) => {
263 const newLines = [...prev]
264 if (newLines.length === currentMessageIndex) {
265 newLines.push(currentText)
266 } else {
267 newLines[currentMessageIndex] = currentText
268 }
269 return newLines
270 })
271
272 if (currentWordIndex < words.length) {
273 setTimeout(addNextWords, Math.random() * 100 + 50)
274 } else {
275 setTimeout(onComplete, 100)
276 }
277 }
278
279 addNextWords()
280 }

Callers 1

streamWordsFunction · 0.85

Calls 1

setTimeoutFunction · 0.85

Tested by

no test coverage detected