MCPcopy Create free account
hub / github.com/breck7/scroll / viewCuttingPoint

Function viewCuttingPoint

external/.scrollLibs.js:5685–5717  ·  view source on GitHub ↗
(cm, oldN, newN, dir)

Source from the content-addressed store, hash-verified

5683 }
5684
5685 function viewCuttingPoint(cm, oldN, newN, dir) {
5686 var index = findViewIndex(cm, oldN),
5687 diff,
5688 view = cm.display.view
5689 if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size) {
5690 return { index: index, lineN: newN }
5691 }
5692 var n = cm.display.viewFrom
5693 for (var i = 0; i < index; i++) {
5694 n += view[i].size
5695 }
5696 if (n != oldN) {
5697 if (dir > 0) {
5698 if (index == view.length - 1) {
5699 return null
5700 }
5701 diff = n + view[index].size - oldN
5702 index++
5703 } else {
5704 diff = n - oldN
5705 }
5706 oldN += diff
5707 newN += diff
5708 }
5709 while (visualLineNo(cm.doc, newN) != newN) {
5710 if (index == (dir < 0 ? 0 : view.length - 1)) {
5711 return null
5712 }
5713 newN += dir * view[index - (dir < 0 ? 1 : 0)].size
5714 index += dir
5715 }
5716 return { index: index, lineN: newN }
5717 }
5718
5719 // Force the view to cover a given range, adding empty view element
5720 // or clipping off existing ones as needed.

Callers 1

regChangeFunction · 0.85

Calls 2

findViewIndexFunction · 0.85
visualLineNoFunction · 0.85

Tested by

no test coverage detected