in sapp/ui/frontend/src/Source.js [110:152]
function computeLayout(
ranges: Array<Range>,
lines: $ReadOnlyArray<string>,
): Layout {
if (ranges.length === 0) {
return {totalLines: 10, folds: []};
}
var totalLines = Math.max(
ranges[ranges.length - 1].from.line - ranges[0].from.line + 3,
10,
);
var folds = [];
const foldingThreshold = 10;
const padding = 1;
for (var index = 0; index < ranges.length - 1; index++) {
const distance = ranges[index + 1].from.line - ranges[index].from.line;
const foldSize = distance - 2 * padding;
if (distance > foldingThreshold) {
const startLine = ranges[index].from.line + padding;
const endLine = startLine + foldSize;
folds.push({
line: startLine,
range: {
from: {
line: startLine,
ch: lines[startLine].length,
},
to: {
line: endLine,
ch: lines[endLine].length,
},
},
});
totalLines = totalLines - foldSize + linesPerFold;
}
}
return {totalLines, folds};
}