Sha256: 6360de3d099780d0062320d59f7ff264fbe0f4964e7f0a728ee44918eaf73458

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

CodeMirror.runMode = function(string, modespec, callback, options) {
  var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);

  if (callback.nodeType == 1) {
    var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
    var node = callback, col = 0;
    node.innerHTML = "";
    callback = function(text, style) {
      if (text == "\n") {
        node.appendChild(document.createElement("br"));
        col = 0;
        return;
      }
      var content = "";
      // replace tabs
      for (var pos = 0;;) {
        var idx = text.indexOf("\t", pos);
        if (idx == -1) {
          content += text.slice(pos);
          col += text.length - pos;
          break;
        } else {
          col += idx - pos;
          content += text.slice(pos, idx);
          var size = tabSize - col % tabSize;
          col += size;
          for (var i = 0; i < size; ++i) content += " ";
          pos = idx + 1;
        }
      }

      if (style) {
        var sp = node.appendChild(document.createElement("span"));
        sp.className = "cm-" + style.replace(/ +/g, " cm-");
        sp.appendChild(document.createTextNode(content));
      } else {
        node.appendChild(document.createTextNode(content));
      }
    };
  }

  var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
  for (var i = 0, e = lines.length; i < e; ++i) {
    if (i) callback("\n");
    var stream = new CodeMirror.StringStream(lines[i]);
    while (!stream.eol()) {
      var style = mode.token(stream, state);
      callback(stream.current(), style, i, stream.start);
      stream.start = stream.pos;
    }
  }
};

Version data entries

12 entries across 11 versions & 4 rubygems

Version Path
mdbe-0.1.0 public/libs/codemirror/addon/runmode/runmode.js
maglev-database-explorer-0.0.5 public/libs/codemirror/addon/runmode/runmode.js
maglev-database-explorer-0.0.4 public/libs/codemirror/addon/runmode/runmode.js
maglev-database-explorer-0.0.3 public/libs/codemirror/addon/runmode/runmode.js
maglev-database-explorer-0.0.2 public/libs/codemirror/addon/runmode/runmode.js
maglev-database-explorer-0.0.1 public/libs/codemirror/addon/runmode/runmode.js
codemirror-rails-3.12 vendor/assets/javascripts/codemirror/addons/runmode/runmode.js
codemirror-rails-3.02 vendor/assets/javascripts/codemirror/utils/runmode.js
swagr-0.0.10 examples/examples01/static/js/codemirror/lib/util/runmode.js
swagr-0.0.8 templates/static/js/codemirror/lib/util/runmode.js
swagr-0.0.8 examples/examples01/static/js/codemirror/lib/util/runmode.js
codemirror-rails-3.00 vendor/assets/javascripts/codemirror/utils/runmode.js