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

Function viewCuttingPoint

static/editor.md/lib/codemirror/lib/codemirror.js:3230–3252  ·  view source on GitHub ↗
(cm, oldN, newN, dir)

Source from the content-addressed store, hash-verified

3228 }
3229
3230 function viewCuttingPoint(cm, oldN, newN, dir) {
3231 var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
3232 if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
3233 return {index: index, lineN: newN};
3234 for (var i = 0, n = cm.display.viewFrom; i < index; i++)
3235 n += view[i].size;
3236 if (n != oldN) {
3237 if (dir > 0) {
3238 if (index == view.length - 1) return null;
3239 diff = (n + view[index].size) - oldN;
3240 index++;
3241 } else {
3242 diff = n - oldN;
3243 }
3244 oldN += diff; newN += diff;
3245 }
3246 while (visualLineNo(cm.doc, newN) != newN) {
3247 if (index == (dir < 0 ? 0 : view.length - 1)) return null;
3248 newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
3249 index += dir;
3250 }
3251 return {index: index, lineN: newN};
3252 }
3253
3254 // Force the view to cover a given range, adding empty view element
3255 // 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