Sha256: 73b5e9c8f8aec0c843fe1914969cc165228e9938af11113932a8de9c073631f8

Contents?: true

Size: 1.59 KB

Versions: 81

Compression:

Stored size: 1.59 KB

Contents

// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE

(function(mod) {
  if (typeof exports == "object" && typeof module == "object") // CommonJS
    mod(require("../../lib/codemirror"));
  else if (typeof define == "function" && define.amd) // AMD
    define(["../../lib/codemirror"], mod);
  else // Plain browser env
    mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

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)
  };
});

});

Version data entries

81 entries across 81 versions & 10 rubygems

Version Path
locomotivecms-4.2.0.alpha2 vendor/assets/javascripts/locomotive/codemirror/addons/fold/indent-fold.js
locomotivecms-4.2.0.alpha1 vendor/assets/javascripts/locomotive/codemirror/addons/fold/indent-fold.js
scrivito_codemirror_editor-1.1.0 vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js
jeygeethanmedia-inkpen-1.2.6.2 public/codemirror/addon/fold/indent-fold.js
jeygeethanmedia-inkpen-1.2.6.1 public/codemirror/addon/fold/indent-fold.js
lines-engine-1.2.6.1 public/codemirror/addon/fold/indent-fold.js
lines-engine-1.2.6 public/codemirror/addon/fold/indent-fold.js
lines-engine-1.2.5 public/codemirror/addon/fold/indent-fold.js
kms-1.2.1 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js
kms-1.2.0 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js
kms-1.1.0 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js
lines-engine-1.2.3 public/codemirror/addon/fold/indent-fold.js
lines-engine-1.2.2 public/codemirror/addon/fold/indent-fold.js
kms-1.0.1 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js
kms-1.0.0 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js
lines-engine-1.2.1.1 public/codemirror/addon/fold/indent-fold.js
kms-0.9.0 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js
glebtv-ckeditor-4.6.0 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/fold/indent-fold.js
kms-0.8.0 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js
kms-0.7.0 vendor/assets/bower_components/codemirror/addon/fold/indent-fold.js