Sha256: dc6af796f9ffe44dd7264b333d26d01c26f808c1958467b2c670a271f352b464

Contents?: true

Size: 1.63 KB

Versions: 52

Compression:

Stored size: 1.63 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";

function lineIndent(cm, lineNo) {
  var text = cm.getLine(lineNo)
  var spaceTo = text.search(/\S/)
  if (spaceTo == -1 || /\bcomment\b/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, spaceTo + 1))))
    return -1
  return CodeMirror.countColumn(text, null, cm.getOption("tabSize"))
}

CodeMirror.registerHelper("fold", "indent", function(cm, start) {
  var myIndent = lineIndent(cm, start.line)
  if (myIndent < 0) return
  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 indent = lineIndent(cm, i)
    if (indent == -1) {
    } else if (indent > myIndent) {
      // Lines with a greater indent are considered part of the block.
      lastLineInFold = i;
    } else {
      // If this line has non-space, non-comment content, and is
      // indented less or equal to the start line, it is the start of
      // another block.
      break;
    }
  }
  if (lastLineInFold) return {
    from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
    to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
  };
});

});

Version data entries

52 entries across 26 versions & 3 rubygems

Version Path
keppler-2.1.22 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.22 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.21 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.21 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.20 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.20 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.19 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.19 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.18 testing-with-2.1.18/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.18 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.18 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.18 testing-with-2.1.18/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.17 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.17 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
stisla-rails-0.0.2 vendor/assets/modules/codemirror/addon/fold/indent-fold.js
keppler-2.1.16 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.16 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.15 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.15 installer/core/app/assets/javascripts/admin/codemirror/addon/fold/indent-fold.js
keppler-2.1.14 installer/core/app/assets/stylesheets/admin/codemirror/addon/fold/indent-fold.js