MCPcopy
hub / github.com/hokein/electron-sample-apps / scrollIntoView

Function scrollIntoView

mini-code-editor/cm/lib/codemirror.js:895–917  ·  view source on GitHub ↗
(x1, y1, x2, y2)

Source from the content-addressed store, hash-verified

893 return scrollIntoView(x, cursor.y, x, cursor.yBot);
894 }
895 function scrollIntoView(x1, y1, x2, y2) {
896 var pl = paddingLeft(), pt = paddingTop();
897 y1 += pt; y2 += pt; x1 += pl; x2 += pl;
898 var screen = scroller.clientHeight, screentop = scroller.scrollTop, scrolled = false, result = true;
899 if (y1 < screentop) {scroller.scrollTop = Math.max(0, y1); scrolled = true;}
900 else if (y2 > screentop + screen) {scroller.scrollTop = y2 - screen; scrolled = true;}
901
902 var screenw = scroller.clientWidth, screenleft = scroller.scrollLeft;
903 var gutterw = options.fixedGutter ? gutter.clientWidth : 0;
904 var atLeft = x1 < gutterw + pl + 10;
905 if (x1 < screenleft + gutterw || atLeft) {
906 if (atLeft) x1 = 0;
907 scroller.scrollLeft = Math.max(0, x1 - 10 - gutterw);
908 scrolled = true;
909 }
910 else if (x2 > screenw + screenleft - 3) {
911 scroller.scrollLeft = x2 + 10 - screenw;
912 scrolled = true;
913 if (x2 > code.clientWidth) result = false;
914 }
915 if (scrolled && options.onScroll) options.onScroll(instance);
916 return result;
917 }
918
919 function visibleLines() {
920 var lh = textHeight(), top = scroller.scrollTop - paddingTop();

Callers 2

CodeMirrorFunction · 0.85
scrollCursorIntoViewFunction · 0.85

Calls 2

paddingLeftFunction · 0.85
paddingTopFunction · 0.85

Tested by

no test coverage detected