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

Function findStartLine

external/.scrollLibs.js:2736–2757  ·  view source on GitHub ↗
(cm, n, precise)

Source from the content-addressed store, hash-verified

2734 // smallest indentation, which tends to need the least context to
2735 // parse correctly.
2736 function findStartLine(cm, n, precise) {
2737 var minindent,
2738 minline,
2739 doc = cm.doc
2740 var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100)
2741 for (var search = n; search > lim; --search) {
2742 if (search <= doc.first) {
2743 return doc.first
2744 }
2745 var line = getLine(doc, search - 1),
2746 after = line.stateAfter
2747 if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier)) {
2748 return search
2749 }
2750 var indented = countColumn(line.text, null, cm.options.tabSize)
2751 if (minline == null || minindent > indented) {
2752 minline = search - 1
2753 minindent = indented
2754 }
2755 }
2756 return minline
2757 }
2758
2759 function retreatFrontier(doc, n) {
2760 doc.modeFrontier = Math.min(doc.modeFrontier, n)

Callers 1

getContextBeforeFunction · 0.85

Calls 2

getLineFunction · 0.85
countColumnFunction · 0.85

Tested by

no test coverage detected