MCPcopy
hub / github.com/anomalyco/opencode / PromptInput

Function PromptInput

packages/app/src/components/prompt-input.tsx:202–2067  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

200] as const
201
202export const PromptInput: Component<PromptInputProps> = (props) => {
203 const sdk = useSDK()
204
205 const sync = useSync()
206 const files = useFile()
207 const prompt = props.state ?? usePrompt()
208 const layout = useLayout()
209 const comments = useComments()
210 const dialog = useDialog()
211 const command = useCommand()
212 const permission = usePermission()
213 const language = useLanguage()
214 const platform = usePlatform()
215 const tabs = () => props.controls.session.tabs
216 let editorRef!: HTMLDivElement
217 let fileInputRef: HTMLInputElement | undefined
218 let scrollRef!: HTMLDivElement
219 let slashPopoverRef!: HTMLDivElement
220 let restoreEndOnFocus = true
221
222 const mirror = { input: false }
223 const inset = 56
224 const space = `${inset}px`
225
226 const scrollCursorIntoView = () => {
227 const container = scrollRef
228 const selection = window.getSelection()
229 if (!container || !selection || selection.rangeCount === 0) return
230
231 const range = selection.getRangeAt(0)
232 if (!editorRef.contains(range.startContainer)) return
233
234 const cursor = getCursorPosition(editorRef)
235 const length = promptLength(prompt.current().filter((part) => part.type !== "image"))
236 if (cursor >= length) {
237 container.scrollTop = container.scrollHeight
238 return
239 }
240
241 const rect = range.getClientRects().item(0) ?? range.getBoundingClientRect()
242 if (!rect.height) return
243
244 const containerRect = container.getBoundingClientRect()
245 const top = rect.top - containerRect.top + container.scrollTop
246 const bottom = rect.bottom - containerRect.top + container.scrollTop
247 const padding = 12
248
249 if (top < container.scrollTop + padding) {
250 container.scrollTop = Math.max(0, top - padding)
251 return
252 }
253
254 if (bottom > container.scrollTop + container.clientHeight - inset) {
255 container.scrollTop = bottom - container.clientHeight + inset
256 }
257 }
258
259 const queueScroll = (count = 2) => {

Callers

nothing calls this directly

Calls 15

useSyncFunction · 0.90
useDialogFunction · 0.90
createSessionTabsFunction · 0.90
useSpringFunction · 0.90
promptPlaceholderFunction · 0.90
useFilteredListFunction · 0.90
promptLengthFunction · 0.90
setCursorPositionFunction · 0.90
createPromptAttachmentsFunction · 0.90
createPromptSubmitFunction · 0.90
motionFunction · 0.85

Tested by

no test coverage detected