Sha256: b1e322dc5dc501a364379a317933b75b4787474aa11459e1c93910b1dfba7a7e

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

CodeMirror.registerHelper("fold", "indent", function(cm, start) {
  var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
  if (!/\S/.test(firstLine)) return;
  var getIndent = function(line) {
    return CodeMirror.countColumn(line, null, tabSize);
  };
  var myIndent = getIndent(firstLine);
  var lastLineInFold = null;
  // Go through lines until we find a line that definitely doesn't belong in
  // the block we're folding, or to the end.
  for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
    var curLine = cm.getLine(i);
    var curIndent = getIndent(curLine);
    if (curIndent > myIndent) {
      // Lines with a greater indent are considered part of the block.
      lastLineInFold = i;
    } else if (!/\S/.test(curLine)) {
      // Empty lines might be breaks within the block we're trying to fold.
    } else {
      // A non-empty line at an indent equal to or less than ours marks the
      // start of another block.
      break;
    }
  }
  if (lastLineInFold) return {
    from: CodeMirror.Pos(start.line, firstLine.length),
    to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
  };
});
CodeMirror.indentRangeFinder = CodeMirror.fold.indent; // deprecated

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
codemirror-rails-3.24 vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js
codemirror-rails-3.23 vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js
codemirror-rails-3.22 vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js
codemirror-rails-3.21 vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js