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 66 insertions and 37 deletions:
0 comments (0 inline, 0 general)
rhodecode/public/css/codemirror.css
Show inline comments
 
@@ -35,96 +35,97 @@
 
     rather than sitting to the right of it. */
 
  position: absolute;
 
  z-index: 1;
 
  float: none;
 
  right: 0;
 
  min-width: 12px;
 
}
 
.CodeMirror-scrollbar.cm-sb-nonoverlap {
 
  min-width: 12px;
 
}
 
.CodeMirror-scrollbar.cm-sb-ie7 {
 
  min-width: 18px;
 
}
 

	
 
.CodeMirror-gutter {
 
  position: absolute; left: 0; top: 0;
 
  z-index: 10;
 
  background-color: #f7f7f7;
 
  border-right: 1px solid #eee;
 
  min-width: 2em;
 
  height: 100%;
 
}
 
.CodeMirror-gutter-text {
 
  color: #aaa;
 
  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 {
 
  width: auto;
 
  border: 0;
 
  background: transparent;
 
  background: rgba(0, 200, 0, .4);
 
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#6600c800, endColorstr=#4c00c800);
 
}
 
/* Kludge to turn off filter in ie9+, which also accepts rgba */
 
.cm-keymap-fat-cursor pre.CodeMirror-cursor:not(#nonsense_id) {
 
  filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
 
}
 
.CodeMirror pre.CodeMirror-cursor.CodeMirror-overwrite {}
 
.CodeMirror-focused pre.CodeMirror-cursor {
 
  visibility: visible;
 
}
 

	
 
div.CodeMirror-selected { background: #d9d9d9; }
 
.CodeMirror-focused div.CodeMirror-selected { background: #d7d4f0; }
 

	
 
.CodeMirror-searching {
 
  background: #ffa;
 
  background: rgba(255, 255, 0, .4);
 
}
 

	
 
/* Default theme */
rhodecode/public/js/codemirror.js
Show inline comments
 
@@ -30,250 +30,252 @@ window.CodeMirror = (function() {
 
    var measure = elt("div", null, null, "position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden;");
 
    var lineSpace = elt("div", [measure, cursor, widthForcer, selectionDiv, lineDiv], null, "position: relative; z-index: 0");
 
    var gutterText = elt("div", null, "CodeMirror-gutter-text"), gutter = elt("div", [gutterText], "CodeMirror-gutter");
 
    // Moved around its parent to cover visible view
 
    var mover = elt("div", [gutter, elt("div", [lineSpace], "CodeMirror-lines")], null, "position: relative");
 
    // Set to the height of the text, causes scrolling
 
    var sizer = elt("div", [mover], null, "position: relative");
 
    // Provides scrolling
 
    var scroller = elt("div", [sizer], "CodeMirror-scroll");
 
    scroller.setAttribute("tabIndex", "-1");
 
    // The element in which the editor lives.
 
    var wrapper = elt("div", [inputDiv, scrollbar, scroller], "CodeMirror" + (options.lineWrapping ? " CodeMirror-wrap" : ""));
 
    if (place.appendChild) place.appendChild(wrapper); else place(wrapper);
 

	
 
    themeChanged(); keyMapChanged();
 
    // Needed to hide big blue blinking cursor on Mobile Safari
 
    if (ios) input.style.width = "0px";
 
    if (!webkit) scroller.draggable = true;
 
    lineSpace.style.outline = "none";
 
    if (options.tabindex != null) input.tabIndex = options.tabindex;
 
    if (options.autofocus) focusInput();
 
    if (!options.gutter && !options.lineNumbers) gutter.style.display = "none";
 
    // Needed to handle Tab key in KHTML
 
    if (khtml) inputDiv.style.height = "1px", inputDiv.style.position = "absolute";
 

	
 
    // 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
 
    // which point we can't mess with it anymore. Context menu is
 
    // handled in onMouseDown for Gecko.
 
    if (!gecko) connect(scroller, "contextmenu", onContextMenu);
 
    connect(scroller, "scroll", onScrollMain);
 
    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;
 
      },
 
      getHistory: function() {
 
        function cp(arr) {
 
          for (var i = 0, nw = [], nwelt; i < arr.length; ++i) {
 
            nw.push(nwelt = []);
 
            for (var j = 0, elt = arr[i]; j < elt.length; ++j) {
 
              var old = [], cur = elt[j];
 
              nwelt.push({start: cur.start, added: cur.added, old: old});
 
              for (var k = 0; k < cur.old.length; ++k) old.push(hlText(cur.old[k]));
 
            }
 
          }
 
          return nw;
 
        }
 
        return {done: cp(history.done), undone: cp(history.undone)};
 
      },
 
      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;
 
        else if (vert == "near") {
 
          var vspace = Math.max(scroller.offsetHeight, doc.height * textHeight()),
 
              hspace = Math.max(sizer.clientWidth, lineSpace.clientWidth) - paddingLeft();
 
          if (pos.yBot + node.offsetHeight > vspace && pos.y > node.offsetHeight)
 
            top = pos.y - node.offsetHeight;
 
          if (left + node.offsetWidth > hspace)
 
            left = hspace - node.offsetWidth;
 
        }
 
        node.style.top = (top + paddingTop()) + "px";
 
        node.style.left = node.style.right = "";
 
        if (horiz == "right") {
 
          left = sizer.clientWidth - node.offsetWidth;
 
          node.style.right = "0px";
 
        } else {
 
          if (horiz == "left") left = 0;
 
          else if (horiz == "middle") left = (sizer.clientWidth - node.offsetWidth) / 2;
 
          node.style.left = (left + paddingLeft()) + "px";
 
        }
 
        if (scroll)
 
          scrollIntoView(left, top, left + node.offsetWidth, top + node.offsetHeight);
 
      },
 

	
 
      lineCount: function() {return doc.size;},
 
      clipPos: clipPos,
 
@@ -298,155 +300,160 @@ window.CodeMirror = (function() {
 
        if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0}));
 
      }),
 
      replaceRange: operation(replaceRange),
 
      getRange: function(from, to, lineSep) {return getRange(clipPos(from), clipPos(to), lineSep);},
 

	
 
      triggerOnKeyDown: operation(onKeyDown),
 
      execCommand: function(cmd) {return commands[cmd](instance);},
 
      // Stuff used by commands, probably not much use to outside code.
 
      moveH: operation(moveH),
 
      deleteH: operation(deleteH),
 
      moveV: operation(moveV),
 
      toggleOverwrite: function() {
 
        if(overwrite){
 
          overwrite = false;
 
          cursor.className = cursor.className.replace(" CodeMirror-overwrite", "");
 
        } else {
 
          overwrite = true;
 
          cursor.className += " CodeMirror-overwrite";
 
        }
 
      },
 

	
 
      posFromIndex: function(off) {
 
        var lineNo = 0, ch;
 
        doc.iter(0, doc.size, function(line) {
 
          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); }
 
    function updateLineHeight(line, height) {
 
      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);
 

	
 
      switch (e_button(e)) {
 
      case 3:
 
        if (gecko) onContextMenu(e);
 
        return;
 
      case 2:
 
        if (start) setCursor(start.line, start.ch, true);
 
        setTimeout(focusInput, 20);
 
        e_preventDefault(e);
 
        return;
 
      }
 
      // For button 1, if it was clicked inside the editor
 
      // (posFromMouse returning non-null), we have to adjust the
 
      // selection.
 
      if (!start) {if (e_target(e) == scroller) e_preventDefault(e); return;}
 

	
 
      if (!focused) onFocus();
 

	
 
      var now = +new Date, type = "single";
 
      if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
 
        type = "triple";
 
        e_preventDefault(e);
 
        setTimeout(focusInput, 20);
 
        selectLine(start.line);
 
      } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
 
@@ -589,97 +596,97 @@ window.CodeMirror = (function() {
 
      var prevShift = shiftSelecting;
 
      try {
 
        if (options.readOnly) suppressEdits = true;
 
        if (dropShift) shiftSelecting = null;
 
        bound(instance);
 
      } catch(e) {
 
        if (e != Pass) throw e;
 
        return false;
 
      } finally {
 
        shiftSelecting = prevShift;
 
        suppressEdits = false;
 
      }
 
      return true;
 
    }
 
    var maybeTransition;
 
    function handleKeyBinding(e) {
 
      // Handle auto keymap transitions
 
      var startMap = getKeyMap(options.keyMap), next = startMap.auto;
 
      clearTimeout(maybeTransition);
 
      if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
 
        if (getKeyMap(options.keyMap) == startMap) {
 
          options.keyMap = (next.call ? next.call(null, instance) : next);
 
        }
 
      }, 50);
 

	
 
      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);
 
      if (opera) {
 
        lastStoppedKey = handled ? code : null;
 
        // Opera has no cut event... we try to at least catch the key combo
 
        if (!handled && code == 88 && e_prop(e, mac ? "metaKey" : "ctrlKey"))
 
          replaceSelection("");
 
      }
 
    }
 
    function onKeyPress(e) {
 
      if (pollingFast) readInput();
 
      if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
 
      var keyCode = e_prop(e, "keyCode"), charCode = e_prop(e, "charCode");
 
      if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
 
      if (((opera && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(e)) return;
 
      var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
 
      if (options.electricChars && mode.electricChars && options.smartIndent && !options.readOnly) {
 
        if (mode.electricChars.indexOf(ch) > -1)
 
          setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 75);
 
      }
 
      if (handleCharBinding(e, ch)) return;
 
      fastPoll();
 
    }
 
    function onKeyUp(e) {
 
      if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
 
      if (e_prop(e, "keyCode") == 16) shiftSelecting = null;
 
@@ -909,102 +916,103 @@ window.CodeMirror = (function() {
 
    }
 

	
 
    function getRange(from, to, lineSep) {
 
      var l1 = from.line, l2 = to.line;
 
      if (l1 == l2) return getLine(l1).text.slice(from.ch, to.ch);
 
      var code = [getLine(l1).text.slice(from.ch)];
 
      doc.iter(l1 + 1, l2, function(line) { code.push(line.text); });
 
      code.push(getLine(l2).text.slice(0, to.ch));
 
      return code.join(lineSep || "\n");
 
    }
 
    function getSelection(lineSep) {
 
      return getRange(sel.from, sel.to, lineSep);
 
    }
 

	
 
    function slowPoll() {
 
      if (pollingFast) return;
 
      poll.set(options.pollInterval, function() {
 
        readInput();
 
        if (focused) slowPoll();
 
      });
 
    }
 
    function fastPoll() {
 
      var missed = false;
 
      pollingFast = true;
 
      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) {
 
          cursor.style.display = "";
 
          cursor.style.left = coords.x + "px";
 
          cursor.style.top = (coords.y - displayOffset) + "px";
 
        }
 
        cursor.scrollIntoView(doScroll);
 
        if (hidden) cursor.style.display = "none";
 
      }
 
    }
 
    function calculateCursorCoords() {
 
      var cursor = localCoords(sel.inverted ? sel.from : sel.to);
 
      var x = options.lineWrapping ? Math.min(cursor.x, lineSpace.offsetWidth) : cursor.x;
 
      return {x: x, y: cursor.y, yBot: cursor.yBot};
 
    }
 
    function scrollIntoView(x1, y1, x2, y2) {
 
      var scrollPos = calculateScrollPos(x1, y1, x2, y2);
 
      if (scrollPos.scrollLeft != null) {scroller.scrollLeft = scrollPos.scrollLeft;}
 
      if (scrollPos.scrollTop != null) {scrollbar.scrollTop = scroller.scrollTop = scrollPos.scrollTop;}
 
    }
 
    function calculateScrollPos(x1, y1, x2, y2) {
 
      var pl = paddingLeft(), pt = paddingTop();
 
      y1 += pt; y2 += pt; x1 += pl; x2 += pl;
 
      var screen = scroller.clientHeight, screentop = scrollbar.scrollTop, result = {};
 
      var docBottom = needsScrollbar() || Infinity;
 
      var atTop = y1 < pt + 10, atBottom = y2 + pt > docBottom - 10;
 
@@ -1371,326 +1379,325 @@ window.CodeMirror = (function() {
 
      }
 
      if (unit == "char") moveOnce();
 
      else if (unit == "column") moveOnce(true);
 
      else if (unit == "word") {
 
        var sawWord = false;
 
        for (;;) {
 
          if (dir < 0) if (!moveOnce()) break;
 
          if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
 
          else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
 
          if (dir > 0) if (!moveOnce()) break;
 
        }
 
      }
 
      return {line: line, ch: ch};
 
    }
 
    function moveH(dir, unit) {
 
      var pos = dir < 0 ? sel.from : sel.to;
 
      if (shiftSelecting || posEq(sel.from, sel.to)) pos = findPosH(dir, unit);
 
      setCursor(pos.line, pos.ch, true);
 
    }
 
    function deleteH(dir, unit) {
 
      if (!posEq(sel.from, sel.to)) replaceRange("", sel.from, sel.to);
 
      else if (dir < 0) replaceRange("", findPosH(dir, unit), sel.to);
 
      else replaceRange("", sel.from, findPosH(dir, unit));
 
      userSelChange = true;
 
    }
 
    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);
 
        }
 
      }
 
      if (min != Infinity)
 
        changes.push({from: min, to: max + 1});
 
        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 != 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));
 
      line.gutterMarker = null;
 
      gutterDirty = true;
 
    }
 

	
 
    function changeLine(handle, op) {
 
      var no = handle, line = handle;
 
      if (typeof handle == "number") line = getLine(clipLine(handle));
 
      else no = lineNo(handle);
 
      if (no == null) return null;
 
      if (op(line, no)) changes.push({from: no, to: no + 1});
 
      else return null;
 
      return line;
 
    }
 
    function setLineClass(handle, className, bgClassName) {
 
      return changeLine(handle, function(line) {
 
        if (line.className != className || line.bgClassName != bgClassName) {
 
          line.className = className;
 
          line.bgClassName = bgClassName;
 
          return true;
 
        }
 
      });
 
    }
 
    function setLineHidden(handle, hidden) {
 
      return changeLine(handle, function(line, no) {
 
        if (line.hidden != hidden) {
 
          line.hidden = hidden;
 
          if (!options.lineWrapping) {
 
            if (hidden && line.text.length == maxLine.text.length) {
 
              updateMaxLine = true;
 
            } else if (!hidden && line.text.length > maxLine.text.length) {
 
              maxLine = line; updateMaxLine = false;
 
            }
 
          }
 
          updateLineHeight(line, hidden ? 0 : 1);
 
          var fline = sel.from.line, tline = sel.to.line;
 
          if (hidden && (fline == no || tline == no)) {
 
            var from = fline == no ? skipHidden({line: fline, ch: 0}, fline, 0) : sel.from;
 
            var to = tline == no ? skipHidden({line: tline, ch: 0}, tline, 0) : sel.to;
 
            // Can't hide the last visible line, we'd have no place to put the cursor
 
            if (!to) return;
 
            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) {
 
      var th = textHeight(), cw = charWidth(), heightPos = displayOffset + Math.floor(y / th);
 
      if (heightPos < 0) return {line: 0, ch: 0};
 
      var lineNo = lineAtHeight(doc, heightPos);
 
      if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc.size - 1).text.length};
 
      var lineObj = getLine(lineNo), text = lineObj.text;
 
      var tw = options.lineWrapping, innerOff = tw ? heightPos - heightAtLine(doc, lineNo) : 0;
 
      if (x <= 0 && innerOff == 0) return {line: lineNo, ch: 0};
 
      var wrongLine = false;
 
      function getX(len) {
 
        var sp = measureLine(lineObj, len);
 
        if (tw) {
 
          var off = Math.round(sp.top / th);
 
          wrongLine = off != innerOff;
 
          return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth);
 
        }
 
        return sp.left;
 
      }
 
      var from = 0, fromX = 0, to = text.length, toX;
 
      // Guess a suitable upper bound for our search.
 
      var estimated = Math.min(to, Math.ceil((x + innerOff * scroller.clientWidth * .9) / cw));
 
      for (;;) {
 
        var estX = getX(estimated);
 
        if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
 
        else {toX = estX; to = estimated; break;}
 
@@ -1933,96 +1940,97 @@ window.CodeMirror = (function() {
 
      if (selectionChanged) {
 
        var coords = calculateCursorCoords();
 
        newScrollPos = calculateScrollPos(coords.x, coords.y, coords.x, coords.yBot);
 
      }
 
      if (changes.length || newScrollPos && newScrollPos.scrollTop != null)
 
        updated = updateDisplay(changes, true, newScrollPos && newScrollPos.scrollTop);
 
      if (!updated) {
 
        if (selectionChanged) updateSelection();
 
        if (gutterDirty) updateGutter();
 
      }
 
      if (newScrollPos) scrollCursorIntoView();
 
      if (selectionChanged) restartBlink();
 

	
 
      if (focused && (updateInput === true || (updateInput !== false && selectionChanged)))
 
        resetInput(userSelChange);
 

	
 
      if (selectionChanged && options.matchBrackets)
 
        setTimeout(operation(function() {
 
          if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;}
 
          if (posEq(sel.from, sel.to)) matchBrackets(false);
 
        }), 20);
 
      var sc = selectionChanged, cbs = callbacks; // these can be reset by callbacks
 
      if (textChanged && options.onChange && instance)
 
        options.onChange(instance, textChanged);
 
      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,
 
    dragDrop: true,
 
    onChange: null,
 
    onCursorActivity: null,
 
    onViewportChange: null,
 
    onGutterClick: null,
 
    onUpdate: null,
 
    onFocus: null, onBlur: null, onScroll: null,
 
    matchBrackets: false,
 
    cursorBlinkRate: 530,
 
    workTime: 100,
 
    workDelay: 200,
 
    pollInterval: 100,
 
    undoDepth: 40,
 
    tabindex: null,
 
    autofocus: null,
 
    lineNumberFormatter: function(integer) { return integer; }
 
  };
 

	
 
  var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
 
  var mac = ios || /Mac/.test(navigator.platform);
 
  var win = /Win/.test(navigator.platform);
 

	
 
  // Known modes, by name and by MIME
 
  var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
 
@@ -2030,255 +2038,257 @@ window.CodeMirror = (function() {
 
    if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
 
    if (arguments.length > 2) {
 
      mode.dependencies = [];
 
      for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
 
    }
 
    modes[name] = mode;
 
  };
 
  CodeMirror.defineMIME = function(mime, spec) {
 
    mimeModes[mime] = spec;
 
  };
 
  CodeMirror.resolveMode = function(spec) {
 
    if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
 
      spec = mimeModes[spec];
 
    else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec))
 
      return CodeMirror.resolveMode("application/xml");
 
    if (typeof spec == "string") return {name: spec};
 
    else return spec || {name: "null"};
 
  };
 
  CodeMirror.getMode = function(options, spec) {
 
    var spec = CodeMirror.resolveMode(spec);
 
    var mfactory = modes[spec.name];
 
    if (!mfactory) return CodeMirror.getMode(options, "text/plain");
 
    var modeObj = mfactory(options, spec);
 
    if (modeExtensions.hasOwnProperty(spec.name)) {
 
      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);
 
    },
 
    goLineEnd: function(cm) {cm.setSelection({line: cm.getCursor().line}, null, true);},
 
    goLineUp: function(cm) {cm.moveV(-1, "line");},
 
    goLineDown: function(cm) {cm.moveV(1, "line");},
 
    goPageUp: function(cm) {cm.moveV(-1, "page");},
 
    goPageDown: function(cm) {cm.moveV(1, "page");},
 
    goCharLeft: function(cm) {cm.moveH(-1, "char");},
 
    goCharRight: function(cm) {cm.moveH(1, "char");},
 
    goColumnLeft: function(cm) {cm.moveH(-1, "column");},
 
    goColumnRight: function(cm) {cm.moveH(1, "column");},
 
    goWordLeft: function(cm) {cm.moveH(-1, "word");},
 
    goWordRight: function(cm) {cm.moveH(1, "word");},
 
    delCharLeft: function(cm) {cm.deleteH(-1, "char");},
 
    delCharRight: function(cm) {cm.deleteH(1, "char");},
 
    delWordLeft: function(cm) {cm.deleteH(-1, "word");},
 
    delWordRight: function(cm) {cm.deleteH(1, "word");},
 
    indentAuto: function(cm) {cm.indentSelection("smart");},
 
    indentMore: function(cm) {cm.indentSelection("add");},
 
    indentLess: function(cm) {cm.indentSelection("subtract");},
 
    insertTab: function(cm) {cm.replaceSelection("\t", "end");},
 
    defaultTab: function(cm) {
 
      if (cm.somethingSelected()) cm.indentSelection("add");
 
      else cm.replaceSelection("\t", "end");
 
    },
 
    transposeChars: function(cm) {
 
      var cur = cm.getCursor(), line = cm.getLine(cur.line);
 
      if (cur.ch > 0 && cur.ch < line.length - 1)
 
        cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
 
                        {line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1});
 
    },
 
    newlineAndIndent: function(cm) {
 
      cm.replaceSelection("\n", "end");
 
      cm.indentLine(cm.getCursor().line);
 
    },
 
    toggleOverwrite: function(cm) {cm.toggleOverwrite();}
 
  };
 

	
 
  var keyMap = CodeMirror.keyMap = {};
 
  keyMap.basic = {
 
    "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
 
    "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
 
    "Delete": "delCharRight", "Backspace": "delCharLeft", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
 
    "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
 
  };
 
  // 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;
 
        };
 
      }
 
    }
 

	
 
    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);
 
  var ie_lt9 = /MSIE [1-8]\b/.test(navigator.userAgent);
 
  var quirksMode = ie && document.documentMode == 5;
 
  var webkit = /WebKit\//.test(navigator.userAgent);
 
  var chrome = /Chrome\//.test(navigator.userAgent);
 
  var opera = /Opera\//.test(navigator.userAgent);
 
  var safari = /Apple Computer/.test(navigator.vendor);
 
  var khtml = /KHTML\//.test(navigator.userAgent);
 
  var mac_geLion = /Mac OS X 10\D([7-9]|\d\d)\D/.test(navigator.userAgent);
 

	
 
  // Utility functions for working with state. Exported because modes
 
  // sometimes need to do this.
 
  function copyState(mode, state) {
 
    if (state === true) return state;
 
    if (mode.copyState) return mode.copyState(state);
 
    var nstate = {};
 
    for (var n in state) {
 
      var val = state[n];
 
      if (val instanceof Array) val = val.concat([]);
 
      nstate[n] = val;
 
    }
 
    return nstate;
 
  }
 
  CodeMirror.copyState = copyState;
 
  function startState(mode, a1, a2) {
 
    return mode.startState ? mode.startState(a1, a2) : true;
 
@@ -2308,190 +2318,202 @@ window.CodeMirror = (function() {
 
        return this.string.charAt(this.pos++);
 
    },
 
    eat: function(match) {
 
      var ch = this.string.charAt(this.pos);
 
      if (typeof match == "string") var ok = ch == match;
 
      else var ok = ch && (match.test ? match.test(ch) : match(ch));
 
      if (ok) {++this.pos; return ch;}
 
    },
 
    eatWhile: function(match) {
 
      var start = this.pos;
 
      while (this.eat(match)){}
 
      return this.pos > start;
 
    },
 
    eatSpace: function() {
 
      var start = this.pos;
 
      while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
 
      return this.pos > start;
 
    },
 
    skipToEnd: function() {this.pos = this.string.length;},
 
    skipTo: function(ch) {
 
      var found = this.string.indexOf(ch, this.pos);
 
      if (found > -1) {this.pos = found; return true;}
 
    },
 
    backUp: function(n) {this.pos -= n;},
 
    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});
 
      }
 
    }
 
    return nw;
 
  }
 

	
 
  function updateMarkedSpans(oldFirst, oldLast, startCh, endCh, newText) {
 
    if (!oldFirst && !oldLast) return newText;
 
    // Get the spans that 'stick out' on both sides
 
    var first = markedSpansBefore(oldFirst, startCh);
 
    var last = markedSpansAfter(oldLast, endCh);
 

	
 
    // Next, merge those two ends
 
    var sameLine = newText.length == 1, offset = lst(newText).length + (sameLine ? startCh : 0);
 
    if (first) {
 
      // Fix up .to properties of first
 
      for (var i = 0; i < first.length; ++i) {
 
        var span = first[i];
 
        if (span.to == null) {
 
          var found = getMarkedSpanFor(last, span.marker);
 
          if (!found) span.to = startCh;
 
          else if (sameLine) span.to = found.to == null ? null : found.to + offset;
 
        }
 
      }
 
    }
 
    if (last) {
 
      // Fix up .from in last (or move them into first in case of sameLine)
 
      for (var i = 0; i < last.length; ++i) {
 
        var span = last[i];
 
        if (span.to != null) span.to += offset;
 
        if (span.from == null) {
 
          var found = getMarkedSpanFor(first, span.marker);
 
          if (!found) {
 
            span.from = offset;
 
            if (sameLine) (first || (first = [])).push(span);
 
          }
 
        } else {
 
          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
 
  // the next line when wrapping it, others work with a zero-width
 
  // space.
 
  var eolSpanContent = " ";
 
  if (gecko || (ie && !ie_lt8)) eolSpanContent = "\u200b";
 
  else if (opera) eolSpanContent = "";
 

	
 
  // Line objects. These hold state related to a line, including
 
  // highlighting info (the styles array).
 
  function Line(text, markedSpans) {
 
    this.text = text;
 
    this.height = 1;
 
    attachMarkedSpans(this, markedSpans);
 
  }
 
  Line.prototype = {
 
    update: function(text, markedSpans) {
 
      this.text = text;
 
      this.stateAfter = this.styles = null;
 
      detachMarkedSpans(this);
 
      attachMarkedSpans(this, markedSpans);
 
    },
 
    // Run the given mode's parser over a line, update the styles
 
    // array, which contains alternating fragments of text and CSS
 
    // classes.
 
    highlight: function(mode, state, tabSize) {
 
@@ -2537,103 +2559,107 @@ window.CodeMirror = (function() {
 
    },
 
    indentation: function(tabSize) {return countColumn(this.text, null, tabSize);},
 
    // Produces an HTML fragment for the line, taking selection,
 
    // marking, and highlighting into account.
 
    getContent: function(tabSize, wrapAt, compensateForWrapping) {
 
      var first = true, col = 0, specials = /[\t\u0000-\u0019\u200b\u2028\u2029\uFEFF]/g;
 
      var pre = elt("pre");
 
      function span_(html, text, style) {
 
        if (!text) return;
 
        // Work around a bug where, in some compat modes, IE ignores leading spaces
 
        if (first && ie && text.charAt(0) == " ") text = "\u00a0" + text.slice(1);
 
        first = false;
 
        if (!specials.test(text)) {
 
          col += text.length;
 
          var content = document.createTextNode(text);
 
        } else {
 
          var content = document.createDocumentFragment(), pos = 0;
 
          while (true) {
 
            specials.lastIndex = pos;
 
            var m = specials.exec(text);
 
            var skipped = m ? m.index - pos : text.length - pos;
 
            if (skipped) {
 
              content.appendChild(document.createTextNode(text.slice(pos, pos + skipped)));
 
              col += skipped;
 
            }
 
            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) {
 
        span(pre, " ");
 
      } else if (!marked || !marked.length) {
 
        for (var i = 0, ch = 0; ch < len; i+=2) {
 
          var str = st[i], style = st[i+1], l = str.length;
 
          if (ch + l > len) str = str.slice(0, len - ch);
 
          ch += l;
 
          span(pre, str, styleToClass(style));
 
        }
 
      } else {
 
        marked.sort(function(a, b) { return a.from - b.from; });
 
        var pos = 0, i = 0, text = "", style, sg = 0;
 
        var nextChange = marked[0].from || 0, marks = [], markpos = 0;
 
        var advanceMarks = function() {
 
          var m;
 
          while (markpos < marked.length &&
 
                 ((m = marked[markpos]).from == pos || m.from == null)) {
 
            if (m.marker.type == "range") marks.push(m);
 
            ++markpos;
 
          }
 
          nextChange = markpos < marked.length ? marked[markpos].from : Infinity;
 
          for (var i = 0; i < marks.length; ++i) {
 
            var to = marks[i].to;
 
            if (to == null) to = Infinity;
 
            if (to == pos) marks.splice(i--, 1);
 
@@ -2827,97 +2853,97 @@ window.CodeMirror = (function() {
 
  }
 
  function lineAtHeight(chunk, h) {
 
    var n = 0;
 
    outer: do {
 
      for (var i = 0, e = chunk.children.length; i < e; ++i) {
 
        var child = chunk.children[i], ch = child.height;
 
        if (h < ch) { chunk = child; continue outer; }
 
        h -= ch;
 
        n += child.chunkSize();
 
      }
 
      return n;
 
    } while (!chunk.lines);
 
    for (var i = 0, e = chunk.lines.length; i < e; ++i) {
 
      var line = chunk.lines[i], lh = line.height;
 
      if (h < lh) break;
 
      h -= lh;
 
    }
 
    return n + i;
 
  }
 
  function heightAtLine(chunk, n) {
 
    var h = 0;
 
    outer: do {
 
      for (var i = 0, e = chunk.children.length; i < e; ++i) {
 
        var child = chunk.children[i], sz = child.chunkSize();
 
        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);}
 
  // Ensure an event has a stop method.
 
  function addStop(event) {
 
    if (!event.stop) event.stop = stopMethod;
 
    return event;
 
  }
 

	
 
  function e_preventDefault(e) {
 
    if (e.preventDefault) e.preventDefault();
 
    else e.returnValue = false;
 
  }
 
  function e_stopPropagation(e) {
 
    if (e.stopPropagation) e.stopPropagation();
 
    else e.cancelBubble = true;
 
  }
 
  function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
 
  CodeMirror.e_stop = e_stop;
 
  CodeMirror.e_preventDefault = e_preventDefault;
 
  CodeMirror.e_stopPropagation = e_stopPropagation;
 

	
 
  function e_target(e) {return e.target || e.srcElement;}
 
  function e_button(e) {
 
    var b = e.which;
 
    if (b == null) {
 
      if (e.button & 1) b = 1;
 
@@ -3033,109 +3059,111 @@ window.CodeMirror = (function() {
 
      node.selectionStart = 0;
 
      node.selectionEnd = node.value.length;
 
    } else node.select();
 
  }
 

	
 
  // Operations on {line, ch} objects.
 
  function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
 
  function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
 
  function copyPos(x) {return {line: x.line, ch: x.ch};}
 

	
 
  function elt(tag, content, className, style) {
 
    var e = document.createElement(tag);
 
    if (className) e.className = className;
 
    if (style) e.style.cssText = style;
 
    if (typeof content == "string") setTextContent(e, content);
 
    else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
 
    return e;
 
  }
 
  function removeChildren(e) {
 
    e.innerHTML = "";
 
    return e;
 
  }
 
  function removeChildrenAndAdd(parent, e) {
 
    removeChildren(parent).appendChild(e);
 
  }
 
  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) {
 
    try { return te.selectionStart != te.selectionEnd; }
 
    catch(e) { return false; }
 
  } : function(te) {
 
    try {var range = te.ownerDocument.selection.createRange();}
 
    catch(e) {}
 
    if (!range || range.parentElement() != te) return false;
 
    return range.compareEndPoints("StartToEnd", range) != 0;
 
  };
 

	
 
  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)