MCPcopy Create free account
hub / github.com/TruthHun/BookStack / visibleLines

Function visibleLines

static/mergely/lib/codemirror.js:562–581  ·  view source on GitHub ↗
(display, doc, viewport)

Source from the content-addressed store, hash-verified

560 // the the current scroll position). viewport may contain top,
561 // height, and ensure (see op.scrollToPos) properties.
562 function visibleLines(display, doc, viewport) {
563 var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
564 top = Math.floor(top - paddingTop(display));
565 var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
566
567 var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
568 // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
569 // forces those lines into the viewport (if possible).
570 if (viewport && viewport.ensure) {
571 var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
572 if (ensureFrom < from) {
573 from = ensureFrom;
574 to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
575 } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
576 from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
577 to = ensureTo;
578 }
579 }
580 return {from: from, to: Math.max(to, from + 1)};
581 }
582
583 // LINE NUMBERS
584

Callers 3

DisplayUpdateFunction · 0.70
postUpdateDisplayFunction · 0.70
extendFunction · 0.70

Calls 4

paddingTopFunction · 0.70
lineAtHeightFunction · 0.70
heightAtLineFunction · 0.70
getLineFunction · 0.70

Tested by

no test coverage detected