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
 
@@ -59,48 +59,49 @@
 
  text-align: right;
 
  padding: .4em .2em .4em .4em;
 
  white-space: pre !important;
 
  cursor: default;
 
}
 
.CodeMirror-lines {
 
  padding: .4em;
 
  white-space: pre;
 
  cursor: text;
 
}
 

	
 
.CodeMirror pre {
 
  -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 {
 
  outline: none !important;
 
}
 

	
 
.CodeMirror pre.CodeMirror-cursor {
 
  z-index: 10;
 
  position: absolute;
 
  visibility: hidden;
 
  border-left: 1px solid black;
 
  border-right: none;
 
  width: 0;
 
}
 
.cm-keymap-fat-cursor pre.CodeMirror-cursor {
rhodecode/public/js/codemirror.js
Show inline comments
 
@@ -54,49 +54,49 @@ window.CodeMirror = (function() {
 

	
 
    // Check for OS X >= 10.7. This has transparent scrollbars, so the
 
    // overlaying of one scrollbar with another won't work. This is a
 
    // temporary hack to simply turn off the overlay scrollbar. See
 
    // issue #727.
 
    if (mac_geLion) { scrollbar.style.zIndex = -2; scrollbar.style.visibility = "hidden"; }
 
    // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
 
    else if (ie_lt8) scrollbar.style.minWidth = "18px";
 

	
 
    // Delayed object wrap timeouts, making sure only one is active. blinker holds an interval.
 
    var poll = new Delayed(), highlight = new Delayed(), blinker;
 

	
 
    // 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;
 
    var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll
 
    var goalColumn = null;
 

	
 
    // Initialize the content.
 
    operation(function(){setValue(options.value || ""); updateInput = false;})();
 
    var history = new History();
 

	
 
    // Register our event handlers.
 
    connect(scroller, "mousedown", operation(onMouseDown));
 
    connect(scroller, "dblclick", operation(onDoubleClick));
 
    connect(lineSpace, "selectstart", e_preventDefault);
 
    // Gecko browsers fire contextmenu *after* opening the menu, at
 
@@ -107,87 +107,88 @@ window.CodeMirror = (function() {
 
    connect(scrollbar, "scroll", onScrollBar);
 
    connect(scrollbar, "mousedown", function() {if (focused) setTimeout(focusInput, 0);});
 
    var resizeHandler = connect(window, "resize", function() {
 
      if (wrapper.parentNode) updateDisplay(true);
 
      else resizeHandler();
 
    }, true);
 
    connect(input, "keyup", operation(onKeyUp));
 
    connect(input, "input", fastPoll);
 
    connect(input, "keydown", operation(onKeyDown));
 
    connect(input, "keypress", operation(onKeyPress));
 
    connect(input, "focus", onFocus);
 
    connect(input, "blur", onBlur);
 

	
 
    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
 
    var hasFocus; try { hasFocus = (document.activeElement == input); } catch(e) { }
 
    if (hasFocus || options.autofocus) setTimeout(onFocus, 20);
 
    else onBlur();
 

	
 
    function isLine(l) {return l >= 0 && l < doc.size;}
 
    // The instance object that we'll return. Mostly calls out to
 
    // local functions in the CodeMirror function. Some do some extra
 
    // range checking and/or clipping. operation is used to wrap the
 
    // call so that changes it makes are tracked, and the display is
 
    // updated afterwards.
 
    var instance = wrapper.CodeMirror = {
 
      getValue: getValue,
 
      setValue: operation(setValue),
 
      getSelection: getSelection,
 
      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") {
 
          if (dir == null) dir = options.smartIndent ? "smart" : "prev";
 
          else dir = dir ? "add" : "subtract";
 
        }
 
        if (isLine(n)) indentLine(n, dir);
 
      }),
 
      indentSelection: operation(indentSelected),
 
      historySize: function() {return {undo: history.done.length, redo: history.undone.length};},
 
      clearHistory: function() {history = new History();},
 
      setHistory: function(histData) {
 
        history = new History();
 
        history.done = histData.done;
 
        history.undone = histData.undone;
 
@@ -208,48 +209,49 @@ window.CodeMirror = (function() {
 
      },
 
      matchBrackets: operation(function(){matchBrackets(true);}),
 
      getTokenAt: operation(function(pos) {
 
        pos = clipPos(pos);
 
        return getLine(pos.line).getTokenAt(mode, getStateBefore(pos.line), options.tabSize, pos.ch);
 
      }),
 
      getStateAfter: function(line) {
 
        line = clipLine(line == null ? doc.size - 1: line);
 
        return getStateBefore(line + 1);
 
      },
 
      cursorCoords: function(start, mode) {
 
        if (start == null) start = sel.inverted;
 
        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);
 
        }
 
        (line.handlers || (line.handlers = [])).push(f);
 
        return line;
 
      },
 
      lineInfo: lineInfo,
 
      getViewport: function() { return {from: showingFrom, to: showingTo};},
 
      addWidget: function(pos, node, scroll, vert, horiz) {
 
        pos = localCoords(clipPos(pos));
 
        var top = pos.yBot, left = pos.x;
 
        node.style.position = "absolute";
 
        sizer.appendChild(node);
 
        if (vert == "over") top = pos.y;
 
@@ -322,48 +324,53 @@ window.CodeMirror = (function() {
 
          var sz = line.text.length + 1;
 
          if (sz > off) { ch = off; return true; }
 
          off -= sz;
 
          ++lineNo;
 
        });
 
        return clipPos({line: lineNo, ch: ch});
 
      },
 
      indexFromPos: function (coords) {
 
        if (coords.line < 0 || coords.ch < 0) return 0;
 
        var index = coords.ch;
 
        doc.iter(0, coords.line, function (line) {
 
          index += line.text.length + 1;
 
        });
 
        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);},
 
      refresh: function(){
 
        updateDisplay(true, null, lastScrollTop);
 
        if (scrollbar.scrollHeight > lastScrollTop)
 
          scrollbar.scrollTop = lastScrollTop;
 
      },
 
      getInputField: function(){return input;},
 
      getWrapperElement: function(){return wrapper;},
 
      getScrollerElement: function(){return scroller;},
 
      getGutterElement: function(){return gutter;}
 
    };
 

	
 
    function getLine(n) { return getLineAt(doc, n); }
 
@@ -371,58 +378,58 @@ window.CodeMirror = (function() {
 
      gutterDirty = true;
 
      var diff = height - line.height;
 
      for (var n = line; n; n = n.parent) n.height += diff;
 
    }
 

	
 
    function lineContent(line, wrapAt) {
 
      if (!line.styles)
 
        line.highlight(mode, line.stateAfter = getStateBefore(lineNo(line)), options.tabSize);
 
      return line.getContent(options.tabSize, wrapAt, options.lineWrapping);
 
    }
 

	
 
    function setValue(code) {
 
      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)
 
        if (n.parentNode == sizer && n != mover) return;
 

	
 
      // See if this is a click in the gutter
 
      for (var n = e_target(e); n != wrapper; n = n.parentNode)
 
        if (n.parentNode == gutterText) {
 
          if (options.onGutterClick)
 
            options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom, e);
 
          return e_preventDefault(e);
 
        }
 

	
 
      var start = posFromMouse(e);
 

	
 
@@ -613,49 +620,49 @@ window.CodeMirror = (function() {
 

	
 
      var name = keyNames[e_prop(e, "keyCode")], handled = false;
 
      var flipCtrlCmd = opera && mac;
 
      if (name == null || e.altGraphKey) return false;
 
      if (e_prop(e, "altKey")) name = "Alt-" + name;
 
      if (e_prop(e, flipCtrlCmd ? "metaKey" : "ctrlKey")) name = "Ctrl-" + name;
 
      if (e_prop(e, flipCtrlCmd ? "ctrlKey" : "metaKey")) name = "Cmd-" + name;
 

	
 
      var stopped = false;
 
      function stop() { stopped = true; }
 

	
 
      if (e_prop(e, "shiftKey")) {
 
        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;
 
    }
 

	
 
    var lastStoppedKey = null;
 
    function onKeyDown(e) {
 
      if (!focused) onFocus();
 
      if (ie && e.keyCode == 27) { e.returnValue = false; }
 
      if (pollingFast) { if (readInput()) pollingFast = false; }
 
      if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
 
      var code = e_prop(e, "keyCode");
 
      // IE does strange things with escape.
 
      setShift(code == 16 || e_prop(e, "shiftKey"));
 
      // First give onKeyEvent option a chance to handle this.
 
      var handled = handleKeyBinding(e);
 
@@ -933,54 +940,55 @@ window.CodeMirror = (function() {
 
      function p() {
 
        var changed = readInput();
 
        if (!changed && !missed) {missed = true; poll.set(60, p);}
 
        else {pollingFast = false; slowPoll();}
 
      }
 
      poll.set(20, p);
 
    }
 

	
 
    // Previnput is a hack to work with IME. If we reset the textarea
 
    // on every change, that breaks IME. So we look for changes
 
    // compared to the previous content instead. (Modern browsers have
 
    // events that indicate IME taking place, but these are not widely
 
    // 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();
 
    }
 

	
 
    function scrollCursorIntoView() {
 
      var coords = calculateCursorCoords();
 
      scrollIntoView(coords.x, coords.y, coords.x, coords.yBot);
 
      if (!focused) return;
 
      var box = sizer.getBoundingClientRect(), doScroll = null;
 
      if (coords.y + box.top < 0) doScroll = true;
 
      else if (coords.y + box.top + textHeight() > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
 
      if (doScroll != null) {
 
        var hidden = cursor.style.display == "none";
 
        if (hidden) {
 
@@ -1395,188 +1403,189 @@ window.CodeMirror = (function() {
 
    }
 
    function moveV(dir, unit) {
 
      var dist = 0, pos = localCoords(sel.inverted ? sel.from : sel.to, true);
 
      if (goalColumn != null) pos.x = goalColumn;
 
      if (unit == "page") {
 
        var screen = Math.min(scroller.clientHeight, window.innerHeight || document.documentElement.clientHeight);
 
        var target = coordsChar(pos.x, pos.y + screen * dir);
 
      } else if (unit == "line") {
 
        var th = textHeight();
 
        var target = coordsChar(pos.x, pos.y + .5 * th + dir * th);
 
      }
 
      if (unit == "page") scrollbar.scrollTop += localCoords(target, true).y - pos.y;
 
      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);
 
    }
 

	
 
    function indentLine(n, how) {
 
      if (!how) how = "add";
 
      if (how == "smart") {
 
        if (!mode.indent) how = "prev";
 
        else var state = getStateBefore(n);
 
      }
 

	
 
      var line = getLine(n), curSpace = line.indentation(options.tabSize),
 
          curSpaceString = line.text.match(/^\s*/)[0], indentation;
 
      if (how == "smart") {
 
        indentation = mode.indent(state, line.text.slice(curSpaceString.length), line.text);
 
        if (indentation == Pass) how = "prev";
 
      }
 
      if (how == "prev") {
 
        if (n) indentation = getLine(n-1).indentation(options.tabSize);
 
        else indentation = 0;
 
      }
 
      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;
 
      else lineDiv.parentNode.style.marginLeft = 0;
 
    }
 
    function wrappingChanged(from, to) {
 
      if (options.lineWrapping) {
 
        wrapper.className += " CodeMirror-wrap";
 
        var perLine = scroller.clientWidth / charWidth() - 3;
 
        doc.iter(0, doc.size, function(line) {
 
          if (line.hidden) return;
 
          var guess = Math.ceil(line.text.length / perLine) || 1;
 
          if (guess != 1) updateLineHeight(line, guess);
 
        });
 
        lineSpace.style.minWidth = widthForcer.style.left = "";
 
      } else {
 
        wrapper.className = wrapper.className.replace(" CodeMirror-wrap", "");
 
        computeMaxLength();
 
        doc.iter(0, doc.size, function(line) {
 
          if (line.height != 1 && !line.hidden) updateLineHeight(line, 1);
 
        });
 
      }
 
      changes.push({from: 0, to: doc.size});
 
    }
 
    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};
 
        }
 
      }
 
      if (this.type == "bookmark") return from;
 
      return from && {from: from, to: to};
 
    };
 

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

	
 
    function addGutterMarker(line, text, className) {
 
      if (typeof line == "number") line = getLine(clipLine(line));
 
      line.gutterMarker = {text: text, style: className};
 
      gutterDirty = true;
 
      return line;
 
    }
 
    function removeGutterMarker(line) {
 
      if (typeof line == "number") line = getLine(clipLine(line));
 
@@ -1623,50 +1632,48 @@ window.CodeMirror = (function() {
 
            setSelection(from, to);
 
          }
 
          return (gutterDirty = true);
 
        }
 
      });
 
    }
 

	
 
    function lineInfo(line) {
 
      if (typeof line == "number") {
 
        if (!isLine(line)) return null;
 
        var n = line;
 
        line = getLine(line);
 
        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};
 
    }
 
    function localCoords(pos, inLineWrap) {
 
      var x, lh = textHeight(), y = lh * (heightAtLine(doc, pos.line) - (inLineWrap ? displayOffset : 0));
 
      if (pos.ch == 0) x = 0;
 
      else {
 
        var sp = measureLine(getLine(pos.line), pos.ch);
 
        x = sp.left;
 
        if (options.lineWrapping) y += Math.max(0, sp.top);
 
      }
 
      return {x: x, y: y, yBot: y + lh};
 
    }
 
    // Coords must be lineSpace-local
 
    function coordsChar(x, y) {
 
@@ -1957,48 +1964,49 @@ window.CodeMirror = (function() {
 
      if (sc && options.onCursorActivity)
 
        options.onCursorActivity(instance);
 
      for (var i = 0; i < cbs.length; ++i) cbs[i](instance);
 
      if (updated && options.onUpdate) options.onUpdate(instance);
 
    }
 
    var nestedOperation = 0;
 
    function operation(f) {
 
      return function() {
 
        if (!nestedOperation++) startOperation();
 
        try {var result = f.apply(this, arguments);}
 
        finally {if (!--nestedOperation) endOperation();}
 
        return result;
 
      };
 
    }
 

	
 
    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,
 
    keyMap: "default",
 
    extraKeys: null,
 
    electricChars: true,
 
    autoClearEmptyLines: false,
 
    onKeyEvent: null,
 
    onDragEvent: null,
 
    lineWrapping: false,
 
    lineNumbers: false,
 
    gutter: false,
 
    fixedGutter: false,
 
    firstLineNumber: 1,
 
    readOnly: false,
 
@@ -2054,48 +2062,51 @@ window.CodeMirror = (function() {
 
      var exts = modeExtensions[spec.name];
 
      for (var prop in exts) if (exts.hasOwnProperty(prop)) modeObj[prop] = exts[prop];
 
    }
 
    modeObj.name = spec.name;
 
    return modeObj;
 
  };
 
  CodeMirror.listModes = function() {
 
    var list = [];
 
    for (var m in modes)
 
      if (modes.propertyIsEnumerable(m)) list.push(m);
 
    return list;
 
  };
 
  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});
 
      else cm.replaceRange("", from, sel ? to : {line: from.line});
 
    },
 
    deleteLine: function(cm) {var l = cm.getCursor().line; cm.replaceRange("", {line: l, ch: 0}, {line: l});},
 
    undo: function(cm) {cm.undo();},
 
    redo: function(cm) {cm.redo();},
 
    goDocStart: function(cm) {cm.setCursor(0, 0, true);},
 
    goDocEnd: function(cm) {cm.setSelection({line: cm.lineCount() - 1}, null, true);},
 
    goLineStart: function(cm) {cm.setCursor(cm.getCursor().line, 0, true);},
 
    goLineStartSmart: function(cm) {
 
      var cur = cm.getCursor();
 
      var text = cm.getLine(cur.line), firstNonWS = Math.max(0, text.search(/\S/));
 
      cm.setCursor(cur.line, cur.ch <= firstNonWS && cur.ch ? 0 : firstNonWS, true);
 
@@ -2146,114 +2157,113 @@ window.CodeMirror = (function() {
 
  // Note that the save and find-related commands aren't defined by
 
  // default. Unknown commands are simply ignored.
 
  keyMap.pcDefault = {
 
    "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
 
    "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
 
    "Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
 
    "Ctrl-Backspace": "delWordLeft", "Ctrl-Delete": "delWordRight", "Ctrl-S": "save", "Ctrl-F": "find",
 
    "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
 
    "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
 
    fallthrough: "basic"
 
  };
 
  keyMap.macDefault = {
 
    "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) {
 
        if (stop) stop();
 
        return true;
 
      }
 
      if (found != null && handle(found)) return true;
 
      if (map.nofallthrough) {
 
        if (stop) stop();
 
        return true;
 
      }
 
      var fallthrough = map.fallthrough;
 
      if (fallthrough == null) return false;
 
      if (Object.prototype.toString.call(fallthrough) != "[object Array]")
 
        return lookup(fallthrough);
 
      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 = "";
 
      if (textarea.form) {
 
        rmSubmit();
 
        if (typeof textarea.form.submit == "function")
 
          textarea.form.submit = realSubmit;
 
      }
 
    };
 
    return instance;
 
  };
 

	
 
  var gecko = /gecko\/\d{7}/i.test(navigator.userAgent);
 
  var ie = /MSIE \d/.test(navigator.userAgent);
 
  var ie_lt8 = /MSIE [1-7]\b/.test(navigator.userAgent);
 
@@ -2332,58 +2342,62 @@ window.CodeMirror = (function() {
 
    column: function() {return countColumn(this.string, this.start, this.tabSize);},
 
    indentation: function() {return countColumn(this.string, null, this.tabSize);},
 
    match: function(pattern, consume, caseInsensitive) {
 
      if (typeof pattern == "string") {
 
        var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
 
        if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
 
          if (consume !== false) this.pos += pattern.length;
 
          return true;
 
        }
 
      } else {
 
        var match = this.string.slice(this.pos).match(pattern);
 
        if (match && match.index > 0) return null;
 
        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;
 
  }
 

	
 
  function markedSpansAfter(old, endCh) {
 
    if (old) for (var i = 0, nw; i < old.length; ++i) {
 
      var span = old[i], marker = span.marker;
 
      var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
 
      if (endsAfter || marker.type == "bookmark" && span.from == endCh) {
 
        var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
 
        (nw || (nw = [])).push({from: startsBefore ? null : span.from - endCh,
 
                                to: span.to == null ? null : span.to - endCh,
 
                                marker: marker});
 
      }
 
@@ -2425,49 +2439,57 @@ window.CodeMirror = (function() {
 
          span.from += offset;
 
          if (sameLine) (first || (first = [])).push(span);
 
        }
 
      }
 
    }
 

	
 
    var newMarkers = [newHL(newText[0], first)];
 
    if (!sameLine) {
 
      // Fill gap with whole-line-spans
 
      var gap = newText.length - 2, gapMarkers;
 
      if (gap > 0 && first)
 
        for (var i = 0; i < first.length; ++i)
 
          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;
 
  }
 

	
 
  function attachMarkedSpans(line, spans) {
 
    if (!spans) return;
 
    for (var i = 0; i < spans.length; ++i)
 
      var marker = spans[i].marker.lines.push(line);
 
    line.markedSpans = spans;
 
  }
 

	
 
  // When measuring the position of the end of a line, different
 
  // browsers require different approaches. If an empty span is added,
 
  // many browsers report bogus offsets. Of those, some (Webkit,
 
  // recent IE) will accept a space without moving the whole span to
 
@@ -2561,55 +2583,59 @@ window.CodeMirror = (function() {
 
            }
 
            if (!m) break;
 
            pos += skipped + 1;
 
            if (m[0] == "\t") {
 
              var tabWidth = tabSize - col % tabSize;
 
              content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
 
              col += tabWidth;
 
            } else {
 
              var token = elt("span", "\u2022", "cm-invalidchar");
 
              token.title = "\\u" + m[0].charCodeAt(0).toString(16);
 
              content.appendChild(token);
 
              col += 1;
 
            }
 
          }
 
        }
 
        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
 
            else if (outPos > wrapAt + 10 && /\s/.test(text)) span = function(){};
 
          }
 
        };
 
      }
 

	
 
      var st = this.styles, allText = this.text, marked = this.markedSpans;
 
      var len = allText.length;
 
      function styleToClass(style) {
 
        if (!style) return null;
 
        return "cm-" + style.replace(/ +/g, " cm-");
 
      }
 
      if (!allText && wrapAt == null) {
 
@@ -2851,49 +2877,49 @@ window.CodeMirror = (function() {
 
        if (n < sz) { chunk = child; continue outer; }
 
        n -= sz;
 
        h += child.height;
 
      }
 
      return h;
 
    } while (!chunk.lines);
 
    for (var i = 0; i < n; ++i) h += chunk.lines[i].height;
 
    return h;
 
  }
 

	
 
  // The history object 'chunks' changes that are made close together
 
  // and at almost the same time into bigger undoable units.
 
  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);
 
      }
 
      this.time = time;
 
    },
 
    startCompound: function() {
 
      if (!this.compound++) this.closed = true;
 
    },
 
    endCompound: function() {
 
      if (!--this.compound) this.closed = true;
 
    }
 
  };
 

	
 
  function stopMethod() {e_stop(this);}
 
@@ -3057,50 +3083,52 @@ window.CodeMirror = (function() {
 
  }
 
  function setTextContent(e, str) {
 
    if (ie_lt9) {
 
      e.innerHTML = "";
 
      e.appendChild(document.createTextNode(str));
 
    } else e.textContent = str;
 
  }
 

	
 
  // Used to position the cursor after an undo/redo by finding the
 
  // last edited character.
 
  function editEnd(from, to) {
 
    if (!to) return 0;
 
    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) {
 
        result.push(line.slice(0, rt));
 
        pos += rt + 1;
 
      } else {
 
        result.push(line);
 
        pos = nl + 1;
 
      }
 
    }
 
    return result;
 
  } : function(string){return string.split(/\r\n?|\n/);};
 
  CodeMirror.splitLines = splitLines;
 

	
 
  var hasSelection = window.getSelection ? function(te) {
 
@@ -3114,28 +3142,28 @@ window.CodeMirror = (function() {
 
  };
 

	
 
  CodeMirror.defineMode("null", function() {
 
    return {token: function(stream) {stream.skipToEnd();}};
 
  });
 
  CodeMirror.defineMIME("text/plain", "null");
 

	
 
  var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
 
                  19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
 
                  36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
 
                  46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 109: "-", 107: "=", 127: "Delete",
 
                  186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
 
                  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)