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

Function viewCuttingPoint

static/mergely/lib/codemirror.js:3339–3361  ·  view source on GitHub ↗
(cm, oldN, newN, dir)

Source from the content-addressed store, hash-verified

3337 }
3338
3339 function viewCuttingPoint(cm, oldN, newN, dir) {
3340 var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
3341 if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
3342 return {index: index, lineN: newN};
3343 for (var i = 0, n = cm.display.viewFrom; i < index; i++)
3344 n += view[i].size;
3345 if (n != oldN) {
3346 if (dir > 0) {
3347 if (index == view.length - 1) return null;
3348 diff = (n + view[index].size) - oldN;
3349 index++;
3350 } else {
3351 diff = n - oldN;
3352 }
3353 oldN += diff; newN += diff;
3354 }
3355 while (visualLineNo(cm.doc, newN) != newN) {
3356 if (index == (dir < 0 ? 0 : view.length - 1)) return null;
3357 newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
3358 index += dir;
3359 }
3360 return {index: index, lineN: newN};
3361 }
3362
3363 // Force the view to cover a given range, adding empty view element
3364 // or clipping off existing ones as needed.

Callers 1

regChangeFunction · 0.70

Calls 2

findViewIndexFunction · 0.70
visualLineNoFunction · 0.70

Tested by

no test coverage detected