function updateFoldsCache(cm, from, linesDiff) {
        var oldRange, newRange;
        var minFoldSize = prefs.getSetting("minFoldSize") || 2;
        var foldedLines = Object.keys(cm._lineFolds).map(function (d) {
            return +d;
        });
        var opts = cm.state.foldGutter.options || {};
        var rf = opts.rangeFinder || CodeMirror.fold.auto;

        if (linesDiff === 0) {
            if (foldedLines.indexOf(from) >= 0) {
                newRange = rf(cm, CodeMirror.Pos(from, 0));
                if (newRange && newRange.to.line - newRange.from.line >= minFoldSize) {
                    cm._lineFolds[from] = newRange;
                } else {
                    delete cm._lineFolds[from];
                }
            }
        } else if (foldedLines.length) {
            var newFolds = {};
            foldedLines.forEach(function (line) {
                oldRange = cm._lineFolds[line];
                //update range with lines-diff
                newRange = moveRange(oldRange, linesDiff);
                // for removed lines we want to check lines that lie outside the deleted range
                if (linesDiff < 0) {
                    if (line < from) {
                        newFolds[line] = oldRange;
                    } else if (line >= from + Math.abs(linesDiff)) {
                        newFolds[line + linesDiff] = newRange;
                    }
                } else {
                    if (line < from) {
                        newFolds[line] = oldRange;
                    } else if (line >= from) {
                        newFolds[line + linesDiff] = newRange;
                    }
                }
            });
            cm._lineFolds = newFolds;
        }
    }
Updates the line folds cache usually when the document changes.
The following cases are accounted for:
1.  When the change does not add a new line to the document we check if the line being modified
    is folded. If that is the case, changes to this line might affect the range stored in the cache
    so we update the range using the range finder function.
2.  If lines have been added, we need to update the records for all lines in the folds cache
    which are greater than the line position at which we are adding the new line(s). When existing
    folds are above the addition we keep the original position in the cache.
3.  If lines are being removed, we need to update the records for all lines in the folds cache which are
    greater than the line position at which we are removing the new lines, while making sure to
    not include any folded lines in the cache that are part of the removed chunk.
@param {!CodeMirror} cm        the CodeMirror instance for the active editor
@param {!number}     from      the line number designating the start position of the change
@param {!number}     linesDiff a number to show how many lines where removed or added to the document.
                               This value is negative for deletions and positive for additions.