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

Function scrollPosIntoView

lib/web/CodeMirror/src/display/scrolling.js:35–66  ·  view source on GitHub ↗
(cm, pos, end, margin)

Source from the content-addressed store, hash-verified

33// it actually became visible (as line heights are accurately
34// measured, the position of something may 'drift' during drawing).
35export function scrollPosIntoView(cm, pos, end, margin) {
36 if (margin == null) margin = 0
37 let rect
38 if (!cm.options.lineWrapping && pos == end) {
39 // Set pos and end to the cursor positions around the character pos sticks to
40 // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
41 // If pos == Pos(_, 0, "before"), pos and end are unchanged
42 pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos
43 end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos
44 }
45 for (let limit = 0; limit < 5; limit++) {
46 let changed = false
47 let coords = cursorCoords(cm, pos)
48 let endCoords = !end || end == pos ? coords : cursorCoords(cm, end)
49 rect = {left: Math.min(coords.left, endCoords.left),
50 top: Math.min(coords.top, endCoords.top) - margin,
51 right: Math.max(coords.left, endCoords.left),
52 bottom: Math.max(coords.bottom, endCoords.bottom) + margin}
53 let scrollPos = calculateScrollPos(cm, rect)
54 let startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft
55 if (scrollPos.scrollTop != null) {
56 updateScrollTop(cm, scrollPos.scrollTop)
57 if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true
58 }
59 if (scrollPos.scrollLeft != null) {
60 setScrollLeft(cm, scrollPos.scrollLeft)
61 if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true
62 }
63 if (!changed) break
64 }
65 return rect
66}
67
68// Scroll a given set of coordinates into view (immediately).
69export function scrollIntoView(cm, rect) {

Callers 1

endOperation_finishFunction · 0.90

Calls 7

PosFunction · 0.90
cursorCoordsFunction · 0.90
calculateScrollPosFunction · 0.70
updateScrollTopFunction · 0.70
setScrollLeftFunction · 0.70
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected