Changeset - 31f98c850623
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2012-11-27 22:48:28
marcin@python-works.com
updated codemirror version
2 files changed with 71 insertions and 42 deletions:
0 comments (0 inline, 0 general)
rhodecode/public/css/codemirror.css
Show inline comments
 
@@ -71,24 +71,25 @@
 
  -moz-border-radius: 0;
 
  -webkit-border-radius: 0;
 
  -o-border-radius: 0;
 
  border-radius: 0;
 
  border-width: 0; margin: 0; padding: 0; background: transparent;
 
  font-family: inherit;
 
  font-size: inherit;
 
  padding: 0; margin: 0;
 
  white-space: pre;
 
  word-wrap: normal;
 
  line-height: inherit;
 
  color: inherit;
 
  overflow: visible;
 
}
 

	
 
.CodeMirror-wrap pre {
 
  word-wrap: break-word;
 
  white-space: pre-wrap;
 
  word-break: normal;
 
}
 
.CodeMirror-wrap .CodeMirror-scroll {
 
  overflow-x: hidden;
 
}
 

	
 
.CodeMirror textarea {
rhodecode/public/js/codemirror.js
Show inline comments
 
@@ -66,25 +66,25 @@ window.CodeMirror = (function() {
 
    // mode holds a mode API object. doc is the tree of Line objects,
 
    // frontier is the point up to which the content has been parsed,
 
    // and history the undo history (instance of History constructor).
 
    var mode, doc = new BranchChunk([new LeafChunk([new Line("")])]), frontier = 0, focused;
 
    loadMode();
 
    // The selection. These are always maintained to point at valid
 
    // positions. Inverted is used to remember that the user is
 
    // selecting bottom-to-top.
 
    var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false};
 
    // Selection-related flags. shiftSelecting obviously tracks
 
    // whether the user is holding shift.
 
    var shiftSelecting, lastClick, lastDoubleClick, lastScrollTop = 0, draggingText,
 
        overwrite = false, suppressEdits = false;
 
        overwrite = false, suppressEdits = false, pasteIncoming = false;
 
    // Variables used by startOperation/endOperation to track what
 
    // happened during the operation.
 
    var updateInput, userSelChange, changes, textChanged, selectionChanged,
 
        gutterDirty, callbacks;
 
    // Current visible range (may be bigger than the view window).
 
    var displayOffset = 0, showingFrom = 0, showingTo = 0, lastSizeC = 0;
 
    // bracketHighlighted is used to remember that a bracket has been
 
    // marked.
 
    var bracketHighlighted;
 
    // Tracks the maximum line length so that the horizontal scrollbar
 
    // can be kept static when scrolling.
 
    var maxLine = getLine(0), updateMaxLine = false, maxLineChanged = true;
 
@@ -119,25 +119,25 @@ window.CodeMirror = (function() {
 

	
 
    function drag_(e) {
 
      if (options.onDragEvent && options.onDragEvent(instance, addStop(e))) return;
 
      e_stop(e);
 
    }
 
    if (options.dragDrop) {
 
      connect(scroller, "dragstart", onDragStart);
 
      connect(scroller, "dragenter", drag_);
 
      connect(scroller, "dragover", drag_);
 
      connect(scroller, "drop", operation(onDrop));
 
    }
 
    connect(scroller, "paste", function(){focusInput(); fastPoll();});
 
    connect(input, "paste", fastPoll);
 
    connect(input, "paste", function(){pasteIncoming = true; fastPoll();});
 
    connect(input, "cut", operation(function(){
 
      if (!options.readOnly) replaceSelection("");
 
    }));
 

	
 
    // Needed to handle Tab key in KHTML
 
    if (khtml) connect(sizer, "mouseup", function() {
 
        if (document.activeElement == input) input.blur();
 
        focusInput();
 
    });
 

	
 
    // IE throws unspecified error in certain cases, when
 
    // trying to access activeElement before onload
 
@@ -158,24 +158,25 @@ window.CodeMirror = (function() {
 
      replaceSelection: operation(replaceSelection),
 
      focus: function(){window.focus(); focusInput(); onFocus(); fastPoll();},
 
      setOption: function(option, value) {
 
        var oldVal = options[option];
 
        options[option] = value;
 
        if (option == "mode" || option == "indentUnit") loadMode();
 
        else if (option == "readOnly" && value == "nocursor") {onBlur(); input.blur();}
 
        else if (option == "readOnly" && !value) {resetInput(true);}
 
        else if (option == "theme") themeChanged();
 
        else if (option == "lineWrapping" && oldVal != value) operation(wrappingChanged)();
 
        else if (option == "tabSize") updateDisplay(true);
 
        else if (option == "keyMap") keyMapChanged();
 
        else if (option == "tabindex") input.tabIndex = value;
 
        if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber" ||
 
            option == "theme" || option == "lineNumberFormatter") {
 
          gutterChanged();
 
          updateDisplay(true);
 
        }
 
      },
 
      getOption: function(option) {return options[option];},
 
      getMode: function() {return mode;},
 
      undo: operation(undo),
 
      redo: operation(redo),
 
      indentLine: operation(function(n, dir) {
 
        if (typeof dir != "string") {
 
@@ -220,24 +221,25 @@ window.CodeMirror = (function() {
 
        return this.charCoords(start ? sel.from : sel.to, mode);
 
      },
 
      charCoords: function(pos, mode) {
 
        pos = clipPos(pos);
 
        if (mode == "local") return localCoords(pos, false);
 
        if (mode == "div") return localCoords(pos, true);
 
        return pageCoords(pos);
 
      },
 
      coordsChar: function(coords) {
 
        var off = eltOffset(lineSpace);
 
        return coordsChar(coords.x - off.left, coords.y - off.top);
 
      },
 
      defaultTextHeight: function() { return textHeight(); },
 
      markText: operation(markText),
 
      setBookmark: setBookmark,
 
      findMarksAt: findMarksAt,
 
      setMarker: operation(addGutterMarker),
 
      clearMarker: operation(removeGutterMarker),
 
      setLineClass: operation(setLineClass),
 
      hideLine: operation(function(h) {return setLineHidden(h, true);}),
 
      showLine: operation(function(h) {return setLineHidden(h, false);}),
 
      onDeleteLine: function(line, f) {
 
        if (typeof line == "number") {
 
          if (!isLine(line)) return null;
 
          line = getLine(line);
 
@@ -334,24 +336,29 @@ window.CodeMirror = (function() {
 
        });
 
        return index;
 
      },
 
      scrollTo: function(x, y) {
 
        if (x != null) scroller.scrollLeft = x;
 
        if (y != null) scrollbar.scrollTop = scroller.scrollTop = y;
 
        updateDisplay([]);
 
      },
 
      getScrollInfo: function() {
 
        return {x: scroller.scrollLeft, y: scrollbar.scrollTop,
 
                height: scrollbar.scrollHeight, width: scroller.scrollWidth};
 
      },
 
      scrollIntoView: function(pos) {
 
        var coords = localCoords(pos ? clipPos(pos) : sel.inverted ? sel.from : sel.to);
 
        scrollIntoView(coords.x, coords.y, coords.x, coords.yBot);
 
      },
 

	
 
      setSize: function(width, height) {
 
        function interpret(val) {
 
          val = String(val);
 
          return /^\d+$/.test(val) ? val + "px" : val;
 
        }
 
        if (width != null) wrapper.style.width = interpret(width);
 
        if (height != null) scroller.style.height = interpret(height);
 
        instance.refresh();
 
      },
 

	
 
      operation: function(f){return operation(f)();},
 
      compoundChange: function(f){return compoundChange(f);},
 
@@ -383,34 +390,34 @@ window.CodeMirror = (function() {
 
      var top = {line: 0, ch: 0};
 
      updateLines(top, {line: doc.size - 1, ch: getLine(doc.size-1).text.length},
 
                  splitLines(code), top, top);
 
      updateInput = true;
 
    }
 
    function getValue(lineSep) {
 
      var text = [];
 
      doc.iter(0, doc.size, function(line) { text.push(line.text); });
 
      return text.join(lineSep || "\n");
 
    }
 

	
 
    function onScrollBar(e) {
 
      if (scrollbar.scrollTop != lastScrollTop) {
 
      if (Math.abs(scrollbar.scrollTop - lastScrollTop) > 1) {
 
        lastScrollTop = scroller.scrollTop = scrollbar.scrollTop;
 
        updateDisplay([]);
 
      }
 
    }
 

	
 
    function onScrollMain(e) {
 
      if (options.fixedGutter && gutter.style.left != scroller.scrollLeft + "px")
 
        gutter.style.left = scroller.scrollLeft + "px";
 
      if (scroller.scrollTop != lastScrollTop) {
 
      if (Math.abs(scroller.scrollTop - lastScrollTop) > 1) {
 
        lastScrollTop = scroller.scrollTop;
 
        if (scrollbar.scrollTop != lastScrollTop)
 
          scrollbar.scrollTop = lastScrollTop;
 
        updateDisplay([]);
 
      }
 
      if (options.onScroll) options.onScroll(instance);
 
    }
 

	
 
    function onMouseDown(e) {
 
      setShift(e_prop(e, "shiftKey"));
 
      // Check whether this is a click in a widget
 
      for (var n = e_target(e); n != wrapper; n = n.parentNode)
 
@@ -625,25 +632,25 @@ window.CodeMirror = (function() {
 
        handled = lookupKey("Shift-" + name, options.extraKeys, options.keyMap,
 
                            function(b) {return doHandleBinding(b, true);}, stop)
 
               || lookupKey(name, options.extraKeys, options.keyMap, function(b) {
 
                 if (typeof b == "string" && /^go[A-Z]/.test(b)) return doHandleBinding(b);
 
               }, stop);
 
      } else {
 
        handled = lookupKey(name, options.extraKeys, options.keyMap, doHandleBinding, stop);
 
      }
 
      if (stopped) handled = false;
 
      if (handled) {
 
        e_preventDefault(e);
 
        restartBlink();
 
        if (ie) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
 
        if (ie_lt9) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
 
      }
 
      return handled;
 
    }
 
    function handleCharBinding(e, ch) {
 
      var handled = lookupKey("'" + ch + "'", options.extraKeys,
 
                              options.keyMap, function(b) { return doHandleBinding(b, true); });
 
      if (handled) {
 
        e_preventDefault(e);
 
        restartBlink();
 
      }
 
      return handled;
 
    }
 
@@ -945,30 +952,31 @@ window.CodeMirror = (function() {
 
    // supported or compatible enough yet to rely on.)
 
    var prevInput = "";
 
    function readInput() {
 
      if (!focused || hasSelection(input) || options.readOnly) return false;
 
      var text = input.value;
 
      if (text == prevInput) return false;
 
      if (!nestedOperation) startOperation();
 
      shiftSelecting = null;
 
      var same = 0, l = Math.min(prevInput.length, text.length);
 
      while (same < l && prevInput[same] == text[same]) ++same;
 
      if (same < prevInput.length)
 
        sel.from = {line: sel.from.line, ch: sel.from.ch - (prevInput.length - same)};
 
      else if (overwrite && posEq(sel.from, sel.to))
 
      else if (overwrite && posEq(sel.from, sel.to) && !pasteIncoming)
 
        sel.to = {line: sel.to.line, ch: Math.min(getLine(sel.to.line).text.length, sel.to.ch + (text.length - same))};
 
      replaceSelection(text.slice(same), "end");
 
      if (text.length > 1000) { input.value = prevInput = ""; }
 
      else prevInput = text;
 
      if (!nestedOperation) endOperation();
 
      pasteIncoming = false;
 
      return true;
 
    }
 
    function resetInput(user) {
 
      if (!posEq(sel.from, sel.to)) {
 
        prevInput = "";
 
        input.value = getSelection();
 
        if (focused) selectInput(input);
 
      } else if (user) prevInput = input.value = "";
 
    }
 

	
 
    function focusInput() {
 
      if (options.readOnly != "nocursor") input.focus();
 
@@ -1407,25 +1415,25 @@ window.CodeMirror = (function() {
 
      setCursor(target.line, target.ch, true);
 
      goalColumn = pos.x;
 
    }
 

	
 
    function findWordAt(pos) {
 
      var line = getLine(pos.line).text;
 
      var start = pos.ch, end = pos.ch;
 
      if (line) {
 
        if (pos.after === false || end == line.length) --start; else ++end;
 
        var startChar = line.charAt(start);
 
        var check = isWordChar(startChar) ? isWordChar :
 
                    /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);} :
 
                    function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
 
                    function(ch) {return !/\s/.test(ch) && isWordChar(ch);};
 
        while (start > 0 && check(line.charAt(start - 1))) --start;
 
        while (end < line.length && check(line.charAt(end))) ++end;
 
      }
 
      return {from: {line: pos.line, ch: start}, to: {line: pos.line, ch: end}};
 
    }
 
    function selectLine(line) {
 
      setSelectionUser({line: line, ch: 0}, clipPos({line: line + 1, ch: 0}));
 
    }
 
    function indentSelected(mode) {
 
      if (posEq(sel.from, sel.to)) return indentLine(sel.from.line, mode);
 
      var e = sel.to.line - (sel.to.ch ? 0 : 1);
 
      for (var i = sel.from.line; i <= e; ++i) indentLine(i, mode);
 
@@ -1451,24 +1459,25 @@ window.CodeMirror = (function() {
 
      else if (how == "add") indentation = curSpace + options.indentUnit;
 
      else if (how == "subtract") indentation = curSpace - options.indentUnit;
 
      indentation = Math.max(0, indentation);
 
      var diff = indentation - curSpace;
 

	
 
      var indentString = "", pos = 0;
 
      if (options.indentWithTabs)
 
        for (var i = Math.floor(indentation / options.tabSize); i; --i) {pos += options.tabSize; indentString += "\t";}
 
      if (pos < indentation) indentString += spaceStr(indentation - pos);
 

	
 
      if (indentString != curSpaceString)
 
        replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
 
      line.stateAfter = null;
 
    }
 

	
 
    function loadMode() {
 
      mode = CodeMirror.getMode(options, options.mode);
 
      doc.iter(0, doc.size, function(line) { line.stateAfter = null; });
 
      frontier = 0;
 
      startWorker(100);
 
    }
 
    function gutterChanged() {
 
      var visible = options.gutter || options.lineNumbers;
 
      gutter.style.display = visible ? "" : "none";
 
      if (visible) gutterDirty = true;
 
@@ -1496,36 +1505,35 @@ window.CodeMirror = (function() {
 
    function themeChanged() {
 
      scroller.className = scroller.className.replace(/\s*cm-s-\S+/g, "") +
 
        options.theme.replace(/(^|\s)\s*/g, " cm-s-");
 
    }
 
    function keyMapChanged() {
 
      var style = keyMap[options.keyMap].style;
 
      wrapper.className = wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
 
        (style ? " cm-keymap-" + style : "");
 
    }
 

	
 
    function TextMarker(type, style) { this.lines = []; this.type = type; if (style) this.style = style; }
 
    TextMarker.prototype.clear = operation(function() {
 
      var min = Infinity, max = -Infinity;
 
      var min, max;
 
      for (var i = 0; i < this.lines.length; ++i) {
 
        var line = this.lines[i];
 
        var span = getMarkedSpanFor(line.markedSpans, this, true);
 
        if (span.from != null || span.to != null) {
 
          var lineN = lineNo(line);
 
          min = Math.min(min, lineN); max = Math.max(max, lineN);
 
        }
 
        var span = getMarkedSpanFor(line.markedSpans, this);
 
        if (span.from != null) min = lineNo(line);
 
        if (span.to != null) max = lineNo(line);
 
        line.markedSpans = removeMarkedSpan(line.markedSpans, span);
 
      }
 
      if (min != Infinity)
 
        changes.push({from: min, to: max + 1});
 
      if (min != null) changes.push({from: min, to: max + 1});
 
      this.lines.length = 0;
 
      this.explicitlyCleared = true;
 
    });
 
    TextMarker.prototype.find = function() {
 
      var from, to;
 
      for (var i = 0; i < this.lines.length; ++i) {
 
        var line = this.lines[i];
 
        var span = getMarkedSpanFor(line.markedSpans, this);
 
        if (span.from != null || span.to != null) {
 
          var found = lineNo(line);
 
          if (span.from != null) from = {line: found, ch: span.from};
 
          if (span.to != null) to = {line: found, ch: span.to};
 
        }
 
      }
 
@@ -1534,37 +1542,38 @@ window.CodeMirror = (function() {
 
    };
 

	
 
    function markText(from, to, className, options) {
 
      from = clipPos(from); to = clipPos(to);
 
      var marker = new TextMarker("range", className);
 
      if (options) for (var opt in options) if (options.hasOwnProperty(opt))
 
        marker[opt] = options[opt];
 
      var curLine = from.line;
 
      doc.iter(curLine, to.line + 1, function(line) {
 
        var span = {from: curLine == from.line ? from.ch : null,
 
                    to: curLine == to.line ? to.ch : null,
 
                    marker: marker};
 
        (line.markedSpans || (line.markedSpans = [])).push(span);
 
        line.markedSpans = (line.markedSpans || []).concat([span]);
 
        marker.lines.push(line);
 
        ++curLine;
 
      });
 
      changes.push({from: from.line, to: to.line + 1});
 
      return marker;
 
    }
 

	
 
    function setBookmark(pos) {
 
      pos = clipPos(pos);
 
      var marker = new TextMarker("bookmark"), line = getLine(pos.line);
 
      history.addChange(pos.line, 1, [newHL(line.text, line.markedSpans)], true);
 
      var span = {from: pos.ch, to: pos.ch, marker: marker};
 
      (line.markedSpans || (line.markedSpans = [])).push(span);
 
      line.markedSpans = (line.markedSpans || []).concat([span]);
 
      marker.lines.push(line);
 
      return marker;
 
    }
 

	
 
    function findMarksAt(pos) {
 
      pos = clipPos(pos);
 
      var markers = [], spans = getLine(pos.line).markedSpans;
 
      if (spans) for (var i = 0; i < spans.length; ++i) {
 
        var span = spans[i];
 
        if ((span.from == null || span.from <= pos.ch) &&
 
            (span.to == null || span.to >= pos.ch))
 
          markers.push(span.marker);
 
@@ -1635,26 +1644,24 @@ window.CodeMirror = (function() {
 
        if (!line) return null;
 
      } else {
 
        var n = lineNo(line);
 
        if (n == null) return null;
 
      }
 
      var marker = line.gutterMarker;
 
      return {line: n, handle: line, text: line.text, markerText: marker && marker.text,
 
              markerClass: marker && marker.style, lineClass: line.className, bgClass: line.bgClassName};
 
    }
 

	
 
    function measureLine(line, ch) {
 
      if (ch == 0) return {top: 0, left: 0};
 
      var wbr = options.lineWrapping && ch < line.text.length &&
 
                spanAffectsWrapping.test(line.text.slice(ch - 1, ch + 1));
 
      var pre = lineContent(line, ch);
 
      removeChildrenAndAdd(measure, pre);
 
      var anchor = pre.anchor;
 
      var top = anchor.offsetTop, left = anchor.offsetLeft;
 
      // Older IEs report zero offsets for spans directly after a wrap
 
      if (ie && top == 0 && left == 0) {
 
        var backup = elt("span", "x");
 
        anchor.parentNode.insertBefore(backup, anchor.nextSibling);
 
        top = backup.offsetTop;
 
      }
 
      return {top: top, left: left};
 
    }
 
@@ -1969,24 +1976,25 @@ window.CodeMirror = (function() {
 
      };
 
    }
 

	
 
    function compoundChange(f) {
 
      history.startCompound();
 
      try { return f(); } finally { history.endCompound(); }
 
    }
 

	
 
    for (var ext in extensions)
 
      if (extensions.propertyIsEnumerable(ext) &&
 
          !instance.propertyIsEnumerable(ext))
 
        instance[ext] = extensions[ext];
 
    for (var i = 0; i < initHooks.length; ++i) initHooks[i](instance);
 
    return instance;
 
  } // (end of function CodeMirror)
 

	
 
  // The default configuration options.
 
  CodeMirror.defaults = {
 
    value: "",
 
    mode: null,
 
    theme: "default",
 
    indentUnit: 2,
 
    indentWithTabs: false,
 
    smartIndent: true,
 
    tabSize: 4,
 
@@ -2066,24 +2074,27 @@ window.CodeMirror = (function() {
 
  CodeMirror.listMIMEs = function() {
 
    var list = [];
 
    for (var m in mimeModes)
 
      if (mimeModes.propertyIsEnumerable(m)) list.push({mime: m, mode: mimeModes[m]});
 
    return list;
 
  };
 

	
 
  var extensions = CodeMirror.extensions = {};
 
  CodeMirror.defineExtension = function(name, func) {
 
    extensions[name] = func;
 
  };
 

	
 
  var initHooks = [];
 
  CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
 

	
 
  var modeExtensions = CodeMirror.modeExtensions = {};
 
  CodeMirror.extendMode = function(mode, properties) {
 
    var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
 
    for (var prop in properties) if (properties.hasOwnProperty(prop))
 
      exts[prop] = properties[prop];
 
  };
 

	
 
  var commands = CodeMirror.commands = {
 
    selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});},
 
    killLine: function(cm) {
 
      var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
 
      if (!sel && cm.getLine(from.line).length == from.ch) cm.replaceRange("", from, {line: from.line + 1, ch: 0});
 
@@ -2158,25 +2169,25 @@ window.CodeMirror = (function() {
 
    "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
 
    "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft",
 
    "Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordLeft",
 
    "Ctrl-Alt-Backspace": "delWordRight", "Alt-Delete": "delWordRight", "Cmd-S": "save", "Cmd-F": "find",
 
    "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
 
    "Cmd-[": "indentLess", "Cmd-]": "indentMore",
 
    fallthrough: ["basic", "emacsy"]
 
  };
 
  keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
 
  keyMap.emacsy = {
 
    "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
 
    "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
 
    "Ctrl-V": "goPageUp", "Shift-Ctrl-V": "goPageDown", "Ctrl-D": "delCharRight", "Ctrl-H": "delCharLeft",
 
    "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharRight", "Ctrl-H": "delCharLeft",
 
    "Alt-D": "delWordRight", "Alt-Backspace": "delWordLeft", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
 
  };
 

	
 
  function getKeyMap(val) {
 
    if (typeof val == "string") return keyMap[val];
 
    else return val;
 
  }
 
  function lookupKey(name, extraMap, map, handle, stop) {
 
    function lookup(map) {
 
      map = getKeyMap(map);
 
      var found = map[name];
 
      if (found === false) {
 
@@ -2195,53 +2206,52 @@ window.CodeMirror = (function() {
 
      for (var i = 0, e = fallthrough.length; i < e; ++i) {
 
        if (lookup(fallthrough[i])) return true;
 
      }
 
      return false;
 
    }
 
    if (extraMap && lookup(extraMap)) return true;
 
    return lookup(map);
 
  }
 
  function isModifierKey(event) {
 
    var name = keyNames[e_prop(event, "keyCode")];
 
    return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
 
  }
 
  CodeMirror.isModifierKey = isModifierKey;
 

	
 
  CodeMirror.fromTextArea = function(textarea, options) {
 
    if (!options) options = {};
 
    options.value = textarea.value;
 
    if (!options.tabindex && textarea.tabindex)
 
      options.tabindex = textarea.tabindex;
 
    // Set autofocus to true if this textarea is focused, or if it has
 
    // autofocus and no other element is focused.
 
    if (options.autofocus == null) {
 
      var hasFocus = document.body;
 
      // doc.activeElement occasionally throws on IE
 
      try { hasFocus = document.activeElement; } catch(e) {}
 
      options.autofocus = hasFocus == textarea ||
 
        textarea.getAttribute("autofocus") != null && hasFocus == document.body;
 
    }
 

	
 
    function save() {textarea.value = instance.getValue();}
 
    if (textarea.form) {
 
      // Deplorable hack to make the submit method do the right thing.
 
      var rmSubmit = connect(textarea.form, "submit", save, true);
 
      if (typeof textarea.form.submit == "function") {
 
        var realSubmit = textarea.form.submit;
 
        textarea.form.submit = function wrappedSubmit() {
 
          save();
 
          textarea.form.submit = realSubmit;
 
          textarea.form.submit();
 
          textarea.form.submit = wrappedSubmit;
 
        };
 
      }
 
      var realSubmit = textarea.form.submit;
 
      textarea.form.submit = function wrappedSubmit() {
 
        save();
 
        textarea.form.submit = realSubmit;
 
        textarea.form.submit();
 
        textarea.form.submit = wrappedSubmit;
 
      };
 
    }
 

	
 
    textarea.style.display = "none";
 
    var instance = CodeMirror(function(node) {
 
      textarea.parentNode.insertBefore(node, textarea.nextSibling);
 
    }, options);
 
    instance.save = save;
 
    instance.getTextArea = function() { return textarea; };
 
    instance.toTextArea = function() {
 
      save();
 
      textarea.parentNode.removeChild(instance.getWrapperElement());
 
      textarea.style.display = "";
 
@@ -2344,34 +2354,38 @@ window.CodeMirror = (function() {
 
        if (match && consume !== false) this.pos += match[0].length;
 
        return match;
 
      }
 
    },
 
    current: function(){return this.string.slice(this.start, this.pos);}
 
  };
 
  CodeMirror.StringStream = StringStream;
 

	
 
  function MarkedSpan(from, to, marker) {
 
    this.from = from; this.to = to; this.marker = marker;
 
  }
 

	
 
  function getMarkedSpanFor(spans, marker, del) {
 
  function getMarkedSpanFor(spans, marker) {
 
    if (spans) for (var i = 0; i < spans.length; ++i) {
 
      var span = spans[i];
 
      if (span.marker == marker) {
 
        if (del) spans.splice(i, 1);
 
        return span;
 
      }
 
      if (span.marker == marker) return span;
 
    }
 
  }
 

	
 
  function removeMarkedSpan(spans, span) {
 
    var r;
 
    for (var i = 0; i < spans.length; ++i)
 
      if (spans[i] != span) (r || (r = [])).push(spans[i]);
 
    return r;
 
  }
 

	
 
  function markedSpansBefore(old, startCh, endCh) {
 
    if (old) for (var i = 0, nw; i < old.length; ++i) {
 
      var span = old[i], marker = span.marker;
 
      var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
 
      if (startsBefore || marker.type == "bookmark" && span.from == startCh && span.from != endCh) {
 
        var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
 
        (nw || (nw = [])).push({from: span.from,
 
                                to: endsAfter ? null : span.to,
 
                                marker: marker});
 
      }
 
    }
 
    return nw;
 
@@ -2437,25 +2451,33 @@ window.CodeMirror = (function() {
 
          if (first[i].to == null)
 
            (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
 
      for (var i = 0; i < gap; ++i)
 
        newMarkers.push(newHL(newText[i+1], gapMarkers));
 
      newMarkers.push(newHL(lst(newText), last));
 
    }
 
    return newMarkers;
 
  }
 

	
 
  // hl stands for history-line, a data structure that can be either a
 
  // string (line without markers) or a {text, markedSpans} object.
 
  function hlText(val) { return typeof val == "string" ? val : val.text; }
 
  function hlSpans(val) { return typeof val == "string" ? null : val.markedSpans; }
 
  function hlSpans(val) {
 
    if (typeof val == "string") return null;
 
    var spans = val.markedSpans, out = null;
 
    for (var i = 0; i < spans.length; ++i) {
 
      if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
 
      else if (out) out.push(spans[i]);
 
    }
 
    return !out ? spans : out.length ? out : null;
 
  }
 
  function newHL(text, spans) { return spans ? {text: text, markedSpans: spans} : text; }
 

	
 
  function detachMarkedSpans(line) {
 
    var spans = line.markedSpans;
 
    if (!spans) return;
 
    for (var i = 0; i < spans.length; ++i) {
 
      var lines = spans[i].marker.lines;
 
      var ix = indexOf(lines, line);
 
      lines.splice(ix, 1);
 
    }
 
    line.markedSpans = null;
 
  }
 
@@ -2573,31 +2595,35 @@ window.CodeMirror = (function() {
 
            }
 
          }
 
        }
 
        if (style) html.appendChild(elt("span", [content], style));
 
        else html.appendChild(content);
 
      }
 
      var span = span_;
 
      if (wrapAt != null) {
 
        var outPos = 0, anchor = pre.anchor = elt("span");
 
        span = function(html, text, style) {
 
          var l = text.length;
 
          if (wrapAt >= outPos && wrapAt < outPos + l) {
 
            if (wrapAt > outPos) {
 
              span_(html, text.slice(0, wrapAt - outPos), style);
 
            var cut = wrapAt - outPos;
 
            if (cut) {
 
              span_(html, text.slice(0, cut), style);
 
              // See comment at the definition of spanAffectsWrapping
 
              if (compensateForWrapping) html.appendChild(elt("wbr"));
 
              if (compensateForWrapping) {
 
                var view = text.slice(cut - 1, cut + 1);
 
                if (spanAffectsWrapping.test(view)) html.appendChild(elt("wbr"));
 
                else if (!ie_lt8 && /\w\w/.test(view)) html.appendChild(document.createTextNode("\u200d"));
 
              }
 
            }
 
            html.appendChild(anchor);
 
            var cut = wrapAt - outPos;
 
            span_(anchor, opera ? text.slice(cut, cut + 1) : text.slice(cut), style);
 
            if (opera) span_(html, text.slice(cut + 1), style);
 
            wrapAt--;
 
            outPos += l;
 
          } else {
 
            outPos += l;
 
            span_(html, text, style);
 
            if (outPos == wrapAt && outPos == len) {
 
              setTextContent(anchor, eolSpanContent);
 
              html.appendChild(anchor);
 
            }
 
            // Stop outputting HTML when gone sufficiently far beyond measure
 
@@ -2863,25 +2889,25 @@ window.CodeMirror = (function() {
 
  function History() {
 
    this.time = 0;
 
    this.done = []; this.undone = [];
 
    this.compound = 0;
 
    this.closed = false;
 
  }
 
  History.prototype = {
 
    addChange: function(start, added, old) {
 
      this.undone.length = 0;
 
      var time = +new Date, cur = lst(this.done), last = cur && lst(cur);
 
      var dtime = time - this.time;
 

	
 
      if (this.compound && cur && !this.closed) {
 
      if (cur && !this.closed && this.compound) {
 
        cur.push({start: start, added: added, old: old});
 
      } else if (dtime > 400 || !last || this.closed ||
 
                 last.start > start + old.length || last.start + last.added < start) {
 
        this.done.push([{start: start, added: added, old: old}]);
 
        this.closed = false;
 
      } else {
 
        var startBefore = Math.max(0, last.start - start),
 
            endAfter = Math.max(0, (start + old.length) - (last.start + last.added));
 
        for (var i = startBefore; i > 0; --i) last.old.unshift(old[i - 1]);
 
        for (var i = endAfter; i > 0; --i) last.old.push(old[old.length - i]);
 
        if (startBefore) last.start = start;
 
        last.added += added - (old.length - startBefore - endAfter);
 
@@ -3069,26 +3095,28 @@ window.CodeMirror = (function() {
 
    if (!from) return to.length;
 
    for (var i = from.length, j = to.length; i >= 0 && j >= 0; --i, --j)
 
      if (from.charAt(i) != to.charAt(j)) break;
 
    return j + 1;
 
  }
 

	
 
  function indexOf(collection, elt) {
 
    if (collection.indexOf) return collection.indexOf(elt);
 
    for (var i = 0, e = collection.length; i < e; ++i)
 
      if (collection[i] == elt) return i;
 
    return -1;
 
  }
 
  var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc]/;
 
  function isWordChar(ch) {
 
    return /\w/.test(ch) || ch.toUpperCase() != ch.toLowerCase();
 
    return /\w/.test(ch) || ch > "\x80" &&
 
      (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
 
  }
 

	
 
  // See if "".split is the broken IE version, if so, provide an
 
  // alternative way to split lines.
 
  var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
 
    var pos = 0, result = [], l = string.length;
 
    while (pos <= l) {
 
      var nl = string.indexOf("\n", pos);
 
      if (nl == -1) nl = string.length;
 
      var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
 
      var rt = line.indexOf("\r");
 
      if (rt != -1) {
 
@@ -3126,16 +3154,16 @@ window.CodeMirror = (function() {
 
                  221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home",
 
                  63234: "Left", 63232: "Up", 63235: "Right", 63233: "Down", 63302: "Insert", 63272: "Delete"};
 
  CodeMirror.keyNames = keyNames;
 
  (function() {
 
    // Number keys
 
    for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
 
    // Alphabetic keys
 
    for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
 
    // Function keys
 
    for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
 
  })();
 

	
 
  CodeMirror.version = "2.34";
 
  CodeMirror.version = "2.36";
 

	
 
  return CodeMirror;
 
})();
0 comments (0 inline, 0 general)