MCPcopy Create free account
hub / github.com/anomalyco/opencode / scrollCursorIntoView

Function scrollCursorIntoView

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

Source from the content-addressed store, hash-verified

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(() => {

Callers 1

queueScrollFunction · 0.85

Calls 4

getCursorPositionFunction · 0.90
promptLengthFunction · 0.90
itemMethod · 0.80
currentMethod · 0.45

Tested by

no test coverage detected