(function (e) {
  if (typeof exports == 'object' && typeof module == 'object') module.exports = e();
  else if (typeof define == 'function' && define.amd) return define([], e);
  else this.CodeMirror = e();
})(function () {
  'use strict';
  function S(e, t) {
    if (!(this instanceof S)) return new S(e, t);
    this.options = t = t ? Qo(t) : {};
    Qo(mi, t, false);
    H(t);
    var n = t.value;
    if (typeof n == 'string') n = new Ws(n, t.mode);
    this.doc = n;
    var s = (this.display = new x(e, n));
    s.wrapper.CodeMirror = this;
    M(this);
    A(this);
    if (t.lineWrapping) this.display.wrapper.className += ' CodeMirror-wrap';
    if (t.autofocus && !d) or(this);
    I(this);
    this.state = { keyMaps: [], overlays: [], modeGen: 0, overwrite: false, focused: false, suppressEdits: false, pasteIncoming: false, cutIncoming: false, draggingText: false, highlight: new qo(), keySeq: null };
    if (r && i < 11) setTimeout(Go(sr, this, true), 20);
    fr(this);
    mu();
    Dn(this);
    this.curOp.forceUpdate = true;
    Js(this, n);
    if ((t.autofocus && !d) || fu() == s.input) setTimeout(Go(Rr, this), 20);
    else Ur(this);
    for (var o in gi) if (gi.hasOwnProperty(o)) gi[o](this, t[o], bi);
    W(this);
    for (var u = 0; u < xi.length; ++u) xi[u](this);
    Hn(this);
  }
  function x(e, t) {
    var n = this;
    var o = (n.input = iu('textarea', null, null, 'position: absolute; padding: 0; width: 1px; height: 1em; outline: none'));
    if (s) o.style.width = '1000px';
    else o.setAttribute('wrap', 'off');
    if (p) o.style.border = '1px solid black';
    o.setAttribute('autocorrect', 'off');
    o.setAttribute('autocapitalize', 'off');
    o.setAttribute('spellcheck', 'false');
    n.inputDiv = iu('div', [o], null, 'overflow: hidden; position: relative; width: 3px; height: 0px;');
    n.scrollbarFiller = iu('div', null, 'CodeMirror-scrollbar-filler');
    n.scrollbarFiller.setAttribute('not-content', 'true');
    n.gutterFiller = iu('div', null, 'CodeMirror-gutter-filler');
    n.gutterFiller.setAttribute('not-content', 'true');
    n.lineDiv = iu('div', null, 'CodeMirror-code');
    n.selectionDiv = iu('div', null, null, 'position: relative; z-index: 1');
    n.cursorDiv = iu('div', null, 'CodeMirror-cursors');
    n.measure = iu('div', null, 'CodeMirror-measure');
    n.lineMeasure = iu('div', null, 'CodeMirror-measure');
    n.lineSpace = iu('div', [n.measure, n.lineMeasure, n.selectionDiv, n.cursorDiv, n.lineDiv], null, 'position: relative; outline: none');
    n.mover = iu('div', [iu('div', [n.lineSpace], 'CodeMirror-lines')], null, 'position: relative');
    n.sizer = iu('div', [n.mover], 'CodeMirror-sizer');
    n.sizerWidth = null;
    n.heightForcer = iu('div', null, null, 'position: absolute; height: ' + Ho + 'px; width: 1px;');
    n.gutters = iu('div', null, 'CodeMirror-gutters');
    n.lineGutter = null;
    n.scroller = iu('div', [n.sizer, n.heightForcer, n.gutters], 'CodeMirror-scroll');
    n.scroller.setAttribute('tabIndex', '-1');
    n.wrapper = iu('div', [n.inputDiv, n.scrollbarFiller, n.gutterFiller, n.scroller], 'CodeMirror');
    if (r && i < 8) {
      n.gutters.style.zIndex = -1;
      n.scroller.style.paddingRight = 0;
    }
    if (p) o.style.width = '0px';
    if (!s) n.scroller.draggable = true;
    if (l) {
      n.inputDiv.style.height = '1px';
      n.inputDiv.style.position = 'absolute';
    }
    if (e) {
      if (e.appendChild) e.appendChild(n.wrapper);
      else e(n.wrapper);
    }
    n.viewFrom = n.viewTo = t.first;
    n.reportedViewFrom = n.reportedViewTo = t.first;
    n.view = [];
    n.renderedView = null;
    n.externalMeasured = null;
    n.viewOffset = 0;
    n.lastWrapHeight = n.lastWrapWidth = 0;
    n.updateLineNumbers = null;
    n.nativeBarWidth = n.barHeight = n.barWidth = 0;
    n.scrollbarsClipped = false;
    n.lineNumWidth = n.lineNumInnerWidth = n.lineNumChars = null;
    n.prevInput = '';
    n.alignWidgets = false;
    n.pollingFast = false;
    n.poll = new qo();
    n.cachedCharWidth = n.cachedTextHeight = n.cachedPaddingH = null;
    n.inaccurateSelection = false;
    n.maxLine = null;
    n.maxLineLength = 0;
    n.maxLineChanged = false;
    n.wheelDX = n.wheelDY = n.wheelStartX = n.wheelStartY = null;
    n.shift = false;
    n.selForContextMenu = null;
  }
  function T(e) {
    e.doc.mode = S.getMode(e.options, e.doc.modeOption);
    N(e);
  }
  function N(e) {
    e.doc.iter(function (e) {
      if (e.stateAfter) e.stateAfter = null;
      if (e.styles) e.styles = null;
    });
    e.doc.frontier = e.doc.first;
    Jt(e, 100);
    e.state.modeGen++;
    if (e.curOp) Jn(e);
  }
  function C(e) {
    if (e.options.lineWrapping) {
      hu(e.display.wrapper, 'CodeMirror-wrap');
      e.display.sizer.style.minWidth = '';
      e.display.sizerWidth = null;
    } else {
      cu(e.display.wrapper, 'CodeMirror-wrap');
      P(e);
    }
    L(e);
    Jn(e);
    gn(e);
    setTimeout(function () {
      q(e);
    }, 100);
  }
  function k(e) {
    var t = An(e.display),
      n = e.options.lineWrapping;
    var r = n && Math.max(5, e.display.scroller.clientWidth / On(e.display) - 3);
    return function (i) {
      if (hs(e.doc, i)) return 0;
      var s = 0;
      if (i.widgets)
        for (var o = 0; o < i.widgets.length; o++) {
          if (i.widgets[o].height) s += i.widgets[o].height;
        }
      if (n) return s + (Math.ceil(i.text.length / r) || 1) * t;
      else return s + t;
    };
  }
  function L(e) {
    var t = e.doc,
      n = k(e);
    t.iter(function (e) {
      var t = n(e);
      if (t != e.height) Ys(e, t);
    });
  }
  function A(e) {
    e.display.wrapper.className = e.display.wrapper.className.replace(/\s*cm-s-\S+/g, '') + e.options.theme.replace(/(^|\s)\s*/g, ' cm-s-');
    gn(e);
  }
  function O(e) {
    M(e);
    Jn(e);
    setTimeout(function () {
      z(e);
    }, 20);
  }
  function M(e) {
    var t = e.display.gutters,
      n = e.options.gutters;
    ou(t);
    for (var r = 0; r < n.length; ++r) {
      var i = n[r];
      var s = t.appendChild(iu('div', null, 'CodeMirror-gutter ' + i));
      if (i == 'CodeMirror-linenumbers') {
        e.display.lineGutter = s;
        s.style.width = (e.display.lineNumWidth || 1) + 'px';
      }
    }
    t.style.display = r ? '' : 'none';
    _(e);
  }
  function _(e) {
    var t = e.display.gutters.offsetWidth;
    e.display.sizer.style.marginLeft = t + 'px';
  }
  function D(e) {
    if (e.height == 0) return 0;
    var t = e.text.length,
      n,
      r = e;
    while ((n = ss(r))) {
      var i = n.find(0, true);
      r = i.from.line;
      t += i.from.ch - i.to.ch;
    }
    r = e;
    while ((n = os(r))) {
      var i = n.find(0, true);
      t -= r.text.length - i.from.ch;
      r = i.to.line;
      t += r.text.length - i.to.ch;
    }
    return t;
  }
  function P(e) {
    var t = e.display,
      n = e.doc;
    t.maxLine = Ks(n, n.first);
    t.maxLineLength = D(t.maxLine);
    t.maxLineChanged = true;
    n.iter(function (e) {
      var n = D(e);
      if (n > t.maxLineLength) {
        t.maxLineLength = n;
        t.maxLine = e;
      }
    });
  }
  function H(e) {
    var t = $o(e.gutters, 'CodeMirror-linenumbers');
    if (t == -1 && e.lineNumbers) {
      e.gutters = e.gutters.concat(['CodeMirror-linenumbers']);
    } else if (t > -1 && !e.lineNumbers) {
      e.gutters = e.gutters.slice(0);
      e.gutters.splice(t, 1);
    }
  }
  function B(e) {
    var t = e.display,
      n = t.gutters.offsetWidth;
    var r = Math.round(e.doc.height + Zt(e.display));
    return {
      clientHeight: t.scroller.clientHeight,
      viewHeight: t.wrapper.clientHeight,
      scrollWidth: t.scroller.scrollWidth,
      clientWidth: t.scroller.clientWidth,
      viewWidth: t.wrapper.clientWidth,
      barLeft: e.options.fixedGutter ? n : 0,
      docHeight: r,
      scrollHeight: r + tn(e) + t.barHeight,
      nativeBarWidth: t.nativeBarWidth,
      gutterWidth: n,
    };
  }
  function j(e, t, n) {
    this.cm = n;
    var s = (this.vert = iu('div', [iu('div', null, null, 'min-width: 1px')], 'CodeMirror-vscrollbar'));
    var o = (this.horiz = iu('div', [iu('div', null, null, 'height: 100%; min-height: 1px')], 'CodeMirror-hscrollbar'));
    e(s);
    e(o);
    No(s, 'scroll', function () {
      if (s.clientHeight) t(s.scrollTop, 'vertical');
    });
    No(o, 'scroll', function () {
      if (o.clientWidth) t(o.scrollLeft, 'horizontal');
    });
    this.checkedOverlay = false;
    if (r && i < 8) this.horiz.style.minHeight = this.vert.style.minWidth = '18px';
  }
  function F() {}
  function I(e) {
    if (e.display.scrollbars) {
      e.display.scrollbars.clear();
      if (e.display.scrollbars.addClass) cu(e.display.wrapper, e.display.scrollbars.addClass);
    }
    e.display.scrollbars = new S.scrollbarModel[e.options.scrollbarStyle](
      function (t) {
        e.display.wrapper.insertBefore(t, e.display.scrollbarFiller);
        No(t, 'mousedown', function () {
          if (e.state.focused) setTimeout(Go(or, e), 0);
        });
        t.setAttribute('not-content', 'true');
      },
      function (t, n) {
        if (n == 'horizontal') Nr(e, t);
        else Tr(e, t);
      },
      e
    );
    if (e.display.scrollbars.addClass) hu(e.display.wrapper, e.display.scrollbars.addClass);
  }
  function q(e, t) {
    if (!t) t = B(e);
    var n = e.display.barWidth,
      r = e.display.barHeight;
    R(e, t);
    for (var i = 0; (i < 4 && n != e.display.barWidth) || r != e.display.barHeight; i++) {
      if (n != e.display.barWidth && e.options.lineWrapping) Z(e);
      R(e, B(e));
      n = e.display.barWidth;
      r = e.display.barHeight;
    }
  }
  function R(e, t) {
    var n = e.display;
    var r = n.scrollbars.update(t);
    n.sizer.style.paddingRight = (n.barWidth = r.right) + 'px';
    n.sizer.style.paddingBottom = (n.barHeight = r.bottom) + 'px';
    if (r.right && r.bottom) {
      n.scrollbarFiller.style.display = 'block';
      n.scrollbarFiller.style.height = r.bottom + 'px';
      n.scrollbarFiller.style.width = r.right + 'px';
    } else n.scrollbarFiller.style.display = '';
    if (r.bottom && e.options.coverGutterNextToScrollbar && e.options.fixedGutter) {
      n.gutterFiller.style.display = 'block';
      n.gutterFiller.style.height = r.bottom + 'px';
      n.gutterFiller.style.width = t.gutterWidth + 'px';
    } else n.gutterFiller.style.display = '';
  }
  function U(e, t, n) {
    var r = n && n.top != null ? Math.max(0, n.top) : e.scroller.scrollTop;
    r = Math.floor(r - Yt(e));
    var i = n && n.bottom != null ? n.bottom : r + e.wrapper.clientHeight;
    var s = eo(t, r),
      o = eo(t, i);
    if (n && n.ensure) {
      var u = n.ensure.from.line,
        a = n.ensure.to.line;
      if (u < s) {
        s = u;
        o = eo(t, to(Ks(t, u)) + e.wrapper.clientHeight);
      } else if (Math.min(a, t.lastLine()) >= o) {
        s = eo(t, to(Ks(t, a)) - e.wrapper.clientHeight);
        o = a;
      }
    }
    return { from: s, to: Math.max(o, s + 1) };
  }
  function z(e) {
    var t = e.display,
      n = t.view;
    if (!t.alignWidgets && (!t.gutters.firstChild || !e.options.fixedGutter)) return;
    var r = V(t) - t.scroller.scrollLeft + e.doc.scrollLeft;
    var i = t.gutters.offsetWidth,
      s = r + 'px';
    for (var o = 0; o < n.length; o++)
      if (!n[o].hidden) {
        if (e.options.fixedGutter && n[o].gutter) n[o].gutter.style.left = s;
        var u = n[o].alignable;
        if (u) for (var a = 0; a < u.length; a++) u[a].style.left = s;
      }
    if (e.options.fixedGutter) t.gutters.style.left = r + i + 'px';
  }
  function W(e) {
    if (!e.options.lineNumbers) return false;
    var t = e.doc,
      n = X(e.options, t.first + t.size - 1),
      r = e.display;
    if (n.length != r.lineNumChars) {
      var i = r.measure.appendChild(iu('div', [iu('div', n)], 'CodeMirror-linenumber CodeMirror-gutter-elt'));
      var s = i.firstChild.offsetWidth,
        o = i.offsetWidth - s;
      r.lineGutter.style.width = '';
      r.lineNumInnerWidth = Math.max(s, r.lineGutter.offsetWidth - o);
      r.lineNumWidth = r.lineNumInnerWidth + o;
      r.lineNumChars = r.lineNumInnerWidth ? n.length : -1;
      r.lineGutter.style.width = r.lineNumWidth + 'px';
      _(e);
      return true;
    }
    return false;
  }
  function X(e, t) {
    return String(e.lineNumberFormatter(t + e.firstLineNumber));
  }
  function V(e) {
    return e.scroller.getBoundingClientRect().left - e.sizer.getBoundingClientRect().left;
  }
  function $(e, t, n) {
    var r = e.display;
    this.viewport = t;
    this.visible = U(r, e.doc, t);
    this.editorIsHidden = !r.wrapper.offsetWidth;
    this.wrapperHeight = r.wrapper.clientHeight;
    this.wrapperWidth = r.wrapper.clientWidth;
    this.oldDisplayWidth = nn(e);
    this.force = n;
    this.dims = tt(e);
  }
  function J(e) {
    var t = e.display;
    if (!t.scrollbarsClipped && t.scroller.offsetWidth) {
      t.nativeBarWidth = t.scroller.offsetWidth - t.scroller.clientWidth;
      t.heightForcer.style.height = tn(e) + 'px';
      t.sizer.style.marginBottom = -t.nativeBarWidth + 'px';
      t.sizer.style.borderRightWidth = tn(e) + 'px';
      t.scrollbarsClipped = true;
    }
  }
  function K(e, t) {
    var n = e.display,
      r = e.doc;
    if (t.editorIsHidden) {
      Qn(e);
      return false;
    }
    if (!t.force && t.visible.from >= n.viewFrom && t.visible.to <= n.viewTo && (n.updateLineNumbers == null || n.updateLineNumbers >= n.viewTo) && n.renderedView == n.view && er(e) == 0) return false;
    if (W(e)) {
      Qn(e);
      t.dims = tt(e);
    }
    var i = r.first + r.size;
    var s = Math.max(t.visible.from - e.options.viewportMargin, r.first);
    var o = Math.min(i, t.visible.to + e.options.viewportMargin);
    if (n.viewFrom < s && s - n.viewFrom < 20) s = Math.max(r.first, n.viewFrom);
    if (n.viewTo > o && n.viewTo - o < 20) o = Math.min(i, n.viewTo);
    if (E) {
      s = ls(e.doc, s);
      o = cs(e.doc, o);
    }
    var u = s != n.viewFrom || o != n.viewTo || n.lastWrapHeight != t.wrapperHeight || n.lastWrapWidth != t.wrapperWidth;
    Zn(e, s, o);
    n.viewOffset = to(Ks(e.doc, n.viewFrom));
    e.display.mover.style.top = n.viewOffset + 'px';
    var a = er(e);
    if (!u && a == 0 && !t.force && n.renderedView == n.view && (n.updateLineNumbers == null || n.updateLineNumbers >= n.viewTo)) return false;
    var f = fu();
    if (a > 4) n.lineDiv.style.display = 'none';
    nt(e, n.updateLineNumbers, t.dims);
    if (a > 4) n.lineDiv.style.display = '';
    n.renderedView = n.view;
    if (f && fu() != f && f.offsetHeight) f.focus();
    ou(n.cursorDiv);
    ou(n.selectionDiv);
    n.heightForcer.style.top = n.gutters.style.height = 0;
    if (u) {
      n.lastWrapHeight = t.wrapperHeight;
      n.lastWrapWidth = t.wrapperWidth;
      Jt(e, 400);
    }
    n.updateLineNumbers = null;
    return true;
  }
  function Q(e, t) {
    var n = t.force,
      r = t.viewport;
    for (var i = true; ; i = false) {
      if (i && e.options.lineWrapping && t.oldDisplayWidth != nn(e)) {
        n = true;
      } else {
        n = false;
        if (r && r.top != null) r = { top: Math.min(e.doc.height + Zt(e.display) - rn(e), r.top) };
        t.visible = U(e.display, e.doc, r);
        if (t.visible.from >= e.display.viewFrom && t.visible.to <= e.display.viewTo) break;
      }
      if (!K(e, t)) break;
      Z(e);
      var s = B(e);
      Wt(e);
      Y(e, s);
      q(e, s);
    }
    Ao(e, 'update', e);
    if (e.display.viewFrom != e.display.reportedViewFrom || e.display.viewTo != e.display.reportedViewTo) {
      Ao(e, 'viewportChange', e, e.display.viewFrom, e.display.viewTo);
      e.display.reportedViewFrom = e.display.viewFrom;
      e.display.reportedViewTo = e.display.viewTo;
    }
  }
  function G(e, t) {
    var n = new $(e, t);
    if (K(e, n)) {
      Z(e);
      Q(e, n);
      var r = B(e);
      Wt(e);
      Y(e, r);
      q(e, r);
    }
  }
  function Y(e, t) {
    e.display.sizer.style.minHeight = t.docHeight + 'px';
    var n = t.docHeight + tn(e);
    e.display.heightForcer.style.top = n + 'px';
    e.display.gutters.style.height = Math.max(n, t.clientHeight) + 'px';
  }
  function Z(e) {
    var t = e.display;
    var n = t.lineDiv.offsetTop;
    for (var s = 0; s < t.view.length; s++) {
      var o = t.view[s],
        u;
      if (o.hidden) continue;
      if (r && i < 8) {
        var a = o.node.offsetTop + o.node.offsetHeight;
        u = a - n;
        n = a;
      } else {
        var f = o.node.getBoundingClientRect();
        u = f.bottom - f.top;
      }
      var l = o.line.height - u;
      if (u < 2) u = An(t);
      if (l > 0.001 || l < -0.001) {
        Ys(o.line, u);
        et(o.line);
        if (o.rest) for (var c = 0; c < o.rest.length; c++) et(o.rest[c]);
      }
    }
  }
  function et(e) {
    if (e.widgets) for (var t = 0; t < e.widgets.length; ++t) e.widgets[t].height = e.widgets[t].node.offsetHeight;
  }
  function tt(e) {
    var t = e.display,
      n = {},
      r = {};
    var i = t.gutters.clientLeft;
    for (var s = t.gutters.firstChild, o = 0; s; s = s.nextSibling, ++o) {
      n[e.options.gutters[o]] = s.offsetLeft + s.clientLeft + i;
      r[e.options.gutters[o]] = s.clientWidth;
    }
    return { fixedPos: V(t), gutterTotalWidth: t.gutters.offsetWidth, gutterLeft: n, gutterWidth: r, wrapperWidth: t.wrapper.clientWidth };
  }
  function nt(e, t, n) {
    function a(t) {
      var n = t.nextSibling;
      if (s && v && e.display.currentWheelTarget == t) t.style.display = 'none';
      else t.parentNode.removeChild(t);
      return n;
    }
    var r = e.display,
      i = e.options.lineNumbers;
    var o = r.lineDiv,
      u = o.firstChild;
    var f = r.view,
      l = r.viewFrom;
    for (var c = 0; c < f.length; c++) {
      var h = f[c];
      if (h.hidden) {
      } else if (!h.node) {
        var p = ct(e, h, l, n);
        o.insertBefore(p, u);
      } else {
        while (u != h.node) u = a(u);
        var d = i && t != null && t <= l && h.lineNumber;
        if (h.changes) {
          if ($o(h.changes, 'gutter') > -1) d = false;
          rt(e, h, l, n);
        }
        if (d) {
          ou(h.lineNumber);
          h.lineNumber.appendChild(document.createTextNode(X(e.options, l)));
        }
        u = h.node.nextSibling;
      }
      l += h.size;
    }
    while (u) u = a(u);
  }
  function rt(e, t, n, r) {
    for (var i = 0; i < t.changes.length; i++) {
      var s = t.changes[i];
      if (s == 'text') ut(e, t);
      else if (s == 'gutter') ft(e, t, n, r);
      else if (s == 'class') at(t);
      else if (s == 'widget') lt(t, r);
    }
    t.changes = null;
  }
  function it(e) {
    if (e.node == e.text) {
      e.node = iu('div', null, null, 'position: relative');
      if (e.text.parentNode) e.text.parentNode.replaceChild(e.node, e.text);
      e.node.appendChild(e.text);
      if (r && i < 8) e.node.style.zIndex = 2;
    }
    return e.node;
  }
  function st(e) {
    var t = e.bgClass ? e.bgClass + ' ' + (e.line.bgClass || '') : e.line.bgClass;
    if (t) t += ' CodeMirror-linebackground';
    if (e.background) {
      if (t) e.background.className = t;
      else {
        e.background.parentNode.removeChild(e.background);
        e.background = null;
      }
    } else if (t) {
      var n = it(e);
      e.background = n.insertBefore(iu('div', null, t), n.firstChild);
    }
  }
  function ot(e, t) {
    var n = e.display.externalMeasured;
    if (n && n.line == t.line) {
      e.display.externalMeasured = null;
      t.measure = n.measure;
      return n.built;
    }
    return _s(e, t);
  }
  function ut(e, t) {
    var n = t.text.className;
    var r = ot(e, t);
    if (t.text == t.node) t.node = r.pre;
    t.text.parentNode.replaceChild(r.pre, t.text);
    t.text = r.pre;
    if (r.bgClass != t.bgClass || r.textClass != t.textClass) {
      t.bgClass = r.bgClass;
      t.textClass = r.textClass;
      at(t);
    } else if (n) {
      t.text.className = n;
    }
  }
  function at(e) {
    st(e);
    if (e.line.wrapClass) it(e).className = e.line.wrapClass;
    else if (e.node != e.text) e.node.className = '';
    var t = e.textClass ? e.textClass + ' ' + (e.line.textClass || '') : e.line.textClass;
    e.text.className = t || '';
  }
  function ft(e, t, n, r) {
    if (t.gutter) {
      t.node.removeChild(t.gutter);
      t.gutter = null;
    }
    var i = t.line.gutterMarkers;
    if (e.options.lineNumbers || i) {
      var s = it(t);
      var o = (t.gutter = s.insertBefore(iu('div', null, 'CodeMirror-gutter-wrapper', 'left: ' + (e.options.fixedGutter ? r.fixedPos : -r.gutterTotalWidth) + 'px; width: ' + r.gutterTotalWidth + 'px'), t.text));
      if (t.line.gutterClass) o.className += ' ' + t.line.gutterClass;
      if (e.options.lineNumbers && (!i || !i['CodeMirror-linenumbers'])) t.lineNumber = o.appendChild(iu('div', X(e.options, n), 'CodeMirror-linenumber CodeMirror-gutter-elt', 'left: ' + r.gutterLeft['CodeMirror-linenumbers'] + 'px; width: ' + e.display.lineNumInnerWidth + 'px'));
      if (i)
        for (var u = 0; u < e.options.gutters.length; ++u) {
          var a = e.options.gutters[u],
            f = i.hasOwnProperty(a) && i[a];
          if (f) o.appendChild(iu('div', [f], 'CodeMirror-gutter-elt', 'left: ' + r.gutterLeft[a] + 'px; width: ' + r.gutterWidth[a] + 'px'));
        }
    }
  }
  function lt(e, t) {
    if (e.alignable) e.alignable = null;
    for (var n = e.node.firstChild, r; n; n = r) {
      var r = n.nextSibling;
      if (n.className == 'CodeMirror-linewidget') e.node.removeChild(n);
    }
    ht(e, t);
  }
  function ct(e, t, n, r) {
    var i = ot(e, t);
    t.text = t.node = i.pre;
    if (i.bgClass) t.bgClass = i.bgClass;
    if (i.textClass) t.textClass = i.textClass;
    at(t);
    ft(e, t, n, r);
    ht(t, r);
    return t.node;
  }
  function ht(e, t) {
    pt(e.line, e, t, true);
    if (e.rest) for (var n = 0; n < e.rest.length; n++) pt(e.rest[n], e, t, false);
  }
  function pt(e, t, n, r) {
    if (!e.widgets) return;
    var i = it(t);
    for (var s = 0, o = e.widgets; s < o.length; ++s) {
      var u = o[s],
        a = iu('div', [u.node], 'CodeMirror-linewidget');
      if (!u.handleMouseEvents) a.setAttribute('cm-ignore-events', 'true');
      dt(u, a, t, n);
      if (r && u.above) i.insertBefore(a, t.gutter || t.text);
      else i.appendChild(a);
      Ao(u, 'redraw');
    }
  }
  function dt(e, t, n, r) {
    if (e.noHScroll) {
      (n.alignable || (n.alignable = [])).push(t);
      var i = r.wrapperWidth;
      t.style.left = r.fixedPos + 'px';
      if (!e.coverGutter) {
        i -= r.gutterTotalWidth;
        t.style.paddingLeft = r.gutterTotalWidth + 'px';
      }
      t.style.width = i + 'px';
    }
    if (e.coverGutter) {
      t.style.zIndex = 5;
      t.style.position = 'relative';
      if (!e.noHScroll) t.style.marginLeft = -r.gutterTotalWidth + 'px';
    }
  }
  function gt(e) {
    return vt(e.line, e.ch);
  }
  function yt(e, t) {
    return mt(e, t) < 0 ? t : e;
  }
  function bt(e, t) {
    return mt(e, t) < 0 ? e : t;
  }
  function wt(e, t) {
    this.ranges = e;
    this.primIndex = t;
  }
  function Et(e, t) {
    this.anchor = e;
    this.head = t;
  }
  function St(e, t) {
    var n = e[t];
    e.sort(function (e, t) {
      return mt(e.from(), t.from());
    });
    t = $o(e, n);
    for (var r = 1; r < e.length; r++) {
      var i = e[r],
        s = e[r - 1];
      if (mt(s.to(), i.from()) >= 0) {
        var o = bt(s.from(), i.from()),
          u = yt(s.to(), i.to());
        var a = s.empty() ? i.from() == i.head : s.from() == s.head;
        if (r <= t) --t;
        e.splice(--r, 2, new Et(a ? u : o, a ? o : u));
      }
    }
    return new wt(e, t);
  }
  function xt(e, t) {
    return new wt([new Et(e, t || e)], 0);
  }
  function Tt(e, t) {
    return Math.max(e.first, Math.min(t, e.first + e.size - 1));
  }
  function Nt(e, t) {
    if (t.line < e.first) return vt(e.first, 0);
    var n = e.first + e.size - 1;
    if (t.line > n) return vt(n, Ks(e, n).text.length);
    return Ct(t, Ks(e, t.line).text.length);
  }
  function Ct(e, t) {
    var n = e.ch;
    if (n == null || n > t) return vt(e.line, t);
    else if (n < 0) return vt(e.line, 0);
    else return e;
  }
  function kt(e, t) {
    return t >= e.first && t < e.first + e.size;
  }
  function Lt(e, t) {
    for (var n = [], r = 0; r < t.length; r++) n[r] = Nt(e, t[r]);
    return n;
  }
  function At(e, t, n, r) {
    if ((e.cm && e.cm.display.shift) || e.extend) {
      var i = t.anchor;
      if (r) {
        var s = mt(n, i) < 0;
        if (s != mt(r, i) < 0) {
          i = n;
          n = r;
        } else if (s != mt(n, r) < 0) {
          n = r;
        }
      }
      return new Et(i, n);
    } else {
      return new Et(r || n, n);
    }
  }
  function Ot(e, t, n, r) {
    Bt(e, new wt([At(e, e.sel.primary(), t, n)], 0), r);
  }
  function Mt(e, t, n) {
    for (var r = [], i = 0; i < e.sel.ranges.length; i++) r[i] = At(e, e.sel.ranges[i], t[i], null);
    var s = St(r, e.sel.primIndex);
    Bt(e, s, n);
  }
  function _t(e, t, n, r) {
    var i = e.sel.ranges.slice(0);
    i[t] = n;
    Bt(e, St(i, e.sel.primIndex), r);
  }
  function Dt(e, t, n, r) {
    Bt(e, xt(t, n), r);
  }
  function Pt(e, t) {
    var n = {
      ranges: t.ranges,
      update: function (t) {
        this.ranges = [];
        for (var n = 0; n < t.length; n++) this.ranges[n] = new Et(Nt(e, t[n].anchor), Nt(e, t[n].head));
      },
    };
    ko(e, 'beforeSelectionChange', e, n);
    if (e.cm) ko(e.cm, 'beforeSelectionChange', e.cm, n);
    if (n.ranges != t.ranges) return St(n.ranges, n.ranges.length - 1);
    else return t;
  }
  function Ht(e, t, n) {
    var r = e.history.done,
      i = Xo(r);
    if (i && i.ranges) {
      r[r.length - 1] = t;
      jt(e, t, n);
    } else {
      Bt(e, t, n);
    }
  }
  function Bt(e, t, n) {
    jt(e, t, n);
    fo(e, e.sel, e.cm ? e.cm.curOp.id : NaN, n);
  }
  function jt(e, t, n) {
    if (Do(e, 'beforeSelectionChange') || (e.cm && Do(e.cm, 'beforeSelectionChange'))) t = Pt(e, t);
    var r = (n && n.bias) || (mt(t.primary().head, e.sel.primary().head) < 0 ? -1 : 1);
    Ft(e, qt(e, t, r, true));
    if (!(n && n.scroll === false) && e.cm) fi(e.cm);
  }
  function Ft(e, t) {
    if (t.equals(e.sel)) return;
    e.sel = t;
    if (e.cm) {
      e.cm.curOp.updateInput = e.cm.curOp.selectionChanged = true;
      _o(e.cm);
    }
    Ao(e, 'cursorActivity', e);
  }
  function It(e) {
    Ft(e, qt(e, e.sel, null, false), jo);
  }
  function qt(e, t, n, r) {
    var i;
    for (var s = 0; s < t.ranges.length; s++) {
      var o = t.ranges[s];
      var u = Rt(e, o.anchor, n, r);
      var a = Rt(e, o.head, n, r);
      if (i || u != o.anchor || a != o.head) {
        if (!i) i = t.ranges.slice(0, s);
        i[s] = new Et(u, a);
      }
    }
    return i ? St(i, t.primIndex) : t;
  }
  function Rt(e, t, n, r) {
    var i = false,
      s = t;
    var o = n || 1;
    e.cantEdit = false;
    e: for (;;) {
      var u = Ks(e, s.line);
      if (u.markedSpans) {
        for (var a = 0; a < u.markedSpans.length; ++a) {
          var f = u.markedSpans[a],
            l = f.marker;
          if ((f.from == null || (l.inclusiveLeft ? f.from <= s.ch : f.from < s.ch)) && (f.to == null || (l.inclusiveRight ? f.to >= s.ch : f.to > s.ch))) {
            if (r) {
              ko(l, 'beforeCursorEnter');
              if (l.explicitlyCleared) {
                if (!u.markedSpans) break;
                else {
                  --a;
                  continue;
                }
              }
            }
            if (!l.atomic) continue;
            var c = l.find(o < 0 ? -1 : 1);
            if (mt(c, s) == 0) {
              c.ch += o;
              if (c.ch < 0) {
                if (c.line > e.first) c = Nt(e, vt(c.line - 1));
                else c = null;
              } else if (c.ch > u.text.length) {
                if (c.line < e.first + e.size - 1) c = vt(c.line + 1, 0);
                else c = null;
              }
              if (!c) {
                if (i) {
                  if (!r) return Rt(e, t, n, true);
                  e.cantEdit = true;
                  return vt(e.first, 0);
                }
                i = true;
                c = t;
                o = -o;
              }
            }
            s = c;
            continue e;
          }
        }
      }
      return s;
    }
  }
  function Ut(e) {
    var t = e.display,
      n = e.doc,
      r = {};
    var i = (r.cursors = document.createDocumentFragment());
    var s = (r.selection = document.createDocumentFragment());
    for (var o = 0; o < n.sel.ranges.length; o++) {
      var u = n.sel.ranges[o];
      var a = u.empty();
      if (a || e.options.showCursorWhenSelecting) Xt(e, u, i);
      if (!a) Vt(e, u, s);
    }
    if (e.options.moveInputWithCursor) {
      var f = xn(e, n.sel.primary().head, 'div');
      var l = t.wrapper.getBoundingClientRect(),
        c = t.lineDiv.getBoundingClientRect();
      r.teTop = Math.max(0, Math.min(t.wrapper.clientHeight - 10, f.top + c.top - l.top));
      r.teLeft = Math.max(0, Math.min(t.wrapper.clientWidth - 10, f.left + c.left - l.left));
    }
    return r;
  }
  function zt(e, t) {
    uu(e.display.cursorDiv, t.cursors);
    uu(e.display.selectionDiv, t.selection);
    if (t.teTop != null) {
      e.display.inputDiv.style.top = t.teTop + 'px';
      e.display.inputDiv.style.left = t.teLeft + 'px';
    }
  }
  function Wt(e) {
    zt(e, Ut(e));
  }
  function Xt(e, t, n) {
    var r = xn(e, t.head, 'div', null, null, !e.options.singleCursorHeightPerLine);
    var i = n.appendChild(iu('div', ' ', 'CodeMirror-cursor'));
    i.style.left = r.left + 'px';
    i.style.top = r.top + 'px';
    i.style.height = Math.max(0, r.bottom - r.top) * e.options.cursorHeight + 'px';
    if (r.other) {
      var s = n.appendChild(iu('div', ' ', 'CodeMirror-cursor CodeMirror-secondarycursor'));
      s.style.display = '';
      s.style.left = r.other.left + 'px';
      s.style.top = r.other.top + 'px';
      s.style.height = (r.other.bottom - r.other.top) * 0.85 + 'px';
    }
  }
  function Vt(e, t, n) {
    function f(e, t, n, r) {
      if (t < 0) t = 0;
      t = Math.round(t);
      r = Math.round(r);
      s.appendChild(iu('div', null, 'CodeMirror-selected', 'position: absolute; left: ' + e + 'px; top: ' + t + 'px; width: ' + (n == null ? a - e : n) + 'px; height: ' + (r - t) + 'px'));
    }
    function l(t, n, r) {
      function h(n, r) {
        return Sn(e, vt(t, n), 'div', s, r);
      }
      var s = Ks(i, t);
      var o = s.text.length;
      var l, c;
      Au(no(s), n || 0, r == null ? o : r, function (e, t, i) {
        var s = h(e, 'left'),
          p,
          d,
          v;
        if (e == t) {
          p = s;
          d = v = s.left;
        } else {
          p = h(t - 1, 'right');
          if (i == 'rtl') {
            var m = s;
            s = p;
            p = m;
          }
          d = s.left;
          v = p.right;
        }
        if (n == null && e == 0) d = u;
        if (p.top - s.top > 3) {
          f(d, s.top, null, s.bottom);
          d = u;
          if (s.bottom < p.top) f(d, s.bottom, null, p.top);
        }
        if (r == null && t == o) v = a;
        if (!l || s.top < l.top || (s.top == l.top && s.left < l.left)) l = s;
        if (!c || p.bottom > c.bottom || (p.bottom == c.bottom && p.right > c.right)) c = p;
        if (d < u + 1) d = u;
        f(d, p.top, v - d, p.bottom);
      });
      return { start: l, end: c };
    }
    var r = e.display,
      i = e.doc;
    var s = document.createDocumentFragment();
    var o = en(e.display),
      u = o.left;
    var a = Math.max(r.sizerWidth, nn(e) - r.sizer.offsetLeft) - o.right;
    var c = t.from(),
      h = t.to();
    if (c.line == h.line) {
      l(c.line, c.ch, h.ch);
    } else {
      var p = Ks(i, c.line),
        d = Ks(i, h.line);
      var v = as(p) == as(d);
      var m = l(c.line, c.ch, v ? p.text.length + 1 : null).end;
      var g = l(h.line, v ? 0 : null, h.ch).start;
      if (v) {
        if (m.top < g.top - 2) {
          f(m.right, m.top, null, m.bottom);
          f(u, g.top, g.left, g.bottom);
        } else {
          f(m.right, m.top, g.left - m.right, m.bottom);
        }
      }
      if (m.bottom < g.top) f(u, m.bottom, null, g.top);
    }
    n.appendChild(s);
  }
  function $t(e) {
    if (!e.state.focused) return;
    var t = e.display;
    clearInterval(t.blinker);
    var n = true;
    t.cursorDiv.style.visibility = '';
    if (e.options.cursorBlinkRate > 0)
      t.blinker = setInterval(function () {
        t.cursorDiv.style.visibility = (n = !n) ? '' : 'hidden';
      }, e.options.cursorBlinkRate);
    else if (e.options.cursorBlinkRate < 0) t.cursorDiv.style.visibility = 'hidden';
  }
  function Jt(e, t) {
    if (e.doc.mode.startState && e.doc.frontier < e.display.viewTo) e.state.highlight.set(t, Go(Kt, e));
  }
  function Kt(e) {
    var t = e.doc;
    if (t.frontier < t.first) t.frontier = t.first;
    if (t.frontier >= e.display.viewTo) return;
    var n = +new Date() + e.options.workTime;
    var r = Ni(t.mode, Gt(e, t.frontier));
    var i = [];
    t.iter(t.frontier, Math.min(t.first + t.size, e.display.viewTo + 500), function (s) {
      if (t.frontier >= e.display.viewFrom) {
        var o = s.styles;
        var u = Cs(e, s, r, true);
        s.styles = u.styles;
        var a = s.styleClasses,
          f = u.classes;
        if (f) s.styleClasses = f;
        else if (a) s.styleClasses = null;
        var l = !o || o.length != s.styles.length || (a != f && (!a || !f || a.bgClass != f.bgClass || a.textClass != f.textClass));
        for (var c = 0; !l && c < o.length; ++c) l = o[c] != s.styles[c];
        if (l) i.push(t.frontier);
        s.stateAfter = Ni(t.mode, r);
      } else {
        Ls(e, s.text, r);
        s.stateAfter = t.frontier % 5 == 0 ? Ni(t.mode, r) : null;
      }
      ++t.frontier;
      if (+new Date() > n) {
        Jt(e, e.options.workDelay);
        return true;
      }
    });
    if (i.length)
      Un(e, function () {
        for (var t = 0; t < i.length; t++) Kn(e, i[t], 'text');
      });
  }
  function Qt(e, t, n) {
    var r,
      i,
      s = e.doc;
    var o = n ? -1 : t - (e.doc.mode.innerMode ? 1e3 : 100);
    for (var u = t; u > o; --u) {
      if (u <= s.first) return s.first;
      var a = Ks(s, u - 1);
      if (a.stateAfter && (!n || u <= s.frontier)) return u;
      var f = Ro(a.text, null, e.options.tabSize);
      if (i == null || r > f) {
        i = u - 1;
        r = f;
      }
    }
    return i;
  }
  function Gt(e, t, n) {
    var r = e.doc,
      i = e.display;
    if (!r.mode.startState) return true;
    var s = Qt(e, t, n),
      o = s > r.first && Ks(r, s - 1).stateAfter;
    if (!o) o = Ci(r.mode);
    else o = Ni(r.mode, o);
    r.iter(s, t, function (n) {
      Ls(e, n.text, o);
      var u = s == t - 1 || s % 5 == 0 || (s >= i.viewFrom && s < i.viewTo);
      n.stateAfter = u ? Ni(r.mode, o) : null;
      ++s;
    });
    if (n) r.frontier = s;
    return o;
  }
  function Yt(e) {
    return e.lineSpace.offsetTop;
  }
  function Zt(e) {
    return e.mover.offsetHeight - e.lineSpace.offsetHeight;
  }
  function en(e) {
    if (e.cachedPaddingH) return e.cachedPaddingH;
    var t = uu(e.measure, iu('pre', 'x'));
    var n = window.getComputedStyle ? window.getComputedStyle(t) : t.currentStyle;
    var r = { left: parseInt(n.paddingLeft), right: parseInt(n.paddingRight) };
    if (!isNaN(r.left) && !isNaN(r.right)) e.cachedPaddingH = r;
    return r;
  }
  function tn(e) {
    return Ho - e.display.nativeBarWidth;
  }
  function nn(e) {
    return e.display.scroller.clientWidth - tn(e) - e.display.barWidth;
  }
  function rn(e) {
    return e.display.scroller.clientHeight - tn(e) - e.display.barHeight;
  }
  function sn(e, t, n) {
    var r = e.options.lineWrapping;
    var i = r && nn(e);
    if (!t.measure.heights || (r && t.measure.width != i)) {
      var s = (t.measure.heights = []);
      if (r) {
        t.measure.width = i;
        var o = t.text.firstChild.getClientRects();
        for (var u = 0; u < o.length - 1; u++) {
          var a = o[u],
            f = o[u + 1];
          if (Math.abs(a.bottom - f.bottom) > 2) s.push((a.bottom + f.top) / 2 - n.top);
        }
      }
      s.push(n.bottom - n.top);
    }
  }
  function on(e, t, n) {
    if (e.line == t) return { map: e.measure.map, cache: e.measure.cache };
    for (var r = 0; r < e.rest.length; r++) if (e.rest[r] == t) return { map: e.measure.maps[r], cache: e.measure.caches[r] };
    for (var r = 0; r < e.rest.length; r++) if (Zs(e.rest[r]) > n) return { map: e.measure.maps[r], cache: e.measure.caches[r], before: true };
  }
  function un(e, t) {
    t = as(t);
    var n = Zs(t);
    var r = (e.display.externalMeasured = new Vn(e.doc, t, n));
    r.lineN = n;
    var i = (r.built = _s(e, r));
    r.text = i.pre;
    uu(e.display.lineMeasure, i.pre);
    return r;
  }
  function an(e, t, n, r) {
    return cn(e, ln(e, t), n, r);
  }
  function fn(e, t) {
    if (t >= e.display.viewFrom && t < e.display.viewTo) return e.display.view[Gn(e, t)];
    var n = e.display.externalMeasured;
    if (n && t >= n.lineN && t < n.lineN + n.size) return n;
  }
  function ln(e, t) {
    var n = Zs(t);
    var r = fn(e, n);
    if (r && !r.text) r = null;
    else if (r && r.changes) rt(e, r, n, tt(e));
    if (!r) r = un(e, t);
    var i = on(r, t, n);
    return { line: t, view: r, rect: null, map: i.map, cache: i.cache, before: i.before, hasHeights: false };
  }
  function cn(e, t, n, r, i) {
    if (t.before) n = -1;
    var s = n + (r || ''),
      o;
    if (t.cache.hasOwnProperty(s)) {
      o = t.cache[s];
    } else {
      if (!t.rect) t.rect = t.view.text.getBoundingClientRect();
      if (!t.hasHeights) {
        sn(e, t.view, t.rect);
        t.hasHeights = true;
      }
      o = pn(e, t, n, r);
      if (!o.bogus) t.cache[s] = o;
    }
    return { left: o.left, right: o.right, top: i ? o.rtop : o.top, bottom: i ? o.rbottom : o.bottom };
  }
  function pn(e, t, n, s) {
    var o = t.map;
    var u, a, f, l;
    for (var c = 0; c < o.length; c += 3) {
      var h = o[c],
        p = o[c + 1];
      if (n < h) {
        a = 0;
        f = 1;
        l = 'left';
      } else if (n < p) {
        a = n - h;
        f = a + 1;
      } else if (c == o.length - 3 || (n == p && o[c + 3] > n)) {
        f = p - h;
        a = f - 1;
        if (n >= p) l = 'right';
      }
      if (a != null) {
        u = o[c + 2];
        if (h == p && s == (u.insertLeft ? 'left' : 'right')) l = s;
        if (s == 'left' && a == 0)
          while (c && o[c - 2] == o[c - 3] && o[c - 1].insertLeft) {
            u = o[(c -= 3) + 2];
            l = 'left';
          }
        if (s == 'right' && a == p - h)
          while (c < o.length - 3 && o[c + 3] == o[c + 4] && !o[c + 5].insertLeft) {
            u = o[(c += 3) + 2];
            l = 'right';
          }
        break;
      }
    }
    var d;
    if (u.nodeType == 3) {
      for (var c = 0; c < 4; c++) {
        while (a && ru(t.line.text.charAt(h + a))) --a;
        while (h + f < p && ru(t.line.text.charAt(h + f))) ++f;
        if (r && i < 9 && a == 0 && f == p - h) {
          d = u.parentNode.getBoundingClientRect();
        } else if (r && e.options.lineWrapping) {
          var v = su(u, a, f).getClientRects();
          if (v.length) d = v[s == 'right' ? v.length - 1 : 0];
          else d = hn;
        } else {
          d = su(u, a, f).getBoundingClientRect() || hn;
        }
        if (d.left || d.right || a == 0) break;
        f = a;
        a = a - 1;
        l = 'right';
      }
      if (r && i < 11) d = dn(e.display.measure, d);
    } else {
      if (a > 0) l = s = 'right';
      var v;
      if (e.options.lineWrapping && (v = u.getClientRects()).length > 1) d = v[s == 'right' ? v.length - 1 : 0];
      else d = u.getBoundingClientRect();
    }
    if (r && i < 9 && !a && (!d || (!d.left && !d.right))) {
      var m = u.parentNode.getClientRects()[0];
      if (m) d = { left: m.left, right: m.left + On(e.display), top: m.top, bottom: m.bottom };
      else d = hn;
    }
    var g = d.top - t.rect.top,
      y = d.bottom - t.rect.top;
    var b = (g + y) / 2;
    var w = t.view.measure.heights;
    for (var c = 0; c < w.length - 1; c++) if (b < w[c]) break;
    var E = c ? w[c - 1] : 0,
      S = w[c];
    var x = { left: (l == 'right' ? d.right : d.left) - t.rect.left, right: (l == 'left' ? d.left : d.right) - t.rect.left, top: E, bottom: S };
    if (!d.left && !d.right) x.bogus = true;
    if (!e.options.singleCursorHeightPerLine) {
      x.rtop = g;
      x.rbottom = y;
    }
    return x;
  }
  function dn(e, t) {
    if (!window.screen || screen.logicalXDPI == null || screen.logicalXDPI == screen.deviceXDPI || !ku(e)) return t;
    var n = screen.logicalXDPI / screen.deviceXDPI;
    var r = screen.logicalYDPI / screen.deviceYDPI;
    return { left: t.left * n, right: t.right * n, top: t.top * r, bottom: t.bottom * r };
  }
  function vn(e) {
    if (e.measure) {
      e.measure.cache = {};
      e.measure.heights = null;
      if (e.rest) for (var t = 0; t < e.rest.length; t++) e.measure.caches[t] = {};
    }
  }
  function mn(e) {
    e.display.externalMeasure = null;
    ou(e.display.lineMeasure);
    for (var t = 0; t < e.display.view.length; t++) vn(e.display.view[t]);
  }
  function gn(e) {
    mn(e);
    e.display.cachedCharWidth = e.display.cachedTextHeight = e.display.cachedPaddingH = null;
    if (!e.options.lineWrapping) e.display.maxLineChanged = true;
    e.display.lineNumChars = null;
  }
  function yn() {
    return window.pageXOffset || (document.documentElement || document.body).scrollLeft;
  }
  function bn() {
    return window.pageYOffset || (document.documentElement || document.body).scrollTop;
  }
  function wn(e, t, n, r) {
    if (t.widgets)
      for (var i = 0; i < t.widgets.length; ++i)
        if (t.widgets[i].above) {
          var s = ms(t.widgets[i]);
          n.top += s;
          n.bottom += s;
        }
    if (r == 'line') return n;
    if (!r) r = 'local';
    var o = to(t);
    if (r == 'local') o += Yt(e.display);
    else o -= e.display.viewOffset;
    if (r == 'page' || r == 'window') {
      var u = e.display.lineSpace.getBoundingClientRect();
      o += u.top + (r == 'window' ? 0 : bn());
      var a = u.left + (r == 'window' ? 0 : yn());
      n.left += a;
      n.right += a;
    }
    n.top += o;
    n.bottom += o;
    return n;
  }
  function En(e, t, n) {
    if (n == 'div') return t;
    var r = t.left,
      i = t.top;
    if (n == 'page') {
      r -= yn();
      i -= bn();
    } else if (n == 'local' || !n) {
      var s = e.display.sizer.getBoundingClientRect();
      r += s.left;
      i += s.top;
    }
    var o = e.display.lineSpace.getBoundingClientRect();
    return { left: r - o.left, top: i - o.top };
  }
  function Sn(e, t, n, r, i) {
    if (!r) r = Ks(e.doc, t.line);
    return wn(e, r, an(e, r, t.ch, i), n);
  }
  function xn(e, t, n, r, i, s) {
    function o(t, o) {
      var u = cn(e, i, t, o ? 'right' : 'left', s);
      if (o) u.left = u.right;
      else u.right = u.left;
      return wn(e, r, u, n);
    }
    function u(e, t) {
      var n = a[t],
        r = n.level % 2;
      if (e == Ou(n) && t && n.level < a[t - 1].level) {
        n = a[--t];
        e = Mu(n) - (n.level % 2 ? 0 : 1);
        r = true;
      } else if (e == Mu(n) && t < a.length - 1 && n.level < a[t + 1].level) {
        n = a[++t];
        e = Ou(n) - (n.level % 2);
        r = false;
      }
      if (r && e == n.to && e > n.from) return o(e - 1);
      return o(e, r);
    }
    r = r || Ks(e.doc, t.line);
    if (!i) i = ln(e, r);
    var a = no(r),
      f = t.ch;
    if (!a) return o(f);
    var l = Iu(a, f);
    var c = u(f, l);
    if (Fu != null) c.other = u(f, Fu);
    return c;
  }
  function Tn(e, t) {
    var n = 0,
      t = Nt(e.doc, t);
    if (!e.options.lineWrapping) n = On(e.display) * t.ch;
    var r = Ks(e.doc, t.line);
    var i = to(r) + Yt(e.display);
    return { left: n, right: n, top: i, bottom: i + r.height };
  }
  function Nn(e, t, n, r) {
    var i = vt(e, t);
    i.xRel = r;
    if (n) i.outside = true;
    return i;
  }
  function Cn(e, t, n) {
    var r = e.doc;
    n += e.display.viewOffset;
    if (n < 0) return Nn(r.first, 0, true, -1);
    var i = eo(r, n),
      s = r.first + r.size - 1;
    if (i > s) return Nn(r.first + r.size - 1, Ks(r, s).text.length, true, 1);
    if (t < 0) t = 0;
    var o = Ks(r, i);
    for (;;) {
      var u = kn(e, o, i, t, n);
      var a = os(o);
      var f = a && a.find(0, true);
      if (a && (u.ch > f.from.ch || (u.ch == f.from.ch && u.xRel > 0))) i = Zs((o = f.to.line));
      else return u;
    }
  }
  function kn(e, t, n, r, i) {
    function f(r) {
      var i = xn(e, vt(n, r), 'line', t, a);
      o = true;
      if (s > i.bottom) return i.left - u;
      else if (s < i.top) return i.left + u;
      else o = false;
      return i.left;
    }
    var s = i - to(t);
    var o = false,
      u = 2 * e.display.wrapper.clientWidth;
    var a = ln(e, t);
    var l = no(t),
      c = t.text.length;
    var h = _u(t),
      p = Du(t);
    var d = f(h),
      v = o,
      m = f(p),
      g = o;
    if (r > m) return Nn(n, p, g, 1);
    for (;;) {
      if (l ? p == h || p == Ru(t, h, 1) : p - h <= 1) {
        var y = r < d || r - d <= m - r ? h : p;
        var b = r - (y == h ? d : m);
        while (ru(t.text.charAt(y))) ++y;
        var w = Nn(n, y, y == h ? v : g, b < -1 ? -1 : b > 1 ? 1 : 0);
        return w;
      }
      var E = Math.ceil(c / 2),
        S = h + E;
      if (l) {
        S = h;
        for (var x = 0; x < E; ++x) S = Ru(t, S, 1);
      }
      var T = f(S);
      if (T > r) {
        p = S;
        m = T;
        if ((g = o)) m += 1e3;
        c = E;
      } else {
        h = S;
        d = T;
        v = o;
        c -= E;
      }
    }
  }
  function An(e) {
    if (e.cachedTextHeight != null) return e.cachedTextHeight;
    if (Ln == null) {
      Ln = iu('pre');
      for (var t = 0; t < 49; ++t) {
        Ln.appendChild(document.createTextNode('x'));
        Ln.appendChild(iu('br'));
      }
      Ln.appendChild(document.createTextNode('x'));
    }
    uu(e.measure, Ln);
    var n = Ln.offsetHeight / 50;
    if (n > 3) e.cachedTextHeight = n;
    ou(e.measure);
    return n || 1;
  }
  function On(e) {
    if (e.cachedCharWidth != null) return e.cachedCharWidth;
    var t = iu('span', 'xxxxxxxxxx');
    var n = iu('pre', [t]);
    uu(e.measure, n);
    var r = t.getBoundingClientRect(),
      i = (r.right - r.left) / 10;
    if (i > 2) e.cachedCharWidth = i;
    return i || 10;
  }
  function Dn(e) {
    e.curOp = {
      cm: e,
      viewChanged: false,
      startHeight: e.doc.height,
      forceUpdate: false,
      updateInput: null,
      typing: false,
      changeObjs: null,
      cursorActivityHandlers: null,
      cursorActivityCalled: 0,
      selectionChanged: false,
      updateMaxLine: false,
      scrollLeft: null,
      scrollTop: null,
      scrollToPos: null,
      id: ++_n,
    };
    if (Mn) {
      Mn.ops.push(e.curOp);
    } else {
      e.curOp.ownsGroup = Mn = { ops: [e.curOp], delayedCallbacks: [] };
    }
  }
  function Pn(e) {
    var t = e.delayedCallbacks,
      n = 0;
    do {
      for (; n < t.length; n++) t[n]();
      for (var r = 0; r < e.ops.length; r++) {
        var i = e.ops[r];
        if (i.cursorActivityHandlers) while (i.cursorActivityCalled < i.cursorActivityHandlers.length) i.cursorActivityHandlers[i.cursorActivityCalled++](i.cm);
      }
    } while (n < t.length);
  }
  function Hn(e) {
    var t = e.curOp,
      n = t.ownsGroup;
    if (!n) return;
    try {
      Pn(n);
    } finally {
      Mn = null;
      for (var r = 0; r < n.ops.length; r++) n.ops[r].cm.curOp = null;
      Bn(n);
    }
  }
  function Bn(e) {
    var t = e.ops;
    for (var n = 0; n < t.length; n++) jn(t[n]);
    for (var n = 0; n < t.length; n++) Fn(t[n]);
    for (var n = 0; n < t.length; n++) In(t[n]);
    for (var n = 0; n < t.length; n++) qn(t[n]);
    for (var n = 0; n < t.length; n++) Rn(t[n]);
  }
  function jn(e) {
    var t = e.cm,
      n = t.display;
    J(t);
    if (e.updateMaxLine) P(t);
    e.mustUpdate = e.viewChanged || e.forceUpdate || e.scrollTop != null || (e.scrollToPos && (e.scrollToPos.from.line < n.viewFrom || e.scrollToPos.to.line >= n.viewTo)) || (n.maxLineChanged && t.options.lineWrapping);
    e.update = e.mustUpdate && new $(t, e.mustUpdate && { top: e.scrollTop, ensure: e.scrollToPos }, e.forceUpdate);
  }
  function Fn(e) {
    e.updatedDisplay = e.mustUpdate && K(e.cm, e.update);
  }
  function In(e) {
    var t = e.cm,
      n = t.display;
    if (e.updatedDisplay) Z(t);
    e.barMeasure = B(t);
    if (n.maxLineChanged && !t.options.lineWrapping) {
      e.adjustWidthTo = an(t, n.maxLine, n.maxLine.text.length).left + 3;
      t.display.sizerWidth = e.adjustWidthTo;
      e.barMeasure.scrollWidth = Math.max(n.scroller.clientWidth, n.sizer.offsetLeft + e.adjustWidthTo + tn(t) + t.display.barWidth);
      e.maxScrollLeft = Math.max(0, n.sizer.offsetLeft + e.adjustWidthTo - nn(t));
    }
    if (e.updatedDisplay || e.selectionChanged) e.newSelectionNodes = Ut(t);
  }
  function qn(e) {
    var t = e.cm;
    if (e.adjustWidthTo != null) {
      t.display.sizer.style.minWidth = e.adjustWidthTo + 'px';
      if (e.maxScrollLeft < t.doc.scrollLeft) Nr(t, Math.min(t.display.scroller.scrollLeft, e.maxScrollLeft), true);
      t.display.maxLineChanged = false;
    }
    if (e.newSelectionNodes) zt(t, e.newSelectionNodes);
    if (e.updatedDisplay) Y(t, e.barMeasure);
    if (e.updatedDisplay || e.startHeight != t.doc.height) q(t, e.barMeasure);
    if (e.selectionChanged) $t(t);
    if (t.state.focused && e.updateInput) sr(t, e.typing);
  }
  function Rn(e) {
    var t = e.cm,
      n = t.display,
      r = t.doc;
    if (e.updatedDisplay) Q(t, e.update);
    if (n.wheelStartX != null && (e.scrollTop != null || e.scrollLeft != null || e.scrollToPos)) n.wheelStartX = n.wheelStartY = null;
    if (e.scrollTop != null && (n.scroller.scrollTop != e.scrollTop || e.forceScroll)) {
      r.scrollTop = Math.max(0, Math.min(n.scroller.scrollHeight - n.scroller.clientHeight, e.scrollTop));
      n.scrollbars.setScrollTop(r.scrollTop);
      n.scroller.scrollTop = r.scrollTop;
    }
    if (e.scrollLeft != null && (n.scroller.scrollLeft != e.scrollLeft || e.forceScroll)) {
      r.scrollLeft = Math.max(0, Math.min(n.scroller.scrollWidth - nn(t), e.scrollLeft));
      n.scrollbars.setScrollLeft(r.scrollLeft);
      n.scroller.scrollLeft = r.scrollLeft;
      z(t);
    }
    if (e.scrollToPos) {
      var i = si(t, Nt(r, e.scrollToPos.from), Nt(r, e.scrollToPos.to), e.scrollToPos.margin);
      if (e.scrollToPos.isCursor && t.state.focused) ii(t, i);
    }
    var s = e.maybeHiddenMarkers,
      o = e.maybeUnhiddenMarkers;
    if (s) for (var u = 0; u < s.length; ++u) if (!s[u].lines.length) ko(s[u], 'hide');
    if (o) for (var u = 0; u < o.length; ++u) if (o[u].lines.length) ko(o[u], 'unhide');
    if (n.wrapper.offsetHeight) r.scrollTop = t.display.scroller.scrollTop;
    if (e.changeObjs) ko(t, 'changes', t, e.changeObjs);
  }
  function Un(e, t) {
    if (e.curOp) return t();
    Dn(e);
    try {
      return t();
    } finally {
      Hn(e);
    }
  }
  function zn(e, t) {
    return function () {
      if (e.curOp) return t.apply(e, arguments);
      Dn(e);
      try {
        return t.apply(e, arguments);
      } finally {
        Hn(e);
      }
    };
  }
  function Wn(e) {
    return function () {
      if (this.curOp) return e.apply(this, arguments);
      Dn(this);
      try {
        return e.apply(this, arguments);
      } finally {
        Hn(this);
      }
    };
  }
  function Xn(e) {
    return function () {
      var t = this.cm;
      if (!t || t.curOp) return e.apply(this, arguments);
      Dn(t);
      try {
        return e.apply(this, arguments);
      } finally {
        Hn(t);
      }
    };
  }
  function Vn(e, t, n) {
    this.line = t;
    this.rest = fs(t);
    this.size = this.rest ? Zs(Xo(this.rest)) - n + 1 : 1;
    this.node = this.text = null;
    this.hidden = hs(e, t);
  }
  function $n(e, t, n) {
    var r = [],
      i;
    for (var s = t; s < n; s = i) {
      var o = new Vn(e.doc, Ks(e.doc, s), s);
      i = s + o.size;
      r.push(o);
    }
    return r;
  }
  function Jn(e, t, n, r) {
    if (t == null) t = e.doc.first;
    if (n == null) n = e.doc.first + e.doc.size;
    if (!r) r = 0;
    var i = e.display;
    if (r && n < i.viewTo && (i.updateLineNumbers == null || i.updateLineNumbers > t)) i.updateLineNumbers = t;
    e.curOp.viewChanged = true;
    if (t >= i.viewTo) {
      if (E && ls(e.doc, t) < i.viewTo) Qn(e);
    } else if (n <= i.viewFrom) {
      if (E && cs(e.doc, n + r) > i.viewFrom) {
        Qn(e);
      } else {
        i.viewFrom += r;
        i.viewTo += r;
      }
    } else if (t <= i.viewFrom && n >= i.viewTo) {
      Qn(e);
    } else if (t <= i.viewFrom) {
      var s = Yn(e, n, n + r, 1);
      if (s) {
        i.view = i.view.slice(s.index);
        i.viewFrom = s.lineN;
        i.viewTo += r;
      } else {
        Qn(e);
      }
    } else if (n >= i.viewTo) {
      var s = Yn(e, t, t, -1);
      if (s) {
        i.view = i.view.slice(0, s.index);
        i.viewTo = s.lineN;
      } else {
        Qn(e);
      }
    } else {
      var o = Yn(e, t, t, -1);
      var u = Yn(e, n, n + r, 1);
      if (o && u) {
        i.view = i.view
          .slice(0, o.index)
          .concat($n(e, o.lineN, u.lineN))
          .concat(i.view.slice(u.index));
        i.viewTo += r;
      } else {
        Qn(e);
      }
    }
    var a = i.externalMeasured;
    if (a) {
      if (n < a.lineN) a.lineN += r;
      else if (t < a.lineN + a.size) i.externalMeasured = null;
    }
  }
  function Kn(e, t, n) {
    e.curOp.viewChanged = true;
    var r = e.display,
      i = e.display.externalMeasured;
    if (i && t >= i.lineN && t < i.lineN + i.size) r.externalMeasured = null;
    if (t < r.viewFrom || t >= r.viewTo) return;
    var s = r.view[Gn(e, t)];
    if (s.node == null) return;
    var o = s.changes || (s.changes = []);
    if ($o(o, n) == -1) o.push(n);
  }
  function Qn(e) {
    e.display.viewFrom = e.display.viewTo = e.doc.first;
    e.display.view = [];
    e.display.viewOffset = 0;
  }
  function Gn(e, t) {
    if (t >= e.display.viewTo) return null;
    t -= e.display.viewFrom;
    if (t < 0) return null;
    var n = e.display.view;
    for (var r = 0; r < n.length; r++) {
      t -= n[r].size;
      if (t < 0) return r;
    }
  }
  function Yn(e, t, n, r) {
    var i = Gn(e, t),
      s,
      o = e.display.view;
    if (!E || n == e.doc.first + e.doc.size) return { index: i, lineN: n };
    for (var u = 0, a = e.display.viewFrom; u < i; u++) a += o[u].size;
    if (a != t) {
      if (r > 0) {
        if (i == o.length - 1) return null;
        s = a + o[i].size - t;
        i++;
      } else {
        s = a - t;
      }
      t += s;
      n += s;
    }
    while (ls(e.doc, n) != n) {
      if (i == (r < 0 ? 0 : o.length - 1)) return null;
      n += r * o[i - (r < 0 ? 1 : 0)].size;
      i += r;
    }
    return { index: i, lineN: n };
  }
  function Zn(e, t, n) {
    var r = e.display,
      i = r.view;
    if (i.length == 0 || t >= r.viewTo || n <= r.viewFrom) {
      r.view = $n(e, t, n);
      r.viewFrom = t;
    } else {
      if (r.viewFrom > t) r.view = $n(e, t, r.viewFrom).concat(r.view);
      else if (r.viewFrom < t) r.view = r.view.slice(Gn(e, t));
      r.viewFrom = t;
      if (r.viewTo < n) r.view = r.view.concat($n(e, r.viewTo, n));
      else if (r.viewTo > n) r.view = r.view.slice(0, Gn(e, n));
    }
    r.viewTo = n;
  }
  function er(e) {
    var t = e.display.view,
      n = 0;
    for (var r = 0; r < t.length; r++) {
      var i = t[r];
      if (!i.hidden && (!i.node || i.changes)) ++n;
    }
    return n;
  }
  function tr(e) {
    if (e.display.pollingFast) return;
    e.display.poll.set(e.options.pollInterval, function () {
      ir(e);
      if (e.state.focused) tr(e);
    });
  }
  function nr(e) {
    function n() {
      var r = ir(e);
      if (!r && !t) {
        t = true;
        e.display.poll.set(60, n);
      } else {
        e.display.pollingFast = false;
        tr(e);
      }
    }
    var t = false;
    e.display.pollingFast = true;
    e.display.poll.set(20, n);
  }
  function ir(e) {
    var t = e.display.input,
      n = e.display.prevInput,
      s = e.doc;
    if (!e.state.focused || (Tu(t) && !n) || ar(e) || e.options.disableInput || e.state.keySeq) return false;
    if (e.state.pasteIncoming && e.state.fakedLastChar) {
      t.value = t.value.substring(0, t.value.length - 1);
      e.state.fakedLastChar = false;
    }
    var o = t.value;
    if (o == n && !e.somethingSelected()) return false;
    if ((r && i >= 9 && e.display.inputHasSelection === o) || (v && /[\uf700-\uf7ff]/.test(o))) {
      sr(e);
      return false;
    }
    var u = !e.curOp;
    if (u) Dn(e);
    e.display.shift = false;
    if (o.charCodeAt(0) == 8203 && s.sel == e.display.selForContextMenu && !n) n = '​';
    var a = 0,
      f = Math.min(n.length, o.length);
    while (a < f && n.charCodeAt(a) == o.charCodeAt(a)) ++a;
    var l = o.slice(a),
      c = xu(l);
    var h = null;
    if (e.state.pasteIncoming && s.sel.ranges.length > 1) {
      if (rr && rr.join('\n') == l) h = s.sel.ranges.length % rr.length == 0 && Jo(rr, xu);
      else if (c.length == s.sel.ranges.length)
        h = Jo(c, function (e) {
          return [e];
        });
    }
    for (var p = s.sel.ranges.length - 1; p >= 0; p--) {
      var d = s.sel.ranges[p];
      var m = d.from(),
        g = d.to();
      if (a < n.length) m = vt(m.line, m.ch - (n.length - a));
      else if (e.state.overwrite && d.empty() && !e.state.pasteIncoming) g = vt(g.line, Math.min(Ks(s, g.line).text.length, g.ch + Xo(c).length));
      var y = e.curOp.updateInput;
      var b = { from: m, to: g, text: h ? h[p % h.length] : c, origin: e.state.pasteIncoming ? 'paste' : e.state.cutIncoming ? 'cut' : '+input' };
      Gr(e.doc, b);
      Ao(e, 'inputRead', e, b);
      if (l && !e.state.pasteIncoming && e.options.electricChars && e.options.smartIndent && d.head.ch < 100 && (!p || s.sel.ranges[p - 1].head.line != d.head.line)) {
        var w = e.getModeAt(d.head);
        var E = Xr(b);
        if (w.electricChars) {
          for (var S = 0; S < w.electricChars.length; S++)
            if (l.indexOf(w.electricChars.charAt(S)) > -1) {
              ci(e, E.line, 'smart');
              break;
            }
        } else if (w.electricInput) {
          if (w.electricInput.test(Ks(s, E.line).text.slice(0, E.ch))) ci(e, E.line, 'smart');
        }
      }
    }
    fi(e);
    e.curOp.updateInput = y;
    e.curOp.typing = true;
    if (o.length > 1e3 || o.indexOf('\n') > -1) t.value = e.display.prevInput = '';
    else e.display.prevInput = o;
    if (u) Hn(e);
    e.state.pasteIncoming = e.state.cutIncoming = false;
    return true;
  }
  function sr(e, t) {
    if (e.display.contextMenuPending) return;
    var n,
      s,
      o = e.doc;
    if (e.somethingSelected()) {
      e.display.prevInput = '';
      var u = o.sel.primary();
      n = Nu && (u.to().line - u.from().line > 100 || (s = e.getSelection()).length > 1e3);
      var a = n ? '-' : s || e.getSelection();
      e.display.input.value = a;
      if (e.state.focused) Vo(e.display.input);
      if (r && i >= 9) e.display.inputHasSelection = a;
    } else if (!t) {
      e.display.prevInput = e.display.input.value = '';
      if (r && i >= 9) e.display.inputHasSelection = null;
    }
    e.display.inaccurateSelection = n;
  }
  function or(e) {
    if (e.options.readOnly != 'nocursor' && (!d || fu() != e.display.input)) e.display.input.focus();
  }
  function ur(e) {
    if (!e.state.focused) {
      or(e);
      Rr(e);
    }
  }
  function ar(e) {
    return e.options.readOnly || e.doc.cantEdit;
  }
  function fr(e) {
    function n(t) {
      if (!Mo(e, t)) So(t);
    }
    function o(n) {
      if (e.somethingSelected()) {
        rr = e.getSelections();
        if (t.inaccurateSelection) {
          t.prevInput = '';
          t.inaccurateSelection = false;
          t.input.value = rr.join('\n');
          Vo(t.input);
        }
      } else {
        var r = [],
          i = [];
        for (var s = 0; s < e.doc.sel.ranges.length; s++) {
          var o = e.doc.sel.ranges[s].head.line;
          var u = { anchor: vt(o, 0), head: vt(o + 1, 0) };
          i.push(u);
          r.push(e.getRange(u.anchor, u.head));
        }
        if (n.type == 'cut') {
          e.setSelections(i, null, jo);
        } else {
          t.prevInput = '';
          t.input.value = r.join('\n');
          Vo(t.input);
        }
        rr = r;
      }
      if (n.type == 'cut') e.state.cutIncoming = true;
    }
    var t = e.display;
    No(t.scroller, 'mousedown', zn(e, pr));
    if (r && i < 11)
      No(
        t.scroller,
        'dblclick',
        zn(e, function (t) {
          if (Mo(e, t)) return;
          var n = hr(e, t);
          if (!n || wr(e, t) || cr(e.display, t)) return;
          bo(t);
          var r = e.findWordAt(n);
          Ot(e.doc, r.anchor, r.head);
        })
      );
    else
      No(t.scroller, 'dblclick', function (t) {
        Mo(e, t) || bo(t);
      });
    No(t.lineSpace, 'selectstart', function (e) {
      if (!cr(t, e)) bo(e);
    });
    if (!b)
      No(t.scroller, 'contextmenu', function (t) {
        zr(e, t);
      });
    No(t.scroller, 'scroll', function () {
      if (t.scroller.clientHeight) {
        Tr(e, t.scroller.scrollTop);
        Nr(e, t.scroller.scrollLeft, true);
        ko(e, 'scroll', e);
      }
    });
    No(t.scroller, 'mousewheel', function (t) {
      Ar(e, t);
    });
    No(t.scroller, 'DOMMouseScroll', function (t) {
      Ar(e, t);
    });
    No(t.wrapper, 'scroll', function () {
      t.wrapper.scrollTop = t.wrapper.scrollLeft = 0;
    });
    No(t.input, 'keyup', function (t) {
      Ir.call(e, t);
    });
    No(t.input, 'input', function () {
      if (r && i >= 9 && e.display.inputHasSelection) e.display.inputHasSelection = null;
      ir(e);
    });
    No(t.input, 'keydown', zn(e, jr));
    No(t.input, 'keypress', zn(e, qr));
    No(t.input, 'focus', Go(Rr, e));
    No(t.input, 'blur', Go(Ur, e));
    if (e.options.dragDrop) {
      No(t.scroller, 'dragstart', function (t) {
        xr(e, t);
      });
      No(t.scroller, 'dragenter', n);
      No(t.scroller, 'dragover', n);
      No(t.scroller, 'drop', zn(e, Sr));
    }
    No(t.scroller, 'paste', function (n) {
      if (cr(t, n)) return;
      e.state.pasteIncoming = true;
      or(e);
      nr(e);
    });
    No(t.input, 'paste', function () {
      if (s && !e.state.fakedLastChar && !(new Date() - e.state.lastMiddleDown < 200)) {
        var n = t.input.selectionStart,
          r = t.input.selectionEnd;
        t.input.value += '$';
        t.input.selectionEnd = r;
        t.input.selectionStart = n;
        e.state.fakedLastChar = true;
      }
      e.state.pasteIncoming = true;
      nr(e);
    });
    No(t.input, 'cut', o);
    No(t.input, 'copy', o);
    if (l)
      No(t.sizer, 'mouseup', function () {
        if (fu() == t.input) t.input.blur();
        or(e);
      });
  }
  function lr(e) {
    var t = e.display;
    if (t.lastWrapHeight == t.wrapper.clientHeight && t.lastWrapWidth == t.wrapper.clientWidth) return;
    t.cachedCharWidth = t.cachedTextHeight = t.cachedPaddingH = null;
    t.scrollbarsClipped = false;
    e.setSize();
  }
  function cr(e, t) {
    for (var n = xo(t); n != e.wrapper; n = n.parentNode) {
      if (!n || n.getAttribute('cm-ignore-events') == 'true' || (n.parentNode == e.sizer && n != e.mover)) return true;
    }
  }
  function hr(e, t, n, r) {
    var i = e.display;
    if (!n && xo(t).getAttribute('not-content') == 'true') return null;
    var s,
      o,
      u = i.lineSpace.getBoundingClientRect();
    try {
      s = t.clientX - u.left;
      o = t.clientY - u.top;
    } catch (t) {
      return null;
    }
    var a = Cn(e, s, o),
      f;
    if (r && a.xRel == 1 && (f = Ks(e.doc, a.line).text).length == a.ch) {
      var l = Ro(f, f.length, e.options.tabSize) - f.length;
      a = vt(a.line, Math.max(0, Math.round((s - en(e.display).left) / On(e.display)) - l));
    }
    return a;
  }
  function pr(e) {
    if (Mo(this, e)) return;
    var t = this,
      n = t.display;
    n.shift = e.shiftKey;
    if (cr(n, e)) {
      if (!s) {
        n.scroller.draggable = false;
        setTimeout(function () {
          n.scroller.draggable = true;
        }, 100);
      }
      return;
    }
    if (wr(t, e)) return;
    var r = hr(t, e);
    window.focus();
    switch (To(e)) {
      case 1:
        if (r) mr(t, e, r);
        else if (xo(e) == n.scroller) bo(e);
        break;
      case 2:
        if (s) t.state.lastMiddleDown = +new Date();
        if (r) Ot(t.doc, r);
        setTimeout(Go(or, t), 20);
        bo(e);
        break;
      case 3:
        if (b) zr(t, e);
        break;
    }
  }
  function mr(e, t, n) {
    setTimeout(Go(ur, e), 0);
    var r = +new Date(),
      i;
    if (vr && vr.time > r - 400 && mt(vr.pos, n) == 0) {
      i = 'triple';
    } else if (dr && dr.time > r - 400 && mt(dr.pos, n) == 0) {
      i = 'double';
      vr = { time: r, pos: n };
    } else {
      i = 'single';
      dr = { time: r, pos: n };
    }
    var s = e.doc.sel,
      o = v ? t.metaKey : t.ctrlKey,
      u;
    if (e.options.dragDrop && yu && !ar(e) && i == 'single' && (u = s.contains(n)) > -1 && !s.ranges[u].empty()) gr(e, t, n, o);
    else yr(e, t, n, i, o);
  }
  function gr(e, t, n, o) {
    var u = e.display;
    var a = zn(e, function (f) {
      if (s) u.scroller.draggable = false;
      e.state.draggingText = false;
      Co(document, 'mouseup', a);
      Co(u.scroller, 'drop', a);
      if (Math.abs(t.clientX - f.clientX) + Math.abs(t.clientY - f.clientY) < 10) {
        bo(f);
        if (!o) Ot(e.doc, n);
        or(e);
        if (r && i == 9)
          setTimeout(function () {
            document.body.focus();
            or(e);
          }, 20);
      }
    });
    if (s) u.scroller.draggable = true;
    e.state.draggingText = a;
    if (u.scroller.dragDrop) u.scroller.dragDrop();
    No(document, 'mouseup', a);
    No(u.scroller, 'drop', a);
  }
  function yr(e, t, n, r, i) {
    function d(t) {
      if (mt(p, t) == 0) return;
      p = t;
      if (r == 'rect') {
        var i = [],
          s = e.options.tabSize;
        var l = Ro(Ks(o, n.line).text, n.ch, s);
        var c = Ro(Ks(o, t.line).text, t.ch, s);
        var h = Math.min(l, c),
          d = Math.max(l, c);
        for (var v = Math.min(n.line, t.line), m = Math.min(e.lastLine(), Math.max(n.line, t.line)); v <= m; v++) {
          var g = Ks(o, v).text,
            y = Uo(g, h, s);
          if (h == d) i.push(new Et(vt(v, y), vt(v, y)));
          else if (g.length > y) i.push(new Et(vt(v, y), vt(v, Uo(g, d, s))));
        }
        if (!i.length) i.push(new Et(n, n));
        Bt(o, St(f.ranges.slice(0, a).concat(i), a), { origin: '*mouse', scroll: false });
        e.scrollIntoView(t);
      } else {
        var b = u;
        var w = b.anchor,
          E = t;
        if (r != 'single') {
          if (r == 'double') var S = e.findWordAt(t);
          else var S = new Et(vt(t.line, 0), Nt(o, vt(t.line + 1, 0)));
          if (mt(S.anchor, w) > 0) {
            E = S.head;
            w = bt(b.from(), S.anchor);
          } else {
            E = S.anchor;
            w = yt(b.to(), S.head);
          }
        }
        var i = f.ranges.slice(0);
        i[a] = new Et(Nt(o, w), E);
        Bt(o, St(i, a), Fo);
      }
    }
    function g(t) {
      var n = ++m;
      var i = hr(e, t, true, r == 'rect');
      if (!i) return;
      if (mt(i, p) != 0) {
        ur(e);
        d(i);
        var u = U(s, o);
        if (i.line >= u.to || i.line < u.from)
          setTimeout(
            zn(e, function () {
              if (m == n) g(t);
            }),
            150
          );
      } else {
        var a = t.clientY < v.top ? -20 : t.clientY > v.bottom ? 20 : 0;
        if (a)
          setTimeout(
            zn(e, function () {
              if (m != n) return;
              s.scroller.scrollTop += a;
              g(t);
            }),
            50
          );
      }
    }
    function y(t) {
      m = Infinity;
      bo(t);
      or(e);
      Co(document, 'mousemove', b);
      Co(document, 'mouseup', w);
      o.history.lastSelOrigin = null;
    }
    var s = e.display,
      o = e.doc;
    bo(t);
    var u,
      a,
      f = o.sel,
      l = f.ranges;
    if (i && !t.shiftKey) {
      a = o.sel.contains(n);
      if (a > -1) u = l[a];
      else u = new Et(n, n);
    } else {
      u = o.sel.primary();
    }
    if (t.altKey) {
      r = 'rect';
      if (!i) u = new Et(n, n);
      n = hr(e, t, true, true);
      a = -1;
    } else if (r == 'double') {
      var c = e.findWordAt(n);
      if (e.display.shift || o.extend) u = At(o, u, c.anchor, c.head);
      else u = c;
    } else if (r == 'triple') {
      var h = new Et(vt(n.line, 0), Nt(o, vt(n.line + 1, 0)));
      if (e.display.shift || o.extend) u = At(o, u, h.anchor, h.head);
      else u = h;
    } else {
      u = At(o, u, n);
    }
    if (!i) {
      a = 0;
      Bt(o, new wt([u], 0), Fo);
      f = o.sel;
    } else if (a == -1) {
      a = l.length;
      Bt(o, St(l.concat([u]), a), { scroll: false, origin: '*mouse' });
    } else if (l.length > 1 && l[a].empty() && r == 'single') {
      Bt(o, St(l.slice(0, a).concat(l.slice(a + 1)), 0));
      f = o.sel;
    } else {
      _t(o, a, u, Fo);
    }
    var p = n;
    var v = s.wrapper.getBoundingClientRect();
    var m = 0;
    var b = zn(e, function (e) {
      if (!To(e)) y(e);
      else g(e);
    });
    var w = zn(e, y);
    No(document, 'mousemove', b);
    No(document, 'mouseup', w);
  }
  function br(e, t, n, r, i) {
    try {
      var s = t.clientX,
        o = t.clientY;
    } catch (t) {
      return false;
    }
    if (s >= Math.floor(e.display.gutters.getBoundingClientRect().right)) return false;
    if (r) bo(t);
    var u = e.display;
    var a = u.lineDiv.getBoundingClientRect();
    if (o > a.bottom || !Do(e, n)) return Eo(t);
    o -= a.top - u.viewOffset;
    for (var f = 0; f < e.options.gutters.length; ++f) {
      var l = u.gutters.childNodes[f];
      if (l && l.getBoundingClientRect().right >= s) {
        var c = eo(e.doc, o);
        var h = e.options.gutters[f];
        i(e, n, e, c, h, t);
        return Eo(t);
      }
    }
  }
  function wr(e, t) {
    return br(e, t, 'gutterClick', true, Ao);
  }
  function Sr(e) {
    var t = this;
    if (Mo(t, e) || cr(t.display, e)) return;
    bo(e);
    if (r) Er = +new Date();
    var n = hr(t, e, true),
      i = e.dataTransfer.files;
    if (!n || ar(t)) return;
    if (i && i.length && window.FileReader && window.File) {
      var s = i.length,
        o = Array(s),
        u = 0;
      var a = function (e, r) {
        var i = new FileReader();
        i.onload = zn(t, function () {
          o[r] = i.result;
          if (++u == s) {
            n = Nt(t.doc, n);
            var e = { from: n, to: n, text: xu(o.join('\n')), origin: 'paste' };
            Gr(t.doc, e);
            Ht(t.doc, xt(n, Xr(e)));
          }
        });
        i.readAsText(e);
      };
      for (var f = 0; f < s; ++f) a(i[f], f);
    } else {
      if (t.state.draggingText && t.doc.sel.contains(n) > -1) {
        t.state.draggingText(e);
        setTimeout(Go(or, t), 20);
        return;
      }
      try {
        var o = e.dataTransfer.getData('Text');
        if (o) {
          if (t.state.draggingText && !(v ? e.metaKey : e.ctrlKey)) var l = t.listSelections();
          jt(t.doc, xt(n, n));
          if (l) for (var f = 0; f < l.length; ++f) ri(t.doc, '', l[f].anchor, l[f].head, 'drag');
          t.replaceSelection(o, 'around', 'paste');
          or(t);
        }
      } catch (e) {}
    }
  }
  function xr(e, t) {
    if (r && (!e.state.draggingText || +new Date() - Er < 100)) {
      So(t);
      return;
    }
    if (Mo(e, t) || cr(e.display, t)) return;
    t.dataTransfer.setData('Text', e.getSelection());
    if (t.dataTransfer.setDragImage && !f) {
      var n = iu('img', null, null, 'position: fixed; left: 0; top: 0;');
      n.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
      if (a) {
        n.width = n.height = 1;
        e.display.wrapper.appendChild(n);
        n._top = n.offsetTop;
      }
      t.dataTransfer.setDragImage(n, 0, 0);
      if (a) n.parentNode.removeChild(n);
    }
  }
  function Tr(t, n) {
    if (Math.abs(t.doc.scrollTop - n) < 2) return;
    t.doc.scrollTop = n;
    if (!e) G(t, { top: n });
    if (t.display.scroller.scrollTop != n) t.display.scroller.scrollTop = n;
    t.display.scrollbars.setScrollTop(n);
    if (e) G(t);
    Jt(t, 100);
  }
  function Nr(e, t, n) {
    if (n ? t == e.doc.scrollLeft : Math.abs(e.doc.scrollLeft - t) < 2) return;
    t = Math.min(t, e.display.scroller.scrollWidth - e.display.scroller.clientWidth);
    e.doc.scrollLeft = t;
    z(e);
    if (e.display.scroller.scrollLeft != t) e.display.scroller.scrollLeft = t;
    e.display.scrollbars.setScrollLeft(t);
  }
  function Ar(t, n) {
    var r = Lr(n),
      i = r.x,
      o = r.y;
    var u = t.display,
      f = u.scroller;
    if (!((i && f.scrollWidth > f.clientWidth) || (o && f.scrollHeight > f.clientHeight))) return;
    if (o && v && s) {
      e: for (var l = n.target, c = u.view; l != f; l = l.parentNode) {
        for (var h = 0; h < c.length; h++) {
          if (c[h].node == l) {
            t.display.currentWheelTarget = l;
            break e;
          }
        }
      }
    }
    if (i && !e && !a && kr != null) {
      if (o) Tr(t, Math.max(0, Math.min(f.scrollTop + o * kr, f.scrollHeight - f.clientHeight)));
      Nr(t, Math.max(0, Math.min(f.scrollLeft + i * kr, f.scrollWidth - f.clientWidth)));
      bo(n);
      u.wheelStartX = null;
      return;
    }
    if (o && kr != null) {
      var p = o * kr;
      var d = t.doc.scrollTop,
        m = d + u.wrapper.clientHeight;
      if (p < 0) d = Math.max(0, d + p - 50);
      else m = Math.min(t.doc.height, m + p + 50);
      G(t, { top: d, bottom: m });
    }
    if (Cr < 20) {
      if (u.wheelStartX == null) {
        u.wheelStartX = f.scrollLeft;
        u.wheelStartY = f.scrollTop;
        u.wheelDX = i;
        u.wheelDY = o;
        setTimeout(function () {
          if (u.wheelStartX == null) return;
          var e = f.scrollLeft - u.wheelStartX;
          var t = f.scrollTop - u.wheelStartY;
          var n = (t && u.wheelDY && t / u.wheelDY) || (e && u.wheelDX && e / u.wheelDX);
          u.wheelStartX = u.wheelStartY = null;
          if (!n) return;
          kr = (kr * Cr + n) / (Cr + 1);
          ++Cr;
        }, 200);
      } else {
        u.wheelDX += i;
        u.wheelDY += o;
      }
    }
  }
  function Or(e, t, n) {
    if (typeof t == 'string') {
      t = ki[t];
      if (!t) return false;
    }
    if (e.display.pollingFast && ir(e)) e.display.pollingFast = false;
    var r = e.display.shift,
      i = false;
    try {
      if (ar(e)) e.state.suppressEdits = true;
      if (n) e.display.shift = false;
      i = t(e) != Bo;
    } finally {
      e.display.shift = r;
      e.state.suppressEdits = false;
    }
    return i;
  }
  function Mr(e, t, n) {
    for (var r = 0; r < e.state.keyMaps.length; r++) {
      var i = Oi(t, e.state.keyMaps[r], n, e);
      if (i) return i;
    }
    return (e.options.extraKeys && Oi(t, e.options.extraKeys, n, e)) || Oi(t, e.options.keyMap, n, e);
  }
  function Dr(e, t, n, r) {
    var i = e.state.keySeq;
    if (i) {
      if (Mi(t)) return 'handled';
      _r.set(50, function () {
        if (e.state.keySeq == i) {
          e.state.keySeq = null;
          sr(e);
        }
      });
      t = i + ' ' + t;
    }
    var s = Mr(e, t, r);
    if (s == 'multi') e.state.keySeq = t;
    if (s == 'handled') Ao(e, 'keyHandled', e, t, n);
    if (s == 'handled' || s == 'multi') {
      bo(n);
      $t(e);
    }
    if (i && !s && /\'$/.test(t)) {
      bo(n);
      return true;
    }
    return !!s;
  }
  function Pr(e, t) {
    var n = _i(t, true);
    if (!n) return false;
    if (t.shiftKey && !e.state.keySeq) {
      return (
        Dr(e, 'Shift-' + n, t, function (t) {
          return Or(e, t, true);
        }) ||
        Dr(e, n, t, function (t) {
          if (typeof t == 'string' ? /^go[A-Z]/.test(t) : t.motion) return Or(e, t);
        })
      );
    } else {
      return Dr(e, n, t, function (t) {
        return Or(e, t);
      });
    }
  }
  function Hr(e, t, n) {
    return Dr(e, "'" + n + "'", t, function (t) {
      return Or(e, t, true);
    });
  }
  function jr(e) {
    var t = this;
    ur(t);
    if (Mo(t, e)) return;
    if (r && i < 11 && e.keyCode == 27) e.returnValue = false;
    var n = e.keyCode;
    t.display.shift = n == 16 || e.shiftKey;
    var s = Pr(t, e);
    if (a) {
      Br = s ? n : null;
      if (!s && n == 88 && !Nu && (v ? e.metaKey : e.ctrlKey)) t.replaceSelection('', null, 'cut');
    }
    if (n == 18 && !/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)) Fr(t);
  }
  function Fr(e) {
    function n(e) {
      if (e.keyCode == 18 || !e.altKey) {
        cu(t, 'CodeMirror-crosshair');
        Co(document, 'keyup', n);
        Co(document, 'mouseover', n);
      }
    }
    var t = e.display.lineDiv;
    hu(t, 'CodeMirror-crosshair');
    No(document, 'keyup', n);
    No(document, 'mouseover', n);
  }
  function Ir(e) {
    if (e.keyCode == 16) this.doc.sel.shift = false;
    Mo(this, e);
  }
  function qr(e) {
    var t = this;
    if (Mo(t, e) || (e.ctrlKey && !e.altKey) || (v && e.metaKey)) return;
    var n = e.keyCode,
      s = e.charCode;
    if (a && n == Br) {
      Br = null;
      bo(e);
      return;
    }
    if (((a && (!e.which || e.which < 10)) || l) && Pr(t, e)) return;
    var o = String.fromCharCode(s == null ? n : s);
    if (Hr(t, e, o)) return;
    if (r && i >= 9) t.display.inputHasSelection = null;
    nr(t);
  }
  function Rr(e) {
    if (e.options.readOnly == 'nocursor') return;
    if (!e.state.focused) {
      ko(e, 'focus', e);
      e.state.focused = true;
      hu(e.display.wrapper, 'CodeMirror-focused');
      if (!e.curOp && e.display.selForContextMenu != e.doc.sel) {
        sr(e);
        if (s) setTimeout(Go(sr, e, true), 0);
      }
    }
    tr(e);
    $t(e);
  }
  function Ur(e) {
    if (e.state.focused) {
      ko(e, 'blur', e);
      e.state.focused = false;
      cu(e.display.wrapper, 'CodeMirror-focused');
    }
    clearInterval(e.display.blinker);
    setTimeout(function () {
      if (!e.state.focused) e.display.shift = false;
    }, 150);
  }
  function zr(e, t) {
    function h() {
      if (n.input.selectionStart != null) {
        var t = e.somethingSelected();
        var r = (n.input.value = '​' + (t ? n.input.value : ''));
        n.prevInput = t ? '' : '​';
        n.input.selectionStart = 1;
        n.input.selectionEnd = r.length;
        n.selForContextMenu = e.doc.sel;
      }
    }
    function p() {
      n.contextMenuPending = false;
      n.inputDiv.style.position = 'relative';
      n.input.style.cssText = l;
      if (r && i < 9) n.scrollbars.setScrollTop((n.scroller.scrollTop = u));
      tr(e);
      if (n.input.selectionStart != null) {
        if (!r || (r && i < 9)) h();
        var t = 0,
          s = function () {
            if (n.selForContextMenu == e.doc.sel && n.input.selectionStart == 0) zn(e, ki.selectAll)(e);
            else if (t++ < 10) n.detectingSelectAll = setTimeout(s, 500);
            else sr(e);
          };
        n.detectingSelectAll = setTimeout(s, 200);
      }
    }
    if (Mo(e, t, 'contextmenu')) return;
    var n = e.display;
    if (cr(n, t) || Wr(e, t)) return;
    var o = hr(e, t),
      u = n.scroller.scrollTop;
    if (!o || a) return;
    var f = e.options.resetSelectionOnContextMenu;
    if (f && e.doc.sel.contains(o) == -1) zn(e, Bt)(e.doc, xt(o), jo);
    var l = n.input.style.cssText;
    n.inputDiv.style.position = 'absolute';
    n.input.style.cssText =
      'position: fixed; width: 30px; height: 30px; top: ' +
      (t.clientY - 5) +
      'px; left: ' +
      (t.clientX - 5) +
      'px; z-index: 1000; background: ' +
      (r ? 'rgba(255, 255, 255, .05)' : 'transparent') +
      '; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);';
    if (s) var c = window.scrollY;
    or(e);
    if (s) window.scrollTo(null, c);
    sr(e);
    if (!e.somethingSelected()) n.input.value = n.prevInput = ' ';
    n.contextMenuPending = true;
    n.selForContextMenu = e.doc.sel;
    clearTimeout(n.detectingSelectAll);
    if (r && i >= 9) h();
    if (b) {
      So(t);
      var d = function () {
        Co(window, 'mouseup', d);
        setTimeout(p, 20);
      };
      No(window, 'mouseup', d);
    } else {
      setTimeout(p, 50);
    }
  }
  function Wr(e, t) {
    if (!Do(e, 'gutterContextMenu')) return false;
    return br(e, t, 'gutterContextMenu', false, ko);
  }
  function Vr(e, t) {
    if (mt(e, t.from) < 0) return e;
    if (mt(e, t.to) <= 0) return Xr(t);
    var n = e.line + t.text.length - (t.to.line - t.from.line) - 1,
      r = e.ch;
    if (e.line == t.to.line) r += Xr(t).ch - t.to.ch;
    return vt(n, r);
  }
  function $r(e, t) {
    var n = [];
    for (var r = 0; r < e.sel.ranges.length; r++) {
      var i = e.sel.ranges[r];
      n.push(new Et(Vr(i.anchor, t), Vr(i.head, t)));
    }
    return St(n, e.sel.primIndex);
  }
  function Jr(e, t, n) {
    if (e.line == t.line) return vt(n.line, e.ch - t.ch + n.ch);
    else return vt(n.line + (e.line - t.line), e.ch);
  }
  function Kr(e, t, n) {
    var r = [];
    var i = vt(e.first, 0),
      s = i;
    for (var o = 0; o < t.length; o++) {
      var u = t[o];
      var a = Jr(u.from, i, s);
      var f = Jr(Xr(u), i, s);
      i = u.to;
      s = f;
      if (n == 'around') {
        var l = e.sel.ranges[o],
          c = mt(l.head, l.anchor) < 0;
        r[o] = new Et(c ? f : a, c ? a : f);
      } else {
        r[o] = new Et(a, a);
      }
    }
    return new wt(r, e.sel.primIndex);
  }
  function Qr(e, t, n) {
    var r = {
      canceled: false,
      from: t.from,
      to: t.to,
      text: t.text,
      origin: t.origin,
      cancel: function () {
        this.canceled = true;
      },
    };
    if (n)
      r.update = function (t, n, r, i) {
        if (t) this.from = Nt(e, t);
        if (n) this.to = Nt(e, n);
        if (r) this.text = r;
        if (i !== undefined) this.origin = i;
      };
    ko(e, 'beforeChange', e, r);
    if (e.cm) ko(e.cm, 'beforeChange', e.cm, r);
    if (r.canceled) return null;
    return { from: r.from, to: r.to, text: r.text, origin: r.origin };
  }
  function Gr(e, t, n) {
    if (e.cm) {
      if (!e.cm.curOp) return zn(e.cm, Gr)(e, t, n);
      if (e.cm.state.suppressEdits) return;
    }
    if (Do(e, 'beforeChange') || (e.cm && Do(e.cm, 'beforeChange'))) {
      t = Qr(e, t, true);
      if (!t) return;
    }
    var r = w && !n && Yi(e, t.from, t.to);
    if (r) {
      for (var i = r.length - 1; i >= 0; --i) Yr(e, { from: r[i].from, to: r[i].to, text: i ? [''] : t.text });
    } else {
      Yr(e, t);
    }
  }
  function Yr(e, t) {
    if (t.text.length == 1 && t.text[0] == '' && mt(t.from, t.to) == 0) return;
    var n = $r(e, t);
    uo(e, t, n, e.cm ? e.cm.curOp.id : NaN);
    ti(e, t, n, Ki(e, t));
    var r = [];
    $s(e, function (e, n) {
      if (!n && $o(r, e.history) == -1) {
        yo(e.history, t);
        r.push(e.history);
      }
      ti(e, t, null, Ki(e, t));
    });
  }
  function Zr(e, t, n) {
    if (e.cm && e.cm.state.suppressEdits) return;
    var r = e.history,
      i,
      s = e.sel;
    var o = t == 'undo' ? r.done : r.undone,
      u = t == 'undo' ? r.undone : r.done;
    for (var a = 0; a < o.length; a++) {
      i = o[a];
      if (n ? i.ranges && !i.equals(e.sel) : !i.ranges) break;
    }
    if (a == o.length) return;
    r.lastOrigin = r.lastSelOrigin = null;
    for (;;) {
      i = o.pop();
      if (i.ranges) {
        lo(i, u);
        if (n && !i.equals(e.sel)) {
          Bt(e, i, { clearRedo: false });
          return;
        }
        s = i;
      } else break;
    }
    var f = [];
    lo(s, u);
    u.push({ changes: f, generation: r.generation });
    r.generation = i.generation || ++r.maxGeneration;
    var l = Do(e, 'beforeChange') || (e.cm && Do(e.cm, 'beforeChange'));
    for (var a = i.changes.length - 1; a >= 0; --a) {
      var c = i.changes[a];
      c.origin = t;
      if (l && !Qr(e, c, false)) {
        o.length = 0;
        return;
      }
      f.push(io(e, c));
      var h = a ? $r(e, c) : Xo(o);
      ti(e, c, h, Gi(e, c));
      if (!a && e.cm) e.cm.scrollIntoView({ from: c.from, to: Xr(c) });
      var p = [];
      $s(e, function (e, t) {
        if (!t && $o(p, e.history) == -1) {
          yo(e.history, c);
          p.push(e.history);
        }
        ti(e, c, null, Gi(e, c));
      });
    }
  }
  function ei(e, t) {
    if (t == 0) return;
    e.first += t;
    e.sel = new wt(
      Jo(e.sel.ranges, function (e) {
        return new Et(vt(e.anchor.line + t, e.anchor.ch), vt(e.head.line + t, e.head.ch));
      }),
      e.sel.primIndex
    );
    if (e.cm) {
      Jn(e.cm, e.first, e.first - t, t);
      for (var n = e.cm.display, r = n.viewFrom; r < n.viewTo; r++) Kn(e.cm, r, 'gutter');
    }
  }
  function ti(e, t, n, r) {
    if (e.cm && !e.cm.curOp) return zn(e.cm, ti)(e, t, n, r);
    if (t.to.line < e.first) {
      ei(e, t.text.length - 1 - (t.to.line - t.from.line));
      return;
    }
    if (t.from.line > e.lastLine()) return;
    if (t.from.line < e.first) {
      var i = t.text.length - 1 - (e.first - t.from.line);
      ei(e, i);
      t = { from: vt(e.first, 0), to: vt(t.to.line + i, t.to.ch), text: [Xo(t.text)], origin: t.origin };
    }
    var s = e.lastLine();
    if (t.to.line > s) {
      t = { from: t.from, to: vt(s, Ks(e, s).text.length), text: [t.text[0]], origin: t.origin };
    }
    t.removed = Qs(e, t.from, t.to);
    if (!n) n = $r(e, t);
    if (e.cm) ni(e.cm, t, r);
    else qs(e, t, r);
    jt(e, n, jo);
  }
  function ni(e, t, n) {
    var r = e.doc,
      i = e.display,
      s = t.from,
      o = t.to;
    var u = false,
      a = s.line;
    if (!e.options.lineWrapping) {
      a = Zs(as(Ks(r, s.line)));
      r.iter(a, o.line + 1, function (e) {
        if (e == i.maxLine) {
          u = true;
          return true;
        }
      });
    }
    if (r.sel.contains(t.from, t.to) > -1) _o(e);
    qs(r, t, n, k(e));
    if (!e.options.lineWrapping) {
      r.iter(a, s.line + t.text.length, function (e) {
        var t = D(e);
        if (t > i.maxLineLength) {
          i.maxLine = e;
          i.maxLineLength = t;
          i.maxLineChanged = true;
          u = false;
        }
      });
      if (u) e.curOp.updateMaxLine = true;
    }
    r.frontier = Math.min(r.frontier, s.line);
    Jt(e, 400);
    var f = t.text.length - (o.line - s.line) - 1;
    if (s.line == o.line && t.text.length == 1 && !Is(e.doc, t)) Kn(e, s.line, 'text');
    else Jn(e, s.line, o.line + 1, f);
    var l = Do(e, 'changes'),
      c = Do(e, 'change');
    if (c || l) {
      var h = { from: s, to: o, text: t.text, removed: t.removed, origin: t.origin };
      if (c) Ao(e, 'change', e, h);
      if (l) (e.curOp.changeObjs || (e.curOp.changeObjs = [])).push(h);
    }
    e.display.selForContextMenu = null;
  }
  function ri(e, t, n, r, i) {
    if (!r) r = n;
    if (mt(r, n) < 0) {
      var s = r;
      r = n;
      n = s;
    }
    if (typeof t == 'string') t = xu(t);
    Gr(e, { from: n, to: r, text: t, origin: i });
  }
  function ii(e, t) {
    if (Mo(e, 'scrollCursorIntoView')) return;
    var n = e.display,
      r = n.sizer.getBoundingClientRect(),
      i = null;
    if (t.top + r.top < 0) i = true;
    else if (t.bottom + r.top > (window.innerHeight || document.documentElement.clientHeight)) i = false;
    if (i != null && !h) {
      var s = iu('div', '​', null, 'position: absolute; top: ' + (t.top - n.viewOffset - Yt(e.display)) + 'px; height: ' + (t.bottom - t.top + tn(e) + n.barHeight) + 'px; left: ' + t.left + 'px; width: 2px;');
      e.display.lineSpace.appendChild(s);
      s.scrollIntoView(i);
      e.display.lineSpace.removeChild(s);
    }
  }
  function si(e, t, n, r) {
    if (r == null) r = 0;
    for (var i = 0; i < 5; i++) {
      var s = false,
        o = xn(e, t);
      var u = !n || n == t ? o : xn(e, n);
      var a = ui(e, Math.min(o.left, u.left), Math.min(o.top, u.top) - r, Math.max(o.left, u.left), Math.max(o.bottom, u.bottom) + r);
      var f = e.doc.scrollTop,
        l = e.doc.scrollLeft;
      if (a.scrollTop != null) {
        Tr(e, a.scrollTop);
        if (Math.abs(e.doc.scrollTop - f) > 1) s = true;
      }
      if (a.scrollLeft != null) {
        Nr(e, a.scrollLeft);
        if (Math.abs(e.doc.scrollLeft - l) > 1) s = true;
      }
      if (!s) break;
    }
    return o;
  }
  function oi(e, t, n, r, i) {
    var s = ui(e, t, n, r, i);
    if (s.scrollTop != null) Tr(e, s.scrollTop);
    if (s.scrollLeft != null) Nr(e, s.scrollLeft);
  }
  function ui(e, t, n, r, i) {
    var s = e.display,
      o = An(e.display);
    if (n < 0) n = 0;
    var u = e.curOp && e.curOp.scrollTop != null ? e.curOp.scrollTop : s.scroller.scrollTop;
    var a = rn(e),
      f = {};
    if (i - n > a) i = n + a;
    var l = e.doc.height + Zt(s);
    var c = n < o,
      h = i > l - o;
    if (n < u) {
      f.scrollTop = c ? 0 : n;
    } else if (i > u + a) {
      var p = Math.min(n, (h ? l : i) - a);
      if (p != u) f.scrollTop = p;
    }
    var d = e.curOp && e.curOp.scrollLeft != null ? e.curOp.scrollLeft : s.scroller.scrollLeft;
    var v = nn(e) - (e.options.fixedGutter ? s.gutters.offsetWidth : 0);
    var m = r - t > v;
    if (m) r = t + v;
    if (t < 10) f.scrollLeft = 0;
    else if (t < d) f.scrollLeft = Math.max(0, t - (m ? 0 : 10));
    else if (r > v + d - 3) f.scrollLeft = r + (m ? 0 : 10) - v;
    return f;
  }
  function ai(e, t, n) {
    if (t != null || n != null) li(e);
    if (t != null) e.curOp.scrollLeft = (e.curOp.scrollLeft == null ? e.doc.scrollLeft : e.curOp.scrollLeft) + t;
    if (n != null) e.curOp.scrollTop = (e.curOp.scrollTop == null ? e.doc.scrollTop : e.curOp.scrollTop) + n;
  }
  function fi(e) {
    li(e);
    var t = e.getCursor(),
      n = t,
      r = t;
    if (!e.options.lineWrapping) {
      n = t.ch ? vt(t.line, t.ch - 1) : t;
      r = vt(t.line, t.ch + 1);
    }
    e.curOp.scrollToPos = { from: n, to: r, margin: e.options.cursorScrollMargin, isCursor: true };
  }
  function li(e) {
    var t = e.curOp.scrollToPos;
    if (t) {
      e.curOp.scrollToPos = null;
      var n = Tn(e, t.from),
        r = Tn(e, t.to);
      var i = ui(e, Math.min(n.left, r.left), Math.min(n.top, r.top) - t.margin, Math.max(n.right, r.right), Math.max(n.bottom, r.bottom) + t.margin);
      e.scrollTo(i.scrollLeft, i.scrollTop);
    }
  }
  function ci(e, t, n, r) {
    var i = e.doc,
      s;
    if (n == null) n = 'add';
    if (n == 'smart') {
      if (!i.mode.indent) n = 'prev';
      else s = Gt(e, t);
    }
    var o = e.options.tabSize;
    var u = Ks(i, t),
      a = Ro(u.text, null, o);
    if (u.stateAfter) u.stateAfter = null;
    var f = u.text.match(/^\s*/)[0],
      l;
    if (!r && !/\S/.test(u.text)) {
      l = 0;
      n = 'not';
    } else if (n == 'smart') {
      l = i.mode.indent(s, u.text.slice(f.length), u.text);
      if (l == Bo || l > 150) {
        if (!r) return;
        n = 'prev';
      }
    }
    if (n == 'prev') {
      if (t > i.first) l = Ro(Ks(i, t - 1).text, null, o);
      else l = 0;
    } else if (n == 'add') {
      l = a + e.options.indentUnit;
    } else if (n == 'subtract') {
      l = a - e.options.indentUnit;
    } else if (typeof n == 'number') {
      l = a + n;
    }
    l = Math.max(0, l);
    var c = '',
      h = 0;
    if (e.options.indentWithTabs)
      for (var p = Math.floor(l / o); p; --p) {
        h += o;
        c += '	';
      }
    if (h < l) c += Wo(l - h);
    if (c != f) {
      ri(i, c, vt(t, 0), vt(t, f.length), '+input');
    } else {
      for (var p = 0; p < i.sel.ranges.length; p++) {
        var d = i.sel.ranges[p];
        if (d.head.line == t && d.head.ch < f.length) {
          var h = vt(t, f.length);
          _t(i, p, new Et(h, h));
          break;
        }
      }
    }
    u.stateAfter = null;
  }
  function hi(e, t, n, r) {
    var i = t,
      s = t;
    if (typeof t == 'number') s = Ks(e, Tt(e, t));
    else i = Zs(t);
    if (i == null) return null;
    if (r(s, i) && e.cm) Kn(e.cm, i, n);
    return s;
  }
  function pi(e, t) {
    var n = e.doc.sel.ranges,
      r = [];
    for (var i = 0; i < n.length; i++) {
      var s = t(n[i]);
      while (r.length && mt(s.from, Xo(r).to) <= 0) {
        var o = r.pop();
        if (mt(o.from, s.from) < 0) {
          s.from = o.from;
          break;
        }
      }
      r.push(s);
    }
    Un(e, function () {
      for (var t = r.length - 1; t >= 0; t--) ri(e.doc, '', r[t].from, r[t].to, '+delete');
      fi(e);
    });
  }
  function di(e, t, n, r, i) {
    function l() {
      var t = s + n;
      if (t < e.first || t >= e.first + e.size) return (f = false);
      s = t;
      return (a = Ks(e, t));
    }
    function c(e) {
      var t = (i ? Ru : Uu)(a, o, n, true);
      if (t == null) {
        if (!e && l()) {
          if (i) o = (n < 0 ? Du : _u)(a);
          else o = n < 0 ? a.text.length : 0;
        } else return (f = false);
      } else o = t;
      return true;
    }
    var s = t.line,
      o = t.ch,
      u = n;
    var a = Ks(e, s);
    var f = true;
    if (r == 'char') c();
    else if (r == 'column') c(true);
    else if (r == 'word' || r == 'group') {
      var h = null,
        p = r == 'group';
      var d = e.cm && e.cm.getHelper(t, 'wordChars');
      for (var v = true; ; v = false) {
        if (n < 0 && !c(!v)) break;
        var m = a.text.charAt(o) || '\n';
        var g = eu(m, d) ? 'w' : p && m == '\n' ? 'n' : !p || /\s/.test(m) ? null : 'p';
        if (p && !v && !g) g = 's';
        if (h && h != g) {
          if (n < 0) {
            n = 1;
            c();
          }
          break;
        }
        if (g) h = g;
        if (n > 0 && !c(!v)) break;
      }
    }
    var y = Rt(e, vt(s, o), u, true);
    if (!f) y.hitSide = true;
    return y;
  }
  function vi(e, t, n, r) {
    var i = e.doc,
      s = t.left,
      o;
    if (r == 'page') {
      var u = Math.min(e.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
      o = t.top + n * (u - (n < 0 ? 1.5 : 0.5) * An(e.display));
    } else if (r == 'line') {
      o = n > 0 ? t.bottom + 3 : t.top - 3;
    }
    for (;;) {
      var a = Cn(e, s, o);
      if (!a.outside) break;
      if (n < 0 ? o <= 0 : o >= i.height) {
        a.hitSide = true;
        break;
      }
      o += n * 5;
    }
    return a;
  }
  function yi(e, t, n, r) {
    S.defaults[e] = t;
    if (n)
      gi[e] = r
        ? function (e, t, r) {
            if (r != bi) n(e, t, r);
          }
        : n;
  }
  function Ai(e) {
    var t = e.split(/-(?!$)/),
      e = t[t.length - 1];
    var n, r, i, s;
    for (var o = 0; o < t.length - 1; o++) {
      var u = t[o];
      if (/^(cmd|meta|m)$/i.test(u)) s = true;
      else if (/^a(lt)?$/i.test(u)) n = true;
      else if (/^(c|ctrl|control)$/i.test(u)) r = true;
      else if (/^s(hift)$/i.test(u)) i = true;
      else throw new Error('Unrecognized modifier name: ' + u);
    }
    if (n) e = 'Alt-' + e;
    if (r) e = 'Ctrl-' + e;
    if (s) e = 'Cmd-' + e;
    if (i) e = 'Shift-' + e;
    return e;
  }
  function Di(e) {
    return typeof e == 'string' ? Li[e] : e;
  }
  function ji(e, t, n, r, i) {
    if (r && r.shared) return Ii(e, t, n, r, i);
    if (e.cm && !e.cm.curOp) return zn(e.cm, ji)(e, t, n, r, i);
    var s = new Hi(e, i),
      o = mt(t, n);
    if (r) Qo(r, s, false);
    if (o > 0 || (o == 0 && s.clearWhenEmpty !== false)) return s;
    if (s.replacedWith) {
      s.collapsed = true;
      s.widgetNode = iu('span', [s.replacedWith], 'CodeMirror-widget');
      if (!r.handleMouseEvents) s.widgetNode.setAttribute('cm-ignore-events', 'true');
      if (r.insertLeft) s.widgetNode.insertLeft = true;
    }
    if (s.collapsed) {
      if (us(e, t.line, t, n, s) || (t.line != n.line && us(e, n.line, t, n, s))) throw new Error('Inserting collapsed marker partially overlapping an existing one');
      E = true;
    }
    if (s.addToHistory) uo(e, { from: t, to: n, origin: 'markText' }, e.sel, NaN);
    var u = t.line,
      a = e.cm,
      f;
    e.iter(u, n.line + 1, function (e) {
      if (a && s.collapsed && !a.options.lineWrapping && as(e) == a.display.maxLine) f = true;
      if (s.collapsed && u != t.line) Ys(e, 0);
      Vi(e, new zi(s, u == t.line ? t.ch : null, u == n.line ? n.ch : null));
      ++u;
    });
    if (s.collapsed)
      e.iter(t.line, n.line + 1, function (t) {
        if (hs(e, t)) Ys(t, 0);
      });
    if (s.clearOnEnter)
      No(s, 'beforeCursorEnter', function () {
        s.clear();
      });
    if (s.readOnly) {
      w = true;
      if (e.history.done.length || e.history.undone.length) e.clearHistory();
    }
    if (s.collapsed) {
      s.id = ++Bi;
      s.atomic = true;
    }
    if (a) {
      if (f) a.curOp.updateMaxLine = true;
      if (s.collapsed) Jn(a, t.line, n.line + 1);
      else if (s.className || s.title || s.startStyle || s.endStyle || s.css) for (var l = t.line; l <= n.line; l++) Kn(a, l, 'text');
      if (s.atomic) It(a.doc);
      Ao(a, 'markerAdded', a, s);
    }
    return s;
  }
  function Ii(e, t, n, r, i) {
    r = Qo(r);
    r.shared = false;
    var s = [ji(e, t, n, r, i)],
      o = s[0];
    var u = r.widgetNode;
    $s(e, function (e) {
      if (u) r.widgetNode = u.cloneNode(true);
      s.push(ji(e, Nt(e, t), Nt(e, n), r, i));
      for (var a = 0; a < e.linked.length; ++a) if (e.linked[a].isParent) return;
      o = Xo(s);
    });
    return new Fi(s, o);
  }
  function qi(e) {
    return e.findMarks(vt(e.first, 0), e.clipPos(vt(e.lastLine())), function (e) {
      return e.parent;
    });
  }
  function Ri(e, t) {
    for (var n = 0; n < t.length; n++) {
      var r = t[n],
        i = r.find();
      var s = e.clipPos(i.from),
        o = e.clipPos(i.to);
      if (mt(s, o)) {
        var u = ji(e, s, o, r.primary, r.primary.type);
        r.markers.push(u);
        u.parent = r;
      }
    }
  }
  function Ui(e) {
    for (var t = 0; t < e.length; t++) {
      var n = e[t],
        r = [n.primary.doc];
      $s(n.primary.doc, function (e) {
        r.push(e);
      });
      for (var i = 0; i < n.markers.length; i++) {
        var s = n.markers[i];
        if ($o(r, s.doc) == -1) {
          s.parent = null;
          n.markers.splice(i--, 1);
        }
      }
    }
  }
  function zi(e, t, n) {
    this.marker = e;
    this.from = t;
    this.to = n;
  }
  function Wi(e, t) {
    if (e)
      for (var n = 0; n < e.length; ++n) {
        var r = e[n];
        if (r.marker == t) return r;
      }
  }
  function Xi(e, t) {
    for (var n, r = 0; r < e.length; ++r) if (e[r] != t) (n || (n = [])).push(e[r]);
    return n;
  }
  function Vi(e, t) {
    e.markedSpans = e.markedSpans ? e.markedSpans.concat([t]) : [t];
    t.marker.attachLine(e);
  }
  function $i(e, t, n) {
    if (e)
      for (var r = 0, i; r < e.length; ++r) {
        var s = e[r],
          o = s.marker;
        var u = s.from == null || (o.inclusiveLeft ? s.from <= t : s.from < t);
        if (u || (s.from == t && o.type == 'bookmark' && (!n || !s.marker.insertLeft))) {
          var a = s.to == null || (o.inclusiveRight ? s.to >= t : s.to > t);
          (i || (i = [])).push(new zi(o, s.from, a ? null : s.to));
        }
      }
    return i;
  }
  function Ji(e, t, n) {
    if (e)
      for (var r = 0, i; r < e.length; ++r) {
        var s = e[r],
          o = s.marker;
        var u = s.to == null || (o.inclusiveRight ? s.to >= t : s.to > t);
        if (u || (s.from == t && o.type == 'bookmark' && (!n || s.marker.insertLeft))) {
          var a = s.from == null || (o.inclusiveLeft ? s.from <= t : s.from < t);
          (i || (i = [])).push(new zi(o, a ? null : s.from - t, s.to == null ? null : s.to - t));
        }
      }
    return i;
  }
  function Ki(e, t) {
    var n = kt(e, t.from.line) && Ks(e, t.from.line).markedSpans;
    var r = kt(e, t.to.line) && Ks(e, t.to.line).markedSpans;
    if (!n && !r) return null;
    var i = t.from.ch,
      s = t.to.ch,
      o = mt(t.from, t.to) == 0;
    var u = $i(n, i, o);
    var a = Ji(r, s, o);
    var f = t.text.length == 1,
      l = Xo(t.text).length + (f ? i : 0);
    if (u) {
      for (var c = 0; c < u.length; ++c) {
        var h = u[c];
        if (h.to == null) {
          var p = Wi(a, h.marker);
          if (!p) h.to = i;
          else if (f) h.to = p.to == null ? null : p.to + l;
        }
      }
    }
    if (a) {
      for (var c = 0; c < a.length; ++c) {
        var h = a[c];
        if (h.to != null) h.to += l;
        if (h.from == null) {
          var p = Wi(u, h.marker);
          if (!p) {
            h.from = l;
            if (f) (u || (u = [])).push(h);
          }
        } else {
          h.from += l;
          if (f) (u || (u = [])).push(h);
        }
      }
    }
    if (u) u = Qi(u);
    if (a && a != u) a = Qi(a);
    var d = [u];
    if (!f) {
      var v = t.text.length - 2,
        m;
      if (v > 0 && u) for (var c = 0; c < u.length; ++c) if (u[c].to == null) (m || (m = [])).push(new zi(u[c].marker, null, null));
      for (var c = 0; c < v; ++c) d.push(m);
      d.push(a);
    }
    return d;
  }
  function Qi(e) {
    for (var t = 0; t < e.length; ++t) {
      var n = e[t];
      if (n.from != null && n.from == n.to && n.marker.clearWhenEmpty !== false) e.splice(t--, 1);
    }
    if (!e.length) return null;
    return e;
  }
  function Gi(e, t) {
    var n = po(e, t);
    var r = Ki(e, t);
    if (!n) return r;
    if (!r) return n;
    for (var i = 0; i < n.length; ++i) {
      var s = n[i],
        o = r[i];
      if (s && o) {
        e: for (var u = 0; u < o.length; ++u) {
          var a = o[u];
          for (var f = 0; f < s.length; ++f) if (s[f].marker == a.marker) continue e;
          s.push(a);
        }
      } else if (o) {
        n[i] = o;
      }
    }
    return n;
  }
  function Yi(e, t, n) {
    var r = null;
    e.iter(t.line, n.line + 1, function (e) {
      if (e.markedSpans)
        for (var t = 0; t < e.markedSpans.length; ++t) {
          var n = e.markedSpans[t].marker;
          if (n.readOnly && (!r || $o(r, n) == -1)) (r || (r = [])).push(n);
        }
    });
    if (!r) return null;
    var i = [{ from: t, to: n }];
    for (var s = 0; s < r.length; ++s) {
      var o = r[s],
        u = o.find(0);
      for (var a = 0; a < i.length; ++a) {
        var f = i[a];
        if (mt(f.to, u.from) < 0 || mt(f.from, u.to) > 0) continue;
        var l = [a, 1],
          c = mt(f.from, u.from),
          h = mt(f.to, u.to);
        if (c < 0 || (!o.inclusiveLeft && !c)) l.push({ from: f.from, to: u.from });
        if (h > 0 || (!o.inclusiveRight && !h)) l.push({ from: u.to, to: f.to });
        i.splice.apply(i, l);
        a += l.length - 1;
      }
    }
    return i;
  }
  function Zi(e) {
    var t = e.markedSpans;
    if (!t) return;
    for (var n = 0; n < t.length; ++n) t[n].marker.detachLine(e);
    e.markedSpans = null;
  }
  function es(e, t) {
    if (!t) return;
    for (var n = 0; n < t.length; ++n) t[n].marker.attachLine(e);
    e.markedSpans = t;
  }
  function ts(e) {
    return e.inclusiveLeft ? -1 : 0;
  }
  function ns(e) {
    return e.inclusiveRight ? 1 : 0;
  }
  function rs(e, t) {
    var n = e.lines.length - t.lines.length;
    if (n != 0) return n;
    var r = e.find(),
      i = t.find();
    var s = mt(r.from, i.from) || ts(e) - ts(t);
    if (s) return -s;
    var o = mt(r.to, i.to) || ns(e) - ns(t);
    if (o) return o;
    return t.id - e.id;
  }
  function is(e, t) {
    var n = E && e.markedSpans,
      r;
    if (n)
      for (var i, s = 0; s < n.length; ++s) {
        i = n[s];
        if (i.marker.collapsed && (t ? i.from : i.to) == null && (!r || rs(r, i.marker) < 0)) r = i.marker;
      }
    return r;
  }
  function ss(e) {
    return is(e, true);
  }
  function os(e) {
    return is(e, false);
  }
  function us(e, t, n, r, i) {
    var s = Ks(e, t);
    var o = E && s.markedSpans;
    if (o)
      for (var u = 0; u < o.length; ++u) {
        var a = o[u];
        if (!a.marker.collapsed) continue;
        var f = a.marker.find(0);
        var l = mt(f.from, n) || ts(a.marker) - ts(i);
        var c = mt(f.to, r) || ns(a.marker) - ns(i);
        if ((l >= 0 && c <= 0) || (l <= 0 && c >= 0)) continue;
        if ((l <= 0 && (mt(f.to, n) > 0 || (a.marker.inclusiveRight && i.inclusiveLeft))) || (l >= 0 && (mt(f.from, r) < 0 || (a.marker.inclusiveLeft && i.inclusiveRight)))) return true;
      }
  }
  function as(e) {
    var t;
    while ((t = ss(e))) e = t.find(-1, true).line;
    return e;
  }
  function fs(e) {
    var t, n;
    while ((t = os(e))) {
      e = t.find(1, true).line;
      (n || (n = [])).push(e);
    }
    return n;
  }
  function ls(e, t) {
    var n = Ks(e, t),
      r = as(n);
    if (n == r) return t;
    return Zs(r);
  }
  function cs(e, t) {
    if (t > e.lastLine()) return t;
    var n = Ks(e, t),
      r;
    if (!hs(e, n)) return t;
    while ((r = os(n))) n = r.find(1, true).line;
    return Zs(n) + 1;
  }
  function hs(e, t) {
    var n = E && t.markedSpans;
    if (n)
      for (var r, i = 0; i < n.length; ++i) {
        r = n[i];
        if (!r.marker.collapsed) continue;
        if (r.from == null) return true;
        if (r.marker.widgetNode) continue;
        if (r.from == 0 && r.marker.inclusiveLeft && ps(e, t, r)) return true;
      }
  }
  function ps(e, t, n) {
    if (n.to == null) {
      var r = n.marker.find(1, true);
      return ps(e, r.line, Wi(r.line.markedSpans, n.marker));
    }
    if (n.marker.inclusiveRight && n.to == t.text.length) return true;
    for (var i, s = 0; s < t.markedSpans.length; ++s) {
      i = t.markedSpans[s];
      if (i.marker.collapsed && !i.marker.widgetNode && i.from == n.to && (i.to == null || i.to != n.from) && (i.marker.inclusiveLeft || n.marker.inclusiveRight) && ps(e, t, i)) return true;
    }
  }
  function vs(e, t, n) {
    if (to(t) < ((e.curOp && e.curOp.scrollTop) || e.doc.scrollTop)) ai(e, null, n);
  }
  function ms(e) {
    if (e.height != null) return e.height;
    if (!au(document.body, e.node)) {
      var t = 'position: relative;';
      if (e.coverGutter) t += 'margin-left: -' + e.cm.getGutterElement().offsetWidth + 'px;';
      uu(e.cm.display.measure, iu('div', [e.node], null, t));
    }
    return (e.height = e.node.offsetHeight);
  }
  function gs(e, t, n, r) {
    var i = new ds(e, n, r);
    if (i.noHScroll) e.display.alignWidgets = true;
    hi(e.doc, t, 'widget', function (t) {
      var n = t.widgets || (t.widgets = []);
      if (i.insertAt == null) n.push(i);
      else n.splice(Math.min(n.length - 1, Math.max(0, i.insertAt)), 0, i);
      i.line = t;
      if (!hs(e.doc, t)) {
        var r = to(t) < e.doc.scrollTop;
        Ys(t, t.height + ms(i));
        if (r) ai(e, null, i.height);
        e.curOp.forceUpdate = true;
      }
      return true;
    });
    return i;
  }
  function bs(e, t, n, r) {
    e.text = t;
    if (e.stateAfter) e.stateAfter = null;
    if (e.styles) e.styles = null;
    if (e.order != null) e.order = null;
    Zi(e);
    es(e, n);
    var i = r ? r(e) : 1;
    if (i != e.height) Ys(e, i);
  }
  function ws(e) {
    e.parent = null;
    Zi(e);
  }
  function Es(e, t) {
    if (e)
      for (;;) {
        var n = e.match(/(?:^|\s+)line-(background-)?(\S+)/);
        if (!n) break;
        e = e.slice(0, n.index) + e.slice(n.index + n[0].length);
        var r = n[1] ? 'bgClass' : 'textClass';
        if (t[r] == null) t[r] = n[2];
        else if (!new RegExp('(?:^|s)' + n[2] + '(?:$|s)').test(t[r])) t[r] += ' ' + n[2];
      }
    return e;
  }
  function Ss(e, t) {
    if (e.blankLine) return e.blankLine(t);
    if (!e.innerMode) return;
    var n = S.innerMode(e, t);
    if (n.mode.blankLine) return n.mode.blankLine(n.state);
  }
  function xs(e, t, n, r) {
    for (var i = 0; i < 10; i++) {
      if (r) r[0] = S.innerMode(e, n).mode;
      var s = e.token(t, n);
      if (t.pos > t.start) return s;
    }
    throw new Error('Mode ' + e.name + ' failed to advance stream.');
  }
  function Ts(e, t, n, r) {
    function i(e) {
      return { start: l.start, end: l.pos, string: l.current(), type: u || null, state: e ? Ni(s.mode, f) : f };
    }
    var s = e.doc,
      o = s.mode,
      u;
    t = Nt(s, t);
    var a = Ks(s, t.line),
      f = Gt(e, t.line, n);
    var l = new Pi(a.text, e.options.tabSize),
      c;
    if (r) c = [];
    while ((r || l.pos < t.ch) && !l.eol()) {
      l.start = l.pos;
      u = xs(o, l, f);
      if (r) c.push(i(true));
    }
    return r ? c : i();
  }
  function Ns(e, t, n, r, i, s, o) {
    var u = n.flattenSpans;
    if (u == null) u = e.options.flattenSpans;
    var a = 0,
      f = null;
    var l = new Pi(t, e.options.tabSize),
      c;
    var h = e.options.addModeClass && [null];
    if (t == '') Es(Ss(n, r), s);
    while (!l.eol()) {
      if (l.pos > e.options.maxHighlightLength) {
        u = false;
        if (o) Ls(e, t, r, l.pos);
        l.pos = t.length;
        c = null;
      } else {
        c = Es(xs(n, l, r, h), s);
      }
      if (h) {
        var p = h[0].name;
        if (p) c = 'm-' + (c ? p + ' ' + c : p);
      }
      if (!u || f != c) {
        while (a < l.start) {
          a = Math.min(l.start, a + 5e4);
          i(a, f);
        }
        f = c;
      }
      l.start = l.pos;
    }
    while (a < l.pos) {
      var d = Math.min(l.pos, a + 5e4);
      i(d, f);
      a = d;
    }
  }
  function Cs(e, t, n, r) {
    var i = [e.state.modeGen],
      s = {};
    Ns(
      e,
      t.text,
      e.doc.mode,
      n,
      function (e, t) {
        i.push(e, t);
      },
      s,
      r
    );
    for (var o = 0; o < e.state.overlays.length; ++o) {
      var u = e.state.overlays[o],
        a = 1,
        f = 0;
      Ns(
        e,
        t.text,
        u.mode,
        true,
        function (e, t) {
          var n = a;
          while (f < e) {
            var r = i[a];
            if (r > e) i.splice(a, 1, e, i[a + 1], r);
            a += 2;
            f = Math.min(e, r);
          }
          if (!t) return;
          if (u.opaque) {
            i.splice(n, a - n, e, 'cm-overlay ' + t);
            a = n + 2;
          } else {
            for (; n < a; n += 2) {
              var s = i[n + 1];
              i[n + 1] = (s ? s + ' ' : '') + 'cm-overlay ' + t;
            }
          }
        },
        s
      );
    }
    return { styles: i, classes: s.bgClass || s.textClass ? s : null };
  }
  function ks(e, t, n) {
    if (!t.styles || t.styles[0] != e.state.modeGen) {
      var r = Cs(e, t, (t.stateAfter = Gt(e, Zs(t))));
      t.styles = r.styles;
      if (r.classes) t.styleClasses = r.classes;
      else if (t.styleClasses) t.styleClasses = null;
      if (n === e.doc.frontier) e.doc.frontier++;
    }
    return t.styles;
  }
  function Ls(e, t, n, r) {
    var i = e.doc.mode;
    var s = new Pi(t, e.options.tabSize);
    s.start = s.pos = r || 0;
    if (t == '') Ss(i, n);
    while (!s.eol() && s.pos <= e.options.maxHighlightLength) {
      xs(i, s, n);
      s.start = s.pos;
    }
  }
  function Ms(e, t) {
    if (!e || /^\s*$/.test(e)) return null;
    var n = t.addModeClass ? Os : As;
    return n[e] || (n[e] = e.replace(/\S+/g, 'cm-$&'));
  }
  function _s(e, t) {
    var n = iu('span', null, null, s ? 'padding-right: .1px' : null);
    var i = { pre: iu('pre', [n]), content: n, col: 0, pos: 0, cm: e };
    t.measure = {};
    for (var o = 0; o <= (t.rest ? t.rest.length : 0); o++) {
      var u = o ? t.rest[o - 1] : t.line,
        a;
      i.pos = 0;
      i.addToken = Ps;
      if ((r || s) && e.getOption('lineWrapping')) i.addToken = Hs(i.addToken);
      if (Su(e.display.measure) && (a = no(u))) i.addToken = Bs(i.addToken, a);
      i.map = [];
      var f = t != e.display.externalMeasured && Zs(u);
      Fs(u, i, ks(e, u, f));
      if (u.styleClasses) {
        if (u.styleClasses.bgClass) i.bgClass = pu(u.styleClasses.bgClass, i.bgClass || '');
        if (u.styleClasses.textClass) i.textClass = pu(u.styleClasses.textClass, i.textClass || '');
      }
      if (i.map.length == 0) i.map.push(0, 0, i.content.appendChild(wu(e.display.measure)));
      if (o == 0) {
        t.measure.map = i.map;
        t.measure.cache = {};
      } else {
        (t.measure.maps || (t.measure.maps = [])).push(i.map);
        (t.measure.caches || (t.measure.caches = [])).push({});
      }
    }
    if (s && /\bcm-tab\b/.test(i.content.lastChild.className)) i.content.className = 'cm-tab-wrap-hack';
    ko(e, 'renderLine', e, t.line, i.pre);
    if (i.pre.className) i.textClass = pu(i.pre.className, i.textClass || '');
    return i;
  }
  function Ds(e) {
    var t = iu('span', '•', 'cm-invalidchar');
    t.title = '\\u' + e.charCodeAt(0).toString(16);
    return t;
  }
  function Ps(e, t, n, s, o, u, a) {
    if (!t) return;
    var f = e.cm.options.specialChars,
      l = false;
    if (!f.test(t)) {
      e.col += t.length;
      var c = document.createTextNode(t);
      e.map.push(e.pos, e.pos + t.length, c);
      if (r && i < 9) l = true;
      e.pos += t.length;
    } else {
      var c = document.createDocumentFragment(),
        h = 0;
      while (true) {
        f.lastIndex = h;
        var p = f.exec(t);
        var d = p ? p.index - h : t.length - h;
        if (d) {
          var v = document.createTextNode(t.slice(h, h + d));
          if (r && i < 9) c.appendChild(iu('span', [v]));
          else c.appendChild(v);
          e.map.push(e.pos, e.pos + d, v);
          e.col += d;
          e.pos += d;
        }
        if (!p) break;
        h += d + 1;
        if (p[0] == '	') {
          var m = e.cm.options.tabSize,
            g = m - (e.col % m);
          var v = c.appendChild(iu('span', Wo(g), 'cm-tab'));
          e.col += g;
        } else {
          var v = e.cm.options.specialCharPlaceholder(p[0]);
          if (r && i < 9) c.appendChild(iu('span', [v]));
          else c.appendChild(v);
          e.col += 1;
        }
        e.map.push(e.pos, e.pos + 1, v);
        e.pos++;
      }
    }
    if (n || s || o || l || a) {
      var y = n || '';
      if (s) y += s;
      if (o) y += o;
      var b = iu('span', [c], y, a);
      if (u) b.title = u;
      return e.content.appendChild(b);
    }
    e.content.appendChild(c);
  }
  function Hs(e) {
    function t(e) {
      var t = ' ';
      for (var n = 0; n < e.length - 2; ++n) t += n % 2 ? ' ' : ' ';
      t += ' ';
      return t;
    }
    return function (n, r, i, s, o, u) {
      e(n, r.replace(/ {3,}/g, t), i, s, o, u);
    };
  }
  function Bs(e, t) {
    return function (n, r, i, s, o, u) {
      i = i ? i + ' cm-force-border' : 'cm-force-border';
      var a = n.pos,
        f = a + r.length;
      for (;;) {
        for (var l = 0; l < t.length; l++) {
          var c = t[l];
          if (c.to > a && c.from <= a) break;
        }
        if (c.to >= f) return e(n, r, i, s, o, u);
        e(n, r.slice(0, c.to - a), i, s, null, u);
        s = null;
        r = r.slice(c.to - a);
        a = c.to;
      }
    };
  }
  function js(e, t, n, r) {
    var i = !r && n.widgetNode;
    if (i) {
      e.map.push(e.pos, e.pos + t, i);
      e.content.appendChild(i);
    }
    e.pos += t;
  }
  function Fs(e, t, n) {
    var r = e.markedSpans,
      i = e.text,
      s = 0;
    if (!r) {
      for (var o = 1; o < n.length; o += 2) t.addToken(t, i.slice(s, (s = n[o])), Ms(n[o + 1], t.cm.options));
      return;
    }
    var u = i.length,
      a = 0,
      o = 1,
      f = '',
      l,
      c;
    var h = 0,
      p,
      d,
      v,
      m,
      g;
    for (;;) {
      if (h == a) {
        p = d = v = m = c = '';
        g = null;
        h = Infinity;
        var y = [];
        for (var b = 0; b < r.length; ++b) {
          var w = r[b],
            E = w.marker;
          if (w.from <= a && (w.to == null || w.to > a)) {
            if (w.to != null && h > w.to) {
              h = w.to;
              d = '';
            }
            if (E.className) p += ' ' + E.className;
            if (E.css) c = E.css;
            if (E.startStyle && w.from == a) v += ' ' + E.startStyle;
            if (E.endStyle && w.to == h) d += ' ' + E.endStyle;
            if (E.title && !m) m = E.title;
            if (E.collapsed && (!g || rs(g.marker, E) < 0)) g = w;
          } else if (w.from > a && h > w.from) {
            h = w.from;
          }
          if (E.type == 'bookmark' && w.from == a && E.widgetNode) y.push(E);
        }
        if (g && (g.from || 0) == a) {
          js(t, (g.to == null ? u + 1 : g.to) - a, g.marker, g.from == null);
          if (g.to == null) return;
        }
        if (!g && y.length) for (var b = 0; b < y.length; ++b) js(t, 0, y[b]);
      }
      if (a >= u) break;
      var S = Math.min(u, h);
      while (true) {
        if (f) {
          var x = a + f.length;
          if (!g) {
            var T = x > S ? f.slice(0, S - a) : f;
            t.addToken(t, T, l ? l + p : p, v, a + T.length == h ? d : '', m, c);
          }
          if (x >= S) {
            f = f.slice(S - a);
            a = S;
            break;
          }
          a = x;
          v = '';
        }
        f = i.slice(s, (s = n[o++]));
        l = Ms(n[o++], t.cm.options);
      }
    }
  }
  function Is(e, t) {
    return t.from.ch == 0 && t.to.ch == 0 && Xo(t.text) == '' && (!e.cm || e.cm.options.wholeLineUpdateBefore);
  }
  function qs(e, t, n, r) {
    function i(e) {
      return n ? n[e] : null;
    }
    function s(e, n, i) {
      bs(e, n, i, r);
      Ao(e, 'change', e, t);
    }
    var o = t.from,
      u = t.to,
      a = t.text;
    var f = Ks(e, o.line),
      l = Ks(e, u.line);
    var c = Xo(a),
      h = i(a.length - 1),
      p = u.line - o.line;
    if (Is(e, t)) {
      for (var d = 0, v = []; d < a.length - 1; ++d) v.push(new ys(a[d], i(d), r));
      s(l, l.text, h);
      if (p) e.remove(o.line, p);
      if (v.length) e.insert(o.line, v);
    } else if (f == l) {
      if (a.length == 1) {
        s(f, f.text.slice(0, o.ch) + c + f.text.slice(u.ch), h);
      } else {
        for (var v = [], d = 1; d < a.length - 1; ++d) v.push(new ys(a[d], i(d), r));
        v.push(new ys(c + f.text.slice(u.ch), h, r));
        s(f, f.text.slice(0, o.ch) + a[0], i(0));
        e.insert(o.line + 1, v);
      }
    } else if (a.length == 1) {
      s(f, f.text.slice(0, o.ch) + a[0] + l.text.slice(u.ch), i(0));
      e.remove(o.line + 1, p);
    } else {
      s(f, f.text.slice(0, o.ch) + a[0], i(0));
      s(l, c + l.text.slice(u.ch), h);
      for (var d = 1, v = []; d < a.length - 1; ++d) v.push(new ys(a[d], i(d), r));
      if (p > 1) e.remove(o.line + 1, p - 1);
      e.insert(o.line + 1, v);
    }
    Ao(e, 'change', e, t);
  }
  function Rs(e) {
    this.lines = e;
    this.parent = null;
    for (var t = 0, n = 0; t < e.length; ++t) {
      e[t].parent = this;
      n += e[t].height;
    }
    this.height = n;
  }
  function Us(e) {
    this.children = e;
    var t = 0,
      n = 0;
    for (var r = 0; r < e.length; ++r) {
      var i = e[r];
      t += i.chunkSize();
      n += i.height;
      i.parent = this;
    }
    this.size = t;
    this.height = n;
    this.parent = null;
  }
  function $s(e, t, n) {
    function r(e, i, s) {
      if (e.linked)
        for (var o = 0; o < e.linked.length; ++o) {
          var u = e.linked[o];
          if (u.doc == i) continue;
          var a = s && u.sharedHist;
          if (n && !a) continue;
          t(u.doc, a);
          r(u.doc, e, a);
        }
    }
    r(e, null, true);
  }
  function Js(e, t) {
    if (t.cm) throw new Error('This document is already in use.');
    e.doc = t;
    t.cm = e;
    L(e);
    T(e);
    if (!e.options.lineWrapping) P(e);
    e.options.mode = t.modeOption;
    Jn(e);
  }
  function Ks(e, t) {
    t -= e.first;
    if (t < 0 || t >= e.size) throw new Error('There is no line ' + (t + e.first) + ' in the document.');
    for (var n = e; !n.lines; ) {
      for (var r = 0; ; ++r) {
        var i = n.children[r],
          s = i.chunkSize();
        if (t < s) {
          n = i;
          break;
        }
        t -= s;
      }
    }
    return n.lines[t];
  }
  function Qs(e, t, n) {
    var r = [],
      i = t.line;
    e.iter(t.line, n.line + 1, function (e) {
      var s = e.text;
      if (i == n.line) s = s.slice(0, n.ch);
      if (i == t.line) s = s.slice(t.ch);
      r.push(s);
      ++i;
    });
    return r;
  }
  function Gs(e, t, n) {
    var r = [];
    e.iter(t, n, function (e) {
      r.push(e.text);
    });
    return r;
  }
  function Ys(e, t) {
    var n = t - e.height;
    if (n) for (var r = e; r; r = r.parent) r.height += n;
  }
  function Zs(e) {
    if (e.parent == null) return null;
    var t = e.parent,
      n = $o(t.lines, e);
    for (var r = t.parent; r; t = r, r = r.parent) {
      for (var i = 0; ; ++i) {
        if (r.children[i] == t) break;
        n += r.children[i].chunkSize();
      }
    }
    return n + t.first;
  }
  function eo(e, t) {
    var n = e.first;
    e: do {
      for (var r = 0; r < e.children.length; ++r) {
        var i = e.children[r],
          s = i.height;
        if (t < s) {
          e = i;
          continue e;
        }
        t -= s;
        n += i.chunkSize();
      }
      return n;
    } while (!e.lines);
    for (var r = 0; r < e.lines.length; ++r) {
      var o = e.lines[r],
        u = o.height;
      if (t < u) break;
      t -= u;
    }
    return n + r;
  }
  function to(e) {
    e = as(e);
    var t = 0,
      n = e.parent;
    for (var r = 0; r < n.lines.length; ++r) {
      var i = n.lines[r];
      if (i == e) break;
      else t += i.height;
    }
    for (var s = n.parent; s; n = s, s = n.parent) {
      for (var r = 0; r < s.children.length; ++r) {
        var o = s.children[r];
        if (o == n) break;
        else t += o.height;
      }
    }
    return t;
  }
  function no(e) {
    var t = e.order;
    if (t == null) t = e.order = zu(e.text);
    return t;
  }
  function ro(e) {
    this.done = [];
    this.undone = [];
    this.undoDepth = Infinity;
    this.lastModTime = this.lastSelTime = 0;
    this.lastOp = this.lastSelOp = null;
    this.lastOrigin = this.lastSelOrigin = null;
    this.generation = this.maxGeneration = e || 1;
  }
  function io(e, t) {
    var n = { from: gt(t.from), to: Xr(t), text: Qs(e, t.from, t.to) };
    co(e, n, t.from.line, t.to.line + 1);
    $s(
      e,
      function (e) {
        co(e, n, t.from.line, t.to.line + 1);
      },
      true
    );
    return n;
  }
  function so(e) {
    while (e.length) {
      var t = Xo(e);
      if (t.ranges) e.pop();
      else break;
    }
  }
  function oo(e, t) {
    if (t) {
      so(e.done);
      return Xo(e.done);
    } else if (e.done.length && !Xo(e.done).ranges) {
      return Xo(e.done);
    } else if (e.done.length > 1 && !e.done[e.done.length - 2].ranges) {
      e.done.pop();
      return Xo(e.done);
    }
  }
  function uo(e, t, n, r) {
    var i = e.history;
    i.undone.length = 0;
    var s = +new Date(),
      o;
    if ((i.lastOp == r || (i.lastOrigin == t.origin && t.origin && ((t.origin.charAt(0) == '+' && e.cm && i.lastModTime > s - e.cm.options.historyEventDelay) || t.origin.charAt(0) == '*'))) && (o = oo(i, i.lastOp == r))) {
      var u = Xo(o.changes);
      if (mt(t.from, t.to) == 0 && mt(t.from, u.to) == 0) {
        u.to = Xr(t);
      } else {
        o.changes.push(io(e, t));
      }
    } else {
      var a = Xo(i.done);
      if (!a || !a.ranges) lo(e.sel, i.done);
      o = { changes: [io(e, t)], generation: i.generation };
      i.done.push(o);
      while (i.done.length > i.undoDepth) {
        i.done.shift();
        if (!i.done[0].ranges) i.done.shift();
      }
    }
    i.done.push(n);
    i.generation = ++i.maxGeneration;
    i.lastModTime = i.lastSelTime = s;
    i.lastOp = i.lastSelOp = r;
    i.lastOrigin = i.lastSelOrigin = t.origin;
    if (!u) ko(e, 'historyAdded');
  }
  function ao(e, t, n, r) {
    var i = t.charAt(0);
    return i == '*' || (i == '+' && n.ranges.length == r.ranges.length && n.somethingSelected() == r.somethingSelected() && new Date() - e.history.lastSelTime <= (e.cm ? e.cm.options.historyEventDelay : 500));
  }
  function fo(e, t, n, r) {
    var i = e.history,
      s = r && r.origin;
    if (n == i.lastSelOp || (s && i.lastSelOrigin == s && ((i.lastModTime == i.lastSelTime && i.lastOrigin == s) || ao(e, s, Xo(i.done), t)))) i.done[i.done.length - 1] = t;
    else lo(t, i.done);
    i.lastSelTime = +new Date();
    i.lastSelOrigin = s;
    i.lastSelOp = n;
    if (r && r.clearRedo !== false) so(i.undone);
  }
  function lo(e, t) {
    var n = Xo(t);
    if (!(n && n.ranges && n.equals(e))) t.push(e);
  }
  function co(e, t, n, r) {
    var i = t['spans_' + e.id],
      s = 0;
    e.iter(Math.max(e.first, n), Math.min(e.first + e.size, r), function (n) {
      if (n.markedSpans) (i || (i = t['spans_' + e.id] = {}))[s] = n.markedSpans;
      ++s;
    });
  }
  function ho(e) {
    if (!e) return null;
    for (var t = 0, n; t < e.length; ++t) {
      if (e[t].marker.explicitlyCleared) {
        if (!n) n = e.slice(0, t);
      } else if (n) n.push(e[t]);
    }
    return !n ? e : n.length ? n : null;
  }
  function po(e, t) {
    var n = t['spans_' + e.id];
    if (!n) return null;
    for (var r = 0, i = []; r < t.text.length; ++r) i.push(ho(n[r]));
    return i;
  }
  function vo(e, t, n) {
    for (var r = 0, i = []; r < e.length; ++r) {
      var s = e[r];
      if (s.ranges) {
        i.push(n ? wt.prototype.deepCopy.call(s) : s);
        continue;
      }
      var o = s.changes,
        u = [];
      i.push({ changes: u });
      for (var a = 0; a < o.length; ++a) {
        var f = o[a],
          l;
        u.push({ from: f.from, to: f.to, text: f.text });
        if (t)
          for (var c in f)
            if ((l = c.match(/^spans_(\d+)$/))) {
              if ($o(t, Number(l[1])) > -1) {
                Xo(u)[c] = f[c];
                delete f[c];
              }
            }
      }
    }
    return i;
  }
  function mo(e, t, n, r) {
    if (n < e.line) {
      e.line += r;
    } else if (t < e.line) {
      e.line = t;
      e.ch = 0;
    }
  }
  function go(e, t, n, r) {
    for (var i = 0; i < e.length; ++i) {
      var s = e[i],
        o = true;
      if (s.ranges) {
        if (!s.copied) {
          s = e[i] = s.deepCopy();
          s.copied = true;
        }
        for (var u = 0; u < s.ranges.length; u++) {
          mo(s.ranges[u].anchor, t, n, r);
          mo(s.ranges[u].head, t, n, r);
        }
        continue;
      }
      for (var u = 0; u < s.changes.length; ++u) {
        var a = s.changes[u];
        if (n < a.from.line) {
          a.from = vt(a.from.line + r, a.from.ch);
          a.to = vt(a.to.line + r, a.to.ch);
        } else if (t <= a.to.line) {
          o = false;
          break;
        }
      }
      if (!o) {
        e.splice(0, i + 1);
        i = 0;
      }
    }
  }
  function yo(e, t) {
    var n = t.from.line,
      r = t.to.line,
      i = t.text.length - (r - n) - 1;
    go(e.done, n, r, i);
    go(e.undone, n, r, i);
  }
  function Eo(e) {
    return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
  }
  function xo(e) {
    return e.target || e.srcElement;
  }
  function To(e) {
    var t = e.which;
    if (t == null) {
      if (e.button & 1) t = 1;
      else if (e.button & 2) t = 3;
      else if (e.button & 4) t = 2;
    }
    if (v && e.ctrlKey && t == 1) t = 3;
    return t;
  }
  function Ao(e, t) {
    function s(e) {
      return function () {
        e.apply(null, r);
      };
    }
    var n = e._handlers && e._handlers[t];
    if (!n) return;
    var r = Array.prototype.slice.call(arguments, 2),
      i;
    if (Mn) {
      i = Mn.delayedCallbacks;
    } else if (Lo) {
      i = Lo;
    } else {
      i = Lo = [];
      setTimeout(Oo, 0);
    }
    for (var o = 0; o < n.length; ++o) i.push(s(n[o]));
  }
  function Oo() {
    var e = Lo;
    Lo = null;
    for (var t = 0; t < e.length; ++t) e[t]();
  }
  function Mo(e, t, n) {
    if (typeof t == 'string')
      t = {
        type: t,
        preventDefault: function () {
          this.defaultPrevented = true;
        },
      };
    ko(e, n || t.type, e, t);
    return Eo(t) || t.codemirrorIgnore;
  }
  function _o(e) {
    var t = e._handlers && e._handlers.cursorActivity;
    if (!t) return;
    var n = e.curOp.cursorActivityHandlers || (e.curOp.cursorActivityHandlers = []);
    for (var r = 0; r < t.length; ++r) if ($o(n, t[r]) == -1) n.push(t[r]);
  }
  function Do(e, t) {
    var n = e._handlers && e._handlers[t];
    return n && n.length > 0;
  }
  function Po(e) {
    e.prototype.on = function (e, t) {
      No(this, e, t);
    };
    e.prototype.off = function (e, t) {
      Co(this, e, t);
    };
  }
  function qo() {
    this.id = null;
  }
  function Uo(e, t, n) {
    for (var r = 0, i = 0; ; ) {
      var s = e.indexOf('	', r);
      if (s == -1) s = e.length;
      var o = s - r;
      if (s == e.length || i + o >= t) return r + Math.min(o, t - i);
      i += s - r;
      i += n - (i % n);
      r = s + 1;
      if (i >= t) return r;
    }
  }
  function Wo(e) {
    while (zo.length <= e) zo.push(Xo(zo) + ' ');
    return zo[e];
  }
  function Xo(e) {
    return e[e.length - 1];
  }
  function $o(e, t) {
    for (var n = 0; n < e.length; ++n) if (e[n] == t) return n;
    return -1;
  }
  function Jo(e, t) {
    var n = [];
    for (var r = 0; r < e.length; r++) n[r] = t(e[r], r);
    return n;
  }
  function Ko(e, t) {
    var n;
    if (Object.create) {
      n = Object.create(e);
    } else {
      var r = function () {};
      r.prototype = e;
      n = new r();
    }
    if (t) Qo(t, n);
    return n;
  }
  function Qo(e, t, n) {
    if (!t) t = {};
    for (var r in e) if (e.hasOwnProperty(r) && (n !== false || !t.hasOwnProperty(r))) t[r] = e[r];
    return t;
  }
  function Go(e) {
    var t = Array.prototype.slice.call(arguments, 1);
    return function () {
      return e.apply(null, t);
    };
  }
  function eu(e, t) {
    if (!t) return Zo(e);
    if (t.source.indexOf('\\w') > -1 && Zo(e)) return true;
    return t.test(e);
  }
  function tu(e) {
    for (var t in e) if (e.hasOwnProperty(t) && e[t]) return false;
    return true;
  }
  function ru(e) {
    return e.charCodeAt(0) >= 768 && nu.test(e);
  }
  function iu(e, t, n, r) {
    var i = document.createElement(e);
    if (n) i.className = n;
    if (r) i.style.cssText = r;
    if (typeof t == 'string') i.appendChild(document.createTextNode(t));
    else if (t) for (var s = 0; s < t.length; ++s) i.appendChild(t[s]);
    return i;
  }
  function ou(e) {
    for (var t = e.childNodes.length; t > 0; --t) e.removeChild(e.firstChild);
    return e;
  }
  function uu(e, t) {
    return ou(e).appendChild(t);
  }
  function au(e, t) {
    if (e.contains) return e.contains(t);
    while ((t = t.parentNode)) if (t == e) return true;
  }
  function fu() {
    return document.activeElement;
  }
  function lu(e) {
    return new RegExp('(^|\\s)' + e + '(?:$|\\s)\\s*');
  }
  function pu(e, t) {
    var n = e.split(' ');
    for (var r = 0; r < n.length; r++) if (n[r] && !lu(n[r]).test(t)) t += ' ' + n[r];
    return t;
  }
  function du(e) {
    if (!document.body.getElementsByClassName) return;
    var t = document.body.getElementsByClassName('CodeMirror');
    for (var n = 0; n < t.length; n++) {
      var r = t[n].CodeMirror;
      if (r) e(r);
    }
  }
  function mu() {
    if (vu) return;
    gu();
    vu = true;
  }
  function gu() {
    var e;
    No(window, 'resize', function () {
      if (e == null)
        e = setTimeout(function () {
          e = null;
          du(lr);
        }, 100);
    });
    No(window, 'blur', function () {
      du(Ur);
    });
  }
  function wu(e) {
    if (bu == null) {
      var t = iu('span', '​');
      uu(e, iu('span', [t, document.createTextNode('x')]));
      if (e.firstChild.offsetHeight != 0) bu = t.offsetWidth <= 1 && t.offsetHeight > 2 && !(r && i < 8);
    }
    if (bu) return iu('span', '​');
    else return iu('span', ' ', null, 'display: inline-block; width: 1px; margin-right: -1px');
  }
  function Su(e) {
    if (Eu != null) return Eu;
    var t = uu(e, document.createTextNode('AخA'));
    var n = su(t, 0, 1).getBoundingClientRect();
    if (!n || n.left == n.right) return false;
    var r = su(t, 1, 2).getBoundingClientRect();
    return (Eu = r.right - n.right < 3);
  }
  function ku(e) {
    if (Cu != null) return Cu;
    var t = uu(e, iu('span', 'x'));
    var n = t.getBoundingClientRect();
    var r = su(t, 0, 1).getBoundingClientRect();
    return (Cu = Math.abs(n.left - r.left) > 1);
  }
  function Au(e, t, n, r) {
    if (!e) return r(t, n, 'ltr');
    var i = false;
    for (var s = 0; s < e.length; ++s) {
      var o = e[s];
      if ((o.from < n && o.to > t) || (t == n && o.to == t)) {
        r(Math.max(o.from, t), Math.min(o.to, n), o.level == 1 ? 'rtl' : 'ltr');
        i = true;
      }
    }
    if (!i) r(t, n, 'ltr');
  }
  function Ou(e) {
    return e.level % 2 ? e.to : e.from;
  }
  function Mu(e) {
    return e.level % 2 ? e.from : e.to;
  }
  function _u(e) {
    var t = no(e);
    return t ? Ou(t[0]) : 0;
  }
  function Du(e) {
    var t = no(e);
    if (!t) return e.text.length;
    return Mu(Xo(t));
  }
  function Pu(e, t) {
    var n = Ks(e.doc, t);
    var r = as(n);
    if (r != n) t = Zs(r);
    var i = no(r);
    var s = !i ? 0 : i[0].level % 2 ? Du(r) : _u(r);
    return vt(t, s);
  }
  function Hu(e, t) {
    var n,
      r = Ks(e.doc, t);
    while ((n = os(r))) {
      r = n.find(1, true).line;
      t = null;
    }
    var i = no(r);
    var s = !i ? r.text.length : i[0].level % 2 ? _u(r) : Du(r);
    return vt(t == null ? Zs(r) : t, s);
  }
  function Bu(e, t) {
    var n = Pu(e, t.line);
    var r = Ks(e.doc, n.line);
    var i = no(r);
    if (!i || i[0].level == 0) {
      var s = Math.max(0, r.text.search(/\S/));
      var o = t.line == n.line && t.ch <= s && t.ch;
      return vt(n.line, o ? 0 : s);
    }
    return n;
  }
  function ju(e, t, n) {
    var r = e[0].level;
    if (t == r) return true;
    if (n == r) return false;
    return t < n;
  }
  function Iu(e, t) {
    Fu = null;
    for (var n = 0, r; n < e.length; ++n) {
      var i = e[n];
      if (i.from < t && i.to > t) return n;
      if (i.from == t || i.to == t) {
        if (r == null) {
          r = n;
        } else if (ju(e, i.level, e[r].level)) {
          if (i.from != i.to) Fu = r;
          return n;
        } else {
          if (i.from != i.to) Fu = n;
          return r;
        }
      }
    }
    return r;
  }
  function qu(e, t, n, r) {
    if (!r) return t + n;
    do t += n;
    while (t > 0 && ru(e.text.charAt(t)));
    return t;
  }
  function Ru(e, t, n, r) {
    var i = no(e);
    if (!i) return Uu(e, t, n, r);
    var s = Iu(i, t),
      o = i[s];
    var u = qu(e, t, o.level % 2 ? -n : n, r);
    for (;;) {
      if (u > o.from && u < o.to) return u;
      if (u == o.from || u == o.to) {
        if (Iu(i, u) == s) return u;
        o = i[(s += n)];
        return n > 0 == o.level % 2 ? o.to : o.from;
      } else {
        o = i[(s += n)];
        if (!o) return null;
        if (n > 0 == o.level % 2) u = qu(e, o.to, -1, r);
        else u = qu(e, o.from, 1, r);
      }
    }
  }
  function Uu(e, t, n, r) {
    var i = t + n;
    if (r) while (i > 0 && ru(e.text.charAt(i))) i += n;
    return i < 0 || i > e.text.length ? null : i;
  }
  var e = /gecko\/\d/i.test(navigator.userAgent);
  var t = /MSIE \d/.test(navigator.userAgent);
  var n = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
  var r = t || n;
  var i = r && (t ? document.documentMode || 6 : n[1]);
  var s = /WebKit\//.test(navigator.userAgent);
  var o = s && /Qt\/\d+\.\d+/.test(navigator.userAgent);
  var u = /Chrome\//.test(navigator.userAgent);
  var a = /Opera\//.test(navigator.userAgent);
  var f = /Apple Computer/.test(navigator.vendor);
  var l = /KHTML\//.test(navigator.userAgent);
  var c = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
  var h = /PhantomJS/.test(navigator.userAgent);
  var p = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
  var d = p || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
  var v = p || /Mac/.test(navigator.platform);
  var m = /win/i.test(navigator.platform);
  var g = a && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
  if (g) g = Number(g[1]);
  if (g && g >= 15) {
    a = false;
    s = true;
  }
  var y = v && (o || (a && (g == null || g < 12.11)));
  var b = e || (r && i >= 9);
  var w = false,
    E = false;
  j.prototype = Qo(
    {
      update: function (e) {
        var t = e.scrollWidth > e.clientWidth + 1;
        var n = e.scrollHeight > e.clientHeight + 1;
        var r = e.nativeBarWidth;
        if (n) {
          this.vert.style.display = 'block';
          this.vert.style.bottom = t ? r + 'px' : '0';
          var i = e.viewHeight - (t ? r : 0);
          this.vert.firstChild.style.height = Math.max(0, e.scrollHeight - e.clientHeight + i) + 'px';
        } else {
          this.vert.style.display = '';
          this.vert.firstChild.style.height = '0';
        }
        if (t) {
          this.horiz.style.display = 'block';
          this.horiz.style.right = n ? r + 'px' : '0';
          this.horiz.style.left = e.barLeft + 'px';
          var s = e.viewWidth - e.barLeft - (n ? r : 0);
          this.horiz.firstChild.style.width = e.scrollWidth - e.clientWidth + s + 'px';
        } else {
          this.horiz.style.display = '';
          this.horiz.firstChild.style.width = '0';
        }
        if (!this.checkedOverlay && e.clientHeight > 0) {
          if (r == 0) this.overlayHack();
          this.checkedOverlay = true;
        }
        return { right: n ? r : 0, bottom: t ? r : 0 };
      },
      setScrollLeft: function (e) {
        if (this.horiz.scrollLeft != e) this.horiz.scrollLeft = e;
      },
      setScrollTop: function (e) {
        if (this.vert.scrollTop != e) this.vert.scrollTop = e;
      },
      overlayHack: function () {
        var e = v && !c ? '12px' : '18px';
        this.horiz.style.minHeight = this.vert.style.minWidth = e;
        var t = this;
        var n = function (e) {
          if (xo(e) != t.vert && xo(e) != t.horiz) zn(t.cm, pr)(e);
        };
        No(this.vert, 'mousedown', n);
        No(this.horiz, 'mousedown', n);
      },
      clear: function () {
        var e = this.horiz.parentNode;
        e.removeChild(this.horiz);
        e.removeChild(this.vert);
      },
    },
    j.prototype
  );
  F.prototype = Qo(
    {
      update: function () {
        return { bottom: 0, right: 0 };
      },
      setScrollLeft: function () {},
      setScrollTop: function () {},
      clear: function () {},
    },
    F.prototype
  );
  S.scrollbarModel = { native: j, null: F };
  var vt = (S.Pos = function (e, t) {
    if (!(this instanceof vt)) return new vt(e, t);
    this.line = e;
    this.ch = t;
  });
  var mt = (S.cmpPos = function (e, t) {
    return e.line - t.line || e.ch - t.ch;
  });
  wt.prototype = {
    primary: function () {
      return this.ranges[this.primIndex];
    },
    equals: function (e) {
      if (e == this) return true;
      if (e.primIndex != this.primIndex || e.ranges.length != this.ranges.length) return false;
      for (var t = 0; t < this.ranges.length; t++) {
        var n = this.ranges[t],
          r = e.ranges[t];
        if (mt(n.anchor, r.anchor) != 0 || mt(n.head, r.head) != 0) return false;
      }
      return true;
    },
    deepCopy: function () {
      for (var e = [], t = 0; t < this.ranges.length; t++) e[t] = new Et(gt(this.ranges[t].anchor), gt(this.ranges[t].head));
      return new wt(e, this.primIndex);
    },
    somethingSelected: function () {
      for (var e = 0; e < this.ranges.length; e++) if (!this.ranges[e].empty()) return true;
      return false;
    },
    contains: function (e, t) {
      if (!t) t = e;
      for (var n = 0; n < this.ranges.length; n++) {
        var r = this.ranges[n];
        if (mt(t, r.from()) >= 0 && mt(e, r.to()) <= 0) return n;
      }
      return -1;
    },
  };
  Et.prototype = {
    from: function () {
      return bt(this.anchor, this.head);
    },
    to: function () {
      return yt(this.anchor, this.head);
    },
    empty: function () {
      return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
    },
  };
  var hn = { left: 0, right: 0, top: 0, bottom: 0 };
  var Ln;
  var Mn = null;
  var _n = 0;
  var rr = null;
  var dr, vr;
  var Er = 0;
  var Cr = 0,
    kr = null;
  if (r) kr = -0.53;
  else if (e) kr = 15;
  else if (u) kr = -0.7;
  else if (f) kr = -1 / 3;
  var Lr = function (e) {
    var t = e.wheelDeltaX,
      n = e.wheelDeltaY;
    if (t == null && e.detail && e.axis == e.HORIZONTAL_AXIS) t = e.detail;
    if (n == null && e.detail && e.axis == e.VERTICAL_AXIS) n = e.detail;
    else if (n == null) n = e.wheelDelta;
    return { x: t, y: n };
  };
  S.wheelEventPixels = function (e) {
    var t = Lr(e);
    t.x *= kr;
    t.y *= kr;
    return t;
  };
  var _r = new qo();
  var Br = null;
  var Xr = (S.changeEnd = function (e) {
    if (!e.text) return e.to;
    return vt(e.from.line + e.text.length - 1, Xo(e.text).length + (e.text.length == 1 ? e.from.ch : 0));
  });
  S.prototype = {
    constructor: S,
    focus: function () {
      window.focus();
      or(this);
      nr(this);
    },
    setOption: function (e, t) {
      var n = this.options,
        r = n[e];
      if (n[e] == t && e != 'mode') return;
      n[e] = t;
      if (gi.hasOwnProperty(e)) zn(this, gi[e])(this, t, r);
    },
    getOption: function (e) {
      return this.options[e];
    },
    getDoc: function () {
      return this.doc;
    },
    addKeyMap: function (e, t) {
      this.state.keyMaps[t ? 'push' : 'unshift'](Di(e));
    },
    removeKeyMap: function (e) {
      var t = this.state.keyMaps;
      for (var n = 0; n < t.length; ++n)
        if (t[n] == e || t[n].name == e) {
          t.splice(n, 1);
          return true;
        }
    },
    addOverlay: Wn(function (e, t) {
      var n = e.token ? e : S.getMode(this.options, e);
      if (n.startState) throw new Error('Overlays may not be stateful.');
      this.state.overlays.push({ mode: n, modeSpec: e, opaque: t && t.opaque });
      this.state.modeGen++;
      Jn(this);
    }),
    removeOverlay: Wn(function (e) {
      var t = this.state.overlays;
      for (var n = 0; n < t.length; ++n) {
        var r = t[n].modeSpec;
        if (r == e || (typeof e == 'string' && r.name == e)) {
          t.splice(n, 1);
          this.state.modeGen++;
          Jn(this);
          return;
        }
      }
    }),
    indentLine: Wn(function (e, t, n) {
      if (typeof t != 'string' && typeof t != 'number') {
        if (t == null) t = this.options.smartIndent ? 'smart' : 'prev';
        else t = t ? 'add' : 'subtract';
      }
      if (kt(this.doc, e)) ci(this, e, t, n);
    }),
    indentSelection: Wn(function (e) {
      var t = this.doc.sel.ranges,
        n = -1;
      for (var r = 0; r < t.length; r++) {
        var i = t[r];
        if (!i.empty()) {
          var s = i.from(),
            o = i.to();
          var u = Math.max(n, s.line);
          n = Math.min(this.lastLine(), o.line - (o.ch ? 0 : 1)) + 1;
          for (var a = u; a < n; ++a) ci(this, a, e);
          var f = this.doc.sel.ranges;
          if (s.ch == 0 && t.length == f.length && f[r].from().ch > 0) _t(this.doc, r, new Et(s, f[r].to()), jo);
        } else if (i.head.line > n) {
          ci(this, i.head.line, e, true);
          n = i.head.line;
          if (r == this.doc.sel.primIndex) fi(this);
        }
      }
    }),
    getTokenAt: function (e, t) {
      return Ts(this, e, t);
    },
    getLineTokens: function (e, t) {
      return Ts(this, vt(e), t, true);
    },
    getTokenTypeAt: function (e) {
      e = Nt(this.doc, e);
      var t = ks(this, Ks(this.doc, e.line));
      var n = 0,
        r = (t.length - 1) / 2,
        i = e.ch;
      var s;
      if (i == 0) s = t[2];
      else
        for (;;) {
          var o = (n + r) >> 1;
          if ((o ? t[o * 2 - 1] : 0) >= i) r = o;
          else if (t[o * 2 + 1] < i) n = o + 1;
          else {
            s = t[o * 2 + 2];
            break;
          }
        }
      var u = s ? s.indexOf('cm-overlay ') : -1;
      return u < 0 ? s : u == 0 ? null : s.slice(0, u - 1);
    },
    getModeAt: function (e) {
      var t = this.doc.mode;
      if (!t.innerMode) return t;
      return S.innerMode(t, this.getTokenAt(e).state).mode;
    },
    getHelper: function (e, t) {
      return this.getHelpers(e, t)[0];
    },
    getHelpers: function (e, t) {
      var n = [];
      if (!Ti.hasOwnProperty(t)) return Ti;
      var r = Ti[t],
        i = this.getModeAt(e);
      if (typeof i[t] == 'string') {
        if (r[i[t]]) n.push(r[i[t]]);
      } else if (i[t]) {
        for (var s = 0; s < i[t].length; s++) {
          var o = r[i[t][s]];
          if (o) n.push(o);
        }
      } else if (i.helperType && r[i.helperType]) {
        n.push(r[i.helperType]);
      } else if (r[i.name]) {
        n.push(r[i.name]);
      }
      for (var s = 0; s < r._global.length; s++) {
        var u = r._global[s];
        if (u.pred(i, this) && $o(n, u.val) == -1) n.push(u.val);
      }
      return n;
    },
    getStateAfter: function (e, t) {
      var n = this.doc;
      e = Tt(n, e == null ? n.first + n.size - 1 : e);
      return Gt(this, e + 1, t);
    },
    cursorCoords: function (e, t) {
      var n,
        r = this.doc.sel.primary();
      if (e == null) n = r.head;
      else if (typeof e == 'object') n = Nt(this.doc, e);
      else n = e ? r.from() : r.to();
      return xn(this, n, t || 'page');
    },
    charCoords: function (e, t) {
      return Sn(this, Nt(this.doc, e), t || 'page');
    },
    coordsChar: function (e, t) {
      e = En(this, e, t || 'page');
      return Cn(this, e.left, e.top);
    },
    lineAtHeight: function (e, t) {
      e = En(this, { top: e, left: 0 }, t || 'page').top;
      return eo(this.doc, e + this.display.viewOffset);
    },
    heightAtLine: function (e, t) {
      var n = false,
        r = this.doc.first + this.doc.size - 1;
      if (e < this.doc.first) e = this.doc.first;
      else if (e > r) {
        e = r;
        n = true;
      }
      var i = Ks(this.doc, e);
      return wn(this, i, { top: 0, left: 0 }, t || 'page').top + (n ? this.doc.height - to(i) : 0);
    },
    defaultTextHeight: function () {
      return An(this.display);
    },
    defaultCharWidth: function () {
      return On(this.display);
    },
    setGutterMarker: Wn(function (e, t, n) {
      return hi(this.doc, e, 'gutter', function (e) {
        var r = e.gutterMarkers || (e.gutterMarkers = {});
        r[t] = n;
        if (!n && tu(r)) e.gutterMarkers = null;
        return true;
      });
    }),
    clearGutter: Wn(function (e) {
      var t = this,
        n = t.doc,
        r = n.first;
      n.iter(function (n) {
        if (n.gutterMarkers && n.gutterMarkers[e]) {
          n.gutterMarkers[e] = null;
          Kn(t, r, 'gutter');
          if (tu(n.gutterMarkers)) n.gutterMarkers = null;
        }
        ++r;
      });
    }),
    addLineWidget: Wn(function (e, t, n) {
      return gs(this, e, t, n);
    }),
    removeLineWidget: function (e) {
      e.clear();
    },
    lineInfo: function (e) {
      if (typeof e == 'number') {
        if (!kt(this.doc, e)) return null;
        var t = e;
        e = Ks(this.doc, e);
        if (!e) return null;
      } else {
        var t = Zs(e);
        if (t == null) return null;
      }
      return { line: t, handle: e, text: e.text, gutterMarkers: e.gutterMarkers, textClass: e.textClass, bgClass: e.bgClass, wrapClass: e.wrapClass, widgets: e.widgets };
    },
    getViewport: function () {
      return { from: this.display.viewFrom, to: this.display.viewTo };
    },
    addWidget: function (e, t, n, r, i) {
      var s = this.display;
      e = xn(this, Nt(this.doc, e));
      var o = e.bottom,
        u = e.left;
      t.style.position = 'absolute';
      t.setAttribute('cm-ignore-events', 'true');
      s.sizer.appendChild(t);
      if (r == 'over') {
        o = e.top;
      } else if (r == 'above' || r == 'near') {
        var a = Math.max(s.wrapper.clientHeight, this.doc.height),
          f = Math.max(s.sizer.clientWidth, s.lineSpace.clientWidth);
        if ((r == 'above' || e.bottom + t.offsetHeight > a) && e.top > t.offsetHeight) o = e.top - t.offsetHeight;
        else if (e.bottom + t.offsetHeight <= a) o = e.bottom;
        if (u + t.offsetWidth > f) u = f - t.offsetWidth;
      }
      t.style.top = o + 'px';
      t.style.left = t.style.right = '';
      if (i == 'right') {
        u = s.sizer.clientWidth - t.offsetWidth;
        t.style.right = '0px';
      } else {
        if (i == 'left') u = 0;
        else if (i == 'middle') u = (s.sizer.clientWidth - t.offsetWidth) / 2;
        t.style.left = u + 'px';
      }
      if (n) oi(this, u, o, u + t.offsetWidth, o + t.offsetHeight);
    },
    triggerOnKeyDown: Wn(jr),
    triggerOnKeyPress: Wn(qr),
    triggerOnKeyUp: Ir,
    execCommand: function (e) {
      if (ki.hasOwnProperty(e)) return ki[e](this);
    },
    findPosH: function (e, t, n, r) {
      var i = 1;
      if (t < 0) {
        i = -1;
        t = -t;
      }
      for (var s = 0, o = Nt(this.doc, e); s < t; ++s) {
        o = di(this.doc, o, i, n, r);
        if (o.hitSide) break;
      }
      return o;
    },
    moveH: Wn(function (e, t) {
      var n = this;
      n.extendSelectionsBy(function (r) {
        if (n.display.shift || n.doc.extend || r.empty()) return di(n.doc, r.head, e, t, n.options.rtlMoveVisually);
        else return e < 0 ? r.from() : r.to();
      }, Io);
    }),
    deleteH: Wn(function (e, t) {
      var n = this.doc.sel,
        r = this.doc;
      if (n.somethingSelected()) r.replaceSelection('', null, '+delete');
      else
        pi(this, function (n) {
          var i = di(r, n.head, e, t, false);
          return e < 0 ? { from: i, to: n.head } : { from: n.head, to: i };
        });
    }),
    findPosV: function (e, t, n, r) {
      var i = 1,
        s = r;
      if (t < 0) {
        i = -1;
        t = -t;
      }
      for (var o = 0, u = Nt(this.doc, e); o < t; ++o) {
        var a = xn(this, u, 'div');
        if (s == null) s = a.left;
        else a.left = s;
        u = vi(this, a, i, n);
        if (u.hitSide) break;
      }
      return u;
    },
    moveV: Wn(function (e, t) {
      var n = this,
        r = this.doc,
        i = [];
      var s = !n.display.shift && !r.extend && r.sel.somethingSelected();
      r.extendSelectionsBy(function (o) {
        if (s) return e < 0 ? o.from() : o.to();
        var u = xn(n, o.head, 'div');
        if (o.goalColumn != null) u.left = o.goalColumn;
        i.push(u.left);
        var a = vi(n, u, e, t);
        if (t == 'page' && o == r.sel.primary()) ai(n, null, Sn(n, a, 'div').top - u.top);
        return a;
      }, Io);
      if (i.length) for (var o = 0; o < r.sel.ranges.length; o++) r.sel.ranges[o].goalColumn = i[o];
    }),
    findWordAt: function (e) {
      var t = this.doc,
        n = Ks(t, e.line).text;
      var r = e.ch,
        i = e.ch;
      if (n) {
        var s = this.getHelper(e, 'wordChars');
        if ((e.xRel < 0 || i == n.length) && r) --r;
        else ++i;
        var o = n.charAt(r);
        var u = eu(o, s)
          ? function (e) {
              return eu(e, s);
            }
          : /\s/.test(o)
            ? function (e) {
                return /\s/.test(e);
              }
            : function (e) {
                return !/\s/.test(e) && !eu(e);
              };
        while (r > 0 && u(n.charAt(r - 1))) --r;
        while (i < n.length && u(n.charAt(i))) ++i;
      }
      return new Et(vt(e.line, r), vt(e.line, i));
    },
    toggleOverwrite: function (e) {
      if (e != null && e == this.state.overwrite) return;
      if ((this.state.overwrite = !this.state.overwrite)) hu(this.display.cursorDiv, 'CodeMirror-overwrite');
      else cu(this.display.cursorDiv, 'CodeMirror-overwrite');
      ko(this, 'overwriteToggle', this, this.state.overwrite);
    },
    hasFocus: function () {
      return fu() == this.display.input;
    },
    scrollTo: Wn(function (e, t) {
      if (e != null || t != null) li(this);
      if (e != null) this.curOp.scrollLeft = e;
      if (t != null) this.curOp.scrollTop = t;
    }),
    getScrollInfo: function () {
      var e = this.display.scroller;
      return { left: e.scrollLeft, top: e.scrollTop, height: e.scrollHeight - tn(this) - this.display.barHeight, width: e.scrollWidth - tn(this) - this.display.barWidth, clientHeight: rn(this), clientWidth: nn(this) };
    },
    scrollIntoView: Wn(function (e, t) {
      if (e == null) {
        e = { from: this.doc.sel.primary().head, to: null };
        if (t == null) t = this.options.cursorScrollMargin;
      } else if (typeof e == 'number') {
        e = { from: vt(e, 0), to: null };
      } else if (e.from == null) {
        e = { from: e, to: null };
      }
      if (!e.to) e.to = e.from;
      e.margin = t || 0;
      if (e.from.line != null) {
        li(this);
        this.curOp.scrollToPos = e;
      } else {
        var n = ui(this, Math.min(e.from.left, e.to.left), Math.min(e.from.top, e.to.top) - e.margin, Math.max(e.from.right, e.to.right), Math.max(e.from.bottom, e.to.bottom) + e.margin);
        this.scrollTo(n.scrollLeft, n.scrollTop);
      }
    }),
    setSize: Wn(function (e, t) {
      function r(e) {
        return typeof e == 'number' || /^\d+$/.test(String(e)) ? e + 'px' : e;
      }
      var n = this;
      if (e != null) n.display.wrapper.style.width = r(e);
      if (t != null) n.display.wrapper.style.height = r(t);
      if (n.options.lineWrapping) mn(this);
      var i = n.display.viewFrom;
      n.doc.iter(i, n.display.viewTo, function (e) {
        if (e.widgets)
          for (var t = 0; t < e.widgets.length; t++)
            if (e.widgets[t].noHScroll) {
              Kn(n, i, 'widget');
              break;
            }
        ++i;
      });
      n.curOp.forceUpdate = true;
      ko(n, 'refresh', this);
    }),
    operation: function (e) {
      return Un(this, e);
    },
    refresh: Wn(function () {
      var e = this.display.cachedTextHeight;
      Jn(this);
      this.curOp.forceUpdate = true;
      gn(this);
      this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop);
      _(this);
      if (e == null || Math.abs(e - An(this.display)) > 0.5) L(this);
      ko(this, 'refresh', this);
    }),
    swapDoc: Wn(function (e) {
      var t = this.doc;
      t.cm = null;
      Js(this, e);
      gn(this);
      sr(this);
      this.scrollTo(e.scrollLeft, e.scrollTop);
      this.curOp.forceScroll = true;
      Ao(this, 'swapDoc', this, t);
      return t;
    }),
    getInputField: function () {
      return this.display.input;
    },
    getWrapperElement: function () {
      return this.display.wrapper;
    },
    getScrollerElement: function () {
      return this.display.scroller;
    },
    getGutterElement: function () {
      return this.display.gutters;
    },
  };
  Po(S);
  var mi = (S.defaults = {});
  var gi = (S.optionHandlers = {});
  var bi = (S.Init = {
    toString: function () {
      return 'CodeMirror.Init';
    },
  });
  yi(
    'value',
    '',
    function (e, t) {
      e.setValue(t);
    },
    true
  );
  yi(
    'mode',
    null,
    function (e, t) {
      e.doc.modeOption = t;
      T(e);
    },
    true
  );
  yi('indentUnit', 2, T, true);
  yi('indentWithTabs', false);
  yi('smartIndent', true);
  yi(
    'tabSize',
    4,
    function (e) {
      N(e);
      gn(e);
      Jn(e);
    },
    true
  );
  yi(
    'specialChars',
    /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g,
    function (e, t) {
      e.options.specialChars = new RegExp(t.source + (t.test('	') ? '' : '|	'), 'g');
      e.refresh();
    },
    true
  );
  yi(
    'specialCharPlaceholder',
    Ds,
    function (e) {
      e.refresh();
    },
    true
  );
  yi('electricChars', true);
  yi('rtlMoveVisually', !m);
  yi('wholeLineUpdateBefore', true);
  yi(
    'theme',
    'default',
    function (e) {
      A(e);
      O(e);
    },
    true
  );
  yi('keyMap', 'default', function (e, t, n) {
    var r = Di(t);
    var i = n != S.Init && Di(n);
    if (i && i.detach) i.detach(e, r);
    if (r.attach) r.attach(e, i || null);
  });
  yi('extraKeys', null);
  yi('lineWrapping', false, C, true);
  yi(
    'gutters',
    [],
    function (e) {
      H(e.options);
      O(e);
    },
    true
  );
  yi(
    'fixedGutter',
    true,
    function (e, t) {
      e.display.gutters.style.left = t ? V(e.display) + 'px' : '0';
      e.refresh();
    },
    true
  );
  yi(
    'coverGutterNextToScrollbar',
    false,
    function (e) {
      q(e);
    },
    true
  );
  yi(
    'scrollbarStyle',
    'native',
    function (e) {
      I(e);
      q(e);
      e.display.scrollbars.setScrollTop(e.doc.scrollTop);
      e.display.scrollbars.setScrollLeft(e.doc.scrollLeft);
    },
    true
  );
  yi(
    'lineNumbers',
    false,
    function (e) {
      H(e.options);
      O(e);
    },
    true
  );
  yi('firstLineNumber', 1, O, true);
  yi(
    'lineNumberFormatter',
    function (e) {
      return e;
    },
    O,
    true
  );
  yi('showCursorWhenSelecting', false, Wt, true);
  yi('resetSelectionOnContextMenu', true);
  yi('readOnly', false, function (e, t) {
    if (t == 'nocursor') {
      Ur(e);
      e.display.input.blur();
      e.display.disabled = true;
    } else {
      e.display.disabled = false;
      if (!t) sr(e);
    }
  });
  yi(
    'disableInput',
    false,
    function (e, t) {
      if (!t) sr(e);
    },
    true
  );
  yi('dragDrop', true);
  yi('cursorBlinkRate', 530);
  yi('cursorScrollMargin', 0);
  yi('cursorHeight', 1, Wt, true);
  yi('singleCursorHeightPerLine', true, Wt, true);
  yi('workTime', 100);
  yi('workDelay', 100);
  yi('flattenSpans', true, N, true);
  yi('addModeClass', false, N, true);
  yi('pollInterval', 100);
  yi('undoDepth', 200, function (e, t) {
    e.doc.history.undoDepth = t;
  });
  yi('historyEventDelay', 1250);
  yi(
    'viewportMargin',
    10,
    function (e) {
      e.refresh();
    },
    true
  );
  yi('maxHighlightLength', 1e4, N, true);
  yi('moveInputWithCursor', true, function (e, t) {
    if (!t) e.display.inputDiv.style.top = e.display.inputDiv.style.left = 0;
  });
  yi('tabindex', null, function (e, t) {
    e.display.input.tabIndex = t || '';
  });
  yi('autofocus', null);
  var wi = (S.modes = {}),
    Ei = (S.mimeModes = {});
  S.defineMode = function (e, t) {
    if (!S.defaults.mode && e != 'null') S.defaults.mode = e;
    if (arguments.length > 2) t.dependencies = Array.prototype.slice.call(arguments, 2);
    wi[e] = t;
  };
  S.defineMIME = function (e, t) {
    Ei[e] = t;
  };
  S.resolveMode = function (e) {
    if (typeof e == 'string' && Ei.hasOwnProperty(e)) {
      e = Ei[e];
    } else if (e && typeof e.name == 'string' && Ei.hasOwnProperty(e.name)) {
      var t = Ei[e.name];
      if (typeof t == 'string') t = { name: t };
      e = Ko(t, e);
      e.name = t.name;
    } else if (typeof e == 'string' && /^[\w\-]+\/[\w\-]+\+xml$/.test(e)) {
      return S.resolveMode('application/xml');
    }
    if (typeof e == 'string') return { name: e };
    else return e || { name: 'null' };
  };
  S.getMode = function (e, t) {
    var t = S.resolveMode(t);
    var n = wi[t.name];
    if (!n) return S.getMode(e, 'text/plain');
    var r = n(e, t);
    if (Si.hasOwnProperty(t.name)) {
      var i = Si[t.name];
      for (var s in i) {
        if (!i.hasOwnProperty(s)) continue;
        if (r.hasOwnProperty(s)) r['_' + s] = r[s];
        r[s] = i[s];
      }
    }
    r.name = t.name;
    if (t.helperType) r.helperType = t.helperType;
    if (t.modeProps) for (var s in t.modeProps) r[s] = t.modeProps[s];
    return r;
  };
  S.defineMode('null', function () {
    return {
      token: function (e) {
        e.skipToEnd();
      },
    };
  });
  S.defineMIME('text/plain', 'null');
  var Si = (S.modeExtensions = {});
  S.extendMode = function (e, t) {
    var n = Si.hasOwnProperty(e) ? Si[e] : (Si[e] = {});
    Qo(t, n);
  };
  S.defineExtension = function (e, t) {
    S.prototype[e] = t;
  };
  S.defineDocExtension = function (e, t) {
    Ws.prototype[e] = t;
  };
  S.defineOption = yi;
  var xi = [];
  S.defineInitHook = function (e) {
    xi.push(e);
  };
  var Ti = (S.helpers = {});
  S.registerHelper = function (e, t, n) {
    if (!Ti.hasOwnProperty(e)) Ti[e] = S[e] = { _global: [] };
    Ti[e][t] = n;
  };
  S.registerGlobalHelper = function (e, t, n, r) {
    S.registerHelper(e, t, r);
    Ti[e]._global.push({ pred: n, val: r });
  };
  var Ni = (S.copyState = function (e, t) {
    if (t === true) return t;
    if (e.copyState) return e.copyState(t);
    var n = {};
    for (var r in t) {
      var i = t[r];
      if (i instanceof Array) i = i.concat([]);
      n[r] = i;
    }
    return n;
  });
  var Ci = (S.startState = function (e, t, n) {
    return e.startState ? e.startState(t, n) : true;
  });
  S.innerMode = function (e, t) {
    while (e.innerMode) {
      var n = e.innerMode(t);
      if (!n || n.mode == e) break;
      t = n.state;
      e = n.mode;
    }
    return n || { mode: e, state: t };
  };
  var ki = (S.commands = {
    selectAll: function (e) {
      e.setSelection(vt(e.firstLine(), 0), vt(e.lastLine()), jo);
    },
    singleSelection: function (e) {
      e.setSelection(e.getCursor('anchor'), e.getCursor('head'), jo);
    },
    killLine: function (e) {
      pi(e, function (t) {
        if (t.empty()) {
          var n = Ks(e.doc, t.head.line).text.length;
          if (t.head.ch == n && t.head.line < e.lastLine()) return { from: t.head, to: vt(t.head.line + 1, 0) };
          else return { from: t.head, to: vt(t.head.line, n) };
        } else {
          return { from: t.from(), to: t.to() };
        }
      });
    },
    deleteLine: function (e) {
      pi(e, function (t) {
        return { from: vt(t.from().line, 0), to: Nt(e.doc, vt(t.to().line + 1, 0)) };
      });
    },
    delLineLeft: function (e) {
      pi(e, function (e) {
        return { from: vt(e.from().line, 0), to: e.from() };
      });
    },
    delWrappedLineLeft: function (e) {
      pi(e, function (t) {
        var n = e.charCoords(t.head, 'div').top + 5;
        var r = e.coordsChar({ left: 0, top: n }, 'div');
        return { from: r, to: t.from() };
      });
    },
    delWrappedLineRight: function (e) {
      pi(e, function (t) {
        var n = e.charCoords(t.head, 'div').top + 5;
        var r = e.coordsChar({ left: e.display.lineDiv.offsetWidth + 100, top: n }, 'div');
        return { from: t.from(), to: r };
      });
    },
    undo: function (e) {
      e.undo();
    },
    redo: function (e) {
      e.redo();
    },
    undoSelection: function (e) {
      e.undoSelection();
    },
    redoSelection: function (e) {
      e.redoSelection();
    },
    goDocStart: function (e) {
      e.extendSelection(vt(e.firstLine(), 0));
    },
    goDocEnd: function (e) {
      e.extendSelection(vt(e.lastLine()));
    },
    goLineStart: function (e) {
      e.extendSelectionsBy(
        function (t) {
          return Pu(e, t.head.line);
        },
        { origin: '+move', bias: 1 }
      );
    },
    goLineStartSmart: function (e) {
      e.extendSelectionsBy(
        function (t) {
          return Bu(e, t.head);
        },
        { origin: '+move', bias: 1 }
      );
    },
    goLineEnd: function (e) {
      e.extendSelectionsBy(
        function (t) {
          return Hu(e, t.head.line);
        },
        { origin: '+move', bias: -1 }
      );
    },
    goLineRight: function (e) {
      e.extendSelectionsBy(function (t) {
        var n = e.charCoords(t.head, 'div').top + 5;
        return e.coordsChar({ left: e.display.lineDiv.offsetWidth + 100, top: n }, 'div');
      }, Io);
    },
    goLineLeft: function (e) {
      e.extendSelectionsBy(function (t) {
        var n = e.charCoords(t.head, 'div').top + 5;
        return e.coordsChar({ left: 0, top: n }, 'div');
      }, Io);
    },
    goLineLeftSmart: function (e) {
      e.extendSelectionsBy(function (t) {
        var n = e.charCoords(t.head, 'div').top + 5;
        var r = e.coordsChar({ left: 0, top: n }, 'div');
        if (r.ch < e.getLine(r.line).search(/\S/)) return Bu(e, t.head);
        return r;
      }, Io);
    },
    goLineUp: function (e) {
      e.moveV(-1, 'line');
    },
    goLineDown: function (e) {
      e.moveV(1, 'line');
    },
    goPageUp: function (e) {
      e.moveV(-1, 'page');
    },
    goPageDown: function (e) {
      e.moveV(1, 'page');
    },
    goCharLeft: function (e) {
      e.moveH(-1, 'char');
    },
    goCharRight: function (e) {
      e.moveH(1, 'char');
    },
    goColumnLeft: function (e) {
      e.moveH(-1, 'column');
    },
    goColumnRight: function (e) {
      e.moveH(1, 'column');
    },
    goWordLeft: function (e) {
      e.moveH(-1, 'word');
    },
    goGroupRight: function (e) {
      e.moveH(1, 'group');
    },
    goGroupLeft: function (e) {
      e.moveH(-1, 'group');
    },
    goWordRight: function (e) {
      e.moveH(1, 'word');
    },
    delCharBefore: function (e) {
      e.deleteH(-1, 'char');
    },
    delCharAfter: function (e) {
      e.deleteH(1, 'char');
    },
    delWordBefore: function (e) {
      e.deleteH(-1, 'word');
    },
    delWordAfter: function (e) {
      e.deleteH(1, 'word');
    },
    delGroupBefore: function (e) {
      e.deleteH(-1, 'group');
    },
    delGroupAfter: function (e) {
      e.deleteH(1, 'group');
    },
    indentAuto: function (e) {
      e.indentSelection('smart');
    },
    indentMore: function (e) {
      e.indentSelection('add');
    },
    indentLess: function (e) {
      e.indentSelection('subtract');
    },
    insertTab: function (e) {
      e.replaceSelection('	');
    },
    insertSoftTab: function (e) {
      var t = [],
        n = e.listSelections(),
        r = e.options.tabSize;
      for (var i = 0; i < n.length; i++) {
        var s = n[i].from();
        var o = Ro(e.getLine(s.line), s.ch, r);
        t.push(new Array(r - (o % r) + 1).join(' '));
      }
      e.replaceSelections(t);
    },
    defaultTab: function (e) {
      if (e.somethingSelected()) e.indentSelection('add');
      else e.execCommand('insertTab');
    },
    transposeChars: function (e) {
      Un(e, function () {
        var t = e.listSelections(),
          n = [];
        for (var r = 0; r < t.length; r++) {
          var i = t[r].head,
            s = Ks(e.doc, i.line).text;
          if (s) {
            if (i.ch == s.length) i = new vt(i.line, i.ch - 1);
            if (i.ch > 0) {
              i = new vt(i.line, i.ch + 1);
              e.replaceRange(s.charAt(i.ch - 1) + s.charAt(i.ch - 2), vt(i.line, i.ch - 2), i, '+transpose');
            } else if (i.line > e.doc.first) {
              var o = Ks(e.doc, i.line - 1).text;
              if (o) e.replaceRange(s.charAt(0) + '\n' + o.charAt(o.length - 1), vt(i.line - 1, o.length - 1), vt(i.line, 1), '+transpose');
            }
          }
          n.push(new Et(i, i));
        }
        e.setSelections(n);
      });
    },
    newlineAndIndent: function (e) {
      Un(e, function () {
        var t = e.listSelections().length;
        for (var n = 0; n < t; n++) {
          var r = e.listSelections()[n];
          e.replaceRange('\n', r.anchor, r.head, '+input');
          e.indentLine(r.from().line + 1, null, true);
          fi(e);
        }
      });
    },
    toggleOverwrite: function (e) {
      e.toggleOverwrite();
    },
  });
  var Li = (S.keyMap = {});
  Li.basic = {
    Left: 'goCharLeft',
    Right: 'goCharRight',
    Up: 'goLineUp',
    Down: 'goLineDown',
    End: 'goLineEnd',
    Home: 'goLineStartSmart',
    PageUp: 'goPageUp',
    PageDown: 'goPageDown',
    Delete: 'delCharAfter',
    Backspace: 'delCharBefore',
    'Shift-Backspace': 'delCharBefore',
    Tab: 'defaultTab',
    'Shift-Tab': 'indentAuto',
    Enter: 'newlineAndIndent',
    Insert: 'toggleOverwrite',
    Esc: 'singleSelection',
  };
  Li.pcDefault = {
    'Ctrl-A': 'selectAll',
    'Ctrl-D': 'deleteLine',
    'Ctrl-Z': 'undo',
    'Shift-Ctrl-Z': 'redo',
    'Ctrl-Y': 'redo',
    'Ctrl-Home': 'goDocStart',
    'Ctrl-End': 'goDocEnd',
    'Ctrl-Up': 'goLineUp',
    'Ctrl-Down': 'goLineDown',
    'Ctrl-Left': 'goGroupLeft',
    'Ctrl-Right': 'goGroupRight',
    'Alt-Left': 'goLineStart',
    'Alt-Right': 'goLineEnd',
    'Ctrl-Backspace': 'delGroupBefore',
    'Ctrl-Delete': 'delGroupAfter',
    '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',
    'Ctrl-U': 'undoSelection',
    'Shift-Ctrl-U': 'redoSelection',
    'Alt-U': 'redoSelection',
    fallthrough: 'basic',
  };
  Li.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': 'goPageDown',
    'Shift-Ctrl-V': 'goPageUp',
    'Ctrl-D': 'delCharAfter',
    'Ctrl-H': 'delCharBefore',
    'Alt-D': 'delWordAfter',
    'Alt-Backspace': 'delWordBefore',
    'Ctrl-K': 'killLine',
    'Ctrl-T': 'transposeChars',
  };
  Li.macDefault = {
    'Cmd-A': 'selectAll',
    'Cmd-D': 'deleteLine',
    'Cmd-Z': 'undo',
    'Shift-Cmd-Z': 'redo',
    'Cmd-Y': 'redo',
    'Cmd-Home': 'goDocStart',
    'Cmd-Up': 'goDocStart',
    'Cmd-End': 'goDocEnd',
    'Cmd-Down': 'goDocEnd',
    'Alt-Left': 'goGroupLeft',
    'Alt-Right': 'goGroupRight',
    'Cmd-Left': 'goLineLeft',
    'Cmd-Right': 'goLineRight',
    'Alt-Backspace': 'delGroupBefore',
    'Ctrl-Alt-Backspace': 'delGroupAfter',
    'Alt-Delete': 'delGroupAfter',
    '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',
    'Cmd-Backspace': 'delWrappedLineLeft',
    'Cmd-Delete': 'delWrappedLineRight',
    'Cmd-U': 'undoSelection',
    'Shift-Cmd-U': 'redoSelection',
    'Ctrl-Up': 'goDocStart',
    'Ctrl-Down': 'goDocEnd',
    fallthrough: ['basic', 'emacsy'],
  };
  Li['default'] = v ? Li.macDefault : Li.pcDefault;
  S.normalizeKeyMap = function (e) {
    var t = {};
    for (var n in e)
      if (e.hasOwnProperty(n)) {
        var r = e[n];
        if (/^(name|fallthrough|(de|at)tach)$/.test(n)) continue;
        if (r == '...') {
          delete e[n];
          continue;
        }
        var i = Jo(n.split(' '), Ai);
        for (var s = 0; s < i.length; s++) {
          var o, u;
          if (s == i.length - 1) {
            u = n;
            o = r;
          } else {
            u = i.slice(0, s + 1).join(' ');
            o = '...';
          }
          var a = t[u];
          if (!a) t[u] = o;
          else if (a != o) throw new Error('Inconsistent bindings for ' + u);
        }
        delete e[n];
      }
    for (var f in t) e[f] = t[f];
    return e;
  };
  var Oi = (S.lookupKey = function (e, t, n, r) {
    t = Di(t);
    var i = t.call ? t.call(e, r) : t[e];
    if (i === false) return 'nothing';
    if (i === '...') return 'multi';
    if (i != null && n(i)) return 'handled';
    if (t.fallthrough) {
      if (Object.prototype.toString.call(t.fallthrough) != '[object Array]') return Oi(e, t.fallthrough, n, r);
      for (var s = 0; s < t.fallthrough.length; s++) {
        var o = Oi(e, t.fallthrough[s], n, r);
        if (o) return o;
      }
    }
  });
  var Mi = (S.isModifierKey = function (e) {
    var t = typeof e == 'string' ? e : Lu[e.keyCode];
    return t == 'Ctrl' || t == 'Alt' || t == 'Shift' || t == 'Mod';
  });
  var _i = (S.keyName = function (e, t) {
    if (a && e.keyCode == 34 && e['char']) return false;
    var n = Lu[e.keyCode],
      r = n;
    if (r == null || e.altGraphKey) return false;
    if (e.altKey && n != 'Alt') r = 'Alt-' + r;
    if ((y ? e.metaKey : e.ctrlKey) && n != 'Ctrl') r = 'Ctrl-' + r;
    if ((y ? e.ctrlKey : e.metaKey) && n != 'Cmd') r = 'Cmd-' + r;
    if (!t && e.shiftKey && n != 'Shift') r = 'Shift-' + r;
    return r;
  });
  S.fromTextArea = function (e, t) {
    function r() {
      e.value = a.getValue();
    }
    if (!t) t = {};
    t.value = e.value;
    if (!t.tabindex && e.tabindex) t.tabindex = e.tabindex;
    if (!t.placeholder && e.placeholder) t.placeholder = e.placeholder;
    if (t.autofocus == null) {
      var n = fu();
      t.autofocus = n == e || (e.getAttribute('autofocus') != null && n == document.body);
    }
    if (e.form) {
      No(e.form, 'submit', r);
      if (!t.leaveSubmitMethodAlone) {
        var i = e.form,
          s = i.submit;
        try {
          var o = (i.submit = function () {
            r();
            i.submit = s;
            i.submit();
            i.submit = o;
          });
        } catch (u) {}
      }
    }
    e.style.display = 'none';
    var a = S(function (t) {
      e.parentNode.insertBefore(t, e.nextSibling);
    }, t);
    a.save = r;
    a.getTextArea = function () {
      return e;
    };
    a.toTextArea = function () {
      a.toTextArea = isNaN;
      r();
      e.parentNode.removeChild(a.getWrapperElement());
      e.style.display = '';
      if (e.form) {
        Co(e.form, 'submit', r);
        if (typeof e.form.submit == 'function') e.form.submit = s;
      }
    };
    return a;
  };
  var Pi = (S.StringStream = function (e, t) {
    this.pos = this.start = 0;
    this.string = e;
    this.tabSize = t || 8;
    this.lastColumnPos = this.lastColumnValue = 0;
    this.lineStart = 0;
  });
  Pi.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 (e) {
      var t = this.string.charAt(this.pos);
      if (typeof e == 'string') var n = t == e;
      else var n = t && (e.test ? e.test(t) : e(t));
      if (n) {
        ++this.pos;
        return t;
      }
    },
    eatWhile: function (e) {
      var t = this.pos;
      while (this.eat(e)) {}
      return this.pos > t;
    },
    eatSpace: function () {
      var e = this.pos;
      while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
      return this.pos > e;
    },
    skipToEnd: function () {
      this.pos = this.string.length;
    },
    skipTo: function (e) {
      var t = this.string.indexOf(e, this.pos);
      if (t > -1) {
        this.pos = t;
        return true;
      }
    },
    backUp: function (e) {
      this.pos -= e;
    },
    column: function () {
      if (this.lastColumnPos < this.start) {
        this.lastColumnValue = Ro(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
        this.lastColumnPos = this.start;
      }
      return this.lastColumnValue - (this.lineStart ? Ro(this.string, this.lineStart, this.tabSize) : 0);
    },
    indentation: function () {
      return Ro(this.string, null, this.tabSize) - (this.lineStart ? Ro(this.string, this.lineStart, this.tabSize) : 0);
    },
    match: function (e, t, n) {
      if (typeof e == 'string') {
        var r = function (e) {
          return n ? e.toLowerCase() : e;
        };
        var i = this.string.substr(this.pos, e.length);
        if (r(i) == r(e)) {
          if (t !== false) this.pos += e.length;
          return true;
        }
      } else {
        var s = this.string.slice(this.pos).match(e);
        if (s && s.index > 0) return null;
        if (s && t !== false) this.pos += s[0].length;
        return s;
      }
    },
    current: function () {
      return this.string.slice(this.start, this.pos);
    },
    hideFirstChars: function (e, t) {
      this.lineStart += e;
      try {
        return t();
      } finally {
        this.lineStart -= e;
      }
    },
  };
  var Hi = (S.TextMarker = function (e, t) {
    this.lines = [];
    this.type = t;
    this.doc = e;
  });
  Po(Hi);
  Hi.prototype.clear = function () {
    if (this.explicitlyCleared) return;
    var e = this.doc.cm,
      t = e && !e.curOp;
    if (t) Dn(e);
    if (Do(this, 'clear')) {
      var n = this.find();
      if (n) Ao(this, 'clear', n.from, n.to);
    }
    var r = null,
      i = null;
    for (var s = 0; s < this.lines.length; ++s) {
      var o = this.lines[s];
      var u = Wi(o.markedSpans, this);
      if (e && !this.collapsed) Kn(e, Zs(o), 'text');
      else if (e) {
        if (u.to != null) i = Zs(o);
        if (u.from != null) r = Zs(o);
      }
      o.markedSpans = Xi(o.markedSpans, u);
      if (u.from == null && this.collapsed && !hs(this.doc, o) && e) Ys(o, An(e.display));
    }
    if (e && this.collapsed && !e.options.lineWrapping)
      for (var s = 0; s < this.lines.length; ++s) {
        var a = as(this.lines[s]),
          f = D(a);
        if (f > e.display.maxLineLength) {
          e.display.maxLine = a;
          e.display.maxLineLength = f;
          e.display.maxLineChanged = true;
        }
      }
    if (r != null && e && this.collapsed) Jn(e, r, i + 1);
    this.lines.length = 0;
    this.explicitlyCleared = true;
    if (this.atomic && this.doc.cantEdit) {
      this.doc.cantEdit = false;
      if (e) It(e.doc);
    }
    if (e) Ao(e, 'markerCleared', e, this);
    if (t) Hn(e);
    if (this.parent) this.parent.clear();
  };
  Hi.prototype.find = function (e, t) {
    if (e == null && this.type == 'bookmark') e = 1;
    var n, r;
    for (var i = 0; i < this.lines.length; ++i) {
      var s = this.lines[i];
      var o = Wi(s.markedSpans, this);
      if (o.from != null) {
        n = vt(t ? s : Zs(s), o.from);
        if (e == -1) return n;
      }
      if (o.to != null) {
        r = vt(t ? s : Zs(s), o.to);
        if (e == 1) return r;
      }
    }
    return n && { from: n, to: r };
  };
  Hi.prototype.changed = function () {
    var e = this.find(-1, true),
      t = this,
      n = this.doc.cm;
    if (!e || !n) return;
    Un(n, function () {
      var r = e.line,
        i = Zs(e.line);
      var s = fn(n, i);
      if (s) {
        vn(s);
        n.curOp.selectionChanged = n.curOp.forceUpdate = true;
      }
      n.curOp.updateMaxLine = true;
      if (!hs(t.doc, r) && t.height != null) {
        var o = t.height;
        t.height = null;
        var u = ms(t) - o;
        if (u) Ys(r, r.height + u);
      }
    });
  };
  Hi.prototype.attachLine = function (e) {
    if (!this.lines.length && this.doc.cm) {
      var t = this.doc.cm.curOp;
      if (!t.maybeHiddenMarkers || $o(t.maybeHiddenMarkers, this) == -1) (t.maybeUnhiddenMarkers || (t.maybeUnhiddenMarkers = [])).push(this);
    }
    this.lines.push(e);
  };
  Hi.prototype.detachLine = function (e) {
    this.lines.splice($o(this.lines, e), 1);
    if (!this.lines.length && this.doc.cm) {
      var t = this.doc.cm.curOp;
      (t.maybeHiddenMarkers || (t.maybeHiddenMarkers = [])).push(this);
    }
  };
  var Bi = 0;
  var Fi = (S.SharedTextMarker = function (e, t) {
    this.markers = e;
    this.primary = t;
    for (var n = 0; n < e.length; ++n) e[n].parent = this;
  });
  Po(Fi);
  Fi.prototype.clear = function () {
    if (this.explicitlyCleared) return;
    this.explicitlyCleared = true;
    for (var e = 0; e < this.markers.length; ++e) this.markers[e].clear();
    Ao(this, 'clear');
  };
  Fi.prototype.find = function (e, t) {
    return this.primary.find(e, t);
  };
  var ds = (S.LineWidget = function (e, t, n) {
    if (n) for (var r in n) if (n.hasOwnProperty(r)) this[r] = n[r];
    this.cm = e;
    this.node = t;
  });
  Po(ds);
  ds.prototype.clear = function () {
    var e = this.cm,
      t = this.line.widgets,
      n = this.line,
      r = Zs(n);
    if (r == null || !t) return;
    for (var i = 0; i < t.length; ++i) if (t[i] == this) t.splice(i--, 1);
    if (!t.length) n.widgets = null;
    var s = ms(this);
    Un(e, function () {
      vs(e, n, -s);
      Kn(e, r, 'widget');
      Ys(n, Math.max(0, n.height - s));
    });
  };
  ds.prototype.changed = function () {
    var e = this.height,
      t = this.cm,
      n = this.line;
    this.height = null;
    var r = ms(this) - e;
    if (!r) return;
    Un(t, function () {
      t.curOp.forceUpdate = true;
      vs(t, n, r);
      Ys(n, n.height + r);
    });
  };
  var ys = (S.Line = function (e, t, n) {
    this.text = e;
    es(this, t);
    this.height = n ? n(this) : 1;
  });
  Po(ys);
  ys.prototype.lineNo = function () {
    return Zs(this);
  };
  var As = {},
    Os = {};
  Rs.prototype = {
    chunkSize: function () {
      return this.lines.length;
    },
    removeInner: function (e, t) {
      for (var n = e, r = e + t; n < r; ++n) {
        var i = this.lines[n];
        this.height -= i.height;
        ws(i);
        Ao(i, 'delete');
      }
      this.lines.splice(e, t);
    },
    collapse: function (e) {
      e.push.apply(e, this.lines);
    },
    insertInner: function (e, t, n) {
      this.height += n;
      this.lines = this.lines.slice(0, e).concat(t).concat(this.lines.slice(e));
      for (var r = 0; r < t.length; ++r) t[r].parent = this;
    },
    iterN: function (e, t, n) {
      for (var r = e + t; e < r; ++e) if (n(this.lines[e])) return true;
    },
  };
  Us.prototype = {
    chunkSize: function () {
      return this.size;
    },
    removeInner: function (e, t) {
      this.size -= t;
      for (var n = 0; n < this.children.length; ++n) {
        var r = this.children[n],
          i = r.chunkSize();
        if (e < i) {
          var s = Math.min(t, i - e),
            o = r.height;
          r.removeInner(e, s);
          this.height -= o - r.height;
          if (i == s) {
            this.children.splice(n--, 1);
            r.parent = null;
          }
          if ((t -= s) == 0) break;
          e = 0;
        } else e -= i;
      }
      if (this.size - t < 25 && (this.children.length > 1 || !(this.children[0] instanceof Rs))) {
        var u = [];
        this.collapse(u);
        this.children = [new Rs(u)];
        this.children[0].parent = this;
      }
    },
    collapse: function (e) {
      for (var t = 0; t < this.children.length; ++t) this.children[t].collapse(e);
    },
    insertInner: function (e, t, n) {
      this.size += t.length;
      this.height += n;
      for (var r = 0; r < this.children.length; ++r) {
        var i = this.children[r],
          s = i.chunkSize();
        if (e <= s) {
          i.insertInner(e, t, n);
          if (i.lines && i.lines.length > 50) {
            while (i.lines.length > 50) {
              var o = i.lines.splice(i.lines.length - 25, 25);
              var u = new Rs(o);
              i.height -= u.height;
              this.children.splice(r + 1, 0, u);
              u.parent = this;
            }
            this.maybeSpill();
          }
          break;
        }
        e -= s;
      }
    },
    maybeSpill: function () {
      if (this.children.length <= 10) return;
      var e = this;
      do {
        var t = e.children.splice(e.children.length - 5, 5);
        var n = new Us(t);
        if (!e.parent) {
          var r = new Us(e.children);
          r.parent = e;
          e.children = [r, n];
          e = r;
        } else {
          e.size -= n.size;
          e.height -= n.height;
          var i = $o(e.parent.children, e);
          e.parent.children.splice(i + 1, 0, n);
        }
        n.parent = e.parent;
      } while (e.children.length > 10);
      e.parent.maybeSpill();
    },
    iterN: function (e, t, n) {
      for (var r = 0; r < this.children.length; ++r) {
        var i = this.children[r],
          s = i.chunkSize();
        if (e < s) {
          var o = Math.min(t, s - e);
          if (i.iterN(e, o, n)) return true;
          if ((t -= o) == 0) break;
          e = 0;
        } else e -= s;
      }
    },
  };
  var zs = 0;
  var Ws = (S.Doc = function (e, t, n) {
    if (!(this instanceof Ws)) return new Ws(e, t, n);
    if (n == null) n = 0;
    Us.call(this, [new Rs([new ys('', null)])]);
    this.first = n;
    this.scrollTop = this.scrollLeft = 0;
    this.cantEdit = false;
    this.cleanGeneration = 1;
    this.frontier = n;
    var r = vt(n, 0);
    this.sel = xt(r);
    this.history = new ro(null);
    this.id = ++zs;
    this.modeOption = t;
    if (typeof e == 'string') e = xu(e);
    qs(this, { from: r, to: r, text: e });
    Bt(this, xt(r), jo);
  });
  Ws.prototype = Ko(Us.prototype, {
    constructor: Ws,
    iter: function (e, t, n) {
      if (n) this.iterN(e - this.first, t - e, n);
      else this.iterN(this.first, this.first + this.size, e);
    },
    insert: function (e, t) {
      var n = 0;
      for (var r = 0; r < t.length; ++r) n += t[r].height;
      this.insertInner(e - this.first, t, n);
    },
    remove: function (e, t) {
      this.removeInner(e - this.first, t);
    },
    getValue: function (e) {
      var t = Gs(this, this.first, this.first + this.size);
      if (e === false) return t;
      return t.join(e || '\n');
    },
    setValue: Xn(function (e) {
      var t = vt(this.first, 0),
        n = this.first + this.size - 1;
      Gr(this, { from: t, to: vt(n, Ks(this, n).text.length), text: xu(e), origin: 'setValue' }, true);
      Bt(this, xt(t));
    }),
    replaceRange: function (e, t, n, r) {
      t = Nt(this, t);
      n = n ? Nt(this, n) : t;
      ri(this, e, t, n, r);
    },
    getRange: function (e, t, n) {
      var r = Qs(this, Nt(this, e), Nt(this, t));
      if (n === false) return r;
      return r.join(n || '\n');
    },
    getLine: function (e) {
      var t = this.getLineHandle(e);
      return t && t.text;
    },
    getLineHandle: function (e) {
      if (kt(this, e)) return Ks(this, e);
    },
    getLineNumber: function (e) {
      return Zs(e);
    },
    getLineHandleVisualStart: function (e) {
      if (typeof e == 'number') e = Ks(this, e);
      return as(e);
    },
    lineCount: function () {
      return this.size;
    },
    firstLine: function () {
      return this.first;
    },
    lastLine: function () {
      return this.first + this.size - 1;
    },
    clipPos: function (e) {
      return Nt(this, e);
    },
    getCursor: function (e) {
      var t = this.sel.primary(),
        n;
      if (e == null || e == 'head') n = t.head;
      else if (e == 'anchor') n = t.anchor;
      else if (e == 'end' || e == 'to' || e === false) n = t.to();
      else n = t.from();
      return n;
    },
    listSelections: function () {
      return this.sel.ranges;
    },
    somethingSelected: function () {
      return this.sel.somethingSelected();
    },
    setCursor: Xn(function (e, t, n) {
      Dt(this, Nt(this, typeof e == 'number' ? vt(e, t || 0) : e), null, n);
    }),
    setSelection: Xn(function (e, t, n) {
      Dt(this, Nt(this, e), Nt(this, t || e), n);
    }),
    extendSelection: Xn(function (e, t, n) {
      Ot(this, Nt(this, e), t && Nt(this, t), n);
    }),
    extendSelections: Xn(function (e, t) {
      Mt(this, Lt(this, e, t));
    }),
    extendSelectionsBy: Xn(function (e, t) {
      Mt(this, Jo(this.sel.ranges, e), t);
    }),
    setSelections: Xn(function (e, t, n) {
      if (!e.length) return;
      for (var r = 0, i = []; r < e.length; r++) i[r] = new Et(Nt(this, e[r].anchor), Nt(this, e[r].head));
      if (t == null) t = Math.min(e.length - 1, this.sel.primIndex);
      Bt(this, St(i, t), n);
    }),
    addSelection: Xn(function (e, t, n) {
      var r = this.sel.ranges.slice(0);
      r.push(new Et(Nt(this, e), Nt(this, t || e)));
      Bt(this, St(r, r.length - 1), n);
    }),
    getSelection: function (e) {
      var t = this.sel.ranges,
        n;
      for (var r = 0; r < t.length; r++) {
        var i = Qs(this, t[r].from(), t[r].to());
        n = n ? n.concat(i) : i;
      }
      if (e === false) return n;
      else return n.join(e || '\n');
    },
    getSelections: function (e) {
      var t = [],
        n = this.sel.ranges;
      for (var r = 0; r < n.length; r++) {
        var i = Qs(this, n[r].from(), n[r].to());
        if (e !== false) i = i.join(e || '\n');
        t[r] = i;
      }
      return t;
    },
    replaceSelection: function (e, t, n) {
      var r = [];
      for (var i = 0; i < this.sel.ranges.length; i++) r[i] = e;
      this.replaceSelections(r, t, n || '+input');
    },
    replaceSelections: Xn(function (e, t, n) {
      var r = [],
        i = this.sel;
      for (var s = 0; s < i.ranges.length; s++) {
        var o = i.ranges[s];
        r[s] = { from: o.from(), to: o.to(), text: xu(e[s]), origin: n };
      }
      var u = t && t != 'end' && Kr(this, r, t);
      for (var s = r.length - 1; s >= 0; s--) Gr(this, r[s]);
      if (u) Ht(this, u);
      else if (this.cm) fi(this.cm);
    }),
    undo: Xn(function () {
      Zr(this, 'undo');
    }),
    redo: Xn(function () {
      Zr(this, 'redo');
    }),
    undoSelection: Xn(function () {
      Zr(this, 'undo', true);
    }),
    redoSelection: Xn(function () {
      Zr(this, 'redo', true);
    }),
    setExtending: function (e) {
      this.extend = e;
    },
    getExtending: function () {
      return this.extend;
    },
    historySize: function () {
      var e = this.history,
        t = 0,
        n = 0;
      for (var r = 0; r < e.done.length; r++) if (!e.done[r].ranges) ++t;
      for (var r = 0; r < e.undone.length; r++) if (!e.undone[r].ranges) ++n;
      return { undo: t, redo: n };
    },
    clearHistory: function () {
      this.history = new ro(this.history.maxGeneration);
    },
    markClean: function () {
      this.cleanGeneration = this.changeGeneration(true);
    },
    changeGeneration: function (e) {
      if (e) this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;
      return this.history.generation;
    },
    isClean: function (e) {
      return this.history.generation == (e || this.cleanGeneration);
    },
    getHistory: function () {
      return { done: vo(this.history.done), undone: vo(this.history.undone) };
    },
    setHistory: function (e) {
      var t = (this.history = new ro(this.history.maxGeneration));
      t.done = vo(e.done.slice(0), null, true);
      t.undone = vo(e.undone.slice(0), null, true);
    },
    addLineClass: Xn(function (e, t, n) {
      return hi(this, e, t == 'gutter' ? 'gutter' : 'class', function (e) {
        var r = t == 'text' ? 'textClass' : t == 'background' ? 'bgClass' : t == 'gutter' ? 'gutterClass' : 'wrapClass';
        if (!e[r]) e[r] = n;
        else if (lu(n).test(e[r])) return false;
        else e[r] += ' ' + n;
        return true;
      });
    }),
    removeLineClass: Xn(function (e, t, n) {
      return hi(this, e, t == 'gutter' ? 'gutter' : 'class', function (e) {
        var r = t == 'text' ? 'textClass' : t == 'background' ? 'bgClass' : t == 'gutter' ? 'gutterClass' : 'wrapClass';
        var i = e[r];
        if (!i) return false;
        else if (n == null) e[r] = null;
        else {
          var s = i.match(lu(n));
          if (!s) return false;
          var o = s.index + s[0].length;
          e[r] = i.slice(0, s.index) + (!s.index || o == i.length ? '' : ' ') + i.slice(o) || null;
        }
        return true;
      });
    }),
    markText: function (e, t, n) {
      return ji(this, Nt(this, e), Nt(this, t), n, 'range');
    },
    setBookmark: function (e, t) {
      var n = { replacedWith: t && (t.nodeType == null ? t.widget : t), insertLeft: t && t.insertLeft, clearWhenEmpty: false, shared: t && t.shared };
      e = Nt(this, e);
      return ji(this, e, e, n, 'bookmark');
    },
    findMarksAt: function (e) {
      e = Nt(this, e);
      var t = [],
        n = Ks(this, e.line).markedSpans;
      if (n)
        for (var r = 0; r < n.length; ++r) {
          var i = n[r];
          if ((i.from == null || i.from <= e.ch) && (i.to == null || i.to >= e.ch)) t.push(i.marker.parent || i.marker);
        }
      return t;
    },
    findMarks: function (e, t, n) {
      e = Nt(this, e);
      t = Nt(this, t);
      var r = [],
        i = e.line;
      this.iter(e.line, t.line + 1, function (s) {
        var o = s.markedSpans;
        if (o)
          for (var u = 0; u < o.length; u++) {
            var a = o[u];
            if (!((i == e.line && e.ch > a.to) || (a.from == null && i != e.line) || (i == t.line && a.from > t.ch)) && (!n || n(a.marker))) r.push(a.marker.parent || a.marker);
          }
        ++i;
      });
      return r;
    },
    getAllMarks: function () {
      var e = [];
      this.iter(function (t) {
        var n = t.markedSpans;
        if (n) for (var r = 0; r < n.length; ++r) if (n[r].from != null) e.push(n[r].marker);
      });
      return e;
    },
    posFromIndex: function (e) {
      var t,
        n = this.first;
      this.iter(function (r) {
        var i = r.text.length + 1;
        if (i > e) {
          t = e;
          return true;
        }
        e -= i;
        ++n;
      });
      return Nt(this, vt(n, t));
    },
    indexFromPos: function (e) {
      e = Nt(this, e);
      var t = e.ch;
      if (e.line < this.first || e.ch < 0) return 0;
      this.iter(this.first, e.line, function (e) {
        t += e.text.length + 1;
      });
      return t;
    },
    copy: function (e) {
      var t = new Ws(Gs(this, this.first, this.first + this.size), this.modeOption, this.first);
      t.scrollTop = this.scrollTop;
      t.scrollLeft = this.scrollLeft;
      t.sel = this.sel;
      t.extend = false;
      if (e) {
        t.history.undoDepth = this.history.undoDepth;
        t.setHistory(this.getHistory());
      }
      return t;
    },
    linkedDoc: function (e) {
      if (!e) e = {};
      var t = this.first,
        n = this.first + this.size;
      if (e.from != null && e.from > t) t = e.from;
      if (e.to != null && e.to < n) n = e.to;
      var r = new Ws(Gs(this, t, n), e.mode || this.modeOption, t);
      if (e.sharedHist) r.history = this.history;
      (this.linked || (this.linked = [])).push({ doc: r, sharedHist: e.sharedHist });
      r.linked = [{ doc: this, isParent: true, sharedHist: e.sharedHist }];
      Ri(r, qi(this));
      return r;
    },
    unlinkDoc: function (e) {
      if (e instanceof S) e = e.doc;
      if (this.linked)
        for (var t = 0; t < this.linked.length; ++t) {
          var n = this.linked[t];
          if (n.doc != e) continue;
          this.linked.splice(t, 1);
          e.unlinkDoc(this);
          Ui(qi(this));
          break;
        }
      if (e.history == this.history) {
        var r = [e.id];
        $s(
          e,
          function (e) {
            r.push(e.id);
          },
          true
        );
        e.history = new ro(null);
        e.history.done = vo(this.history.done, r);
        e.history.undone = vo(this.history.undone, r);
      }
    },
    iterLinkedDocs: function (e) {
      $s(this, e);
    },
    getMode: function () {
      return this.mode;
    },
    getEditor: function () {
      return this.cm;
    },
  });
  Ws.prototype.eachLine = Ws.prototype.iter;
  var Xs = 'iter insert remove copy getEditor'.split(' ');
  for (var Vs in Ws.prototype)
    if (Ws.prototype.hasOwnProperty(Vs) && $o(Xs, Vs) < 0)
      S.prototype[Vs] = (function (e) {
        return function () {
          return e.apply(this.doc, arguments);
        };
      })(Ws.prototype[Vs]);
  Po(Ws);
  var bo = (S.e_preventDefault = function (e) {
    if (e.preventDefault) e.preventDefault();
    else e.returnValue = false;
  });
  var wo = (S.e_stopPropagation = function (e) {
    if (e.stopPropagation) e.stopPropagation();
    else e.cancelBubble = true;
  });
  var So = (S.e_stop = function (e) {
    bo(e);
    wo(e);
  });
  var No = (S.on = function (e, t, n) {
    if (e.addEventListener) e.addEventListener(t, n, false);
    else if (e.attachEvent) e.attachEvent('on' + t, n);
    else {
      var r = e._handlers || (e._handlers = {});
      var i = r[t] || (r[t] = []);
      i.push(n);
    }
  });
  var Co = (S.off = function (e, t, n) {
    if (e.removeEventListener) e.removeEventListener(t, n, false);
    else if (e.detachEvent) e.detachEvent('on' + t, n);
    else {
      var r = e._handlers && e._handlers[t];
      if (!r) return;
      for (var i = 0; i < r.length; ++i)
        if (r[i] == n) {
          r.splice(i, 1);
          break;
        }
    }
  });
  var ko = (S.signal = function (e, t) {
    var n = e._handlers && e._handlers[t];
    if (!n) return;
    var r = Array.prototype.slice.call(arguments, 2);
    for (var i = 0; i < n.length; ++i) n[i].apply(null, r);
  });
  var Lo = null;
  var Ho = 30;
  var Bo = (S.Pass = {
    toString: function () {
      return 'CodeMirror.Pass';
    },
  });
  var jo = { scroll: false },
    Fo = { origin: '*mouse' },
    Io = { origin: '+move' };
  qo.prototype.set = function (e, t) {
    clearTimeout(this.id);
    this.id = setTimeout(t, e);
  };
  var Ro = (S.countColumn = function (e, t, n, r, i) {
    if (t == null) {
      t = e.search(/[^\s\u00a0]/);
      if (t == -1) t = e.length;
    }
    for (var s = r || 0, o = i || 0; ; ) {
      var u = e.indexOf('	', s);
      if (u < 0 || u >= t) return o + (t - s);
      o += u - s;
      o += n - (o % n);
      s = u + 1;
    }
  });
  var zo = [''];
  var Vo = function (e) {
    e.select();
  };
  if (p)
    Vo = function (e) {
      e.selectionStart = 0;
      e.selectionEnd = e.value.length;
    };
  else if (r)
    Vo = function (e) {
      try {
        e.select();
      } catch (t) {}
    };
  if ([].indexOf)
    $o = function (e, t) {
      return e.indexOf(t);
    };
  if ([].map)
    Jo = function (e, t) {
      return e.map(t);
    };
  var Yo = /[\u00df\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
  var Zo = (S.isWordChar = function (e) {
    return /\w/.test(e) || (e > '' && (e.toUpperCase() != e.toLowerCase() || Yo.test(e)));
  });
  var nu =
    /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
  var su;
  if (document.createRange)
    su = function (e, t, n) {
      var r = document.createRange();
      r.setEnd(e, n);
      r.setStart(e, t);
      return r;
    };
  else
    su = function (e, t, n) {
      var r = document.body.createTextRange();
      try {
        r.moveToElementText(e.parentNode);
      } catch (i) {
        return r;
      }
      r.collapse(true);
      r.moveEnd('character', n);
      r.moveStart('character', t);
      return r;
    };
  if (r && i < 11)
    fu = function () {
      try {
        return document.activeElement;
      } catch (e) {
        return document.body;
      }
    };
  var cu = (S.rmClass = function (e, t) {
    var n = e.className;
    var r = lu(t).exec(n);
    if (r) {
      var i = n.slice(r.index + r[0].length);
      e.className = n.slice(0, r.index) + (i ? r[1] + i : '');
    }
  });
  var hu = (S.addClass = function (e, t) {
    var n = e.className;
    if (!lu(t).test(n)) e.className += (n ? ' ' : '') + t;
  });
  var vu = false;
  var yu = (function () {
    if (r && i < 9) return false;
    var e = iu('div');
    return 'draggable' in e || 'dragDrop' in e;
  })();
  var bu;
  var Eu;
  var xu = (S.splitLines =
    '\n\nb'.split(/\n/).length != 3
      ? function (e) {
          var t = 0,
            n = [],
            r = e.length;
          while (t <= r) {
            var i = e.indexOf('\n', t);
            if (i == -1) i = e.length;
            var s = e.slice(t, e.charAt(i - 1) == '\r' ? i - 1 : i);
            var o = s.indexOf('\r');
            if (o != -1) {
              n.push(s.slice(0, o));
              t += o + 1;
            } else {
              n.push(s);
              t = i + 1;
            }
          }
          return n;
        }
      : function (e) {
          return e.split(/\r\n?|\n/);
        });
  var Tu = window.getSelection
    ? function (e) {
        try {
          return e.selectionStart != e.selectionEnd;
        } catch (t) {
          return false;
        }
      }
    : function (e) {
        try {
          var t = e.ownerDocument.selection.createRange();
        } catch (n) {}
        if (!t || t.parentElement() != e) return false;
        return t.compareEndPoints('StartToEnd', t) != 0;
      };
  var Nu = (function () {
    var e = iu('div');
    if ('oncopy' in e) return true;
    e.setAttribute('oncopy', 'return;');
    return typeof e.oncopy == 'function';
  })();
  var Cu = null;
  var Lu = {
    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: ';',
    61: '=',
    91: 'Mod',
    92: 'Mod',
    93: 'Mod',
    107: '=',
    109: '-',
    127: 'Delete',
    173: '-',
    186: ';',
    187: '=',
    188: ',',
    189: '-',
    190: '.',
    191: '/',
    192: '`',
    219: '[',
    220: '\\',
    221: ']',
    222: "'",
    63232: 'Up',
    63233: 'Down',
    63234: 'Left',
    63235: 'Right',
    63272: 'Delete',
    63273: 'Home',
    63275: 'End',
    63276: 'PageUp',
    63277: 'PageDown',
    63302: 'Insert',
  };
  S.keyNames = Lu;
  (function () {
    for (var e = 0; e < 10; e++) Lu[e + 48] = Lu[e + 96] = String(e);
    for (var e = 65; e <= 90; e++) Lu[e] = String.fromCharCode(e);
    for (var e = 1; e <= 12; e++) Lu[e + 111] = Lu[e + 63235] = 'F' + e;
  })();
  var Fu;
  var zu = (function () {
    function n(n) {
      if (n <= 247) return e.charAt(n);
      else if (1424 <= n && n <= 1524) return 'R';
      else if (1536 <= n && n <= 1773) return t.charAt(n - 1536);
      else if (1774 <= n && n <= 2220) return 'r';
      else if (8192 <= n && n <= 8203) return 'w';
      else if (n == 8204) return 'b';
      else return 'L';
    }
    function f(e, t, n) {
      this.level = e;
      this.from = t;
      this.to = n;
    }
    var e = 'bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN';
    var t = 'rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm';
    var r = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
    var i = /[stwN]/,
      s = /[LRr]/,
      o = /[Lb1n]/,
      u = /[1n]/;
    var a = 'L';
    return function (e) {
      if (!r.test(e)) return false;
      var t = e.length,
        l = [];
      for (var c = 0, h; c < t; ++c) l.push((h = n(e.charCodeAt(c))));
      for (var c = 0, p = a; c < t; ++c) {
        var h = l[c];
        if (h == 'm') l[c] = p;
        else p = h;
      }
      for (var c = 0, d = a; c < t; ++c) {
        var h = l[c];
        if (h == '1' && d == 'r') l[c] = 'n';
        else if (s.test(h)) {
          d = h;
          if (h == 'r') l[c] = 'R';
        }
      }
      for (var c = 1, p = l[0]; c < t - 1; ++c) {
        var h = l[c];
        if (h == '+' && p == '1' && l[c + 1] == '1') l[c] = '1';
        else if (h == ',' && p == l[c + 1] && (p == '1' || p == 'n')) l[c] = p;
        p = h;
      }
      for (var c = 0; c < t; ++c) {
        var h = l[c];
        if (h == ',') l[c] = 'N';
        else if (h == '%') {
          for (var v = c + 1; v < t && l[v] == '%'; ++v) {}
          var m = (c && l[c - 1] == '!') || (v < t && l[v] == '1') ? '1' : 'N';
          for (var g = c; g < v; ++g) l[g] = m;
          c = v - 1;
        }
      }
      for (var c = 0, d = a; c < t; ++c) {
        var h = l[c];
        if (d == 'L' && h == '1') l[c] = 'L';
        else if (s.test(h)) d = h;
      }
      for (var c = 0; c < t; ++c) {
        if (i.test(l[c])) {
          for (var v = c + 1; v < t && i.test(l[v]); ++v) {}
          var y = (c ? l[c - 1] : a) == 'L';
          var b = (v < t ? l[v] : a) == 'L';
          var m = y || b ? 'L' : 'R';
          for (var g = c; g < v; ++g) l[g] = m;
          c = v - 1;
        }
      }
      var w = [],
        E;
      for (var c = 0; c < t; ) {
        if (o.test(l[c])) {
          var S = c;
          for (++c; c < t && o.test(l[c]); ++c) {}
          w.push(new f(0, S, c));
        } else {
          var x = c,
            T = w.length;
          for (++c; c < t && l[c] != 'L'; ++c) {}
          for (var g = x; g < c; ) {
            if (u.test(l[g])) {
              if (x < g) w.splice(T, 0, new f(1, x, g));
              var N = g;
              for (++g; g < c && u.test(l[g]); ++g) {}
              w.splice(T, 0, new f(2, N, g));
              x = g;
            } else ++g;
          }
          if (x < c) w.splice(T, 0, new f(1, x, c));
        }
      }
      if (w[0].level == 1 && (E = e.match(/^\s+/))) {
        w[0].from = E[0].length;
        w.unshift(new f(0, 0, E[0].length));
      }
      if (Xo(w).level == 1 && (E = e.match(/\s+$/))) {
        Xo(w).to -= E[0].length;
        w.push(new f(0, t - E[0].length, t));
      }
      if (w[0].level != Xo(w).level) w.push(new f(w[0].level, t, t));
      return w;
    };
  })();
  S.version = '4.10.0';
  return S;
});
