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

Function calculateScrollPos

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

Source from the content-addressed store, hash-verified

77// scrollLeft properties. When these are undefined, the
78// vertical/horizontal position does not need to be adjusted.
79function calculateScrollPos(cm, rect) {
80 let display = cm.display, snapMargin = textHeight(cm.display)
81 if (rect.top < 0) rect.top = 0
82 let screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
83 let screen = displayHeight(cm), result = {}
84 if (rect.bottom - rect.top > screen) rect.bottom = rect.top + screen
85 let docBottom = cm.doc.height + paddingVert(display)
86 let atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin
87 if (rect.top < screentop) {
88 result.scrollTop = atTop ? 0 : rect.top
89 } else if (rect.bottom > screentop + screen) {
90 let newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen)
91 if (newTop != screentop) result.scrollTop = newTop
92 }
93
94 let gutterSpace = cm.options.fixedGutter ? 0 : display.gutters.offsetWidth
95 let screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft - gutterSpace
96 let screenw = displayWidth(cm) - display.gutters.offsetWidth
97 let tooWide = rect.right - rect.left > screenw
98 if (tooWide) rect.right = rect.left + screenw
99 if (rect.left < 10)
100 result.scrollLeft = 0
101 else if (rect.left < screenleft)
102 result.scrollLeft = Math.max(0, rect.left + gutterSpace - (tooWide ? 0 : 10))
103 else if (rect.right > screenw + screenleft - 3)
104 result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw
105 return result
106}
107
108// Store a relative adjustment to the scroll position in the current
109// operation (to be applied when the operation finishes).

Callers 3

scrollPosIntoViewFunction · 0.70
scrollIntoViewFunction · 0.70
scrollToCoordsRangeFunction · 0.70

Calls 6

textHeightFunction · 0.90
displayHeightFunction · 0.90
paddingVertFunction · 0.90
displayWidthFunction · 0.90
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected