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

Function estimateHeight

static/editor.md/lib/codemirror/lib/codemirror.js:266–282  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

264 // first approximation until the line becomes visible (and is thus
265 // properly measurable).
266 function estimateHeight(cm) {
267 var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
268 var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
269 return function(line) {
270 if (lineIsHidden(cm.doc, line)) return 0;
271
272 var widgetsHeight = 0;
273 if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
274 if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
275 }
276
277 if (wrapping)
278 return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
279 else
280 return widgetsHeight + th;
281 };
282 }
283
284 function estimateLineHeights(cm) {
285 var doc = cm.doc, est = estimateHeight(cm);

Callers 4

estimateLineHeightsFunction · 0.70
codemirror.jsFile · 0.70
updateLineFunction · 0.70

Calls 3

textHeightFunction · 0.70
charWidthFunction · 0.70
lineIsHiddenFunction · 0.70

Tested by

no test coverage detected