couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [45/53] [abbrv] [partial] fauxton commit: updated refs/heads/master to 8699e98
Date Wed, 23 Mar 2016 12:24:47 GMT
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f5b0260e/assets/js/libs/ace/keybinding-vim.js
----------------------------------------------------------------------
diff --git a/assets/js/libs/ace/keybinding-vim.js b/assets/js/libs/ace/keybinding-vim.js
deleted file mode 100644
index bd9b4e4..0000000
--- a/assets/js/libs/ace/keybinding-vim.js
+++ /dev/null
@@ -1,5320 +0,0 @@
-define("ace/keyboard/vim",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/dom","ace/lib/oop","ace/lib/keys","ace/lib/event","ace/search","ace/lib/useragent","ace/search_highlight","ace/commands/multi_select_commands","ace/multi_select"], function(require, exports, module) {
-  'use strict';
-
-  function log() {
-    var d = "";
-    function format(p) {
-      if (typeof p != "object")
-        return p + ""
-      if ("line" in p) {
-        return p.line + ":" + p.ch
-      }
-      if ("anchor" in p) {
-        return format(p.anchor) + "->" + format(p.head)
-      }
-      if (Array.isArray(p))
-        return "[" + p.map(function(x) {return format(x)})+"]"
-      return JSON.stringify(p)
-    }
-    for (var i = 0; i < arguments.length; i++) {
-      var p = arguments[i]
-      var f = format(p)
-      d+= f+"  "
-    }
-    console.log(d)
-  }
-  var Range = require("../range").Range;
-  var EventEmitter = require("../lib/event_emitter").EventEmitter;
-  var dom = require("../lib/dom");
-  var oop = require("../lib/oop");
-  var KEYS = require("../lib/keys");
-  var event = require("../lib/event");
-  var Search = require("../search").Search;
-  var useragent = require("../lib/useragent");
-  var SearchHighlight = require("../search_highlight").SearchHighlight;
-  var multiSelectCommands = require("../commands/multi_select_commands");
-  require("../multi_select");
-
-  var CodeMirror = function(ace) {
-    this.ace = ace;
-    this.state = {};
-    this.marks = {};
-    this.$uid = 0;
-    this.onChange = this.onChange.bind(this);
-    this.onSelectionChange = this.onSelectionChange.bind(this);
-    this.onBeforeEndOperation = this.onBeforeEndOperation.bind(this);
-    this.ace.on('change', this.onChange);
-    this.ace.on('changeSelection', this.onSelectionChange);
-    this.ace.on('beforeEndOperation', this.onBeforeEndOperation);
-  };
-  CodeMirror.Pos = function(line, ch) {
-    if (!(this instanceof Pos)) return new Pos(line, ch);
-    this.line = line; this.ch = ch;
-  };
-  CodeMirror.defineOption = function(name, val, setter) {};
-  CodeMirror.commands = {
-    redo: function(cm) { cm.ace.redo(); },
-    undo: function(cm) { cm.ace.undo(); },
-    newlineAndIndent: function(cm) { cm.ace.insert("\n"); },
-  };
-  CodeMirror.keyMap = {};
-  CodeMirror.addClass = CodeMirror.rmClass =
-  CodeMirror.e_stop = function() {};
-  CodeMirror.keyName = function(e) {
-    if (e.key) return e.key;
-    var key = (KEYS[e.keyCode] || "");
-    if (key.length == 1) key = key.toUpperCase();
-    key = event.getModifierString(e).replace(/(^|-)\w/g, function(m) {
-      return m.toUpperCase();
-    }) + key;
-    return key;
-  };
-  CodeMirror.keyMap['default'] = function(key) {
-    return function(cm) {
-      var cmd = cm.ace.commands.commandKeyBinding[key.toLowerCase()];
-      return cmd && cm.ace.execCommand(cmd) !== false;
-    };
-  };
-  CodeMirror.lookupKey = function lookupKey(key, map, handle) {
-    if (typeof map == "string")
-      map = CodeMirror.keyMap[map];
-    var found = typeof map == "function" ? map(key) : map[key];
-    if (found === false) return "nothing";
-    if (found === "...") return "multi";
-    if (found != null && handle(found)) return "handled";
-
-    if (map.fallthrough) {
-      if (!Array.isArray(map.fallthrough))
-        return lookupKey(key, map.fallthrough, handle);
-      for (var i = 0; i < map.fallthrough.length; i++) {
-        var result = lookupKey(key, map.fallthrough[i], handle);
-        if (result) return result;
-      }
-    }
-  };
-
-  CodeMirror.signal = function(o, name, e) { return o._signal(name, e) };
-  CodeMirror.on = event.addListener;
-  CodeMirror.off = event.removeListener;
-(function() {
-  oop.implement(CodeMirror.prototype, EventEmitter);
-  
-  this.destroy = function() {
-    this.ace.off('change', this.onChange);
-    this.ace.off('changeSelection', this.onSelectionChange);
-    this.ace.off('beforeEndOperation', this.onBeforeEndOperation);
-    this.removeOverlay();
-  };
-  this.virtualSelectionMode = function() {
-    return this.ace.inVirtualSelectionMode && this.ace.selection.index
-  };
-  this.onChange = function(delta) {
-    var oldDelta = delta.data;
-    delta = {
-      start: oldDelta.range.start,
-      end: oldDelta.range.end,
-      action: oldDelta.action,
-      lines: oldDelta.lines || [oldDelta.text]
-    };// v1.2 api compatibility
-    if (delta.action[0] == 'i') {
-      var change = { text: delta.lines };
-      var curOp = this.curOp = this.curOp || {};
-      if (!curOp.changeHandlers)
-        curOp.changeHandlers = this._eventRegistry["change"] && this._eventRegistry["change"].slice();
-      if (this.virtualSelectionMode()) return;
-      if (!curOp.lastChange) {
-        curOp.lastChange = curOp.change = change;
-      } else {
-        curOp.lastChange.next = curOp.lastChange = change;
-      }
-    }
-    this.$updateMarkers(delta);
-  };
-  this.onSelectionChange = function() {
-    var curOp = this.curOp = this.curOp || {};
-    if (!curOp.cursorActivityHandlers)
-      curOp.cursorActivityHandlers = this._eventRegistry["cursorActivity"] && this._eventRegistry["cursorActivity"].slice();
-    this.curOp.cursorActivity = true;
-    if (this.ace.inMultiSelectMode) {
-      this.ace.keyBinding.removeKeyboardHandler(multiSelectCommands.keyboardHandler);
-    }
-  };
-  this.operation = function(fn, force) {
-    if (!force && this.curOp || force && this.curOp && this.curOp.force) {
-      return fn();
-    }
-    if (force || !this.ace.curOp) {
-      if (this.curOp)
-        this.onBeforeEndOperation();
-    }
-    if (!this.ace.curOp) {
-      var prevOp = this.ace.prevOp;
-      this.ace.startOperation({
-        command: { name: "vim",  scrollIntoView: "cursor" }
-      });
-    }
-    var curOp = this.curOp = this.curOp || {};
-    this.curOp.force = force;
-    var result = fn();
-    if (this.ace.curOp && this.ace.curOp.command.name == "vim") {
-      this.ace.endOperation();
-      if (!curOp.cursorActivity && !curOp.lastChange && prevOp)
-        this.ace.prevOp = prevOp;
-    }
-    if (force || !this.ace.curOp) {
-      if (this.curOp)
-        this.onBeforeEndOperation();
-    }
-    return result;
-  };
-  this.onBeforeEndOperation = function() {
-    var op = this.curOp;
-    if (op) {
-      if (op.change) { this.signal("change", op.change, op); }
-      if (op && op.cursorActivity) { this.signal("cursorActivity", null, op); }
-      this.curOp = null;
-    }
-  };
-
-  this.signal = function(eventName, e, handlers) {
-    var listeners = handlers ? handlers[eventName + "Handlers"]
-        : (this._eventRegistry || {})[eventName];
-    if (!listeners)
-        return;
-    listeners = listeners.slice();
-    for (var i=0; i<listeners.length; i++)
-        listeners[i](this, e);
-  };
-  this.firstLine = function() { return 0; };
-  this.lastLine = function() { return this.ace.session.getLength() - 1; };
-  this.lineCount = function() { return this.ace.session.getLength(); };
-  this.setCursor = function(line, ch) {
-    if (typeof line === 'object') {
-      ch = line.ch;
-      line = line.line;
-    }
-    if (!this.ace.inVirtualSelectionMode)
-      this.ace.exitMultiSelectMode();
-    this.ace.selection.moveTo(line, ch);
-  };
-  this.getCursor = function(p) {
-    var sel = this.ace.selection;
-    var pos = p == 'anchor' ? (sel.isEmpty() ? sel.lead : sel.anchor) :
-        p == 'head' || !p ? sel.lead : sel.getRange()[p];
-    return toCmPos(pos);
-  };
-  this.listSelections = function(p) {
-    var ranges = this.ace.multiSelect.rangeList.ranges;
-    if (!ranges.length || this.ace.inVirtualSelectionMode)
-      return [{anchor: this.getCursor('anchor'), head: this.getCursor('head')}];
-    return ranges.map(function(r) {
-      return {
-        anchor: this.clipPos(toCmPos(r.cursor == r.end ? r.start : r.end)),
-        head: this.clipPos(toCmPos(r.cursor))
-      };
-    }, this);
-  };
-  this.setSelections = function(p, primIndex) {
-    var sel = this.ace.multiSelect;
-    var ranges = p.map(function(x) {
-      var anchor = toAcePos(x.anchor);
-      var head = toAcePos(x.head);
-      var r = Range.comparePoints(anchor, head) < 0
-        ? new Range.fromPoints(anchor, head)
-        : new Range.fromPoints(head, anchor);
-      r.cursor = Range.comparePoints(r.start, head) ? r.end : r.start;
-      return r;
-    });
-    
-    if (this.ace.inVirtualSelectionMode) {
-      this.ace.selection.fromOrientedRange(ranges[0]);
-      return;
-    }
-    if (!primIndex) {
-        ranges = ranges.reverse();
-    } else if (ranges[primIndex]) {
-       ranges.push(ranges.splice(primIndex, 1)[0]);
-    }
-    sel.toSingleRange(ranges[0].clone());
-    var session = this.ace.session;
-    for (var i = 0; i < ranges.length; i++) {
-      var range = session.$clipRangeToDocument(ranges[i]); // todo why ace doesn't do this?
-      sel.addRange(range);
-    }
-  };
-  this.setSelection = function(a, h, options) {
-    var sel = this.ace.selection;
-    sel.moveTo(a.line, a.ch);
-    sel.selectTo(h.line, h.ch);
-    if (options && options.origin == '*mouse') {
-      this.onBeforeEndOperation();
-    }
-  };
-  this.somethingSelected = function(p) {
-    return !this.ace.selection.isEmpty();
-  };
-  this.clipPos = function(p) {
-    var pos = this.ace.session.$clipPositionToDocument(p.line, p.ch);
-    return toCmPos(pos);
-  };
-  this.markText = function(cursor) {
-    return {clear: function() {}, find: function() {}};
-  };
-  this.$updateMarkers = function(delta) {
-    var isInsert = delta.action == "insert";
-    var start = delta.start;
-    var end = delta.end;
-    var rowShift = (end.row - start.row) * (isInsert ? 1 : -1);
-    var colShift = (end.column - start.column) * (isInsert ? 1 : -1);
-    if (isInsert) end = start;
-    
-    for (var i in this.marks) {
-      var point = this.marks[i];
-      var cmp = Range.comparePoints(point, start);
-      if (cmp < 0) {
-        continue; // delta starts after the range
-      }
-      if (cmp === 0) {
-        if (isInsert) {
-          if (point.bias == 1) {
-            cmp = 1;
-          } else {
-            point.bias == -1;
-            continue;
-          }
-        }
-      }
-      var cmp2 = isInsert ? cmp : Range.comparePoints(point, end);
-      if (cmp2 > 0) {
-        point.row += rowShift;
-        point.column += point.row == end.row ? colShift : 0;
-        continue;
-      }
-      if (!isInsert && cmp2 <= 0) {
-        point.row = start.row;
-        point.column = start.column;
-        if (cmp2 === 0)
-          point.bias = 1
-      }
-    }
-  };
-  var Marker = function(cm, id, row, column) {
-    this.cm = cm;
-    this.id = id;
-    this.row = row;
-    this.column = column;
-    cm.marks[this.id] = this;
-  };
-  Marker.prototype.clear = function() { delete this.cm.marks[this.id] };
-  Marker.prototype.find = function() { return toCmPos(this) };
-  this.setBookmark = function(cursor, options) {
-    var bm = new Marker(this, this.$uid++, cursor.line, cursor.ch);
-    if (!options || !options.insertLeft)
-      bm.$insertRight = true;
-    this.marks[bm.id] = bm;
-    return bm;
-  };
-  this.moveH = function(increment, unit) {
-    if (unit == 'char') {
-      var sel = this.ace.selection;
-      sel.clearSelection();
-      sel.moveCursorBy(0, increment);
-    }
-  };
-  this.findPosV = function(start, amaount, unit, goalColumn) {
-    if (unit == 'line') {
-      var screenPos = this.ace.session.documentToScreenPosition(start.line, start.ch);
-      if (goalColumn != null)
-        screenPos.column = goalColumn;
-      screenPos.row += amaount;
-      screenPos.row = Math.min(Math.max(0, screenPos.row), this.ace.session.getScreenLength() - 1);
-      var pos = this.ace.session.screenToDocumentPosition(screenPos.row, screenPos.column);
-      return toCmPos(pos);
-    } else {
-      debugger;
-    }
-  };
-  this.charCoords = function(pos, mode) {
-    if (mode == 'div' || !mode) {
-      var sc = this.ace.session.documentToScreenPosition(pos.line, pos.ch);
-      return {left: sc.column, top: sc.row};
-    }if (mode == 'local') {
-      var renderer = this.ace.renderer;
-      var sc = this.ace.session.documentToScreenPosition(pos.line, pos.ch);
-      var lh = renderer.layerConfig.lineHeight;
-      var cw = renderer.layerConfig.characterWidth;
-      var top = lh * sc.row;
-      return {left: sc.column * cw, top: top, bottom: top + lh};
-    }
-  };
-  this.coordsChar = function(pos, mode) {
-    var renderer = this.ace.renderer;
-    if (mode == 'local') {
-      var row = Math.max(0, Math.floor(pos.top / renderer.lineHeight));
-      var col = Math.max(0, Math.floor(pos.left / renderer.characterWidth));
-      var ch = renderer.session.screenToDocumentPosition(row, col);
-      return toCmPos(ch);
-    } else if (mode == 'div') {
-      throw "not implemented";
-    }
-  };
-  this.openDialog = function() { 
-    debugger
-  };
-  this.getSearchCursor = function(query, pos, caseFold) {
-    var caseSensitive = false;
-    var isRegexp = false;
-    if (query instanceof RegExp && !query.global) {
-      caseSensitive = !query.ignoreCase;
-      query = query.source;
-      isRegexp = true;
-    }
-    var search = new Search();
-    if (pos.ch == undefined) pos.ch = Number.MAX_VALUE;
-    var acePos = {row: pos.line, column: pos.ch};
-    var cm = this;
-    var last = null;
-    return {
-      findNext: function() { return this.find(false) },
-      findPrevious: function() {return this.find(true) },
-      find: function(back) {
-        search.setOptions({
-          needle: query,
-          caseSensitive: caseSensitive,
-          wrap: false,
-          backwards: back,
-          regExp: isRegexp,
-          start: last || acePos
-        });
-        var range = search.find(cm.ace.session);
-        if (range && range.isEmpty()) {
-          if (cm.getLine(range.start.row).length == range.start.column) {
-            search.$options.start = range;
-            range = search.find(cm.ace.session);
-          }
-        }
-        last = range;
-        return last;
-      },
-      from: function() { return last && toCmPos(last.start) },
-      to: function() { return last && toCmPos(last.end) },
-      replace: function(text) {
-        if (last) {
-          last.end = cm.ace.session.doc.replace(last, text);
-        }
-      }
-    };
-  };
-  this.scrollTo = function(x, y) {
-    var renderer = this.ace.renderer;
-    var config = renderer.layerConfig;
-    var maxHeight = config.maxHeight;
-    maxHeight -= (renderer.$size.scrollerHeight - renderer.lineHeight) * renderer.$scrollPastEnd;
-    if (y != null) this.ace.session.setScrollTop(Math.max(0, Math.min(y, maxHeight)));
-    if (x != null) this.ace.session.setScrollLeft(Math.max(0, Math.min(x, config.width)));
-  };
-  this.scrollInfo = function() { return 0; };
-  this.scrollIntoView = function(pos, margin) {
-    if (pos)
-      this.ace.renderer.scrollCursorIntoView(toAcePos(pos), null, margin);
-  };
-  this.getLine = function(row) { return this.ace.session.getLine(row) };
-  this.getRange = function(s, e) {
-    return this.ace.session.getTextRange(new Range(s.line, s.ch, e.line, e.ch));
-  };
-  this.replaceRange = function(text, s, e) {
-    if (!e) e = s;
-    return this.ace.session.replace(new Range(s.line, s.ch, e.line, e.ch), text);
-  };
-  this.replaceSelections = function(p) {
-    var sel = this.ace.selection;
-    if (this.ace.inVirtualSelectionMode) {
-      this.ace.session.replace(sel.getRange(), p[0] || "");
-      return;
-    }
-    sel.inVirtualSelectionMode = true;
-    var ranges = sel.rangeList.ranges;
-    if (!ranges.length) ranges = [this.ace.multiSelect.getRange()];
-    for (var i = ranges.length; i--;)
-       this.ace.session.replace(ranges[i], p[i] || "");
-    sel.inVirtualSelectionMode = false;
-  };
-  this.getSelection = function() {
-    return this.ace.getSelectedText();
-  };
-  this.getSelections = function() {
-    return this.listSelections().map(function(x) {
-      return this.getRange(x.anchor, x.head);
-    }, this);
-  };
-  this.getInputField = function() {
-    return this.ace.textInput.getElement();
-  };
-  this.getWrapperElement = function() {
-    return this.ace.containter;
-  };
-  var optMap = {
-    indentWithTabs: "useSoftTabs",
-    indentUnit: "tabSize",
-    firstLineNumber: "firstLineNumber"
-  };
-  this.setOption = function(name, val) {
-    this.state[name] = val;
-    switch (name) {
-      case 'indentWithTabs':
-        name = optMap[name];
-        val = !val;
-      break;
-      default:
-        name = optMap[name];
-    }
-    if (name)
-      this.ace.setOption(name, val);
-  };
-  this.getOption = function(name, val) {
-    var aceOpt = optMap[name];
-    if (aceOpt)
-      val = this.ace.getOption(aceOpt);
-    switch (name) {
-      case 'indentWithTabs':
-        name = optMap[name];
-        return !val;
-    }
-    return aceOpt ? val : this.state[name];
-  };
-  this.toggleOverwrite = function(on) {
-    this.state.overwrite = on;
-    return this.ace.setOverwrite(on);
-  };
-  this.addOverlay = function(o) {
-    if (!this.$searchHighlight || !this.$searchHighlight.session) {
-      var highlight = new SearchHighlight(null, "ace_highlight-marker", "text");
-      var marker = this.ace.session.addDynamicMarker(highlight);
-      highlight.id = marker.id;
-      highlight.session = this.ace.session;
-      highlight.destroy = function(o) {
-        highlight.session.off("change", highlight.updateOnChange);
-        highlight.session.off("changeEditor", highlight.destroy);
-        highlight.session.removeMarker(highlight.id);
-        highlight.session = null;
-      };
-      highlight.updateOnChange = function(delta) {
-        delta = delta.data.range;// v1.2 api compatibility
-        var row = delta.start.row;
-        if (row == delta.end.row) highlight.cache[row] = undefined;
-        else highlight.cache.splice(row, highlight.cache.length);
-      }
-      highlight.session.on("changeEditor", highlight.destroy);
-      highlight.session.on("change", highlight.updateOnChange);
-    }
-    var re = new RegExp(o.query.source, "gmi");
-    console.log(re)
-    this.$searchHighlight = o.highlight = highlight;
-    this.$searchHighlight.setRegexp(re);
-    this.ace.renderer.updateBackMarkers();
-  };
-  this.removeOverlay = function(o) {
-    if (this.$searchHighlight && this.$searchHighlight.session) {
-      this.$searchHighlight.destroy();
-    }
-  };
-  this.getScrollInfo = function() {
-    var renderer = this.ace.renderer;
-    var config = renderer.layerConfig;
-    return {
-      left: renderer.scrollLeft,
-      top: renderer.scrollTop,
-      height: config.maxHeight,
-      width: config.width,
-      clientHeight: config.height,
-      clientWidth: config.width
-    };
-  };
-  this.getValue = function() {
-    return this.ace.getValue();
-  };
-  this.setValue = function(v) {
-    return this.ace.setValue(v);
-  };
-  this.getTokenTypeAt = function(pos) {
-    var token = this.ace.session.getTokenAt(pos.line, pos.ch);
-    return token && /comment|string/.test(token.type) ? "string" : "";
-  };
-  this.findMatchingBracket = function(pos) {
-    var m = this.ace.session.findMatchingBracket(toAcePos(pos));
-    return {to: m && toCmPos(m)};
-  };
-  this.indentLine = function(line, method) {
-    if (method === true)
-        this.ace.session.indentRows(line, line, "\t");
-    else if (method === false)
-        this.ace.session.outdentRows(new Range(line, 0, line, 0));
-  };
-  this.indexFromPos = function(pos) {
-    return this.ace.session.doc.positionToIndex(toAcePos(pos));
-  };
-  this.posFromIndex = function(index) {
-    return toCmPos(this.ace.session.doc.indexToPosition(index));
-  };
-  this.focus = function(index) {
-    return this.ace.focus();
-  };
-  this.blur = function(index) {
-    return this.ace.blur();
-  };
-  this.defaultTextHeight = function(index) {
-    return this.ace.renderer.layerConfig.lineHeight;
-  };
-  this.scanForBracket = function(pos, dir, _, options) {
-    var re = options.bracketRegex.source;
-    if (dir == 1) {
-      var m = this.ace.session.$findClosingBracket(re.slice(1, 2), toAcePos(pos), /paren|text/);
-    } else {
-      var m = this.ace.session.$findOpeningBracket(re.slice(-2, -1), {row: pos.line, column: pos.ch + 1}, /paren|text/);
-    }
-    return m && {pos: toCmPos(m)};
-  };
-  this.refresh = function() {
-    return this.ace.resize(true);
-  };
-}).call(CodeMirror.prototype);
-  function toAcePos(cmPos) {
-    return {row: cmPos.line, column: cmPos.ch};
-  }
-  function toCmPos(acePos) {
-    return new Pos(acePos.row, acePos.column);
-  }
-
-  var StringStream = CodeMirror.StringStream = function(string, tabSize) {
-    this.pos = this.start = 0;
-    this.string = string;
-    this.tabSize = tabSize || 8;
-    this.lastColumnPos = this.lastColumnValue = 0;
-    this.lineStart = 0;
-  };
-
-  StringStream.prototype = {
-    eol: function() {return this.pos >= this.string.length;},
-    sol: function() {return this.pos == this.lineStart;},
-    peek: function() {return this.string.charAt(this.pos) || undefined;},
-    next: function() {
-      if (this.pos < this.string.length)
-        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() {
-      throw "not implemented";
-    },
-    indentation: function() {
-      throw "not implemented";
-    },
-    match: function(pattern, consume, caseInsensitive) {
-      if (typeof pattern == "string") {
-        var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
-        var substr = this.string.substr(this.pos, pattern.length);
-        if (cased(substr) == cased(pattern)) {
-          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);},
-    hideFirstChars: function(n, inner) {
-      this.lineStart += n;
-      try { return inner(); }
-      finally { this.lineStart -= n; }
-    }
-  };
-CodeMirror.defineExtension = function(name, fn) {
-  CodeMirror.prototype[name] = fn;
-};
-dom.importCssString(".normal-mode .ace_cursor{\
-  border: 0!important;\
-  background-color: red;\
-  opacity: 0.5;\
-}.ace_dialog {\
-  position: absolute;\
-  left: 0; right: 0;\
-  background: white;\
-  z-index: 15;\
-  padding: .1em .8em;\
-  overflow: hidden;\
-  color: #333;\
-}\
-.ace_dialog-top {\
-  border-bottom: 1px solid #eee;\
-  top: 0;\
-}\
-.ace_dialog-bottom {\
-  border-top: 1px solid #eee;\
-  bottom: 0;\
-}\
-.ace_dialog input {\
-  border: none;\
-  outline: none;\
-  background: transparent;\
-  width: 20em;\
-  color: inherit;\
-  font-family: monospace;\
-}", "vimMode");
-(function() {
-  function dialogDiv(cm, template, bottom) {
-    var wrap = cm.ace.container;
-    var dialog;
-    dialog = wrap.appendChild(document.createElement("div"));
-    if (bottom)
-      dialog.className = "ace_dialog ace_dialog-bottom";
-    else
-      dialog.className = "ace_dialog ace_dialog-top";
-
-    if (typeof template == "string") {
-      dialog.innerHTML = template;
-    } else { // Assuming it's a detached DOM element.
-      dialog.appendChild(template);
-    }
-    return dialog;
-  }
-
-  function closeNotification(cm, newVal) {
-    if (cm.state.currentNotificationClose)
-      cm.state.currentNotificationClose();
-    cm.state.currentNotificationClose = newVal;
-  }
-
-  CodeMirror.defineExtension("openDialog", function(template, callback, options) {
-    if (this.virtualSelectionMode()) return;
-    if (!options) options = {};
-
-    closeNotification(this, null);
-
-    var dialog = dialogDiv(this, template, options.bottom);
-    var closed = false, me = this;
-    function close(newVal) {
-      if (typeof newVal == 'string') {
-        inp.value = newVal;
-      } else {
-        if (closed) return;
-        closed = true;
-        dialog.parentNode.removeChild(dialog);
-        me.focus();
-
-        if (options.onClose) options.onClose(dialog);
-      }
-    }
-
-    var inp = dialog.getElementsByTagName("input")[0], button;
-    if (inp) {
-      if (options.value) {
-        inp.value = options.value;
-        inp.select();
-      }
-
-      if (options.onInput)
-        CodeMirror.on(inp, "input", function(e) { options.onInput(e, inp.value, close);});
-      if (options.onKeyUp)
-        CodeMirror.on(inp, "keyup", function(e) {options.onKeyUp(e, inp.value, close);});
-
-      CodeMirror.on(inp, "keydown", function(e) {
-        if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
-        if (e.keyCode == 27 || (options.closeOnEnter !== false && e.keyCode == 13)) {
-          inp.blur();
-          CodeMirror.e_stop(e);
-          close();
-        }
-        if (e.keyCode == 13) callback(inp.value);
-      });
-
-      if (options.closeOnBlur !== false) CodeMirror.on(inp, "blur", close);
-
-      inp.focus();
-    } else if (button = dialog.getElementsByTagName("button")[0]) {
-      CodeMirror.on(button, "click", function() {
-        close();
-        me.focus();
-      });
-
-      if (options.closeOnBlur !== false) CodeMirror.on(button, "blur", close);
-
-      button.focus();
-    }
-    return close;
-  });
-
-  CodeMirror.defineExtension("openNotification", function(template, options) {
-    if (this.virtualSelectionMode()) return;
-    closeNotification(this, close);
-    var dialog = dialogDiv(this, template, options && options.bottom);
-    var closed = false, doneTimer;
-    var duration = options && typeof options.duration !== "undefined" ? options.duration : 5000;
-
-    function close() {
-      if (closed) return;
-      closed = true;
-      clearTimeout(doneTimer);
-      dialog.parentNode.removeChild(dialog);
-    }
-
-    CodeMirror.on(dialog, 'click', function(e) {
-      CodeMirror.e_preventDefault(e);
-      close();
-    });
-
-    if (duration)
-      doneTimer = setTimeout(close, duration);
-
-    return close;
-  });
-})();
-
-  
-  var defaultKeymap = [
-    { keys: '<Left>', type: 'keyToKey', toKeys: 'h' },
-    { keys: '<Right>', type: 'keyToKey', toKeys: 'l' },
-    { keys: '<Up>', type: 'keyToKey', toKeys: 'k' },
-    { keys: '<Down>', type: 'keyToKey', toKeys: 'j' },
-    { keys: '<Space>', type: 'keyToKey', toKeys: 'l' },
-    { keys: '<BS>', type: 'keyToKey', toKeys: 'h' },
-    { keys: '<C-Space>', type: 'keyToKey', toKeys: 'W' },
-    { keys: '<C-BS>', type: 'keyToKey', toKeys: 'B' },
-    { keys: '<S-Space>', type: 'keyToKey', toKeys: 'w' },
-    { keys: '<S-BS>', type: 'keyToKey', toKeys: 'b' },
-    { keys: '<C-n>', type: 'keyToKey', toKeys: 'j' },
-    { keys: '<C-p>', type: 'keyToKey', toKeys: 'k' },
-    { keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>' },
-    { keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>' },
-    { keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' },
-    { keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' },
-    { keys: 's', type: 'keyToKey', toKeys: 'cl', context: 'normal' },
-    { keys: 's', type: 'keyToKey', toKeys: 'xi', context: 'visual'},
-    { keys: 'S', type: 'keyToKey', toKeys: 'cc', context: 'normal' },
-    { keys: 'S', type: 'keyToKey', toKeys: 'dcc', context: 'visual' },
-    { keys: '<Home>', type: 'keyToKey', toKeys: '0' },
-    { keys: '<End>', type: 'keyToKey', toKeys: '$' },
-    { keys: '<PageUp>', type: 'keyToKey', toKeys: '<C-b>' },
-    { keys: '<PageDown>', type: 'keyToKey', toKeys: '<C-f>' },
-    { keys: '<CR>', type: 'keyToKey', toKeys: 'j^', context: 'normal' },
-    { keys: 'H', type: 'motion', motion: 'moveToTopLine', motionArgs: { linewise: true, toJumplist: true }},
-    { keys: 'M', type: 'motion', motion: 'moveToMiddleLine', motionArgs: { linewise: true, toJumplist: true }},
-    { keys: 'L', type: 'motion', motion: 'moveToBottomLine', motionArgs: { linewise: true, toJumplist: true }},
-    { keys: 'h', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: false }},
-    { keys: 'l', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: true }},
-    { keys: 'j', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, linewise: true }},
-    { keys: 'k', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, linewise: true }},
-    { keys: 'gj', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: true }},
-    { keys: 'gk', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: false }},
-    { keys: 'w', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false }},
-    { keys: 'W', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false, bigWord: true }},
-    { keys: 'e', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, inclusive: true }},
-    { keys: 'E', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, bigWord: true, inclusive: true }},
-    { keys: 'b', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }},
-    { keys: 'B', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false, bigWord: true }},
-    { keys: 'ge', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, inclusive: true }},
-    { keys: 'gE', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, bigWord: true, inclusive: true }},
-    { keys: '{', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: false, toJumplist: true }},
-    { keys: '}', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: true, toJumplist: true }},
-    { keys: '<C-f>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: true }},
-    { keys: '<C-b>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: false }},
-    { keys: '<C-d>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: true, explicitRepeat: true }},
-    { keys: '<C-u>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: false, explicitRepeat: true }},
-    { keys: 'gg', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: false, explicitRepeat: true, linewise: true, toJumplist: true }},
-    { keys: 'G', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: true, explicitRepeat: true, linewise: true, toJumplist: true }},
-    { keys: '0', type: 'motion', motion: 'moveToStartOfLine' },
-    { keys: '^', type: 'motion', motion: 'moveToFirstNonWhiteSpaceCharacter' },
-    { keys: '+', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar:true }},
-    { keys: '-', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, toFirstChar:true }},
-    { keys: '_', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar:true, repeatOffset:-1 }},
-    { keys: '$', type: 'motion', motion: 'moveToEol', motionArgs: { inclusive: true }},
-    { keys: '%', type: 'motion', motion: 'moveToMatchedSymbol', motionArgs: { inclusive: true, toJumplist: true }},
-    { keys: 'f<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: true , inclusive: true }},
-    { keys: 'F<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: false }},
-    { keys: 't<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: true, inclusive: true }},
-    { keys: 'T<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: false }},
-    { keys: ';', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: true }},
-    { keys: ',', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: false }},
-    { keys: '\'<character>', type: 'motion', motion: 'goToMark', motionArgs: {toJumplist: true, linewise: true}},
-    { keys: '`<character>', type: 'motion', motion: 'goToMark', motionArgs: {toJumplist: true}},
-    { keys: ']`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true } },
-    { keys: '[`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false } },
-    { keys: ']\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true, linewise: true } },
-    { keys: '[\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false, linewise: true } },
-    { keys: ']p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true, matchIndent: true}},
-    { keys: '[p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true, matchIndent: true}},
-    { keys: ']<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: true, toJumplist: true}},
-    { keys: '[<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: false, toJumplist: true}},
-    { keys: '|', type: 'motion', motion: 'moveToColumn'},
-    { keys: 'o', type: 'motion', motion: 'moveToOtherHighlightedEnd', context:'visual'},
-    { keys: 'O', type: 'motion', motion: 'moveToOtherHighlightedEnd', motionArgs: {sameLine: true}, context:'visual'},
-    { keys: 'd', type: 'operator', operator: 'delete' },
-    { keys: 'y', type: 'operator', operator: 'yank' },
-    { keys: 'c', type: 'operator', operator: 'change' },
-    { keys: '>', type: 'operator', operator: 'indent', operatorArgs: { indentRight: true }},
-    { keys: '<', type: 'operator', operator: 'indent', operatorArgs: { indentRight: false }},
-    { keys: 'g~', type: 'operator', operator: 'changeCase' },
-    { keys: 'gu', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, isEdit: true },
-    { keys: 'gU', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, isEdit: true },
-    { keys: 'n', type: 'motion', motion: 'findNext', motionArgs: { forward: true, toJumplist: true }},
-    { keys: 'N', type: 'motion', motion: 'findNext', motionArgs: { forward: false, toJumplist: true }},
-    { keys: 'x', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorMotionArgs: { visualLine: false }},
-    { keys: 'X', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: false }, operatorMotionArgs: { visualLine: true }},
-    { keys: 'D', type: 'operatorMotion', operator: 'delete', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
-    { keys: 'D', type: 'operator', operator: 'delete', operatorArgs: { linewise: true }, context: 'visual'},
-    { keys: 'Y', type: 'operatorMotion', operator: 'yank', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
-    { keys: 'Y', type: 'operator', operator: 'yank', operatorArgs: { linewise: true }, context: 'visual'},
-    { keys: 'C', type: 'operatorMotion', operator: 'change', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
-    { keys: 'C', type: 'operator', operator: 'change', operatorArgs: { linewise: true }, context: 'visual'},
-    { keys: '~', type: 'operatorMotion', operator: 'changeCase', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorArgs: { shouldMoveCursor: true }, context: 'normal'},
-    { keys: '~', type: 'operator', operator: 'changeCase', context: 'visual'},
-    { keys: '<C-w>', type: 'operatorMotion', operator: 'delete', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }, context: 'insert' },
-    { keys: '<C-i>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: true }},
-    { keys: '<C-o>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: false }},
-    { keys: '<C-e>', type: 'action', action: 'scroll', actionArgs: { forward: true, linewise: true }},
-    { keys: '<C-y>', type: 'action', action: 'scroll', actionArgs: { forward: false, linewise: true }},
-    { keys: 'a', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'charAfter' }, context: 'normal' },
-    { keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'eol' }, context: 'normal' },
-    { keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'endOfSelectedArea' }, context: 'visual' },
-    { keys: 'i', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'inplace' }, context: 'normal' },
-    { keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'firstNonBlank'}, context: 'normal' },
-    { keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'startOfSelectedArea' }, context: 'visual' },
-    { keys: 'o', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: true }, context: 'normal' },
-    { keys: 'O', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: false }, context: 'normal' },
-    { keys: 'v', type: 'action', action: 'toggleVisualMode' },
-    { keys: 'V', type: 'action', action: 'toggleVisualMode', actionArgs: { linewise: true }},
-    { keys: '<C-v>', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true }},
-    { keys: 'gv', type: 'action', action: 'reselectLastSelection' },
-    { keys: 'J', type: 'action', action: 'joinLines', isEdit: true },
-    { keys: 'p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true }},
-    { keys: 'P', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true }},
-    { keys: 'r<character>', type: 'action', action: 'replace', isEdit: true },
-    { keys: '@<character>', type: 'action', action: 'replayMacro' },
-    { keys: 'q<character>', type: 'action', action: 'enterMacroRecordMode' },
-    { keys: 'R', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { replace: true }},
-    { keys: 'u', type: 'action', action: 'undo', context: 'normal' },
-    { keys: 'u', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, context: 'visual', isEdit: true },
-    { keys: 'U', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, context: 'visual', isEdit: true },
-    { keys: '<C-r>', type: 'action', action: 'redo' },
-    { keys: 'm<character>', type: 'action', action: 'setMark' },
-    { keys: '"<character>', type: 'action', action: 'setRegister' },
-    { keys: 'zz', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }},
-    { keys: 'z.', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
-    { keys: 'zt', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }},
-    { keys: 'z<CR>', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
-    { keys: 'z-', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' }},
-    { keys: 'zb', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
-    { keys: '.', type: 'action', action: 'repeatLastEdit' },
-    { keys: '<C-a>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: {increase: true, backtrack: false}},
-    { keys: '<C-x>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: {increase: false, backtrack: false}},
-    { keys: 'a<character>', type: 'motion', motion: 'textObjectManipulation' },
-    { keys: 'i<character>', type: 'motion', motion: 'textObjectManipulation', motionArgs: { textObjectInner: true }},
-    { keys: '/', type: 'search', searchArgs: { forward: true, querySrc: 'prompt', toJumplist: true }},
-    { keys: '?', type: 'search', searchArgs: { forward: false, querySrc: 'prompt', toJumplist: true }},
-    { keys: '*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
-    { keys: '#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
-    { keys: 'g*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true }},
-    { keys: 'g#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true }},
-    { keys: ':', type: 'ex' }
-  ];
-
-  var Pos = CodeMirror.Pos;
-
-  var modifierCodes = [16, 17, 18, 91];
-  var specialKey = {Enter:'CR',Backspace:'BS',Delete:'Del'};
-  var mac = /Mac/.test(navigator.platform);
-  var Vim = function() { return vimApi; } //{
-    function lookupKey(e) {
-      var keyCode = e.keyCode;
-      if (modifierCodes.indexOf(keyCode) != -1) { return; }
-      var hasModifier = e.ctrlKey || e.metaKey;
-      var key = CodeMirror.keyNames[keyCode];
-      key = specialKey[key] || key;
-      var name = '';
-      if (e.ctrlKey) { name += 'C-'; }
-      if (e.altKey) { name += 'A-'; }
-      if (mac && e.metaKey || (!hasModifier && e.shiftKey) && key.length < 2) {
-        return;
-      } else if (e.shiftKey && !/^[A-Za-z]$/.test(key)) {
-        name += 'S-';
-      }
-      if (key.length == 1) { key = key.toLowerCase(); }
-      name += key;
-      if (name.length > 1) { name = '<' + name + '>'; }
-      return name;
-    }
-    function handleKeyDown(cm, e) {
-      var name = lookupKey(e);
-      if (!name) { return; }
-
-      CodeMirror.signal(cm, 'vim-keypress', name);
-      if (CodeMirror.Vim.handleKey(cm, name, 'user')) {
-        CodeMirror.e_stop(e);
-      }
-    }
-    function handleKeyPress(cm, e) {
-      var code = e.charCode || e.keyCode;
-      if (e.ctrlKey || e.metaKey || e.altKey ||
-          e.shiftKey && code < 32) { return; }
-      var name = String.fromCharCode(code);
-
-      CodeMirror.signal(cm, 'vim-keypress', name);
-      if (CodeMirror.Vim.handleKey(cm, name, 'user')) {
-        CodeMirror.e_stop(e);
-      }
-    }
-
-    function enterVimMode(cm) {
-      cm.setOption('disableInput', true);
-      cm.setOption('showCursorWhenSelecting', false);
-      CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
-      cm.on('cursorActivity', onCursorActivity);
-      maybeInitVimState(cm);
-      CodeMirror.on(cm.getInputField(), 'paste', getOnPasteFn(cm));
-      cm.on('keypress', handleKeyPress);
-      cm.on('keydown', handleKeyDown);
-    }
-
-    function leaveVimMode(cm) {
-      cm.setOption('disableInput', false);
-      cm.off('cursorActivity', onCursorActivity);
-      CodeMirror.off(cm.getInputField(), 'paste', getOnPasteFn(cm));
-      cm.state.vim = null;
-      cm.off('keypress', handleKeyPress);
-      cm.off('keydown', handleKeyDown);
-    }
-
-    function detachVimMap(cm, next) {
-      if (this == CodeMirror.keyMap.vim)
-        CodeMirror.rmClass(cm.getWrapperElement(), "cm-fat-cursor");
-
-      if (!next || next.attach != attachVimMap)
-        leaveVimMode(cm, false);
-    }
-    function attachVimMap(cm, prev) {
-      if (this == CodeMirror.keyMap.vim)
-        CodeMirror.addClass(cm.getWrapperElement(), "cm-fat-cursor");
-
-      if (!prev || prev.attach != attachVimMap)
-        enterVimMode(cm);
-    }
-    CodeMirror.defineOption('vimMode', false, function(cm, val, prev) {
-      if (val && cm.getOption("keyMap") != "vim")
-        cm.setOption("keyMap", "vim");
-      else if (!val && prev != CodeMirror.Init && /^vim/.test(cm.getOption("keyMap")))
-        cm.setOption("keyMap", "default");
-    });
-    function getOnPasteFn(cm) {
-      var vim = cm.state.vim;
-      if (!vim.onPasteFn) {
-        vim.onPasteFn = function() {
-          if (!vim.insertMode) {
-            cm.setCursor(offsetCursor(cm.getCursor(), 0, 1));
-            actions.enterInsertMode(cm, {}, vim);
-          }
-        };
-      }
-      return vim.onPasteFn;
-    }
-
-    var numberRegex = /[\d]/;
-    var wordRegexp = [(/\w/), (/[^\w\s]/)], bigWordRegexp = [(/\S/)];
-    function makeKeyRange(start, size) {
-      var keys = [];
-      for (var i = start; i < start + size; i++) {
-        keys.push(String.fromCharCode(i));
-      }
-      return keys;
-    }
-    var upperCaseAlphabet = makeKeyRange(65, 26);
-    var lowerCaseAlphabet = makeKeyRange(97, 26);
-    var numbers = makeKeyRange(48, 10);
-    var validMarks = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['<', '>']);
-    var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"', '.', ':', '/']);
-
-    function isLine(cm, line) {
-      return line >= cm.firstLine() && line <= cm.lastLine();
-    }
-    function isLowerCase(k) {
-      return (/^[a-z]$/).test(k);
-    }
-    function isMatchableSymbol(k) {
-      return '()[]{}'.indexOf(k) != -1;
-    }
-    function isNumber(k) {
-      return numberRegex.test(k);
-    }
-    function isUpperCase(k) {
-      return (/^[A-Z]$/).test(k);
-    }
-    function isWhiteSpaceString(k) {
-      return (/^\s*$/).test(k);
-    }
-    function inArray(val, arr) {
-      for (var i = 0; i < arr.length; i++) {
-        if (arr[i] == val) {
-          return true;
-        }
-      }
-      return false;
-    }
-
-    var options = {};
-    function defineOption(name, defaultValue, type) {
-      if (defaultValue === undefined) { throw Error('defaultValue is required'); }
-      if (!type) { type = 'string'; }
-      var opt = name;
-      if (typeof name == "string")
-        opt = {
-          type: type,
-          defaultValue: defaultValue
-        };
-      else
-        name = opt.name;
-      options[name] = opt;
-      setOption(name, defaultValue);
-    }
-
-    function setOption(name, value, cm) {
-      var option = options[name];
-      if (!option) {
-        throw Error('Unknown option: ' + name);
-      }
-      if (option.type == 'boolean') {
-        if (value && value !== true) {
-          throw Error('Invalid argument: ' + name + '=' + value);
-        } else if (value !== false) {
-          value = true;
-        }
-      }
-      option.value = value;
-      if (option.set) option.set(value, cm);
-    }
-
-    function getOption(name) {
-      var option = options[name];
-      if (!option) {
-        throw Error('Unknown option: ' + name);
-      }
-      return option.value;
-    }
-
-    var createCircularJumpList = function() {
-      var size = 100;
-      var pointer = -1;
-      var head = 0;
-      var tail = 0;
-      var buffer = new Array(size);
-      function add(cm, oldCur, newCur) {
-        var current = pointer % size;
-        var curMark = buffer[current];
-        function useNextSlot(cursor) {
-          var next = ++pointer % size;
-          var trashMark = buffer[next];
-          if (trashMark) {
-            trashMark.clear();
-          }
-          buffer[next] = cm.setBookmark(cursor);
-        }
-        if (curMark) {
-          var markPos = curMark.find();
-          if (markPos && !cursorEqual(markPos, oldCur)) {
-            useNextSlot(oldCur);
-          }
-        } else {
-          useNextSlot(oldCur);
-        }
-        useNextSlot(newCur);
-        head = pointer;
-        tail = pointer - size + 1;
-        if (tail < 0) {
-          tail = 0;
-        }
-      }
-      function move(cm, offset) {
-        pointer += offset;
-        if (pointer > head) {
-          pointer = head;
-        } else if (pointer < tail) {
-          pointer = tail;
-        }
-        var mark = buffer[(size + pointer) % size];
-        if (mark && !mark.find()) {
-          var inc = offset > 0 ? 1 : -1;
-          var newCur;
-          var oldCur = cm.getCursor();
-          do {
-            pointer += inc;
-            mark = buffer[(size + pointer) % size];
-            if (mark &&
-                (newCur = mark.find()) &&
-                !cursorEqual(oldCur, newCur)) {
-              break;
-            }
-          } while (pointer < head && pointer > tail);
-        }
-        return mark;
-      }
-      return {
-        cachedCursor: undefined, //used for # and * jumps
-        add: add,
-        move: move
-      };
-    };
-    var createInsertModeChanges = function(c) {
-      if (c) {
-        return {
-          changes: c.changes,
-          expectCursorActivityForChange: c.expectCursorActivityForChange
-        };
-      }
-      return {
-        changes: [],
-        expectCursorActivityForChange: false
-      };
-    };
-
-    function MacroModeState() {
-      this.latestRegister = undefined;
-      this.isPlaying = false;
-      this.isRecording = false;
-      this.replaySearchQueries = [];
-      this.onRecordingDone = undefined;
-      this.lastInsertModeChanges = createInsertModeChanges();
-    }
-    MacroModeState.prototype = {
-      exitMacroRecordMode: function() {
-        var macroModeState = vimGlobalState.macroModeState;
-        if (macroModeState.onRecordingDone) {
-          macroModeState.onRecordingDone(); // close dialog
-        }
-        macroModeState.onRecordingDone = undefined;
-        macroModeState.isRecording = false;
-      },
-      enterMacroRecordMode: function(cm, registerName) {
-        var register =
-            vimGlobalState.registerController.getRegister(registerName);
-        if (register) {
-          register.clear();
-          this.latestRegister = registerName;
-          if (cm.openDialog) {
-            this.onRecordingDone = cm.openDialog(
-                '(recording)['+registerName+']', null, {bottom:true});
-          }
-          this.isRecording = true;
-        }
-      }
-    };
-
-    function maybeInitVimState(cm) {
-      if (!cm.state.vim) {
-        cm.state.vim = {
-          inputState: new InputState(),
-          lastEditInputState: undefined,
-          lastEditActionCommand: undefined,
-          lastHPos: -1,
-          lastHSPos: -1,
-          lastMotion: null,
-          marks: {},
-          fakeCursor: null,
-          insertMode: false,
-          insertModeRepeat: undefined,
-          visualMode: false,
-          visualLine: false,
-          visualBlock: false,
-          lastSelection: null,
-          lastPastedText: null,
-          sel: {
-          }
-        };
-      }
-      return cm.state.vim;
-    }
-    var vimGlobalState;
-    function resetVimGlobalState() {
-      vimGlobalState = {
-        searchQuery: null,
-        searchIsReversed: false,
-        lastSubstituteReplacePart: undefined,
-        jumpList: createCircularJumpList(),
-        macroModeState: new MacroModeState,
-        lastChararacterSearch: {increment:0, forward:true, selectedCharacter:''},
-        registerController: new RegisterController({}),
-        searchHistoryController: new HistoryController({}),
-        exCommandHistoryController : new HistoryController({})
-      };
-      for (var optionName in options) {
-        var option = options[optionName];
-        option.value = option.defaultValue;
-      }
-    }
-
-    var lastInsertModeKeyTimer;
-    var vimApi= {
-      buildKeyMap: function() {
-      },
-      getRegisterController: function() {
-        return vimGlobalState.registerController;
-      },
-      resetVimGlobalState_: resetVimGlobalState,
-      getVimGlobalState_: function() {
-        return vimGlobalState;
-      },
-      maybeInitVimState_: maybeInitVimState,
-
-      InsertModeKey: InsertModeKey,
-      map: function(lhs, rhs, ctx) {
-        exCommandDispatcher.map(lhs, rhs, ctx);
-      },
-      unmap: function(lhs, ctx) {
-        exCommandDispatcher.unmap(lhs, ctx);
-      },
-      setOption: setOption,
-      getOption: getOption,
-      defineOption: defineOption,
-      defineEx: function(name, prefix, func){
-        if (name.indexOf(prefix) !== 0) {
-          throw new Error('(Vim.defineEx) "'+prefix+'" is not a prefix of "'+name+'", command not registered');
-        }
-        exCommands[name]=func;
-        exCommandDispatcher.commandMap_[prefix]={name:name, shortName:prefix, type:'api'};
-      },
-      handleKey: function(cm, key, origin) {
-        var vim = maybeInitVimState(cm);
-        function handleMacroRecording() {
-          var macroModeState = vimGlobalState.macroModeState;
-          if (macroModeState.isRecording) {
-            if (key == 'q') {
-              macroModeState.exitMacroRecordMode();
-              clearInputState(cm);
-              return true;
-            }
-            if (origin != 'mapping') {
-              logKey(macroModeState, key);
-            }
-          }
-        }
-        function handleEsc() {
-          if (key == '<Esc>') {
-            clearInputState(cm);
-            if (vim.visualMode) {
-              exitVisualMode(cm);
-            } else if (vim.insertMode) {
-              exitInsertMode(cm);
-            }
-            return true;
-          }
-        }
-        function doKeyToKey(keys) {
-          var match;
-          while (keys) {
-            match = (/<\w+-.+?>|<\w+>|./).exec(keys);
-            key = match[0];
-            keys = keys.substring(match.index + key.length);
-            CodeMirror.Vim.handleKey(cm, key, 'mapping');
-          }
-        }
-
-        function handleKeyInsertMode() {
-          if (handleEsc()) { return true; }
-          var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
-          var keysAreChars = key.length == 1;
-          var match = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
-          while (keys.length > 1 && match.type != 'full') {
-            var keys = vim.inputState.keyBuffer = keys.slice(1);
-            var thisMatch = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
-            if (thisMatch.type != 'none') { match = thisMatch; }
-          }
-          if (match.type == 'none') { clearInputState(cm); return false; }
-          else if (match.type == 'partial') {
-            if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
-            lastInsertModeKeyTimer = window.setTimeout(
-              function() { if (vim.insertMode && vim.inputState.keyBuffer) { clearInputState(cm); } },
-              getOption('insertModeEscKeysTimeout'));
-            return !keysAreChars;
-          }
-
-          if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
-          if (keysAreChars) {
-            var here = cm.getCursor();
-            cm.replaceRange('', offsetCursor(here, 0, -(keys.length - 1)), here, '+input');
-          }
-          clearInputState(cm);
-          var command = match.command;
-          if (command.type == 'keyToKey') {
-            doKeyToKey(command.toKeys);
-          } else {
-            commandDispatcher.processCommand(cm, vim, command);
-          }
-          return true;
-        }
-
-        function handleKeyNonInsertMode() {
-          if (handleMacroRecording() || handleEsc()) { return true; };
-
-          var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
-          if (/^[1-9]\d*$/.test(keys)) { return true; }
-
-          var keysMatcher = /^(\d*)(.*)$/.exec(keys);
-          if (!keysMatcher) { clearInputState(cm); return false; }
-          var context = vim.visualMode ? 'visual' :
-                                         'normal';
-          var match = commandDispatcher.matchCommand(keysMatcher[2] || keysMatcher[1], defaultKeymap, vim.inputState, context);
-          if (match.type == 'none') { clearInputState(cm); return false; }
-          else if (match.type == 'partial') { return true; }
-
-          vim.inputState.keyBuffer = '';
-          var command = match.command;
-          var keysMatcher = /^(\d*)(.*)$/.exec(keys);
-          if (keysMatcher[1] && keysMatcher[1] != '0') {
-            vim.inputState.pushRepeatDigit(keysMatcher[1]);
-          }
-          if (command.type == 'keyToKey') {
-            doKeyToKey(command.toKeys);
-          } else {
-            commandDispatcher.processCommand(cm, vim, command);
-          }
-          return true;
-        }
-
-        return cm.operation(function() {
-          cm.curOp.isVimOp = true;
-          try {
-            if (vim.insertMode) { return handleKeyInsertMode(); }
-            else { return handleKeyNonInsertMode(); }
-          } catch (e) {
-            cm.state.vim = undefined;
-            maybeInitVimState(cm);
-            throw e;
-          }
-        });
-      },
-      handleEx: function(cm, input) {
-        exCommandDispatcher.processCommand(cm, input);
-      }
-    };
-    function InputState() {
-      this.prefixRepeat = [];
-      this.motionRepeat = [];
-
-      this.operator = null;
-      this.operatorArgs = null;
-      this.motion = null;
-      this.motionArgs = null;
-      this.keyBuffer = []; // For matching multi-key commands.
-      this.registerName = null; // Defaults to the unnamed register.
-    }
-    InputState.prototype.pushRepeatDigit = function(n) {
-      if (!this.operator) {
-        this.prefixRepeat = this.prefixRepeat.concat(n);
-      } else {
-        this.motionRepeat = this.motionRepeat.concat(n);
-      }
-    };
-    InputState.prototype.getRepeat = function() {
-      var repeat = 0;
-      if (this.prefixRepeat.length > 0 || this.motionRepeat.length > 0) {
-        repeat = 1;
-        if (this.prefixRepeat.length > 0) {
-          repeat *= parseInt(this.prefixRepeat.join(''), 10);
-        }
-        if (this.motionRepeat.length > 0) {
-          repeat *= parseInt(this.motionRepeat.join(''), 10);
-        }
-      }
-      return repeat;
-    };
-
-    function clearInputState(cm, reason) {
-      cm.state.vim.inputState = new InputState();
-      CodeMirror.signal(cm, 'vim-command-done', reason);
-    }
-    function Register(text, linewise, blockwise) {
-      this.clear();
-      this.keyBuffer = [text || ''];
-      this.insertModeChanges = [];
-      this.searchQueries = [];
-      this.linewise = !!linewise;
-      this.blockwise = !!blockwise;
-    }
-    Register.prototype = {
-      setText: function(text, linewise, blockwise) {
-        this.keyBuffer = [text || ''];
-        this.linewise = !!linewise;
-        this.blockwise = !!blockwise;
-      },
-      pushText: function(text, linewise) {
-        if (linewise) {
-          if (!this.linewise) {
-            this.keyBuffer.push('\n');
-          }
-          this.linewise = true;
-        }
-        this.keyBuffer.push(text);
-      },
-      pushInsertModeChanges: function(changes) {
-        this.insertModeChanges.push(createInsertModeChanges(changes));
-      },
-      pushSearchQuery: function(query) {
-        this.searchQueries.push(query);
-      },
-      clear: function() {
-        this.keyBuffer = [];
-        this.insertModeChanges = [];
-        this.searchQueries = [];
-        this.linewise = false;
-      },
-      toString: function() {
-        return this.keyBuffer.join('');
-      }
-    };
-    function RegisterController(registers) {
-      this.registers = registers;
-      this.unnamedRegister = registers['"'] = new Register();
-      registers['.'] = new Register();
-      registers[':'] = new Register();
-      registers['/'] = new Register();
-    }
-    RegisterController.prototype = {
-      pushText: function(registerName, operator, text, linewise, blockwise) {
-        if (linewise && text.charAt(0) == '\n') {
-          text = text.slice(1) + '\n';
-        }
-        if (linewise && text.charAt(text.length - 1) !== '\n'){
-          text += '\n';
-        }
-        var register = this.isValidRegister(registerName) ?
-            this.getRegister(registerName) : null;
-        if (!register) {
-          switch (operator) {
-            case 'yank':
-              this.registers['0'] = new Register(text, linewise, blockwise);
-              break;
-            case 'delete':
-            case 'change':
-              if (text.indexOf('\n') == -1) {
-                this.registers['-'] = new Register(text, linewise);
-              } else {
-                this.shiftNumericRegisters_();
-                this.registers['1'] = new Register(text, linewise);
-              }
-              break;
-          }
-          this.unnamedRegister.setText(text, linewise, blockwise);
-          return;
-        }
-        var append = isUpperCase(registerName);
-        if (append) {
-          register.pushText(text, linewise);
-        } else {
-          register.setText(text, linewise, blockwise);
-        }
-        this.unnamedRegister.setText(register.toString(), linewise);
-      },
-      getRegister: function(name) {
-        if (!this.isValidRegister(name)) {
-          return this.unnamedRegister;
-        }
-        name = name.toLowerCase();
-        if (!this.registers[name]) {
-          this.registers[name] = new Register();
-        }
-        return this.registers[name];
-      },
-      isValidRegister: function(name) {
-        return name && inArray(name, validRegisters);
-      },
-      shiftNumericRegisters_: function() {
-        for (var i = 9; i >= 2; i--) {
-          this.registers[i] = this.getRegister('' + (i - 1));
-        }
-      }
-    };
-    function HistoryController() {
-        this.historyBuffer = [];
-        this.iterator;
-        this.initialPrefix = null;
-    }
-    HistoryController.prototype = {
-      nextMatch: function (input, up) {
-        var historyBuffer = this.historyBuffer;
-        var dir = up ? -1 : 1;
-        if (this.initialPrefix === null) this.initialPrefix = input;
-        for (var i = this.iterator + dir; up ? i >= 0 : i < historyBuffer.length; i+= dir) {
-          var element = historyBuffer[i];
-          for (var j = 0; j <= element.length; j++) {
-            if (this.initialPrefix == element.substring(0, j)) {
-              this.iterator = i;
-              return element;
-            }
-          }
-        }
-        if (i >= historyBuffer.length) {
-          this.iterator = historyBuffer.length;
-          return this.initialPrefix;
-        }
-        if (i < 0 ) return input;
-      },
-      pushInput: function(input) {
-        var index = this.historyBuffer.indexOf(input);
-        if (index > -1) this.historyBuffer.splice(index, 1);
-        if (input.length) this.historyBuffer.push(input);
-      },
-      reset: function() {
-        this.initialPrefix = null;
-        this.iterator = this.historyBuffer.length;
-      }
-    };
-    var commandDispatcher = {
-      matchCommand: function(keys, keyMap, inputState, context) {
-        var matches = commandMatches(keys, keyMap, context, inputState);
-        if (!matches.full && !matches.partial) {
-          return {type: 'none'};
-        } else if (!matches.full && matches.partial) {
-          return {type: 'partial'};
-        }
-
-        var bestMatch;
-        for (var i = 0; i < matches.full.length; i++) {
-          var match = matches.full[i];
-          if (!bestMatch) {
-            bestMatch = match;
-          }
-        }
-        if (bestMatch.keys.slice(-11) == '<character>') {
-          inputState.selectedCharacter = lastChar(keys);
-        }
-        return {type: 'full', command: bestMatch};
-      },
-      processCommand: function(cm, vim, command) {
-        vim.inputState.repeatOverride = command.repeatOverride;
-        switch (command.type) {
-          case 'motion':
-            this.processMotion(cm, vim, command);
-            break;
-          case 'operator':
-            this.processOperator(cm, vim, command);
-            break;
-          case 'operatorMotion':
-            this.processOperatorMotion(cm, vim, command);
-            break;
-          case 'action':
-            this.processAction(cm, vim, command);
-            break;
-          case 'search':
-            this.processSearch(cm, vim, command);
-            clearInputState(cm);
-            break;
-          case 'ex':
-          case 'keyToEx':
-            this.processEx(cm, vim, command);
-            clearInputState(cm);
-            break;
-          default:
-            break;
-        }
-      },
-      processMotion: function(cm, vim, command) {
-        vim.inputState.motion = command.motion;
-        vim.inputState.motionArgs = copyArgs(command.motionArgs);
-        this.evalInput(cm, vim);
-      },
-      processOperator: function(cm, vim, command) {
-        var inputState = vim.inputState;
-        if (inputState.operator) {
-          if (inputState.operator == command.operator) {
-            inputState.motion = 'expandToLine';
-            inputState.motionArgs = { linewise: true };
-            this.evalInput(cm, vim);
-            return;
-          } else {
-            clearInputState(cm);
-          }
-        }
-        inputState.operator = command.operator;
-        inputState.operatorArgs = copyArgs(command.operatorArgs);
-        if (vim.visualMode) {
-          this.evalInput(cm, vim);
-        }
-      },
-      processOperatorMotion: function(cm, vim, command) {
-        var visualMode = vim.visualMode;
-        var operatorMotionArgs = copyArgs(command.operatorMotionArgs);
-        if (operatorMotionArgs) {
-          if (visualMode && operatorMotionArgs.visualLine) {
-            vim.visualLine = true;
-          }
-        }
-        this.processOperator(cm, vim, command);
-        if (!visualMode) {
-          this.processMotion(cm, vim, command);
-        }
-      },
-      processAction: function(cm, vim, command) {
-        var inputState = vim.inputState;
-        var repeat = inputState.getRepeat();
-        var repeatIsExplicit = !!repeat;
-        var actionArgs = copyArgs(command.actionArgs) || {};
-        if (inputState.selectedCharacter) {
-          actionArgs.selectedCharacter = inputState.selectedCharacter;
-        }
-        if (command.operator) {
-          this.processOperator(cm, vim, command);
-        }
-        if (command.motion) {
-          this.processMotion(cm, vim, command);
-        }
-        if (command.motion || command.operator) {
-          this.evalInput(cm, vim);
-        }
-        actionArgs.repeat = repeat || 1;
-        actionArgs.repeatIsExplicit = repeatIsExplicit;
-        actionArgs.registerName = inputState.registerName;
-        clearInputState(cm);
-        vim.lastMotion = null;
-        if (command.isEdit) {
-          this.recordLastEdit(vim, inputState, command);
-        }
-        actions[command.action](cm, actionArgs, vim);
-      },
-      processSearch: function(cm, vim, command) {
-        if (!cm.getSearchCursor) {
-          return;
-        }
-        var forward = command.searchArgs.forward;
-        var wholeWordOnly = command.searchArgs.wholeWordOnly;
-        getSearchState(cm).setReversed(!forward);
-        var promptPrefix = (forward) ? '/' : '?';
-        var originalQuery = getSearchState(cm).getQuery();
-        var originalScrollPos = cm.getScrollInfo();
-        function handleQuery(query, ignoreCase, smartCase) {
-          vimGlobalState.searchHistoryController.pushInput(query);
-          vimGlobalState.searchHistoryController.reset();
-          try {
-            updateSearchQuery(cm, query, ignoreCase, smartCase);
-          } catch (e) {
-            showConfirm(cm, 'Invalid regex: ' + query);
-            return;
-          }
-          commandDispatcher.processMotion(cm, vim, {
-            type: 'motion',
-            motion: 'findNext',
-            motionArgs: { forward: true, toJumplist: command.searchArgs.toJumplist }
-          });
-        }
-        function onPromptClose(query) {
-          cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
-          handleQuery(query, true /** ignoreCase */, true /** smartCase */);
-          var macroModeState = vimGlobalState.macroModeState;
-          if (macroModeState.isRecording) {
-            logSearchQuery(macroModeState, query);
-          }
-        }
-        function onPromptKeyUp(e, query, close) {
-          var keyName = CodeMirror.keyName(e), up;
-          if (keyName == 'Up' || keyName == 'Down') {
-            up = keyName == 'Up' ? true : false;
-            query = vimGlobalState.searchHistoryController.nextMatch(query, up) || '';
-            close(query);
-          } else {
-            if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift')
-              vimGlobalState.searchHistoryController.reset();
-          }
-          var parsedQuery;
-          try {
-            parsedQuery = updateSearchQuery(cm, query,
-                true /** ignoreCase */, true /** smartCase */);
-          } catch (e) {
-          }
-          if (parsedQuery) {
-            cm.scrollIntoView(findNext(cm, !forward, parsedQuery), 30);
-          } else {
-            clearSearchHighlight(cm);
-            cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
-          }
-        }
-        function onPromptKeyDown(e, query, close) {
-          var keyName = CodeMirror.keyName(e);
-          if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[') {
-            vimGlobalState.searchHistoryController.pushInput(query);
-            vimGlobalState.searchHistoryController.reset();
-            updateSearchQuery(cm, originalQuery);
-            clearSearchHighlight(cm);
-            cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
-            CodeMirror.e_stop(e);
-            close();
-            cm.focus();
-          }
-        }
-        switch (command.searchArgs.querySrc) {
-          case 'prompt':
-            var macroModeState = vimGlobalState.macroModeState;
-            if (macroModeState.isPlaying) {
-              var query = macroModeState.replaySearchQueries.shift();
-              handleQuery(query, true /** ignoreCase */, false /** smartCase */);
-            } else {
-              showPrompt(cm, {
-                  onClose: onPromptClose,
-                  prefix: promptPrefix,
-                  desc: searchPromptDesc,
-                  onKeyUp: onPromptKeyUp,
-                  onKeyDown: onPromptKeyDown
-              });
-            }
-            break;
-          case 'wordUnderCursor':
-            var word = expandWordUnderCursor(cm, false /** inclusive */,
-                true /** forward */, false /** bigWord */,
-                true /** noSymbol */);
-            var isKeyword = true;
-            if (!word) {
-              word = expandWordUnderCursor(cm, false /** inclusive */,
-                  true /** forward */, false /** bigWord */,
-                  false /** noSymbol */);
-              isKeyword = false;
-            }
-            if (!word) {
-              return;
-            }
-            var query = cm.getLine(word.start.line).substring(word.start.ch,
-                word.end.ch);
-            if (isKeyword && wholeWordOnly) {
-                query = '\\b' + query + '\\b';
-            } else {
-              query = escapeRegex(query);
-            }
-            vimGlobalState.jumpList.cachedCursor = cm.getCursor();
-            cm.setCursor(word.start);
-
-            handleQuery(query, true /** ignoreCase */, false /** smartCase */);
-            break;
-        }
-      },
-      processEx: function(cm, vim, command) {
-        function onPromptClose(input) {
-          vimGlobalState.exCommandHistoryController.pushInput(input);
-          vimGlobalState.exCommandHistoryController.reset();
-          exCommandDispatcher.processCommand(cm, input);
-        }
-        function onPromptKeyDown(e, input, close) {
-          var keyName = CodeMirror.keyName(e), up;
-          if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[') {
-            vimGlobalState.exCommandHistoryController.pushInput(input);
-            vimGlobalState.exCommandHistoryController.reset();
-            CodeMirror.e_stop(e);
-            close();
-            cm.focus();
-          }
-          if (keyName == 'Up' || keyName == 'Down') {
-            up = keyName == 'Up' ? true : false;
-            input = vimGlobalState.exCommandHistoryController.nextMatch(input, up) || '';
-            close(input);
-          } else {
-            if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift')
-              vimGlobalState.exCommandHistoryController.reset();
-          }
-        }
-        if (command.type == 'keyToEx') {
-          exCommandDispatcher.processCommand(cm, command.exArgs.input);
-        } else {
-          if (vim.visualMode) {
-            showPrompt(cm, { onClose: onPromptClose, prefix: ':', value: '\'<,\'>',
-                onKeyDown: onPromptKeyDown});
-          } else {
-            showPrompt(cm, { onClose: onPromptClose, prefix: ':',
-                onKeyDown: onPromptKeyDown});
-          }
-        }
-      },
-      evalInput: function(cm, vim) {
-        var inputState = vim.inputState;
-        var motion = inputState.motion;
-        var motionArgs = inputState.motionArgs || {};
-        var operator = inputState.operator;
-        var operatorArgs = inputState.operatorArgs || {};
-        var registerName = inputState.registerName;
-        var sel = vim.sel;
-        var origHead = copyCursor(vim.visualMode ? sel.head: cm.getCursor('head'));
-        var origAnchor = copyCursor(vim.visualMode ? sel.anchor : cm.getCursor('anchor'));
-        var oldHead = copyCursor(origHead);
-        var oldAnchor = copyCursor(origAnchor);
-        var newHead, newAnchor;
-        var repeat;
-        if (operator) {
-          this.recordLastEdit(vim, inputState);
-        }
-        if (inputState.repeatOverride !== undefined) {
-          repeat = inputState.repeatOverride;
-        } else {
-          repeat = inputState.getRepeat();
-        }
-        if (repeat > 0 && motionArgs.explicitRepeat) {
-          motionArgs.repeatIsExplicit = true;
-        } else if (motionArgs.noRepeat ||
-            (!motionArgs.explicitRepeat && repeat === 0)) {
-          repeat = 1;
-          motionArgs.repeatIsExplicit = false;
-        }
-        if (inputState.selectedCharacter) {
-          motionArgs.selectedCharacter = operatorArgs.selectedCharacter =
-              inputState.selectedCharacter;
-        }
-        motionArgs.repeat = repeat;
-        clearInputState(cm);
-        if (motion) {
-          var motionResult = motions[motion](cm, origHead, motionArgs, vim);
-          vim.lastMotion = motions[motion];
-          if (!motionResult) {
-            return;
-          }
-          if (motionArgs.toJumplist) {
-            var jumpList = vimGlobalState.jumpList;
-            var cachedCursor = jumpList.cachedCursor;
-            if (cachedCursor) {
-              recordJumpPosition(cm, cachedCursor, motionResult);
-              delete jumpList.cachedCursor;
-            } else {
-              recordJumpPosition(cm, origHead, motionResult);
-            }
-          }
-          if (motionResult instanceof Array) {
-            newAnchor = motionResult[0];
-            newHead = motionResult[1];
-          } else {
-            newHead = motionResult;
-          }
-          if (!newHead) {
-            newHead = copyCursor(origHead);
-          }
-          if (vim.visualMode) {
-            newHead = clipCursorToContent(cm, newHead, true);
-            if (newAnchor) {
-              newAnchor = clipCursorToContent(cm, newAnchor, true);
-            }
-            newAnchor = newAnchor || oldAnchor;
-            sel.anchor = newAnchor;
-            sel.head = newHead;
-            updateCmSelection(cm);
-            updateMark(cm, vim, '<',
-                cursorIsBefore(newAnchor, newHead) ? newAnchor
-                    : newHead);
-            updateMark(cm, vim, '>',
-                cursorIsBefore(newAnchor, newHead) ? newHead
-                    : newAnchor);
-          } else if (!operator) {
-            newHead = clipCursorToContent(cm, newHead);
-            cm.setCursor(newHead.line, newHead.ch);
-          }
-        }
-        if (operator) {
-          if (operatorArgs.lastSel) {
-            newAnchor = oldAnchor;
-            var lastSel = operatorArgs.lastSel;
-            var lineOffset = Math.abs(lastSel.head.line - lastSel.anchor.line);
-            var chOffset = Math.abs(lastSel.head.ch - lastSel.anchor.ch);
-            if (lastSel.visualLine) {
-              newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
-            } else if (lastSel.visualBlock) {
-              newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch + chOffset);
-            } else if (lastSel.head.line == lastSel.anchor.line) {
-              newHead = Pos(oldAnchor.line, oldAnchor.ch + chOffset);
-            } else {
-              newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
-            }
-            vim.visualMode = true;
-            vim.visualLine = lastSel.visualLine;
-            vim.visualBlock = lastSel.visualBlock;
-            sel = vim.sel = {
-              anchor: newAnchor,
-              head: newHead
-            };
-            updateCmSelection(cm);
-          } else if (vim.visualMode) {
-            operatorArgs.lastSel = {
-              anchor: copyCursor(sel.anchor),
-              head: copyCursor(sel.head),
-              visualBlock: vim.visualBlock,
-              visualLine: vim.visualLine
-            };
-          }
-          var curStart, curEnd, linewise, mode;
-          var cmSel;
-          if (vim.visualMode) {
-            curStart = cursorMin(sel.head, sel.anchor);
-            curEnd = cursorMax(sel.head, sel.anchor);
-            linewise = vim.visualLine || operatorArgs.linewise;
-            mode = vim.visualBlock ? 'block' :
-                   linewise ? 'line' :
-                   'char';
-            cmSel = makeCmSelection(cm, {
-              anchor: curStart,
-              head: curEnd
-            }, mode);
-            if (linewise) {
-              var ranges = cmSel.ranges;
-              if (mode == 'block') {
-                for (var i = 0; i < ranges.length; i++) {
-                  ranges[i].head.ch = lineLength(cm, ranges[i].head.line);
-                }
-              } else if (mode == 'line') {
-                ranges[0].head = Pos(ranges[0].head.line + 1, 0);
-              }
-            }
-          } else {
-            curStart = copyCursor(newAnchor || oldAnchor);
-            curEnd = copyCursor(newHead || oldHead);
-            if (cursorIsBefore(curEnd, curStart)) {
-              var tmp = curStart;
-              curStart = curEnd;
-              curEnd = tmp;
-            }
-            linewise = motionArgs.linewise || operatorArgs.linewise;
-            if (linewise) {
-              expandSelectionToLine(cm, curStart, curEnd);
-            } else if (motionArgs.forward) {
-              clipToLine(cm, curStart, curEnd);
-            }
-            mode = 'char';
-            var exclusive = !motionArgs.inclusive || linewise;
-            cmSel = makeCmSelection(cm, {
-              anchor: curStart,
-              head: curEnd
-            }, mode, exclusive);
-          }
-          cm.setSelections(cmSel.ranges, cmSel.primary);
-          vim.lastMotion = null;
-          operatorArgs.repeat = repeat; // For indent in visual mode.
-          operatorArgs.registerName = registerName;
-          operatorArgs.linewise = linewise;
-          var operatorMoveTo = operators[operator](
-            cm, operatorArgs, cmSel.ranges, oldAnchor, newHead);
-          if (vim.visualMode) {
-            exitVisualMode(cm);
-          }
-          if (operatorMoveTo) {
-            cm.setCursor(operatorMoveTo);
-          }
-        }
-      },
-      recordLastEdit: function(vim, inputState, actionCommand) {
-        var macroModeState = vimGlobalState.macroModeState;
-        if (macroModeState.isPlaying) { return; }
-        vim.lastEditInputState = inputState;
-        vim.lastEditActionCommand = actionCommand;
-        macroModeState.lastInsertModeChanges.changes = [];
-        macroModeState.lastInsertModeChanges.expectCursorActivityForChange = false;
-      }
-    };
-    var motions = {
-      moveToTopLine: function(cm, _head, motionArgs) {
-        var line = getUserVisibleLines(cm).top + motionArgs.repeat -1;
-        return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
-      },
-      moveToMiddleLine: function(cm) {
-        var range = getUserVisibleLines(cm);
-        var line = Math.floor((range.top + range.bottom) * 0.5);
-        return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
-      },
-      moveToBottomLine: function(cm, _head, motionArgs) {
-        var line = getUserVisibleLines(cm).bottom - motionArgs.repeat +1;
-        return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
-      },
-      expandToLine: function(_cm, head, motionArgs) {
-        var cur = head;
-        return Pos(cur.line + motionArgs.repeat - 1, Infinity);
-      },
-      findNext: function(cm, _head, motionArgs) {
-        var state = getSearchState(cm);
-        var query = state.getQuery();
-        if (!query) {
-          return;
-        }
-        var prev = !motionArgs.forward;
-        prev = (state.isReversed()) ? !prev : prev;
-        highlightSearchMatches(cm, query);
-        return findNext(cm, prev/** prev */, query, motionArgs.repeat);
-      },
-      goToMark: function(cm, _head, motionArgs, vim) {
-        var mark = vim.marks[motionArgs.selectedCharacter];
-        if (mark) {
-          var pos = mark.find();
-          return motionArgs.linewise ? { line: pos.line, ch: findFirstNonWhiteSpaceCharacter(cm.getLine(pos.line)) } : pos;
-        }
-        return null;
-      },
-      moveToOtherHighlightedEnd: function(cm, _head, motionArgs, vim) {
-        if (vim.visualBlock && motionArgs.sameLine) {
-          var sel = vim.sel;
-          return [
-            clipCursorToContent(cm, Pos(sel.anchor.line, sel.head.ch)),
-            clipCursorToContent(cm, Pos(sel.head.line, sel.anchor.ch))
-          ];
-        } else {
-          return ([vim.sel.head, vim.sel.anchor]);
-        }
-      },
-      jumpToMark: function(cm, head, motionArgs, vim) {
-        var best = head;
-        for (var i = 0; i < motionArgs.repeat; i++) {
-          var cursor = best;
-          for (var key in vim.marks) {
-            if (!isLowerCase(key)) {
-              continue;
-            }
-            var mark = vim.marks[key].find();
-            var isWrongDirection = (motionArgs.forward) ?
-              cursorIsBefore(mark, cursor) : cursorIsBefore(cursor, mark);
-
-            if (isWrongDirection) {
-              continue;
-            }
-            if (motionArgs.linewise && (mark.line == cursor.line)) {
-              continue;
-            }
-
-            var equal = cursorEqual(cursor, best);
-            var between = (motionArgs.forward) ?
-              cursorIsBetween(cursor, mark, best) :
-              cursorIsBetween(best, mark, cursor);
-
-            if (equal || between) {
-              best = mark;
-            }
-          }
-        }
-
-        if (motionArgs.linewise) {
-          best = Pos(best.line, findFirstNonWhiteSpaceCharacter(cm.getLine(best.line)));
-        }
-        return best;
-      },
-      moveByCharacters: function(_cm, head, motionArgs) {
-        var cur = head;
-        var repeat = motionArgs.repeat;
-        var ch = motionArgs.forward ? cur.ch + repeat : cur.ch - repeat;
-        return Pos(cur.line, ch);
-      },
-      moveByLines: function(cm, head, motionArgs, vim) {
-        var cur = head;
-        var endCh = cur.ch;
-        switch (vim.lastMotion) {
-          case this.moveByLines:
-          case this.moveByDisplayLines:
-          case this.moveByScroll:
-          case this.moveToColumn:
-          case this.moveToEol:
-            endCh = vim.lastHPos;
-            break;
-          default:
-            vim.lastHPos = endCh;
-        }
-        var repeat = motionArgs.repeat+(motionArgs.repeatOffset||0);
-        var line = motionArgs.forward ? cur.line + repeat : cur.line - repeat;
-        var first = cm.firstLine();
-        var last = cm.lastLine();
-        if ((line < first && cur.line == first) ||
-            (line > last && cur.line == last)) {
-          return;
-        }
-        if (motionArgs.toFirstChar){
-          endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line));
-          vim.lastHPos = endCh;
-        }
-        vim.lastHSPos = cm.charCoords(Pos(line, endCh),'div').left;
-        return Pos(line, endCh);
-      },
-      moveByDisplayLines: function(cm, head, motionArgs, vim) {
-        var cur = head;
-        switch (vim.lastMotion) {
-          case this.moveByDisplayLines:
-          case this.moveByScroll:
-          case this.moveByLines:
-          case this.moveToColumn:
-          case this.moveToEol:
-            break;
-          default:
-            vim.lastHSPos = cm.charCoords(cur,'div').left;
-        }
-        var repeat = motionArgs.repeat;
-        var res=cm.findPosV(cur,(motionArgs.forward ? repeat : -repeat),'line',vim.lastHSPos);
-        if (res.hitSide) {
-          if (motionArgs.forward) {
-            var lastCharCoords = cm.charCoords(res, 'div');
-            var goalCoords = { top: lastCharCoords.top + 8, left: vim.lastHSPos };
-            var res = cm.coordsChar(goalCoords, 'div');
-          } else {
-            var resCoords = cm.charCoords(Pos(cm.firstLine(), 0), 'div');
-            resCoords.left = vim.lastHSPos;
-            res = cm.coordsChar(resCoords, 'div');
-          }
-        }
-        vim.lastHPos = res.ch;
-        return res;
-      },
-      moveByPage: function(cm, head, motionArgs) {
-        var curStart = head;
-        var repeat = motionArgs.repeat;
-        return cm.findPosV(curStart, (motionArgs.forward ? repeat : -repeat), 'page');
-      },
-      moveByParagraph: function(cm, head, motionArgs) {
-        var line = head.line;
-        var repeat = motionArgs.repeat;
-        var inc = motionArgs.forward ? 1 : -1;
-        for (var i = 0; i < repeat; i++) {
-          if ((!motionArgs.forward && line === cm.firstLine() ) ||
-              (motionArgs.forward && line == cm.lastLine())) {
-            break;
-          }
-          line += inc;
-          while (line !== cm.firstLine() && line != cm.lastLine() && cm.getLine(line)) {
-            line += inc;
-          }
-        }
-        return Pos(line, 0);
-      },
-      moveByScroll: function(cm, head, motionArgs, vim) {
-        var scrollbox = cm.getScrollInfo();
-        var curEnd = null;
-        var repeat = motionArgs.repeat;
-        if (!repeat) {
-          repeat = scrollbox.clientHeight / (2 * cm.defaultTextHeight());
-        }
-        var orig = cm.charCoords(head, 'local');
-        motionArgs.repeat = repeat;
-        var curEnd = motions.moveByDisplayLines(cm, head, motionArgs, vim);
-        if (!curEnd) {
-          return null;
-        }
-        var dest = cm.charCoords(curEnd, 'local');
-        cm.scrollTo(null, scrollbox.top + dest.top - orig.top);
-        return curEnd;
-      },
-      moveByWords: function(cm, head, motionArgs) {
-        return moveToWord(cm, head, motionArgs.repeat, !!motionArgs.forward,
-            !!motionArgs.wordEnd, !!motionArgs.bigWord);
-      },
-      moveTillCharacter: function(cm, _head, motionArgs) {
-        var repeat = motionArgs.repeat;
-        var curEnd = moveToCharacter(cm, repeat, motionArgs.forward,
-            motionArgs.selectedCharacter);
-        var increment = motionArgs.forward ? -1 : 1;
-        recordLastCharacterSearch(increment, motionArgs);
-        if (!curEnd) return null;
-        curEnd.ch += increment;
-

<TRUNCATED>

Mime
View raw message