MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / maybeScrollWindow

Function maybeScrollWindow

lib/web/CodeMirror/src/display/scrolling.js:15–30  ·  view source on GitHub ↗
(cm, rect)

Source from the content-addressed store, hash-verified

13// If an editor sits on the top or bottom of the window, partially
14// scrolled out of view, this ensures that the cursor is visible.
15export function maybeScrollWindow(cm, rect) {
16 if (signalDOMEvent(cm, "scrollCursorIntoView")) return
17
18 let display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null
19 if (rect.top + box.top < 0) doScroll = true
20 else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false
21 if (doScroll != null && !phantom) {
22 let scrollNode = elt("div", "\u200b", null, `position: absolute;
23 top: ${rect.top - display.viewOffset - paddingTop(cm.display)}px;
24 height: ${rect.bottom - rect.top + scrollGap(cm) + display.barHeight}px;
25 left: ${rect.left}px; width: ${Math.max(2, rect.right - rect.left)}px;`)
26 cm.display.lineSpace.appendChild(scrollNode)
27 scrollNode.scrollIntoView(doScroll)
28 cm.display.lineSpace.removeChild(scrollNode)
29 }
30}
31
32// Scroll a given position into view (immediately), verifying that
33// it actually became visible (as line heights are accurately

Callers 1

endOperation_finishFunction · 0.90

Calls 5

signalDOMEventFunction · 0.90
eltFunction · 0.90
paddingTopFunction · 0.90
scrollGapFunction · 0.90
maxMethod · 0.45

Tested by

no test coverage detected