()
| 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) => { |
| 260 | requestAnimationFrame(() => { |
no test coverage detected