"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.splitCodeAndIndentation = splitCodeAndIndentation;
exports.collateAllIntervalsWithColors = collateAllIntervalsWithColors;
function splitCodeAndIndentation(code) {
    const codeStartIdx = code.search(/\S|$/);
    const indents = code.substring(0, codeStartIdx);
    const content = code.substring(codeStartIdx);
    return [indents, content];
}
function collateAllIntervalsWithColors(boundsWithColors) {
    if (boundsWithColors.length === 0) {
        return [];
    }
    boundsWithColors.sort((a, b) => a.bounds[0] - b.bounds[0]);
    const merged = [];
    let current = boundsWithColors[0];
    for (let i = 1; i < boundsWithColors.length; i += 1) {
        const next = boundsWithColors[i];
        if (next.bounds[0] <= (current.bounds[1] - 1)) {
            // merge if overlap
            current.bounds[1] = Math.max(current.bounds[1], next.bounds[1]);
            current.color = next.color;
        }
        else {
            merged.push(current);
            current = next;
        }
    }
    // Add the last merged interval
    merged.push(current);
    return merged;
}
//# sourceMappingURL=helper.js.map