(props)
| 200 | ] as const |
| 201 | |
| 202 | export 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) => { |
nothing calls this directly
no test coverage detected