MailChimp for WordPress - Version 4.1.1

Version Description

Download this release

Release Info

Developer DvanKooten
Plugin Icon 128x128 MailChimp for WordPress
Version 4.1.1
Comparing to
See all releases

Code changes from version 4.1.0 to 4.1.1

CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
  Changelog
2
  =========
3
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  #### 4.1.0 - March 14, 2017
5
 
6
  **Improvements**
1
  Changelog
2
  =========
3
 
4
+ #### 4.1.1 - April 11, 2017
5
+
6
+ **Fixes**
7
+
8
+ - WPML String Translation not working with the checkbox label for sign-up integrations.
9
+
10
+ **Improvements**
11
+
12
+ - Use updated order methods when using WooCommerce 3.0, thanks to Liam McArthur.
13
+ - Updated JavaScript dependencies.
14
+
15
+
16
  #### 4.1.0 - March 14, 2017
17
 
18
  **Improvements**
assets/js/admin.js CHANGED
@@ -462,10 +462,10 @@ module.exports = URL;
462
 
463
  },{}],7:[function(require,module,exports){
464
  (function (global){
465
- new function() {
466
-
467
  function Vnode(tag, key, attrs0, children, text, dom) {
468
- return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false}
469
  }
470
  Vnode.normalize = function(node) {
471
  if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
@@ -480,62 +480,82 @@ Vnode.normalizeChildren = function normalizeChildren(children) {
480
  }
481
  var selectorParser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g
482
  var selectorCache = {}
483
- function hyperscript(selector) {
484
- if (selector == null || typeof selector !== "string" && typeof selector.view !== "function") {
485
- throw Error("The selector must be either a string or a component.");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
  }
487
- if (typeof selector === "string" && selectorCache[selector] === undefined) {
488
- var match, tag, classes = [], attributes = {}
489
- while (match = selectorParser.exec(selector)) {
490
- var type = match[1], value = match[2]
491
- if (type === "" && value !== "") tag = value
492
- else if (type === "#") attributes.id = value
493
- else if (type === ".") classes.push(value)
494
- else if (match[3][0] === "[") {
495
- var attrValue = match[6]
496
- if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\")
497
- if (match[4] === "class") classes.push(attrValue)
498
- else attributes[match[4]] = attrValue || true
499
- }
500
  }
501
- if (classes.length > 0) attributes.className = classes.join(" ")
502
- selectorCache[selector] = function(attrs, children) {
503
- var hasAttrs = false, childList, text
504
- var className = attrs.className || attrs.class
505
- for (var key in attributes) attrs[key] = attributes[key]
506
- if (className !== undefined) {
507
- if (attrs.class !== undefined) {
508
- attrs.class = undefined
509
- attrs.className = className
510
- }
511
- if (attributes.className !== undefined) attrs.className = attributes.className + " " + className
512
- }
513
- for (var key in attrs) {
514
- if (key !== "key") {
515
- hasAttrs = true
516
- break
517
- }
518
- }
519
- if (Array.isArray(children) && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children
520
- else childList = children
521
- return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)
522
  }
523
  }
524
- var attrs, children, childrenIndex
525
- if (arguments[1] == null || typeof arguments[1] === "object" && arguments[1].tag === undefined && !Array.isArray(arguments[1])) {
526
- attrs = arguments[1]
527
- childrenIndex = 2
 
 
 
 
 
 
 
 
 
 
 
528
  }
529
- else childrenIndex = 1
530
- if (arguments.length === childrenIndex + 1) {
531
- children = Array.isArray(arguments[childrenIndex]) ? arguments[childrenIndex] : [arguments[childrenIndex]]
 
 
532
  }
533
- else {
 
 
 
534
  children = []
535
- for (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i])
 
 
 
 
 
 
536
  }
537
- if (typeof selector === "string") return selectorCache[selector](attrs || {}, Vnode.normalizeChildren(children))
538
- return Vnode(selector, attrs && attrs.key, attrs || {}, Vnode.normalizeChildren(children), undefined, undefined)
539
  }
540
  hyperscript.trust = function(html) {
541
  if (html == null) html = ""
@@ -667,6 +687,7 @@ var buildQueryString = function(object) {
667
  else args.push(encodeURIComponent(key0) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""))
668
  }
669
  }
 
670
  var _8 = function($window, Promise) {
671
  var callbackCount = 0
672
  var oncompletion
@@ -702,14 +723,20 @@ var _8 = function($window, Promise) {
702
  var promise0 = new Promise(function(resolve, reject) {
703
  if (args.method == null) args.method = "GET"
704
  args.method = args.method.toUpperCase()
705
- var useBody = typeof args.useBody === "boolean" ? args.useBody : args.method !== "GET" && args.method !== "TRACE"
706
  if (typeof args.serialize !== "function") args.serialize = typeof FormData !== "undefined" && args.data instanceof FormData ? function(value) {return value} : JSON.stringify
707
  if (typeof args.deserialize !== "function") args.deserialize = deserialize
708
  if (typeof args.extract !== "function") args.extract = extract
709
  args.url = interpolate(args.url, args.data)
710
  if (useBody) args.data = args.serialize(args.data)
711
  else args.url = assemble(args.url, args.data)
712
- var xhr = new $window.XMLHttpRequest()
 
 
 
 
 
 
713
  xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined)
714
  if (args.serialize === JSON.stringify && useBody) {
715
  xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8")
@@ -723,12 +750,12 @@ var _8 = function($window, Promise) {
723
  }
724
  if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
725
  xhr.onreadystatechange = function() {
726
- // Don't throw errors on xhr.abort(). XMLHttpRequests ends up in a state of
727
- // xhr.status == 0 and xhr.readyState == 4 if aborted after open, but before completion.
728
- if (xhr.status && xhr.readyState === 4) {
729
  try {
730
  var response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args))
731
- if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
732
  resolve(cast(args.type, response))
733
  }
734
  else {
@@ -825,8 +852,9 @@ var coreRenderer = function($window) {
825
  }
826
  function createNode(parent, vnode, hooks, ns, nextSibling) {
827
  var tag = vnode.tag
828
- if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)
829
  if (typeof tag === "string") {
 
 
830
  switch (tag) {
831
  case "#": return createText(parent, vnode, nextSibling)
832
  case "<": return createHTML(parent, vnode, nextSibling)
@@ -899,16 +927,30 @@ var coreRenderer = function($window) {
899
  }
900
  return element
901
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
902
  function createComponent(parent, vnode, hooks, ns, nextSibling) {
903
- vnode.state = Object.create(vnode.tag)
904
- var view = vnode.tag.view
905
- if (view.reentrantLock != null) return $emptyFragment
906
- view.reentrantLock = true
907
- initLifecycle(vnode.tag, vnode, hooks)
908
- vnode.instance = Vnode.normalize(view.call(vnode.state, vnode))
909
- view.reentrantLock = null
910
  if (vnode.instance != null) {
911
- if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as arguments")
912
  var element = createNode(parent, vnode.instance, hooks, ns, nextSibling)
913
  vnode.dom = vnode.instance.dom
914
  vnode.domSize = vnode.dom != null ? vnode.instance.domSize : 0
@@ -939,14 +981,16 @@ var coreRenderer = function($window) {
939
  if (old[i] === vnodes[i]) continue
940
  else if (old[i] == null && vnodes[i] != null) createNode(parent, vnodes[i], hooks, ns, getNextSibling(old, i + 1, nextSibling))
941
  else if (vnodes[i] == null) removeNodes(old, i, i + 1, vnodes)
942
- else updateNode(parent, old[i], vnodes[i], hooks, getNextSibling(old, i + 1, nextSibling), false, ns)
943
  }
944
  return
945
  }
946
  }
947
  recycling = recycling || isRecyclable(old, vnodes)
948
- if (recycling) old = old.concat(old.pool)
949
-
 
 
950
  var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
951
  while (oldEnd >= oldStart && end >= start) {
952
  var o = old[oldStart], v = vnodes[start]
@@ -954,8 +998,9 @@ var coreRenderer = function($window) {
954
  else if (o == null) oldStart++
955
  else if (v == null) start++
956
  else if (o.key === v.key) {
 
957
  oldStart++, start++
958
- updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)
959
  if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
960
  }
961
  else {
@@ -964,7 +1009,8 @@ var coreRenderer = function($window) {
964
  else if (o == null) oldEnd--
965
  else if (v == null) start++
966
  else if (o.key === v.key) {
967
- updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
 
968
  if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
969
  oldEnd--, start++
970
  }
@@ -977,7 +1023,8 @@ var coreRenderer = function($window) {
977
  else if (o == null) oldEnd--
978
  else if (v == null) end--
979
  else if (o.key === v.key) {
980
- updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
 
981
  if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
982
  if (o.dom != null) nextSibling = o.dom
983
  oldEnd--, end--
@@ -988,6 +1035,7 @@ var coreRenderer = function($window) {
988
  var oldIndex = map[v.key]
989
  if (oldIndex != null) {
990
  var movable = old[oldIndex]
 
991
  updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
992
  insertNode(parent, toFragment(movable), nextSibling)
993
  old[oldIndex].skip = true
@@ -1010,12 +1058,17 @@ var coreRenderer = function($window) {
1010
  var oldTag = old.tag, tag = vnode.tag
1011
  if (oldTag === tag) {
1012
  vnode.state = old.state
 
1013
  vnode.events = old.events
1014
- if (shouldUpdate(vnode, old)) return
1015
- if (vnode.attrs != null) {
1016
- updateLifecycle(vnode.attrs, vnode, hooks, recycling)
1017
- }
1018
  if (typeof oldTag === "string") {
 
 
 
 
 
 
 
1019
  switch (oldTag) {
1020
  case "#": updateText(old, vnode); break
1021
  case "<": updateHTML(parent, old, vnode, nextSibling); break
@@ -1085,8 +1138,14 @@ var coreRenderer = function($window) {
1085
  }
1086
  }
1087
  function updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) {
1088
- vnode.instance = Vnode.normalize(vnode.tag.view.call(vnode.state, vnode))
1089
- updateLifecycle(vnode.tag, vnode, hooks, recycling)
 
 
 
 
 
 
1090
  if (vnode.instance != null) {
1091
  if (old.instance == null) createNode(parent, vnode.instance, hooks, ns, nextSibling)
1092
  else updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling, ns)
@@ -1168,15 +1227,15 @@ var coreRenderer = function($window) {
1168
  }
1169
  function removeNode(vnode, context) {
1170
  var expected = 1, called = 0
1171
- if (vnode.attrs && vnode.attrs.onbeforeremove) {
1172
  var result = vnode.attrs.onbeforeremove.call(vnode.state, vnode)
1173
  if (result != null && typeof result.then === "function") {
1174
  expected++
1175
  result.then(continuation, continuation)
1176
  }
1177
  }
1178
- if (typeof vnode.tag !== "string" && vnode.tag.onbeforeremove) {
1179
- var result = vnode.tag.onbeforeremove.call(vnode.state, vnode)
1180
  if (result != null && typeof result.then === "function") {
1181
  expected++
1182
  result.then(continuation, continuation)
@@ -1208,8 +1267,8 @@ var coreRenderer = function($window) {
1208
  if (parent != null) parent.removeChild(node)
1209
  }
1210
  function onremove(vnode) {
1211
- if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)
1212
- if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)
1213
  if (vnode.instance != null) onremove(vnode.instance)
1214
  else {
1215
  var children = vnode.children
@@ -1238,11 +1297,16 @@ var coreRenderer = function($window) {
1238
  else if (key2 === "style") updateStyle(element, old, value)
1239
  else if (key2 in element && !isAttribute(key2) && ns === undefined && !isCustomElement(vnode)) {
1240
  //setting input[value] to same value by typing on focused element moves cursor to end in Chrome
1241
- if (vnode.tag === "input" && key2 === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return
1242
  //setting select[value] to same value while having select open blinks select dropdown in Chrome
1243
- if (vnode.tag === "select" && key2 === "value" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return
1244
  //setting option[value] to same value while having select open blinks select dropdown in Chrome
1245
- if (vnode.tag === "option" && key2 === "value" && vnode.dom.value === value) return
 
 
 
 
 
1246
  element[key2] = value
1247
  }
1248
  else {
@@ -1333,14 +1397,13 @@ var coreRenderer = function($window) {
1333
  if (typeof source.oninit === "function") source.oninit.call(vnode.state, vnode)
1334
  if (typeof source.oncreate === "function") hooks.push(source.oncreate.bind(vnode.state, vnode))
1335
  }
1336
- function updateLifecycle(source, vnode, hooks, recycling) {
1337
- if (recycling) initLifecycle(source, vnode, hooks)
1338
- else if (typeof source.onupdate === "function") hooks.push(source.onupdate.bind(vnode.state, vnode))
1339
  }
1340
- function shouldUpdate(vnode, old) {
1341
  var forceVnodeUpdate, forceComponentUpdate
1342
  if (vnode.attrs != null && typeof vnode.attrs.onbeforeupdate === "function") forceVnodeUpdate = vnode.attrs.onbeforeupdate.call(vnode.state, vnode, old)
1343
- if (typeof vnode.tag !== "string" && typeof vnode.tag.onbeforeupdate === "function") forceComponentUpdate = vnode.tag.onbeforeupdate.call(vnode.state, vnode, old)
1344
  if (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {
1345
  vnode.dom = old.dom
1346
  vnode.domSize = old.domSize
@@ -1397,11 +1460,11 @@ var _11 = function($window) {
1397
  var index = callbacks.indexOf(key1)
1398
  if (index > -1) callbacks.splice(index, 2)
1399
  }
1400
- function redraw() {
1401
- for (var i = 1; i < callbacks.length; i += 2) {
1402
- callbacks[i]()
1403
- }
1404
- }
1405
  return {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render}
1406
  }
1407
  var redrawService = _11(window)
@@ -1414,7 +1477,7 @@ var _16 = function(redrawService0) {
1414
  return
1415
  }
1416
 
1417
- if (component.view == null) throw new Error("m.mount(element, component) expects a component, not a vnode")
1418
 
1419
  var run0 = function() {
1420
  redrawService0.render(root, Vnode(component))
@@ -1567,11 +1630,12 @@ var _20 = function($window, redrawService0) {
1567
  routeService.defineRoutes(routes, function(payload, params, path) {
1568
  var update = lastUpdate = function(routeResolver, comp) {
1569
  if (update !== lastUpdate) return
1570
- component = comp != null && typeof comp.view === "function" ? comp : "div", attrs3 = params, currentPath = path, lastUpdate = null
 
1571
  render1 = (routeResolver.render || identity).bind(routeResolver)
1572
  run1()
1573
  }
1574
- if (payload.view) update({}, payload)
1575
  else {
1576
  if (payload.onmatch) {
1577
  Promise.resolve(payload.onmatch(params, path)).then(function(resolved) {
@@ -1620,11 +1684,11 @@ m.request = requestService.request
1620
  m.jsonp = requestService.jsonp
1621
  m.parseQueryString = parseQueryString
1622
  m.buildQueryString = buildQueryString
1623
- m.version = "1.0.1"
1624
  m.vnode = Vnode
1625
  if (typeof module !== "undefined") module["exports"] = m
1626
  else window.m = m
1627
- }
1628
  }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1629
  },{}],8:[function(require,module,exports){
1630
  /*!
462
 
463
  },{}],7:[function(require,module,exports){
464
  (function (global){
465
+ ;(function() {
466
+ "use strict"
467
  function Vnode(tag, key, attrs0, children, text, dom) {
468
+ return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: undefined, _state: undefined, events: undefined, instance: undefined, skip: false}
469
  }
470
  Vnode.normalize = function(node) {
471
  if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
480
  }
481
  var selectorParser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g
482
  var selectorCache = {}
483
+ var hasOwn = {}.hasOwnProperty
484
+ function compileSelector(selector) {
485
+ var match, tag = "div", classes = [], attrs = {}
486
+ while (match = selectorParser.exec(selector)) {
487
+ var type = match[1], value = match[2]
488
+ if (type === "" && value !== "") tag = value
489
+ else if (type === "#") attrs.id = value
490
+ else if (type === ".") classes.push(value)
491
+ else if (match[3][0] === "[") {
492
+ var attrValue = match[6]
493
+ if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\")
494
+ if (match[4] === "class") classes.push(attrValue)
495
+ else attrs[match[4]] = attrValue || true
496
+ }
497
+ }
498
+ if (classes.length > 0) attrs.className = classes.join(" ")
499
+ return selectorCache[selector] = {tag: tag, attrs: attrs}
500
+ }
501
+ function execSelector(state, attrs, children) {
502
+ var hasAttrs = false, childList, text
503
+ var className = attrs.className || attrs.class
504
+ for (var key in state.attrs) {
505
+ if (hasOwn.call(state.attrs, key)) {
506
+ attrs[key] = state.attrs[key]
507
+ }
508
  }
509
+ if (className !== undefined) {
510
+ if (attrs.class !== undefined) {
511
+ attrs.class = undefined
512
+ attrs.className = className
 
 
 
 
 
 
 
 
 
513
  }
514
+ if (state.attrs.className != null) {
515
+ attrs.className = state.attrs.className + " " + className
516
+ }
517
+ }
518
+ for (var key in attrs) {
519
+ if (hasOwn.call(attrs, key) && key !== "key") {
520
+ hasAttrs = true
521
+ break
 
 
 
 
 
 
 
 
 
 
 
 
 
522
  }
523
  }
524
+ if (Array.isArray(children) && children.length === 1 && children[0] != null && children[0].tag === "#") {
525
+ text = children[0].children
526
+ } else {
527
+ childList = children
528
+ }
529
+ return Vnode(state.tag, attrs.key, hasAttrs ? attrs : undefined, childList, text)
530
+ }
531
+ function hyperscript(selector) {
532
+ // Because sloppy mode sucks
533
+ var attrs = arguments[1], start = 2, children
534
+ if (selector == null || typeof selector !== "string" && typeof selector !== "function" && typeof selector.view !== "function") {
535
+ throw Error("The selector must be either a string or a component.");
536
+ }
537
+ if (typeof selector === "string") {
538
+ var cached = selectorCache[selector] || compileSelector(selector)
539
  }
540
+ if (attrs == null) {
541
+ attrs = {}
542
+ } else if (typeof attrs !== "object" || attrs.tag != null || Array.isArray(attrs)) {
543
+ attrs = {}
544
+ start = 1
545
  }
546
+ if (arguments.length === start + 1) {
547
+ children = arguments[start]
548
+ if (!Array.isArray(children)) children = [children]
549
+ } else {
550
  children = []
551
+ while (start < arguments.length) children.push(arguments[start++])
552
+ }
553
+ var normalized = Vnode.normalizeChildren(children)
554
+ if (typeof selector === "string") {
555
+ return execSelector(cached, attrs, normalized)
556
+ } else {
557
+ return Vnode(selector, attrs.key, attrs, normalized)
558
  }
 
 
559
  }
560
  hyperscript.trust = function(html) {
561
  if (html == null) html = ""
687
  else args.push(encodeURIComponent(key0) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : ""))
688
  }
689
  }
690
+ var FILE_PROTOCOL_REGEX = new RegExp("^file://", "i")
691
  var _8 = function($window, Promise) {
692
  var callbackCount = 0
693
  var oncompletion
723
  var promise0 = new Promise(function(resolve, reject) {
724
  if (args.method == null) args.method = "GET"
725
  args.method = args.method.toUpperCase()
726
+ var useBody = (args.method === "GET" || args.method === "TRACE") ? false : (typeof args.useBody === "boolean" ? args.useBody : true)
727
  if (typeof args.serialize !== "function") args.serialize = typeof FormData !== "undefined" && args.data instanceof FormData ? function(value) {return value} : JSON.stringify
728
  if (typeof args.deserialize !== "function") args.deserialize = deserialize
729
  if (typeof args.extract !== "function") args.extract = extract
730
  args.url = interpolate(args.url, args.data)
731
  if (useBody) args.data = args.serialize(args.data)
732
  else args.url = assemble(args.url, args.data)
733
+ var xhr = new $window.XMLHttpRequest(),
734
+ aborted = false,
735
+ _abort = xhr.abort
736
+ xhr.abort = function abort() {
737
+ aborted = true
738
+ _abort.call(xhr)
739
+ }
740
  xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined)
741
  if (args.serialize === JSON.stringify && useBody) {
742
  xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8")
750
  }
751
  if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
752
  xhr.onreadystatechange = function() {
753
+ // Don't throw errors on xhr.abort().
754
+ if(aborted) return
755
+ if (xhr.readyState === 4) {
756
  try {
757
  var response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args))
758
+ if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || FILE_PROTOCOL_REGEX.test(args.url)) {
759
  resolve(cast(args.type, response))
760
  }
761
  else {
852
  }
853
  function createNode(parent, vnode, hooks, ns, nextSibling) {
854
  var tag = vnode.tag
 
855
  if (typeof tag === "string") {
856
+ vnode.state = {}
857
+ if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)
858
  switch (tag) {
859
  case "#": return createText(parent, vnode, nextSibling)
860
  case "<": return createHTML(parent, vnode, nextSibling)
927
  }
928
  return element
929
  }
930
+ function initComponent(vnode, hooks) {
931
+ var sentinel
932
+ if (typeof vnode.tag.view === "function") {
933
+ vnode.state = Object.create(vnode.tag)
934
+ sentinel = vnode.state.view
935
+ if (sentinel.$$reentrantLock$$ != null) return $emptyFragment
936
+ sentinel.$$reentrantLock$$ = true
937
+ } else {
938
+ vnode.state = void 0
939
+ sentinel = vnode.tag
940
+ if (sentinel.$$reentrantLock$$ != null) return $emptyFragment
941
+ sentinel.$$reentrantLock$$ = true
942
+ vnode.state = (vnode.tag.prototype != null && typeof vnode.tag.prototype.view === "function") ? new vnode.tag(vnode) : vnode.tag(vnode)
943
+ }
944
+ vnode._state = vnode.state
945
+ if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)
946
+ initLifecycle(vnode._state, vnode, hooks)
947
+ vnode.instance = Vnode.normalize(vnode._state.view.call(vnode.state, vnode))
948
+ if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as argument")
949
+ sentinel.$$reentrantLock$$ = null
950
+ }
951
  function createComponent(parent, vnode, hooks, ns, nextSibling) {
952
+ initComponent(vnode, hooks)
 
 
 
 
 
 
953
  if (vnode.instance != null) {
 
954
  var element = createNode(parent, vnode.instance, hooks, ns, nextSibling)
955
  vnode.dom = vnode.instance.dom
956
  vnode.domSize = vnode.dom != null ? vnode.instance.domSize : 0
981
  if (old[i] === vnodes[i]) continue
982
  else if (old[i] == null && vnodes[i] != null) createNode(parent, vnodes[i], hooks, ns, getNextSibling(old, i + 1, nextSibling))
983
  else if (vnodes[i] == null) removeNodes(old, i, i + 1, vnodes)
984
+ else updateNode(parent, old[i], vnodes[i], hooks, getNextSibling(old, i + 1, nextSibling), recycling, ns)
985
  }
986
  return
987
  }
988
  }
989
  recycling = recycling || isRecyclable(old, vnodes)
990
+ if (recycling) {
991
+ var pool = old.pool
992
+ old = old.concat(old.pool)
993
+ }
994
  var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
995
  while (oldEnd >= oldStart && end >= start) {
996
  var o = old[oldStart], v = vnodes[start]
998
  else if (o == null) oldStart++
999
  else if (v == null) start++
1000
  else if (o.key === v.key) {
1001
+ var shouldRecycle = (pool != null && oldStart >= old.length - pool.length) || ((pool == null) && recycling)
1002
  oldStart++, start++
1003
+ updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), shouldRecycle, ns)
1004
  if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
1005
  }
1006
  else {
1009
  else if (o == null) oldEnd--
1010
  else if (v == null) start++
1011
  else if (o.key === v.key) {
1012
+ var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
1013
+ updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
1014
  if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
1015
  oldEnd--, start++
1016
  }
1023
  else if (o == null) oldEnd--
1024
  else if (v == null) end--
1025
  else if (o.key === v.key) {
1026
+ var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
1027
+ updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
1028
  if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
1029
  if (o.dom != null) nextSibling = o.dom
1030
  oldEnd--, end--
1035
  var oldIndex = map[v.key]
1036
  if (oldIndex != null) {
1037
  var movable = old[oldIndex]
1038
+ var shouldRecycle = (pool != null && oldIndex >= old.length - pool.length) || ((pool == null) && recycling)
1039
  updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)
1040
  insertNode(parent, toFragment(movable), nextSibling)
1041
  old[oldIndex].skip = true
1058
  var oldTag = old.tag, tag = vnode.tag
1059
  if (oldTag === tag) {
1060
  vnode.state = old.state
1061
+ vnode._state = old._state
1062
  vnode.events = old.events
1063
+ if (!recycling && shouldNotUpdate(vnode, old)) return
 
 
 
1064
  if (typeof oldTag === "string") {
1065
+ if (vnode.attrs != null) {
1066
+ if (recycling) {
1067
+ vnode.state = {}
1068
+ initLifecycle(vnode.attrs, vnode, hooks)
1069
+ }
1070
+ else updateLifecycle(vnode.attrs, vnode, hooks)
1071
+ }
1072
  switch (oldTag) {
1073
  case "#": updateText(old, vnode); break
1074
  case "<": updateHTML(parent, old, vnode, nextSibling); break
1138
  }
1139
  }
1140
  function updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) {
1141
+ if (recycling) {
1142
+ initComponent(vnode, hooks)
1143
+ } else {
1144
+ vnode.instance = Vnode.normalize(vnode._state.view.call(vnode.state, vnode))
1145
+ if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as argument")
1146
+ if (vnode.attrs != null) updateLifecycle(vnode.attrs, vnode, hooks)
1147
+ updateLifecycle(vnode._state, vnode, hooks)
1148
+ }
1149
  if (vnode.instance != null) {
1150
  if (old.instance == null) createNode(parent, vnode.instance, hooks, ns, nextSibling)
1151
  else updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling, ns)
1227
  }
1228
  function removeNode(vnode, context) {
1229
  var expected = 1, called = 0
1230
+ if (vnode.attrs && typeof vnode.attrs.onbeforeremove === "function") {
1231
  var result = vnode.attrs.onbeforeremove.call(vnode.state, vnode)
1232
  if (result != null && typeof result.then === "function") {
1233
  expected++
1234
  result.then(continuation, continuation)
1235
  }
1236
  }
1237
+ if (typeof vnode.tag !== "string" && typeof vnode._state.onbeforeremove === "function") {
1238
+ var result = vnode._state.onbeforeremove.call(vnode.state, vnode)
1239
  if (result != null && typeof result.then === "function") {
1240
  expected++
1241
  result.then(continuation, continuation)
1267
  if (parent != null) parent.removeChild(node)
1268
  }
1269
  function onremove(vnode) {
1270
+ if (vnode.attrs && typeof vnode.attrs.onremove === "function") vnode.attrs.onremove.call(vnode.state, vnode)
1271
+ if (typeof vnode.tag !== "string" && typeof vnode._state.onremove === "function") vnode._state.onremove.call(vnode.state, vnode)
1272
  if (vnode.instance != null) onremove(vnode.instance)
1273
  else {
1274
  var children = vnode.children
1297
  else if (key2 === "style") updateStyle(element, old, value)
1298
  else if (key2 in element && !isAttribute(key2) && ns === undefined && !isCustomElement(vnode)) {
1299
  //setting input[value] to same value by typing on focused element moves cursor to end in Chrome
1300
+ if (vnode.tag === "input" && key2 === "value" && vnode.dom.value == value && vnode.dom === $doc.activeElement) return
1301
  //setting select[value] to same value while having select open blinks select dropdown in Chrome
1302
+ if (vnode.tag === "select" && key2 === "value" && vnode.dom.value == value && vnode.dom === $doc.activeElement) return
1303
  //setting option[value] to same value while having select open blinks select dropdown in Chrome
1304
+ if (vnode.tag === "option" && key2 === "value" && vnode.dom.value == value) return
1305
+ // If you assign an input type1 that is not supported by IE 11 with an assignment expression, an error0 will occur.
1306
+ if (vnode.tag === "input" && key2 === "type") {
1307
+ element.setAttribute(key2, value)
1308
+ return
1309
+ }
1310
  element[key2] = value
1311
  }
1312
  else {
1397
  if (typeof source.oninit === "function") source.oninit.call(vnode.state, vnode)
1398
  if (typeof source.oncreate === "function") hooks.push(source.oncreate.bind(vnode.state, vnode))
1399
  }
1400
+ function updateLifecycle(source, vnode, hooks) {
1401
+ if (typeof source.onupdate === "function") hooks.push(source.onupdate.bind(vnode.state, vnode))
 
1402
  }
1403
+ function shouldNotUpdate(vnode, old) {
1404
  var forceVnodeUpdate, forceComponentUpdate
1405
  if (vnode.attrs != null && typeof vnode.attrs.onbeforeupdate === "function") forceVnodeUpdate = vnode.attrs.onbeforeupdate.call(vnode.state, vnode, old)
1406
+ if (typeof vnode.tag !== "string" && typeof vnode._state.onbeforeupdate === "function") forceComponentUpdate = vnode._state.onbeforeupdate.call(vnode.state, vnode, old)
1407
  if (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {
1408
  vnode.dom = old.dom
1409
  vnode.domSize = old.domSize
1460
  var index = callbacks.indexOf(key1)
1461
  if (index > -1) callbacks.splice(index, 2)
1462
  }
1463
+ function redraw() {
1464
+ for (var i = 1; i < callbacks.length; i += 2) {
1465
+ callbacks[i]()
1466
+ }
1467
+ }
1468
  return {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render}
1469
  }
1470
  var redrawService = _11(window)
1477
  return
1478
  }
1479
 
1480
+ if (component.view == null && typeof component !== "function") throw new Error("m.mount(element, component) expects a component, not a vnode")
1481
 
1482
  var run0 = function() {
1483
  redrawService0.render(root, Vnode(component))
1630
  routeService.defineRoutes(routes, function(payload, params, path) {
1631
  var update = lastUpdate = function(routeResolver, comp) {
1632
  if (update !== lastUpdate) return
1633
+ component = comp != null && (typeof comp.view === "function" || typeof comp === "function")? comp : "div"
1634
+ attrs3 = params, currentPath = path, lastUpdate = null
1635
  render1 = (routeResolver.render || identity).bind(routeResolver)
1636
  run1()
1637
  }
1638
+ if (payload.view || typeof payload === "function") update({}, payload)
1639
  else {
1640
  if (payload.onmatch) {
1641
  Promise.resolve(payload.onmatch(params, path)).then(function(resolved) {
1684
  m.jsonp = requestService.jsonp
1685
  m.parseQueryString = parseQueryString
1686
  m.buildQueryString = buildQueryString
1687
+ m.version = "1.1.1"
1688
  m.vnode = Vnode
1689
  if (typeof module !== "undefined") module["exports"] = m
1690
  else window.m = m
1691
+ }());
1692
  }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1693
  },{}],8:[function(require,module,exports){
1694
  /*!
assets/js/admin.min.js CHANGED
@@ -1,2 +1,3 @@
1
- !function(){var e=void 0,t=void 0;!function t(n,r,i){function o(l,s){if(!r[l]){if(!n[l]){var u="function"==typeof e&&e;if(!s&&u)return u(l,!0);if(a)return a(l,!0);var c=new Error("Cannot find module '"+l+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[l]={exports:{}};n[l][0].call(f.exports,function(e){var t=n[l][1][e];return o(t?t:e)},f,f.exports,t,n,r,i)}return r[l].exports}for(var a="function"==typeof e&&e,l=0;l<i.length;l++)o(i[l]);return o}({1:[function(e,t,n){"use strict";var r=window.m=e("mithril"),i=e("wolfy87-eventemitter"),o=document.getElementById("mc4wp-admin"),a=new i,l=e("./admin/tabs.js")(o),s=e("./admin/helpers.js"),u=e("./admin/settings.js")(o,s,a),c=e("./admin/list-fetcher.js"),f=document.getElementById("mc4wp-list-fetcher");f&&r.mount(f,new c),window.mc4wp=window.mc4wp||{},window.mc4wp.deps=window.mc4wp.deps||{},window.mc4wp.deps.mithril=r,window.mc4wp.helpers=s,window.mc4wp.events=a,window.mc4wp.settings=u,window.mc4wp.tabs=l},{"./admin/helpers.js":2,"./admin/list-fetcher.js":3,"./admin/settings.js":4,"./admin/tabs.js":5,mithril:7,"wolfy87-eventemitter":8}],2:[function(e,t,n){"use strict";var r={};r.toggleElement=function(e){for(var t=document.querySelectorAll(e),n=0;n<t.length;n++){var r=t[n].clientHeight<=0;t[n].style.display=r?"":"none"}},r.bindEventToElement=function(e,t,n){e.addEventListener?e.addEventListener(t,n):e.attachEvent&&e.attachEvent("on"+t,n)},r.bindEventToElements=function(e,t,n){Array.prototype.forEach.call(e,function(e){r.bindEventToElement(e,t,n)})},r.debounce=function(e,t,n){var r;return function(){var i=this,o=arguments,a=function(){r=null,n||e.apply(i,o)},l=n&&!r;clearTimeout(r),r=setTimeout(a,t),l&&e.apply(i,o)}},function(){var e=document.querySelectorAll("[data-showif]");Array.prototype.forEach.call(e,function(e){function t(){if("radio"!==this.getAttribute("type")||this.checked){var t="checkbox"===this.getAttribute("type")?this.checked:this.value,r=t==n.value;a?(e.style.display=r?"":"none",e.style.visibility=r?"":"hidden"):e.style.opacity=r?"":"0.4",Array.prototype.forEach.call(o,function(e){r?e.removeAttribute("readonly"):e.setAttribute("readonly","readonly")})}}var n=JSON.parse(e.getAttribute("data-showif")),i=document.querySelectorAll('[name="'+n.element+'"]'),o=e.querySelectorAll("input,select,textarea:not([readonly])"),a=void 0===n.hide||n.hide;Array.prototype.forEach.call(i,function(e){t.call(e)}),r.bindEventToElements(i,"change",t)})}(),t.exports=r},{}],3:[function(e,t,n){"use strict";function r(){this.working=!1,this.done=!1,o.mailchimp.api_connected&&0==o.mailchimp.lists.length&&this.fetch()}var i=window.jQuery,o=mc4wp_vars,a=o.i18n;r.prototype.fetch=function(e){e&&e.preventDefault(),this.working=!0,this.done=!1,i.post(ajaxurl,{action:"mc4wp_renew_mailchimp_lists"}).done(function(e){e&&window.setTimeout(function(){window.location.reload()},3e3)}).always(function(e){this.working=!1,this.done=!0,m.redraw()}.bind(this))},r.prototype.view=function(){return m("form",{method:"POST",onsubmit:this.fetch.bind(this)},[m("p",[m("input",{type:"submit",value:this.working?a.fetching_mailchimp_lists:a.renew_mailchimp_lists,className:"button",disabled:!!this.working}),m.trust(" &nbsp; "),this.working?[m("span.mc4wp-loader","Loading..."),m.trust(" &nbsp; "),m("em.help",a.fetching_mailchimp_lists_can_take_a_while)]:"",this.done?[m("em.help.green",a.fetching_mailchimp_lists_done)]:""])])},t.exports=r},{}],4:[function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e,t,n){function i(e,t){return c.filter(function(n){return n[e]===t})}function o(){return c}function a(){return c=[],Array.prototype.forEach.call(s,function(e){("boolean"!=typeof e.checked||e.checked)&&"object"===r(u[e.value])&&c.push(u[e.value])}),n.trigger("selectedLists.change",[c]),c}function l(){var e=document.querySelectorAll(".lists--only-selected > *");Array.prototype.forEach.call(e,function(e){i("id",e.getAttribute("data-list-id")).length>0?e.setAttribute("class",e.getAttribute("class").replace("hidden","")):e.setAttribute("class",e.getAttribute("class")+" hidden")})}var s=(e.querySelector("form"),e.querySelectorAll(".mc4wp-list-input")),u=mc4wp_vars.mailchimp.lists,c=[];return n.on("selectedLists.change",l),t.bindEventToElements(s,"change",a),a(),{getSelectedLists:o}};t.exports=i},{}],5:[function(e,t,n){"use strict";var r=e("./url.js"),i=function(e){function t(e){for(var t=0;t<f.length;t++)if(f[t].id===e)return f[t]}function n(e,n){if("string"==typeof e&&(e=t(e)),!e)return!1;void 0==n&&(n=!0),s.removeClass("tab-active").css("display","none"),u.removeClass("nav-tab-active"),Array.prototype.forEach.call(e.nav,function(e){e.className+=" nav-tab-active",e.blur()}),e.element.style.display="block",e.element.className+=" tab-active";var o=r.setParameter(window.location.href,"tab",e.id);return history.pushState&&n&&history.pushState(e.id,"",o),i(e),c.value=o,"function"==typeof tb_remove&&tb_remove(),"fields"===e.id&&window.mc4wp&&window.mc4wp.forms&&window.mc4wp.forms.editor&&mc4wp.forms.editor.refresh(),!0}function i(e){var t=document.title.split("-");document.title=document.title.replace(t[0],e.title+" ")}function o(e){e=e||window.event;var t=this.getAttribute("data-tab");if(!t){var i=this.className.match(/nav-tab-(\w+)?/);i&&(t=i[1])}if(!t){var o=r.parse(this.href);if(!o.tab)return;t=o.tab}return!n(t)||(e.preventDefault(),e.returnValue=!1,!1)}var a=window.jQuery,l=a(e),s=l.find(".tab"),u=l.find(".nav-tab"),c=e.querySelector('input[name="_wp_http_referer"]'),f=[];return a.each(s,function(t,r){var i=r.id.substring(4),o=a(r).find("h2").first().text();f.push({id:i,title:o,element:r,nav:e.querySelectorAll(".nav-tab-"+i),open:function(){return n(i)}})}),u.click(o),a(document.body).on("click",".tab-link",o),function(){if(history.pushState){var e=s.filter(":visible").get(0);if(e){var n=t(e.id.substring(4));n&&(history.replaceState&&null===history.state&&history.replaceState(n.id,""),i(n))}}}(),window.addEventListener&&history.pushState&&window.addEventListener("popstate",function(e){return!e.state||n(e.state,!1)}),{open:n,get:t}};t.exports=i},{"./url.js":6}],6:[function(e,t,n){"use strict";var r={parse:function(e){var t={},n=e.split("&");for(var r in n)if(n.hasOwnProperty(r)){var i=n[r].split("=");t[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return t},build:function(e){var t=[];for(var n in e)t.push(n+"="+encodeURIComponent(e[n]));return t.join("&")},setParameter:function(e,t,n){var i=r.parse(e);return i[t]=n,r.build(i)}};t.exports=r},{}],7:[function(e,t,n){(function(e){new function(){function n(e,t,n,r,i,o){return{tag:e,key:t,attrs:n,children:r,text:i,dom:o,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function r(e){if(null==e||"string"!=typeof e&&"function"!=typeof e.view)throw Error("The selector must be either a string or a component.");if("string"==typeof e&&void 0===a[e]){for(var t,r,i=[],l={};t=o.exec(e);){var s=t[1],u=t[2];if(""===s&&""!==u)r=u;else if("#"===s)l.id=u;else if("."===s)i.push(u);else if("["===t[3][0]){var c=t[6];c&&(c=c.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===t[4]?i.push(c):l[t[4]]=c||!0}}i.length>0&&(l.className=i.join(" ")),a[e]=function(e,t){var i,o,a=!1,s=e.className||e.class;for(var u in l)e[u]=l[u];void 0!==s&&(void 0!==e.class&&(e.class=void 0,e.className=s),void 0!==l.className&&(e.className=l.className+" "+s));for(var u in e)if("key"!==u){a=!0;break}return Array.isArray(t)&&1==t.length&&null!=t[0]&&"#"===t[0].tag?o=t[0].children:i=t,n(r||"div",e.key,a?e:void 0,i,o,void 0)}}var f,d,v;if(null==arguments[1]||"object"==typeof arguments[1]&&void 0===arguments[1].tag&&!Array.isArray(arguments[1])?(f=arguments[1],v=2):v=1,arguments.length===v+1)d=Array.isArray(arguments[v])?arguments[v]:[arguments[v]];else{d=[];for(var h=v;h<arguments.length;h++)d.push(arguments[h])}return"string"==typeof e?a[e](f||{},n.normalizeChildren(d)):n(e,f&&f.key,f||{},n.normalizeChildren(d),void 0,void 0)}function i(e){var t=0,n=null,r="function"==typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var i=Date.now();0===t||i-t>=16?(t=i,e()):null===n&&(n=r(function(){n=null,e(),t=Date.now()},16-(i-t)))}}n.normalize=function(e){return Array.isArray(e)?n("[",void 0,void 0,n.normalizeChildren(e),void 0,void 0):null!=e&&"object"!=typeof e?n("#",void 0,void 0,e===!1?"":e,void 0,void 0):e},n.normalizeChildren=function(e){for(var t=0;t<e.length;t++)e[t]=n.normalize(e[t]);return e};var o=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,a={};r.trust=function(e){return null==e&&(e=""),n("<",void 0,void 0,e,void 0,void 0)},r.fragment=function(e,t){return n("[",e.key,e,n.normalizeChildren(t),void 0,void 0)};var l=r,s=function(e){function t(e,t){return function a(s){var f;try{if(!t||null==s||"object"!=typeof s&&"function"!=typeof s||"function"!=typeof(f=s.then))c(function(){t||0!==e.length||console.error("Possible unhandled promise rejection:",s);for(var n=0;n<e.length;n++)e[n](s);i.length=0,o.length=0,u.state=t,u.retry=function(){a(s)}});else{if(s===r)throw new TypeError("Promise can't be resolved w/ itself");n(f.bind(s))}}catch(e){l(e)}}}function n(e){function t(e){return function(t){n++>0||e(t)}}var n=0,r=t(l);try{e(t(a),r)}catch(e){r(e)}}if(!(this instanceof s))throw new Error("Promise must be called with `new`");if("function"!=typeof e)throw new TypeError("executor must be a function");var r=this,i=[],o=[],a=t(i,!0),l=t(o,!1),u=r._instance={resolvers:i,rejectors:o},c="function"==typeof setImmediate?setImmediate:setTimeout;n(e)};if(s.prototype.then=function(e,t){function n(e,t,n,o){t.push(function(t){if("function"!=typeof e)n(t);else try{r(e(t))}catch(e){i&&i(e)}}),"function"==typeof a.retry&&o===a.state&&a.retry()}var r,i,o=this,a=o._instance,l=new s(function(e,t){r=e,i=t});return n(e,a.resolvers,r,!0),n(t,a.rejectors,i,!1),l},s.prototype.catch=function(e){return this.then(null,e)},s.resolve=function(e){return e instanceof s?e:new s(function(t){t(e)})},s.reject=function(e){return new s(function(t,n){n(e)})},s.all=function(e){return new s(function(t,n){var r=e.length,i=0,o=[];if(0===e.length)t([]);else for(var a=0;a<e.length;a++)!function(a){function l(e){i++,o[a]=e,i===r&&t(o)}null==e[a]||"object"!=typeof e[a]&&"function"!=typeof e[a]||"function"!=typeof e[a].then?l(e[a]):e[a].then(l,n)}(a)})},s.race=function(e){return new s(function(t,n){for(var r=0;r<e.length;r++)e[r].then(t,n)})},"undefined"!=typeof window){void 0===window.Promise&&(window.Promise=s);var s=window.Promise}else if(void 0!==e){void 0===e.Promise&&(e.Promise=s);var s=e.Promise}var u=function(e){function t(e,r){if(Array.isArray(r))for(var i=0;i<r.length;i++)t(e+"["+i+"]",r[i]);else if("[object Object]"===Object.prototype.toString.call(r))for(var i in r)t(e+"["+i+"]",r[i]);else n.push(encodeURIComponent(e)+(null!=r&&""!==r?"="+encodeURIComponent(r):""))}if("[object Object]"!==Object.prototype.toString.call(e))return"";var n=[];for(var r in e)t(r,e[r]);return n.join("&")},c=function(e,t){function n(e){v=e}function r(){function e(){0==--t&&"function"==typeof v&&v()}var t=0;return function n(r){var i=r.then;return r.then=function(){t++;var o=i.apply(r,arguments);return o.then(e,function(n){if(e(),0===t)throw n}),n(o)},r}}function i(e,t){if("string"==typeof e){var n=e;e=t||{},null==e.url&&(e.url=n)}return e}function o(n,o){var a=r();n=i(n,o);var u=new t(function(t,r){null==n.method&&(n.method="GET"),n.method=n.method.toUpperCase();var i="boolean"==typeof n.useBody?n.useBody:"GET"!==n.method&&"TRACE"!==n.method;"function"!=typeof n.serialize&&(n.serialize="undefined"!=typeof FormData&&n.data instanceof FormData?function(e){return e}:JSON.stringify),"function"!=typeof n.deserialize&&(n.deserialize=c),"function"!=typeof n.extract&&(n.extract=f),n.url=l(n.url,n.data),i?n.data=n.serialize(n.data):n.url=s(n.url,n.data);var o=new e.XMLHttpRequest;o.open(n.method,n.url,"boolean"!=typeof n.async||n.async,"string"==typeof n.user?n.user:void 0,"string"==typeof n.password?n.password:void 0),n.serialize===JSON.stringify&&i&&o.setRequestHeader("Content-Type","application/json; charset=utf-8"),n.deserialize===c&&o.setRequestHeader("Accept","application/json, text/*"),n.withCredentials&&(o.withCredentials=n.withCredentials);for(var a in n.headers)({}).hasOwnProperty.call(n.headers,a)&&o.setRequestHeader(a,n.headers[a]);"function"==typeof n.config&&(o=n.config(o,n)||o),o.onreadystatechange=function(){if(o.status&&4===o.readyState)try{var e=n.extract!==f?n.extract(o,n):n.deserialize(n.extract(o,n));if(o.status>=200&&o.status<300||304===o.status)t(d(n.type,e));else{var i=new Error(o.responseText);for(var a in e)i[a]=e[a];r(i)}}catch(e){r(e)}},i&&null!=n.data?o.send(n.data):o.send()});return n.background===!0?u:a(u)}function a(n,o){var a=r();n=i(n,o);var u=new t(function(t,r){var i=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+h++,o=e.document.createElement("script");e[i]=function(r){o.parentNode.removeChild(o),t(d(n.type,r)),delete e[i]},o.onerror=function(){o.parentNode.removeChild(o),r(new Error("JSONP request failed")),delete e[i]},null==n.data&&(n.data={}),n.url=l(n.url,n.data),n.data[n.callbackKey||"callback"]=i,o.src=s(n.url,n.data),e.document.documentElement.appendChild(o)});return n.background===!0?u:a(u)}function l(e,t){if(null==t)return e;for(var n=e.match(/:[^\/]+/gi)||[],r=0;r<n.length;r++){var i=n[r].slice(1);null!=t[i]&&(e=e.replace(n[r],t[i]))}return e}function s(e,t){var n=u(t);if(""!==n){e+=(e.indexOf("?")<0?"?":"&")+n}return e}function c(e){try{return""!==e?JSON.parse(e):null}catch(t){throw new Error(e)}}function f(e){return e.responseText}function d(e,t){if("function"==typeof e){if(!Array.isArray(t))return new e(t);for(var n=0;n<t.length;n++)t[n]=new e(t[n])}return t}var v,h=0;return{request:o,jsonp:a,setCompletionCallback:n}}(window,s),f=function(e){function t(e){return V=e}function r(e,t,n,r,o,a,l){for(var s=n;s<r;s++){var u=t[s];null!=u&&i(e,u,o,l,a)}}function i(e,t,n,r,i){var c=t.tag;if(null!=t.attrs&&M(t.attrs,t,n),"string"!=typeof c)return u(e,t,n,r,i);switch(c){case"#":return o(e,t,i);case"<":return a(e,t,i);case"[":return l(e,t,n,r,i);default:return s(e,t,n,r,i)}}function o(e,t,n){return t.dom=H.createTextNode(t.children),x(e,t.dom,n),t.dom}function a(e,t,n){var r=t.children.match(/^\s*?<(\w+)/im)||[],i={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[r[1]]||"div",o=H.createElement(i);o.innerHTML=t.children,t.dom=o.firstChild,t.domSize=o.childNodes.length;for(var a,l=H.createDocumentFragment();a=o.firstChild;)l.appendChild(a);return x(e,l,n),l}function l(e,t,n,i,o){var a=H.createDocumentFragment();if(null!=t.children){var l=t.children;r(a,l,0,l.length,n,null,i)}return t.dom=a.firstChild,t.domSize=a.childNodes.length,x(e,a,o),a}function s(e,t,i,o,a){var l=t.tag;switch(t.tag){case"svg":o="http://www.w3.org/2000/svg";break;case"math":o="http://www.w3.org/1998/Math/MathML"}var s=t.attrs,u=s&&s.is,c=o?u?H.createElementNS(o,l,{is:u}):H.createElementNS(o,l):u?H.createElement(l,{is:u}):H.createElement(l);if(t.dom=c,null!=s&&j(t,s,o),x(e,c,a),null!=t.attrs&&null!=t.attrs.contenteditable)E(t);else if(null!=t.text&&(""!==t.text?c.textContent=t.text:t.children=[n("#",void 0,void 0,t.text,void 0,void 0)]),null!=t.children){var f=t.children;r(c,f,0,f.length,i,null,o),O(t)}return c}function u(e,t,r,o,a){t.state=Object.create(t.tag);var l=t.tag.view;if(null!=l.reentrantLock)return B;if(l.reentrantLock=!0,M(t.tag,t,r),t.instance=n.normalize(l.call(t.state,t)),l.reentrantLock=null,null!=t.instance){if(t.instance===t)throw Error("A view cannot return the vnode it received as arguments");var s=i(e,t.instance,r,o,a);return t.dom=t.instance.dom,t.domSize=null!=t.dom?t.instance.domSize:0,x(e,s,a),s}return t.domSize=0,B}function c(e,t,n,o,a,l,s){if(t!==n&&(null!=t||null!=n))if(null==t)r(e,n,0,n.length,a,l,void 0);else if(null==n)A(t,0,t.length,n);else{if(t.length===n.length){for(var u=!1,c=0;c<n.length;c++)if(null!=n[c]&&null!=t[c]){u=null==n[c].key&&null==t[c].key;break}if(u){for(var c=0;c<t.length;c++)t[c]!==n[c]&&(null==t[c]&&null!=n[c]?i(e,n[c],a,s,b(t,c+1,l)):null==n[c]?A(t,c,c+1,n):f(e,t[c],n[c],a,b(t,c+1,l),!1,s));return}}o=o||y(t,n),o&&(t=t.concat(t.pool));for(var d,v=0,h=0,p=t.length-1,m=n.length-1;p>=v&&m>=h;){var E=t[v],k=n[h];if(E!==k||o)if(null==E)v++;else if(null==k)h++;else if(E.key===k.key)v++,h++,f(e,E,k,a,b(t,v,l),o,s),o&&E.tag===k.tag&&x(e,w(E),l);else{var E=t[p];if(E!==k||o)if(null==E)p--;else if(null==k)h++;else{if(E.key!==k.key)break;f(e,E,k,a,b(t,p+1,l),o,s),(o||h<m)&&x(e,w(E),b(t,v,l)),p--,h++}else p--,h++}else v++,h++}for(;p>=v&&m>=h;){var E=t[p],k=n[m];if(E!==k||o)if(null==E)p--;else if(null==k)m--;else if(E.key===k.key)f(e,E,k,a,b(t,p+1,l),o,s),o&&E.tag===k.tag&&x(e,w(E),l),null!=E.dom&&(l=E.dom),p--,m--;else{if(d||(d=g(t,p)),null!=k){var S=d[k.key];if(null!=S){var C=t[S];f(e,C,k,a,b(t,p+1,l),o,s),x(e,w(C),l),t[S].skip=!0,null!=C.dom&&(l=C.dom)}else{var j=i(e,k,a,void 0,l);l=j}}m--}else p--,m--;if(m<h)break}r(e,n,h,m+1,a,l,s),A(t,v,p+1,n)}}function f(e,t,n,r,o,a,l){var s=t.tag;if(s===n.tag){if(n.state=t.state,n.events=t.events,U(n,t))return;if(null!=n.attrs&&D(n.attrs,n,r,a),"string"==typeof s)switch(s){case"#":d(t,n);break;case"<":v(e,t,n,o);break;case"[":h(e,t,n,a,r,o,l);break;default:p(t,n,a,r,l)}else m(e,t,n,r,o,a,l)}else k(t,null),i(e,n,r,l,o)}function d(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children),t.dom=e.dom}function v(e,t,n,r){t.children!==n.children?(w(t),a(e,n,r)):(n.dom=t.dom,n.domSize=t.domSize)}function h(e,t,n,r,i,o,a){c(e,t.children,n.children,r,i,o,a);var l=0,s=n.children;if(n.dom=null,null!=s){for(var u=0;u<s.length;u++){var f=s[u];null!=f&&null!=f.dom&&(null==n.dom&&(n.dom=f.dom),l+=f.domSize||1)}1!==l&&(n.domSize=l)}}function p(e,t,r,i,o){var a=t.dom=e.dom;switch(t.tag){case"svg":o="http://www.w3.org/2000/svg";break;case"math":o="http://www.w3.org/1998/Math/MathML"}"textarea"===t.tag&&(null==t.attrs&&(t.attrs={}),null!=t.text&&(t.attrs.value=t.text,t.text=void 0)),_(t,e.attrs,t.attrs,o),null!=t.attrs&&null!=t.attrs.contenteditable?E(t):null!=e.text&&null!=t.text&&""!==t.text?e.text.toString()!==t.text.toString()&&(e.dom.firstChild.nodeValue=t.text):(null!=e.text&&(e.children=[n("#",void 0,void 0,e.text,void 0,e.dom.firstChild)]),null!=t.text&&(t.children=[n("#",void 0,void 0,t.text,void 0,void 0)]),c(a,e.children,t.children,r,i,null,o))}function m(e,t,r,o,a,l,s){r.instance=n.normalize(r.tag.view.call(r.state,r)),D(r.tag,r,o,l),null!=r.instance?(null==t.instance?i(e,r.instance,o,s,a):f(e,t.instance,r.instance,o,a,l,s),r.dom=r.instance.dom,r.domSize=r.instance.domSize):null!=t.instance?(k(t.instance,null),r.dom=void 0,r.domSize=0):(r.dom=t.dom,r.domSize=t.domSize)}function y(e,t){if(null!=e.pool&&Math.abs(e.pool.length-t.length)<=Math.abs(e.length-t.length)){var n=e[0]&&e[0].children&&e[0].children.length||0,r=e.pool[0]&&e.pool[0].children&&e.pool[0].children.length||0,i=t[0]&&t[0].children&&t[0].children.length||0;if(Math.abs(r-i)<=Math.abs(n-i))return!0}return!1}function g(e,t){for(var n={},r=0,r=0;r<t;r++){var i=e[r];if(null!=i){var o=i.key;null!=o&&(n[o]=r)}}return n}function w(e){var t=e.domSize;if(null!=t||null==e.dom){var n=H.createDocumentFragment();if(t>0){for(var r=e.dom;--t;)n.appendChild(r.nextSibling);n.insertBefore(r,n.firstChild)}return n}return e.dom}function b(e,t,n){for(;t<e.length;t++)if(null!=e[t]&&null!=e[t].dom)return e[t].dom;return n}function x(e,t,n){n&&n.parentNode?e.insertBefore(t,n):e.appendChild(t)}function E(e){var t=e.children;if(null!=t&&1===t.length&&"<"===t[0].tag){var n=t[0].children;e.dom.innerHTML!==n&&(e.dom.innerHTML=n)}else if(null!=e.text||null!=t&&0!==t.length)throw new Error("Child node of a contenteditable must be trusted")}function A(e,t,n,r){for(var i=t;i<n;i++){var o=e[i];null!=o&&(o.skip?o.skip=!1:k(o,r))}}function k(e,t){function n(){if(++i===r&&(C(e),e.dom)){var n=e.domSize||1;if(n>1)for(var o=e.dom;--n;)S(o.nextSibling);S(e.dom),null==t||null!=e.domSize||R(e.attrs)||"string"!=typeof e.tag||(t.pool?t.pool.push(e):t.pool=[e])}}var r=1,i=0;if(e.attrs&&e.attrs.onbeforeremove){var o=e.attrs.onbeforeremove.call(e.state,e);null!=o&&"function"==typeof o.then&&(r++,o.then(n,n))}if("string"!=typeof e.tag&&e.tag.onbeforeremove){var o=e.tag.onbeforeremove.call(e.state,e);null!=o&&"function"==typeof o.then&&(r++,o.then(n,n))}n()}function S(e){var t=e.parentNode;null!=t&&t.removeChild(e)}function C(e){if(e.attrs&&e.attrs.onremove&&e.attrs.onremove.call(e.state,e),"string"!=typeof e.tag&&e.tag.onremove&&e.tag.onremove.call(e.state,e),null!=e.instance)C(e.instance);else{var t=e.children;if(Array.isArray(t))for(var n=0;n<t.length;n++){var r=t[n];null!=r&&C(r)}}}function j(e,t,n){for(var r in t)L(e,r,null,t[r],n)}function L(e,t,n,r,i){var o=e.dom;if("key"!==t&&"is"!==t&&(n!==r||z(e,t)||"object"==typeof r)&&void 0!==r&&!T(t)){var a=t.indexOf(":");if(a>-1&&"xlink"===t.substr(0,a))o.setAttributeNS("http://www.w3.org/1999/xlink",t.slice(a+1),r);else if("o"===t[0]&&"n"===t[1]&&"function"==typeof r)q(e,t,r);else if("style"===t)I(o,n,r);else if(t in o&&!N(t)&&void 0===i&&!P(e)){if("input"===e.tag&&"value"===t&&e.dom.value===r&&e.dom===H.activeElement)return;if("select"===e.tag&&"value"===t&&e.dom.value===r&&e.dom===H.activeElement)return;if("option"===e.tag&&"value"===t&&e.dom.value===r)return;o[t]=r}else"boolean"==typeof r?r?o.setAttribute(t,""):o.removeAttribute(t):o.setAttribute("className"===t?"class":t,r)}}function O(e){var t=e.attrs;"select"===e.tag&&null!=t&&("value"in t&&L(e,"value",null,t.value,void 0),"selectedIndex"in t&&L(e,"selectedIndex",null,t.selectedIndex,void 0))}function _(e,t,n,r){if(null!=n)for(var i in n)L(e,i,t&&t[i],n[i],r);if(null!=t)for(var i in t)null!=n&&i in n||("className"===i&&(i="class"),"o"!==i[0]||"n"!==i[1]||T(i)?"key"!==i&&e.dom.removeAttribute(i):q(e,i,void 0))}function z(e,t){return"value"===t||"checked"===t||"selectedIndex"===t||"selected"===t&&e.dom===H.activeElement}function T(e){return"oninit"===e||"oncreate"===e||"onupdate"===e||"onremove"===e||"onbeforeremove"===e||"onbeforeupdate"===e}function N(e){return"href"===e||"list"===e||"form"===e||"width"===e||"height"===e}function P(e){return e.attrs.is||e.tag.indexOf("-")>-1}function R(e){return null!=e&&(e.oncreate||e.onupdate||e.onbeforeremove||e.onremove)}function I(e,t,n){if(t===n&&(e.style.cssText="",t=null),null==n)e.style.cssText="";else if("string"==typeof n)e.style.cssText=n;else{"string"==typeof t&&(e.style.cssText="");for(var r in n)e.style[r]=n[r];if(null!=t&&"string"!=typeof t)for(var r in t)r in n||(e.style[r]="")}}function q(e,t,n){var r=e.dom,i="function"!=typeof V?n:function(e){var t=n.call(r,e);return V.call(r,e),t};if(t in r)r[t]="function"==typeof n?i:null;else{var o=t.slice(2);if(void 0===e.events&&(e.events={}),e.events[t]===i)return;null!=e.events[t]&&r.removeEventListener(o,e.events[t],!1),"function"==typeof n&&(e.events[t]=i,r.addEventListener(o,e.events[t],!1))}}function M(e,t,n){"function"==typeof e.oninit&&e.oninit.call(t.state,t),"function"==typeof e.oncreate&&n.push(e.oncreate.bind(t.state,t))}function D(e,t,n,r){r?M(e,t,n):"function"==typeof e.onupdate&&n.push(e.onupdate.bind(t.state,t))}function U(e,t){var n,r;return null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate&&(n=e.attrs.onbeforeupdate.call(e.state,e,t)),"string"!=typeof e.tag&&"function"==typeof e.tag.onbeforeupdate&&(r=e.tag.onbeforeupdate.call(e.state,e,t)),!(void 0===n&&void 0===r||n||r)&&(e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,!0)}function F(e,t){if(!e)throw new Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var r=[],i=H.activeElement;null==e.vnodes&&(e.textContent=""),Array.isArray(t)||(t=[t]),c(e,e.vnodes,n.normalizeChildren(t),!1,r,null,void 0),e.vnodes=t;for(var o=0;o<r.length;o++)r[o]();H.activeElement!==i&&i.focus()}var V,H=e.document,B=H.createDocumentFragment();return{render:F,setEventCallback:t}},d=function(e){function t(e,t){n(e),a.push(e,i(t))}function n(e){var t=a.indexOf(e);t>-1&&a.splice(t,2)}function r(){for(var e=1;e<a.length;e+=2)a[e]()}var o=f(e);o.setEventCallback(function(e){e.redraw!==!1&&r()});var a=[];return{subscribe:t,unsubscribe:n,redraw:r,render:o.render}}(window);c.setCompletionCallback(d.redraw);l.mount=function(e){return function(t,r){if(null===r)return e.render(t,[]),void e.unsubscribe(t);if(null==r.view)throw new Error("m.mount(element, component) expects a component, not a vnode");var i=function(){e.render(t,n(r))};e.subscribe(t,i),e.redraw()}}(d);var v=s,h=function(e){if(""===e||null==e)return{};"?"===e.charAt(0)&&(e=e.slice(1));for(var t=e.split("&"),n={},r={},i=0;i<t.length;i++){var o=t[i].split("="),a=decodeURIComponent(o[0]),l=2===o.length?decodeURIComponent(o[1]):"";"true"===l?l=!0:"false"===l&&(l=!1);var s=a.split(/\]\[?|\[/),u=n;a.indexOf("[")>-1&&s.pop();for(var c=0;c<s.length;c++){var f=s[c],d=s[c+1],v=""==d||!isNaN(parseInt(d,10)),h=c===s.length-1;if(""===f){var a=s.slice(0,c).join();null==r[a]&&(r[a]=0),f=r[a]++}null==u[f]&&(u[f]=h?l:v?[]:{}),u=u[f]}}return n},p=function(e){function t(t){var n=e.location[t].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);return"pathname"===t&&"/"!==n[0]&&(n="/"+n),n}function n(e){return function(){null==i&&(i=a(function(){i=null,e()}))}}function r(e,t,n){var r=e.indexOf("?"),i=e.indexOf("#"),o=r>-1?r:i>-1?i:e.length;if(r>-1){var a=i>-1?i:e.length,l=h(e.slice(r+1,a));for(var s in l)t[s]=l[s]}if(i>-1){var u=h(e.slice(i+1));for(var s in u)n[s]=u[s]}return e.slice(0,o)}var i,o="function"==typeof e.history.pushState,a="function"==typeof setImmediate?setImmediate:setTimeout,l={prefix:"#!"};return l.getPath=function(){switch(l.prefix.charAt(0)){case"#":return t("hash").slice(l.prefix.length);case"?":return t("search").slice(l.prefix.length)+t("hash");default:return t("pathname").slice(l.prefix.length)+t("search")+t("hash")}},l.setPath=function(t,n,i){var a={},s={};if(t=r(t,a,s),null!=n){for(var c in n)a[c]=n[c];t=t.replace(/:([^\/]+)/g,function(e,t){return delete a[t],n[t]})}var f=u(a);f&&(t+="?"+f);var d=u(s);if(d&&(t+="#"+d),o){var v=i?i.state:null,h=i?i.title:null;e.onpopstate(),i&&i.replace?e.history.replaceState(v,h,l.prefix+t):e.history.pushState(v,h,l.prefix+t)}else e.location.href=l.prefix+t},l.defineRoutes=function(t,i,a){function s(){var n=l.getPath(),o={},s=r(n,o,o),u=e.history.state;if(null!=u)for(var c in u)o[c]=u[c];for(var f in t){var d=new RegExp("^"+f.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(d.test(s))return void s.replace(d,function(){for(var e=f.match(/:[^\/]+/g)||[],r=[].slice.call(arguments,1,-2),a=0;a<e.length;a++)o[e[a].replace(/:|\./g,"")]=decodeURIComponent(r[a]);i(t[f],o,n,f)})}a(n,o)}o?e.onpopstate=n(s):"#"===l.prefix.charAt(0)&&(e.onhashchange=s),s()},l};l.route=function(e,t){var r,i,o,a,l,s=p(e),u=function(e){return e},c=function(e,c,f){if(null==e)throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined");var d=function(){null!=r&&t.render(e,r(n(i,o.key,o)))},h=function(e){if(e===c)throw new Error("Could not resolve default route "+c);s.setPath(c,null,{replace:!0})};s.defineRoutes(f,function(e,t,n){var s=l=function(e,c){s===l&&(i=null!=c&&"function"==typeof c.view?c:"div",o=t,a=n,l=null,r=(e.render||u).bind(e),d())};e.view?s({},e):e.onmatch?v.resolve(e.onmatch(t,n)).then(function(t){s(e,t)},h):s(e,"div")},h),t.subscribe(e,d)};return c.set=function(e,t,n){null!=l&&(n={replace:!0}),l=null,s.setPath(e,t,n)},c.get=function(){return a},c.prefix=function(e){s.prefix=e},c.link=function(e){e.dom.setAttribute("href",s.prefix+e.attrs.href),e.dom.onclick=function(e){if(!(e.ctrlKey||e.metaKey||e.shiftKey||2===e.which)){e.preventDefault(),e.redraw=!1;var t=this.getAttribute("href");0===t.indexOf(s.prefix)&&(t=t.slice(s.prefix.length)),c.set(t,void 0,void 0)}}},c.param=function(e){return void 0!==o&&void 0!==e?o[e]:o},c}(window,d),l.withAttr=function(e,t,n){return function(r){t.call(n||this,e in r.currentTarget?r.currentTarget[e]:r.currentTarget.getAttribute(e))}};var m=f(window);l.render=m.render,l.redraw=d.redraw,l.request=c.request,l.jsonp=c.jsonp,l.parseQueryString=h,l.buildQueryString=u,l.version="1.0.1",l.vnode=n,void 0!==t?t.exports=l:window.m=l}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],8:[function(e,n,r){!function(e){"use strict";function r(){}function i(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function o(e){return function(){return this[e].apply(this,arguments)}}function a(e){return"function"==typeof e||e instanceof RegExp||!(!e||"object"!=typeof e)&&a(e.listener)}var l=r.prototype,s=e.EventEmitter;l.getListeners=function(e){var t,n,r=this._getEvents();if(e instanceof RegExp){t={};for(n in r)r.hasOwnProperty(n)&&e.test(n)&&(t[n]=r[n])}else t=r[e]||(r[e]=[]);return t},l.flattenListeners=function(e){var t,n=[];for(t=0;t<e.length;t+=1)n.push(e[t].listener);return n},l.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},l.addListener=function(e,t){if(!a(t))throw new TypeError("listener must be a function");var n,r=this.getListenersAsObject(e),o="object"==typeof t;for(n in r)r.hasOwnProperty(n)&&i(r[n],t)===-1&&r[n].push(o?t:{listener:t,once:!1});return this},l.on=o("addListener"),l.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},l.once=o("addOnceListener"),l.defineEvent=function(e){return this.getListeners(e),this},l.defineEvents=function(e){for(var t=0;t<e.length;t+=1)this.defineEvent(e[t]);return this},l.removeListener=function(e,t){var n,r,o=this.getListenersAsObject(e);for(r in o)o.hasOwnProperty(r)&&(n=i(o[r],t))!==-1&&o[r].splice(n,1);return this},l.off=o("removeListener"),l.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},l.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},l.manipulateListeners=function(e,t,n){var r,i,o=e?this.removeListener:this.addListener,a=e?this.removeListeners:this.addListeners;if("object"!=typeof t||t instanceof RegExp)for(r=n.length;r--;)o.call(this,t,n[r]);else for(r in t)t.hasOwnProperty(r)&&(i=t[r])&&("function"==typeof i?o.call(this,r,i):a.call(this,r,i));return this},l.removeEvent=function(e){var t,n=typeof e,r=this._getEvents();if("string"===n)delete r[e];else if(e instanceof RegExp)for(t in r)r.hasOwnProperty(t)&&e.test(t)&&delete r[t];else delete this._events;return this},l.removeAllListeners=o("removeEvent"),l.emitEvent=function(e,t){var n,r,i,o,a=this.getListenersAsObject(e);for(o in a)if(a.hasOwnProperty(o))for(n=a[o].slice(0),i=0;i<n.length;i++)r=n[i],r.once===!0&&this.removeListener(e,r.listener),r.listener.apply(this,t||[])===this._getOnceReturnValue()&&this.removeListener(e,r.listener);return this},l.trigger=o("emitEvent"),l.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},l.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},l._getOnceReturnValue=function(){return!this.hasOwnProperty("_onceReturnValue")||this._onceReturnValue},l._getEvents=function(){return this._events||(this._events={})},r.noConflict=function(){return e.EventEmitter=s,r},"function"==typeof t&&t.amd?t(function(){return r}):"object"==typeof n&&n.exports?n.exports=r:e.EventEmitter=r}(this||{})},{}]},{},[1])}();
 
2
  //# sourceMappingURL=admin.min.js.map
1
+ !function(){var e=void 0,t=void 0;!function t(n,r,i){function o(l,s){if(!r[l]){if(!n[l]){var u="function"==typeof e&&e;if(!s&&u)return u(l,!0);if(a)return a(l,!0);var c=new Error("Cannot find module '"+l+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[l]={exports:{}};n[l][0].call(f.exports,function(e){var t=n[l][1][e];return o(t||e)},f,f.exports,t,n,r,i)}return r[l].exports}for(var a="function"==typeof e&&e,l=0;l<i.length;l++)o(i[l]);return o}({1:[function(e,t,n){"use strict";var r=window.m=e("mithril"),i=e("wolfy87-eventemitter"),o=document.getElementById("mc4wp-admin"),a=new i,l=e("./admin/tabs.js")(o),s=e("./admin/helpers.js"),u=e("./admin/settings.js")(o,s,a),c=e("./admin/list-fetcher.js"),f=document.getElementById("mc4wp-list-fetcher");f&&r.mount(f,new c),window.mc4wp=window.mc4wp||{},window.mc4wp.deps=window.mc4wp.deps||{},window.mc4wp.deps.mithril=r,window.mc4wp.helpers=s,window.mc4wp.events=a,window.mc4wp.settings=u,window.mc4wp.tabs=l},{"./admin/helpers.js":2,"./admin/list-fetcher.js":3,"./admin/settings.js":4,"./admin/tabs.js":5,mithril:7,"wolfy87-eventemitter":8}],2:[function(e,t,n){"use strict";var r={};r.toggleElement=function(e){for(var t=document.querySelectorAll(e),n=0;n<t.length;n++){var r=t[n].clientHeight<=0;t[n].style.display=r?"":"none"}},r.bindEventToElement=function(e,t,n){e.addEventListener?e.addEventListener(t,n):e.attachEvent&&e.attachEvent("on"+t,n)},r.bindEventToElements=function(e,t,n){Array.prototype.forEach.call(e,function(e){r.bindEventToElement(e,t,n)})},r.debounce=function(e,t,n){var r;return function(){var i=this,o=arguments,a=function(){r=null,n||e.apply(i,o)},l=n&&!r;clearTimeout(r),r=setTimeout(a,t),l&&e.apply(i,o)}},function(){var e=document.querySelectorAll("[data-showif]");Array.prototype.forEach.call(e,function(e){function t(){if("radio"!==this.getAttribute("type")||this.checked){var t="checkbox"===this.getAttribute("type")?this.checked:this.value,r=t==n.value;a?(e.style.display=r?"":"none",e.style.visibility=r?"":"hidden"):e.style.opacity=r?"":"0.4",Array.prototype.forEach.call(o,function(e){r?e.removeAttribute("readonly"):e.setAttribute("readonly","readonly")})}}var n=JSON.parse(e.getAttribute("data-showif")),i=document.querySelectorAll('[name="'+n.element+'"]'),o=e.querySelectorAll("input,select,textarea:not([readonly])"),a=void 0===n.hide||n.hide;Array.prototype.forEach.call(i,function(e){t.call(e)}),r.bindEventToElements(i,"change",t)})}(),t.exports=r},{}],3:[function(e,t,n){"use strict";function r(){this.working=!1,this.done=!1,o.mailchimp.api_connected&&0==o.mailchimp.lists.length&&this.fetch()}var i=window.jQuery,o=mc4wp_vars,a=o.i18n;r.prototype.fetch=function(e){e&&e.preventDefault(),this.working=!0,this.done=!1,i.post(ajaxurl,{action:"mc4wp_renew_mailchimp_lists"}).done(function(e){e&&window.setTimeout(function(){window.location.reload()},3e3)}).always(function(e){this.working=!1,this.done=!0,m.redraw()}.bind(this))},r.prototype.view=function(){return m("form",{method:"POST",onsubmit:this.fetch.bind(this)},[m("p",[m("input",{type:"submit",value:this.working?a.fetching_mailchimp_lists:a.renew_mailchimp_lists,className:"button",disabled:!!this.working}),m.trust(" &nbsp; "),this.working?[m("span.mc4wp-loader","Loading..."),m.trust(" &nbsp; "),m("em.help",a.fetching_mailchimp_lists_can_take_a_while)]:"",this.done?[m("em.help.green",a.fetching_mailchimp_lists_done)]:""])])},t.exports=r},{}],4:[function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e,t,n){function i(e,t){return c.filter(function(n){return n[e]===t})}function o(){return c}function a(){return c=[],Array.prototype.forEach.call(s,function(e){("boolean"!=typeof e.checked||e.checked)&&"object"===r(u[e.value])&&c.push(u[e.value])}),n.trigger("selectedLists.change",[c]),c}function l(){var e=document.querySelectorAll(".lists--only-selected > *");Array.prototype.forEach.call(e,function(e){i("id",e.getAttribute("data-list-id")).length>0?e.setAttribute("class",e.getAttribute("class").replace("hidden","")):e.setAttribute("class",e.getAttribute("class")+" hidden")})}var s=(e.querySelector("form"),e.querySelectorAll(".mc4wp-list-input")),u=mc4wp_vars.mailchimp.lists,c=[];return n.on("selectedLists.change",l),t.bindEventToElements(s,"change",a),a(),{getSelectedLists:o}};t.exports=i},{}],5:[function(e,t,n){"use strict";var r=e("./url.js"),i=function(e){function t(e){for(var t=0;t<f.length;t++)if(f[t].id===e)return f[t]}function n(e,n){if("string"==typeof e&&(e=t(e)),!e)return!1;void 0==n&&(n=!0),s.removeClass("tab-active").css("display","none"),u.removeClass("nav-tab-active"),Array.prototype.forEach.call(e.nav,function(e){e.className+=" nav-tab-active",e.blur()}),e.element.style.display="block",e.element.className+=" tab-active";var o=r.setParameter(window.location.href,"tab",e.id);return history.pushState&&n&&history.pushState(e.id,"",o),i(e),c.value=o,"function"==typeof tb_remove&&tb_remove(),"fields"===e.id&&window.mc4wp&&window.mc4wp.forms&&window.mc4wp.forms.editor&&mc4wp.forms.editor.refresh(),!0}function i(e){var t=document.title.split("-");document.title=document.title.replace(t[0],e.title+" ")}function o(e){e=e||window.event;var t=this.getAttribute("data-tab");if(!t){var i=this.className.match(/nav-tab-(\w+)?/);i&&(t=i[1])}if(!t){var o=r.parse(this.href);if(!o.tab)return;t=o.tab}return!n(t)||(e.preventDefault(),e.returnValue=!1,!1)}var a=window.jQuery,l=a(e),s=l.find(".tab"),u=l.find(".nav-tab"),c=e.querySelector('input[name="_wp_http_referer"]'),f=[];return a.each(s,function(t,r){var i=r.id.substring(4),o=a(r).find("h2").first().text();f.push({id:i,title:o,element:r,nav:e.querySelectorAll(".nav-tab-"+i),open:function(){return n(i)}})}),u.click(o),a(document.body).on("click",".tab-link",o),function(){if(history.pushState){var e=s.filter(":visible").get(0);if(e){var n=t(e.id.substring(4));n&&(history.replaceState&&null===history.state&&history.replaceState(n.id,""),i(n))}}}(),window.addEventListener&&history.pushState&&window.addEventListener("popstate",function(e){return!e.state||n(e.state,!1)}),{open:n,get:t}};t.exports=i},{"./url.js":6}],6:[function(e,t,n){"use strict";var r={parse:function(e){var t={},n=e.split("&");for(var r in n)if(n.hasOwnProperty(r)){var i=n[r].split("=");t[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return t},build:function(e){var t=[];for(var n in e)t.push(n+"="+encodeURIComponent(e[n]));return t.join("&")},setParameter:function(e,t,n){var i=r.parse(e);return i[t]=n,r.build(i)}};t.exports=r},{}],7:[function(e,t,n){(function(e){!function(){"use strict";function n(e,t,n,r,i,o){return{tag:e,key:t,attrs:n,children:r,text:i,dom:o,domSize:void 0,state:void 0,_state:void 0,events:void 0,instance:void 0,skip:!1}}function r(e){for(var t,n="div",r=[],i={};t=l.exec(e);){var o=t[1],a=t[2];if(""===o&&""!==a)n=a;else if("#"===o)i.id=a;else if("."===o)r.push(a);else if("["===t[3][0]){var u=t[6];u&&(u=u.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===t[4]?r.push(u):i[t[4]]=u||!0}}return r.length>0&&(i.className=r.join(" ")),s[e]={tag:n,attrs:i}}function i(e,t,r){var i,o,a=!1,l=t.className||t.class;for(var s in e.attrs)u.call(e.attrs,s)&&(t[s]=e.attrs[s]);void 0!==l&&(void 0!==t.class&&(t.class=void 0,t.className=l),null!=e.attrs.className&&(t.className=e.attrs.className+" "+l));for(var s in t)if(u.call(t,s)&&"key"!==s){a=!0;break}return Array.isArray(r)&&1===r.length&&null!=r[0]&&"#"===r[0].tag?o=r[0].children:i=r,n(e.tag,t.key,a?t:void 0,i,o)}function o(e){var t,o=arguments[1],a=2;if(null==e||"string"!=typeof e&&"function"!=typeof e&&"function"!=typeof e.view)throw Error("The selector must be either a string or a component.");if("string"==typeof e)var l=s[e]||r(e);if(null==o?o={}:("object"!=typeof o||null!=o.tag||Array.isArray(o))&&(o={},a=1),arguments.length===a+1)t=arguments[a],Array.isArray(t)||(t=[t]);else for(t=[];a<arguments.length;)t.push(arguments[a++]);var u=n.normalizeChildren(t);return"string"==typeof e?i(l,o,u):n(e,o.key,o,u)}function a(e){var t=0,n=null,r="function"==typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var i=Date.now();0===t||i-t>=16?(t=i,e()):null===n&&(n=r(function(){n=null,e(),t=Date.now()},16-(i-t)))}}n.normalize=function(e){return Array.isArray(e)?n("[",void 0,void 0,n.normalizeChildren(e),void 0,void 0):null!=e&&"object"!=typeof e?n("#",void 0,void 0,!1===e?"":e,void 0,void 0):e},n.normalizeChildren=function(e){for(var t=0;t<e.length;t++)e[t]=n.normalize(e[t]);return e};var l=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,s={},u={}.hasOwnProperty;o.trust=function(e){return null==e&&(e=""),n("<",void 0,void 0,e,void 0,void 0)},o.fragment=function(e,t){return n("[",e.key,e,n.normalizeChildren(t),void 0,void 0)};var c=o,f=function(e){function t(e,t){return function a(c){var f;try{if(!t||null==c||"object"!=typeof c&&"function"!=typeof c||"function"!=typeof(f=c.then))u(function(){t||0!==e.length||console.error("Possible unhandled promise rejection:",c);for(var n=0;n<e.length;n++)e[n](c);i.length=0,o.length=0,s.state=t,s.retry=function(){a(c)}});else{if(c===r)throw new TypeError("Promise can't be resolved w/ itself");n(f.bind(c))}}catch(e){l(e)}}}function n(e){function t(e){return function(t){n++>0||e(t)}}var n=0,r=t(l);try{e(t(a),r)}catch(e){r(e)}}if(!(this instanceof f))throw new Error("Promise must be called with `new`");if("function"!=typeof e)throw new TypeError("executor must be a function");var r=this,i=[],o=[],a=t(i,!0),l=t(o,!1),s=r._instance={resolvers:i,rejectors:o},u="function"==typeof setImmediate?setImmediate:setTimeout;n(e)};if(f.prototype.then=function(e,t){function n(e,t,n,o){t.push(function(t){if("function"!=typeof e)n(t);else try{r(e(t))}catch(e){i&&i(e)}}),"function"==typeof a.retry&&o===a.state&&a.retry()}var r,i,o=this,a=o._instance,l=new f(function(e,t){r=e,i=t});return n(e,a.resolvers,r,!0),n(t,a.rejectors,i,!1),l},f.prototype.catch=function(e){return this.then(null,e)},f.resolve=function(e){return e instanceof f?e:new f(function(t){t(e)})},f.reject=function(e){return new f(function(t,n){n(e)})},f.all=function(e){return new f(function(t,n){var r=e.length,i=0,o=[];if(0===e.length)t([]);else for(var a=0;a<e.length;a++)!function(a){function l(e){i++,o[a]=e,i===r&&t(o)}null==e[a]||"object"!=typeof e[a]&&"function"!=typeof e[a]||"function"!=typeof e[a].then?l(e[a]):e[a].then(l,n)}(a)})},f.race=function(e){return new f(function(t,n){for(var r=0;r<e.length;r++)e[r].then(t,n)})},"undefined"!=typeof window){void 0===window.Promise&&(window.Promise=f);var f=window.Promise}else if(void 0!==e){void 0===e.Promise&&(e.Promise=f);var f=e.Promise}var d=function(e){function t(e,r){if(Array.isArray(r))for(var i=0;i<r.length;i++)t(e+"["+i+"]",r[i]);else if("[object Object]"===Object.prototype.toString.call(r))for(var i in r)t(e+"["+i+"]",r[i]);else n.push(encodeURIComponent(e)+(null!=r&&""!==r?"="+encodeURIComponent(r):""))}if("[object Object]"!==Object.prototype.toString.call(e))return"";var n=[];for(var r in e)t(r,e[r]);return n.join("&")},h=new RegExp("^file://","i"),v=function(e,t){function n(e){v=e}function r(){function e(){0==--t&&"function"==typeof v&&v()}var t=0;return function n(r){var i=r.then;return r.then=function(){t++;var o=i.apply(r,arguments);return o.then(e,function(n){if(e(),0===t)throw n}),n(o)},r}}function i(e,t){if("string"==typeof e){var n=e;e=t||{},null==e.url&&(e.url=n)}return e}function o(n,o){var a=r();n=i(n,o);var d=new t(function(t,r){null==n.method&&(n.method="GET"),n.method=n.method.toUpperCase();var i="GET"!==n.method&&"TRACE"!==n.method&&("boolean"!=typeof n.useBody||n.useBody);"function"!=typeof n.serialize&&(n.serialize="undefined"!=typeof FormData&&n.data instanceof FormData?function(e){return e}:JSON.stringify),"function"!=typeof n.deserialize&&(n.deserialize=u),"function"!=typeof n.extract&&(n.extract=c),n.url=l(n.url,n.data),i?n.data=n.serialize(n.data):n.url=s(n.url,n.data);var o=new e.XMLHttpRequest,a=!1,d=o.abort;o.abort=function(){a=!0,d.call(o)},o.open(n.method,n.url,"boolean"!=typeof n.async||n.async,"string"==typeof n.user?n.user:void 0,"string"==typeof n.password?n.password:void 0),n.serialize===JSON.stringify&&i&&o.setRequestHeader("Content-Type","application/json; charset=utf-8"),n.deserialize===u&&o.setRequestHeader("Accept","application/json, text/*"),n.withCredentials&&(o.withCredentials=n.withCredentials);for(var v in n.headers)({}).hasOwnProperty.call(n.headers,v)&&o.setRequestHeader(v,n.headers[v]);"function"==typeof n.config&&(o=n.config(o,n)||o),o.onreadystatechange=function(){if(!a&&4===o.readyState)try{var e=n.extract!==c?n.extract(o,n):n.deserialize(n.extract(o,n));if(o.status>=200&&o.status<300||304===o.status||h.test(n.url))t(f(n.type,e));else{var i=new Error(o.responseText);for(var l in e)i[l]=e[l];r(i)}}catch(e){r(e)}},i&&null!=n.data?o.send(n.data):o.send()});return!0===n.background?d:a(d)}function a(n,o){var a=r();n=i(n,o);var u=new t(function(t,r){var i=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+p++,o=e.document.createElement("script");e[i]=function(r){o.parentNode.removeChild(o),t(f(n.type,r)),delete e[i]},o.onerror=function(){o.parentNode.removeChild(o),r(new Error("JSONP request failed")),delete e[i]},null==n.data&&(n.data={}),n.url=l(n.url,n.data),n.data[n.callbackKey||"callback"]=i,o.src=s(n.url,n.data),e.document.documentElement.appendChild(o)});return!0===n.background?u:a(u)}function l(e,t){if(null==t)return e;for(var n=e.match(/:[^\/]+/gi)||[],r=0;r<n.length;r++){var i=n[r].slice(1);null!=t[i]&&(e=e.replace(n[r],t[i]))}return e}function s(e,t){var n=d(t);if(""!==n){e+=(e.indexOf("?")<0?"?":"&")+n}return e}function u(e){try{return""!==e?JSON.parse(e):null}catch(t){throw new Error(e)}}function c(e){return e.responseText}function f(e,t){if("function"==typeof e){if(!Array.isArray(t))return new e(t);for(var n=0;n<t.length;n++)t[n]=new e(t[n])}return t}var v,p=0;return{request:o,jsonp:a,setCompletionCallback:n}}(window,f),p=function(e){function t(e){return V=e}function r(e,t,n,r,o,a,l){for(var s=n;s<r;s++){var u=t[s];null!=u&&i(e,u,o,l,a)}}function i(e,t,n,r,i){var u=t.tag;if("string"!=typeof u)return c(e,t,n,r,i);switch(t.state={},null!=t.attrs&&M(t.attrs,t,n),u){case"#":return o(e,t,i);case"<":return a(e,t,i);case"[":return l(e,t,n,r,i);default:return s(e,t,n,r,i)}}function o(e,t,n){return t.dom=H.createTextNode(t.children),E(e,t.dom,n),t.dom}function a(e,t,n){var r=t.children.match(/^\s*?<(\w+)/im)||[],i={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[r[1]]||"div",o=H.createElement(i);o.innerHTML=t.children,t.dom=o.firstChild,t.domSize=o.childNodes.length;for(var a,l=H.createDocumentFragment();a=o.firstChild;)l.appendChild(a);return E(e,l,n),l}function l(e,t,n,i,o){var a=H.createDocumentFragment();if(null!=t.children){var l=t.children;r(a,l,0,l.length,n,null,i)}return t.dom=a.firstChild,t.domSize=a.childNodes.length,E(e,a,o),a}function s(e,t,i,o,a){var l=t.tag;switch(t.tag){case"svg":o="http://www.w3.org/2000/svg";break;case"math":o="http://www.w3.org/1998/Math/MathML"}var s=t.attrs,u=s&&s.is,c=o?u?H.createElementNS(o,l,{is:u}):H.createElementNS(o,l):u?H.createElement(l,{is:u}):H.createElement(l);if(t.dom=c,null!=s&&j(t,s,o),E(e,c,a),null!=t.attrs&&null!=t.attrs.contenteditable)A(t);else if(null!=t.text&&(""!==t.text?c.textContent=t.text:t.children=[n("#",void 0,void 0,t.text,void 0,void 0)]),null!=t.children){var f=t.children;r(c,f,0,f.length,i,null,o),O(t)}return c}function u(e,t){var r;if("function"==typeof e.tag.view){if(e.state=Object.create(e.tag),r=e.state.view,null!=r.$$reentrantLock$$)return B;r.$$reentrantLock$$=!0}else{if(e.state=void 0,r=e.tag,null!=r.$$reentrantLock$$)return B;r.$$reentrantLock$$=!0,e.state=null!=e.tag.prototype&&"function"==typeof e.tag.prototype.view?new e.tag(e):e.tag(e)}if(e._state=e.state,null!=e.attrs&&M(e.attrs,e,t),M(e._state,e,t),e.instance=n.normalize(e._state.view.call(e.state,e)),e.instance===e)throw Error("A view cannot return the vnode it received as argument");r.$$reentrantLock$$=null}function c(e,t,n,r,o){if(u(t,n),null!=t.instance){var a=i(e,t.instance,n,r,o);return t.dom=t.instance.dom,t.domSize=null!=t.dom?t.instance.domSize:0,E(e,a,o),a}return t.domSize=0,B}function f(e,t,n,o,a,l,s){if(t!==n&&(null!=t||null!=n))if(null==t)r(e,n,0,n.length,a,l,void 0);else if(null==n)k(t,0,t.length,n);else{if(t.length===n.length){for(var u=!1,c=0;c<n.length;c++)if(null!=n[c]&&null!=t[c]){u=null==n[c].key&&null==t[c].key;break}if(u){for(var c=0;c<t.length;c++)t[c]!==n[c]&&(null==t[c]&&null!=n[c]?i(e,n[c],a,s,x(t,c+1,l)):null==n[c]?k(t,c,c+1,n):d(e,t[c],n[c],a,x(t,c+1,l),o,s));return}}if(o=o||g(t,n)){var f=t.pool;t=t.concat(t.pool)}for(var h,v=0,p=0,m=t.length-1,y=n.length-1;m>=v&&y>=p;){var A=t[v],S=n[p];if(A!==S||o)if(null==A)v++;else if(null==S)p++;else if(A.key===S.key){var _=null!=f&&v>=t.length-f.length||null==f&&o;v++,p++,d(e,A,S,a,x(t,v,l),_,s),o&&A.tag===S.tag&&E(e,b(A),l)}else{var A=t[m];if(A!==S||o)if(null==A)m--;else if(null==S)p++;else{if(A.key!==S.key)break;var _=null!=f&&m>=t.length-f.length||null==f&&o;d(e,A,S,a,x(t,m+1,l),_,s),(o||p<y)&&E(e,b(A),x(t,v,l)),m--,p++}else m--,p++}else v++,p++}for(;m>=v&&y>=p;){var A=t[m],S=n[y];if(A!==S||o)if(null==A)m--;else if(null==S)y--;else if(A.key===S.key){var _=null!=f&&m>=t.length-f.length||null==f&&o;d(e,A,S,a,x(t,m+1,l),_,s),o&&A.tag===S.tag&&E(e,b(A),l),null!=A.dom&&(l=A.dom),m--,y--}else{if(h||(h=w(t,m)),null!=S){var L=h[S.key];if(null!=L){var j=t[L],_=null!=f&&L>=t.length-f.length||null==f&&o;d(e,j,S,a,x(t,m+1,l),o,s),E(e,b(j),l),t[L].skip=!0,null!=j.dom&&(l=j.dom)}else{var C=i(e,S,a,void 0,l);l=C}}y--}else m--,y--;if(y<p)break}r(e,n,p,y+1,a,l,s),k(t,v,m+1,n)}}function d(e,t,n,r,o,a,l){var s=t.tag;if(s===n.tag){if(n.state=t.state,n._state=t._state,n.events=t.events,!a&&U(n,t))return;if("string"==typeof s)switch(null!=n.attrs&&(a?(n.state={},M(n.attrs,n,r)):D(n.attrs,n,r)),s){case"#":h(t,n);break;case"<":v(e,t,n,o);break;case"[":p(e,t,n,a,r,o,l);break;default:m(t,n,a,r,l)}else y(e,t,n,r,o,a,l)}else S(t,null),i(e,n,r,l,o)}function h(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children),t.dom=e.dom}function v(e,t,n,r){t.children!==n.children?(b(t),a(e,n,r)):(n.dom=t.dom,n.domSize=t.domSize)}function p(e,t,n,r,i,o,a){f(e,t.children,n.children,r,i,o,a);var l=0,s=n.children;if(n.dom=null,null!=s){for(var u=0;u<s.length;u++){var c=s[u];null!=c&&null!=c.dom&&(null==n.dom&&(n.dom=c.dom),l+=c.domSize||1)}1!==l&&(n.domSize=l)}}function m(e,t,r,i,o){var a=t.dom=e.dom;switch(t.tag){case"svg":o="http://www.w3.org/2000/svg";break;case"math":o="http://www.w3.org/1998/Math/MathML"}"textarea"===t.tag&&(null==t.attrs&&(t.attrs={}),null!=t.text&&(t.attrs.value=t.text,t.text=void 0)),z(t,e.attrs,t.attrs,o),null!=t.attrs&&null!=t.attrs.contenteditable?A(t):null!=e.text&&null!=t.text&&""!==t.text?e.text.toString()!==t.text.toString()&&(e.dom.firstChild.nodeValue=t.text):(null!=e.text&&(e.children=[n("#",void 0,void 0,e.text,void 0,e.dom.firstChild)]),null!=t.text&&(t.children=[n("#",void 0,void 0,t.text,void 0,void 0)]),f(a,e.children,t.children,r,i,null,o))}function y(e,t,r,o,a,l,s){if(l)u(r,o);else{if(r.instance=n.normalize(r._state.view.call(r.state,r)),r.instance===r)throw Error("A view cannot return the vnode it received as argument");null!=r.attrs&&D(r.attrs,r,o),D(r._state,r,o)}null!=r.instance?(null==t.instance?i(e,r.instance,o,s,a):d(e,t.instance,r.instance,o,a,l,s),r.dom=r.instance.dom,r.domSize=r.instance.domSize):null!=t.instance?(S(t.instance,null),r.dom=void 0,r.domSize=0):(r.dom=t.dom,r.domSize=t.domSize)}function g(e,t){if(null!=e.pool&&Math.abs(e.pool.length-t.length)<=Math.abs(e.length-t.length)){var n=e[0]&&e[0].children&&e[0].children.length||0,r=e.pool[0]&&e.pool[0].children&&e.pool[0].children.length||0,i=t[0]&&t[0].children&&t[0].children.length||0;if(Math.abs(r-i)<=Math.abs(n-i))return!0}return!1}function w(e,t){for(var n={},r=0,r=0;r<t;r++){var i=e[r];if(null!=i){var o=i.key;null!=o&&(n[o]=r)}}return n}function b(e){var t=e.domSize;if(null!=t||null==e.dom){var n=H.createDocumentFragment();if(t>0){for(var r=e.dom;--t;)n.appendChild(r.nextSibling);n.insertBefore(r,n.firstChild)}return n}return e.dom}function x(e,t,n){for(;t<e.length;t++)if(null!=e[t]&&null!=e[t].dom)return e[t].dom;return n}function E(e,t,n){n&&n.parentNode?e.insertBefore(t,n):e.appendChild(t)}function A(e){var t=e.children;if(null!=t&&1===t.length&&"<"===t[0].tag){var n=t[0].children;e.dom.innerHTML!==n&&(e.dom.innerHTML=n)}else if(null!=e.text||null!=t&&0!==t.length)throw new Error("Child node of a contenteditable must be trusted")}function k(e,t,n,r){for(var i=t;i<n;i++){var o=e[i];null!=o&&(o.skip?o.skip=!1:S(o,r))}}function S(e,t){function n(){if(++i===r&&(L(e),e.dom)){var n=e.domSize||1;if(n>1)for(var o=e.dom;--n;)_(o.nextSibling);_(e.dom),null==t||null!=e.domSize||$(e.attrs)||"string"!=typeof e.tag||(t.pool?t.pool.push(e):t.pool=[e])}}var r=1,i=0;if(e.attrs&&"function"==typeof e.attrs.onbeforeremove){var o=e.attrs.onbeforeremove.call(e.state,e);null!=o&&"function"==typeof o.then&&(r++,o.then(n,n))}if("string"!=typeof e.tag&&"function"==typeof e._state.onbeforeremove){var o=e._state.onbeforeremove.call(e.state,e);null!=o&&"function"==typeof o.then&&(r++,o.then(n,n))}n()}function _(e){var t=e.parentNode;null!=t&&t.removeChild(e)}function L(e){if(e.attrs&&"function"==typeof e.attrs.onremove&&e.attrs.onremove.call(e.state,e),"string"!=typeof e.tag&&"function"==typeof e._state.onremove&&e._state.onremove.call(e.state,e),null!=e.instance)L(e.instance);else{var t=e.children;if(Array.isArray(t))for(var n=0;n<t.length;n++){var r=t[n];null!=r&&L(r)}}}function j(e,t,n){for(var r in t)C(e,r,null,t[r],n)}function C(e,t,n,r,i){var o=e.dom;if("key"!==t&&"is"!==t&&(n!==r||T(e,t)||"object"==typeof r)&&void 0!==r&&!N(t)){var a=t.indexOf(":");if(a>-1&&"xlink"===t.substr(0,a))o.setAttributeNS("http://www.w3.org/1999/xlink",t.slice(a+1),r);else if("o"===t[0]&&"n"===t[1]&&"function"==typeof r)q(e,t,r);else if("style"===t)I(o,n,r);else if(t in o&&!P(t)&&void 0===i&&!R(e)){if("input"===e.tag&&"value"===t&&e.dom.value==r&&e.dom===H.activeElement)return;if("select"===e.tag&&"value"===t&&e.dom.value==r&&e.dom===H.activeElement)return;if("option"===e.tag&&"value"===t&&e.dom.value==r)return;if("input"===e.tag&&"type"===t)return void o.setAttribute(t,r);o[t]=r}else"boolean"==typeof r?r?o.setAttribute(t,""):o.removeAttribute(t):o.setAttribute("className"===t?"class":t,r)}}function O(e){var t=e.attrs;"select"===e.tag&&null!=t&&("value"in t&&C(e,"value",null,t.value,void 0),"selectedIndex"in t&&C(e,"selectedIndex",null,t.selectedIndex,void 0))}function z(e,t,n,r){if(null!=n)for(var i in n)C(e,i,t&&t[i],n[i],r);if(null!=t)for(var i in t)null!=n&&i in n||("className"===i&&(i="class"),"o"!==i[0]||"n"!==i[1]||N(i)?"key"!==i&&e.dom.removeAttribute(i):q(e,i,void 0))}function T(e,t){return"value"===t||"checked"===t||"selectedIndex"===t||"selected"===t&&e.dom===H.activeElement}function N(e){return"oninit"===e||"oncreate"===e||"onupdate"===e||"onremove"===e||"onbeforeremove"===e||"onbeforeupdate"===e}function P(e){return"href"===e||"list"===e||"form"===e||"width"===e||"height"===e}function R(e){return e.attrs.is||e.tag.indexOf("-")>-1}function $(e){return null!=e&&(e.oncreate||e.onupdate||e.onbeforeremove||e.onremove)}function I(e,t,n){if(t===n&&(e.style.cssText="",t=null),null==n)e.style.cssText="";else if("string"==typeof n)e.style.cssText=n;else{"string"==typeof t&&(e.style.cssText="");for(var r in n)e.style[r]=n[r];if(null!=t&&"string"!=typeof t)for(var r in t)r in n||(e.style[r]="")}}function q(e,t,n){var r=e.dom,i="function"!=typeof V?n:function(e){var t=n.call(r,e);return V.call(r,e),t};if(t in r)r[t]="function"==typeof n?i:null;else{var o=t.slice(2);if(void 0===e.events&&(e.events={}),e.events[t]===i)return;null!=e.events[t]&&r.removeEventListener(o,e.events[t],!1),"function"==typeof n&&(e.events[t]=i,r.addEventListener(o,e.events[t],!1))}}function M(e,t,n){"function"==typeof e.oninit&&e.oninit.call(t.state,t),"function"==typeof e.oncreate&&n.push(e.oncreate.bind(t.state,t))}function D(e,t,n){"function"==typeof e.onupdate&&n.push(e.onupdate.bind(t.state,t))}function U(e,t){var n,r;return null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate&&(n=e.attrs.onbeforeupdate.call(e.state,e,t)),"string"!=typeof e.tag&&"function"==typeof e._state.onbeforeupdate&&(r=e._state.onbeforeupdate.call(e.state,e,t)),!(void 0===n&&void 0===r||n||r)&&(e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,!0)}function F(e,t){if(!e)throw new Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var r=[],i=H.activeElement;null==e.vnodes&&(e.textContent=""),Array.isArray(t)||(t=[t]),f(e,e.vnodes,n.normalizeChildren(t),!1,r,null,void 0),e.vnodes=t;for(var o=0;o<r.length;o++)r[o]();H.activeElement!==i&&i.focus()}var V,H=e.document,B=H.createDocumentFragment();return{render:F,setEventCallback:t}},m=function(e){function t(e,t){n(e),o.push(e,a(t))}function n(e){var t=o.indexOf(e);t>-1&&o.splice(t,2)}function r(){for(var e=1;e<o.length;e+=2)o[e]()}var i=p(e);i.setEventCallback(function(e){!1!==e.redraw&&r()});var o=[];return{subscribe:t,unsubscribe:n,redraw:r,render:i.render}}(window);v.setCompletionCallback(m.redraw);c.mount=function(e){return function(t,r){if(null===r)return e.render(t,[]),void e.unsubscribe(t);if(null==r.view&&"function"!=typeof r)throw new Error("m.mount(element, component) expects a component, not a vnode");var i=function(){e.render(t,n(r))};e.subscribe(t,i),e.redraw()}}(m);var y=f,g=function(e){if(""===e||null==e)return{};"?"===e.charAt(0)&&(e=e.slice(1));for(var t=e.split("&"),n={},r={},i=0;i<t.length;i++){var o=t[i].split("="),a=decodeURIComponent(o[0]),l=2===o.length?decodeURIComponent(o[1]):"";"true"===l?l=!0:"false"===l&&(l=!1);var s=a.split(/\]\[?|\[/),u=n;a.indexOf("[")>-1&&s.pop();for(var c=0;c<s.length;c++){var f=s[c],d=s[c+1],h=""==d||!isNaN(parseInt(d,10)),v=c===s.length-1;if(""===f){var a=s.slice(0,c).join();null==r[a]&&(r[a]=0),f=r[a]++}null==u[f]&&(u[f]=v?l:h?[]:{}),u=u[f]}}return n},w=function(e){function t(t){var n=e.location[t].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);return"pathname"===t&&"/"!==n[0]&&(n="/"+n),n}function n(e){return function(){null==i&&(i=a(function(){i=null,e()}))}}function r(e,t,n){var r=e.indexOf("?"),i=e.indexOf("#"),o=r>-1?r:i>-1?i:e.length;if(r>-1){var a=i>-1?i:e.length,l=g(e.slice(r+1,a));for(var s in l)t[s]=l[s]}if(i>-1){var u=g(e.slice(i+1));for(var s in u)n[s]=u[s]}return e.slice(0,o)}var i,o="function"==typeof e.history.pushState,a="function"==typeof setImmediate?setImmediate:setTimeout,l={prefix:"#!"};return l.getPath=function(){switch(l.prefix.charAt(0)){case"#":return t("hash").slice(l.prefix.length);case"?":return t("search").slice(l.prefix.length)+t("hash");default:return t("pathname").slice(l.prefix.length)+t("search")+t("hash")}},l.setPath=function(t,n,i){var a={},s={};if(t=r(t,a,s),null!=n){for(var u in n)a[u]=n[u];t=t.replace(/:([^\/]+)/g,function(e,t){return delete a[t],n[t]})}var c=d(a);c&&(t+="?"+c);var f=d(s);if(f&&(t+="#"+f),o){var h=i?i.state:null,v=i?i.title:null;e.onpopstate(),i&&i.replace?e.history.replaceState(h,v,l.prefix+t):e.history.pushState(h,v,l.prefix+t)}else e.location.href=l.prefix+t},l.defineRoutes=function(t,i,a){function s(){var n=l.getPath(),o={},s=r(n,o,o),u=e.history.state;if(null!=u)for(var c in u)o[c]=u[c];for(var f in t){var d=new RegExp("^"+f.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(d.test(s))return void s.replace(d,function(){for(var e=f.match(/:[^\/]+/g)||[],r=[].slice.call(arguments,1,-2),a=0;a<e.length;a++)o[e[a].replace(/:|\./g,"")]=decodeURIComponent(r[a]);i(t[f],o,n,f)})}a(n,o)}o?e.onpopstate=n(s):"#"===l.prefix.charAt(0)&&(e.onhashchange=s),s()},l};c.route=function(e,t){var r,i,o,a,l,s=w(e),u=function(e){return e},c=function(e,c,f){if(null==e)throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined");var d=function(){null!=r&&t.render(e,r(n(i,o.key,o)))},h=function(e){if(e===c)throw new Error("Could not resolve default route "+c);s.setPath(c,null,{replace:!0})};s.defineRoutes(f,function(e,t,n){var s=l=function(e,c){s===l&&(i=null==c||"function"!=typeof c.view&&"function"!=typeof c?"div":c,o=t,a=n,l=null,r=(e.render||u).bind(e),d())};e.view||"function"==typeof e?s({},e):e.onmatch?y.resolve(e.onmatch(t,n)).then(function(t){s(e,t)},h):s(e,"div")},h),t.subscribe(e,d)};return c.set=function(e,t,n){null!=l&&(n={replace:!0}),l=null,s.setPath(e,t,n)},c.get=function(){return a},c.prefix=function(e){s.prefix=e},c.link=function(e){e.dom.setAttribute("href",s.prefix+e.attrs.href),e.dom.onclick=function(e){if(!(e.ctrlKey||e.metaKey||e.shiftKey||2===e.which)){e.preventDefault(),e.redraw=!1;var t=this.getAttribute("href");0===t.indexOf(s.prefix)&&(t=t.slice(s.prefix.length)),c.set(t,void 0,void 0)}}},c.param=function(e){return void 0!==o&&void 0!==e?o[e]:o},c}(window,m),c.withAttr=function(e,t,n){return function(r){t.call(n||this,e in r.currentTarget?r.currentTarget[e]:r.currentTarget.getAttribute(e))}};var b=p(window);c.render=b.render,c.redraw=m.redraw,c.request=v.request,c.jsonp=v.jsonp,c.parseQueryString=g,c.buildQueryString=d,c.version="1.1.1",c.vnode=n,void 0!==t?t.exports=c:window.m=c}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],8:[function(e,n,r){!function(e){"use strict";function r(){}function i(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function o(e){return function(){return this[e].apply(this,arguments)}}function a(e){return"function"==typeof e||e instanceof RegExp||!(!e||"object"!=typeof e)&&a(e.listener)}var l=r.prototype,s=e.EventEmitter;l.getListeners=function(e){var t,n,r=this._getEvents();if(e instanceof RegExp){t={};for(n in r)r.hasOwnProperty(n)&&e.test(n)&&(t[n]=r[n])}else t=r[e]||(r[e]=[]);return t},l.flattenListeners=function(e){var t,n=[];for(t=0;t<e.length;t+=1)n.push(e[t].listener);return n},l.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},l.addListener=function(e,t){if(!a(t))throw new TypeError("listener must be a function");var n,r=this.getListenersAsObject(e),o="object"==typeof t;for(n in r)r.hasOwnProperty(n)&&-1===i(r[n],t)&&r[n].push(o?t:{listener:t,once:!1});return this},l.on=o("addListener"),l.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},l.once=o("addOnceListener"),l.defineEvent=function(e){return this.getListeners(e),this},l.defineEvents=function(e){for(var t=0;t<e.length;t+=1)this.defineEvent(e[t]);return this},l.removeListener=function(e,t){var n,r,o=this.getListenersAsObject(e);for(r in o)o.hasOwnProperty(r)&&-1!==(n=i(o[r],t))&&o[r].splice(n,1);return this},l.off=o("removeListener"),l.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},l.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},l.manipulateListeners=function(e,t,n){var r,i,o=e?this.removeListener:this.addListener,a=e?this.removeListeners:this.addListeners;if("object"!=typeof t||t instanceof RegExp)for(r=n.length;r--;)o.call(this,t,n[r]);else for(r in t)t.hasOwnProperty(r)&&(i=t[r])&&("function"==typeof i?o.call(this,r,i):a.call(this,r,i));return this},l.removeEvent=function(e){var t,n=typeof e,r=this._getEvents();if("string"===n)delete r[e];else if(e instanceof RegExp)for(t in r)r.hasOwnProperty(t)&&e.test(t)&&delete r[t];else delete this._events;return this},l.removeAllListeners=o("removeEvent"),l.emitEvent=function(e,t){var n,r,i,o,a=this.getListenersAsObject(e);for(o in a)if(a.hasOwnProperty(o))for(n=a[o].slice(0),i=0;i<n.length;i++)r=n[i],!0===r.once&&this.removeListener(e,r.listener),
2
+ r.listener.apply(this,t||[])===this._getOnceReturnValue()&&this.removeListener(e,r.listener);return this},l.trigger=o("emitEvent"),l.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},l.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},l._getOnceReturnValue=function(){return!this.hasOwnProperty("_onceReturnValue")||this._onceReturnValue},l._getEvents=function(){return this._events||(this._events={})},r.noConflict=function(){return e.EventEmitter=s,r},"function"==typeof t&&t.amd?t(function(){return r}):"object"==typeof n&&n.exports?n.exports=r:e.EventEmitter=r}(this||{})},{}]},{},[1])}();
3
  //# sourceMappingURL=admin.min.js.map
assets/js/admin.min.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["admin.js"],"names":["require","undefined","define","e","t","n","r","s","o","u","a","i","f","Error","code","l","exports","call","length","1","module","m","window","EventEmitter","context","document","getElementById","events","tabs","helpers","settings","ListFetcher","mount","mc4wp","deps","mithril","./admin/helpers.js","./admin/list-fetcher.js","./admin/settings.js","./admin/tabs.js","wolfy87-eventemitter","2","toggleElement","selector","elements","querySelectorAll","show","clientHeight","style","display","bindEventToElement","element","event","handler","addEventListener","attachEvent","bindEventToElements","Array","prototype","forEach","debounce","func","wait","immediate","timeout","this","args","arguments","later","apply","callNow","clearTimeout","setTimeout","showIfElements","getAttribute","checked","value","conditionMet","config","hide","visibility","opacity","inputs","inputElement","removeAttribute","setAttribute","JSON","parse","parentElements","parentElement","3","working","done","mailchimp","api_connected","lists","fetch","$","jQuery","mc4wp_vars","i18n","preventDefault","post","ajaxurl","action","data","location","reload","always","redraw","bind","view","method","onsubmit","type","fetching_mailchimp_lists","renew_mailchimp_lists","className","disabled","trust","fetching_mailchimp_lists_can_take_a_while","fetching_mailchimp_lists_done","4","_typeof","Symbol","iterator","obj","constructor","Settings","getSelectedListsWhere","searchKey","searchValue","selectedLists","filter","el","getSelectedLists","updateSelectedLists","listInputs","input","push","trigger","toggleVisibleLists","rows","replace","querySelector","on","5","URL","Tabs","get","id","_open","tab","updateState","$tabs","removeClass","css","$tabNavs","nav","blur","url","setParameter","href","history","pushState","title","refererField","tb_remove","forms","editor","refresh","split","switchTab","tabId","match","urlParams","returnValue","$context","find","each","substring","first","text","open","click","body","activeTab","replaceState","state","./url.js","6","query","hasOwnProperty","b","decodeURIComponent","build","ret","d","encodeURIComponent","join","key","7","global","Vnode","tag","attrs0","children","dom","attrs","domSize","instance","skip","hyperscript","selectorCache","classes","attributes","selectorParser","exec","attrValue","childList","hasAttrs","class","isArray","childrenIndex","normalizeChildren","throttle","callback","last","pending","requestAnimationFrame","now","Date","normalize","node","html","fragment","attrs1","PromisePolyfill","executor","list","shouldAbsorb","execute","then","callAsync","console","error","resolvers","rejectors","retry","self","TypeError","executeOnce","rejectCurrent","run","fn","runs","onerror","resolveCurrent","_instance","setImmediate","onFulfilled","onRejection","handle","next","resolveNext","rejectNext","promise","resolve","reject","catch","all","total","count","values","consume","race","Promise","buildQueryString","object","destructure","key0","Object","toString","requestService","$window","setCompletionCallback","oncompletion","finalizer","complete","finalize","promise0","then0","extra","request","toUpperCase","useBody","serialize","FormData","stringify","deserialize","extract","interpolate","assemble","xhr","XMLHttpRequest","async","user","password","setRequestHeader","withCredentials","headers","onreadystatechange","status","readyState","response","cast","responseText","send","background","jsonp","callbackName","Math","round","random","callbackCount","script","createElement","parentNode","removeChild","callbackKey","src","documentElement","appendChild","tokens","slice","querystring","indexOf","type0","coreRenderer","setEventCallback","onevent","createNodes","parent","vnodes","start","end","hooks","nextSibling","ns","vnode","createNode","initLifecycle","createComponent","createText","createHTML","createFragment","$doc","createTextNode","insertNode","match1","parent1","caption","thead","tbody","tfoot","tr","th","td","colgroup","col","temp","innerHTML","firstChild","childNodes","child","createDocumentFragment","attrs2","is","createElementNS","setAttrs","contenteditable","setContentEditable","textContent","setLateAttrs","create","reentrantLock","$emptyFragment","updateNodes","old","recycling","removeNodes","isUnkeyed","getNextSibling","updateNode","isRecyclable","concat","pool","map","oldStart","oldEnd","v","toFragment","getKeyMap","oldIndex","movable","oldTag","shouldUpdate","updateLifecycle","updateText","updateHTML","updateFragment","updateElement","updateComponent","removeNode","nodeValue","updateAttrs","abs","oldChildrenLength","poolChildrenLength","vnodesChildrenLength","key2","count0","insertBefore","content","continuation","called","expected","onremove","removeNodeFromDOM","hasIntegrationMethods","onbeforeremove","result","setAttr","isFormAttribute","isLifecycleMethod","nsLastIndex","substr","setAttributeNS","updateEvent","updateStyle","isAttribute","isCustomElement","activeElement","selectedIndex","attr","source","oncreate","onupdate","cssText","eventName","removeEventListener","oninit","forceVnodeUpdate","forceComponentUpdate","onbeforeupdate","render","active","focus","redrawService","subscribe","key1","unsubscribe","callbacks","index","splice","renderService","redrawService0","root","component","run0","parseQueryString","string","charAt","entries","data0","counters","entry","key5","levels","cursor","pop","j","level","nextLevel","isNumber","isNaN","parseInt","isValue","coreRouter","normalize1","fragment0","debounceAsync","callback0","asyncId","callAsync0","parsePath","path","queryData","hashData","queryIndex","hashIndex","pathEnd","queryEnd","queryParams","key4","hashParams","supportsPushState","router","prefix","getPath","setPath","options","match2","token","hash","onpopstate","defineRoutes","routes","resolveRoute","params","pathname","k","route0","matcher","RegExp","test","keys","onhashchange","route","render1","attrs3","currentPath","lastUpdate","routeService","identity","defaultRoute","run1","bail","payload","update","routeResolver","comp","onmatch","resolved","set","prefix0","link","vnode1","onclick","ctrlKey","metaKey","shiftKey","which","param","key3","withAttr","attrName","callback1","currentTarget","_28","version","8","indexOfListener","listeners","listener","alias","name","isValidListener","proto","originalGlobalValue","getListeners","evt","_getEvents","flattenListeners","flatListeners","getListenersAsObject","addListener","listenerIsWrapped","once","addOnceListener","defineEvent","defineEvents","evts","removeListener","off","addListeners","manipulateListeners","removeListeners","remove","single","multiple","removeEvent","_events","removeAllListeners","emitEvent","listenersMap","_getOnceReturnValue","emit","setOnceReturnValue","_onceReturnValue","noConflict","amd"],"mappings":"CAAA,WAAe,GAAIA,GAAUC,OAAeC,EAASD,QAAW,QAAUE,GAAEC,EAAEC,EAAEC,GAAG,QAASC,GAAEC,EAAEC,GAAG,IAAIJ,EAAEG,GAAG,CAAC,IAAIJ,EAAEI,GAAG,CAAC,GAAIE,GAAkB,kBAATV,IAAqBA,CAAQ,KAAIS,GAAGC,EAAE,MAAOA,GAAEF,GAAE,EAAI,IAAGG,EAAE,MAAOA,GAAEH,GAAE,EAAI,IAAII,GAAE,GAAIC,OAAM,uBAAuBL,EAAE,IAAK,MAAMI,GAAEE,KAAK,mBAAmBF,EAAE,GAAIG,GAAEV,EAAEG,IAAIQ,WAAYZ,GAAEI,GAAG,GAAGS,KAAKF,EAAEC,QAAQ,SAASb,GAAG,GAAIE,GAAED,EAAEI,GAAG,GAAGL,EAAG,OAAOI,GAAEF,EAAEA,EAAEF,I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AAO2Y,GACR,GAAIA,EAAanZ,eAAeQ,GAG5B,IAFA2W,EAAYgC,EAAa3Y,GAAKsI,MAAM,GAE/BnU,EAAI,EAAGA,EAAIwiB,EAAUjiB,OAAQP,IAG9ByiB,EAAWD,EAAUxiB,GAEjByiB,EAASc,QAAS,GAClBjgB,KAAKsgB,eAAeZ,EAAKP,EAASA,UAG3BA,EAASA,SAAS/e,MAAMJ,KAAMC,SAExBD,KAAKmhB,uBAClBnhB,KAAKsgB,eAAeZ,EAAKP,EAASA,SAMlD,OAAOnf,OAMXuf,EAAM5a,QAAUya,EAAM,aAUtBG,EAAM6B,KAAO,SAAc1B,GACvB,GAAIzf,GAAOT,MAAMC,UAAUoR,MAAM7T,KAAKkD,UAAW,EACjD,OAAOF,MAAKihB,UAAUvB,EAAKzf,IAW/Bsf,EAAM8B,mBAAqB,SAA4B1gB,GAEnD,MADAX,MAAKshB,iBAAmB3gB,EACjBX,MAWXuf,EAAM4B,oBAAsB,WACxB,OAAInhB,KAAK+H,eAAe,qBACb/H,KAAKshB,kBAapB/B,EAAMI,WAAa,WACf,MAAO3f,MAAK+gB,UAAY/gB,KAAK+gB,aAQjCzjB,EAAaikB,WAAa,WAEtB,MADAxkB,GAAQO,aAAekiB,EAChBliB,GAIW,kBAAXrB,IAAyBA,EAAOulB,IACvCvlB,EAAO,WACH,MAAOqB,KAGY,gBAAXH,IAAuBA,EAAOJ,QAC1CI,EAAOJ,QAAUO,EAGjBP,EAAQO,aAAeA,GAE7B0C,oBAES","file":"admin.min.js","sourcesContent":["(function () { var require = undefined; var define = undefined; (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\n'use strict';\n\n// dependencies\n\nvar m = window.m = require('mithril');\nvar EventEmitter = require('wolfy87-eventemitter');\n\n// vars\nvar context = document.getElementById('mc4wp-admin');\nvar events = new EventEmitter();\nvar tabs = require('./admin/tabs.js')(context);\nvar helpers = require('./admin/helpers.js');\nvar settings = require('./admin/settings.js')(context, helpers, events);\n\n// list fetcher\nvar ListFetcher = require('./admin/list-fetcher.js');\nvar mount = document.getElementById('mc4wp-list-fetcher');\nif (mount) {\n m.mount(mount, new ListFetcher());\n}\n\n// expose some things\nwindow.mc4wp = window.mc4wp || {};\nwindow.mc4wp.deps = window.mc4wp.deps || {};\nwindow.mc4wp.deps.mithril = m;\nwindow.mc4wp.helpers = helpers;\nwindow.mc4wp.events = events;\nwindow.mc4wp.settings = settings;\nwindow.mc4wp.tabs = tabs;\n\n},{\"./admin/helpers.js\":2,\"./admin/list-fetcher.js\":3,\"./admin/settings.js\":4,\"./admin/tabs.js\":5,\"mithril\":7,\"wolfy87-eventemitter\":8}],2:[function(require,module,exports){\n'use strict';\n\nvar helpers = {};\n\nhelpers.toggleElement = function (selector) {\n\tvar elements = document.querySelectorAll(selector);\n\tfor (var i = 0; i < elements.length; i++) {\n\t\tvar show = elements[i].clientHeight <= 0;\n\t\telements[i].style.display = show ? '' : 'none';\n\t}\n};\n\nhelpers.bindEventToElement = function (element, event, handler) {\n\tif (element.addEventListener) {\n\t\telement.addEventListener(event, handler);\n\t} else if (element.attachEvent) {\n\t\telement.attachEvent('on' + event, handler);\n\t}\n};\n\nhelpers.bindEventToElements = function (elements, event, handler) {\n\tArray.prototype.forEach.call(elements, function (element) {\n\t\thelpers.bindEventToElement(element, event, handler);\n\t});\n};\n\n// polling\nhelpers.debounce = function (func, wait, immediate) {\n\tvar timeout;\n\treturn function () {\n\t\tvar context = this,\n\t\t args = arguments;\n\t\tvar later = function later() {\n\t\t\ttimeout = null;\n\t\t\tif (!immediate) func.apply(context, args);\n\t\t};\n\t\tvar callNow = immediate && !timeout;\n\t\tclearTimeout(timeout);\n\t\ttimeout = setTimeout(later, wait);\n\t\tif (callNow) func.apply(context, args);\n\t};\n};\n\n/**\n * Showif.js\n */\n(function () {\n\tvar showIfElements = document.querySelectorAll('[data-showif]');\n\n\t// dependent elements\n\tArray.prototype.forEach.call(showIfElements, function (element) {\n\t\tvar config = JSON.parse(element.getAttribute('data-showif'));\n\t\tvar parentElements = document.querySelectorAll('[name=\"' + config.element + '\"]');\n\t\tvar inputs = element.querySelectorAll('input,select,textarea:not([readonly])');\n\t\tvar hide = config.hide === undefined || config.hide;\n\n\t\tfunction toggleElement() {\n\n\t\t\t// do nothing with unchecked radio inputs\n\t\t\tif (this.getAttribute('type') === \"radio\" && !this.checked) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvar value = this.getAttribute(\"type\") === \"checkbox\" ? this.checked : this.value;\n\t\t\tvar conditionMet = value == config.value;\n\n\t\t\tif (hide) {\n\t\t\t\telement.style.display = conditionMet ? '' : 'none';\n\t\t\t\telement.style.visibility = conditionMet ? '' : 'hidden';\n\t\t\t} else {\n\t\t\t\telement.style.opacity = conditionMet ? '' : '0.4';\n\t\t\t}\n\n\t\t\t// disable input fields to stop sending their values to server\n\t\t\tArray.prototype.forEach.call(inputs, function (inputElement) {\n\t\t\t\tconditionMet ? inputElement.removeAttribute('readonly') : inputElement.setAttribute('readonly', 'readonly');\n\t\t\t});\n\t\t}\n\n\t\t// find checked element and call toggleElement function\n\t\tArray.prototype.forEach.call(parentElements, function (parentElement) {\n\t\t\ttoggleElement.call(parentElement);\n\t\t});\n\n\t\t// bind on all changes\n\t\thelpers.bindEventToElements(parentElements, 'change', toggleElement);\n\t});\n})();\n\nmodule.exports = helpers;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar $ = window.jQuery;\nvar config = mc4wp_vars;\nvar i18n = config.i18n;\n\nfunction ListFetcher() {\n this.working = false;\n this.done = false;\n\n // start fetching right away when no lists but api key given\n if (config.mailchimp.api_connected && config.mailchimp.lists.length == 0) {\n this.fetch();\n }\n}\n\nListFetcher.prototype.fetch = function (e) {\n e && e.preventDefault();\n\n this.working = true;\n this.done = false;\n\n $.post(ajaxurl, {\n action: \"mc4wp_renew_mailchimp_lists\"\n }).done(function (data) {\n if (data) {\n window.setTimeout(function () {\n window.location.reload();\n }, 3000);\n }\n }).always(function (data) {\n this.working = false;\n this.done = true;\n\n m.redraw();\n }.bind(this));\n};\n\nListFetcher.prototype.view = function () {\n return m('form', {\n method: \"POST\",\n onsubmit: this.fetch.bind(this)\n }, [m('p', [m('input', {\n type: \"submit\",\n value: this.working ? i18n.fetching_mailchimp_lists : i18n.renew_mailchimp_lists,\n className: \"button\",\n disabled: !!this.working\n }), m.trust(' &nbsp; '), this.working ? [m('span.mc4wp-loader', \"Loading...\"), m.trust(' &nbsp; '), m('em.help', i18n.fetching_mailchimp_lists_can_take_a_while)] : '', this.done ? [m('em.help.green', i18n.fetching_mailchimp_lists_done)] : ''])]);\n};\n\nmodule.exports = ListFetcher;\n\n},{}],4:[function(require,module,exports){\n'use strict';\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar Settings = function Settings(context, helpers, events) {\n\t'use strict';\n\n\t// vars\n\n\tvar form = context.querySelector('form');\n\tvar listInputs = context.querySelectorAll('.mc4wp-list-input');\n\tvar lists = mc4wp_vars.mailchimp.lists;\n\tvar selectedLists = [];\n\n\t// functions\n\tfunction getSelectedListsWhere(searchKey, searchValue) {\n\t\treturn selectedLists.filter(function (el) {\n\t\t\treturn el[searchKey] === searchValue;\n\t\t});\n\t}\n\n\tfunction getSelectedLists() {\n\t\treturn selectedLists;\n\t}\n\n\tfunction updateSelectedLists() {\n\t\tselectedLists = [];\n\n\t\tArray.prototype.forEach.call(listInputs, function (input) {\n\t\t\t// skip unchecked checkboxes\n\t\t\tif (typeof input.checked === \"boolean\" && !input.checked) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (_typeof(lists[input.value]) === \"object\") {\n\t\t\t\tselectedLists.push(lists[input.value]);\n\t\t\t}\n\t\t});\n\n\t\tevents.trigger('selectedLists.change', [selectedLists]);\n\t\treturn selectedLists;\n\t}\n\n\tfunction toggleVisibleLists() {\n\t\tvar rows = document.querySelectorAll('.lists--only-selected > *');\n\t\tArray.prototype.forEach.call(rows, function (el) {\n\n\t\t\tvar listId = el.getAttribute('data-list-id');\n\t\t\tvar isSelected = getSelectedListsWhere('id', listId).length > 0;\n\n\t\t\tif (isSelected) {\n\t\t\t\tel.setAttribute('class', el.getAttribute('class').replace('hidden', ''));\n\t\t\t} else {\n\t\t\t\tel.setAttribute('class', el.getAttribute('class') + \" hidden\");\n\t\t\t}\n\t\t});\n\t}\n\n\tevents.on('selectedLists.change', toggleVisibleLists);\n\thelpers.bindEventToElements(listInputs, 'change', updateSelectedLists);\n\n\tupdateSelectedLists();\n\n\treturn {\n\t\tgetSelectedLists: getSelectedLists\n\t};\n};\n\nmodule.exports = Settings;\n\n},{}],5:[function(require,module,exports){\n'use strict';\n\nvar URL = require('./url.js');\n\n// Tabs\nvar Tabs = function Tabs(context) {\n\n\t// TODO: last piece of jQuery... can we get rid of it?\n\tvar $ = window.jQuery;\n\n\tvar $context = $(context);\n\tvar $tabs = $context.find('.tab');\n\tvar $tabNavs = $context.find('.nav-tab');\n\tvar refererField = context.querySelector('input[name=\"_wp_http_referer\"]');\n\tvar tabs = [];\n\n\t$.each($tabs, function (i, t) {\n\t\tvar id = t.id.substring(4);\n\t\tvar title = $(t).find('h2').first().text();\n\n\t\ttabs.push({\n\t\t\tid: id,\n\t\t\ttitle: title,\n\t\t\telement: t,\n\t\t\tnav: context.querySelectorAll('.nav-tab-' + id),\n\t\t\topen: function open() {\n\t\t\t\treturn _open(id);\n\t\t\t}\n\t\t});\n\t});\n\n\tfunction get(id) {\n\n\t\tfor (var i = 0; i < tabs.length; i++) {\n\t\t\tif (tabs[i].id === id) {\n\t\t\t\treturn tabs[i];\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tfunction _open(tab, updateState) {\n\n\t\t// make sure we have a tab object\n\t\tif (typeof tab === \"string\") {\n\t\t\ttab = get(tab);\n\t\t}\n\n\t\tif (!tab) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// should we update state?\n\t\tif (updateState == undefined) {\n\t\t\tupdateState = true;\n\t\t}\n\n\t\t// hide all tabs & remove active class\n\t\t$tabs.removeClass('tab-active').css('display', 'none');\n\t\t$tabNavs.removeClass('nav-tab-active');\n\n\t\t// add `nav-tab-active` to this tab\n\t\tArray.prototype.forEach.call(tab.nav, function (nav) {\n\t\t\tnav.className += \" nav-tab-active\";\n\t\t\tnav.blur();\n\t\t});\n\n\t\t// show target tab\n\t\ttab.element.style.display = 'block';\n\t\ttab.element.className += \" tab-active\";\n\n\t\t// create new URL\n\t\tvar url = URL.setParameter(window.location.href, \"tab\", tab.id);\n\n\t\t// update hash\n\t\tif (history.pushState && updateState) {\n\t\t\thistory.pushState(tab.id, '', url);\n\t\t}\n\n\t\t// update document title\n\t\ttitle(tab);\n\n\t\t// update referer field\n\t\trefererField.value = url;\n\n\t\t// if thickbox is open, close it.\n\t\tif (typeof tb_remove === \"function\") {\n\t\t\ttb_remove();\n\t\t}\n\n\t\t// refresh editor after switching tabs\n\t\t// TODO: decouple this! law of demeter etc.\n\t\tif (tab.id === 'fields' && window.mc4wp && window.mc4wp.forms && window.mc4wp.forms.editor) {\n\t\t\tmc4wp.forms.editor.refresh();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tfunction title(tab) {\n\t\tvar title = document.title.split('-');\n\t\tdocument.title = document.title.replace(title[0], tab.title + \" \");\n\t}\n\n\tfunction switchTab(e) {\n\t\te = e || window.event;\n\n\t\t// get from data attribute\n\t\tvar tabId = this.getAttribute('data-tab');\n\n\t\t// get from classname\n\t\tif (!tabId) {\n\t\t\tvar match = this.className.match(/nav-tab-(\\w+)?/);\n\t\t\tif (match) {\n\t\t\t\ttabId = match[1];\n\t\t\t}\n\t\t}\n\n\t\t// get from href\n\t\tif (!tabId) {\n\t\t\tvar urlParams = URL.parse(this.href);\n\t\t\tif (!urlParams.tab) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttabId = urlParams.tab;\n\t\t}\n\n\t\tvar opened = _open(tabId);\n\n\t\tif (opened) {\n\t\t\te.preventDefault();\n\t\t\te.returnValue = false;\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tfunction init() {\n\n\t\t// check for current tab\n\t\tif (!history.pushState) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar activeTab = $tabs.filter(':visible').get(0);\n\t\tif (!activeTab) {\n\t\t\treturn;\n\t\t}\n\t\tvar tab = get(activeTab.id.substring(4));\n\t\tif (!tab) return;\n\n\t\t// check if tab is in html5 history\n\t\tif (history.replaceState && history.state === null) {\n\t\t\thistory.replaceState(tab.id, '');\n\t\t}\n\n\t\t// update document title\n\t\ttitle(tab);\n\t}\n\n\t$tabNavs.click(switchTab);\n\t$(document.body).on('click', '.tab-link', switchTab);\n\tinit();\n\n\tif (window.addEventListener && history.pushState) {\n\t\twindow.addEventListener('popstate', function (e) {\n\t\t\tif (!e.state) return true;\n\t\t\tvar tabId = e.state;\n\t\t\treturn _open(tabId, false);\n\t\t});\n\t}\n\n\treturn {\n\t\topen: _open,\n\t\tget: get\n\t};\n};\n\nmodule.exports = Tabs;\n\n},{\"./url.js\":6}],6:[function(require,module,exports){\n'use strict';\n\nvar URL = {\n\tparse: function parse(url) {\n\t\tvar query = {};\n\t\tvar a = url.split('&');\n\t\tfor (var i in a) {\n\t\t\tif (!a.hasOwnProperty(i)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvar b = a[i].split('=');\n\t\t\tquery[decodeURIComponent(b[0])] = decodeURIComponent(b[1]);\n\t\t}\n\n\t\treturn query;\n\t},\n\tbuild: function build(data) {\n\t\tvar ret = [];\n\t\tfor (var d in data) {\n\t\t\tret.push(d + \"=\" + encodeURIComponent(data[d]));\n\t\t}return ret.join(\"&\");\n\t},\n\tsetParameter: function setParameter(url, key, value) {\n\t\tvar data = URL.parse(url);\n\t\tdata[key] = value;\n\t\treturn URL.build(data);\n\t}\n};\n\nmodule.exports = URL;\n\n},{}],7:[function(require,module,exports){\n(function (global){\nnew function() {\n\nfunction Vnode(tag, key, attrs0, children, text, dom) {\n\treturn {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false}\n}\nVnode.normalize = function(node) {\n\tif (Array.isArray(node)) return Vnode(\"[\", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)\n\tif (node != null && typeof node !== \"object\") return Vnode(\"#\", undefined, undefined, node === false ? \"\" : node, undefined, undefined)\n\treturn node\n}\nVnode.normalizeChildren = function normalizeChildren(children) {\n\tfor (var i = 0; i < children.length; i++) {\n\t\tchildren[i] = Vnode.normalize(children[i])\n\t}\n\treturn children\n}\nvar selectorParser = /(?:(^|#|\\.)([^#\\.\\[\\]]+))|(\\[(.+?)(?:\\s*=\\s*(\"|'|)((?:\\\\[\"'\\]]|.)*?)\\5)?\\])/g\nvar selectorCache = {}\nfunction hyperscript(selector) {\n\tif (selector == null || typeof selector !== \"string\" && typeof selector.view !== \"function\") {\n\t\tthrow Error(\"The selector must be either a string or a component.\");\n\t}\n\tif (typeof selector === \"string\" && selectorCache[selector] === undefined) {\n\t\tvar match, tag, classes = [], attributes = {}\n\t\twhile (match = selectorParser.exec(selector)) {\n\t\t\tvar type = match[1], value = match[2]\n\t\t\tif (type === \"\" && value !== \"\") tag = value\n\t\t\telse if (type === \"#\") attributes.id = value\n\t\t\telse if (type === \".\") classes.push(value)\n\t\t\telse if (match[3][0] === \"[\") {\n\t\t\t\tvar attrValue = match[6]\n\t\t\t\tif (attrValue) attrValue = attrValue.replace(/\\\\([\"'])/g, \"$1\").replace(/\\\\\\\\/g, \"\\\\\")\n\t\t\t\tif (match[4] === \"class\") classes.push(attrValue)\n\t\t\t\telse attributes[match[4]] = attrValue || true\n\t\t\t}\n\t\t}\n\t\tif (classes.length > 0) attributes.className = classes.join(\" \")\n\t\tselectorCache[selector] = function(attrs, children) {\n\t\t\tvar hasAttrs = false, childList, text\n\t\t\tvar className = attrs.className || attrs.class\n\t\t\tfor (var key in attributes) attrs[key] = attributes[key]\n\t\t\tif (className !== undefined) {\n\t\t\t\tif (attrs.class !== undefined) {\n\t\t\t\t\tattrs.class = undefined\n\t\t\t\t\tattrs.className = className\n\t\t\t\t}\n\t\t\t\tif (attributes.className !== undefined) attrs.className = attributes.className + \" \" + className\n\t\t\t}\n\t\t\tfor (var key in attrs) {\n\t\t\t\tif (key !== \"key\") {\n\t\t\t\t\thasAttrs = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Array.isArray(children) && children.length == 1 && children[0] != null && children[0].tag === \"#\") text = children[0].children\n\t\t\telse childList = children\n\t\t\treturn Vnode(tag || \"div\", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined)\n\t\t}\n\t}\n\tvar attrs, children, childrenIndex\n\tif (arguments[1] == null || typeof arguments[1] === \"object\" && arguments[1].tag === undefined && !Array.isArray(arguments[1])) {\n\t\tattrs = arguments[1]\n\t\tchildrenIndex = 2\n\t}\n\telse childrenIndex = 1\n\tif (arguments.length === childrenIndex + 1) {\n\t\tchildren = Array.isArray(arguments[childrenIndex]) ? arguments[childrenIndex] : [arguments[childrenIndex]]\n\t}\n\telse {\n\t\tchildren = []\n\t\tfor (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i])\n\t}\n\tif (typeof selector === \"string\") return selectorCache[selector](attrs || {}, Vnode.normalizeChildren(children))\n\treturn Vnode(selector, attrs && attrs.key, attrs || {}, Vnode.normalizeChildren(children), undefined, undefined)\n}\nhyperscript.trust = function(html) {\n\tif (html == null) html = \"\"\n\treturn Vnode(\"<\", undefined, undefined, html, undefined, undefined)\n}\nhyperscript.fragment = function(attrs1, children) {\n\treturn Vnode(\"[\", attrs1.key, attrs1, Vnode.normalizeChildren(children), undefined, undefined)\n}\nvar m = hyperscript\n/** @constructor */\nvar PromisePolyfill = function(executor) {\n\tif (!(this instanceof PromisePolyfill)) throw new Error(\"Promise must be called with `new`\")\n\tif (typeof executor !== \"function\") throw new TypeError(\"executor must be a function\")\n\tvar self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false)\n\tvar instance = self._instance = {resolvers: resolvers, rejectors: rejectors}\n\tvar callAsync = typeof setImmediate === \"function\" ? setImmediate : setTimeout\n\tfunction handler(list, shouldAbsorb) {\n\t\treturn function execute(value) {\n\t\t\tvar then\n\t\t\ttry {\n\t\t\t\tif (shouldAbsorb && value != null && (typeof value === \"object\" || typeof value === \"function\") && typeof (then = value.then) === \"function\") {\n\t\t\t\t\tif (value === self) throw new TypeError(\"Promise can't be resolved w/ itself\")\n\t\t\t\t\texecuteOnce(then.bind(value))\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tcallAsync(function() {\n\t\t\t\t\t\tif (!shouldAbsorb && list.length === 0) console.error(\"Possible unhandled promise rejection:\", value)\n\t\t\t\t\t\tfor (var i = 0; i < list.length; i++) list[i](value)\n\t\t\t\t\t\tresolvers.length = 0, rejectors.length = 0\n\t\t\t\t\t\tinstance.state = shouldAbsorb\n\t\t\t\t\t\tinstance.retry = function() {execute(value)}\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\trejectCurrent(e)\n\t\t\t}\n\t\t}\n\t}\n\tfunction executeOnce(then) {\n\t\tvar runs = 0\n\t\tfunction run(fn) {\n\t\t\treturn function(value) {\n\t\t\t\tif (runs++ > 0) return\n\t\t\t\tfn(value)\n\t\t\t}\n\t\t}\n\t\tvar onerror = run(rejectCurrent)\n\t\ttry {then(run(resolveCurrent), onerror)} catch (e) {onerror(e)}\n\t}\n\texecuteOnce(executor)\n}\nPromisePolyfill.prototype.then = function(onFulfilled, onRejection) {\n\tvar self = this, instance = self._instance\n\tfunction handle(callback, list, next, state) {\n\t\tlist.push(function(value) {\n\t\t\tif (typeof callback !== \"function\") next(value)\n\t\t\telse try {resolveNext(callback(value))} catch (e) {if (rejectNext) rejectNext(e)}\n\t\t})\n\t\tif (typeof instance.retry === \"function\" && state === instance.state) instance.retry()\n\t}\n\tvar resolveNext, rejectNext\n\tvar promise = new PromisePolyfill(function(resolve, reject) {resolveNext = resolve, rejectNext = reject})\n\thandle(onFulfilled, instance.resolvers, resolveNext, true), handle(onRejection, instance.rejectors, rejectNext, false)\n\treturn promise\n}\nPromisePolyfill.prototype.catch = function(onRejection) {\n\treturn this.then(null, onRejection)\n}\nPromisePolyfill.resolve = function(value) {\n\tif (value instanceof PromisePolyfill) return value\n\treturn new PromisePolyfill(function(resolve) {resolve(value)})\n}\nPromisePolyfill.reject = function(value) {\n\treturn new PromisePolyfill(function(resolve, reject) {reject(value)})\n}\nPromisePolyfill.all = function(list) {\n\treturn new PromisePolyfill(function(resolve, reject) {\n\t\tvar total = list.length, count = 0, values = []\n\t\tif (list.length === 0) resolve([])\n\t\telse for (var i = 0; i < list.length; i++) {\n\t\t\t(function(i) {\n\t\t\t\tfunction consume(value) {\n\t\t\t\t\tcount++\n\t\t\t\t\tvalues[i] = value\n\t\t\t\t\tif (count === total) resolve(values)\n\t\t\t\t}\n\t\t\t\tif (list[i] != null && (typeof list[i] === \"object\" || typeof list[i] === \"function\") && typeof list[i].then === \"function\") {\n\t\t\t\t\tlist[i].then(consume, reject)\n\t\t\t\t}\n\t\t\t\telse consume(list[i])\n\t\t\t})(i)\n\t\t}\n\t})\n}\nPromisePolyfill.race = function(list) {\n\treturn new PromisePolyfill(function(resolve, reject) {\n\t\tfor (var i = 0; i < list.length; i++) {\n\t\t\tlist[i].then(resolve, reject)\n\t\t}\n\t})\n}\nif (typeof window !== \"undefined\") {\n\tif (typeof window.Promise === \"undefined\") window.Promise = PromisePolyfill\n\tvar PromisePolyfill = window.Promise\n} else if (typeof global !== \"undefined\") {\n\tif (typeof global.Promise === \"undefined\") global.Promise = PromisePolyfill\n\tvar PromisePolyfill = global.Promise\n} else {\n}\nvar buildQueryString = function(object) {\n\tif (Object.prototype.toString.call(object) !== \"[object Object]\") return \"\"\n\tvar args = []\n\tfor (var key0 in object) {\n\t\tdestructure(key0, object[key0])\n\t}\n\treturn args.join(\"&\")\n\tfunction destructure(key0, value) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (var i = 0; i < value.length; i++) {\n\t\t\t\tdestructure(key0 + \"[\" + i + \"]\", value[i])\n\t\t\t}\n\t\t}\n\t\telse if (Object.prototype.toString.call(value) === \"[object Object]\") {\n\t\t\tfor (var i in value) {\n\t\t\t\tdestructure(key0 + \"[\" + i + \"]\", value[i])\n\t\t\t}\n\t\t}\n\t\telse args.push(encodeURIComponent(key0) + (value != null && value !== \"\" ? \"=\" + encodeURIComponent(value) : \"\"))\n\t}\n}\nvar _8 = function($window, Promise) {\n\tvar callbackCount = 0\n\tvar oncompletion\n\tfunction setCompletionCallback(callback) {oncompletion = callback}\n\tfunction finalizer() {\n\t\tvar count = 0\n\t\tfunction complete() {if (--count === 0 && typeof oncompletion === \"function\") oncompletion()}\n\t\treturn function finalize(promise0) {\n\t\t\tvar then0 = promise0.then\n\t\t\tpromise0.then = function() {\n\t\t\t\tcount++\n\t\t\t\tvar next = then0.apply(promise0, arguments)\n\t\t\t\tnext.then(complete, function(e) {\n\t\t\t\t\tcomplete()\n\t\t\t\t\tif (count === 0) throw e\n\t\t\t\t})\n\t\t\t\treturn finalize(next)\n\t\t\t}\n\t\t\treturn promise0\n\t\t}\n\t}\n\tfunction normalize(args, extra) {\n\t\tif (typeof args === \"string\") {\n\t\t\tvar url = args\n\t\t\targs = extra || {}\n\t\t\tif (args.url == null) args.url = url\n\t\t}\n\t\treturn args\n\t}\n\tfunction request(args, extra) {\n\t\tvar finalize = finalizer()\n\t\targs = normalize(args, extra)\n\t\tvar promise0 = new Promise(function(resolve, reject) {\n\t\t\tif (args.method == null) args.method = \"GET\"\n\t\t\targs.method = args.method.toUpperCase()\n\t\t\tvar useBody = typeof args.useBody === \"boolean\" ? args.useBody : args.method !== \"GET\" && args.method !== \"TRACE\"\n\t\t\tif (typeof args.serialize !== \"function\") args.serialize = typeof FormData !== \"undefined\" && args.data instanceof FormData ? function(value) {return value} : JSON.stringify\n\t\t\tif (typeof args.deserialize !== \"function\") args.deserialize = deserialize\n\t\t\tif (typeof args.extract !== \"function\") args.extract = extract\n\t\t\targs.url = interpolate(args.url, args.data)\n\t\t\tif (useBody) args.data = args.serialize(args.data)\n\t\t\telse args.url = assemble(args.url, args.data)\n\t\t\tvar xhr = new $window.XMLHttpRequest()\n\t\t\txhr.open(args.method, args.url, typeof args.async === \"boolean\" ? args.async : true, typeof args.user === \"string\" ? args.user : undefined, typeof args.password === \"string\" ? args.password : undefined)\n\t\t\tif (args.serialize === JSON.stringify && useBody) {\n\t\t\t\txhr.setRequestHeader(\"Content-Type\", \"application/json; charset=utf-8\")\n\t\t\t}\n\t\t\tif (args.deserialize === deserialize) {\n\t\t\t\txhr.setRequestHeader(\"Accept\", \"application/json, text/*\")\n\t\t\t}\n\t\t\tif (args.withCredentials) xhr.withCredentials = args.withCredentials\n\t\t\tfor (var key in args.headers) if ({}.hasOwnProperty.call(args.headers, key)) {\n\t\t\t\txhr.setRequestHeader(key, args.headers[key])\n\t\t\t}\n\t\t\tif (typeof args.config === \"function\") xhr = args.config(xhr, args) || xhr\n\t\t\txhr.onreadystatechange = function() {\n\t\t\t\t// Don't throw errors on xhr.abort(). XMLHttpRequests ends up in a state of\n\t\t\t\t// xhr.status == 0 and xhr.readyState == 4 if aborted after open, but before completion.\n\t\t\t\tif (xhr.status && xhr.readyState === 4) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvar response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args))\n\t\t\t\t\t\tif ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {\n\t\t\t\t\t\t\tresolve(cast(args.type, response))\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tvar error = new Error(xhr.responseText)\n\t\t\t\t\t\t\tfor (var key in response) error[key] = response[key]\n\t\t\t\t\t\t\treject(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\treject(e)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (useBody && (args.data != null)) xhr.send(args.data)\n\t\t\telse xhr.send()\n\t\t})\n\t\treturn args.background === true ? promise0 : finalize(promise0)\n\t}\n\tfunction jsonp(args, extra) {\n\t\tvar finalize = finalizer()\n\t\targs = normalize(args, extra)\n\t\tvar promise0 = new Promise(function(resolve, reject) {\n\t\t\tvar callbackName = args.callbackName || \"_mithril_\" + Math.round(Math.random() * 1e16) + \"_\" + callbackCount++\n\t\t\tvar script = $window.document.createElement(\"script\")\n\t\t\t$window[callbackName] = function(data) {\n\t\t\t\tscript.parentNode.removeChild(script)\n\t\t\t\tresolve(cast(args.type, data))\n\t\t\t\tdelete $window[callbackName]\n\t\t\t}\n\t\t\tscript.onerror = function() {\n\t\t\t\tscript.parentNode.removeChild(script)\n\t\t\t\treject(new Error(\"JSONP request failed\"))\n\t\t\t\tdelete $window[callbackName]\n\t\t\t}\n\t\t\tif (args.data == null) args.data = {}\n\t\t\targs.url = interpolate(args.url, args.data)\n\t\t\targs.data[args.callbackKey || \"callback\"] = callbackName\n\t\t\tscript.src = assemble(args.url, args.data)\n\t\t\t$window.document.documentElement.appendChild(script)\n\t\t})\n\t\treturn args.background === true? promise0 : finalize(promise0)\n\t}\n\tfunction interpolate(url, data) {\n\t\tif (data == null) return url\n\t\tvar tokens = url.match(/:[^\\/]+/gi) || []\n\t\tfor (var i = 0; i < tokens.length; i++) {\n\t\t\tvar key = tokens[i].slice(1)\n\t\t\tif (data[key] != null) {\n\t\t\t\turl = url.replace(tokens[i], data[key])\n\t\t\t}\n\t\t}\n\t\treturn url\n\t}\n\tfunction assemble(url, data) {\n\t\tvar querystring = buildQueryString(data)\n\t\tif (querystring !== \"\") {\n\t\t\tvar prefix = url.indexOf(\"?\") < 0 ? \"?\" : \"&\"\n\t\t\turl += prefix + querystring\n\t\t}\n\t\treturn url\n\t}\n\tfunction deserialize(data) {\n\t\ttry {return data !== \"\" ? JSON.parse(data) : null}\n\t\tcatch (e) {throw new Error(data)}\n\t}\n\tfunction extract(xhr) {return xhr.responseText}\n\tfunction cast(type0, data) {\n\t\tif (typeof type0 === \"function\") {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\tfor (var i = 0; i < data.length; i++) {\n\t\t\t\t\tdata[i] = new type0(data[i])\n\t\t\t\t}\n\t\t\t}\n\t\t\telse return new type0(data)\n\t\t}\n\t\treturn data\n\t}\n\treturn {request: request, jsonp: jsonp, setCompletionCallback: setCompletionCallback}\n}\nvar requestService = _8(window, PromisePolyfill)\nvar coreRenderer = function($window) {\n\tvar $doc = $window.document\n\tvar $emptyFragment = $doc.createDocumentFragment()\n\tvar onevent\n\tfunction setEventCallback(callback) {return onevent = callback}\n\t//create\n\tfunction createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {\n\t\tfor (var i = start; i < end; i++) {\n\t\t\tvar vnode = vnodes[i]\n\t\t\tif (vnode != null) {\n\t\t\t\tcreateNode(parent, vnode, hooks, ns, nextSibling)\n\t\t\t}\n\t\t}\n\t}\n\tfunction createNode(parent, vnode, hooks, ns, nextSibling) {\n\t\tvar tag = vnode.tag\n\t\tif (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)\n\t\tif (typeof tag === \"string\") {\n\t\t\tswitch (tag) {\n\t\t\t\tcase \"#\": return createText(parent, vnode, nextSibling)\n\t\t\t\tcase \"<\": return createHTML(parent, vnode, nextSibling)\n\t\t\t\tcase \"[\": return createFragment(parent, vnode, hooks, ns, nextSibling)\n\t\t\t\tdefault: return createElement(parent, vnode, hooks, ns, nextSibling)\n\t\t\t}\n\t\t}\n\t\telse return createComponent(parent, vnode, hooks, ns, nextSibling)\n\t}\n\tfunction createText(parent, vnode, nextSibling) {\n\t\tvnode.dom = $doc.createTextNode(vnode.children)\n\t\tinsertNode(parent, vnode.dom, nextSibling)\n\t\treturn vnode.dom\n\t}\n\tfunction createHTML(parent, vnode, nextSibling) {\n\t\tvar match1 = vnode.children.match(/^\\s*?<(\\w+)/im) || []\n\t\tvar parent1 = {caption: \"table\", thead: \"table\", tbody: \"table\", tfoot: \"table\", tr: \"tbody\", th: \"tr\", td: \"tr\", colgroup: \"table\", col: \"colgroup\"}[match1[1]] || \"div\"\n\t\tvar temp = $doc.createElement(parent1)\n\t\ttemp.innerHTML = vnode.children\n\t\tvnode.dom = temp.firstChild\n\t\tvnode.domSize = temp.childNodes.length\n\t\tvar fragment = $doc.createDocumentFragment()\n\t\tvar child\n\t\twhile (child = temp.firstChild) {\n\t\t\tfragment.appendChild(child)\n\t\t}\n\t\tinsertNode(parent, fragment, nextSibling)\n\t\treturn fragment\n\t}\n\tfunction createFragment(parent, vnode, hooks, ns, nextSibling) {\n\t\tvar fragment = $doc.createDocumentFragment()\n\t\tif (vnode.children != null) {\n\t\t\tvar children = vnode.children\n\t\t\tcreateNodes(fragment, children, 0, children.length, hooks, null, ns)\n\t\t}\n\t\tvnode.dom = fragment.firstChild\n\t\tvnode.domSize = fragment.childNodes.length\n\t\tinsertNode(parent, fragment, nextSibling)\n\t\treturn fragment\n\t}\n\tfunction createElement(parent, vnode, hooks, ns, nextSibling) {\n\t\tvar tag = vnode.tag\n\t\tswitch (vnode.tag) {\n\t\t\tcase \"svg\": ns = \"http://www.w3.org/2000/svg\"; break\n\t\t\tcase \"math\": ns = \"http://www.w3.org/1998/Math/MathML\"; break\n\t\t}\n\t\tvar attrs2 = vnode.attrs\n\t\tvar is = attrs2 && attrs2.is\n\t\tvar element = ns ?\n\t\t\tis ? $doc.createElementNS(ns, tag, {is: is}) : $doc.createElementNS(ns, tag) :\n\t\t\tis ? $doc.createElement(tag, {is: is}) : $doc.createElement(tag)\n\t\tvnode.dom = element\n\t\tif (attrs2 != null) {\n\t\t\tsetAttrs(vnode, attrs2, ns)\n\t\t}\n\t\tinsertNode(parent, element, nextSibling)\n\t\tif (vnode.attrs != null && vnode.attrs.contenteditable != null) {\n\t\t\tsetContentEditable(vnode)\n\t\t}\n\t\telse {\n\t\t\tif (vnode.text != null) {\n\t\t\t\tif (vnode.text !== \"\") element.textContent = vnode.text\n\t\t\t\telse vnode.children = [Vnode(\"#\", undefined, undefined, vnode.text, undefined, undefined)]\n\t\t\t}\n\t\t\tif (vnode.children != null) {\n\t\t\t\tvar children = vnode.children\n\t\t\t\tcreateNodes(element, children, 0, children.length, hooks, null, ns)\n\t\t\t\tsetLateAttrs(vnode)\n\t\t\t}\n\t\t}\n\t\treturn element\n\t}\n\tfunction createComponent(parent, vnode, hooks, ns, nextSibling) {\n\t\tvnode.state = Object.create(vnode.tag)\n\t\tvar view = vnode.tag.view\n\t\tif (view.reentrantLock != null) return $emptyFragment\n\t\tview.reentrantLock = true\n\t\tinitLifecycle(vnode.tag, vnode, hooks)\n\t\tvnode.instance = Vnode.normalize(view.call(vnode.state, vnode))\n\t\tview.reentrantLock = null\n\t\tif (vnode.instance != null) {\n\t\t\tif (vnode.instance === vnode) throw Error(\"A view cannot return the vnode it received as arguments\")\n\t\t\tvar element = createNode(parent, vnode.instance, hooks, ns, nextSibling)\n\t\t\tvnode.dom = vnode.instance.dom\n\t\t\tvnode.domSize = vnode.dom != null ? vnode.instance.domSize : 0\n\t\t\tinsertNode(parent, element, nextSibling)\n\t\t\treturn element\n\t\t}\n\t\telse {\n\t\t\tvnode.domSize = 0\n\t\t\treturn $emptyFragment\n\t\t}\n\t}\n\t//update\n\tfunction updateNodes(parent, old, vnodes, recycling, hooks, nextSibling, ns) {\n\t\tif (old === vnodes || old == null && vnodes == null) return\n\t\telse if (old == null) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, undefined)\n\t\telse if (vnodes == null) removeNodes(old, 0, old.length, vnodes)\n\t\telse {\n\t\t\tif (old.length === vnodes.length) {\n\t\t\t\tvar isUnkeyed = false\n\t\t\t\tfor (var i = 0; i < vnodes.length; i++) {\n\t\t\t\t\tif (vnodes[i] != null && old[i] != null) {\n\t\t\t\t\t\tisUnkeyed = vnodes[i].key == null && old[i].key == null\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isUnkeyed) {\n\t\t\t\t\tfor (var i = 0; i < old.length; i++) {\n\t\t\t\t\t\tif (old[i] === vnodes[i]) continue\n\t\t\t\t\t\telse if (old[i] == null && vnodes[i] != null) createNode(parent, vnodes[i], hooks, ns, getNextSibling(old, i + 1, nextSibling))\n\t\t\t\t\t\telse if (vnodes[i] == null) removeNodes(old, i, i + 1, vnodes)\n\t\t\t\t\t\telse updateNode(parent, old[i], vnodes[i], hooks, getNextSibling(old, i + 1, nextSibling), false, ns)\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\trecycling = recycling || isRecyclable(old, vnodes)\n\t\t\tif (recycling) old = old.concat(old.pool)\n\t\t\t\n\t\t\tvar oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map\n\t\t\twhile (oldEnd >= oldStart && end >= start) {\n\t\t\t\tvar o = old[oldStart], v = vnodes[start]\n\t\t\t\tif (o === v && !recycling) oldStart++, start++\n\t\t\t\telse if (o == null) oldStart++\n\t\t\t\telse if (v == null) start++\n\t\t\t\telse if (o.key === v.key) {\n\t\t\t\t\toldStart++, start++\n\t\t\t\t\tupdateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), recycling, ns)\n\t\t\t\t\tif (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tvar o = old[oldEnd]\n\t\t\t\t\tif (o === v && !recycling) oldEnd--, start++\n\t\t\t\t\telse if (o == null) oldEnd--\n\t\t\t\t\telse if (v == null) start++\n\t\t\t\t\telse if (o.key === v.key) {\n\t\t\t\t\t\tupdateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)\n\t\t\t\t\t\tif (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))\n\t\t\t\t\t\toldEnd--, start++\n\t\t\t\t\t}\n\t\t\t\t\telse break\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (oldEnd >= oldStart && end >= start) {\n\t\t\t\tvar o = old[oldEnd], v = vnodes[end]\n\t\t\t\tif (o === v && !recycling) oldEnd--, end--\n\t\t\t\telse if (o == null) oldEnd--\n\t\t\t\telse if (v == null) end--\n\t\t\t\telse if (o.key === v.key) {\n\t\t\t\t\tupdateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)\n\t\t\t\t\tif (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)\n\t\t\t\t\tif (o.dom != null) nextSibling = o.dom\n\t\t\t\t\toldEnd--, end--\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (!map) map = getKeyMap(old, oldEnd)\n\t\t\t\t\tif (v != null) {\n\t\t\t\t\t\tvar oldIndex = map[v.key]\n\t\t\t\t\t\tif (oldIndex != null) {\n\t\t\t\t\t\t\tvar movable = old[oldIndex]\n\t\t\t\t\t\t\tupdateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)\n\t\t\t\t\t\t\tinsertNode(parent, toFragment(movable), nextSibling)\n\t\t\t\t\t\t\told[oldIndex].skip = true\n\t\t\t\t\t\t\tif (movable.dom != null) nextSibling = movable.dom\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tvar dom = createNode(parent, v, hooks, undefined, nextSibling)\n\t\t\t\t\t\t\tnextSibling = dom\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tend--\n\t\t\t\t}\n\t\t\t\tif (end < start) break\n\t\t\t}\n\t\t\tcreateNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns)\n\t\t\tremoveNodes(old, oldStart, oldEnd + 1, vnodes)\n\t\t}\n\t}\n\tfunction updateNode(parent, old, vnode, hooks, nextSibling, recycling, ns) {\n\t\tvar oldTag = old.tag, tag = vnode.tag\n\t\tif (oldTag === tag) {\n\t\t\tvnode.state = old.state\n\t\t\tvnode.events = old.events\n\t\t\tif (shouldUpdate(vnode, old)) return\n\t\t\tif (vnode.attrs != null) {\n\t\t\t\tupdateLifecycle(vnode.attrs, vnode, hooks, recycling)\n\t\t\t}\n\t\t\tif (typeof oldTag === \"string\") {\n\t\t\t\tswitch (oldTag) {\n\t\t\t\t\tcase \"#\": updateText(old, vnode); break\n\t\t\t\t\tcase \"<\": updateHTML(parent, old, vnode, nextSibling); break\n\t\t\t\t\tcase \"[\": updateFragment(parent, old, vnode, recycling, hooks, nextSibling, ns); break\n\t\t\t\t\tdefault: updateElement(old, vnode, recycling, hooks, ns)\n\t\t\t\t}\n\t\t\t}\n\t\t\telse updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns)\n\t\t}\n\t\telse {\n\t\t\tremoveNode(old, null)\n\t\t\tcreateNode(parent, vnode, hooks, ns, nextSibling)\n\t\t}\n\t}\n\tfunction updateText(old, vnode) {\n\t\tif (old.children.toString() !== vnode.children.toString()) {\n\t\t\told.dom.nodeValue = vnode.children\n\t\t}\n\t\tvnode.dom = old.dom\n\t}\n\tfunction updateHTML(parent, old, vnode, nextSibling) {\n\t\tif (old.children !== vnode.children) {\n\t\t\ttoFragment(old)\n\t\t\tcreateHTML(parent, vnode, nextSibling)\n\t\t}\n\t\telse vnode.dom = old.dom, vnode.domSize = old.domSize\n\t}\n\tfunction updateFragment(parent, old, vnode, recycling, hooks, nextSibling, ns) {\n\t\tupdateNodes(parent, old.children, vnode.children, recycling, hooks, nextSibling, ns)\n\t\tvar domSize = 0, children = vnode.children\n\t\tvnode.dom = null\n\t\tif (children != null) {\n\t\t\tfor (var i = 0; i < children.length; i++) {\n\t\t\t\tvar child = children[i]\n\t\t\t\tif (child != null && child.dom != null) {\n\t\t\t\t\tif (vnode.dom == null) vnode.dom = child.dom\n\t\t\t\t\tdomSize += child.domSize || 1\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (domSize !== 1) vnode.domSize = domSize\n\t\t}\n\t}\n\tfunction updateElement(old, vnode, recycling, hooks, ns) {\n\t\tvar element = vnode.dom = old.dom\n\t\tswitch (vnode.tag) {\n\t\t\tcase \"svg\": ns = \"http://www.w3.org/2000/svg\"; break\n\t\t\tcase \"math\": ns = \"http://www.w3.org/1998/Math/MathML\"; break\n\t\t}\n\t\tif (vnode.tag === \"textarea\") {\n\t\t\tif (vnode.attrs == null) vnode.attrs = {}\n\t\t\tif (vnode.text != null) {\n\t\t\t\tvnode.attrs.value = vnode.text //FIXME handle0 multiple children\n\t\t\t\tvnode.text = undefined\n\t\t\t}\n\t\t}\n\t\tupdateAttrs(vnode, old.attrs, vnode.attrs, ns)\n\t\tif (vnode.attrs != null && vnode.attrs.contenteditable != null) {\n\t\t\tsetContentEditable(vnode)\n\t\t}\n\t\telse if (old.text != null && vnode.text != null && vnode.text !== \"\") {\n\t\t\tif (old.text.toString() !== vnode.text.toString()) old.dom.firstChild.nodeValue = vnode.text\n\t\t}\n\t\telse {\n\t\t\tif (old.text != null) old.children = [Vnode(\"#\", undefined, undefined, old.text, undefined, old.dom.firstChild)]\n\t\t\tif (vnode.text != null) vnode.children = [Vnode(\"#\", undefined, undefined, vnode.text, undefined, undefined)]\n\t\t\tupdateNodes(element, old.children, vnode.children, recycling, hooks, null, ns)\n\t\t}\n\t}\n\tfunction updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) {\n\t\tvnode.instance = Vnode.normalize(vnode.tag.view.call(vnode.state, vnode))\n\t\tupdateLifecycle(vnode.tag, vnode, hooks, recycling)\n\t\tif (vnode.instance != null) {\n\t\t\tif (old.instance == null) createNode(parent, vnode.instance, hooks, ns, nextSibling)\n\t\t\telse updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling, ns)\n\t\t\tvnode.dom = vnode.instance.dom\n\t\t\tvnode.domSize = vnode.instance.domSize\n\t\t}\n\t\telse if (old.instance != null) {\n\t\t\tremoveNode(old.instance, null)\n\t\t\tvnode.dom = undefined\n\t\t\tvnode.domSize = 0\n\t\t}\n\t\telse {\n\t\t\tvnode.dom = old.dom\n\t\t\tvnode.domSize = old.domSize\n\t\t}\n\t}\n\tfunction isRecyclable(old, vnodes) {\n\t\tif (old.pool != null && Math.abs(old.pool.length - vnodes.length) <= Math.abs(old.length - vnodes.length)) {\n\t\t\tvar oldChildrenLength = old[0] && old[0].children && old[0].children.length || 0\n\t\t\tvar poolChildrenLength = old.pool[0] && old.pool[0].children && old.pool[0].children.length || 0\n\t\t\tvar vnodesChildrenLength = vnodes[0] && vnodes[0].children && vnodes[0].children.length || 0\n\t\t\tif (Math.abs(poolChildrenLength - vnodesChildrenLength) <= Math.abs(oldChildrenLength - vnodesChildrenLength)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\tfunction getKeyMap(vnodes, end) {\n\t\tvar map = {}, i = 0\n\t\tfor (var i = 0; i < end; i++) {\n\t\t\tvar vnode = vnodes[i]\n\t\t\tif (vnode != null) {\n\t\t\t\tvar key2 = vnode.key\n\t\t\t\tif (key2 != null) map[key2] = i\n\t\t\t}\n\t\t}\n\t\treturn map\n\t}\n\tfunction toFragment(vnode) {\n\t\tvar count0 = vnode.domSize\n\t\tif (count0 != null || vnode.dom == null) {\n\t\t\tvar fragment = $doc.createDocumentFragment()\n\t\t\tif (count0 > 0) {\n\t\t\t\tvar dom = vnode.dom\n\t\t\t\twhile (--count0) fragment.appendChild(dom.nextSibling)\n\t\t\t\tfragment.insertBefore(dom, fragment.firstChild)\n\t\t\t}\n\t\t\treturn fragment\n\t\t}\n\t\telse return vnode.dom\n\t}\n\tfunction getNextSibling(vnodes, i, nextSibling) {\n\t\tfor (; i < vnodes.length; i++) {\n\t\t\tif (vnodes[i] != null && vnodes[i].dom != null) return vnodes[i].dom\n\t\t}\n\t\treturn nextSibling\n\t}\n\tfunction insertNode(parent, dom, nextSibling) {\n\t\tif (nextSibling && nextSibling.parentNode) parent.insertBefore(dom, nextSibling)\n\t\telse parent.appendChild(dom)\n\t}\n\tfunction setContentEditable(vnode) {\n\t\tvar children = vnode.children\n\t\tif (children != null && children.length === 1 && children[0].tag === \"<\") {\n\t\t\tvar content = children[0].children\n\t\t\tif (vnode.dom.innerHTML !== content) vnode.dom.innerHTML = content\n\t\t}\n\t\telse if (vnode.text != null || children != null && children.length !== 0) throw new Error(\"Child node of a contenteditable must be trusted\")\n\t}\n\t//remove\n\tfunction removeNodes(vnodes, start, end, context) {\n\t\tfor (var i = start; i < end; i++) {\n\t\t\tvar vnode = vnodes[i]\n\t\t\tif (vnode != null) {\n\t\t\t\tif (vnode.skip) vnode.skip = false\n\t\t\t\telse removeNode(vnode, context)\n\t\t\t}\n\t\t}\n\t}\n\tfunction removeNode(vnode, context) {\n\t\tvar expected = 1, called = 0\n\t\tif (vnode.attrs && vnode.attrs.onbeforeremove) {\n\t\t\tvar result = vnode.attrs.onbeforeremove.call(vnode.state, vnode)\n\t\t\tif (result != null && typeof result.then === \"function\") {\n\t\t\t\texpected++\n\t\t\t\tresult.then(continuation, continuation)\n\t\t\t}\n\t\t}\n\t\tif (typeof vnode.tag !== \"string\" && vnode.tag.onbeforeremove) {\n\t\t\tvar result = vnode.tag.onbeforeremove.call(vnode.state, vnode)\n\t\t\tif (result != null && typeof result.then === \"function\") {\n\t\t\t\texpected++\n\t\t\t\tresult.then(continuation, continuation)\n\t\t\t}\n\t\t}\n\t\tcontinuation()\n\t\tfunction continuation() {\n\t\t\tif (++called === expected) {\n\t\t\t\tonremove(vnode)\n\t\t\t\tif (vnode.dom) {\n\t\t\t\t\tvar count0 = vnode.domSize || 1\n\t\t\t\t\tif (count0 > 1) {\n\t\t\t\t\t\tvar dom = vnode.dom\n\t\t\t\t\t\twhile (--count0) {\n\t\t\t\t\t\t\tremoveNodeFromDOM(dom.nextSibling)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tremoveNodeFromDOM(vnode.dom)\n\t\t\t\t\tif (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === \"string\") { //TODO test custom elements\n\t\t\t\t\t\tif (!context.pool) context.pool = [vnode]\n\t\t\t\t\t\telse context.pool.push(vnode)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfunction removeNodeFromDOM(node) {\n\t\tvar parent = node.parentNode\n\t\tif (parent != null) parent.removeChild(node)\n\t}\n\tfunction onremove(vnode) {\n\t\tif (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)\n\t\tif (typeof vnode.tag !== \"string\" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)\n\t\tif (vnode.instance != null) onremove(vnode.instance)\n\t\telse {\n\t\t\tvar children = vnode.children\n\t\t\tif (Array.isArray(children)) {\n\t\t\t\tfor (var i = 0; i < children.length; i++) {\n\t\t\t\t\tvar child = children[i]\n\t\t\t\t\tif (child != null) onremove(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t//attrs2\n\tfunction setAttrs(vnode, attrs2, ns) {\n\t\tfor (var key2 in attrs2) {\n\t\t\tsetAttr(vnode, key2, null, attrs2[key2], ns)\n\t\t}\n\t}\n\tfunction setAttr(vnode, key2, old, value, ns) {\n\t\tvar element = vnode.dom\n\t\tif (key2 === \"key\" || key2 === \"is\" || (old === value && !isFormAttribute(vnode, key2)) && typeof value !== \"object\" || typeof value === \"undefined\" || isLifecycleMethod(key2)) return\n\t\tvar nsLastIndex = key2.indexOf(\":\")\n\t\tif (nsLastIndex > -1 && key2.substr(0, nsLastIndex) === \"xlink\") {\n\t\t\telement.setAttributeNS(\"http://www.w3.org/1999/xlink\", key2.slice(nsLastIndex + 1), value)\n\t\t}\n\t\telse if (key2[0] === \"o\" && key2[1] === \"n\" && typeof value === \"function\") updateEvent(vnode, key2, value)\n\t\telse if (key2 === \"style\") updateStyle(element, old, value)\n\t\telse if (key2 in element && !isAttribute(key2) && ns === undefined && !isCustomElement(vnode)) {\n\t\t\t//setting input[value] to same value by typing on focused element moves cursor to end in Chrome\n\t\t\tif (vnode.tag === \"input\" && key2 === \"value\" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return\n\t\t\t//setting select[value] to same value while having select open blinks select dropdown in Chrome\n\t\t\tif (vnode.tag === \"select\" && key2 === \"value\" && vnode.dom.value === value && vnode.dom === $doc.activeElement) return\n\t\t\t//setting option[value] to same value while having select open blinks select dropdown in Chrome\n\t\t\tif (vnode.tag === \"option\" && key2 === \"value\" && vnode.dom.value === value) return\n\t\t\telement[key2] = value\n\t\t}\n\t\telse {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tif (value) element.setAttribute(key2, \"\")\n\t\t\t\telse element.removeAttribute(key2)\n\t\t\t}\n\t\t\telse element.setAttribute(key2 === \"className\" ? \"class\" : key2, value)\n\t\t}\n\t}\n\tfunction setLateAttrs(vnode) {\n\t\tvar attrs2 = vnode.attrs\n\t\tif (vnode.tag === \"select\" && attrs2 != null) {\n\t\t\tif (\"value\" in attrs2) setAttr(vnode, \"value\", null, attrs2.value, undefined)\n\t\t\tif (\"selectedIndex\" in attrs2) setAttr(vnode, \"selectedIndex\", null, attrs2.selectedIndex, undefined)\n\t\t}\n\t}\n\tfunction updateAttrs(vnode, old, attrs2, ns) {\n\t\tif (attrs2 != null) {\n\t\t\tfor (var key2 in attrs2) {\n\t\t\t\tsetAttr(vnode, key2, old && old[key2], attrs2[key2], ns)\n\t\t\t}\n\t\t}\n\t\tif (old != null) {\n\t\t\tfor (var key2 in old) {\n\t\t\t\tif (attrs2 == null || !(key2 in attrs2)) {\n\t\t\t\t\tif (key2 === \"className\") key2 = \"class\"\n\t\t\t\t\tif (key2[0] === \"o\" && key2[1] === \"n\" && !isLifecycleMethod(key2)) updateEvent(vnode, key2, undefined)\n\t\t\t\t\telse if (key2 !== \"key\") vnode.dom.removeAttribute(key2)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfunction isFormAttribute(vnode, attr) {\n\t\treturn attr === \"value\" || attr === \"checked\" || attr === \"selectedIndex\" || attr === \"selected\" && vnode.dom === $doc.activeElement\n\t}\n\tfunction isLifecycleMethod(attr) {\n\t\treturn attr === \"oninit\" || attr === \"oncreate\" || attr === \"onupdate\" || attr === \"onremove\" || attr === \"onbeforeremove\" || attr === \"onbeforeupdate\"\n\t}\n\tfunction isAttribute(attr) {\n\t\treturn attr === \"href\" || attr === \"list\" || attr === \"form\" || attr === \"width\" || attr === \"height\"// || attr === \"type\"\n\t}\n\tfunction isCustomElement(vnode){\n\t\treturn vnode.attrs.is || vnode.tag.indexOf(\"-\") > -1\n\t}\n\tfunction hasIntegrationMethods(source) {\n\t\treturn source != null && (source.oncreate || source.onupdate || source.onbeforeremove || source.onremove)\n\t}\n\t//style\n\tfunction updateStyle(element, old, style) {\n\t\tif (old === style) element.style.cssText = \"\", old = null\n\t\tif (style == null) element.style.cssText = \"\"\n\t\telse if (typeof style === \"string\") element.style.cssText = style\n\t\telse {\n\t\t\tif (typeof old === \"string\") element.style.cssText = \"\"\n\t\t\tfor (var key2 in style) {\n\t\t\t\telement.style[key2] = style[key2]\n\t\t\t}\n\t\t\tif (old != null && typeof old !== \"string\") {\n\t\t\t\tfor (var key2 in old) {\n\t\t\t\t\tif (!(key2 in style)) element.style[key2] = \"\"\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t//event\n\tfunction updateEvent(vnode, key2, value) {\n\t\tvar element = vnode.dom\n\t\tvar callback = typeof onevent !== \"function\" ? value : function(e) {\n\t\t\tvar result = value.call(element, e)\n\t\t\tonevent.call(element, e)\n\t\t\treturn result\n\t\t}\n\t\tif (key2 in element) element[key2] = typeof value === \"function\" ? callback : null\n\t\telse {\n\t\t\tvar eventName = key2.slice(2)\n\t\t\tif (vnode.events === undefined) vnode.events = {}\n\t\t\tif (vnode.events[key2] === callback) return\n\t\t\tif (vnode.events[key2] != null) element.removeEventListener(eventName, vnode.events[key2], false)\n\t\t\tif (typeof value === \"function\") {\n\t\t\t\tvnode.events[key2] = callback\n\t\t\t\telement.addEventListener(eventName, vnode.events[key2], false)\n\t\t\t}\n\t\t}\n\t}\n\t//lifecycle\n\tfunction initLifecycle(source, vnode, hooks) {\n\t\tif (typeof source.oninit === \"function\") source.oninit.call(vnode.state, vnode)\n\t\tif (typeof source.oncreate === \"function\") hooks.push(source.oncreate.bind(vnode.state, vnode))\n\t}\n\tfunction updateLifecycle(source, vnode, hooks, recycling) {\n\t\tif (recycling) initLifecycle(source, vnode, hooks)\n\t\telse if (typeof source.onupdate === \"function\") hooks.push(source.onupdate.bind(vnode.state, vnode))\n\t}\n\tfunction shouldUpdate(vnode, old) {\n\t\tvar forceVnodeUpdate, forceComponentUpdate\n\t\tif (vnode.attrs != null && typeof vnode.attrs.onbeforeupdate === \"function\") forceVnodeUpdate = vnode.attrs.onbeforeupdate.call(vnode.state, vnode, old)\n\t\tif (typeof vnode.tag !== \"string\" && typeof vnode.tag.onbeforeupdate === \"function\") forceComponentUpdate = vnode.tag.onbeforeupdate.call(vnode.state, vnode, old)\n\t\tif (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {\n\t\t\tvnode.dom = old.dom\n\t\t\tvnode.domSize = old.domSize\n\t\t\tvnode.instance = old.instance\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\tfunction render(dom, vnodes) {\n\t\tif (!dom) throw new Error(\"Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.\")\n\t\tvar hooks = []\n\t\tvar active = $doc.activeElement\n\t\t// First time0 rendering into a node clears it out\n\t\tif (dom.vnodes == null) dom.textContent = \"\"\n\t\tif (!Array.isArray(vnodes)) vnodes = [vnodes]\n\t\tupdateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), false, hooks, null, undefined)\n\t\tdom.vnodes = vnodes\n\t\tfor (var i = 0; i < hooks.length; i++) hooks[i]()\n\t\tif ($doc.activeElement !== active) active.focus()\n\t}\n\treturn {render: render, setEventCallback: setEventCallback}\n}\nfunction throttle(callback) {\n\t//60fps translates to 16.6ms, round it down since setTimeout requires int\n\tvar time = 16\n\tvar last = 0, pending = null\n\tvar timeout = typeof requestAnimationFrame === \"function\" ? requestAnimationFrame : setTimeout\n\treturn function() {\n\t\tvar now = Date.now()\n\t\tif (last === 0 || now - last >= time) {\n\t\t\tlast = now\n\t\t\tcallback()\n\t\t}\n\t\telse if (pending === null) {\n\t\t\tpending = timeout(function() {\n\t\t\t\tpending = null\n\t\t\t\tcallback()\n\t\t\t\tlast = Date.now()\n\t\t\t}, time - (now - last))\n\t\t}\n\t}\n}\nvar _11 = function($window) {\n\tvar renderService = coreRenderer($window)\n\trenderService.setEventCallback(function(e) {\n\t\tif (e.redraw !== false) redraw()\n\t})\n\tvar callbacks = []\n\tfunction subscribe(key1, callback) {\n\t\tunsubscribe(key1)\n\t\tcallbacks.push(key1, throttle(callback))\n\t}\n\tfunction unsubscribe(key1) {\n\t\tvar index = callbacks.indexOf(key1)\n\t\tif (index > -1) callbacks.splice(index, 2)\n\t}\n function redraw() {\n for (var i = 1; i < callbacks.length; i += 2) {\n callbacks[i]()\n }\n }\n\treturn {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render}\n}\nvar redrawService = _11(window)\nrequestService.setCompletionCallback(redrawService.redraw)\nvar _16 = function(redrawService0) {\n\treturn function(root, component) {\n\t\tif (component === null) {\n\t\t\tredrawService0.render(root, [])\n\t\t\tredrawService0.unsubscribe(root)\n\t\t\treturn\n\t\t}\n\t\t\n\t\tif (component.view == null) throw new Error(\"m.mount(element, component) expects a component, not a vnode\")\n\t\t\n\t\tvar run0 = function() {\n\t\t\tredrawService0.render(root, Vnode(component))\n\t\t}\n\t\tredrawService0.subscribe(root, run0)\n\t\tredrawService0.redraw()\n\t}\n}\nm.mount = _16(redrawService)\nvar Promise = PromisePolyfill\nvar parseQueryString = function(string) {\n\tif (string === \"\" || string == null) return {}\n\tif (string.charAt(0) === \"?\") string = string.slice(1)\n\tvar entries = string.split(\"&\"), data0 = {}, counters = {}\n\tfor (var i = 0; i < entries.length; i++) {\n\t\tvar entry = entries[i].split(\"=\")\n\t\tvar key5 = decodeURIComponent(entry[0])\n\t\tvar value = entry.length === 2 ? decodeURIComponent(entry[1]) : \"\"\n\t\tif (value === \"true\") value = true\n\t\telse if (value === \"false\") value = false\n\t\tvar levels = key5.split(/\\]\\[?|\\[/)\n\t\tvar cursor = data0\n\t\tif (key5.indexOf(\"[\") > -1) levels.pop()\n\t\tfor (var j = 0; j < levels.length; j++) {\n\t\t\tvar level = levels[j], nextLevel = levels[j + 1]\n\t\t\tvar isNumber = nextLevel == \"\" || !isNaN(parseInt(nextLevel, 10))\n\t\t\tvar isValue = j === levels.length - 1\n\t\t\tif (level === \"\") {\n\t\t\t\tvar key5 = levels.slice(0, j).join()\n\t\t\t\tif (counters[key5] == null) counters[key5] = 0\n\t\t\t\tlevel = counters[key5]++\n\t\t\t}\n\t\t\tif (cursor[level] == null) {\n\t\t\t\tcursor[level] = isValue ? value : isNumber ? [] : {}\n\t\t\t}\n\t\t\tcursor = cursor[level]\n\t\t}\n\t}\n\treturn data0\n}\nvar coreRouter = function($window) {\n\tvar supportsPushState = typeof $window.history.pushState === \"function\"\n\tvar callAsync0 = typeof setImmediate === \"function\" ? setImmediate : setTimeout\n\tfunction normalize1(fragment0) {\n\t\tvar data = $window.location[fragment0].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent)\n\t\tif (fragment0 === \"pathname\" && data[0] !== \"/\") data = \"/\" + data\n\t\treturn data\n\t}\n\tvar asyncId\n\tfunction debounceAsync(callback0) {\n\t\treturn function() {\n\t\t\tif (asyncId != null) return\n\t\t\tasyncId = callAsync0(function() {\n\t\t\t\tasyncId = null\n\t\t\t\tcallback0()\n\t\t\t})\n\t\t}\n\t}\n\tfunction parsePath(path, queryData, hashData) {\n\t\tvar queryIndex = path.indexOf(\"?\")\n\t\tvar hashIndex = path.indexOf(\"#\")\n\t\tvar pathEnd = queryIndex > -1 ? queryIndex : hashIndex > -1 ? hashIndex : path.length\n\t\tif (queryIndex > -1) {\n\t\t\tvar queryEnd = hashIndex > -1 ? hashIndex : path.length\n\t\t\tvar queryParams = parseQueryString(path.slice(queryIndex + 1, queryEnd))\n\t\t\tfor (var key4 in queryParams) queryData[key4] = queryParams[key4]\n\t\t}\n\t\tif (hashIndex > -1) {\n\t\t\tvar hashParams = parseQueryString(path.slice(hashIndex + 1))\n\t\t\tfor (var key4 in hashParams) hashData[key4] = hashParams[key4]\n\t\t}\n\t\treturn path.slice(0, pathEnd)\n\t}\n\tvar router = {prefix: \"#!\"}\n\trouter.getPath = function() {\n\t\tvar type2 = router.prefix.charAt(0)\n\t\tswitch (type2) {\n\t\t\tcase \"#\": return normalize1(\"hash\").slice(router.prefix.length)\n\t\t\tcase \"?\": return normalize1(\"search\").slice(router.prefix.length) + normalize1(\"hash\")\n\t\t\tdefault: return normalize1(\"pathname\").slice(router.prefix.length) + normalize1(\"search\") + normalize1(\"hash\")\n\t\t}\n\t}\n\trouter.setPath = function(path, data, options) {\n\t\tvar queryData = {}, hashData = {}\n\t\tpath = parsePath(path, queryData, hashData)\n\t\tif (data != null) {\n\t\t\tfor (var key4 in data) queryData[key4] = data[key4]\n\t\t\tpath = path.replace(/:([^\\/]+)/g, function(match2, token) {\n\t\t\t\tdelete queryData[token]\n\t\t\t\treturn data[token]\n\t\t\t})\n\t\t}\n\t\tvar query = buildQueryString(queryData)\n\t\tif (query) path += \"?\" + query\n\t\tvar hash = buildQueryString(hashData)\n\t\tif (hash) path += \"#\" + hash\n\t\tif (supportsPushState) {\n\t\t\tvar state = options ? options.state : null\n\t\t\tvar title = options ? options.title : null\n\t\t\t$window.onpopstate()\n\t\t\tif (options && options.replace) $window.history.replaceState(state, title, router.prefix + path)\n\t\t\telse $window.history.pushState(state, title, router.prefix + path)\n\t\t}\n\t\telse $window.location.href = router.prefix + path\n\t}\n\trouter.defineRoutes = function(routes, resolve, reject) {\n\t\tfunction resolveRoute() {\n\t\t\tvar path = router.getPath()\n\t\t\tvar params = {}\n\t\t\tvar pathname = parsePath(path, params, params)\n\t\t\tvar state = $window.history.state\n\t\t\tif (state != null) {\n\t\t\t\tfor (var k in state) params[k] = state[k]\n\t\t\t}\n\t\t\tfor (var route0 in routes) {\n\t\t\t\tvar matcher = new RegExp(\"^\" + route0.replace(/:[^\\/]+?\\.{3}/g, \"(.*?)\").replace(/:[^\\/]+/g, \"([^\\\\/]+)\") + \"\\/?$\")\n\t\t\t\tif (matcher.test(pathname)) {\n\t\t\t\t\tpathname.replace(matcher, function() {\n\t\t\t\t\t\tvar keys = route0.match(/:[^\\/]+/g) || []\n\t\t\t\t\t\tvar values = [].slice.call(arguments, 1, -2)\n\t\t\t\t\t\tfor (var i = 0; i < keys.length; i++) {\n\t\t\t\t\t\t\tparams[keys[i].replace(/:|\\./g, \"\")] = decodeURIComponent(values[i])\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresolve(routes[route0], params, path, route0)\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\treject(path, params)\n\t\t}\n\t\tif (supportsPushState) $window.onpopstate = debounceAsync(resolveRoute)\n\t\telse if (router.prefix.charAt(0) === \"#\") $window.onhashchange = resolveRoute\n\t\tresolveRoute()\n\t}\n\treturn router\n}\nvar _20 = function($window, redrawService0) {\n\tvar routeService = coreRouter($window)\n\tvar identity = function(v) {return v}\n\tvar render1, component, attrs3, currentPath, lastUpdate\n\tvar route = function(root, defaultRoute, routes) {\n\t\tif (root == null) throw new Error(\"Ensure the DOM element that was passed to `m.route` is not undefined\")\n\t\tvar run1 = function() {\n\t\t\tif (render1 != null) redrawService0.render(root, render1(Vnode(component, attrs3.key, attrs3)))\n\t\t}\n\t\tvar bail = function(path) {\n\t\t\tif (path !== defaultRoute) routeService.setPath(defaultRoute, null, {replace: true})\n\t\t\telse throw new Error(\"Could not resolve default route \" + defaultRoute)\n\t\t}\n\t\trouteService.defineRoutes(routes, function(payload, params, path) {\n\t\t\tvar update = lastUpdate = function(routeResolver, comp) {\n\t\t\t\tif (update !== lastUpdate) return\n\t\t\t\tcomponent = comp != null && typeof comp.view === \"function\" ? comp : \"div\", attrs3 = params, currentPath = path, lastUpdate = null\n\t\t\t\trender1 = (routeResolver.render || identity).bind(routeResolver)\n\t\t\t\trun1()\n\t\t\t}\n\t\t\tif (payload.view) update({}, payload)\n\t\t\telse {\n\t\t\t\tif (payload.onmatch) {\n\t\t\t\t\tPromise.resolve(payload.onmatch(params, path)).then(function(resolved) {\n\t\t\t\t\t\tupdate(payload, resolved)\n\t\t\t\t\t}, bail)\n\t\t\t\t}\n\t\t\t\telse update(payload, \"div\")\n\t\t\t}\n\t\t}, bail)\n\t\tredrawService0.subscribe(root, run1)\n\t}\n\troute.set = function(path, data, options) {\n\t\tif (lastUpdate != null) options = {replace: true}\n\t\tlastUpdate = null\n\t\trouteService.setPath(path, data, options)\n\t}\n\troute.get = function() {return currentPath}\n\troute.prefix = function(prefix0) {routeService.prefix = prefix0}\n\troute.link = function(vnode1) {\n\t\tvnode1.dom.setAttribute(\"href\", routeService.prefix + vnode1.attrs.href)\n\t\tvnode1.dom.onclick = function(e) {\n\t\t\tif (e.ctrlKey || e.metaKey || e.shiftKey || e.which === 2) return\n\t\t\te.preventDefault()\n\t\t\te.redraw = false\n\t\t\tvar href = this.getAttribute(\"href\")\n\t\t\tif (href.indexOf(routeService.prefix) === 0) href = href.slice(routeService.prefix.length)\n\t\t\troute.set(href, undefined, undefined)\n\t\t}\n\t}\n\troute.param = function(key3) {\n\t\tif(typeof attrs3 !== \"undefined\" && typeof key3 !== \"undefined\") return attrs3[key3]\n\t\treturn attrs3\n\t}\n\treturn route\n}\nm.route = _20(window, redrawService)\nm.withAttr = function(attrName, callback1, context) {\n\treturn function(e) {\n\t\tcallback1.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))\n\t}\n}\nvar _28 = coreRenderer(window)\nm.render = _28.render\nm.redraw = redrawService.redraw\nm.request = requestService.request\nm.jsonp = requestService.jsonp\nm.parseQueryString = parseQueryString\nm.buildQueryString = buildQueryString\nm.version = \"1.0.1\"\nm.vnode = Vnode\nif (typeof module !== \"undefined\") module[\"exports\"] = m\nelse window.m = m\n}\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{}],8:[function(require,module,exports){\n/*!\n * EventEmitter v5.1.0 - git.io/ee\n * Unlicense - http://unlicense.org/\n * Oliver Caldwell - http://oli.me.uk/\n * @preserve\n */\n\n;(function (exports) {\n 'use strict';\n\n /**\n * Class for managing events.\n * Can be extended to provide event functionality in other classes.\n *\n * @class EventEmitter Manages event registering and emitting.\n */\n function EventEmitter() {}\n\n // Shortcuts to improve speed and size\n var proto = EventEmitter.prototype;\n var originalGlobalValue = exports.EventEmitter;\n\n /**\n * Finds the index of the listener for the event in its storage array.\n *\n * @param {Function[]} listeners Array of listeners to search through.\n * @param {Function} listener Method to look for.\n * @return {Number} Index of the specified listener, -1 if not found\n * @api private\n */\n function indexOfListener(listeners, listener) {\n var i = listeners.length;\n while (i--) {\n if (listeners[i].listener === listener) {\n return i;\n }\n }\n\n return -1;\n }\n\n /**\n * Alias a method while keeping the context correct, to allow for overwriting of target method.\n *\n * @param {String} name The name of the target method.\n * @return {Function} The aliased method\n * @api private\n */\n function alias(name) {\n return function aliasClosure() {\n return this[name].apply(this, arguments);\n };\n }\n\n /**\n * Returns the listener array for the specified event.\n * Will initialise the event object and listener arrays if required.\n * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.\n * Each property in the object response is an array of listener functions.\n *\n * @param {String|RegExp} evt Name of the event to return the listeners from.\n * @return {Function[]|Object} All listener functions for the event.\n */\n proto.getListeners = function getListeners(evt) {\n var events = this._getEvents();\n var response;\n var key;\n\n // Return a concatenated array of all matching events if\n // the selector is a regular expression.\n if (evt instanceof RegExp) {\n response = {};\n for (key in events) {\n if (events.hasOwnProperty(key) && evt.test(key)) {\n response[key] = events[key];\n }\n }\n }\n else {\n response = events[evt] || (events[evt] = []);\n }\n\n return response;\n };\n\n /**\n * Takes a list of listener objects and flattens it into a list of listener functions.\n *\n * @param {Object[]} listeners Raw listener objects.\n * @return {Function[]} Just the listener functions.\n */\n proto.flattenListeners = function flattenListeners(listeners) {\n var flatListeners = [];\n var i;\n\n for (i = 0; i < listeners.length; i += 1) {\n flatListeners.push(listeners[i].listener);\n }\n\n return flatListeners;\n };\n\n /**\n * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.\n *\n * @param {String|RegExp} evt Name of the event to return the listeners from.\n * @return {Object} All listener functions for an event in an object.\n */\n proto.getListenersAsObject = function getListenersAsObject(evt) {\n var listeners = this.getListeners(evt);\n var response;\n\n if (listeners instanceof Array) {\n response = {};\n response[evt] = listeners;\n }\n\n return response || listeners;\n };\n\n function isValidListener (listener) {\n if (typeof listener === 'function' || listener instanceof RegExp) {\n return true\n } else if (listener && typeof listener === 'object') {\n return isValidListener(listener.listener)\n } else {\n return false\n }\n }\n\n /**\n * Adds a listener function to the specified event.\n * The listener will not be added if it is a duplicate.\n * If the listener returns true then it will be removed after it is called.\n * If you pass a regular expression as the event name then the listener will be added to all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to attach the listener to.\n * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.addListener = function addListener(evt, listener) {\n if (!isValidListener(listener)) {\n throw new TypeError('listener must be a function');\n }\n\n var listeners = this.getListenersAsObject(evt);\n var listenerIsWrapped = typeof listener === 'object';\n var key;\n\n for (key in listeners) {\n if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {\n listeners[key].push(listenerIsWrapped ? listener : {\n listener: listener,\n once: false\n });\n }\n }\n\n return this;\n };\n\n /**\n * Alias of addListener\n */\n proto.on = alias('addListener');\n\n /**\n * Semi-alias of addListener. It will add a listener that will be\n * automatically removed after its first execution.\n *\n * @param {String|RegExp} evt Name of the event to attach the listener to.\n * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.addOnceListener = function addOnceListener(evt, listener) {\n return this.addListener(evt, {\n listener: listener,\n once: true\n });\n };\n\n /**\n * Alias of addOnceListener.\n */\n proto.once = alias('addOnceListener');\n\n /**\n * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.\n * You need to tell it what event names should be matched by a regex.\n *\n * @param {String} evt Name of the event to create.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.defineEvent = function defineEvent(evt) {\n this.getListeners(evt);\n return this;\n };\n\n /**\n * Uses defineEvent to define multiple events.\n *\n * @param {String[]} evts An array of event names to define.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.defineEvents = function defineEvents(evts) {\n for (var i = 0; i < evts.length; i += 1) {\n this.defineEvent(evts[i]);\n }\n return this;\n };\n\n /**\n * Removes a listener function from the specified event.\n * When passed a regular expression as the event name, it will remove the listener from all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to remove the listener from.\n * @param {Function} listener Method to remove from the event.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.removeListener = function removeListener(evt, listener) {\n var listeners = this.getListenersAsObject(evt);\n var index;\n var key;\n\n for (key in listeners) {\n if (listeners.hasOwnProperty(key)) {\n index = indexOfListener(listeners[key], listener);\n\n if (index !== -1) {\n listeners[key].splice(index, 1);\n }\n }\n }\n\n return this;\n };\n\n /**\n * Alias of removeListener\n */\n proto.off = alias('removeListener');\n\n /**\n * Adds listeners in bulk using the manipulateListeners method.\n * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.\n * You can also pass it a regular expression to add the array of listeners to all events that match it.\n * Yeah, this function does quite a bit. That's probably a bad thing.\n *\n * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.\n * @param {Function[]} [listeners] An optional array of listener functions to add.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.addListeners = function addListeners(evt, listeners) {\n // Pass through to manipulateListeners\n return this.manipulateListeners(false, evt, listeners);\n };\n\n /**\n * Removes listeners in bulk using the manipulateListeners method.\n * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.\n * You can also pass it an event name and an array of listeners to be removed.\n * You can also pass it a regular expression to remove the listeners from all events that match it.\n *\n * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.\n * @param {Function[]} [listeners] An optional array of listener functions to remove.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.removeListeners = function removeListeners(evt, listeners) {\n // Pass through to manipulateListeners\n return this.manipulateListeners(true, evt, listeners);\n };\n\n /**\n * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.\n * The first argument will determine if the listeners are removed (true) or added (false).\n * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.\n * You can also pass it an event name and an array of listeners to be added/removed.\n * You can also pass it a regular expression to manipulate the listeners of all events that match it.\n *\n * @param {Boolean} remove True if you want to remove listeners, false if you want to add.\n * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.\n * @param {Function[]} [listeners] An optional array of listener functions to add/remove.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {\n var i;\n var value;\n var single = remove ? this.removeListener : this.addListener;\n var multiple = remove ? this.removeListeners : this.addListeners;\n\n // If evt is an object then pass each of its properties to this method\n if (typeof evt === 'object' && !(evt instanceof RegExp)) {\n for (i in evt) {\n if (evt.hasOwnProperty(i) && (value = evt[i])) {\n // Pass the single listener straight through to the singular method\n if (typeof value === 'function') {\n single.call(this, i, value);\n }\n else {\n // Otherwise pass back to the multiple function\n multiple.call(this, i, value);\n }\n }\n }\n }\n else {\n // So evt must be a string\n // And listeners must be an array of listeners\n // Loop over it and pass each one to the multiple method\n i = listeners.length;\n while (i--) {\n single.call(this, evt, listeners[i]);\n }\n }\n\n return this;\n };\n\n /**\n * Removes all listeners from a specified event.\n * If you do not specify an event then all listeners will be removed.\n * That means every event will be emptied.\n * You can also pass a regex to remove all events that match it.\n *\n * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.removeEvent = function removeEvent(evt) {\n var type = typeof evt;\n var events = this._getEvents();\n var key;\n\n // Remove different things depending on the state of evt\n if (type === 'string') {\n // Remove all listeners for the specified event\n delete events[evt];\n }\n else if (evt instanceof RegExp) {\n // Remove all events matching the regex.\n for (key in events) {\n if (events.hasOwnProperty(key) && evt.test(key)) {\n delete events[key];\n }\n }\n }\n else {\n // Remove all listeners in all events\n delete this._events;\n }\n\n return this;\n };\n\n /**\n * Alias of removeEvent.\n *\n * Added to mirror the node API.\n */\n proto.removeAllListeners = alias('removeEvent');\n\n /**\n * Emits an event of your choice.\n * When emitted, every listener attached to that event will be executed.\n * If you pass the optional argument array then those arguments will be passed to every listener upon execution.\n * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.\n * So they will not arrive within the array on the other side, they will be separate.\n * You can also pass a regular expression to emit to all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to emit and execute listeners for.\n * @param {Array} [args] Optional array of arguments to be passed to each listener.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.emitEvent = function emitEvent(evt, args) {\n var listenersMap = this.getListenersAsObject(evt);\n var listeners;\n var listener;\n var i;\n var key;\n var response;\n\n for (key in listenersMap) {\n if (listenersMap.hasOwnProperty(key)) {\n listeners = listenersMap[key].slice(0);\n\n for (i = 0; i < listeners.length; i++) {\n // If the listener returns true then it shall be removed from the event\n // The function is executed either with a basic call or an apply if there is an args array\n listener = listeners[i];\n\n if (listener.once === true) {\n this.removeListener(evt, listener.listener);\n }\n\n response = listener.listener.apply(this, args || []);\n\n if (response === this._getOnceReturnValue()) {\n this.removeListener(evt, listener.listener);\n }\n }\n }\n }\n\n return this;\n };\n\n /**\n * Alias of emitEvent\n */\n proto.trigger = alias('emitEvent');\n\n /**\n * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.\n * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to emit and execute listeners for.\n * @param {...*} Optional additional arguments to be passed to each listener.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.emit = function emit(evt) {\n var args = Array.prototype.slice.call(arguments, 1);\n return this.emitEvent(evt, args);\n };\n\n /**\n * Sets the current value to check against when executing listeners. If a\n * listeners return value matches the one set here then it will be removed\n * after execution. This value defaults to true.\n *\n * @param {*} value The new value to check for when executing listeners.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.setOnceReturnValue = function setOnceReturnValue(value) {\n this._onceReturnValue = value;\n return this;\n };\n\n /**\n * Fetches the current value to check against when executing listeners. If\n * the listeners return value matches this one then it should be removed\n * automatically. It will return true by default.\n *\n * @return {*|Boolean} The current value to check for or the default, true.\n * @api private\n */\n proto._getOnceReturnValue = function _getOnceReturnValue() {\n if (this.hasOwnProperty('_onceReturnValue')) {\n return this._onceReturnValue;\n }\n else {\n return true;\n }\n };\n\n /**\n * Fetches the events object and creates one if required.\n *\n * @return {Object} The events storage object.\n * @api private\n */\n proto._getEvents = function _getEvents() {\n return this._events || (this._events = {});\n };\n\n /**\n * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.\n *\n * @return {Function} Non conflicting EventEmitter class.\n */\n EventEmitter.noConflict = function noConflict() {\n exports.EventEmitter = originalGlobalValue;\n return EventEmitter;\n };\n\n // Expose the class either via AMD, CommonJS or the global object\n if (typeof define === 'function' && define.amd) {\n define(function () {\n return EventEmitter;\n });\n }\n else if (typeof module === 'object' && module.exports){\n module.exports = EventEmitter;\n }\n else {\n exports.EventEmitter = EventEmitter;\n }\n}(this || {}));\n\n},{}]},{},[1]);\n })();"]}
1
+ {"version":3,"sources":["admin.js"],"names":["require","undefined","define","e","t","n","r","s","o","u","a","i","f","Error","code","l","exports","call","length","1","module","m","window","EventEmitter","context","document","getElementById","events","tabs","helpers","settings","ListFetcher","mount","mc4wp","deps","mithril","./admin/helpers.js","./admin/list-fetcher.js","./admin/settings.js","./admin/tabs.js","wolfy87-eventemitter","2","toggleElement","selector","elements","querySelectorAll","show","clientHeight","style","display","bindEventToElement","element","event","handler","addEventListener","attachEvent","bindEventToElements","Array","prototype","forEach","debounce","func","wait","immediate","timeout","this","args","arguments","later","apply","callNow","clearTimeout","setTimeout","showIfElements","getAttribute","checked","value","conditionMet","config","hide","visibility","opacity","inputs","inputElement","removeAttribute","setAttribute","JSON","parse","parentElements","parentElement","3","working","done","mailchimp","api_connected","lists","fetch","$","jQuery","mc4wp_vars","i18n","preventDefault","post","ajaxurl","action","data","location","reload","always","redraw","bind","view","method","onsubmit","type","fetching_mailchimp_lists","renew_mailchimp_lists","className","disabled","trust","fetching_mailchimp_lists_can_take_a_while","fetching_mailchimp_lists_done","4","_typeof","Symbol","iterator","obj","constructor","Settings","getSelectedListsWhere","searchKey","searchValue","selectedLists","filter","el","getSelectedLists","updateSelectedLists","listInputs","input","push","trigger","toggleVisibleLists","rows","replace","querySelector","on","5","URL","Tabs","get","id","_open","tab","updateState","$tabs","removeClass","css","$tabNavs","nav","blur","url","setParameter","href","history","pushState","title","refererField","tb_remove","forms","editor","refresh","split","switchTab","tabId","match","urlParams","returnValue","$context","find","each","substring","first","text","open","click","body","activeTab","replaceState","state","./url.js","6","query","hasOwnProperty","b","decodeURIComponent","build","ret","d","encodeURIComponent","join","key","7","global","Vnode","tag","attrs0","children","dom","attrs","domSize","_state","instance","skip","compileSelector","classes","selectorParser","exec","attrValue","selectorCache","execSelector","childList","hasAttrs","class","hasOwn","isArray","hyperscript","start","cached","normalized","normalizeChildren","throttle","callback","last","pending","requestAnimationFrame","now","Date","normalize","node","html","fragment","attrs1","PromisePolyfill","executor","list","shouldAbsorb","execute","then","callAsync","console","error","resolvers","rejectors","retry","self","TypeError","executeOnce","rejectCurrent","run","fn","runs","onerror","resolveCurrent","_instance","setImmediate","onFulfilled","onRejection","handle","next","resolveNext","rejectNext","promise","resolve","reject","catch","all","total","count","values","consume","race","Promise","buildQueryString","object","destructure","key0","Object","toString","FILE_PROTOCOL_REGEX","RegExp","requestService","$window","setCompletionCallback","oncompletion","finalizer","complete","finalize","promise0","then0","extra","request","toUpperCase","useBody","serialize","FormData","stringify","deserialize","extract","interpolate","assemble","xhr","XMLHttpRequest","aborted","_abort","abort","async","user","password","setRequestHeader","withCredentials","headers","onreadystatechange","readyState","response","status","test","cast","responseText","send","background","jsonp","callbackName","Math","round","random","callbackCount","script","createElement","parentNode","removeChild","callbackKey","src","documentElement","appendChild","tokens","slice","querystring","indexOf","type0","coreRenderer","setEventCallback","onevent","createNodes","parent","vnodes","end","hooks","nextSibling","ns","vnode","createNode","createComponent","initLifecycle","createText","createHTML","createFragment","$doc","createTextNode","insertNode","match1","parent1","caption","thead","tbody","tfoot","tr","th","td","colgroup","col","temp","innerHTML","firstChild","childNodes","child","createDocumentFragment","attrs2","is","createElementNS","setAttrs","contenteditable","setContentEditable","textContent","setLateAttrs","initComponent","sentinel","create","$$reentrantLock$$","$emptyFragment","updateNodes","old","recycling","removeNodes","isUnkeyed","getNextSibling","updateNode","isRecyclable","pool","concat","map","oldStart","oldEnd","v","shouldRecycle","toFragment","getKeyMap","oldIndex","movable","oldTag","shouldNotUpdate","updateLifecycle","updateText","updateHTML","updateFragment","updateElement","updateComponent","removeNode","nodeValue","updateAttrs","abs","oldChildrenLength","poolChildrenLength","vnodesChildrenLength","key2","count0","insertBefore","content","continuation","called","expected","onremove","removeNodeFromDOM","hasIntegrationMethods","onbeforeremove","result","setAttr","isFormAttribute","isLifecycleMethod","nsLastIndex","substr","setAttributeNS","updateEvent","updateStyle","isAttribute","isCustomElement","activeElement","selectedIndex","attr","source","oncreate","onupdate","cssText","eventName","removeEventListener","oninit","forceVnodeUpdate","forceComponentUpdate","onbeforeupdate","render","active","focus","redrawService","subscribe","key1","unsubscribe","callbacks","index","splice","renderService","redrawService0","root","component","run0","parseQueryString","string","charAt","entries","data0","counters","entry","key5","levels","cursor","pop","j","level","nextLevel","isNumber","isNaN","parseInt","isValue","coreRouter","normalize1","fragment0","debounceAsync","callback0","asyncId","callAsync0","parsePath","path","queryData","hashData","queryIndex","hashIndex","pathEnd","queryEnd","queryParams","key4","hashParams","supportsPushState","router","prefix","getPath","setPath","options","match2","token","hash","onpopstate","defineRoutes","routes","resolveRoute","params","pathname","k","route0","matcher","keys","onhashchange","route","render1","attrs3","currentPath","lastUpdate","routeService","identity","defaultRoute","run1","bail","payload","update","routeResolver","comp","onmatch","resolved","set","prefix0","link","vnode1","onclick","ctrlKey","metaKey","shiftKey","which","param","key3","withAttr","attrName","callback1","currentTarget","_28","version","8","indexOfListener","listeners","listener","alias","name","isValidListener","proto","originalGlobalValue","getListeners","evt","_getEvents","flattenListeners","flatListeners","getListenersAsObject","addListener","listenerIsWrapped","once","addOnceListener","defineEvent","defineEvents","evts","removeListener","off","addListeners","manipulateListeners","removeListeners","remove","single","multiple","removeEvent","_events","removeAllListeners","emitEvent","listenersMap","_getOnceReturnValue","emit","setOnceReturnValue","_onceReturnValue","noConflict","amd"],"mappings":"CAAA,WAAe,GAAIA,OAAUC,GAAeC,MAASD,IAAW,QAAUE,GAAEC,EAAEC,EAAEC,GAAG,QAASC,GAAEC,EAAEC,GAAG,IAAIJ,EAAEG,GAAG,CAAC,IAAIJ,EAAEI,GAAG,CAAC,GAAIE,GAAkB,kBAATV,IAAqBA,CAAQ,KAAIS,GAAGC,EAAE,MAAOA,GAAEF,GAAE,EAAI,IAAGG,EAAE,MAAOA,GAAEH,GAAE,EAAI,IAAII,GAAE,GAAIC,OAAM,uBAAuBL,EAAE,IAAK,MAAMI,GAAEE,KAAK,mBAAmBF,EAAE,GAAIG,GAAEV,EAAEG,IAAIQ,WAAYZ,GAAEI,GAAG,GAAGS,KAAKF,EAAEC,QAAQ,SAASb,GAAG,GAAIE,GAAED,EAAEI,GAAG,GAAGL,EAAG,OAAOI,GAAEF,GAAIF,IAAIY,EAAEA,EAAEC,QAAQb,EAAEC,EAAEC,EAAEC,GAAG,MAAOD,GAAEG,GAAGQ,QAAkD,IAAI,GAA1CL,GAAkB,kBAATX,IAAqBA,EAAgBQ,EAAE,EAAEA,EAAEF,EAAEY,OAAOV,IAAID,EAAED,EAAEE,GAAI,OAAOD,KAAKY,GAAG,SAASnB,EAAQoB,EAAOJ,GACvhB,YAIA,IAAIK,GAAIC,OAAOD,EAAIrB,EAAQ,WACvBuB,EAAevB,EAAQ,wBAGvBwB,EAAUC,SAASC,eAAe,eAClCC,EAAS,GAAIJ,GACbK,EAAO5B,EAAQ,mBAAmBwB,GAClCK,EAAU7B,EAAQ,sBAClB8B,EAAW9B,EAAQ,uBAAuBwB,EAASK,EAASF,GAG5DI,EAAc/B,EAAQ,2BACtBgC,E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G,EAAM0B,UAAY,SAAmBvB,EAAKpgB,GACtC,GACI4f,GACAC,EACApjB,EACA6L,EAJAsZ,EAAe7hB,KAAKygB,qBAAqBJ,EAO7C,KAAK9X,IAAOsZ,GACR,GAAIA,EAAa9Z,eAAeQ,GAG5B,IAFAsX,EAAYgC,EAAatZ,GAAKiJ,MAAM,GAE/B9U,EAAI,EAAGA,EAAImjB,EAAU5iB,OAAQP,IAG9BojB,EAAWD,EAAUnjB,IAEC,IAAlBojB,EAASc,MACT5gB,KAAKihB,eAAeZ,EAAKP,EAASA,UAG3BA,EAASA,SAAS1f,MAAMJ,KAAMC,SAExBD,KAAK8hB,uBAClB9hB,KAAKihB,eAAeZ,EAAKP,EAASA;4FAMlD,OAAO9f,OAMXkgB,EAAMvb,QAAUob,EAAM,aAUtBG,EAAM6B,KAAO,SAAc1B,GACvB,GAAIpgB,GAAOT,MAAMC,UAAU+R,MAAMxU,KAAKkD,UAAW,EACjD,OAAOF,MAAK4hB,UAAUvB,EAAKpgB,IAW/BigB,EAAM8B,mBAAqB,SAA4BrhB,GAEnD,MADAX,MAAKiiB,iBAAmBthB,EACjBX,MAWXkgB,EAAM4B,oBAAsB,WACxB,OAAI9hB,KAAK+H,eAAe,qBACb/H,KAAKiiB,kBAapB/B,EAAMI,WAAa,WACf,MAAOtgB,MAAK0hB,UAAY1hB,KAAK0hB,aAQjCpkB,EAAa4kB,WAAa,WAEtB,MADAnlB,GAAQO,aAAe6iB,EAChB7iB,GAIW,kBAAXrB,IAAyBA,EAAOkmB,IACvClmB,EAAO,WACH,MAAOqB,KAGY,gBAAXH,IAAuBA,EAAOJ,QAC1CI,EAAOJ,QAAUO,EAGjBP,EAAQO,aAAeA,GAE7B0C,oBAES","file":"admin.min.js","sourcesContent":["(function () { var require = undefined; var define = undefined; (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\n'use strict';\n\n// dependencies\n\nvar m = window.m = require('mithril');\nvar EventEmitter = require('wolfy87-eventemitter');\n\n// vars\nvar context = document.getElementById('mc4wp-admin');\nvar events = new EventEmitter();\nvar tabs = require('./admin/tabs.js')(context);\nvar helpers = require('./admin/helpers.js');\nvar settings = require('./admin/settings.js')(context, helpers, events);\n\n// list fetcher\nvar ListFetcher = require('./admin/list-fetcher.js');\nvar mount = document.getElementById('mc4wp-list-fetcher');\nif (mount) {\n m.mount(mount, new ListFetcher());\n}\n\n// expose some things\nwindow.mc4wp = window.mc4wp || {};\nwindow.mc4wp.deps = window.mc4wp.deps || {};\nwindow.mc4wp.deps.mithril = m;\nwindow.mc4wp.helpers = helpers;\nwindow.mc4wp.events = events;\nwindow.mc4wp.settings = settings;\nwindow.mc4wp.tabs = tabs;\n\n},{\"./admin/helpers.js\":2,\"./admin/list-fetcher.js\":3,\"./admin/settings.js\":4,\"./admin/tabs.js\":5,\"mithril\":7,\"wolfy87-eventemitter\":8}],2:[function(require,module,exports){\n'use strict';\n\nvar helpers = {};\n\nhelpers.toggleElement = function (selector) {\n\tvar elements = document.querySelectorAll(selector);\n\tfor (var i = 0; i < elements.length; i++) {\n\t\tvar show = elements[i].clientHeight <= 0;\n\t\telements[i].style.display = show ? '' : 'none';\n\t}\n};\n\nhelpers.bindEventToElement = function (element, event, handler) {\n\tif (element.addEventListener) {\n\t\telement.addEventListener(event, handler);\n\t} else if (element.attachEvent) {\n\t\telement.attachEvent('on' + event, handler);\n\t}\n};\n\nhelpers.bindEventToElements = function (elements, event, handler) {\n\tArray.prototype.forEach.call(elements, function (element) {\n\t\thelpers.bindEventToElement(element, event, handler);\n\t});\n};\n\n// polling\nhelpers.debounce = function (func, wait, immediate) {\n\tvar timeout;\n\treturn function () {\n\t\tvar context = this,\n\t\t args = arguments;\n\t\tvar later = function later() {\n\t\t\ttimeout = null;\n\t\t\tif (!immediate) func.apply(context, args);\n\t\t};\n\t\tvar callNow = immediate && !timeout;\n\t\tclearTimeout(timeout);\n\t\ttimeout = setTimeout(later, wait);\n\t\tif (callNow) func.apply(context, args);\n\t};\n};\n\n/**\n * Showif.js\n */\n(function () {\n\tvar showIfElements = document.querySelectorAll('[data-showif]');\n\n\t// dependent elements\n\tArray.prototype.forEach.call(showIfElements, function (element) {\n\t\tvar config = JSON.parse(element.getAttribute('data-showif'));\n\t\tvar parentElements = document.querySelectorAll('[name=\"' + config.element + '\"]');\n\t\tvar inputs = element.querySelectorAll('input,select,textarea:not([readonly])');\n\t\tvar hide = config.hide === undefined || config.hide;\n\n\t\tfunction toggleElement() {\n\n\t\t\t// do nothing with unchecked radio inputs\n\t\t\tif (this.getAttribute('type') === \"radio\" && !this.checked) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvar value = this.getAttribute(\"type\") === \"checkbox\" ? this.checked : this.value;\n\t\t\tvar conditionMet = value == config.value;\n\n\t\t\tif (hide) {\n\t\t\t\telement.style.display = conditionMet ? '' : 'none';\n\t\t\t\telement.style.visibility = conditionMet ? '' : 'hidden';\n\t\t\t} else {\n\t\t\t\telement.style.opacity = conditionMet ? '' : '0.4';\n\t\t\t}\n\n\t\t\t// disable input fields to stop sending their values to server\n\t\t\tArray.prototype.forEach.call(inputs, function (inputElement) {\n\t\t\t\tconditionMet ? inputElement.removeAttribute('readonly') : inputElement.setAttribute('readonly', 'readonly');\n\t\t\t});\n\t\t}\n\n\t\t// find checked element and call toggleElement function\n\t\tArray.prototype.forEach.call(parentElements, function (parentElement) {\n\t\t\ttoggleElement.call(parentElement);\n\t\t});\n\n\t\t// bind on all changes\n\t\thelpers.bindEventToElements(parentElements, 'change', toggleElement);\n\t});\n})();\n\nmodule.exports = helpers;\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nvar $ = window.jQuery;\nvar config = mc4wp_vars;\nvar i18n = config.i18n;\n\nfunction ListFetcher() {\n this.working = false;\n this.done = false;\n\n // start fetching right away when no lists but api key given\n if (config.mailchimp.api_connected && config.mailchimp.lists.length == 0) {\n this.fetch();\n }\n}\n\nListFetcher.prototype.fetch = function (e) {\n e && e.preventDefault();\n\n this.working = true;\n this.done = false;\n\n $.post(ajaxurl, {\n action: \"mc4wp_renew_mailchimp_lists\"\n }).done(function (data) {\n if (data) {\n window.setTimeout(function () {\n window.location.reload();\n }, 3000);\n }\n }).always(function (data) {\n this.working = false;\n this.done = true;\n\n m.redraw();\n }.bind(this));\n};\n\nListFetcher.prototype.view = function () {\n return m('form', {\n method: \"POST\",\n onsubmit: this.fetch.bind(this)\n }, [m('p', [m('input', {\n type: \"submit\",\n value: this.working ? i18n.fetching_mailchimp_lists : i18n.renew_mailchimp_lists,\n className: \"button\",\n disabled: !!this.working\n }), m.trust(' &nbsp; '), this.working ? [m('span.mc4wp-loader', \"Loading...\"), m.trust(' &nbsp; '), m('em.help', i18n.fetching_mailchimp_lists_can_take_a_while)] : '', this.done ? [m('em.help.green', i18n.fetching_mailchimp_lists_done)] : ''])]);\n};\n\nmodule.exports = ListFetcher;\n\n},{}],4:[function(require,module,exports){\n'use strict';\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar Settings = function Settings(context, helpers, events) {\n\t'use strict';\n\n\t// vars\n\n\tvar form = context.querySelector('form');\n\tvar listInputs = context.querySelectorAll('.mc4wp-list-input');\n\tvar lists = mc4wp_vars.mailchimp.lists;\n\tvar selectedLists = [];\n\n\t// functions\n\tfunction getSelectedListsWhere(searchKey, searchValue) {\n\t\treturn selectedLists.filter(function (el) {\n\t\t\treturn el[searchKey] === searchValue;\n\t\t});\n\t}\n\n\tfunction getSelectedLists() {\n\t\treturn selectedLists;\n\t}\n\n\tfunction updateSelectedLists() {\n\t\tselectedLists = [];\n\n\t\tArray.prototype.forEach.call(listInputs, function (input) {\n\t\t\t// skip unchecked checkboxes\n\t\t\tif (typeof input.checked === \"boolean\" && !input.checked) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (_typeof(lists[input.value]) === \"object\") {\n\t\t\t\tselectedLists.push(lists[input.value]);\n\t\t\t}\n\t\t});\n\n\t\tevents.trigger('selectedLists.change', [selectedLists]);\n\t\treturn selectedLists;\n\t}\n\n\tfunction toggleVisibleLists() {\n\t\tvar rows = document.querySelectorAll('.lists--only-selected > *');\n\t\tArray.prototype.forEach.call(rows, function (el) {\n\n\t\t\tvar listId = el.getAttribute('data-list-id');\n\t\t\tvar isSelected = getSelectedListsWhere('id', listId).length > 0;\n\n\t\t\tif (isSelected) {\n\t\t\t\tel.setAttribute('class', el.getAttribute('class').replace('hidden', ''));\n\t\t\t} else {\n\t\t\t\tel.setAttribute('class', el.getAttribute('class') + \" hidden\");\n\t\t\t}\n\t\t});\n\t}\n\n\tevents.on('selectedLists.change', toggleVisibleLists);\n\thelpers.bindEventToElements(listInputs, 'change', updateSelectedLists);\n\n\tupdateSelectedLists();\n\n\treturn {\n\t\tgetSelectedLists: getSelectedLists\n\t};\n};\n\nmodule.exports = Settings;\n\n},{}],5:[function(require,module,exports){\n'use strict';\n\nvar URL = require('./url.js');\n\n// Tabs\nvar Tabs = function Tabs(context) {\n\n\t// TODO: last piece of jQuery... can we get rid of it?\n\tvar $ = window.jQuery;\n\n\tvar $context = $(context);\n\tvar $tabs = $context.find('.tab');\n\tvar $tabNavs = $context.find('.nav-tab');\n\tvar refererField = context.querySelector('input[name=\"_wp_http_referer\"]');\n\tvar tabs = [];\n\n\t$.each($tabs, function (i, t) {\n\t\tvar id = t.id.substring(4);\n\t\tvar title = $(t).find('h2').first().text();\n\n\t\ttabs.push({\n\t\t\tid: id,\n\t\t\ttitle: title,\n\t\t\telement: t,\n\t\t\tnav: context.querySelectorAll('.nav-tab-' + id),\n\t\t\topen: function open() {\n\t\t\t\treturn _open(id);\n\t\t\t}\n\t\t});\n\t});\n\n\tfunction get(id) {\n\n\t\tfor (var i = 0; i < tabs.length; i++) {\n\t\t\tif (tabs[i].id === id) {\n\t\t\t\treturn tabs[i];\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tfunction _open(tab, updateState) {\n\n\t\t// make sure we have a tab object\n\t\tif (typeof tab === \"string\") {\n\t\t\ttab = get(tab);\n\t\t}\n\n\t\tif (!tab) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// should we update state?\n\t\tif (updateState == undefined) {\n\t\t\tupdateState = true;\n\t\t}\n\n\t\t// hide all tabs & remove active class\n\t\t$tabs.removeClass('tab-active').css('display', 'none');\n\t\t$tabNavs.removeClass('nav-tab-active');\n\n\t\t// add `nav-tab-active` to this tab\n\t\tArray.prototype.forEach.call(tab.nav, function (nav) {\n\t\t\tnav.className += \" nav-tab-active\";\n\t\t\tnav.blur();\n\t\t});\n\n\t\t// show target tab\n\t\ttab.element.style.display = 'block';\n\t\ttab.element.className += \" tab-active\";\n\n\t\t// create new URL\n\t\tvar url = URL.setParameter(window.location.href, \"tab\", tab.id);\n\n\t\t// update hash\n\t\tif (history.pushState && updateState) {\n\t\t\thistory.pushState(tab.id, '', url);\n\t\t}\n\n\t\t// update document title\n\t\ttitle(tab);\n\n\t\t// update referer field\n\t\trefererField.value = url;\n\n\t\t// if thickbox is open, close it.\n\t\tif (typeof tb_remove === \"function\") {\n\t\t\ttb_remove();\n\t\t}\n\n\t\t// refresh editor after switching tabs\n\t\t// TODO: decouple this! law of demeter etc.\n\t\tif (tab.id === 'fields' && window.mc4wp && window.mc4wp.forms && window.mc4wp.forms.editor) {\n\t\t\tmc4wp.forms.editor.refresh();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tfunction title(tab) {\n\t\tvar title = document.title.split('-');\n\t\tdocument.title = document.title.replace(title[0], tab.title + \" \");\n\t}\n\n\tfunction switchTab(e) {\n\t\te = e || window.event;\n\n\t\t// get from data attribute\n\t\tvar tabId = this.getAttribute('data-tab');\n\n\t\t// get from classname\n\t\tif (!tabId) {\n\t\t\tvar match = this.className.match(/nav-tab-(\\w+)?/);\n\t\t\tif (match) {\n\t\t\t\ttabId = match[1];\n\t\t\t}\n\t\t}\n\n\t\t// get from href\n\t\tif (!tabId) {\n\t\t\tvar urlParams = URL.parse(this.href);\n\t\t\tif (!urlParams.tab) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttabId = urlParams.tab;\n\t\t}\n\n\t\tvar opened = _open(tabId);\n\n\t\tif (opened) {\n\t\t\te.preventDefault();\n\t\t\te.returnValue = false;\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tfunction init() {\n\n\t\t// check for current tab\n\t\tif (!history.pushState) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar activeTab = $tabs.filter(':visible').get(0);\n\t\tif (!activeTab) {\n\t\t\treturn;\n\t\t}\n\t\tvar tab = get(activeTab.id.substring(4));\n\t\tif (!tab) return;\n\n\t\t// check if tab is in html5 history\n\t\tif (history.replaceState && history.state === null) {\n\t\t\thistory.replaceState(tab.id, '');\n\t\t}\n\n\t\t// update document title\n\t\ttitle(tab);\n\t}\n\n\t$tabNavs.click(switchTab);\n\t$(document.body).on('click', '.tab-link', switchTab);\n\tinit();\n\n\tif (window.addEventListener && history.pushState) {\n\t\twindow.addEventListener('popstate', function (e) {\n\t\t\tif (!e.state) return true;\n\t\t\tvar tabId = e.state;\n\t\t\treturn _open(tabId, false);\n\t\t});\n\t}\n\n\treturn {\n\t\topen: _open,\n\t\tget: get\n\t};\n};\n\nmodule.exports = Tabs;\n\n},{\"./url.js\":6}],6:[function(require,module,exports){\n'use strict';\n\nvar URL = {\n\tparse: function parse(url) {\n\t\tvar query = {};\n\t\tvar a = url.split('&');\n\t\tfor (var i in a) {\n\t\t\tif (!a.hasOwnProperty(i)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvar b = a[i].split('=');\n\t\t\tquery[decodeURIComponent(b[0])] = decodeURIComponent(b[1]);\n\t\t}\n\n\t\treturn query;\n\t},\n\tbuild: function build(data) {\n\t\tvar ret = [];\n\t\tfor (var d in data) {\n\t\t\tret.push(d + \"=\" + encodeURIComponent(data[d]));\n\t\t}return ret.join(\"&\");\n\t},\n\tsetParameter: function setParameter(url, key, value) {\n\t\tvar data = URL.parse(url);\n\t\tdata[key] = value;\n\t\treturn URL.build(data);\n\t}\n};\n\nmodule.exports = URL;\n\n},{}],7:[function(require,module,exports){\n(function (global){\n;(function() {\n\"use strict\"\nfunction Vnode(tag, key, attrs0, children, text, dom) {\n\treturn {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: undefined, _state: undefined, events: undefined, instance: undefined, skip: false}\n}\nVnode.normalize = function(node) {\n\tif (Array.isArray(node)) return Vnode(\"[\", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)\n\tif (node != null && typeof node !== \"object\") return Vnode(\"#\", undefined, undefined, node === false ? \"\" : node, undefined, undefined)\n\treturn node\n}\nVnode.normalizeChildren = function normalizeChildren(children) {\n\tfor (var i = 0; i < children.length; i++) {\n\t\tchildren[i] = Vnode.normalize(children[i])\n\t}\n\treturn children\n}\nvar selectorParser = /(?:(^|#|\\.)([^#\\.\\[\\]]+))|(\\[(.+?)(?:\\s*=\\s*(\"|'|)((?:\\\\[\"'\\]]|.)*?)\\5)?\\])/g\nvar selectorCache = {}\nvar hasOwn = {}.hasOwnProperty\nfunction compileSelector(selector) {\n\tvar match, tag = \"div\", classes = [], attrs = {}\n\twhile (match = selectorParser.exec(selector)) {\n\t\tvar type = match[1], value = match[2]\n\t\tif (type === \"\" && value !== \"\") tag = value\n\t\telse if (type === \"#\") attrs.id = value\n\t\telse if (type === \".\") classes.push(value)\n\t\telse if (match[3][0] === \"[\") {\n\t\t\tvar attrValue = match[6]\n\t\t\tif (attrValue) attrValue = attrValue.replace(/\\\\([\"'])/g, \"$1\").replace(/\\\\\\\\/g, \"\\\\\")\n\t\t\tif (match[4] === \"class\") classes.push(attrValue)\n\t\t\telse attrs[match[4]] = attrValue || true\n\t\t}\n\t}\n\tif (classes.length > 0) attrs.className = classes.join(\" \")\n\treturn selectorCache[selector] = {tag: tag, attrs: attrs}\n}\nfunction execSelector(state, attrs, children) {\n\tvar hasAttrs = false, childList, text\n\tvar className = attrs.className || attrs.class\n\tfor (var key in state.attrs) {\n\t\tif (hasOwn.call(state.attrs, key)) {\n\t\t\tattrs[key] = state.attrs[key]\n\t\t}\n\t}\n\tif (className !== undefined) {\n\t\tif (attrs.class !== undefined) {\n\t\t\tattrs.class = undefined\n\t\t\tattrs.className = className\n\t\t}\n\t\tif (state.attrs.className != null) {\n\t\t\tattrs.className = state.attrs.className + \" \" + className\n\t\t}\n\t}\n\tfor (var key in attrs) {\n\t\tif (hasOwn.call(attrs, key) && key !== \"key\") {\n\t\t\thasAttrs = true\n\t\t\tbreak\n\t\t}\n\t}\n\tif (Array.isArray(children) && children.length === 1 && children[0] != null && children[0].tag === \"#\") {\n\t\ttext = children[0].children\n\t} else {\n\t\tchildList = children\n\t}\n\treturn Vnode(state.tag, attrs.key, hasAttrs ? attrs : undefined, childList, text)\n}\nfunction hyperscript(selector) {\n\t// Because sloppy mode sucks\n\tvar attrs = arguments[1], start = 2, children\n\tif (selector == null || typeof selector !== \"string\" && typeof selector !== \"function\" && typeof selector.view !== \"function\") {\n\t\tthrow Error(\"The selector must be either a string or a component.\");\n\t}\n\tif (typeof selector === \"string\") {\n\t\tvar cached = selectorCache[selector] || compileSelector(selector)\n\t}\n\tif (attrs == null) {\n\t\tattrs = {}\n\t} else if (typeof attrs !== \"object\" || attrs.tag != null || Array.isArray(attrs)) {\n\t\tattrs = {}\n\t\tstart = 1\n\t}\n\tif (arguments.length === start + 1) {\n\t\tchildren = arguments[start]\n\t\tif (!Array.isArray(children)) children = [children]\n\t} else {\n\t\tchildren = []\n\t\twhile (start < arguments.length) children.push(arguments[start++])\n\t}\n\tvar normalized = Vnode.normalizeChildren(children)\n\tif (typeof selector === \"string\") {\n\t\treturn execSelector(cached, attrs, normalized)\n\t} else {\n\t\treturn Vnode(selector, attrs.key, attrs, normalized)\n\t}\n}\nhyperscript.trust = function(html) {\n\tif (html == null) html = \"\"\n\treturn Vnode(\"<\", undefined, undefined, html, undefined, undefined)\n}\nhyperscript.fragment = function(attrs1, children) {\n\treturn Vnode(\"[\", attrs1.key, attrs1, Vnode.normalizeChildren(children), undefined, undefined)\n}\nvar m = hyperscript\n/** @constructor */\nvar PromisePolyfill = function(executor) {\n\tif (!(this instanceof PromisePolyfill)) throw new Error(\"Promise must be called with `new`\")\n\tif (typeof executor !== \"function\") throw new TypeError(\"executor must be a function\")\n\tvar self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false)\n\tvar instance = self._instance = {resolvers: resolvers, rejectors: rejectors}\n\tvar callAsync = typeof setImmediate === \"function\" ? setImmediate : setTimeout\n\tfunction handler(list, shouldAbsorb) {\n\t\treturn function execute(value) {\n\t\t\tvar then\n\t\t\ttry {\n\t\t\t\tif (shouldAbsorb && value != null && (typeof value === \"object\" || typeof value === \"function\") && typeof (then = value.then) === \"function\") {\n\t\t\t\t\tif (value === self) throw new TypeError(\"Promise can't be resolved w/ itself\")\n\t\t\t\t\texecuteOnce(then.bind(value))\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tcallAsync(function() {\n\t\t\t\t\t\tif (!shouldAbsorb && list.length === 0) console.error(\"Possible unhandled promise rejection:\", value)\n\t\t\t\t\t\tfor (var i = 0; i < list.length; i++) list[i](value)\n\t\t\t\t\t\tresolvers.length = 0, rejectors.length = 0\n\t\t\t\t\t\tinstance.state = shouldAbsorb\n\t\t\t\t\t\tinstance.retry = function() {execute(value)}\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\trejectCurrent(e)\n\t\t\t}\n\t\t}\n\t}\n\tfunction executeOnce(then) {\n\t\tvar runs = 0\n\t\tfunction run(fn) {\n\t\t\treturn function(value) {\n\t\t\t\tif (runs++ > 0) return\n\t\t\t\tfn(value)\n\t\t\t}\n\t\t}\n\t\tvar onerror = run(rejectCurrent)\n\t\ttry {then(run(resolveCurrent), onerror)} catch (e) {onerror(e)}\n\t}\n\texecuteOnce(executor)\n}\nPromisePolyfill.prototype.then = function(onFulfilled, onRejection) {\n\tvar self = this, instance = self._instance\n\tfunction handle(callback, list, next, state) {\n\t\tlist.push(function(value) {\n\t\t\tif (typeof callback !== \"function\") next(value)\n\t\t\telse try {resolveNext(callback(value))} catch (e) {if (rejectNext) rejectNext(e)}\n\t\t})\n\t\tif (typeof instance.retry === \"function\" && state === instance.state) instance.retry()\n\t}\n\tvar resolveNext, rejectNext\n\tvar promise = new PromisePolyfill(function(resolve, reject) {resolveNext = resolve, rejectNext = reject})\n\thandle(onFulfilled, instance.resolvers, resolveNext, true), handle(onRejection, instance.rejectors, rejectNext, false)\n\treturn promise\n}\nPromisePolyfill.prototype.catch = function(onRejection) {\n\treturn this.then(null, onRejection)\n}\nPromisePolyfill.resolve = function(value) {\n\tif (value instanceof PromisePolyfill) return value\n\treturn new PromisePolyfill(function(resolve) {resolve(value)})\n}\nPromisePolyfill.reject = function(value) {\n\treturn new PromisePolyfill(function(resolve, reject) {reject(value)})\n}\nPromisePolyfill.all = function(list) {\n\treturn new PromisePolyfill(function(resolve, reject) {\n\t\tvar total = list.length, count = 0, values = []\n\t\tif (list.length === 0) resolve([])\n\t\telse for (var i = 0; i < list.length; i++) {\n\t\t\t(function(i) {\n\t\t\t\tfunction consume(value) {\n\t\t\t\t\tcount++\n\t\t\t\t\tvalues[i] = value\n\t\t\t\t\tif (count === total) resolve(values)\n\t\t\t\t}\n\t\t\t\tif (list[i] != null && (typeof list[i] === \"object\" || typeof list[i] === \"function\") && typeof list[i].then === \"function\") {\n\t\t\t\t\tlist[i].then(consume, reject)\n\t\t\t\t}\n\t\t\t\telse consume(list[i])\n\t\t\t})(i)\n\t\t}\n\t})\n}\nPromisePolyfill.race = function(list) {\n\treturn new PromisePolyfill(function(resolve, reject) {\n\t\tfor (var i = 0; i < list.length; i++) {\n\t\t\tlist[i].then(resolve, reject)\n\t\t}\n\t})\n}\nif (typeof window !== \"undefined\") {\n\tif (typeof window.Promise === \"undefined\") window.Promise = PromisePolyfill\n\tvar PromisePolyfill = window.Promise\n} else if (typeof global !== \"undefined\") {\n\tif (typeof global.Promise === \"undefined\") global.Promise = PromisePolyfill\n\tvar PromisePolyfill = global.Promise\n} else {\n}\nvar buildQueryString = function(object) {\n\tif (Object.prototype.toString.call(object) !== \"[object Object]\") return \"\"\n\tvar args = []\n\tfor (var key0 in object) {\n\t\tdestructure(key0, object[key0])\n\t}\n\treturn args.join(\"&\")\n\tfunction destructure(key0, value) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (var i = 0; i < value.length; i++) {\n\t\t\t\tdestructure(key0 + \"[\" + i + \"]\", value[i])\n\t\t\t}\n\t\t}\n\t\telse if (Object.prototype.toString.call(value) === \"[object Object]\") {\n\t\t\tfor (var i in value) {\n\t\t\t\tdestructure(key0 + \"[\" + i + \"]\", value[i])\n\t\t\t}\n\t\t}\n\t\telse args.push(encodeURIComponent(key0) + (value != null && value !== \"\" ? \"=\" + encodeURIComponent(value) : \"\"))\n\t}\n}\nvar FILE_PROTOCOL_REGEX = new RegExp(\"^file://\", \"i\")\nvar _8 = function($window, Promise) {\n\tvar callbackCount = 0\n\tvar oncompletion\n\tfunction setCompletionCallback(callback) {oncompletion = callback}\n\tfunction finalizer() {\n\t\tvar count = 0\n\t\tfunction complete() {if (--count === 0 && typeof oncompletion === \"function\") oncompletion()}\n\t\treturn function finalize(promise0) {\n\t\t\tvar then0 = promise0.then\n\t\t\tpromise0.then = function() {\n\t\t\t\tcount++\n\t\t\t\tvar next = then0.apply(promise0, arguments)\n\t\t\t\tnext.then(complete, function(e) {\n\t\t\t\t\tcomplete()\n\t\t\t\t\tif (count === 0) throw e\n\t\t\t\t})\n\t\t\t\treturn finalize(next)\n\t\t\t}\n\t\t\treturn promise0\n\t\t}\n\t}\n\tfunction normalize(args, extra) {\n\t\tif (typeof args === \"string\") {\n\t\t\tvar url = args\n\t\t\targs = extra || {}\n\t\t\tif (args.url == null) args.url = url\n\t\t}\n\t\treturn args\n\t}\n\tfunction request(args, extra) {\n\t\tvar finalize = finalizer()\n\t\targs = normalize(args, extra)\n\t\tvar promise0 = new Promise(function(resolve, reject) {\n\t\t\tif (args.method == null) args.method = \"GET\"\n\t\t\targs.method = args.method.toUpperCase()\n\t\t\tvar useBody = (args.method === \"GET\" || args.method === \"TRACE\") ? false : (typeof args.useBody === \"boolean\" ? args.useBody : true)\n\t\t\tif (typeof args.serialize !== \"function\") args.serialize = typeof FormData !== \"undefined\" && args.data instanceof FormData ? function(value) {return value} : JSON.stringify\n\t\t\tif (typeof args.deserialize !== \"function\") args.deserialize = deserialize\n\t\t\tif (typeof args.extract !== \"function\") args.extract = extract\n\t\t\targs.url = interpolate(args.url, args.data)\n\t\t\tif (useBody) args.data = args.serialize(args.data)\n\t\t\telse args.url = assemble(args.url, args.data)\n\t\t\tvar xhr = new $window.XMLHttpRequest(),\n\t\t\t\taborted = false,\n\t\t\t\t_abort = xhr.abort\n\t\t\txhr.abort = function abort() {\n\t\t\t\taborted = true\n\t\t\t\t_abort.call(xhr)\n\t\t\t}\n\t\t\txhr.open(args.method, args.url, typeof args.async === \"boolean\" ? args.async : true, typeof args.user === \"string\" ? args.user : undefined, typeof args.password === \"string\" ? args.password : undefined)\n\t\t\tif (args.serialize === JSON.stringify && useBody) {\n\t\t\t\txhr.setRequestHeader(\"Content-Type\", \"application/json; charset=utf-8\")\n\t\t\t}\n\t\t\tif (args.deserialize === deserialize) {\n\t\t\t\txhr.setRequestHeader(\"Accept\", \"application/json, text/*\")\n\t\t\t}\n\t\t\tif (args.withCredentials) xhr.withCredentials = args.withCredentials\n\t\t\tfor (var key in args.headers) if ({}.hasOwnProperty.call(args.headers, key)) {\n\t\t\t\txhr.setRequestHeader(key, args.headers[key])\n\t\t\t}\n\t\t\tif (typeof args.config === \"function\") xhr = args.config(xhr, args) || xhr\n\t\t\txhr.onreadystatechange = function() {\n\t\t\t\t// Don't throw errors on xhr.abort().\n\t\t\t\tif(aborted) return\n\t\t\t\tif (xhr.readyState === 4) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvar response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args))\n\t\t\t\t\t\tif ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || FILE_PROTOCOL_REGEX.test(args.url)) {\n\t\t\t\t\t\t\tresolve(cast(args.type, response))\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tvar error = new Error(xhr.responseText)\n\t\t\t\t\t\t\tfor (var key in response) error[key] = response[key]\n\t\t\t\t\t\t\treject(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\treject(e)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (useBody && (args.data != null)) xhr.send(args.data)\n\t\t\telse xhr.send()\n\t\t})\n\t\treturn args.background === true ? promise0 : finalize(promise0)\n\t}\n\tfunction jsonp(args, extra) {\n\t\tvar finalize = finalizer()\n\t\targs = normalize(args, extra)\n\t\tvar promise0 = new Promise(function(resolve, reject) {\n\t\t\tvar callbackName = args.callbackName || \"_mithril_\" + Math.round(Math.random() * 1e16) + \"_\" + callbackCount++\n\t\t\tvar script = $window.document.createElement(\"script\")\n\t\t\t$window[callbackName] = function(data) {\n\t\t\t\tscript.parentNode.removeChild(script)\n\t\t\t\tresolve(cast(args.type, data))\n\t\t\t\tdelete $window[callbackName]\n\t\t\t}\n\t\t\tscript.onerror = function() {\n\t\t\t\tscript.parentNode.removeChild(script)\n\t\t\t\treject(new Error(\"JSONP request failed\"))\n\t\t\t\tdelete $window[callbackName]\n\t\t\t}\n\t\t\tif (args.data == null) args.data = {}\n\t\t\targs.url = interpolate(args.url, args.data)\n\t\t\targs.data[args.callbackKey || \"callback\"] = callbackName\n\t\t\tscript.src = assemble(args.url, args.data)\n\t\t\t$window.document.documentElement.appendChild(script)\n\t\t})\n\t\treturn args.background === true? promise0 : finalize(promise0)\n\t}\n\tfunction interpolate(url, data) {\n\t\tif (data == null) return url\n\t\tvar tokens = url.match(/:[^\\/]+/gi) || []\n\t\tfor (var i = 0; i < tokens.length; i++) {\n\t\t\tvar key = tokens[i].slice(1)\n\t\t\tif (data[key] != null) {\n\t\t\t\turl = url.replace(tokens[i], data[key])\n\t\t\t}\n\t\t}\n\t\treturn url\n\t}\n\tfunction assemble(url, data) {\n\t\tvar querystring = buildQueryString(data)\n\t\tif (querystring !== \"\") {\n\t\t\tvar prefix = url.indexOf(\"?\") < 0 ? \"?\" : \"&\"\n\t\t\turl += prefix + querystring\n\t\t}\n\t\treturn url\n\t}\n\tfunction deserialize(data) {\n\t\ttry {return data !== \"\" ? JSON.parse(data) : null}\n\t\tcatch (e) {throw new Error(data)}\n\t}\n\tfunction extract(xhr) {return xhr.responseText}\n\tfunction cast(type0, data) {\n\t\tif (typeof type0 === \"function\") {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\tfor (var i = 0; i < data.length; i++) {\n\t\t\t\t\tdata[i] = new type0(data[i])\n\t\t\t\t}\n\t\t\t}\n\t\t\telse return new type0(data)\n\t\t}\n\t\treturn data\n\t}\n\treturn {request: request, jsonp: jsonp, setCompletionCallback: setCompletionCallback}\n}\nvar requestService = _8(window, PromisePolyfill)\nvar coreRenderer = function($window) {\n\tvar $doc = $window.document\n\tvar $emptyFragment = $doc.createDocumentFragment()\n\tvar onevent\n\tfunction setEventCallback(callback) {return onevent = callback}\n\t//create\n\tfunction createNodes(parent, vnodes, start, end, hooks, nextSibling, ns) {\n\t\tfor (var i = start; i < end; i++) {\n\t\t\tvar vnode = vnodes[i]\n\t\t\tif (vnode != null) {\n\t\t\t\tcreateNode(parent, vnode, hooks, ns, nextSibling)\n\t\t\t}\n\t\t}\n\t}\n\tfunction createNode(parent, vnode, hooks, ns, nextSibling) {\n\t\tvar tag = vnode.tag\n\t\tif (typeof tag === \"string\") {\n\t\t\tvnode.state = {}\n\t\t\tif (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)\n\t\t\tswitch (tag) {\n\t\t\t\tcase \"#\": return createText(parent, vnode, nextSibling)\n\t\t\t\tcase \"<\": return createHTML(parent, vnode, nextSibling)\n\t\t\t\tcase \"[\": return createFragment(parent, vnode, hooks, ns, nextSibling)\n\t\t\t\tdefault: return createElement(parent, vnode, hooks, ns, nextSibling)\n\t\t\t}\n\t\t}\n\t\telse return createComponent(parent, vnode, hooks, ns, nextSibling)\n\t}\n\tfunction createText(parent, vnode, nextSibling) {\n\t\tvnode.dom = $doc.createTextNode(vnode.children)\n\t\tinsertNode(parent, vnode.dom, nextSibling)\n\t\treturn vnode.dom\n\t}\n\tfunction createHTML(parent, vnode, nextSibling) {\n\t\tvar match1 = vnode.children.match(/^\\s*?<(\\w+)/im) || []\n\t\tvar parent1 = {caption: \"table\", thead: \"table\", tbody: \"table\", tfoot: \"table\", tr: \"tbody\", th: \"tr\", td: \"tr\", colgroup: \"table\", col: \"colgroup\"}[match1[1]] || \"div\"\n\t\tvar temp = $doc.createElement(parent1)\n\t\ttemp.innerHTML = vnode.children\n\t\tvnode.dom = temp.firstChild\n\t\tvnode.domSize = temp.childNodes.length\n\t\tvar fragment = $doc.createDocumentFragment()\n\t\tvar child\n\t\twhile (child = temp.firstChild) {\n\t\t\tfragment.appendChild(child)\n\t\t}\n\t\tinsertNode(parent, fragment, nextSibling)\n\t\treturn fragment\n\t}\n\tfunction createFragment(parent, vnode, hooks, ns, nextSibling) {\n\t\tvar fragment = $doc.createDocumentFragment()\n\t\tif (vnode.children != null) {\n\t\t\tvar children = vnode.children\n\t\t\tcreateNodes(fragment, children, 0, children.length, hooks, null, ns)\n\t\t}\n\t\tvnode.dom = fragment.firstChild\n\t\tvnode.domSize = fragment.childNodes.length\n\t\tinsertNode(parent, fragment, nextSibling)\n\t\treturn fragment\n\t}\n\tfunction createElement(parent, vnode, hooks, ns, nextSibling) {\n\t\tvar tag = vnode.tag\n\t\tswitch (vnode.tag) {\n\t\t\tcase \"svg\": ns = \"http://www.w3.org/2000/svg\"; break\n\t\t\tcase \"math\": ns = \"http://www.w3.org/1998/Math/MathML\"; break\n\t\t}\n\t\tvar attrs2 = vnode.attrs\n\t\tvar is = attrs2 && attrs2.is\n\t\tvar element = ns ?\n\t\t\tis ? $doc.createElementNS(ns, tag, {is: is}) : $doc.createElementNS(ns, tag) :\n\t\t\tis ? $doc.createElement(tag, {is: is}) : $doc.createElement(tag)\n\t\tvnode.dom = element\n\t\tif (attrs2 != null) {\n\t\t\tsetAttrs(vnode, attrs2, ns)\n\t\t}\n\t\tinsertNode(parent, element, nextSibling)\n\t\tif (vnode.attrs != null && vnode.attrs.contenteditable != null) {\n\t\t\tsetContentEditable(vnode)\n\t\t}\n\t\telse {\n\t\t\tif (vnode.text != null) {\n\t\t\t\tif (vnode.text !== \"\") element.textContent = vnode.text\n\t\t\t\telse vnode.children = [Vnode(\"#\", undefined, undefined, vnode.text, undefined, undefined)]\n\t\t\t}\n\t\t\tif (vnode.children != null) {\n\t\t\t\tvar children = vnode.children\n\t\t\t\tcreateNodes(element, children, 0, children.length, hooks, null, ns)\n\t\t\t\tsetLateAttrs(vnode)\n\t\t\t}\n\t\t}\n\t\treturn element\n\t}\n\tfunction initComponent(vnode, hooks) {\n\t\tvar sentinel\n\t\tif (typeof vnode.tag.view === \"function\") {\n\t\t\tvnode.state = Object.create(vnode.tag)\n\t\t\tsentinel = vnode.state.view\n\t\t\tif (sentinel.$$reentrantLock$$ != null) return $emptyFragment\n\t\t\tsentinel.$$reentrantLock$$ = true\n\t\t} else {\n\t\t\tvnode.state = void 0\n\t\t\tsentinel = vnode.tag\n\t\t\tif (sentinel.$$reentrantLock$$ != null) return $emptyFragment\n\t\t\tsentinel.$$reentrantLock$$ = true\n\t\t\tvnode.state = (vnode.tag.prototype != null && typeof vnode.tag.prototype.view === \"function\") ? new vnode.tag(vnode) : vnode.tag(vnode)\n\t\t}\n\t\tvnode._state = vnode.state\n\t\tif (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)\n\t\tinitLifecycle(vnode._state, vnode, hooks)\n\t\tvnode.instance = Vnode.normalize(vnode._state.view.call(vnode.state, vnode))\n\t\tif (vnode.instance === vnode) throw Error(\"A view cannot return the vnode it received as argument\")\n\t\tsentinel.$$reentrantLock$$ = null\n\t}\n\tfunction createComponent(parent, vnode, hooks, ns, nextSibling) {\n\t\tinitComponent(vnode, hooks)\n\t\tif (vnode.instance != null) {\n\t\t\tvar element = createNode(parent, vnode.instance, hooks, ns, nextSibling)\n\t\t\tvnode.dom = vnode.instance.dom\n\t\t\tvnode.domSize = vnode.dom != null ? vnode.instance.domSize : 0\n\t\t\tinsertNode(parent, element, nextSibling)\n\t\t\treturn element\n\t\t}\n\t\telse {\n\t\t\tvnode.domSize = 0\n\t\t\treturn $emptyFragment\n\t\t}\n\t}\n\t//update\n\tfunction updateNodes(parent, old, vnodes, recycling, hooks, nextSibling, ns) {\n\t\tif (old === vnodes || old == null && vnodes == null) return\n\t\telse if (old == null) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, undefined)\n\t\telse if (vnodes == null) removeNodes(old, 0, old.length, vnodes)\n\t\telse {\n\t\t\tif (old.length === vnodes.length) {\n\t\t\t\tvar isUnkeyed = false\n\t\t\t\tfor (var i = 0; i < vnodes.length; i++) {\n\t\t\t\t\tif (vnodes[i] != null && old[i] != null) {\n\t\t\t\t\t\tisUnkeyed = vnodes[i].key == null && old[i].key == null\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isUnkeyed) {\n\t\t\t\t\tfor (var i = 0; i < old.length; i++) {\n\t\t\t\t\t\tif (old[i] === vnodes[i]) continue\n\t\t\t\t\t\telse if (old[i] == null && vnodes[i] != null) createNode(parent, vnodes[i], hooks, ns, getNextSibling(old, i + 1, nextSibling))\n\t\t\t\t\t\telse if (vnodes[i] == null) removeNodes(old, i, i + 1, vnodes)\n\t\t\t\t\t\telse updateNode(parent, old[i], vnodes[i], hooks, getNextSibling(old, i + 1, nextSibling), recycling, ns)\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\trecycling = recycling || isRecyclable(old, vnodes)\n\t\t\tif (recycling) {\n\t\t\t\tvar pool = old.pool\n\t\t\t\told = old.concat(old.pool)\n\t\t\t}\n\t\t\tvar oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map\n\t\t\twhile (oldEnd >= oldStart && end >= start) {\n\t\t\t\tvar o = old[oldStart], v = vnodes[start]\n\t\t\t\tif (o === v && !recycling) oldStart++, start++\n\t\t\t\telse if (o == null) oldStart++\n\t\t\t\telse if (v == null) start++\n\t\t\t\telse if (o.key === v.key) {\n\t\t\t\t\tvar shouldRecycle = (pool != null && oldStart >= old.length - pool.length) || ((pool == null) && recycling)\n\t\t\t\t\toldStart++, start++\n\t\t\t\t\tupdateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), shouldRecycle, ns)\n\t\t\t\t\tif (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tvar o = old[oldEnd]\n\t\t\t\t\tif (o === v && !recycling) oldEnd--, start++\n\t\t\t\t\telse if (o == null) oldEnd--\n\t\t\t\t\telse if (v == null) start++\n\t\t\t\t\telse if (o.key === v.key) {\n\t\t\t\t\t\tvar shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)\n\t\t\t\t\t\tupdateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)\n\t\t\t\t\t\tif (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))\n\t\t\t\t\t\toldEnd--, start++\n\t\t\t\t\t}\n\t\t\t\t\telse break\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (oldEnd >= oldStart && end >= start) {\n\t\t\t\tvar o = old[oldEnd], v = vnodes[end]\n\t\t\t\tif (o === v && !recycling) oldEnd--, end--\n\t\t\t\telse if (o == null) oldEnd--\n\t\t\t\telse if (v == null) end--\n\t\t\t\telse if (o.key === v.key) {\n\t\t\t\t\tvar shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)\n\t\t\t\t\tupdateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)\n\t\t\t\t\tif (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)\n\t\t\t\t\tif (o.dom != null) nextSibling = o.dom\n\t\t\t\t\toldEnd--, end--\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (!map) map = getKeyMap(old, oldEnd)\n\t\t\t\t\tif (v != null) {\n\t\t\t\t\t\tvar oldIndex = map[v.key]\n\t\t\t\t\t\tif (oldIndex != null) {\n\t\t\t\t\t\t\tvar movable = old[oldIndex]\n\t\t\t\t\t\t\tvar shouldRecycle = (pool != null && oldIndex >= old.length - pool.length) || ((pool == null) && recycling)\n\t\t\t\t\t\t\tupdateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), recycling, ns)\n\t\t\t\t\t\t\tinsertNode(parent, toFragment(movable), nextSibling)\n\t\t\t\t\t\t\told[oldIndex].skip = true\n\t\t\t\t\t\t\tif (movable.dom != null) nextSibling = movable.dom\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tvar dom = createNode(parent, v, hooks, undefined, nextSibling)\n\t\t\t\t\t\t\tnextSibling = dom\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tend--\n\t\t\t\t}\n\t\t\t\tif (end < start) break\n\t\t\t}\n\t\t\tcreateNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns)\n\t\t\tremoveNodes(old, oldStart, oldEnd + 1, vnodes)\n\t\t}\n\t}\n\tfunction updateNode(parent, old, vnode, hooks, nextSibling, recycling, ns) {\n\t\tvar oldTag = old.tag, tag = vnode.tag\n\t\tif (oldTag === tag) {\n\t\t\tvnode.state = old.state\n\t\t\tvnode._state = old._state\n\t\t\tvnode.events = old.events\n\t\t\tif (!recycling && shouldNotUpdate(vnode, old)) return\n\t\t\tif (typeof oldTag === \"string\") {\n\t\t\t\tif (vnode.attrs != null) {\n\t\t\t\t\tif (recycling) {\n\t\t\t\t\t\tvnode.state = {}\n\t\t\t\t\t\tinitLifecycle(vnode.attrs, vnode, hooks)\n\t\t\t\t\t}\n\t\t\t\t\telse updateLifecycle(vnode.attrs, vnode, hooks)\n\t\t\t\t}\n\t\t\t\tswitch (oldTag) {\n\t\t\t\t\tcase \"#\": updateText(old, vnode); break\n\t\t\t\t\tcase \"<\": updateHTML(parent, old, vnode, nextSibling); break\n\t\t\t\t\tcase \"[\": updateFragment(parent, old, vnode, recycling, hooks, nextSibling, ns); break\n\t\t\t\t\tdefault: updateElement(old, vnode, recycling, hooks, ns)\n\t\t\t\t}\n\t\t\t}\n\t\t\telse updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns)\n\t\t}\n\t\telse {\n\t\t\tremoveNode(old, null)\n\t\t\tcreateNode(parent, vnode, hooks, ns, nextSibling)\n\t\t}\n\t}\n\tfunction updateText(old, vnode) {\n\t\tif (old.children.toString() !== vnode.children.toString()) {\n\t\t\told.dom.nodeValue = vnode.children\n\t\t}\n\t\tvnode.dom = old.dom\n\t}\n\tfunction updateHTML(parent, old, vnode, nextSibling) {\n\t\tif (old.children !== vnode.children) {\n\t\t\ttoFragment(old)\n\t\t\tcreateHTML(parent, vnode, nextSibling)\n\t\t}\n\t\telse vnode.dom = old.dom, vnode.domSize = old.domSize\n\t}\n\tfunction updateFragment(parent, old, vnode, recycling, hooks, nextSibling, ns) {\n\t\tupdateNodes(parent, old.children, vnode.children, recycling, hooks, nextSibling, ns)\n\t\tvar domSize = 0, children = vnode.children\n\t\tvnode.dom = null\n\t\tif (children != null) {\n\t\t\tfor (var i = 0; i < children.length; i++) {\n\t\t\t\tvar child = children[i]\n\t\t\t\tif (child != null && child.dom != null) {\n\t\t\t\t\tif (vnode.dom == null) vnode.dom = child.dom\n\t\t\t\t\tdomSize += child.domSize || 1\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (domSize !== 1) vnode.domSize = domSize\n\t\t}\n\t}\n\tfunction updateElement(old, vnode, recycling, hooks, ns) {\n\t\tvar element = vnode.dom = old.dom\n\t\tswitch (vnode.tag) {\n\t\t\tcase \"svg\": ns = \"http://www.w3.org/2000/svg\"; break\n\t\t\tcase \"math\": ns = \"http://www.w3.org/1998/Math/MathML\"; break\n\t\t}\n\t\tif (vnode.tag === \"textarea\") {\n\t\t\tif (vnode.attrs == null) vnode.attrs = {}\n\t\t\tif (vnode.text != null) {\n\t\t\t\tvnode.attrs.value = vnode.text //FIXME handle0 multiple children\n\t\t\t\tvnode.text = undefined\n\t\t\t}\n\t\t}\n\t\tupdateAttrs(vnode, old.attrs, vnode.attrs, ns)\n\t\tif (vnode.attrs != null && vnode.attrs.contenteditable != null) {\n\t\t\tsetContentEditable(vnode)\n\t\t}\n\t\telse if (old.text != null && vnode.text != null && vnode.text !== \"\") {\n\t\t\tif (old.text.toString() !== vnode.text.toString()) old.dom.firstChild.nodeValue = vnode.text\n\t\t}\n\t\telse {\n\t\t\tif (old.text != null) old.children = [Vnode(\"#\", undefined, undefined, old.text, undefined, old.dom.firstChild)]\n\t\t\tif (vnode.text != null) vnode.children = [Vnode(\"#\", undefined, undefined, vnode.text, undefined, undefined)]\n\t\t\tupdateNodes(element, old.children, vnode.children, recycling, hooks, null, ns)\n\t\t}\n\t}\n\tfunction updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) {\n\t\tif (recycling) {\n\t\t\tinitComponent(vnode, hooks)\n\t\t} else {\n\t\t\tvnode.instance = Vnode.normalize(vnode._state.view.call(vnode.state, vnode))\n\t\t\tif (vnode.instance === vnode) throw Error(\"A view cannot return the vnode it received as argument\")\n\t\t\tif (vnode.attrs != null) updateLifecycle(vnode.attrs, vnode, hooks)\n\t\t\tupdateLifecycle(vnode._state, vnode, hooks)\n\t\t}\n\t\tif (vnode.instance != null) {\n\t\t\tif (old.instance == null) createNode(parent, vnode.instance, hooks, ns, nextSibling)\n\t\t\telse updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling, ns)\n\t\t\tvnode.dom = vnode.instance.dom\n\t\t\tvnode.domSize = vnode.instance.domSize\n\t\t}\n\t\telse if (old.instance != null) {\n\t\t\tremoveNode(old.instance, null)\n\t\t\tvnode.dom = undefined\n\t\t\tvnode.domSize = 0\n\t\t}\n\t\telse {\n\t\t\tvnode.dom = old.dom\n\t\t\tvnode.domSize = old.domSize\n\t\t}\n\t}\n\tfunction isRecyclable(old, vnodes) {\n\t\tif (old.pool != null && Math.abs(old.pool.length - vnodes.length) <= Math.abs(old.length - vnodes.length)) {\n\t\t\tvar oldChildrenLength = old[0] && old[0].children && old[0].children.length || 0\n\t\t\tvar poolChildrenLength = old.pool[0] && old.pool[0].children && old.pool[0].children.length || 0\n\t\t\tvar vnodesChildrenLength = vnodes[0] && vnodes[0].children && vnodes[0].children.length || 0\n\t\t\tif (Math.abs(poolChildrenLength - vnodesChildrenLength) <= Math.abs(oldChildrenLength - vnodesChildrenLength)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\tfunction getKeyMap(vnodes, end) {\n\t\tvar map = {}, i = 0\n\t\tfor (var i = 0; i < end; i++) {\n\t\t\tvar vnode = vnodes[i]\n\t\t\tif (vnode != null) {\n\t\t\t\tvar key2 = vnode.key\n\t\t\t\tif (key2 != null) map[key2] = i\n\t\t\t}\n\t\t}\n\t\treturn map\n\t}\n\tfunction toFragment(vnode) {\n\t\tvar count0 = vnode.domSize\n\t\tif (count0 != null || vnode.dom == null) {\n\t\t\tvar fragment = $doc.createDocumentFragment()\n\t\t\tif (count0 > 0) {\n\t\t\t\tvar dom = vnode.dom\n\t\t\t\twhile (--count0) fragment.appendChild(dom.nextSibling)\n\t\t\t\tfragment.insertBefore(dom, fragment.firstChild)\n\t\t\t}\n\t\t\treturn fragment\n\t\t}\n\t\telse return vnode.dom\n\t}\n\tfunction getNextSibling(vnodes, i, nextSibling) {\n\t\tfor (; i < vnodes.length; i++) {\n\t\t\tif (vnodes[i] != null && vnodes[i].dom != null) return vnodes[i].dom\n\t\t}\n\t\treturn nextSibling\n\t}\n\tfunction insertNode(parent, dom, nextSibling) {\n\t\tif (nextSibling && nextSibling.parentNode) parent.insertBefore(dom, nextSibling)\n\t\telse parent.appendChild(dom)\n\t}\n\tfunction setContentEditable(vnode) {\n\t\tvar children = vnode.children\n\t\tif (children != null && children.length === 1 && children[0].tag === \"<\") {\n\t\t\tvar content = children[0].children\n\t\t\tif (vnode.dom.innerHTML !== content) vnode.dom.innerHTML = content\n\t\t}\n\t\telse if (vnode.text != null || children != null && children.length !== 0) throw new Error(\"Child node of a contenteditable must be trusted\")\n\t}\n\t//remove\n\tfunction removeNodes(vnodes, start, end, context) {\n\t\tfor (var i = start; i < end; i++) {\n\t\t\tvar vnode = vnodes[i]\n\t\t\tif (vnode != null) {\n\t\t\t\tif (vnode.skip) vnode.skip = false\n\t\t\t\telse removeNode(vnode, context)\n\t\t\t}\n\t\t}\n\t}\n\tfunction removeNode(vnode, context) {\n\t\tvar expected = 1, called = 0\n\t\tif (vnode.attrs && typeof vnode.attrs.onbeforeremove === \"function\") {\n\t\t\tvar result = vnode.attrs.onbeforeremove.call(vnode.state, vnode)\n\t\t\tif (result != null && typeof result.then === \"function\") {\n\t\t\t\texpected++\n\t\t\t\tresult.then(continuation, continuation)\n\t\t\t}\n\t\t}\n\t\tif (typeof vnode.tag !== \"string\" && typeof vnode._state.onbeforeremove === \"function\") {\n\t\t\tvar result = vnode._state.onbeforeremove.call(vnode.state, vnode)\n\t\t\tif (result != null && typeof result.then === \"function\") {\n\t\t\t\texpected++\n\t\t\t\tresult.then(continuation, continuation)\n\t\t\t}\n\t\t}\n\t\tcontinuation()\n\t\tfunction continuation() {\n\t\t\tif (++called === expected) {\n\t\t\t\tonremove(vnode)\n\t\t\t\tif (vnode.dom) {\n\t\t\t\t\tvar count0 = vnode.domSize || 1\n\t\t\t\t\tif (count0 > 1) {\n\t\t\t\t\t\tvar dom = vnode.dom\n\t\t\t\t\t\twhile (--count0) {\n\t\t\t\t\t\t\tremoveNodeFromDOM(dom.nextSibling)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tremoveNodeFromDOM(vnode.dom)\n\t\t\t\t\tif (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === \"string\") { //TODO test custom elements\n\t\t\t\t\t\tif (!context.pool) context.pool = [vnode]\n\t\t\t\t\t\telse context.pool.push(vnode)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfunction removeNodeFromDOM(node) {\n\t\tvar parent = node.parentNode\n\t\tif (parent != null) parent.removeChild(node)\n\t}\n\tfunction onremove(vnode) {\n\t\tif (vnode.attrs && typeof vnode.attrs.onremove === \"function\") vnode.attrs.onremove.call(vnode.state, vnode)\n\t\tif (typeof vnode.tag !== \"string\" && typeof vnode._state.onremove === \"function\") vnode._state.onremove.call(vnode.state, vnode)\n\t\tif (vnode.instance != null) onremove(vnode.instance)\n\t\telse {\n\t\t\tvar children = vnode.children\n\t\t\tif (Array.isArray(children)) {\n\t\t\t\tfor (var i = 0; i < children.length; i++) {\n\t\t\t\t\tvar child = children[i]\n\t\t\t\t\tif (child != null) onremove(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t//attrs2\n\tfunction setAttrs(vnode, attrs2, ns) {\n\t\tfor (var key2 in attrs2) {\n\t\t\tsetAttr(vnode, key2, null, attrs2[key2], ns)\n\t\t}\n\t}\n\tfunction setAttr(vnode, key2, old, value, ns) {\n\t\tvar element = vnode.dom\n\t\tif (key2 === \"key\" || key2 === \"is\" || (old === value && !isFormAttribute(vnode, key2)) && typeof value !== \"object\" || typeof value === \"undefined\" || isLifecycleMethod(key2)) return\n\t\tvar nsLastIndex = key2.indexOf(\":\")\n\t\tif (nsLastIndex > -1 && key2.substr(0, nsLastIndex) === \"xlink\") {\n\t\t\telement.setAttributeNS(\"http://www.w3.org/1999/xlink\", key2.slice(nsLastIndex + 1), value)\n\t\t}\n\t\telse if (key2[0] === \"o\" && key2[1] === \"n\" && typeof value === \"function\") updateEvent(vnode, key2, value)\n\t\telse if (key2 === \"style\") updateStyle(element, old, value)\n\t\telse if (key2 in element && !isAttribute(key2) && ns === undefined && !isCustomElement(vnode)) {\n\t\t\t//setting input[value] to same value by typing on focused element moves cursor to end in Chrome\n\t\t\tif (vnode.tag === \"input\" && key2 === \"value\" && vnode.dom.value == value && vnode.dom === $doc.activeElement) return\n\t\t\t//setting select[value] to same value while having select open blinks select dropdown in Chrome\n\t\t\tif (vnode.tag === \"select\" && key2 === \"value\" && vnode.dom.value == value && vnode.dom === $doc.activeElement) return\n\t\t\t//setting option[value] to same value while having select open blinks select dropdown in Chrome\n\t\t\tif (vnode.tag === \"option\" && key2 === \"value\" && vnode.dom.value == value) return\n\t\t\t// If you assign an input type1 that is not supported by IE 11 with an assignment expression, an error0 will occur.\n\t\t\tif (vnode.tag === \"input\" && key2 === \"type\") {\n\t\t\t\telement.setAttribute(key2, value)\n\t\t\t\treturn\n\t\t\t}\n\t\t\telement[key2] = value\n\t\t}\n\t\telse {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tif (value) element.setAttribute(key2, \"\")\n\t\t\t\telse element.removeAttribute(key2)\n\t\t\t}\n\t\t\telse element.setAttribute(key2 === \"className\" ? \"class\" : key2, value)\n\t\t}\n\t}\n\tfunction setLateAttrs(vnode) {\n\t\tvar attrs2 = vnode.attrs\n\t\tif (vnode.tag === \"select\" && attrs2 != null) {\n\t\t\tif (\"value\" in attrs2) setAttr(vnode, \"value\", null, attrs2.value, undefined)\n\t\t\tif (\"selectedIndex\" in attrs2) setAttr(vnode, \"selectedIndex\", null, attrs2.selectedIndex, undefined)\n\t\t}\n\t}\n\tfunction updateAttrs(vnode, old, attrs2, ns) {\n\t\tif (attrs2 != null) {\n\t\t\tfor (var key2 in attrs2) {\n\t\t\t\tsetAttr(vnode, key2, old && old[key2], attrs2[key2], ns)\n\t\t\t}\n\t\t}\n\t\tif (old != null) {\n\t\t\tfor (var key2 in old) {\n\t\t\t\tif (attrs2 == null || !(key2 in attrs2)) {\n\t\t\t\t\tif (key2 === \"className\") key2 = \"class\"\n\t\t\t\t\tif (key2[0] === \"o\" && key2[1] === \"n\" && !isLifecycleMethod(key2)) updateEvent(vnode, key2, undefined)\n\t\t\t\t\telse if (key2 !== \"key\") vnode.dom.removeAttribute(key2)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfunction isFormAttribute(vnode, attr) {\n\t\treturn attr === \"value\" || attr === \"checked\" || attr === \"selectedIndex\" || attr === \"selected\" && vnode.dom === $doc.activeElement\n\t}\n\tfunction isLifecycleMethod(attr) {\n\t\treturn attr === \"oninit\" || attr === \"oncreate\" || attr === \"onupdate\" || attr === \"onremove\" || attr === \"onbeforeremove\" || attr === \"onbeforeupdate\"\n\t}\n\tfunction isAttribute(attr) {\n\t\treturn attr === \"href\" || attr === \"list\" || attr === \"form\" || attr === \"width\" || attr === \"height\"// || attr === \"type\"\n\t}\n\tfunction isCustomElement(vnode){\n\t\treturn vnode.attrs.is || vnode.tag.indexOf(\"-\") > -1\n\t}\n\tfunction hasIntegrationMethods(source) {\n\t\treturn source != null && (source.oncreate || source.onupdate || source.onbeforeremove || source.onremove)\n\t}\n\t//style\n\tfunction updateStyle(element, old, style) {\n\t\tif (old === style) element.style.cssText = \"\", old = null\n\t\tif (style == null) element.style.cssText = \"\"\n\t\telse if (typeof style === \"string\") element.style.cssText = style\n\t\telse {\n\t\t\tif (typeof old === \"string\") element.style.cssText = \"\"\n\t\t\tfor (var key2 in style) {\n\t\t\t\telement.style[key2] = style[key2]\n\t\t\t}\n\t\t\tif (old != null && typeof old !== \"string\") {\n\t\t\t\tfor (var key2 in old) {\n\t\t\t\t\tif (!(key2 in style)) element.style[key2] = \"\"\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t//event\n\tfunction updateEvent(vnode, key2, value) {\n\t\tvar element = vnode.dom\n\t\tvar callback = typeof onevent !== \"function\" ? value : function(e) {\n\t\t\tvar result = value.call(element, e)\n\t\t\tonevent.call(element, e)\n\t\t\treturn result\n\t\t}\n\t\tif (key2 in element) element[key2] = typeof value === \"function\" ? callback : null\n\t\telse {\n\t\t\tvar eventName = key2.slice(2)\n\t\t\tif (vnode.events === undefined) vnode.events = {}\n\t\t\tif (vnode.events[key2] === callback) return\n\t\t\tif (vnode.events[key2] != null) element.removeEventListener(eventName, vnode.events[key2], false)\n\t\t\tif (typeof value === \"function\") {\n\t\t\t\tvnode.events[key2] = callback\n\t\t\t\telement.addEventListener(eventName, vnode.events[key2], false)\n\t\t\t}\n\t\t}\n\t}\n\t//lifecycle\n\tfunction initLifecycle(source, vnode, hooks) {\n\t\tif (typeof source.oninit === \"function\") source.oninit.call(vnode.state, vnode)\n\t\tif (typeof source.oncreate === \"function\") hooks.push(source.oncreate.bind(vnode.state, vnode))\n\t}\n\tfunction updateLifecycle(source, vnode, hooks) {\n\t\tif (typeof source.onupdate === \"function\") hooks.push(source.onupdate.bind(vnode.state, vnode))\n\t}\n\tfunction shouldNotUpdate(vnode, old) {\n\t\tvar forceVnodeUpdate, forceComponentUpdate\n\t\tif (vnode.attrs != null && typeof vnode.attrs.onbeforeupdate === \"function\") forceVnodeUpdate = vnode.attrs.onbeforeupdate.call(vnode.state, vnode, old)\n\t\tif (typeof vnode.tag !== \"string\" && typeof vnode._state.onbeforeupdate === \"function\") forceComponentUpdate = vnode._state.onbeforeupdate.call(vnode.state, vnode, old)\n\t\tif (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {\n\t\t\tvnode.dom = old.dom\n\t\t\tvnode.domSize = old.domSize\n\t\t\tvnode.instance = old.instance\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\tfunction render(dom, vnodes) {\n\t\tif (!dom) throw new Error(\"Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.\")\n\t\tvar hooks = []\n\t\tvar active = $doc.activeElement\n\t\t// First time0 rendering into a node clears it out\n\t\tif (dom.vnodes == null) dom.textContent = \"\"\n\t\tif (!Array.isArray(vnodes)) vnodes = [vnodes]\n\t\tupdateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), false, hooks, null, undefined)\n\t\tdom.vnodes = vnodes\n\t\tfor (var i = 0; i < hooks.length; i++) hooks[i]()\n\t\tif ($doc.activeElement !== active) active.focus()\n\t}\n\treturn {render: render, setEventCallback: setEventCallback}\n}\nfunction throttle(callback) {\n\t//60fps translates to 16.6ms, round it down since setTimeout requires int\n\tvar time = 16\n\tvar last = 0, pending = null\n\tvar timeout = typeof requestAnimationFrame === \"function\" ? requestAnimationFrame : setTimeout\n\treturn function() {\n\t\tvar now = Date.now()\n\t\tif (last === 0 || now - last >= time) {\n\t\t\tlast = now\n\t\t\tcallback()\n\t\t}\n\t\telse if (pending === null) {\n\t\t\tpending = timeout(function() {\n\t\t\t\tpending = null\n\t\t\t\tcallback()\n\t\t\t\tlast = Date.now()\n\t\t\t}, time - (now - last))\n\t\t}\n\t}\n}\nvar _11 = function($window) {\n\tvar renderService = coreRenderer($window)\n\trenderService.setEventCallback(function(e) {\n\t\tif (e.redraw !== false) redraw()\n\t})\n\tvar callbacks = []\n\tfunction subscribe(key1, callback) {\n\t\tunsubscribe(key1)\n\t\tcallbacks.push(key1, throttle(callback))\n\t}\n\tfunction unsubscribe(key1) {\n\t\tvar index = callbacks.indexOf(key1)\n\t\tif (index > -1) callbacks.splice(index, 2)\n\t}\n\tfunction redraw() {\n\t\tfor (var i = 1; i < callbacks.length; i += 2) {\n\t\t\tcallbacks[i]()\n\t\t}\n\t}\n\treturn {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render}\n}\nvar redrawService = _11(window)\nrequestService.setCompletionCallback(redrawService.redraw)\nvar _16 = function(redrawService0) {\n\treturn function(root, component) {\n\t\tif (component === null) {\n\t\t\tredrawService0.render(root, [])\n\t\t\tredrawService0.unsubscribe(root)\n\t\t\treturn\n\t\t}\n\t\t\n\t\tif (component.view == null && typeof component !== \"function\") throw new Error(\"m.mount(element, component) expects a component, not a vnode\")\n\t\t\n\t\tvar run0 = function() {\n\t\t\tredrawService0.render(root, Vnode(component))\n\t\t}\n\t\tredrawService0.subscribe(root, run0)\n\t\tredrawService0.redraw()\n\t}\n}\nm.mount = _16(redrawService)\nvar Promise = PromisePolyfill\nvar parseQueryString = function(string) {\n\tif (string === \"\" || string == null) return {}\n\tif (string.charAt(0) === \"?\") string = string.slice(1)\n\tvar entries = string.split(\"&\"), data0 = {}, counters = {}\n\tfor (var i = 0; i < entries.length; i++) {\n\t\tvar entry = entries[i].split(\"=\")\n\t\tvar key5 = decodeURIComponent(entry[0])\n\t\tvar value = entry.length === 2 ? decodeURIComponent(entry[1]) : \"\"\n\t\tif (value === \"true\") value = true\n\t\telse if (value === \"false\") value = false\n\t\tvar levels = key5.split(/\\]\\[?|\\[/)\n\t\tvar cursor = data0\n\t\tif (key5.indexOf(\"[\") > -1) levels.pop()\n\t\tfor (var j = 0; j < levels.length; j++) {\n\t\t\tvar level = levels[j], nextLevel = levels[j + 1]\n\t\t\tvar isNumber = nextLevel == \"\" || !isNaN(parseInt(nextLevel, 10))\n\t\t\tvar isValue = j === levels.length - 1\n\t\t\tif (level === \"\") {\n\t\t\t\tvar key5 = levels.slice(0, j).join()\n\t\t\t\tif (counters[key5] == null) counters[key5] = 0\n\t\t\t\tlevel = counters[key5]++\n\t\t\t}\n\t\t\tif (cursor[level] == null) {\n\t\t\t\tcursor[level] = isValue ? value : isNumber ? [] : {}\n\t\t\t}\n\t\t\tcursor = cursor[level]\n\t\t}\n\t}\n\treturn data0\n}\nvar coreRouter = function($window) {\n\tvar supportsPushState = typeof $window.history.pushState === \"function\"\n\tvar callAsync0 = typeof setImmediate === \"function\" ? setImmediate : setTimeout\n\tfunction normalize1(fragment0) {\n\t\tvar data = $window.location[fragment0].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent)\n\t\tif (fragment0 === \"pathname\" && data[0] !== \"/\") data = \"/\" + data\n\t\treturn data\n\t}\n\tvar asyncId\n\tfunction debounceAsync(callback0) {\n\t\treturn function() {\n\t\t\tif (asyncId != null) return\n\t\t\tasyncId = callAsync0(function() {\n\t\t\t\tasyncId = null\n\t\t\t\tcallback0()\n\t\t\t})\n\t\t}\n\t}\n\tfunction parsePath(path, queryData, hashData) {\n\t\tvar queryIndex = path.indexOf(\"?\")\n\t\tvar hashIndex = path.indexOf(\"#\")\n\t\tvar pathEnd = queryIndex > -1 ? queryIndex : hashIndex > -1 ? hashIndex : path.length\n\t\tif (queryIndex > -1) {\n\t\t\tvar queryEnd = hashIndex > -1 ? hashIndex : path.length\n\t\t\tvar queryParams = parseQueryString(path.slice(queryIndex + 1, queryEnd))\n\t\t\tfor (var key4 in queryParams) queryData[key4] = queryParams[key4]\n\t\t}\n\t\tif (hashIndex > -1) {\n\t\t\tvar hashParams = parseQueryString(path.slice(hashIndex + 1))\n\t\t\tfor (var key4 in hashParams) hashData[key4] = hashParams[key4]\n\t\t}\n\t\treturn path.slice(0, pathEnd)\n\t}\n\tvar router = {prefix: \"#!\"}\n\trouter.getPath = function() {\n\t\tvar type2 = router.prefix.charAt(0)\n\t\tswitch (type2) {\n\t\t\tcase \"#\": return normalize1(\"hash\").slice(router.prefix.length)\n\t\t\tcase \"?\": return normalize1(\"search\").slice(router.prefix.length) + normalize1(\"hash\")\n\t\t\tdefault: return normalize1(\"pathname\").slice(router.prefix.length) + normalize1(\"search\") + normalize1(\"hash\")\n\t\t}\n\t}\n\trouter.setPath = function(path, data, options) {\n\t\tvar queryData = {}, hashData = {}\n\t\tpath = parsePath(path, queryData, hashData)\n\t\tif (data != null) {\n\t\t\tfor (var key4 in data) queryData[key4] = data[key4]\n\t\t\tpath = path.replace(/:([^\\/]+)/g, function(match2, token) {\n\t\t\t\tdelete queryData[token]\n\t\t\t\treturn data[token]\n\t\t\t})\n\t\t}\n\t\tvar query = buildQueryString(queryData)\n\t\tif (query) path += \"?\" + query\n\t\tvar hash = buildQueryString(hashData)\n\t\tif (hash) path += \"#\" + hash\n\t\tif (supportsPushState) {\n\t\t\tvar state = options ? options.state : null\n\t\t\tvar title = options ? options.title : null\n\t\t\t$window.onpopstate()\n\t\t\tif (options && options.replace) $window.history.replaceState(state, title, router.prefix + path)\n\t\t\telse $window.history.pushState(state, title, router.prefix + path)\n\t\t}\n\t\telse $window.location.href = router.prefix + path\n\t}\n\trouter.defineRoutes = function(routes, resolve, reject) {\n\t\tfunction resolveRoute() {\n\t\t\tvar path = router.getPath()\n\t\t\tvar params = {}\n\t\t\tvar pathname = parsePath(path, params, params)\n\t\t\tvar state = $window.history.state\n\t\t\tif (state != null) {\n\t\t\t\tfor (var k in state) params[k] = state[k]\n\t\t\t}\n\t\t\tfor (var route0 in routes) {\n\t\t\t\tvar matcher = new RegExp(\"^\" + route0.replace(/:[^\\/]+?\\.{3}/g, \"(.*?)\").replace(/:[^\\/]+/g, \"([^\\\\/]+)\") + \"\\/?$\")\n\t\t\t\tif (matcher.test(pathname)) {\n\t\t\t\t\tpathname.replace(matcher, function() {\n\t\t\t\t\t\tvar keys = route0.match(/:[^\\/]+/g) || []\n\t\t\t\t\t\tvar values = [].slice.call(arguments, 1, -2)\n\t\t\t\t\t\tfor (var i = 0; i < keys.length; i++) {\n\t\t\t\t\t\t\tparams[keys[i].replace(/:|\\./g, \"\")] = decodeURIComponent(values[i])\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresolve(routes[route0], params, path, route0)\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\treject(path, params)\n\t\t}\n\t\tif (supportsPushState) $window.onpopstate = debounceAsync(resolveRoute)\n\t\telse if (router.prefix.charAt(0) === \"#\") $window.onhashchange = resolveRoute\n\t\tresolveRoute()\n\t}\n\treturn router\n}\nvar _20 = function($window, redrawService0) {\n\tvar routeService = coreRouter($window)\n\tvar identity = function(v) {return v}\n\tvar render1, component, attrs3, currentPath, lastUpdate\n\tvar route = function(root, defaultRoute, routes) {\n\t\tif (root == null) throw new Error(\"Ensure the DOM element that was passed to `m.route` is not undefined\")\n\t\tvar run1 = function() {\n\t\t\tif (render1 != null) redrawService0.render(root, render1(Vnode(component, attrs3.key, attrs3)))\n\t\t}\n\t\tvar bail = function(path) {\n\t\t\tif (path !== defaultRoute) routeService.setPath(defaultRoute, null, {replace: true})\n\t\t\telse throw new Error(\"Could not resolve default route \" + defaultRoute)\n\t\t}\n\t\trouteService.defineRoutes(routes, function(payload, params, path) {\n\t\t\tvar update = lastUpdate = function(routeResolver, comp) {\n\t\t\t\tif (update !== lastUpdate) return\n\t\t\t\tcomponent = comp != null && (typeof comp.view === \"function\" || typeof comp === \"function\")? comp : \"div\"\n\t\t\t\tattrs3 = params, currentPath = path, lastUpdate = null\n\t\t\t\trender1 = (routeResolver.render || identity).bind(routeResolver)\n\t\t\t\trun1()\n\t\t\t}\n\t\t\tif (payload.view || typeof payload === \"function\") update({}, payload)\n\t\t\telse {\n\t\t\t\tif (payload.onmatch) {\n\t\t\t\t\tPromise.resolve(payload.onmatch(params, path)).then(function(resolved) {\n\t\t\t\t\t\tupdate(payload, resolved)\n\t\t\t\t\t}, bail)\n\t\t\t\t}\n\t\t\t\telse update(payload, \"div\")\n\t\t\t}\n\t\t}, bail)\n\t\tredrawService0.subscribe(root, run1)\n\t}\n\troute.set = function(path, data, options) {\n\t\tif (lastUpdate != null) options = {replace: true}\n\t\tlastUpdate = null\n\t\trouteService.setPath(path, data, options)\n\t}\n\troute.get = function() {return currentPath}\n\troute.prefix = function(prefix0) {routeService.prefix = prefix0}\n\troute.link = function(vnode1) {\n\t\tvnode1.dom.setAttribute(\"href\", routeService.prefix + vnode1.attrs.href)\n\t\tvnode1.dom.onclick = function(e) {\n\t\t\tif (e.ctrlKey || e.metaKey || e.shiftKey || e.which === 2) return\n\t\t\te.preventDefault()\n\t\t\te.redraw = false\n\t\t\tvar href = this.getAttribute(\"href\")\n\t\t\tif (href.indexOf(routeService.prefix) === 0) href = href.slice(routeService.prefix.length)\n\t\t\troute.set(href, undefined, undefined)\n\t\t}\n\t}\n\troute.param = function(key3) {\n\t\tif(typeof attrs3 !== \"undefined\" && typeof key3 !== \"undefined\") return attrs3[key3]\n\t\treturn attrs3\n\t}\n\treturn route\n}\nm.route = _20(window, redrawService)\nm.withAttr = function(attrName, callback1, context) {\n\treturn function(e) {\n\t\tcallback1.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))\n\t}\n}\nvar _28 = coreRenderer(window)\nm.render = _28.render\nm.redraw = redrawService.redraw\nm.request = requestService.request\nm.jsonp = requestService.jsonp\nm.parseQueryString = parseQueryString\nm.buildQueryString = buildQueryString\nm.version = \"1.1.1\"\nm.vnode = Vnode\nif (typeof module !== \"undefined\") module[\"exports\"] = m\nelse window.m = m\n}());\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{}],8:[function(require,module,exports){\n/*!\n * EventEmitter v5.1.0 - git.io/ee\n * Unlicense - http://unlicense.org/\n * Oliver Caldwell - http://oli.me.uk/\n * @preserve\n */\n\n;(function (exports) {\n 'use strict';\n\n /**\n * Class for managing events.\n * Can be extended to provide event functionality in other classes.\n *\n * @class EventEmitter Manages event registering and emitting.\n */\n function EventEmitter() {}\n\n // Shortcuts to improve speed and size\n var proto = EventEmitter.prototype;\n var originalGlobalValue = exports.EventEmitter;\n\n /**\n * Finds the index of the listener for the event in its storage array.\n *\n * @param {Function[]} listeners Array of listeners to search through.\n * @param {Function} listener Method to look for.\n * @return {Number} Index of the specified listener, -1 if not found\n * @api private\n */\n function indexOfListener(listeners, listener) {\n var i = listeners.length;\n while (i--) {\n if (listeners[i].listener === listener) {\n return i;\n }\n }\n\n return -1;\n }\n\n /**\n * Alias a method while keeping the context correct, to allow for overwriting of target method.\n *\n * @param {String} name The name of the target method.\n * @return {Function} The aliased method\n * @api private\n */\n function alias(name) {\n return function aliasClosure() {\n return this[name].apply(this, arguments);\n };\n }\n\n /**\n * Returns the listener array for the specified event.\n * Will initialise the event object and listener arrays if required.\n * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.\n * Each property in the object response is an array of listener functions.\n *\n * @param {String|RegExp} evt Name of the event to return the listeners from.\n * @return {Function[]|Object} All listener functions for the event.\n */\n proto.getListeners = function getListeners(evt) {\n var events = this._getEvents();\n var response;\n var key;\n\n // Return a concatenated array of all matching events if\n // the selector is a regular expression.\n if (evt instanceof RegExp) {\n response = {};\n for (key in events) {\n if (events.hasOwnProperty(key) && evt.test(key)) {\n response[key] = events[key];\n }\n }\n }\n else {\n response = events[evt] || (events[evt] = []);\n }\n\n return response;\n };\n\n /**\n * Takes a list of listener objects and flattens it into a list of listener functions.\n *\n * @param {Object[]} listeners Raw listener objects.\n * @return {Function[]} Just the listener functions.\n */\n proto.flattenListeners = function flattenListeners(listeners) {\n var flatListeners = [];\n var i;\n\n for (i = 0; i < listeners.length; i += 1) {\n flatListeners.push(listeners[i].listener);\n }\n\n return flatListeners;\n };\n\n /**\n * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.\n *\n * @param {String|RegExp} evt Name of the event to return the listeners from.\n * @return {Object} All listener functions for an event in an object.\n */\n proto.getListenersAsObject = function getListenersAsObject(evt) {\n var listeners = this.getListeners(evt);\n var response;\n\n if (listeners instanceof Array) {\n response = {};\n response[evt] = listeners;\n }\n\n return response || listeners;\n };\n\n function isValidListener (listener) {\n if (typeof listener === 'function' || listener instanceof RegExp) {\n return true\n } else if (listener && typeof listener === 'object') {\n return isValidListener(listener.listener)\n } else {\n return false\n }\n }\n\n /**\n * Adds a listener function to the specified event.\n * The listener will not be added if it is a duplicate.\n * If the listener returns true then it will be removed after it is called.\n * If you pass a regular expression as the event name then the listener will be added to all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to attach the listener to.\n * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.addListener = function addListener(evt, listener) {\n if (!isValidListener(listener)) {\n throw new TypeError('listener must be a function');\n }\n\n var listeners = this.getListenersAsObject(evt);\n var listenerIsWrapped = typeof listener === 'object';\n var key;\n\n for (key in listeners) {\n if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {\n listeners[key].push(listenerIsWrapped ? listener : {\n listener: listener,\n once: false\n });\n }\n }\n\n return this;\n };\n\n /**\n * Alias of addListener\n */\n proto.on = alias('addListener');\n\n /**\n * Semi-alias of addListener. It will add a listener that will be\n * automatically removed after its first execution.\n *\n * @param {String|RegExp} evt Name of the event to attach the listener to.\n * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.addOnceListener = function addOnceListener(evt, listener) {\n return this.addListener(evt, {\n listener: listener,\n once: true\n });\n };\n\n /**\n * Alias of addOnceListener.\n */\n proto.once = alias('addOnceListener');\n\n /**\n * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.\n * You need to tell it what event names should be matched by a regex.\n *\n * @param {String} evt Name of the event to create.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.defineEvent = function defineEvent(evt) {\n this.getListeners(evt);\n return this;\n };\n\n /**\n * Uses defineEvent to define multiple events.\n *\n * @param {String[]} evts An array of event names to define.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.defineEvents = function defineEvents(evts) {\n for (var i = 0; i < evts.length; i += 1) {\n this.defineEvent(evts[i]);\n }\n return this;\n };\n\n /**\n * Removes a listener function from the specified event.\n * When passed a regular expression as the event name, it will remove the listener from all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to remove the listener from.\n * @param {Function} listener Method to remove from the event.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.removeListener = function removeListener(evt, listener) {\n var listeners = this.getListenersAsObject(evt);\n var index;\n var key;\n\n for (key in listeners) {\n if (listeners.hasOwnProperty(key)) {\n index = indexOfListener(listeners[key], listener);\n\n if (index !== -1) {\n listeners[key].splice(index, 1);\n }\n }\n }\n\n return this;\n };\n\n /**\n * Alias of removeListener\n */\n proto.off = alias('removeListener');\n\n /**\n * Adds listeners in bulk using the manipulateListeners method.\n * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.\n * You can also pass it a regular expression to add the array of listeners to all events that match it.\n * Yeah, this function does quite a bit. That's probably a bad thing.\n *\n * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.\n * @param {Function[]} [listeners] An optional array of listener functions to add.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.addListeners = function addListeners(evt, listeners) {\n // Pass through to manipulateListeners\n return this.manipulateListeners(false, evt, listeners);\n };\n\n /**\n * Removes listeners in bulk using the manipulateListeners method.\n * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.\n * You can also pass it an event name and an array of listeners to be removed.\n * You can also pass it a regular expression to remove the listeners from all events that match it.\n *\n * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.\n * @param {Function[]} [listeners] An optional array of listener functions to remove.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.removeListeners = function removeListeners(evt, listeners) {\n // Pass through to manipulateListeners\n return this.manipulateListeners(true, evt, listeners);\n };\n\n /**\n * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.\n * The first argument will determine if the listeners are removed (true) or added (false).\n * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.\n * You can also pass it an event name and an array of listeners to be added/removed.\n * You can also pass it a regular expression to manipulate the listeners of all events that match it.\n *\n * @param {Boolean} remove True if you want to remove listeners, false if you want to add.\n * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.\n * @param {Function[]} [listeners] An optional array of listener functions to add/remove.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {\n var i;\n var value;\n var single = remove ? this.removeListener : this.addListener;\n var multiple = remove ? this.removeListeners : this.addListeners;\n\n // If evt is an object then pass each of its properties to this method\n if (typeof evt === 'object' && !(evt instanceof RegExp)) {\n for (i in evt) {\n if (evt.hasOwnProperty(i) && (value = evt[i])) {\n // Pass the single listener straight through to the singular method\n if (typeof value === 'function') {\n single.call(this, i, value);\n }\n else {\n // Otherwise pass back to the multiple function\n multiple.call(this, i, value);\n }\n }\n }\n }\n else {\n // So evt must be a string\n // And listeners must be an array of listeners\n // Loop over it and pass each one to the multiple method\n i = listeners.length;\n while (i--) {\n single.call(this, evt, listeners[i]);\n }\n }\n\n return this;\n };\n\n /**\n * Removes all listeners from a specified event.\n * If you do not specify an event then all listeners will be removed.\n * That means every event will be emptied.\n * You can also pass a regex to remove all events that match it.\n *\n * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.removeEvent = function removeEvent(evt) {\n var type = typeof evt;\n var events = this._getEvents();\n var key;\n\n // Remove different things depending on the state of evt\n if (type === 'string') {\n // Remove all listeners for the specified event\n delete events[evt];\n }\n else if (evt instanceof RegExp) {\n // Remove all events matching the regex.\n for (key in events) {\n if (events.hasOwnProperty(key) && evt.test(key)) {\n delete events[key];\n }\n }\n }\n else {\n // Remove all listeners in all events\n delete this._events;\n }\n\n return this;\n };\n\n /**\n * Alias of removeEvent.\n *\n * Added to mirror the node API.\n */\n proto.removeAllListeners = alias('removeEvent');\n\n /**\n * Emits an event of your choice.\n * When emitted, every listener attached to that event will be executed.\n * If you pass the optional argument array then those arguments will be passed to every listener upon execution.\n * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.\n * So they will not arrive within the array on the other side, they will be separate.\n * You can also pass a regular expression to emit to all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to emit and execute listeners for.\n * @param {Array} [args] Optional array of arguments to be passed to each listener.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.emitEvent = function emitEvent(evt, args) {\n var listenersMap = this.getListenersAsObject(evt);\n var listeners;\n var listener;\n var i;\n var key;\n var response;\n\n for (key in listenersMap) {\n if (listenersMap.hasOwnProperty(key)) {\n listeners = listenersMap[key].slice(0);\n\n for (i = 0; i < listeners.length; i++) {\n // If the listener returns true then it shall be removed from the event\n // The function is executed either with a basic call or an apply if there is an args array\n listener = listeners[i];\n\n if (listener.once === true) {\n this.removeListener(evt, listener.listener);\n }\n\n response = listener.listener.apply(this, args || []);\n\n if (response === this._getOnceReturnValue()) {\n this.removeListener(evt, listener.listener);\n }\n }\n }\n }\n\n return this;\n };\n\n /**\n * Alias of emitEvent\n */\n proto.trigger = alias('emitEvent');\n\n /**\n * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.\n * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.\n *\n * @param {String|RegExp} evt Name of the event to emit and execute listeners for.\n * @param {...*} Optional additional arguments to be passed to each listener.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.emit = function emit(evt) {\n var args = Array.prototype.slice.call(arguments, 1);\n return this.emitEvent(evt, args);\n };\n\n /**\n * Sets the current value to check against when executing listeners. If a\n * listeners return value matches the one set here then it will be removed\n * after execution. This value defaults to true.\n *\n * @param {*} value The new value to check for when executing listeners.\n * @return {Object} Current instance of EventEmitter for chaining.\n */\n proto.setOnceReturnValue = function setOnceReturnValue(value) {\n this._onceReturnValue = value;\n return this;\n };\n\n /**\n * Fetches the current value to check against when executing listeners. If\n * the listeners return value matches this one then it should be removed\n * automatically. It will return true by default.\n *\n * @return {*|Boolean} The current value to check for or the default, true.\n * @api private\n */\n proto._getOnceReturnValue = function _getOnceReturnValue() {\n if (this.hasOwnProperty('_onceReturnValue')) {\n return this._onceReturnValue;\n }\n else {\n return true;\n }\n };\n\n /**\n * Fetches the events object and creates one if required.\n *\n * @return {Object} The events storage object.\n * @api private\n */\n proto._getEvents = function _getEvents() {\n return this._events || (this._events = {});\n };\n\n /**\n * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.\n *\n * @return {Function} Non conflicting EventEmitter class.\n */\n EventEmitter.noConflict = function noConflict() {\n exports.EventEmitter = originalGlobalValue;\n return EventEmitter;\n };\n\n // Expose the class either via AMD, CommonJS or the global object\n if (typeof define === 'function' && define.amd) {\n define(function () {\n return EventEmitter;\n });\n }\n else if (typeof module === 'object' && module.exports){\n module.exports = EventEmitter;\n }\n else {\n exports.EventEmitter = EventEmitter;\n }\n}(this || {}));\n\n},{}]},{},[1]);\n })();"]}
assets/js/forms-admin.js CHANGED
@@ -1718,58 +1718,59 @@ window.mc4wp.forms.fields = fields;
1718
  // at http://marijnhaverbeke.nl/blog/#cm-internals .
1719
 
1720
  (function (global, factory) {
1721
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
1722
- typeof define === 'function' && define.amd ? define(factory) :
1723
- (global.CodeMirror = factory());
1724
  }(this, (function () { 'use strict';
1725
 
1726
  // Kludges for bugs and behavior differences that can't be feature
1727
  // detected are enabled based on userAgent etc sniffing.
1728
- var userAgent = navigator.userAgent
1729
- var platform = navigator.platform
1730
-
1731
- var gecko = /gecko\/\d/i.test(userAgent)
1732
- var ie_upto10 = /MSIE \d/.test(userAgent)
1733
- var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent)
1734
- var edge = /Edge\/(\d+)/.exec(userAgent)
1735
- var ie = ie_upto10 || ie_11up || edge
1736
- var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1])
1737
- var webkit = !edge && /WebKit\//.test(userAgent)
1738
- var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent)
1739
- var chrome = !edge && /Chrome\//.test(userAgent)
1740
- var presto = /Opera\//.test(userAgent)
1741
- var safari = /Apple Computer/.test(navigator.vendor)
1742
- var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent)
1743
- var phantom = /PhantomJS/.test(userAgent)
1744
-
1745
- var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent)
 
1746
  // This is woefully incomplete. Suggestions for alternative methods welcome.
1747
- var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent)
1748
- var mac = ios || /Mac/.test(platform)
1749
- var chromeOS = /\bCrOS\b/.test(userAgent)
1750
- var windows = /win/i.test(platform)
1751
-
1752
- var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/)
1753
- if (presto_version) { presto_version = Number(presto_version[1]) }
1754
- if (presto_version && presto_version >= 15) { presto = false; webkit = true }
1755
  // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
1756
- var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11))
1757
- var captureRightClick = gecko || (ie && ie_version >= 9)
1758
 
1759
  function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
1760
 
1761
  var rmClass = function(node, cls) {
1762
- var current = node.className
1763
- var match = classTest(cls).exec(current)
1764
  if (match) {
1765
- var after = current.slice(match.index + match[0].length)
1766
- node.className = current.slice(0, match.index) + (after ? match[1] + after : "")
1767
  }
1768
- }
1769
 
1770
  function removeChildren(e) {
1771
  for (var count = e.childNodes.length; count > 0; --count)
1772
- { e.removeChild(e.firstChild) }
1773
  return e
1774
  }
1775
 
@@ -1778,38 +1779,44 @@ function removeChildrenAndAdd(parent, e) {
1778
  }
1779
 
1780
  function elt(tag, content, className, style) {
1781
- var e = document.createElement(tag)
1782
- if (className) { e.className = className }
1783
- if (style) { e.style.cssText = style }
1784
- if (typeof content == "string") { e.appendChild(document.createTextNode(content)) }
1785
- else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]) } }
 
 
 
 
 
 
1786
  return e
1787
  }
1788
 
1789
- var range
1790
  if (document.createRange) { range = function(node, start, end, endNode) {
1791
- var r = document.createRange()
1792
- r.setEnd(endNode || node, end)
1793
- r.setStart(node, start)
1794
  return r
1795
- } }
1796
  else { range = function(node, start, end) {
1797
- var r = document.body.createTextRange()
1798
- try { r.moveToElementText(node.parentNode) }
1799
  catch(e) { return r }
1800
- r.collapse(true)
1801
- r.moveEnd("character", end)
1802
- r.moveStart("character", start)
1803
  return r
1804
- } }
1805
 
1806
  function contains(parent, child) {
1807
  if (child.nodeType == 3) // Android browser always returns false when child is a textnode
1808
- { child = child.parentNode }
1809
  if (parent.contains)
1810
  { return parent.contains(child) }
1811
  do {
1812
- if (child.nodeType == 11) { child = child.host }
1813
  if (child == parent) { return true }
1814
  } while (child = child.parentNode)
1815
  }
@@ -1818,44 +1825,44 @@ function activeElt() {
1818
  // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
1819
  // IE < 10 will throw when accessed while the page is loading or in an iframe.
1820
  // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
1821
- var activeElement
1822
  try {
1823
- activeElement = document.activeElement
1824
  } catch(e) {
1825
- activeElement = document.body || null
1826
  }
1827
- while (activeElement && activeElement.root && activeElement.root.activeElement)
1828
- { activeElement = activeElement.root.activeElement }
1829
  return activeElement
1830
  }
1831
 
1832
  function addClass(node, cls) {
1833
- var current = node.className
1834
- if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls }
1835
  }
1836
  function joinClasses(a, b) {
1837
- var as = a.split(" ")
1838
  for (var i = 0; i < as.length; i++)
1839
- { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i] } }
1840
  return b
1841
  }
1842
 
1843
- var selectInput = function(node) { node.select() }
1844
  if (ios) // Mobile Safari apparently has a bug where select() is broken.
1845
- { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length } }
1846
  else if (ie) // Suppress mysterious IE10 errors
1847
- { selectInput = function(node) { try { node.select() } catch(_e) {} } }
1848
 
1849
  function bind(f) {
1850
- var args = Array.prototype.slice.call(arguments, 1)
1851
  return function(){return f.apply(null, args)}
1852
  }
1853
 
1854
  function copyObj(obj, target, overwrite) {
1855
- if (!target) { target = {} }
1856
  for (var prop in obj)
1857
  { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
1858
- { target[prop] = obj[prop] } }
1859
  return target
1860
  }
1861
 
@@ -1863,23 +1870,23 @@ function copyObj(obj, target, overwrite) {
1863
  // Used mostly to find indentation.
1864
  function countColumn(string, end, tabSize, startIndex, startValue) {
1865
  if (end == null) {
1866
- end = string.search(/[^\s\u00a0]/)
1867
- if (end == -1) { end = string.length }
1868
  }
1869
  for (var i = startIndex || 0, n = startValue || 0;;) {
1870
- var nextTab = string.indexOf("\t", i)
1871
  if (nextTab < 0 || nextTab >= end)
1872
  { return n + (end - i) }
1873
- n += nextTab - i
1874
- n += tabSize - (n % tabSize)
1875
- i = nextTab + 1
1876
  }
1877
  }
1878
 
1879
- var Delayed = function() {this.id = null};
1880
  Delayed.prototype.set = function (ms, f) {
1881
- clearTimeout(this.id)
1882
- this.id = setTimeout(f, ms)
1883
  };
1884
 
1885
  function indexOf(array, elt) {
@@ -1889,68 +1896,69 @@ function indexOf(array, elt) {
1889
  }
1890
 
1891
  // Number of pixels added to scroller and sizer to hide scrollbar
1892
- var scrollerGap = 30
1893
 
1894
  // Returned or thrown by various protocols to signal 'I'm not
1895
  // handling this'.
1896
- var Pass = {toString: function(){return "CodeMirror.Pass"}}
1897
 
1898
  // Reused option objects for setSelection & friends
1899
  var sel_dontScroll = {scroll: false};
1900
  var sel_mouse = {origin: "*mouse"};
1901
  var sel_move = {origin: "+move"};
 
1902
  // The inverse of countColumn -- find the offset that corresponds to
1903
  // a particular column.
1904
  function findColumn(string, goal, tabSize) {
1905
  for (var pos = 0, col = 0;;) {
1906
- var nextTab = string.indexOf("\t", pos)
1907
- if (nextTab == -1) { nextTab = string.length }
1908
- var skipped = nextTab - pos
1909
  if (nextTab == string.length || col + skipped >= goal)
1910
  { return pos + Math.min(skipped, goal - col) }
1911
- col += nextTab - pos
1912
- col += tabSize - (col % tabSize)
1913
- pos = nextTab + 1
1914
  if (col >= goal) { return pos }
1915
  }
1916
  }
1917
 
1918
- var spaceStrs = [""]
1919
  function spaceStr(n) {
1920
  while (spaceStrs.length <= n)
1921
- { spaceStrs.push(lst(spaceStrs) + " ") }
1922
  return spaceStrs[n]
1923
  }
1924
 
1925
  function lst(arr) { return arr[arr.length-1] }
1926
 
1927
  function map(array, f) {
1928
- var out = []
1929
- for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i) }
1930
  return out
1931
  }
1932
 
1933
  function insertSorted(array, value, score) {
1934
- var pos = 0, priority = score(value)
1935
- while (pos < array.length && score(array[pos]) <= priority) { pos++ }
1936
- array.splice(pos, 0, value)
1937
  }
1938
 
1939
  function nothing() {}
1940
 
1941
  function createObj(base, props) {
1942
- var inst
1943
  if (Object.create) {
1944
- inst = Object.create(base)
1945
  } else {
1946
- nothing.prototype = base
1947
- inst = new nothing()
1948
  }
1949
- if (props) { copyObj(props, inst) }
1950
  return inst
1951
  }
1952
 
1953
- var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/
1954
  function isWordCharBasic(ch) {
1955
  return /\w/.test(ch) || ch > "\x80" &&
1956
  (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
@@ -1971,12 +1979,12 @@ function isEmpty(obj) {
1971
  // as editing and measuring is concerned. This is not fully correct,
1972
  // since some scripts/fonts/browsers also treat other configurations
1973
  // of code points as a group.
1974
- var extendingChars = /[\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]/
1975
  function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
1976
 
1977
  // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
1978
  function skipExtendingChars(str, pos, dir) {
1979
- while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir }
1980
  return pos
1981
  }
1982
 
@@ -1985,9 +1993,9 @@ function skipExtendingChars(str, pos, dir) {
1985
  function findFirst(pred, from, to) {
1986
  for (;;) {
1987
  if (Math.abs(from - to) <= 1) { return pred(from) ? from : to }
1988
- var mid = Math.floor((from + to) / 2)
1989
- if (pred(mid)) { to = mid }
1990
- else { from = mid }
1991
  }
1992
  }
1993
 
@@ -1996,113 +2004,114 @@ function findFirst(pred, from, to) {
1996
  // display-related state.
1997
 
1998
  function Display(place, doc, input) {
1999
- var d = this
2000
- this.input = input
2001
 
2002
  // Covers bottom-right square when both scrollbars are present.
2003
- d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler")
2004
- d.scrollbarFiller.setAttribute("cm-not-content", "true")
2005
  // Covers bottom of gutter when coverGutterNextToScrollbar is on
2006
  // and h scrollbar is present.
2007
- d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
2008
- d.gutterFiller.setAttribute("cm-not-content", "true")
2009
  // Will contain the actual code, positioned to cover the viewport.
2010
- d.lineDiv = elt("div", null, "CodeMirror-code")
2011
  // Elements are added to these to represent selection and cursors.
2012
- d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
2013
- d.cursorDiv = elt("div", null, "CodeMirror-cursors")
2014
  // A visibility: hidden element used to find the size of things.
2015
- d.measure = elt("div", null, "CodeMirror-measure")
2016
  // When lines outside of the viewport are measured, they are drawn in this.
2017
- d.lineMeasure = elt("div", null, "CodeMirror-measure")
2018
  // Wraps everything that needs to exist inside the vertically-padded coordinate system
2019
- d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
2020
- null, "position: relative; outline: none")
 
2021
  // Moved around its parent to cover visible view.
2022
- d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative")
2023
  // Set to the height of the document, allowing scrolling.
2024
- d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
2025
- d.sizerWidth = null
2026
  // Behavior of elts with overflow: auto and padding is
2027
  // inconsistent across browsers. This is used to ensure the
2028
  // scrollable area is big enough.
2029
- d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;")
2030
  // Will contain the gutters, if any.
2031
- d.gutters = elt("div", null, "CodeMirror-gutters")
2032
- d.lineGutter = null
2033
  // Actual scrollable element.
2034
- d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll")
2035
- d.scroller.setAttribute("tabIndex", "-1")
2036
  // The element in which the editor lives.
2037
- d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror")
2038
 
2039
  // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
2040
- if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 }
2041
- if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true }
2042
 
2043
  if (place) {
2044
- if (place.appendChild) { place.appendChild(d.wrapper) }
2045
- else { place(d.wrapper) }
2046
  }
2047
 
2048
  // Current rendered range (may be bigger than the view window).
2049
- d.viewFrom = d.viewTo = doc.first
2050
- d.reportedViewFrom = d.reportedViewTo = doc.first
2051
  // Information about the rendered lines.
2052
- d.view = []
2053
- d.renderedView = null
2054
  // Holds info about a single rendered line when it was rendered
2055
  // for measurement, while not in view.
2056
- d.externalMeasured = null
2057
  // Empty space (in pixels) above the view
2058
- d.viewOffset = 0
2059
- d.lastWrapHeight = d.lastWrapWidth = 0
2060
- d.updateLineNumbers = null
2061
 
2062
- d.nativeBarWidth = d.barHeight = d.barWidth = 0
2063
- d.scrollbarsClipped = false
2064
 
2065
  // Used to only resize the line number gutter when necessary (when
2066
  // the amount of lines crosses a boundary that makes its width change)
2067
- d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null
2068
  // Set to true when a non-horizontal-scrolling line widget is
2069
  // added. As an optimization, line widget aligning is skipped when
2070
  // this is false.
2071
- d.alignWidgets = false
2072
 
2073
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
2074
 
2075
  // Tracks the maximum line length so that the horizontal scrollbar
2076
  // can be kept static when scrolling.
2077
- d.maxLine = null
2078
- d.maxLineLength = 0
2079
- d.maxLineChanged = false
2080
 
2081
  // Used for measuring wheel scrolling granularity
2082
- d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null
2083
 
2084
  // True when shift is held down.
2085
- d.shift = false
2086
 
2087
  // Used to track whether anything happened since the context menu
2088
  // was opened.
2089
- d.selForContextMenu = null
2090
 
2091
- d.activeTouch = null
2092
 
2093
- input.init(d)
2094
  }
2095
 
2096
  // Find the line object corresponding to the given line number.
2097
  function getLine(doc, n) {
2098
- n -= doc.first
2099
  if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
2100
- var chunk = doc
2101
  while (!chunk.lines) {
2102
  for (var i = 0;; ++i) {
2103
- var child = chunk.children[i], sz = child.chunkSize()
2104
  if (n < sz) { chunk = child; break }
2105
- n -= sz
2106
  }
2107
  }
2108
  return chunk.lines[n]
@@ -2111,39 +2120,39 @@ function getLine(doc, n) {
2111
  // Get the part of a document between two positions, as an array of
2112
  // strings.
2113
  function getBetween(doc, start, end) {
2114
- var out = [], n = start.line
2115
  doc.iter(start.line, end.line + 1, function (line) {
2116
- var text = line.text
2117
- if (n == end.line) { text = text.slice(0, end.ch) }
2118
- if (n == start.line) { text = text.slice(start.ch) }
2119
- out.push(text)
2120
- ++n
2121
- })
2122
  return out
2123
  }
2124
  // Get the lines between from and to, as array of strings.
2125
  function getLines(doc, from, to) {
2126
- var out = []
2127
- doc.iter(from, to, function (line) { out.push(line.text) }) // iter aborts when callback returns truthy value
2128
  return out
2129
  }
2130
 
2131
  // Update the height of a line, propagating the height change
2132
  // upwards to parent nodes.
2133
  function updateLineHeight(line, height) {
2134
- var diff = height - line.height
2135
- if (diff) { for (var n = line; n; n = n.parent) { n.height += diff } }
2136
  }
2137
 
2138
  // Given a line object, find its line number by walking up through
2139
  // its parent links.
2140
  function lineNo(line) {
2141
  if (line.parent == null) { return null }
2142
- var cur = line.parent, no = indexOf(cur.lines, line)
2143
  for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
2144
  for (var i = 0;; ++i) {
2145
  if (chunk.children[i] == cur) { break }
2146
- no += chunk.children[i].chunkSize()
2147
  }
2148
  }
2149
  return no + cur.first
@@ -2152,21 +2161,21 @@ function lineNo(line) {
2152
  // Find the line at the given vertical position, using the height
2153
  // information in the document tree.
2154
  function lineAtHeight(chunk, h) {
2155
- var n = chunk.first
2156
  outer: do {
2157
  for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
2158
- var child = chunk.children[i$1], ch = child.height
2159
  if (h < ch) { chunk = child; continue outer }
2160
- h -= ch
2161
- n += child.chunkSize()
2162
  }
2163
  return n
2164
  } while (!chunk.lines)
2165
- var i = 0
2166
  for (; i < chunk.lines.length; ++i) {
2167
- var line = chunk.lines[i], lh = line.height
2168
  if (h < lh) { break }
2169
- h -= lh
2170
  }
2171
  return n + i
2172
  }
@@ -2182,9 +2191,9 @@ function Pos(line, ch, sticky) {
2182
  if ( sticky === void 0 ) sticky = null;
2183
 
2184
  if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
2185
- this.line = line
2186
- this.ch = ch
2187
- this.sticky = sticky
2188
  }
2189
 
2190
  // Compare two positions, return 0 if they are the same, a negative
@@ -2202,59 +2211,60 @@ function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
2202
  function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
2203
  function clipPos(doc, pos) {
2204
  if (pos.line < doc.first) { return Pos(doc.first, 0) }
2205
- var last = doc.first + doc.size - 1
2206
  if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
2207
  return clipToLen(pos, getLine(doc, pos.line).text.length)
2208
  }
2209
  function clipToLen(pos, linelen) {
2210
- var ch = pos.ch
2211
  if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
2212
  else if (ch < 0) { return Pos(pos.line, 0) }
2213
  else { return pos }
2214
  }
2215
  function clipPosArray(doc, array) {
2216
- var out = []
2217
- for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]) }
2218
  return out
2219
  }
2220
 
2221
  // Optimize some code when these features are not used.
2222
  var sawReadOnlySpans = false;
2223
  var sawCollapsedSpans = false;
 
2224
  function seeReadOnlySpans() {
2225
- sawReadOnlySpans = true
2226
  }
2227
 
2228
  function seeCollapsedSpans() {
2229
- sawCollapsedSpans = true
2230
  }
2231
 
2232
  // TEXTMARKER SPANS
2233
 
2234
  function MarkedSpan(marker, from, to) {
2235
- this.marker = marker
2236
- this.from = from; this.to = to
2237
  }
2238
 
2239
  // Search an array of spans for a span matching the given marker.
2240
  function getMarkedSpanFor(spans, marker) {
2241
  if (spans) { for (var i = 0; i < spans.length; ++i) {
2242
- var span = spans[i]
2243
  if (span.marker == marker) { return span }
2244
  } }
2245
  }
2246
  // Remove a span from an array, returning undefined if no spans are
2247
  // left (we don't store arrays for lines without spans).
2248
  function removeMarkedSpan(spans, span) {
2249
- var r
2250
  for (var i = 0; i < spans.length; ++i)
2251
- { if (spans[i] != span) { (r || (r = [])).push(spans[i]) } }
2252
  return r
2253
  }
2254
  // Add a span to a line.
2255
  function addMarkedSpan(line, span) {
2256
- line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span]
2257
- span.marker.attachLine(line)
2258
  }
2259
 
2260
  // Used for the algorithm that adjusts markers for a change in the
@@ -2262,26 +2272,24 @@ function addMarkedSpan(line, span) {
2262
  // character position, returning an array of remaining chunks (or
2263
  // undefined if nothing remains).
2264
  function markedSpansBefore(old, startCh, isInsert) {
2265
- var nw
2266
  if (old) { for (var i = 0; i < old.length; ++i) {
2267
- var span = old[i], marker = span.marker
2268
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh)
2269
  if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
2270
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
2271
- ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to))
2272
  }
2273
  } }
2274
  return nw
2275
  }
2276
  function markedSpansAfter(old, endCh, isInsert) {
2277
- var nw
2278
  if (old) { for (var i = 0; i < old.length; ++i) {
2279
- var span = old[i], marker = span.marker
2280
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh)
2281
  if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
2282
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
2283
- ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
2284
- span.to == null ? null : span.to - endCh))
2285
  }
2286
  } }
2287
  return nw
@@ -2295,60 +2303,60 @@ function markedSpansAfter(old, endCh, isInsert) {
2295
  // arrays with one element for each line in (after) the change.
2296
  function stretchSpansOverChange(doc, change) {
2297
  if (change.full) { return null }
2298
- var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans
2299
- var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans
2300
  if (!oldFirst && !oldLast) { return null }
2301
 
2302
- var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0
2303
  // Get the spans that 'stick out' on both sides
2304
- var first = markedSpansBefore(oldFirst, startCh, isInsert)
2305
- var last = markedSpansAfter(oldLast, endCh, isInsert)
2306
 
2307
  // Next, merge those two ends
2308
- var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0)
2309
  if (first) {
2310
  // Fix up .to properties of first
2311
  for (var i = 0; i < first.length; ++i) {
2312
- var span = first[i]
2313
  if (span.to == null) {
2314
- var found = getMarkedSpanFor(last, span.marker)
2315
- if (!found) { span.to = startCh }
2316
- else if (sameLine) { span.to = found.to == null ? null : found.to + offset }
2317
  }
2318
  }
2319
  }
2320
  if (last) {
2321
  // Fix up .from in last (or move them into first in case of sameLine)
2322
  for (var i$1 = 0; i$1 < last.length; ++i$1) {
2323
- var span$1 = last[i$1]
2324
- if (span$1.to != null) { span$1.to += offset }
2325
  if (span$1.from == null) {
2326
- var found$1 = getMarkedSpanFor(first, span$1.marker)
2327
  if (!found$1) {
2328
- span$1.from = offset
2329
- if (sameLine) { (first || (first = [])).push(span$1) }
2330
  }
2331
  } else {
2332
- span$1.from += offset
2333
- if (sameLine) { (first || (first = [])).push(span$1) }
2334
  }
2335
  }
2336
  }
2337
  // Make sure we didn't create any zero-length spans
2338
- if (first) { first = clearEmptySpans(first) }
2339
- if (last && last != first) { last = clearEmptySpans(last) }
2340
 
2341
- var newMarkers = [first]
2342
  if (!sameLine) {
2343
  // Fill gap with whole-line-spans
2344
- var gap = change.text.length - 2, gapMarkers
2345
  if (gap > 0 && first)
2346
  { for (var i$2 = 0; i$2 < first.length; ++i$2)
2347
  { if (first[i$2].to == null)
2348
- { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)) } } }
2349
  for (var i$3 = 0; i$3 < gap; ++i$3)
2350
- { newMarkers.push(gapMarkers) }
2351
- newMarkers.push(last)
2352
  }
2353
  return newMarkers
2354
  }
@@ -2357,9 +2365,9 @@ function stretchSpansOverChange(doc, change) {
2357
  // option of false.
2358
  function clearEmptySpans(spans) {
2359
  for (var i = 0; i < spans.length; ++i) {
2360
- var span = spans[i]
2361
  if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
2362
- { spans.splice(i--, 1) }
2363
  }
2364
  if (!spans.length) { return null }
2365
  return spans
@@ -2367,28 +2375,28 @@ function clearEmptySpans(spans) {
2367
 
2368
  // Used to 'clip' out readOnly ranges when making a change.
2369
  function removeReadOnlyRanges(doc, from, to) {
2370
- var markers = null
2371
  doc.iter(from.line, to.line + 1, function (line) {
2372
  if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
2373
- var mark = line.markedSpans[i].marker
2374
  if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
2375
- { (markers || (markers = [])).push(mark) }
2376
  } }
2377
- })
2378
  if (!markers) { return null }
2379
- var parts = [{from: from, to: to}]
2380
  for (var i = 0; i < markers.length; ++i) {
2381
- var mk = markers[i], m = mk.find(0)
2382
  for (var j = 0; j < parts.length; ++j) {
2383
- var p = parts[j]
2384
  if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
2385
- var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to)
2386
  if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
2387
- { newParts.push({from: p.from, to: m.from}) }
2388
  if (dto > 0 || !mk.inclusiveRight && !dto)
2389
- { newParts.push({from: m.to, to: p.to}) }
2390
- parts.splice.apply(parts, newParts)
2391
- j += newParts.length - 3
2392
  }
2393
  }
2394
  return parts
@@ -2396,17 +2404,17 @@ function removeReadOnlyRanges(doc, from, to) {
2396
 
2397
  // Connect or disconnect spans from a line.
2398
  function detachMarkedSpans(line) {
2399
- var spans = line.markedSpans
2400
  if (!spans) { return }
2401
  for (var i = 0; i < spans.length; ++i)
2402
- { spans[i].marker.detachLine(line) }
2403
- line.markedSpans = null
2404
  }
2405
  function attachMarkedSpans(line, spans) {
2406
  if (!spans) { return }
2407
  for (var i = 0; i < spans.length; ++i)
2408
- { spans[i].marker.attachLine(line) }
2409
- line.markedSpans = spans
2410
  }
2411
 
2412
  // Helpers used when computing which overlapping collapsed span
@@ -2418,12 +2426,12 @@ function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
2418
  // spans is larger (and thus includes the other). Falls back to
2419
  // comparing ids when the spans cover exactly the same range.
2420
  function compareCollapsedMarkers(a, b) {
2421
- var lenDiff = a.lines.length - b.lines.length
2422
  if (lenDiff != 0) { return lenDiff }
2423
- var aPos = a.find(), bPos = b.find()
2424
- var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b)
2425
  if (fromCmp) { return -fromCmp }
2426
- var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b)
2427
  if (toCmp) { return toCmp }
2428
  return b.id - a.id
2429
  }
@@ -2431,12 +2439,12 @@ function compareCollapsedMarkers(a, b) {
2431
  // Find out whether a line ends or starts in a collapsed span. If
2432
  // so, return the marker for that span.
2433
  function collapsedSpanAtSide(line, start) {
2434
- var sps = sawCollapsedSpans && line.markedSpans, found
2435
  if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
2436
- sp = sps[i]
2437
  if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
2438
  (!found || compareCollapsedMarkers(found, sp.marker) < 0))
2439
- { found = sp.marker }
2440
  } }
2441
  return found
2442
  }
@@ -2446,15 +2454,15 @@ function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
2446
  // Test whether there exists a collapsed span that partially
2447
  // overlaps (covers the start or end, but not both) of a new span.
2448
  // Such overlap is not allowed.
2449
- function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
2450
- var line = getLine(doc, lineNo)
2451
- var sps = sawCollapsedSpans && line.markedSpans
2452
  if (sps) { for (var i = 0; i < sps.length; ++i) {
2453
- var sp = sps[i]
2454
  if (!sp.marker.collapsed) { continue }
2455
- var found = sp.marker.find(0)
2456
- var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker)
2457
- var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker)
2458
  if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
2459
  if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
2460
  fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
@@ -2467,26 +2475,26 @@ function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
2467
  // visual line. This finds the start of the visual line that the
2468
  // given line is part of (usually that is the line itself).
2469
  function visualLine(line) {
2470
- var merged
2471
  while (merged = collapsedSpanAtStart(line))
2472
- { line = merged.find(-1, true).line }
2473
  return line
2474
  }
2475
 
2476
  function visualLineEnd(line) {
2477
- var merged
2478
  while (merged = collapsedSpanAtEnd(line))
2479
- { line = merged.find(1, true).line }
2480
  return line
2481
  }
2482
 
2483
  // Returns an array of logical lines that continue the visual line
2484
  // started by the argument, or undefined if there are no such lines.
2485
  function visualLineContinued(line) {
2486
- var merged, lines
2487
  while (merged = collapsedSpanAtEnd(line)) {
2488
  line = merged.find(1, true).line
2489
- ;(lines || (lines = [])).push(line)
2490
  }
2491
  return lines
2492
  }
@@ -2494,7 +2502,7 @@ function visualLineContinued(line) {
2494
  // Get the line number of the start of the visual line that the
2495
  // given line number is part of.
2496
  function visualLineNo(doc, lineN) {
2497
- var line = getLine(doc, lineN), vis = visualLine(line)
2498
  if (line == vis) { return lineN }
2499
  return lineNo(vis)
2500
  }
@@ -2503,10 +2511,10 @@ function visualLineNo(doc, lineN) {
2503
  // the given line.
2504
  function visualLineEndNo(doc, lineN) {
2505
  if (lineN > doc.lastLine()) { return lineN }
2506
- var line = getLine(doc, lineN), merged
2507
  if (!lineIsHidden(doc, line)) { return lineN }
2508
  while (merged = collapsedSpanAtEnd(line))
2509
- { line = merged.find(1, true).line }
2510
  return lineNo(line) + 1
2511
  }
2512
 
@@ -2514,9 +2522,9 @@ function visualLineEndNo(doc, lineN) {
2514
  // are part of a visual line that starts with another line, or when
2515
  // they are entirely covered by collapsed, non-widget span.
2516
  function lineIsHidden(doc, line) {
2517
- var sps = sawCollapsedSpans && line.markedSpans
2518
  if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
2519
- sp = sps[i]
2520
  if (!sp.marker.collapsed) { continue }
2521
  if (sp.from == null) { return true }
2522
  if (sp.marker.widgetNode) { continue }
@@ -2526,13 +2534,13 @@ function lineIsHidden(doc, line) {
2526
  }
2527
  function lineIsHiddenInner(doc, line, span) {
2528
  if (span.to == null) {
2529
- var end = span.marker.find(1, true)
2530
  return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
2531
  }
2532
  if (span.marker.inclusiveRight && span.to == line.text.length)
2533
  { return true }
2534
  for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
2535
- sp = line.markedSpans[i]
2536
  if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
2537
  (sp.to == null || sp.to != span.from) &&
2538
  (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
@@ -2542,19 +2550,19 @@ function lineIsHiddenInner(doc, line, span) {
2542
 
2543
  // Find the height above the given line.
2544
  function heightAtLine(lineObj) {
2545
- lineObj = visualLine(lineObj)
2546
 
2547
- var h = 0, chunk = lineObj.parent
2548
  for (var i = 0; i < chunk.lines.length; ++i) {
2549
- var line = chunk.lines[i]
2550
  if (line == lineObj) { break }
2551
- else { h += line.height }
2552
  }
2553
  for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
2554
  for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
2555
- var cur = p.children[i$1]
2556
  if (cur == chunk) { break }
2557
- else { h += cur.height }
2558
  }
2559
  }
2560
  return h
@@ -2565,66 +2573,66 @@ function heightAtLine(lineObj) {
2565
  // other lines onto it.
2566
  function lineLength(line) {
2567
  if (line.height == 0) { return 0 }
2568
- var len = line.text.length, merged, cur = line
2569
  while (merged = collapsedSpanAtStart(cur)) {
2570
- var found = merged.find(0, true)
2571
- cur = found.from.line
2572
- len += found.from.ch - found.to.ch
2573
  }
2574
- cur = line
2575
  while (merged = collapsedSpanAtEnd(cur)) {
2576
- var found$1 = merged.find(0, true)
2577
- len -= cur.text.length - found$1.from.ch
2578
- cur = found$1.to.line
2579
- len += cur.text.length - found$1.to.ch
2580
  }
2581
  return len
2582
  }
2583
 
2584
  // Find the longest line in the document.
2585
  function findMaxLine(cm) {
2586
- var d = cm.display, doc = cm.doc
2587
- d.maxLine = getLine(doc, doc.first)
2588
- d.maxLineLength = lineLength(d.maxLine)
2589
- d.maxLineChanged = true
2590
  doc.iter(function (line) {
2591
- var len = lineLength(line)
2592
  if (len > d.maxLineLength) {
2593
- d.maxLineLength = len
2594
- d.maxLine = line
2595
  }
2596
- })
2597
  }
2598
 
2599
  // BIDI HELPERS
2600
 
2601
  function iterateBidiSections(order, from, to, f) {
2602
  if (!order) { return f(from, to, "ltr") }
2603
- var found = false
2604
  for (var i = 0; i < order.length; ++i) {
2605
- var part = order[i]
2606
  if (part.from < to && part.to > from || from == to && part.to == from) {
2607
- f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr")
2608
- found = true
2609
  }
2610
  }
2611
- if (!found) { f(from, to, "ltr") }
2612
  }
2613
 
2614
- var bidiOther = null
2615
  function getBidiPartAt(order, ch, sticky) {
2616
- var found
2617
- bidiOther = null
2618
  for (var i = 0; i < order.length; ++i) {
2619
- var cur = order[i]
2620
  if (cur.from < ch && cur.to > ch) { return i }
2621
  if (cur.to == ch) {
2622
- if (cur.from != cur.to && sticky == "before") { found = i }
2623
- else { bidiOther = i }
2624
  }
2625
  if (cur.from == ch) {
2626
- if (cur.from != cur.to && sticky != "before") { found = i }
2627
- else { bidiOther = i }
2628
  }
2629
  }
2630
  return found != null ? found : bidiOther
@@ -2655,9 +2663,9 @@ function getBidiPartAt(order, ch, sticky) {
2655
  // objects) in the order in which they occur visually.
2656
  var bidiOrdering = (function() {
2657
  // Character types for codepoints 0 to 0xff
2658
- var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN"
2659
  // Character types for codepoints 0x600 to 0x6f9
2660
- var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111"
2661
  function charType(code) {
2662
  if (code <= 0xf7) { return lowTypes.charAt(code) }
2663
  else if (0x590 <= code && code <= 0x5f4) { return "R" }
@@ -2668,30 +2676,30 @@ var bidiOrdering = (function() {
2668
  else { return "L" }
2669
  }
2670
 
2671
- var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/
2672
- var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/
2673
- // Browsers seem to always treat the boundaries of block elements as being L.
2674
- var outerType = "L"
2675
 
2676
  function BidiSpan(level, from, to) {
2677
- this.level = level
2678
- this.from = from; this.to = to
2679
  }
2680
 
2681
- return function(str) {
2682
- if (!bidiRE.test(str)) { return false }
2683
- var len = str.length, types = []
 
 
2684
  for (var i = 0; i < len; ++i)
2685
- { types.push(charType(str.charCodeAt(i))) }
2686
 
2687
  // W1. Examine each non-spacing mark (NSM) in the level run, and
2688
  // change the type of the NSM to the type of the previous
2689
  // character. If the NSM is at the start of the level run, it will
2690
  // get the type of sor.
2691
  for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
2692
- var type = types[i$1]
2693
- if (type == "m") { types[i$1] = prev }
2694
- else { prev = type }
2695
  }
2696
 
2697
  // W2. Search backwards from each instance of a European number
@@ -2700,20 +2708,20 @@ var bidiOrdering = (function() {
2700
  // number.
2701
  // W3. Change all ALs to R.
2702
  for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
2703
- var type$1 = types[i$2]
2704
- if (type$1 == "1" && cur == "r") { types[i$2] = "n" }
2705
- else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R" } }
2706
  }
2707
 
2708
  // W4. A single European separator between two European numbers
2709
  // changes to a European number. A single common separator between
2710
  // two numbers of the same type changes to that type.
2711
  for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
2712
- var type$2 = types[i$3]
2713
- if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1" }
2714
  else if (type$2 == "," && prev$1 == types[i$3+1] &&
2715
- (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1 }
2716
- prev$1 = type$2
2717
  }
2718
 
2719
  // W5. A sequence of European terminators adjacent to European
@@ -2721,14 +2729,14 @@ var bidiOrdering = (function() {
2721
  // W6. Otherwise, separators and terminators change to Other
2722
  // Neutral.
2723
  for (var i$4 = 0; i$4 < len; ++i$4) {
2724
- var type$3 = types[i$4]
2725
- if (type$3 == ",") { types[i$4] = "N" }
2726
  else if (type$3 == "%") {
2727
- var end = (void 0)
2728
  for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
2729
- var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N"
2730
- for (var j = i$4; j < end; ++j) { types[j] = replace }
2731
- i$4 = end - 1
2732
  }
2733
  }
2734
 
@@ -2736,9 +2744,9 @@ var bidiOrdering = (function() {
2736
  // until the first strong type (R, L, or sor) is found. If an L is
2737
  // found, then change the type of the European number to L.
2738
  for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
2739
- var type$4 = types[i$5]
2740
- if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L" }
2741
- else if (isStrong.test(type$4)) { cur$1 = type$4 }
2742
  }
2743
 
2744
  // N1. A sequence of neutrals takes the direction of the
@@ -2749,13 +2757,13 @@ var bidiOrdering = (function() {
2749
  // N2. Any remaining neutrals take the embedding direction.
2750
  for (var i$6 = 0; i$6 < len; ++i$6) {
2751
  if (isNeutral.test(types[i$6])) {
2752
- var end$1 = (void 0)
2753
  for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
2754
- var before = (i$6 ? types[i$6-1] : outerType) == "L"
2755
- var after = (end$1 < len ? types[end$1] : outerType) == "L"
2756
- var replace$1 = before || after ? "L" : "R"
2757
- for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1 }
2758
- i$6 = end$1 - 1
2759
  }
2760
  }
2761
 
@@ -2764,67 +2772,67 @@ var bidiOrdering = (function() {
2764
  // levels (0, 1, 2) in an implementation that doesn't take
2765
  // explicit embedding into account, we can build up the order on
2766
  // the fly, without following the level-based algorithm.
2767
- var order = [], m
2768
  for (var i$7 = 0; i$7 < len;) {
2769
  if (countsAsLeft.test(types[i$7])) {
2770
- var start = i$7
2771
  for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
2772
- order.push(new BidiSpan(0, start, i$7))
2773
  } else {
2774
- var pos = i$7, at = order.length
2775
  for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
2776
  for (var j$2 = pos; j$2 < i$7;) {
2777
  if (countsAsNum.test(types[j$2])) {
2778
- if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)) }
2779
- var nstart = j$2
2780
  for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
2781
- order.splice(at, 0, new BidiSpan(2, nstart, j$2))
2782
- pos = j$2
2783
- } else { ++j$2 }
2784
  }
2785
- if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)) }
2786
  }
2787
  }
2788
  if (order[0].level == 1 && (m = str.match(/^\s+/))) {
2789
- order[0].from = m[0].length
2790
- order.unshift(new BidiSpan(0, 0, m[0].length))
2791
  }
2792
  if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
2793
- lst(order).to -= m[0].length
2794
- order.push(new BidiSpan(0, len - m[0].length, len))
2795
  }
2796
 
2797
- return order
2798
  }
2799
- })()
2800
 
2801
  // Get the bidi ordering for the given line (and cache it). Returns
2802
  // false for lines that are fully left-to-right, and an array of
2803
  // BidiSpan objects otherwise.
2804
- function getOrder(line) {
2805
- var order = line.order
2806
- if (order == null) { order = line.order = bidiOrdering(line.text) }
2807
  return order
2808
  }
2809
 
2810
  function moveCharLogically(line, ch, dir) {
2811
- var target = skipExtendingChars(line.text, ch + dir, dir)
2812
  return target < 0 || target > line.text.length ? null : target
2813
  }
2814
 
2815
  function moveLogically(line, start, dir) {
2816
- var ch = moveCharLogically(line, start.ch, dir)
2817
  return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
2818
  }
2819
 
2820
  function endOfLine(visually, cm, lineObj, lineNo, dir) {
2821
  if (visually) {
2822
- var order = getOrder(lineObj)
2823
  if (order) {
2824
- var part = dir < 0 ? lst(order) : order[0]
2825
- var moveInStorageOrder = (dir < 0) == (part.level == 1)
2826
- var sticky = moveInStorageOrder ? "after" : "before"
2827
- var ch
2828
  // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
2829
  // it could be that the last bidi part is not on the last visual line,
2830
  // since visual lines contain content order-consecutive chunks.
@@ -2832,12 +2840,12 @@ function endOfLine(visually, cm, lineObj, lineNo, dir) {
2832
  // in the rtl chunk that is on the last line (that is, the same line
2833
  // as the last (content-order) character).
2834
  if (part.level > 0) {
2835
- var prep = prepareMeasureForLine(cm, lineObj)
2836
- ch = dir < 0 ? lineObj.text.length - 1 : 0
2837
- var targetTop = measureCharPrepared(cm, prep, ch).top
2838
- ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch)
2839
- if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1, true) }
2840
- } else { ch = dir < 0 ? part.to : part.from }
2841
  return new Pos(lineNo, ch, sticky)
2842
  }
2843
  }
@@ -2845,36 +2853,37 @@ function endOfLine(visually, cm, lineObj, lineNo, dir) {
2845
  }
2846
 
2847
  function moveVisually(cm, line, start, dir) {
2848
- var bidi = getOrder(line)
2849
  if (!bidi) { return moveLogically(line, start, dir) }
2850
  if (start.ch >= line.text.length) {
2851
- start.ch = line.text.length
2852
- start.sticky = "before"
2853
  } else if (start.ch <= 0) {
2854
- start.ch = 0
2855
- start.sticky = "after"
2856
  }
2857
- var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos]
2858
- if (part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
2859
- // Case 1: We move within an ltr part. Even with wrapped lines,
2860
  // nothing interesting happens.
2861
  return moveLogically(line, start, dir)
2862
  }
2863
 
2864
- var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); }
2865
- var prep
2866
  var getWrappedLineExtent = function (ch) {
2867
  if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
2868
- prep = prep || prepareMeasureForLine(cm, line)
2869
  return wrappedLineExtentChar(cm, line, prep, ch)
2870
- }
2871
- var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch)
2872
-
2873
- if (part.level % 2 == 1) {
2874
- var ch = mv(start, -dir)
2875
- if (ch != null && (dir > 0 ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
2876
- // Case 2: We move within an rtl part on the same visual line
2877
- var sticky = dir < 0 ? "before" : "after"
 
2878
  return new Pos(start.line, ch, sticky)
2879
  }
2880
  }
@@ -2885,26 +2894,26 @@ function moveVisually(cm, line, start, dir) {
2885
  var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
2886
  var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
2887
  ? new Pos(start.line, mv(ch, 1), "before")
2888
- : new Pos(start.line, ch, "after"); }
2889
 
2890
  for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
2891
- var part = bidi[partPos]
2892
- var moveInStorageOrder = (dir > 0) == (part.level != 1)
2893
- var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1)
2894
  if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
2895
- ch = moveInStorageOrder ? part.from : mv(part.to, -1)
2896
  if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
2897
  }
2898
- }
2899
 
2900
  // Case 3a: Look for other bidi parts on the same visual line
2901
- var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent)
2902
  if (res) { return res }
2903
 
2904
  // Case 3b: Look for other bidi parts on the next visual line
2905
- var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1)
2906
  if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
2907
- res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh))
2908
  if (res) { return res }
2909
  }
2910
 
@@ -2917,18 +2926,18 @@ function moveVisually(cm, line, start, dir) {
2917
  // Lightweight event framework. on/off also work on DOM nodes,
2918
  // registering native DOM handlers.
2919
 
2920
- var noHandlers = []
2921
 
2922
  var on = function(emitter, type, f) {
2923
  if (emitter.addEventListener) {
2924
- emitter.addEventListener(type, f, false)
2925
  } else if (emitter.attachEvent) {
2926
- emitter.attachEvent("on" + type, f)
2927
  } else {
2928
- var map = emitter._handlers || (emitter._handlers = {})
2929
- map[type] = (map[type] || noHandlers).concat(f)
2930
  }
2931
- }
2932
 
2933
  function getHandlers(emitter, type) {
2934
  return emitter._handlers && emitter._handlers[type] || noHandlers
@@ -2936,24 +2945,24 @@ function getHandlers(emitter, type) {
2936
 
2937
  function off(emitter, type, f) {
2938
  if (emitter.removeEventListener) {
2939
- emitter.removeEventListener(type, f, false)
2940
  } else if (emitter.detachEvent) {
2941
- emitter.detachEvent("on" + type, f)
2942
  } else {
2943
- var map = emitter._handlers, arr = map && map[type]
2944
  if (arr) {
2945
- var index = indexOf(arr, f)
2946
  if (index > -1)
2947
- { map[type] = arr.slice(0, index).concat(arr.slice(index + 1)) }
2948
  }
2949
  }
2950
  }
2951
 
2952
  function signal(emitter, type /*, values...*/) {
2953
- var handlers = getHandlers(emitter, type)
2954
  if (!handlers.length) { return }
2955
- var args = Array.prototype.slice.call(arguments, 2)
2956
- for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args) }
2957
  }
2958
 
2959
  // The DOM events that CodeMirror handles can be overridden by
@@ -2961,17 +2970,17 @@ function signal(emitter, type /*, values...*/) {
2961
  // and preventDefault-ing the event in that handler.
2962
  function signalDOMEvent(cm, e, override) {
2963
  if (typeof e == "string")
2964
- { e = {type: e, preventDefault: function() { this.defaultPrevented = true }} }
2965
- signal(cm, override || e.type, cm, e)
2966
  return e_defaultPrevented(e) || e.codemirrorIgnore
2967
  }
2968
 
2969
  function signalCursorActivity(cm) {
2970
- var arr = cm._handlers && cm._handlers.cursorActivity
2971
  if (!arr) { return }
2972
- var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = [])
2973
  for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
2974
- { set.push(arr[i]) } }
2975
  }
2976
 
2977
  function hasHandler(emitter, type) {
@@ -2981,35 +2990,35 @@ function hasHandler(emitter, type) {
2981
  // Add on and off methods to a constructor's prototype, to make
2982
  // registering events on such objects more convenient.
2983
  function eventMixin(ctor) {
2984
- ctor.prototype.on = function(type, f) {on(this, type, f)}
2985
- ctor.prototype.off = function(type, f) {off(this, type, f)}
2986
  }
2987
 
2988
  // Due to the fact that we still support jurassic IE versions, some
2989
  // compatibility wrappers are needed.
2990
 
2991
  function e_preventDefault(e) {
2992
- if (e.preventDefault) { e.preventDefault() }
2993
- else { e.returnValue = false }
2994
  }
2995
  function e_stopPropagation(e) {
2996
- if (e.stopPropagation) { e.stopPropagation() }
2997
- else { e.cancelBubble = true }
2998
  }
2999
  function e_defaultPrevented(e) {
3000
  return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
3001
  }
3002
- function e_stop(e) {e_preventDefault(e); e_stopPropagation(e)}
3003
 
3004
  function e_target(e) {return e.target || e.srcElement}
3005
  function e_button(e) {
3006
- var b = e.which
3007
  if (b == null) {
3008
- if (e.button & 1) { b = 1 }
3009
- else if (e.button & 2) { b = 3 }
3010
- else if (e.button & 4) { b = 2 }
3011
  }
3012
- if (mac && e.ctrlKey && b == 1) { b = 3 }
3013
  return b
3014
  }
3015
 
@@ -3018,32 +3027,32 @@ var dragAndDrop = function() {
3018
  // There is *some* kind of drag-and-drop support in IE6-8, but I
3019
  // couldn't get it to work yet.
3020
  if (ie && ie_version < 9) { return false }
3021
- var div = elt('div')
3022
  return "draggable" in div || "dragDrop" in div
3023
- }()
3024
 
3025
- var zwspSupported
3026
  function zeroWidthElement(measure) {
3027
  if (zwspSupported == null) {
3028
- var test = elt("span", "\u200b")
3029
- removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]))
3030
  if (measure.firstChild.offsetHeight != 0)
3031
- { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8) }
3032
  }
3033
  var node = zwspSupported ? elt("span", "\u200b") :
3034
- elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px")
3035
- node.setAttribute("cm-text", "")
3036
  return node
3037
  }
3038
 
3039
  // Feature-detect IE's crummy client rect reporting for bidi text
3040
- var badBidiRects
3041
  function hasBadBidiRects(measure) {
3042
  if (badBidiRects != null) { return badBidiRects }
3043
- var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"))
3044
- var r0 = range(txt, 0, 1).getBoundingClientRect()
3045
- var r1 = range(txt, 1, 2).getBoundingClientRect()
3046
- removeChildren(measure)
3047
  if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
3048
  return badBidiRects = (r1.right - r0.right < 3)
3049
  }
@@ -3051,75 +3060,77 @@ function hasBadBidiRects(measure) {
3051
  // See if "".split is the broken IE version, if so, provide an
3052
  // alternative way to split lines.
3053
  var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
3054
- var pos = 0, result = [], l = string.length
3055
  while (pos <= l) {
3056
- var nl = string.indexOf("\n", pos)
3057
- if (nl == -1) { nl = string.length }
3058
- var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl)
3059
- var rt = line.indexOf("\r")
3060
  if (rt != -1) {
3061
- result.push(line.slice(0, rt))
3062
- pos += rt + 1
3063
  } else {
3064
- result.push(line)
3065
- pos = nl + 1
3066
  }
3067
  }
3068
  return result
3069
- } : function (string) { return string.split(/\r\n?|\n/); }
3070
 
3071
  var hasSelection = window.getSelection ? function (te) {
3072
  try { return te.selectionStart != te.selectionEnd }
3073
  catch(e) { return false }
3074
  } : function (te) {
3075
- var range
3076
- try {range = te.ownerDocument.selection.createRange()}
3077
  catch(e) {}
3078
- if (!range || range.parentElement() != te) { return false }
3079
- return range.compareEndPoints("StartToEnd", range) != 0
3080
- }
3081
 
3082
  var hasCopyEvent = (function () {
3083
- var e = elt("div")
3084
  if ("oncopy" in e) { return true }
3085
- e.setAttribute("oncopy", "return;")
3086
  return typeof e.oncopy == "function"
3087
- })()
3088
 
3089
- var badZoomedRects = null
3090
  function hasBadZoomedRects(measure) {
3091
  if (badZoomedRects != null) { return badZoomedRects }
3092
- var node = removeChildrenAndAdd(measure, elt("span", "x"))
3093
- var normal = node.getBoundingClientRect()
3094
- var fromRange = range(node, 0, 1).getBoundingClientRect()
3095
  return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
3096
  }
3097
 
 
3098
  var modes = {};
3099
  var mimeModes = {};
 
3100
  // Extra arguments are stored as the mode's dependencies, which is
3101
  // used by (legacy) mechanisms like loadmode.js to automatically
3102
  // load a mode. (Preferred mechanism is the require/define calls.)
3103
  function defineMode(name, mode) {
3104
  if (arguments.length > 2)
3105
- { mode.dependencies = Array.prototype.slice.call(arguments, 2) }
3106
- modes[name] = mode
3107
  }
3108
 
3109
  function defineMIME(mime, spec) {
3110
- mimeModes[mime] = spec
3111
  }
3112
 
3113
  // Given a MIME type, a {name, ...options} config object, or a name
3114
  // string, return a mode config object.
3115
  function resolveMode(spec) {
3116
  if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
3117
- spec = mimeModes[spec]
3118
  } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
3119
- var found = mimeModes[spec.name]
3120
- if (typeof found == "string") { found = {name: found} }
3121
- spec = createObj(found, spec)
3122
- spec.name = found.name
3123
  } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
3124
  return resolveMode("application/xml")
3125
  } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
@@ -3132,42 +3143,42 @@ function resolveMode(spec) {
3132
  // Given a mode spec (anything that resolveMode accepts), find and
3133
  // initialize an actual mode object.
3134
  function getMode(options, spec) {
3135
- spec = resolveMode(spec)
3136
- var mfactory = modes[spec.name]
3137
  if (!mfactory) { return getMode(options, "text/plain") }
3138
- var modeObj = mfactory(options, spec)
3139
  if (modeExtensions.hasOwnProperty(spec.name)) {
3140
- var exts = modeExtensions[spec.name]
3141
  for (var prop in exts) {
3142
  if (!exts.hasOwnProperty(prop)) { continue }
3143
- if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop] }
3144
- modeObj[prop] = exts[prop]
3145
  }
3146
  }
3147
- modeObj.name = spec.name
3148
- if (spec.helperType) { modeObj.helperType = spec.helperType }
3149
  if (spec.modeProps) { for (var prop$1 in spec.modeProps)
3150
- { modeObj[prop$1] = spec.modeProps[prop$1] } }
3151
 
3152
  return modeObj
3153
  }
3154
 
3155
  // This can be used to attach properties to mode objects from
3156
  // outside the actual mode definition.
3157
- var modeExtensions = {}
3158
  function extendMode(mode, properties) {
3159
- var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {})
3160
- copyObj(properties, exts)
3161
  }
3162
 
3163
  function copyState(mode, state) {
3164
  if (state === true) { return state }
3165
  if (mode.copyState) { return mode.copyState(state) }
3166
- var nstate = {}
3167
  for (var n in state) {
3168
- var val = state[n]
3169
- if (val instanceof Array) { val = val.concat([]) }
3170
- nstate[n] = val
3171
  }
3172
  return nstate
3173
  }
@@ -3175,12 +3186,12 @@ function copyState(mode, state) {
3175
  // Given a mode and a state (for that mode), find the inner mode and
3176
  // state at the position that the state refers to.
3177
  function innerMode(mode, state) {
3178
- var info
3179
  while (mode.innerMode) {
3180
- info = mode.innerMode(state)
3181
  if (!info || info.mode == mode) { break }
3182
- state = info.state
3183
- mode = info.mode
3184
  }
3185
  return info || {mode: mode, state: state}
3186
  }
@@ -3195,11 +3206,11 @@ function startState(mode, a1, a2) {
3195
  // parsers more succinct.
3196
 
3197
  var StringStream = function(string, tabSize) {
3198
- this.pos = this.start = 0
3199
- this.string = string
3200
- this.tabSize = tabSize || 8
3201
- this.lastColumnPos = this.lastColumnValue = 0
3202
- this.lineStart = 0
3203
  };
3204
 
3205
  StringStream.prototype.eol = function () {return this.pos >= this.string.length};
@@ -3210,34 +3221,34 @@ StringStream.prototype.next = function () {
3210
  { return this.string.charAt(this.pos++) }
3211
  };
3212
  StringStream.prototype.eat = function (match) {
3213
- var ch = this.string.charAt(this.pos)
3214
- var ok
3215
- if (typeof match == "string") { ok = ch == match }
3216
- else { ok = ch && (match.test ? match.test(ch) : match(ch)) }
3217
  if (ok) {++this.pos; return ch}
3218
  };
3219
  StringStream.prototype.eatWhile = function (match) {
3220
- var start = this.pos
3221
  while (this.eat(match)){}
3222
  return this.pos > start
3223
  };
3224
  StringStream.prototype.eatSpace = function () {
3225
  var this$1 = this;
3226
 
3227
- var start = this.pos
3228
- while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos }
3229
  return this.pos > start
3230
  };
3231
- StringStream.prototype.skipToEnd = function () {this.pos = this.string.length};
3232
  StringStream.prototype.skipTo = function (ch) {
3233
- var found = this.string.indexOf(ch, this.pos)
3234
  if (found > -1) {this.pos = found; return true}
3235
  };
3236
- StringStream.prototype.backUp = function (n) {this.pos -= n};
3237
  StringStream.prototype.column = function () {
3238
  if (this.lastColumnPos < this.start) {
3239
- this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue)
3240
- this.lastColumnPos = this.start
3241
  }
3242
  return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
3243
  };
@@ -3247,24 +3258,24 @@ StringStream.prototype.indentation = function () {
3247
  };
3248
  StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
3249
  if (typeof pattern == "string") {
3250
- var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; }
3251
- var substr = this.string.substr(this.pos, pattern.length)
3252
  if (cased(substr) == cased(pattern)) {
3253
- if (consume !== false) { this.pos += pattern.length }
3254
  return true
3255
  }
3256
  } else {
3257
- var match = this.string.slice(this.pos).match(pattern)
3258
  if (match && match.index > 0) { return null }
3259
- if (match && consume !== false) { this.pos += match[0].length }
3260
  return match
3261
  }
3262
  };
3263
  StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
3264
  StringStream.prototype.hideFirstChars = function (n, inner) {
3265
- this.lineStart += n
3266
  try { return inner() }
3267
- finally { this.lineStart -= n }
3268
  };
3269
 
3270
  // Compute a style array (an array starting with a mode generation
@@ -3274,35 +3285,35 @@ StringStream.prototype.hideFirstChars = function (n, inner) {
3274
  function highlightLine(cm, line, state, forceToEnd) {
3275
  // A styles array always starts with a number identifying the
3276
  // mode/overlays that it is based on (for easy invalidation).
3277
- var st = [cm.state.modeGen], lineClasses = {}
3278
  // Compute the base array of styles
3279
  runMode(cm, line.text, cm.doc.mode, state, function (end, style) { return st.push(end, style); },
3280
- lineClasses, forceToEnd)
3281
 
3282
  // Run overlays, adjust style array.
3283
  var loop = function ( o ) {
3284
- var overlay = cm.state.overlays[o], i = 1, at = 0
3285
  runMode(cm, line.text, overlay.mode, true, function (end, style) {
3286
- var start = i
3287
  // Ensure there's a token end at the current position, and that i points at it
3288
  while (at < end) {
3289
- var i_end = st[i]
3290
  if (i_end > end)
3291
- { st.splice(i, 1, end, st[i+1], i_end) }
3292
- i += 2
3293
- at = Math.min(end, i_end)
3294
  }
3295
  if (!style) { return }
3296
  if (overlay.opaque) {
3297
- st.splice(start, i - start, end, "overlay " + style)
3298
- i = start + 2
3299
  } else {
3300
  for (; start < i; start += 2) {
3301
- var cur = st[start+1]
3302
- st[start+1] = (cur ? cur + " " : "") + "overlay " + style
3303
  }
3304
  }
3305
- }, lineClasses)
3306
  };
3307
 
3308
  for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
@@ -3312,30 +3323,30 @@ function highlightLine(cm, line, state, forceToEnd) {
3312
 
3313
  function getLineStyles(cm, line, updateFrontier) {
3314
  if (!line.styles || line.styles[0] != cm.state.modeGen) {
3315
- var state = getStateBefore(cm, lineNo(line))
3316
- var result = highlightLine(cm, line, line.text.length > cm.options.maxHighlightLength ? copyState(cm.doc.mode, state) : state)
3317
- line.stateAfter = state
3318
- line.styles = result.styles
3319
- if (result.classes) { line.styleClasses = result.classes }
3320
- else if (line.styleClasses) { line.styleClasses = null }
3321
- if (updateFrontier === cm.doc.frontier) { cm.doc.frontier++ }
3322
  }
3323
  return line.styles
3324
  }
3325
 
3326
  function getStateBefore(cm, n, precise) {
3327
- var doc = cm.doc, display = cm.display
3328
  if (!doc.mode.startState) { return true }
3329
- var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter
3330
- if (!state) { state = startState(doc.mode) }
3331
- else { state = copyState(doc.mode, state) }
3332
  doc.iter(pos, n, function (line) {
3333
- processLine(cm, line.text, state)
3334
- var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo
3335
- line.stateAfter = save ? copyState(doc.mode, state) : null
3336
- ++pos
3337
- })
3338
- if (precise) { doc.frontier = pos }
3339
  return state
3340
  }
3341
 
@@ -3343,27 +3354,27 @@ function getStateBefore(cm, n, precise) {
3343
  // update state, but don't save a style array. Used for lines that
3344
  // aren't currently visible.
3345
  function processLine(cm, text, state, startAt) {
3346
- var mode = cm.doc.mode
3347
- var stream = new StringStream(text, cm.options.tabSize)
3348
- stream.start = stream.pos = startAt || 0
3349
- if (text == "") { callBlankLine(mode, state) }
3350
  while (!stream.eol()) {
3351
- readToken(mode, stream, state)
3352
- stream.start = stream.pos
3353
  }
3354
  }
3355
 
3356
  function callBlankLine(mode, state) {
3357
  if (mode.blankLine) { return mode.blankLine(state) }
3358
  if (!mode.innerMode) { return }
3359
- var inner = innerMode(mode, state)
3360
  if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
3361
  }
3362
 
3363
  function readToken(mode, stream, state, inner) {
3364
  for (var i = 0; i < 10; i++) {
3365
- if (inner) { inner[0] = innerMode(mode, state).mode }
3366
- var style = mode.token(stream, state)
3367
  if (stream.pos > stream.start) { return style }
3368
  }
3369
  throw new Error("Mode " + mode.name + " failed to advance stream.")
@@ -3376,72 +3387,72 @@ function takeToken(cm, pos, precise, asArray) {
3376
  string: stream.current(),
3377
  type: style || null,
3378
  state: copy ? copyState(doc.mode, state) : state
3379
- }); }
3380
 
3381
- var doc = cm.doc, mode = doc.mode, style
3382
- pos = clipPos(doc, pos)
3383
- var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise)
3384
- var stream = new StringStream(line.text, cm.options.tabSize), tokens
3385
- if (asArray) { tokens = [] }
3386
  while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
3387
- stream.start = stream.pos
3388
- style = readToken(mode, stream, state)
3389
- if (asArray) { tokens.push(getObj(true)) }
3390
  }
3391
  return asArray ? tokens : getObj()
3392
  }
3393
 
3394
  function extractLineClasses(type, output) {
3395
  if (type) { for (;;) {
3396
- var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/)
3397
  if (!lineClass) { break }
3398
- type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length)
3399
- var prop = lineClass[1] ? "bgClass" : "textClass"
3400
  if (output[prop] == null)
3401
- { output[prop] = lineClass[2] }
3402
  else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
3403
- { output[prop] += " " + lineClass[2] }
3404
  } }
3405
  return type
3406
  }
3407
 
3408
  // Run the given mode's parser over a line, calling f for each token.
3409
  function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
3410
- var flattenSpans = mode.flattenSpans
3411
- if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans }
3412
- var curStart = 0, curStyle = null
3413
- var stream = new StringStream(text, cm.options.tabSize), style
3414
- var inner = cm.options.addModeClass && [null]
3415
- if (text == "") { extractLineClasses(callBlankLine(mode, state), lineClasses) }
3416
  while (!stream.eol()) {
3417
  if (stream.pos > cm.options.maxHighlightLength) {
3418
- flattenSpans = false
3419
- if (forceToEnd) { processLine(cm, text, state, stream.pos) }
3420
- stream.pos = text.length
3421
- style = null
3422
  } else {
3423
- style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses)
3424
  }
3425
  if (inner) {
3426
- var mName = inner[0].name
3427
- if (mName) { style = "m-" + (style ? mName + " " + style : mName) }
3428
  }
3429
  if (!flattenSpans || curStyle != style) {
3430
  while (curStart < stream.start) {
3431
- curStart = Math.min(stream.start, curStart + 5000)
3432
- f(curStart, curStyle)
3433
  }
3434
- curStyle = style
3435
  }
3436
- stream.start = stream.pos
3437
  }
3438
  while (curStart < stream.pos) {
3439
  // Webkit seems to refuse to render text nodes longer than 57444
3440
  // characters, and returns inaccurate measurements in nodes
3441
  // starting around 5000 chars.
3442
- var pos = Math.min(stream.pos, curStart + 5000)
3443
- f(pos, curStyle)
3444
- curStart = pos
3445
  }
3446
  }
3447
 
@@ -3451,16 +3462,16 @@ function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
3451
  // smallest indentation, which tends to need the least context to
3452
  // parse correctly.
3453
  function findStartLine(cm, n, precise) {
3454
- var minindent, minline, doc = cm.doc
3455
- var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100)
3456
  for (var search = n; search > lim; --search) {
3457
  if (search <= doc.first) { return doc.first }
3458
- var line = getLine(doc, search - 1)
3459
  if (line.stateAfter && (!precise || search <= doc.frontier)) { return search }
3460
- var indented = countColumn(line.text, null, cm.options.tabSize)
3461
  if (minline == null || minindent > indented) {
3462
- minline = search - 1
3463
- minindent = indented
3464
  }
3465
  }
3466
  return minline
@@ -3471,32 +3482,32 @@ function findStartLine(cm, n, precise) {
3471
  // Line objects. These hold state related to a line, including
3472
  // highlighting info (the styles array).
3473
  var Line = function(text, markedSpans, estimateHeight) {
3474
- this.text = text
3475
- attachMarkedSpans(this, markedSpans)
3476
- this.height = estimateHeight ? estimateHeight(this) : 1
3477
  };
3478
 
3479
  Line.prototype.lineNo = function () { return lineNo(this) };
3480
- eventMixin(Line)
3481
 
3482
  // Change the content (text, markers) of a line. Automatically
3483
  // invalidates cached information and tries to re-estimate the
3484
  // line's height.
3485
  function updateLine(line, text, markedSpans, estimateHeight) {
3486
- line.text = text
3487
- if (line.stateAfter) { line.stateAfter = null }
3488
- if (line.styles) { line.styles = null }
3489
- if (line.order != null) { line.order = null }
3490
- detachMarkedSpans(line)
3491
- attachMarkedSpans(line, markedSpans)
3492
- var estHeight = estimateHeight ? estimateHeight(line) : 1
3493
- if (estHeight != line.height) { updateLineHeight(line, estHeight) }
3494
  }
3495
 
3496
  // Detach a line from the document tree and its markers.
3497
  function cleanUpLine(line) {
3498
- line.parent = null
3499
- detachMarkedSpans(line)
3500
  }
3501
 
3502
  // Convert a style as returned by a mode (either null, or a string
@@ -3506,7 +3517,7 @@ var styleToClassCache = {};
3506
  var styleToClassCacheWithMode = {};
3507
  function interpretTokenStyle(style, options) {
3508
  if (!style || /^\s*$/.test(style)) { return null }
3509
- var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache
3510
  return cache[style] ||
3511
  (cache[style] = style.replace(/\S+/g, "cm-$&"))
3512
  }
@@ -3520,67 +3531,64 @@ function buildLineContent(cm, lineView) {
3520
  // The padding-right forces the element to have a 'border', which
3521
  // is needed on Webkit to be able to get line-level bounding
3522
  // rectangles for it (in measureChar).
3523
- var content = elt("span", null, null, webkit ? "padding-right: .1px" : null)
3524
- var builder = {pre: elt("pre", [content], "CodeMirror-line"), content: content,
3525
  col: 0, pos: 0, cm: cm,
3526
  trailingSpace: false,
3527
- splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")}
3528
- // hide from accessibility tree
3529
- content.setAttribute("role", "presentation")
3530
- builder.pre.setAttribute("role", "presentation")
3531
- lineView.measure = {}
3532
 
3533
  // Iterate over the logical lines that make up this visual line.
3534
  for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
3535
- var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0)
3536
- builder.pos = 0
3537
- builder.addToken = buildToken
3538
  // Optionally wire in some hacks into the token-rendering
3539
  // algorithm, to deal with browser quirks.
3540
- if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
3541
- { builder.addToken = buildTokenBadBidi(builder.addToken, order) }
3542
- builder.map = []
3543
- var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line)
3544
- insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate))
3545
  if (line.styleClasses) {
3546
  if (line.styleClasses.bgClass)
3547
- { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "") }
3548
  if (line.styleClasses.textClass)
3549
- { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "") }
3550
  }
3551
 
3552
  // Ensure at least a single node is present, for measuring.
3553
  if (builder.map.length == 0)
3554
- { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))) }
3555
 
3556
  // Store the map and a cache object for the current logical line
3557
  if (i == 0) {
3558
- lineView.measure.map = builder.map
3559
- lineView.measure.cache = {}
3560
  } else {
3561
- ;(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
3562
- ;(lineView.measure.caches || (lineView.measure.caches = [])).push({})
3563
  }
3564
  }
3565
 
3566
  // See issue #2901
3567
  if (webkit) {
3568
- var last = builder.content.lastChild
3569
  if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
3570
- { builder.content.className = "cm-tab-wrap-hack" }
3571
  }
3572
 
3573
- signal(cm, "renderLine", cm, lineView.line, builder.pre)
3574
  if (builder.pre.className)
3575
- { builder.textClass = joinClasses(builder.pre.className, builder.textClass || "") }
3576
 
3577
  return builder
3578
  }
3579
 
3580
  function defaultSpecialCharPlaceholder(ch) {
3581
- var token = elt("span", "\u2022", "cm-invalidchar")
3582
- token.title = "\\u" + ch.charCodeAt(0).toString(16)
3583
- token.setAttribute("aria-label", token.title)
3584
  return token
3585
  }
3586
 
@@ -3588,75 +3596,75 @@ function defaultSpecialCharPlaceholder(ch) {
3588
  // the line map. Takes care to render special characters separately.
3589
  function buildToken(builder, text, style, startStyle, endStyle, title, css) {
3590
  if (!text) { return }
3591
- var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
3592
- var special = builder.cm.state.specialChars, mustWrap = false
3593
- var content
3594
  if (!special.test(text)) {
3595
- builder.col += text.length
3596
- content = document.createTextNode(displayText)
3597
- builder.map.push(builder.pos, builder.pos + text.length, content)
3598
- if (ie && ie_version < 9) { mustWrap = true }
3599
- builder.pos += text.length
3600
  } else {
3601
- content = document.createDocumentFragment()
3602
- var pos = 0
3603
  while (true) {
3604
- special.lastIndex = pos
3605
- var m = special.exec(text)
3606
- var skipped = m ? m.index - pos : text.length - pos
3607
  if (skipped) {
3608
- var txt = document.createTextNode(displayText.slice(pos, pos + skipped))
3609
- if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])) }
3610
- else { content.appendChild(txt) }
3611
- builder.map.push(builder.pos, builder.pos + skipped, txt)
3612
- builder.col += skipped
3613
- builder.pos += skipped
3614
  }
3615
  if (!m) { break }
3616
- pos += skipped + 1
3617
- var txt$1 = (void 0)
3618
  if (m[0] == "\t") {
3619
- var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize
3620
- txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"))
3621
- txt$1.setAttribute("role", "presentation")
3622
- txt$1.setAttribute("cm-text", "\t")
3623
- builder.col += tabWidth
3624
  } else if (m[0] == "\r" || m[0] == "\n") {
3625
- txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"))
3626
- txt$1.setAttribute("cm-text", m[0])
3627
- builder.col += 1
3628
  } else {
3629
- txt$1 = builder.cm.options.specialCharPlaceholder(m[0])
3630
- txt$1.setAttribute("cm-text", m[0])
3631
- if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])) }
3632
- else { content.appendChild(txt$1) }
3633
- builder.col += 1
3634
  }
3635
- builder.map.push(builder.pos, builder.pos + 1, txt$1)
3636
- builder.pos++
3637
  }
3638
  }
3639
- builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32
3640
  if (style || startStyle || endStyle || mustWrap || css) {
3641
- var fullStyle = style || ""
3642
- if (startStyle) { fullStyle += startStyle }
3643
- if (endStyle) { fullStyle += endStyle }
3644
- var token = elt("span", [content], fullStyle, css)
3645
- if (title) { token.title = title }
3646
  return builder.content.appendChild(token)
3647
  }
3648
- builder.content.appendChild(content)
3649
  }
3650
 
3651
  function splitSpaces(text, trailingBefore) {
3652
  if (text.length > 1 && !/ /.test(text)) { return text }
3653
- var spaceBefore = trailingBefore, result = ""
3654
  for (var i = 0; i < text.length; i++) {
3655
- var ch = text.charAt(i)
3656
  if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
3657
- { ch = "\u00a0" }
3658
- result += ch
3659
- spaceBefore = ch == " "
3660
  }
3661
  return result
3662
  }
@@ -3665,106 +3673,106 @@ function splitSpaces(text, trailingBefore) {
3665
  // right-to-left text.
3666
  function buildTokenBadBidi(inner, order) {
3667
  return function (builder, text, style, startStyle, endStyle, title, css) {
3668
- style = style ? style + " cm-force-border" : "cm-force-border"
3669
- var start = builder.pos, end = start + text.length
3670
  for (;;) {
3671
  // Find the part that overlaps with the start of this text
3672
- var part = (void 0)
3673
  for (var i = 0; i < order.length; i++) {
3674
- part = order[i]
3675
  if (part.to > start && part.from <= start) { break }
3676
  }
3677
  if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, title, css) }
3678
- inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css)
3679
- startStyle = null
3680
- text = text.slice(part.to - start)
3681
- start = part.to
3682
  }
3683
  }
3684
  }
3685
 
3686
  function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
3687
- var widget = !ignoreWidget && marker.widgetNode
3688
- if (widget) { builder.map.push(builder.pos, builder.pos + size, widget) }
3689
  if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
3690
  if (!widget)
3691
- { widget = builder.content.appendChild(document.createElement("span")) }
3692
- widget.setAttribute("cm-marker", marker.id)
3693
  }
3694
  if (widget) {
3695
- builder.cm.display.input.setUneditable(widget)
3696
- builder.content.appendChild(widget)
3697
  }
3698
- builder.pos += size
3699
- builder.trailingSpace = false
3700
  }
3701
 
3702
  // Outputs a number of spans to make up a line, taking highlighting
3703
  // and marked text into account.
3704
  function insertLineContent(line, builder, styles) {
3705
- var spans = line.markedSpans, allText = line.text, at = 0
3706
  if (!spans) {
3707
  for (var i$1 = 1; i$1 < styles.length; i$1+=2)
3708
- { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)) }
3709
  return
3710
  }
3711
 
3712
- var len = allText.length, pos = 0, i = 1, text = "", style, css
3713
- var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed
3714
  for (;;) {
3715
  if (nextChange == pos) { // Update current marker set
3716
- spanStyle = spanEndStyle = spanStartStyle = title = css = ""
3717
- collapsed = null; nextChange = Infinity
3718
- var foundBookmarks = [], endStyles = (void 0)
3719
  for (var j = 0; j < spans.length; ++j) {
3720
- var sp = spans[j], m = sp.marker
3721
  if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
3722
- foundBookmarks.push(m)
3723
  } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
3724
  if (sp.to != null && sp.to != pos && nextChange > sp.to) {
3725
- nextChange = sp.to
3726
- spanEndStyle = ""
3727
  }
3728
- if (m.className) { spanStyle += " " + m.className }
3729
- if (m.css) { css = (css ? css + ";" : "") + m.css }
3730
- if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle }
3731
- if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to) }
3732
- if (m.title && !title) { title = m.title }
3733
  if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
3734
- { collapsed = sp }
3735
  } else if (sp.from > pos && nextChange > sp.from) {
3736
- nextChange = sp.from
3737
  }
3738
  }
3739
  if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
3740
- { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1] } } }
3741
 
3742
  if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
3743
- { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]) } }
3744
  if (collapsed && (collapsed.from || 0) == pos) {
3745
  buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
3746
- collapsed.marker, collapsed.from == null)
3747
  if (collapsed.to == null) { return }
3748
- if (collapsed.to == pos) { collapsed = false }
3749
  }
3750
  }
3751
  if (pos >= len) { break }
3752
 
3753
- var upto = Math.min(len, nextChange)
3754
  while (true) {
3755
  if (text) {
3756
- var end = pos + text.length
3757
  if (!collapsed) {
3758
- var tokenText = end > upto ? text.slice(0, upto - pos) : text
3759
  builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
3760
- spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css)
3761
  }
3762
  if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
3763
- pos = end
3764
- spanStartStyle = ""
3765
  }
3766
- text = allText.slice(at, at = styles[i++])
3767
- style = interpretTokenStyle(styles[i++], builder.cm.options)
3768
  }
3769
  }
3770
  }
@@ -3775,67 +3783,67 @@ function insertLineContent(line, builder, styles) {
3775
  // logical lines, if those are connected by collapsed ranges.
3776
  function LineView(doc, line, lineN) {
3777
  // The starting line
3778
- this.line = line
3779
  // Continuing lines, if any
3780
- this.rest = visualLineContinued(line)
3781
  // Number of logical lines in this visual line
3782
- this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1
3783
- this.node = this.text = null
3784
- this.hidden = lineIsHidden(doc, line)
3785
  }
3786
 
3787
  // Create a range of LineView objects for the given lines.
3788
  function buildViewArray(cm, from, to) {
3789
- var array = [], nextPos
3790
  for (var pos = from; pos < to; pos = nextPos) {
3791
- var view = new LineView(cm.doc, getLine(cm.doc, pos), pos)
3792
- nextPos = pos + view.size
3793
- array.push(view)
3794
  }
3795
  return array
3796
  }
3797
 
3798
- var operationGroup = null
3799
 
3800
  function pushOperation(op) {
3801
  if (operationGroup) {
3802
- operationGroup.ops.push(op)
3803
  } else {
3804
  op.ownsGroup = operationGroup = {
3805
  ops: [op],
3806
  delayedCallbacks: []
3807
- }
3808
  }
3809
  }
3810
 
3811
  function fireCallbacksForOps(group) {
3812
  // Calls delayed callbacks and cursorActivity handlers until no
3813
  // new ones appear
3814
- var callbacks = group.delayedCallbacks, i = 0
3815
  do {
3816
  for (; i < callbacks.length; i++)
3817
- { callbacks[i].call(null) }
3818
  for (var j = 0; j < group.ops.length; j++) {
3819
- var op = group.ops[j]
3820
  if (op.cursorActivityHandlers)
3821
  { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
3822
- { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm) } }
3823
  }
3824
  } while (i < callbacks.length)
3825
  }
3826
 
3827
  function finishOperation(op, endCb) {
3828
- var group = op.ownsGroup
3829
  if (!group) { return }
3830
 
3831
- try { fireCallbacksForOps(group) }
3832
  finally {
3833
- operationGroup = null
3834
- endCb(group)
3835
  }
3836
  }
3837
 
3838
- var orphanDelayedCallbacks = null
3839
 
3840
  // Often, we want to signal events at a point where we are in the
3841
  // middle of some work, but don't want the handler to start calling
@@ -3845,19 +3853,19 @@ var orphanDelayedCallbacks = null
3845
  // them to be executed when the last operation ends, or, if no
3846
  // operation is active, when a timeout fires.
3847
  function signalLater(emitter, type /*, values...*/) {
3848
- var arr = getHandlers(emitter, type)
3849
  if (!arr.length) { return }
3850
- var args = Array.prototype.slice.call(arguments, 2), list
3851
  if (operationGroup) {
3852
- list = operationGroup.delayedCallbacks
3853
  } else if (orphanDelayedCallbacks) {
3854
- list = orphanDelayedCallbacks
3855
  } else {
3856
- list = orphanDelayedCallbacks = []
3857
- setTimeout(fireOrphanDelayed, 0)
3858
  }
3859
  var loop = function ( i ) {
3860
- list.push(function () { return arr[i].apply(null, args); })
3861
  };
3862
 
3863
  for (var i = 0; i < arr.length; ++i)
@@ -3865,9 +3873,9 @@ function signalLater(emitter, type /*, values...*/) {
3865
  }
3866
 
3867
  function fireOrphanDelayed() {
3868
- var delayed = orphanDelayedCallbacks
3869
- orphanDelayedCallbacks = null
3870
- for (var i = 0; i < delayed.length; ++i) { delayed[i]() }
3871
  }
3872
 
3873
  // When an aspect of a line changes, a string is added to
@@ -3875,47 +3883,48 @@ function fireOrphanDelayed() {
3875
  // DOM structure.
3876
  function updateLineForChanges(cm, lineView, lineN, dims) {
3877
  for (var j = 0; j < lineView.changes.length; j++) {
3878
- var type = lineView.changes[j]
3879
- if (type == "text") { updateLineText(cm, lineView) }
3880
- else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims) }
3881
- else if (type == "class") { updateLineClasses(lineView) }
3882
- else if (type == "widget") { updateLineWidgets(cm, lineView, dims) }
3883
  }
3884
- lineView.changes = null
3885
  }
3886
 
3887
  // Lines with gutter elements, widgets or a background class need to
3888
  // be wrapped, and have the extra elements added to the wrapper div
3889
  function ensureLineWrapped(lineView) {
3890
  if (lineView.node == lineView.text) {
3891
- lineView.node = elt("div", null, null, "position: relative")
3892
  if (lineView.text.parentNode)
3893
- { lineView.text.parentNode.replaceChild(lineView.node, lineView.text) }
3894
- lineView.node.appendChild(lineView.text)
3895
- if (ie && ie_version < 8) { lineView.node.style.zIndex = 2 }
3896
  }
3897
  return lineView.node
3898
  }
3899
 
3900
- function updateLineBackground(lineView) {
3901
- var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass
3902
- if (cls) { cls += " CodeMirror-linebackground" }
3903
  if (lineView.background) {
3904
- if (cls) { lineView.background.className = cls }
3905
- else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null }
3906
  } else if (cls) {
3907
- var wrap = ensureLineWrapped(lineView)
3908
- lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild)
 
3909
  }
3910
  }
3911
 
3912
  // Wrapper around buildLineContent which will reuse the structure
3913
  // in display.externalMeasured when possible.
3914
  function getLineContent(cm, lineView) {
3915
- var ext = cm.display.externalMeasured
3916
  if (ext && ext.line == lineView.line) {
3917
- cm.display.externalMeasured = null
3918
- lineView.measure = ext.measure
3919
  return ext.built
3920
  }
3921
  return buildLineContent(cm, lineView)
@@ -3925,143 +3934,144 @@ function getLineContent(cm, lineView) {
3925
  // classes because the mode may output tokens that influence these
3926
  // classes.
3927
  function updateLineText(cm, lineView) {
3928
- var cls = lineView.text.className
3929
- var built = getLineContent(cm, lineView)
3930
- if (lineView.text == lineView.node) { lineView.node = built.pre }
3931
- lineView.text.parentNode.replaceChild(built.pre, lineView.text)
3932
- lineView.text = built.pre
3933
  if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
3934
- lineView.bgClass = built.bgClass
3935
- lineView.textClass = built.textClass
3936
- updateLineClasses(lineView)
3937
  } else if (cls) {
3938
- lineView.text.className = cls
3939
  }
3940
  }
3941
 
3942
- function updateLineClasses(lineView) {
3943
- updateLineBackground(lineView)
3944
  if (lineView.line.wrapClass)
3945
- { ensureLineWrapped(lineView).className = lineView.line.wrapClass }
3946
  else if (lineView.node != lineView.text)
3947
- { lineView.node.className = "" }
3948
- var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass
3949
- lineView.text.className = textClass || ""
3950
  }
3951
 
3952
  function updateLineGutter(cm, lineView, lineN, dims) {
3953
  if (lineView.gutter) {
3954
- lineView.node.removeChild(lineView.gutter)
3955
- lineView.gutter = null
3956
  }
3957
  if (lineView.gutterBackground) {
3958
- lineView.node.removeChild(lineView.gutterBackground)
3959
- lineView.gutterBackground = null
3960
  }
3961
  if (lineView.line.gutterClass) {
3962
- var wrap = ensureLineWrapped(lineView)
3963
  lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
3964
- ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"))
3965
- wrap.insertBefore(lineView.gutterBackground, lineView.text)
 
3966
  }
3967
- var markers = lineView.line.gutterMarkers
3968
  if (cm.options.lineNumbers || markers) {
3969
- var wrap$1 = ensureLineWrapped(lineView)
3970
- var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"))
3971
- cm.display.input.setUneditable(gutterWrap)
3972
- wrap$1.insertBefore(gutterWrap, lineView.text)
3973
  if (lineView.line.gutterClass)
3974
- { gutterWrap.className += " " + lineView.line.gutterClass }
3975
  if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
3976
  { lineView.lineNumber = gutterWrap.appendChild(
3977
  elt("div", lineNumberFor(cm.options, lineN),
3978
  "CodeMirror-linenumber CodeMirror-gutter-elt",
3979
- ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))) }
3980
  if (markers) { for (var k = 0; k < cm.options.gutters.length; ++k) {
3981
- var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id]
3982
  if (found)
3983
  { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
3984
- ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))) }
3985
  } }
3986
  }
3987
  }
3988
 
3989
  function updateLineWidgets(cm, lineView, dims) {
3990
- if (lineView.alignable) { lineView.alignable = null }
3991
  for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
3992
- next = node.nextSibling
3993
  if (node.className == "CodeMirror-linewidget")
3994
- { lineView.node.removeChild(node) }
3995
  }
3996
- insertLineWidgets(cm, lineView, dims)
3997
  }
3998
 
3999
  // Build a line's DOM representation from scratch
4000
  function buildLineElement(cm, lineView, lineN, dims) {
4001
- var built = getLineContent(cm, lineView)
4002
- lineView.text = lineView.node = built.pre
4003
- if (built.bgClass) { lineView.bgClass = built.bgClass }
4004
- if (built.textClass) { lineView.textClass = built.textClass }
4005
-
4006
- updateLineClasses(lineView)
4007
- updateLineGutter(cm, lineView, lineN, dims)
4008
- insertLineWidgets(cm, lineView, dims)
4009
  return lineView.node
4010
  }
4011
 
4012
  // A lineView may contain multiple logical lines (when merged by
4013
  // collapsed spans). The widgets for all of them need to be drawn.
4014
  function insertLineWidgets(cm, lineView, dims) {
4015
- insertLineWidgetsFor(cm, lineView.line, lineView, dims, true)
4016
  if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
4017
- { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false) } }
4018
  }
4019
 
4020
  function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
4021
  if (!line.widgets) { return }
4022
- var wrap = ensureLineWrapped(lineView)
4023
  for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
4024
- var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget")
4025
- if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true") }
4026
- positionLineWidget(widget, node, lineView, dims)
4027
- cm.display.input.setUneditable(node)
4028
  if (allowAbove && widget.above)
4029
- { wrap.insertBefore(node, lineView.gutter || lineView.text) }
4030
  else
4031
- { wrap.appendChild(node) }
4032
- signalLater(widget, "redraw")
4033
  }
4034
  }
4035
 
4036
  function positionLineWidget(widget, node, lineView, dims) {
4037
  if (widget.noHScroll) {
4038
- ;(lineView.alignable || (lineView.alignable = [])).push(node)
4039
- var width = dims.wrapperWidth
4040
- node.style.left = dims.fixedPos + "px"
4041
  if (!widget.coverGutter) {
4042
- width -= dims.gutterTotalWidth
4043
- node.style.paddingLeft = dims.gutterTotalWidth + "px"
4044
  }
4045
- node.style.width = width + "px"
4046
  }
4047
  if (widget.coverGutter) {
4048
- node.style.zIndex = 5
4049
- node.style.position = "relative"
4050
- if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px" }
4051
  }
4052
  }
4053
 
4054
  function widgetHeight(widget) {
4055
  if (widget.height != null) { return widget.height }
4056
- var cm = widget.doc.cm
4057
  if (!cm) { return 0 }
4058
  if (!contains(document.body, widget.node)) {
4059
- var parentStyle = "position: relative;"
4060
  if (widget.coverGutter)
4061
- { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;" }
4062
  if (widget.noHScroll)
4063
- { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;" }
4064
- removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle))
4065
  }
4066
  return widget.height = widget.node.parentNode.offsetHeight
4067
  }
@@ -4081,10 +4091,10 @@ function paddingTop(display) {return display.lineSpace.offsetTop}
4081
  function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
4082
  function paddingH(display) {
4083
  if (display.cachedPaddingH) { return display.cachedPaddingH }
4084
- var e = removeChildrenAndAdd(display.measure, elt("pre", "x"))
4085
- var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle
4086
- var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)}
4087
- if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data }
4088
  return data
4089
  }
4090
 
@@ -4101,20 +4111,20 @@ function displayHeight(cm) {
4101
  // line. When lineWrapping is on, there might be more than one
4102
  // height.
4103
  function ensureLineHeights(cm, lineView, rect) {
4104
- var wrapping = cm.options.lineWrapping
4105
- var curWidth = wrapping && displayWidth(cm)
4106
  if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
4107
- var heights = lineView.measure.heights = []
4108
  if (wrapping) {
4109
- lineView.measure.width = curWidth
4110
- var rects = lineView.text.firstChild.getClientRects()
4111
  for (var i = 0; i < rects.length - 1; i++) {
4112
- var cur = rects[i], next = rects[i + 1]
4113
  if (Math.abs(cur.bottom - next.bottom) > 2)
4114
- { heights.push((cur.bottom + next.top) / 2 - rect.top) }
4115
  }
4116
  }
4117
- heights.push(rect.bottom - rect.top)
4118
  }
4119
  }
4120
 
@@ -4135,13 +4145,13 @@ function mapFromLineView(lineView, line, lineN) {
4135
  // Render a line into the hidden node display.externalMeasured. Used
4136
  // when measurement is needed for a line that's not in the viewport.
4137
  function updateExternalMeasurement(cm, line) {
4138
- line = visualLine(line)
4139
- var lineN = lineNo(line)
4140
- var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN)
4141
- view.lineN = lineN
4142
- var built = view.built = buildLineContent(cm, view)
4143
- view.text = built.pre
4144
- removeChildrenAndAdd(cm.display.lineMeasure, built.pre)
4145
  return view
4146
  }
4147
 
@@ -4155,7 +4165,7 @@ function measureChar(cm, line, ch, bias) {
4155
  function findViewForLine(cm, lineN) {
4156
  if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
4157
  { return cm.display.view[findViewIndex(cm, lineN)] }
4158
- var ext = cm.display.externalMeasured
4159
  if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
4160
  { return ext }
4161
  }
@@ -4166,18 +4176,18 @@ function findViewForLine(cm, lineN) {
4166
  // measurements in a row, can thus ensure that the set-up work is
4167
  // only done once.
4168
  function prepareMeasureForLine(cm, line) {
4169
- var lineN = lineNo(line)
4170
- var view = findViewForLine(cm, lineN)
4171
  if (view && !view.text) {
4172
- view = null
4173
  } else if (view && view.changes) {
4174
- updateLineForChanges(cm, view, lineN, getDimensions(cm))
4175
- cm.curOp.forceUpdate = true
4176
  }
4177
  if (!view)
4178
- { view = updateExternalMeasurement(cm, line) }
4179
 
4180
- var info = mapFromLineView(view, line, lineN)
4181
  return {
4182
  line: line, view: view, rect: null,
4183
  map: info.map, cache: info.cache, before: info.before,
@@ -4188,58 +4198,58 @@ function prepareMeasureForLine(cm, line) {
4188
  // Given a prepared measurement object, measures the position of an
4189
  // actual character (or fetches it from the cache).
4190
  function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
4191
- if (prepared.before) { ch = -1 }
4192
- var key = ch + (bias || ""), found
4193
  if (prepared.cache.hasOwnProperty(key)) {
4194
- found = prepared.cache[key]
4195
  } else {
4196
  if (!prepared.rect)
4197
- { prepared.rect = prepared.view.text.getBoundingClientRect() }
4198
  if (!prepared.hasHeights) {
4199
- ensureLineHeights(cm, prepared.view, prepared.rect)
4200
- prepared.hasHeights = true
4201
  }
4202
- found = measureCharInner(cm, prepared, ch, bias)
4203
- if (!found.bogus) { prepared.cache[key] = found }
4204
  }
4205
  return {left: found.left, right: found.right,
4206
  top: varHeight ? found.rtop : found.top,
4207
  bottom: varHeight ? found.rbottom : found.bottom}
4208
  }
4209
 
4210
- var nullRect = {left: 0, right: 0, top: 0, bottom: 0}
4211
 
4212
- function nodeAndOffsetInLineMap(map, ch, bias) {
4213
- var node, start, end, collapse, mStart, mEnd
4214
  // First, search the line map for the text node corresponding to,
4215
  // or closest to, the target character.
4216
- for (var i = 0; i < map.length; i += 3) {
4217
- mStart = map[i]
4218
- mEnd = map[i + 1]
4219
  if (ch < mStart) {
4220
- start = 0; end = 1
4221
- collapse = "left"
4222
  } else if (ch < mEnd) {
4223
- start = ch - mStart
4224
- end = start + 1
4225
- } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
4226
- end = mEnd - mStart
4227
- start = end - 1
4228
- if (ch >= mEnd) { collapse = "right" }
4229
  }
4230
  if (start != null) {
4231
- node = map[i + 2]
4232
  if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
4233
- { collapse = bias }
4234
  if (bias == "left" && start == 0)
4235
- { while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
4236
- node = map[(i -= 3) + 2]
4237
- collapse = "left"
4238
  } }
4239
  if (bias == "right" && start == mEnd - mStart)
4240
- { while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
4241
- node = map[(i += 3) + 2]
4242
- collapse = "right"
4243
  } }
4244
  break
4245
  }
@@ -4248,7 +4258,7 @@ function nodeAndOffsetInLineMap(map, ch, bias) {
4248
  }
4249
 
4250
  function getUsefulRect(rects, bias) {
4251
- var rect = nullRect
4252
  if (bias == "left") { for (var i = 0; i < rects.length; i++) {
4253
  if ((rect = rects[i]).left != rect.right) { break }
4254
  } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
@@ -4258,52 +4268,52 @@ function getUsefulRect(rects, bias) {
4258
  }
4259
 
4260
  function measureCharInner(cm, prepared, ch, bias) {
4261
- var place = nodeAndOffsetInLineMap(prepared.map, ch, bias)
4262
- var node = place.node, start = place.start, end = place.end, collapse = place.collapse
4263
 
4264
- var rect
4265
  if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
4266
  for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
4267
- while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start }
4268
- while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end }
4269
  if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
4270
- { rect = node.parentNode.getBoundingClientRect() }
4271
  else
4272
- { rect = getUsefulRect(range(node, start, end).getClientRects(), bias) }
4273
  if (rect.left || rect.right || start == 0) { break }
4274
- end = start
4275
- start = start - 1
4276
- collapse = "right"
4277
  }
4278
- if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect) }
4279
  } else { // If it is a widget, simply get the box for the whole widget.
4280
- if (start > 0) { collapse = bias = "right" }
4281
- var rects
4282
  if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
4283
- { rect = rects[bias == "right" ? rects.length - 1 : 0] }
4284
  else
4285
- { rect = node.getBoundingClientRect() }
4286
  }
4287
  if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
4288
- var rSpan = node.parentNode.getClientRects()[0]
4289
  if (rSpan)
4290
- { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom} }
4291
  else
4292
- { rect = nullRect }
4293
  }
4294
 
4295
- var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top
4296
- var mid = (rtop + rbot) / 2
4297
- var heights = prepared.view.measure.heights
4298
- var i = 0
4299
  for (; i < heights.length - 1; i++)
4300
  { if (mid < heights[i]) { break } }
4301
- var top = i ? heights[i - 1] : 0, bot = heights[i]
4302
  var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
4303
  right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
4304
- top: top, bottom: bot}
4305
- if (!rect.left && !rect.right) { result.bogus = true }
4306
- if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot }
4307
 
4308
  return result
4309
  }
@@ -4314,33 +4324,33 @@ function maybeUpdateRectForZooming(measure, rect) {
4314
  if (!window.screen || screen.logicalXDPI == null ||
4315
  screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
4316
  { return rect }
4317
- var scaleX = screen.logicalXDPI / screen.deviceXDPI
4318
- var scaleY = screen.logicalYDPI / screen.deviceYDPI
4319
  return {left: rect.left * scaleX, right: rect.right * scaleX,
4320
  top: rect.top * scaleY, bottom: rect.bottom * scaleY}
4321
  }
4322
 
4323
  function clearLineMeasurementCacheFor(lineView) {
4324
  if (lineView.measure) {
4325
- lineView.measure.cache = {}
4326
- lineView.measure.heights = null
4327
  if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
4328
- { lineView.measure.caches[i] = {} } }
4329
  }
4330
  }
4331
 
4332
  function clearLineMeasurementCache(cm) {
4333
- cm.display.externalMeasure = null
4334
- removeChildren(cm.display.lineMeasure)
4335
  for (var i = 0; i < cm.display.view.length; i++)
4336
- { clearLineMeasurementCacheFor(cm.display.view[i]) }
4337
  }
4338
 
4339
  function clearCaches(cm) {
4340
- clearLineMeasurementCache(cm)
4341
- cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null
4342
- if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true }
4343
- cm.display.lineNumChars = null
4344
  }
4345
 
4346
  function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft }
@@ -4352,21 +4362,21 @@ function pageScrollY() { return window.pageYOffset || (document.documentElement
4352
  // or "page".
4353
  function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
4354
  if (!includeWidgets && lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above) {
4355
- var size = widgetHeight(lineObj.widgets[i])
4356
- rect.top += size; rect.bottom += size
4357
  } } }
4358
  if (context == "line") { return rect }
4359
- if (!context) { context = "local" }
4360
- var yOff = heightAtLine(lineObj)
4361
- if (context == "local") { yOff += paddingTop(cm.display) }
4362
- else { yOff -= cm.display.viewOffset }
4363
  if (context == "page" || context == "window") {
4364
- var lOff = cm.display.lineSpace.getBoundingClientRect()
4365
- yOff += lOff.top + (context == "window" ? 0 : pageScrollY())
4366
- var xOff = lOff.left + (context == "window" ? 0 : pageScrollX())
4367
- rect.left += xOff; rect.right += xOff
4368
  }
4369
- rect.top += yOff; rect.bottom += yOff
4370
  return rect
4371
  }
4372
 
@@ -4374,23 +4384,23 @@ function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
4374
  // Context may be "window", "page", "div", or "local"./null.
4375
  function fromCoordSystem(cm, coords, context) {
4376
  if (context == "div") { return coords }
4377
- var left = coords.left, top = coords.top
4378
  // First move into "page" coordinate system
4379
  if (context == "page") {
4380
- left -= pageScrollX()
4381
- top -= pageScrollY()
4382
  } else if (context == "local" || !context) {
4383
- var localBox = cm.display.sizer.getBoundingClientRect()
4384
- left += localBox.left
4385
- top += localBox.top
4386
  }
4387
 
4388
- var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect()
4389
  return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
4390
  }
4391
 
4392
  function charCoords(cm, pos, context, lineObj, bias) {
4393
- if (!lineObj) { lineObj = getLine(cm.doc, pos.line) }
4394
  return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
4395
  }
4396
 
@@ -4411,42 +4421,42 @@ function charCoords(cm, pos, context, lineObj, bias) {
4411
  // Every position after the last character on a line is considered to stick
4412
  // to the last character on the line.
4413
  function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
4414
- lineObj = lineObj || getLine(cm.doc, pos.line)
4415
- if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) }
4416
  function get(ch, right) {
4417
- var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight)
4418
- if (right) { m.left = m.right; } else { m.right = m.left }
4419
  return intoCoordSystem(cm, lineObj, m, context)
4420
  }
4421
- var order = getOrder(lineObj), ch = pos.ch, sticky = pos.sticky
4422
  if (ch >= lineObj.text.length) {
4423
- ch = lineObj.text.length
4424
- sticky = "before"
4425
  } else if (ch <= 0) {
4426
- ch = 0
4427
- sticky = "after"
4428
  }
4429
  if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
4430
 
4431
  function getBidi(ch, partPos, invert) {
4432
- var part = order[partPos], right = (part.level % 2) != 0
4433
  return get(invert ? ch - 1 : ch, right != invert)
4434
  }
4435
- var partPos = getBidiPartAt(order, ch, sticky)
4436
- var other = bidiOther
4437
- var val = getBidi(ch, partPos, sticky == "before")
4438
- if (other != null) { val.other = getBidi(ch, other, sticky != "before") }
4439
  return val
4440
  }
4441
 
4442
  // Used to cheaply estimate the coordinates for a position. Used for
4443
  // intermediate scroll updates.
4444
  function estimateCoords(cm, pos) {
4445
- var left = 0
4446
- pos = clipPos(cm.doc, pos)
4447
- if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch }
4448
- var lineObj = getLine(cm.doc, pos.line)
4449
- var top = heightAtLine(lineObj) + paddingTop(cm.display)
4450
  return {left: left, right: left, top: top, bottom: top + lineObj.height}
4451
  }
4452
 
@@ -4457,139 +4467,139 @@ function estimateCoords(cm, pos) {
4457
  // is true, that means the coordinates lie outside the line's
4458
  // vertical range.
4459
  function PosWithInfo(line, ch, sticky, outside, xRel) {
4460
- var pos = Pos(line, ch, sticky)
4461
- pos.xRel = xRel
4462
- if (outside) { pos.outside = true }
4463
  return pos
4464
  }
4465
 
4466
  // Compute the character position closest to the given coordinates.
4467
  // Input must be lineSpace-local ("div" coordinate system).
4468
  function coordsChar(cm, x, y) {
4469
- var doc = cm.doc
4470
- y += cm.display.viewOffset
4471
  if (y < 0) { return PosWithInfo(doc.first, 0, null, true, -1) }
4472
- var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1
4473
  if (lineN > last)
4474
  { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1) }
4475
- if (x < 0) { x = 0 }
4476
 
4477
- var lineObj = getLine(doc, lineN)
4478
  for (;;) {
4479
- var found = coordsCharInner(cm, lineObj, lineN, x, y)
4480
- var merged = collapsedSpanAtEnd(lineObj)
4481
- var mergedPos = merged && merged.find(0, true)
4482
  if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
4483
- { lineN = lineNo(lineObj = mergedPos.to.line) }
4484
  else
4485
  { return found }
4486
  }
4487
  }
4488
 
4489
  function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
4490
- var measure = function (ch) { return intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, ch), "line"); }
4491
- var end = lineObj.text.length
4492
- var begin = findFirst(function (ch) { return measure(ch - 1).bottom <= y; }, end, 0)
4493
- end = findFirst(function (ch) { return measure(ch).top > y; }, begin, end)
4494
  return {begin: begin, end: end}
4495
  }
4496
 
4497
  function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
4498
- var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top
4499
  return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
4500
  }
4501
 
4502
- function coordsCharInner(cm, lineObj, lineNo, x, y) {
4503
- y -= heightAtLine(lineObj)
4504
- var begin = 0, end = lineObj.text.length
4505
- var preparedMeasure = prepareMeasureForLine(cm, lineObj)
4506
- var pos
4507
- var order = getOrder(lineObj)
4508
  if (order) {
4509
  if (cm.options.lineWrapping) {
4510
- ;var assign;
4511
- ((assign = wrappedLineExtent(cm, lineObj, preparedMeasure, y), begin = assign.begin, end = assign.end, assign))
4512
  }
4513
- pos = new Pos(lineNo, begin)
4514
- var beginLeft = cursorCoords(cm, pos, "line", lineObj, preparedMeasure).left
4515
- var dir = beginLeft < x ? 1 : -1
4516
- var prevDiff, diff = beginLeft - x, prevPos
4517
  do {
4518
- prevDiff = diff
4519
- prevPos = pos
4520
- pos = moveVisually(cm, lineObj, pos, dir)
4521
  if (pos == null || pos.ch < begin || end <= (pos.sticky == "before" ? pos.ch - 1 : pos.ch)) {
4522
- pos = prevPos
4523
  break
4524
  }
4525
- diff = cursorCoords(cm, pos, "line", lineObj, preparedMeasure).left - x
4526
  } while ((dir < 0) != (diff < 0) && (Math.abs(diff) <= Math.abs(prevDiff)))
4527
  if (Math.abs(diff) > Math.abs(prevDiff)) {
4528
  if ((diff < 0) == (prevDiff < 0)) { throw new Error("Broke out of infinite loop in coordsCharInner") }
4529
- pos = prevPos
4530
  }
4531
  } else {
4532
  var ch = findFirst(function (ch) {
4533
- var box = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, ch), "line")
4534
  if (box.top > y) {
4535
  // For the cursor stickiness
4536
- end = Math.min(ch, end)
4537
  return true
4538
  }
4539
  else if (box.bottom <= y) { return false }
4540
  else if (box.left > x) { return true }
4541
  else if (box.right < x) { return false }
4542
  else { return (x - box.left < box.right - x) }
4543
- }, begin, end)
4544
- ch = skipExtendingChars(lineObj.text, ch, 1)
4545
- pos = new Pos(lineNo, ch, ch == end ? "before" : "after")
4546
  }
4547
- var coords = cursorCoords(cm, pos, "line", lineObj, preparedMeasure)
4548
- if (y < coords.top || coords.bottom < y) { pos.outside = true }
4549
- pos.xRel = x < coords.left ? -1 : (x > coords.right ? 1 : 0)
4550
  return pos
4551
  }
4552
 
4553
- var measureText
4554
  // Compute the default text height.
4555
  function textHeight(display) {
4556
  if (display.cachedTextHeight != null) { return display.cachedTextHeight }
4557
  if (measureText == null) {
4558
- measureText = elt("pre")
4559
  // Measure a bunch of lines, for browsers that compute
4560
  // fractional heights.
4561
  for (var i = 0; i < 49; ++i) {
4562
- measureText.appendChild(document.createTextNode("x"))
4563
- measureText.appendChild(elt("br"))
4564
  }
4565
- measureText.appendChild(document.createTextNode("x"))
4566
  }
4567
- removeChildrenAndAdd(display.measure, measureText)
4568
- var height = measureText.offsetHeight / 50
4569
- if (height > 3) { display.cachedTextHeight = height }
4570
- removeChildren(display.measure)
4571
  return height || 1
4572
  }
4573
 
4574
  // Compute the default character width.
4575
  function charWidth(display) {
4576
  if (display.cachedCharWidth != null) { return display.cachedCharWidth }
4577
- var anchor = elt("span", "xxxxxxxxxx")
4578
- var pre = elt("pre", [anchor])
4579
- removeChildrenAndAdd(display.measure, pre)
4580
- var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10
4581
- if (width > 2) { display.cachedCharWidth = width }
4582
  return width || 10
4583
  }
4584
 
4585
  // Do a bulk-read of the DOM positions and sizes needed to draw the
4586
  // view, so that we don't interleave reading and writing to the DOM.
4587
  function getDimensions(cm) {
4588
- var d = cm.display, left = {}, width = {}
4589
- var gutterLeft = d.gutters.clientLeft
4590
  for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
4591
- left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft
4592
- width[cm.options.gutters[i]] = n.clientWidth
4593
  }
4594
  return {fixedPos: compensateForHScroll(d),
4595
  gutterTotalWidth: d.gutters.offsetWidth,
@@ -4609,14 +4619,14 @@ function compensateForHScroll(display) {
4609
  // first approximation until the line becomes visible (and is thus
4610
  // properly measurable).
4611
  function estimateHeight(cm) {
4612
- var th = textHeight(cm.display), wrapping = cm.options.lineWrapping
4613
- var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3)
4614
  return function (line) {
4615
  if (lineIsHidden(cm.doc, line)) { return 0 }
4616
 
4617
- var widgetsHeight = 0
4618
  if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
4619
- if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height }
4620
  } }
4621
 
4622
  if (wrapping)
@@ -4627,11 +4637,11 @@ function estimateHeight(cm) {
4627
  }
4628
 
4629
  function estimateLineHeights(cm) {
4630
- var doc = cm.doc, est = estimateHeight(cm)
4631
  doc.iter(function (line) {
4632
- var estHeight = est(line)
4633
- if (estHeight != line.height) { updateLineHeight(line, estHeight) }
4634
- })
4635
  }
4636
 
4637
  // Given a mouse event, find the corresponding position. If liberal
@@ -4640,17 +4650,17 @@ function estimateLineHeights(cm) {
4640
  // selections, and tries to estimate a character position even for
4641
  // coordinates beyond the right of the text.
4642
  function posFromMouse(cm, e, liberal, forRect) {
4643
- var display = cm.display
4644
  if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
4645
 
4646
- var x, y, space = display.lineSpace.getBoundingClientRect()
4647
  // Fails unpredictably on IE[67] when mouse is dragged around quickly.
4648
- try { x = e.clientX - space.left; y = e.clientY - space.top }
4649
  catch (e) { return null }
4650
- var coords = coordsChar(cm, x, y), line
4651
  if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
4652
- var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length
4653
- coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff))
4654
  }
4655
  return coords
4656
  }
@@ -4659,206 +4669,206 @@ function posFromMouse(cm, e, liberal, forRect) {
4659
  // when the line isn't visible.
4660
  function findViewIndex(cm, n) {
4661
  if (n >= cm.display.viewTo) { return null }
4662
- n -= cm.display.viewFrom
4663
  if (n < 0) { return null }
4664
- var view = cm.display.view
4665
  for (var i = 0; i < view.length; i++) {
4666
- n -= view[i].size
4667
  if (n < 0) { return i }
4668
  }
4669
  }
4670
 
4671
  function updateSelection(cm) {
4672
- cm.display.input.showSelection(cm.display.input.prepareSelection())
4673
  }
4674
 
4675
  function prepareSelection(cm, primary) {
4676
- var doc = cm.doc, result = {}
4677
- var curFragment = result.cursors = document.createDocumentFragment()
4678
- var selFragment = result.selection = document.createDocumentFragment()
4679
 
4680
  for (var i = 0; i < doc.sel.ranges.length; i++) {
4681
  if (primary === false && i == doc.sel.primIndex) { continue }
4682
- var range = doc.sel.ranges[i]
4683
- if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue }
4684
- var collapsed = range.empty()
4685
  if (collapsed || cm.options.showCursorWhenSelecting)
4686
- { drawSelectionCursor(cm, range.head, curFragment) }
4687
  if (!collapsed)
4688
- { drawSelectionRange(cm, range, selFragment) }
4689
  }
4690
  return result
4691
  }
4692
 
4693
  // Draws a cursor for the given range
4694
  function drawSelectionCursor(cm, head, output) {
4695
- var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine)
4696
 
4697
- var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"))
4698
- cursor.style.left = pos.left + "px"
4699
- cursor.style.top = pos.top + "px"
4700
- cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px"
4701
 
4702
  if (pos.other) {
4703
  // Secondary cursor, shown when on a 'jump' in bi-directional text
4704
- var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"))
4705
- otherCursor.style.display = ""
4706
- otherCursor.style.left = pos.other.left + "px"
4707
- otherCursor.style.top = pos.other.top + "px"
4708
- otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px"
4709
  }
4710
  }
4711
 
4712
  // Draws the given range as a highlighted selection
4713
- function drawSelectionRange(cm, range, output) {
4714
- var display = cm.display, doc = cm.doc
4715
- var fragment = document.createDocumentFragment()
4716
- var padding = paddingH(cm.display), leftSide = padding.left
4717
- var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
4718
 
4719
  function add(left, top, width, bottom) {
4720
- if (top < 0) { top = 0 }
4721
- top = Math.round(top)
4722
- bottom = Math.round(bottom)
4723
- fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")))
4724
  }
4725
 
4726
  function drawForLine(line, fromArg, toArg) {
4727
- var lineObj = getLine(doc, line)
4728
- var lineLen = lineObj.text.length
4729
- var start, end
4730
  function coords(ch, bias) {
4731
  return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
4732
  }
4733
 
4734
- iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir) {
4735
- var leftPos = coords(from, "left"), rightPos, left, right
4736
  if (from == to) {
4737
- rightPos = leftPos
4738
- left = right = leftPos.left
4739
  } else {
4740
- rightPos = coords(to - 1, "right")
4741
- if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp }
4742
- left = leftPos.left
4743
- right = rightPos.right
4744
  }
4745
- if (fromArg == null && from == 0) { left = leftSide }
4746
  if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
4747
- add(left, leftPos.top, null, leftPos.bottom)
4748
- left = leftSide
4749
- if (leftPos.bottom < rightPos.top) { add(left, leftPos.bottom, null, rightPos.top) }
4750
  }
4751
- if (toArg == null && to == lineLen) { right = rightSide }
4752
  if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
4753
- { start = leftPos }
4754
  if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
4755
- { end = rightPos }
4756
- if (left < leftSide + 1) { left = leftSide }
4757
- add(left, rightPos.top, right - left, rightPos.bottom)
4758
- })
4759
  return {start: start, end: end}
4760
  }
4761
 
4762
- var sFrom = range.from(), sTo = range.to()
4763
  if (sFrom.line == sTo.line) {
4764
- drawForLine(sFrom.line, sFrom.ch, sTo.ch)
4765
  } else {
4766
- var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line)
4767
- var singleVLine = visualLine(fromLine) == visualLine(toLine)
4768
- var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end
4769
- var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start
4770
  if (singleVLine) {
4771
  if (leftEnd.top < rightStart.top - 2) {
4772
- add(leftEnd.right, leftEnd.top, null, leftEnd.bottom)
4773
- add(leftSide, rightStart.top, rightStart.left, rightStart.bottom)
4774
  } else {
4775
- add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom)
4776
  }
4777
  }
4778
  if (leftEnd.bottom < rightStart.top)
4779
- { add(leftSide, leftEnd.bottom, null, rightStart.top) }
4780
  }
4781
 
4782
- output.appendChild(fragment)
4783
  }
4784
 
4785
  // Cursor-blinking
4786
  function restartBlink(cm) {
4787
  if (!cm.state.focused) { return }
4788
- var display = cm.display
4789
- clearInterval(display.blinker)
4790
- var on = true
4791
- display.cursorDiv.style.visibility = ""
4792
  if (cm.options.cursorBlinkRate > 0)
4793
  { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
4794
- cm.options.cursorBlinkRate) }
4795
  else if (cm.options.cursorBlinkRate < 0)
4796
- { display.cursorDiv.style.visibility = "hidden" }
4797
  }
4798
 
4799
  function ensureFocus(cm) {
4800
- if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm) }
4801
  }
4802
 
4803
  function delayBlurEvent(cm) {
4804
- cm.state.delayingBlurEvent = true
4805
  setTimeout(function () { if (cm.state.delayingBlurEvent) {
4806
- cm.state.delayingBlurEvent = false
4807
- onBlur(cm)
4808
- } }, 100)
4809
  }
4810
 
4811
  function onFocus(cm, e) {
4812
- if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false }
4813
 
4814
  if (cm.options.readOnly == "nocursor") { return }
4815
  if (!cm.state.focused) {
4816
- signal(cm, "focus", cm, e)
4817
- cm.state.focused = true
4818
- addClass(cm.display.wrapper, "CodeMirror-focused")
4819
  // This test prevents this from firing when a context
4820
  // menu is closed (since the input reset would kill the
4821
  // select-all detection hack)
4822
  if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
4823
- cm.display.input.reset()
4824
- if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20) } // Issue #1730
4825
  }
4826
- cm.display.input.receivedFocus()
4827
  }
4828
- restartBlink(cm)
4829
  }
4830
  function onBlur(cm, e) {
4831
  if (cm.state.delayingBlurEvent) { return }
4832
 
4833
  if (cm.state.focused) {
4834
- signal(cm, "blur", cm, e)
4835
- cm.state.focused = false
4836
- rmClass(cm.display.wrapper, "CodeMirror-focused")
4837
  }
4838
- clearInterval(cm.display.blinker)
4839
- setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false } }, 150)
4840
  }
4841
 
4842
  // Re-align line numbers and gutter marks to compensate for
4843
  // horizontal scrolling.
4844
  function alignHorizontally(cm) {
4845
- var display = cm.display, view = display.view
4846
  if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
4847
- var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft
4848
- var gutterW = display.gutters.offsetWidth, left = comp + "px"
4849
  for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
4850
  if (cm.options.fixedGutter) {
4851
  if (view[i].gutter)
4852
- { view[i].gutter.style.left = left }
4853
  if (view[i].gutterBackground)
4854
- { view[i].gutterBackground.style.left = left }
4855
  }
4856
- var align = view[i].alignable
4857
  if (align) { for (var j = 0; j < align.length; j++)
4858
- { align[j].style.left = left } }
4859
  } }
4860
  if (cm.options.fixedGutter)
4861
- { display.gutters.style.left = (comp + gutterW) + "px" }
4862
  }
4863
 
4864
  // Used to ensure that the line number gutter is still the right
@@ -4866,17 +4876,17 @@ function alignHorizontally(cm) {
4866
  // is needed.
4867
  function maybeUpdateLineNumberWidth(cm) {
4868
  if (!cm.options.lineNumbers) { return false }
4869
- var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display
4870
  if (last.length != display.lineNumChars) {
4871
  var test = display.measure.appendChild(elt("div", [elt("div", last)],
4872
- "CodeMirror-linenumber CodeMirror-gutter-elt"))
4873
- var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW
4874
- display.lineGutter.style.width = ""
4875
- display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1
4876
- display.lineNumWidth = display.lineNumInnerWidth + padding
4877
- display.lineNumChars = display.lineNumInnerWidth ? last.length : -1
4878
- display.lineGutter.style.width = display.lineNumWidth + "px"
4879
- updateGutterSpace(cm)
4880
  return true
4881
  }
4882
  return false
@@ -4885,26 +4895,26 @@ function maybeUpdateLineNumberWidth(cm) {
4885
  // Read the actual heights of the rendered lines, and update their
4886
  // stored heights to match.
4887
  function updateHeightsInViewport(cm) {
4888
- var display = cm.display
4889
- var prevBottom = display.lineDiv.offsetTop
4890
  for (var i = 0; i < display.view.length; i++) {
4891
- var cur = display.view[i], height = (void 0)
4892
  if (cur.hidden) { continue }
4893
  if (ie && ie_version < 8) {
4894
- var bot = cur.node.offsetTop + cur.node.offsetHeight
4895
- height = bot - prevBottom
4896
- prevBottom = bot
4897
  } else {
4898
- var box = cur.node.getBoundingClientRect()
4899
- height = box.bottom - box.top
4900
  }
4901
- var diff = cur.line.height - height
4902
- if (height < 2) { height = textHeight(display) }
4903
  if (diff > .001 || diff < -.001) {
4904
- updateLineHeight(cur.line, height)
4905
- updateWidgetHeight(cur.line)
4906
  if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
4907
- { updateWidgetHeight(cur.rest[j]) } }
4908
  }
4909
  }
4910
  }
@@ -4913,28 +4923,28 @@ function updateHeightsInViewport(cm) {
4913
  // given line.
4914
  function updateWidgetHeight(line) {
4915
  if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i)
4916
- { line.widgets[i].height = line.widgets[i].node.parentNode.offsetHeight } }
4917
  }
4918
 
4919
  // Compute the lines that are visible in a given viewport (defaults
4920
  // the the current scroll position). viewport may contain top,
4921
  // height, and ensure (see op.scrollToPos) properties.
4922
  function visibleLines(display, doc, viewport) {
4923
- var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop
4924
- top = Math.floor(top - paddingTop(display))
4925
- var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight
4926
 
4927
- var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom)
4928
  // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
4929
  // forces those lines into the viewport (if possible).
4930
  if (viewport && viewport.ensure) {
4931
- var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line
4932
  if (ensureFrom < from) {
4933
- from = ensureFrom
4934
- to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)
4935
  } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
4936
- from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight)
4937
- to = ensureTo
4938
  }
4939
  }
4940
  return {from: from, to: Math.max(to, from + 1)}
@@ -4944,22 +4954,22 @@ function visibleLines(display, doc, viewport) {
4944
  // covers the visible area.
4945
  function setScrollTop(cm, val) {
4946
  if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
4947
- cm.doc.scrollTop = val
4948
- if (!gecko) { updateDisplaySimple(cm, {top: val}) }
4949
- if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val }
4950
- cm.display.scrollbars.setScrollTop(val)
4951
- if (gecko) { updateDisplaySimple(cm) }
4952
- startWorker(cm, 100)
4953
  }
4954
  // Sync scroller and scrollbar, ensure the gutter elements are
4955
  // aligned.
4956
  function setScrollLeft(cm, val, isScroller) {
4957
  if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) { return }
4958
- val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth)
4959
- cm.doc.scrollLeft = val
4960
- alignHorizontally(cm)
4961
- if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val }
4962
- cm.display.scrollbars.setScrollLeft(val)
4963
  }
4964
 
4965
  // Since the delta values reported on mouse wheel events are
@@ -4979,32 +4989,32 @@ var wheelPixelsPerUnit = null;
4979
  // know one. These don't have to be accurate -- the result of them
4980
  // being wrong would just be a slight flicker on the first wheel
4981
  // scroll (if it is large enough).
4982
- if (ie) { wheelPixelsPerUnit = -.53 }
4983
- else if (gecko) { wheelPixelsPerUnit = 15 }
4984
- else if (chrome) { wheelPixelsPerUnit = -.7 }
4985
- else if (safari) { wheelPixelsPerUnit = -1/3 }
4986
 
4987
  function wheelEventDelta(e) {
4988
- var dx = e.wheelDeltaX, dy = e.wheelDeltaY
4989
- if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail }
4990
- if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail }
4991
- else if (dy == null) { dy = e.wheelDelta }
4992
  return {x: dx, y: dy}
4993
  }
4994
  function wheelEventPixels(e) {
4995
- var delta = wheelEventDelta(e)
4996
- delta.x *= wheelPixelsPerUnit
4997
- delta.y *= wheelPixelsPerUnit
4998
  return delta
4999
  }
5000
 
5001
  function onScrollWheel(cm, e) {
5002
- var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
5003
 
5004
- var display = cm.display, scroll = display.scroller
5005
  // Quit if there's nothing to scroll here
5006
- var canScrollX = scroll.scrollWidth > scroll.clientWidth
5007
- var canScrollY = scroll.scrollHeight > scroll.clientHeight
5008
  if (!(dx && canScrollX || dy && canScrollY)) { return }
5009
 
5010
  // Webkit browsers on OS X abort momentum scrolls when the target
@@ -5015,7 +5025,7 @@ function onScrollWheel(cm, e) {
5015
  outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
5016
  for (var i = 0; i < view.length; i++) {
5017
  if (view[i].node == cur) {
5018
- cm.display.currentWheelTarget = cur
5019
  break outer
5020
  }
5021
  }
@@ -5030,45 +5040,45 @@ function onScrollWheel(cm, e) {
5030
  // better than glitching out.
5031
  if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
5032
  if (dy && canScrollY)
5033
- { setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight))) }
5034
- setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)))
5035
  // Only prevent default scrolling if vertical scrolling is
5036
  // actually possible. Otherwise, it causes vertical scroll
5037
  // jitter on OSX trackpads when deltaX is small and deltaY
5038
  // is large (issue #3579)
5039
  if (!dy || (dy && canScrollY))
5040
- { e_preventDefault(e) }
5041
- display.wheelStartX = null // Abort measurement, if in progress
5042
  return
5043
  }
5044
 
5045
  // 'Project' the visible viewport to cover the area that is being
5046
  // scrolled into view (if we know enough to estimate it).
5047
  if (dy && wheelPixelsPerUnit != null) {
5048
- var pixels = dy * wheelPixelsPerUnit
5049
- var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight
5050
- if (pixels < 0) { top = Math.max(0, top + pixels - 50) }
5051
- else { bot = Math.min(cm.doc.height, bot + pixels + 50) }
5052
- updateDisplaySimple(cm, {top: top, bottom: bot})
5053
  }
5054
 
5055
  if (wheelSamples < 20) {
5056
  if (display.wheelStartX == null) {
5057
- display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
5058
- display.wheelDX = dx; display.wheelDY = dy
5059
  setTimeout(function () {
5060
  if (display.wheelStartX == null) { return }
5061
- var movedX = scroll.scrollLeft - display.wheelStartX
5062
- var movedY = scroll.scrollTop - display.wheelStartY
5063
  var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
5064
- (movedX && display.wheelDX && movedX / display.wheelDX)
5065
- display.wheelStartX = display.wheelStartY = null
5066
  if (!sample) { return }
5067
- wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1)
5068
- ++wheelSamples
5069
- }, 200)
5070
  } else {
5071
- display.wheelDX += dx; display.wheelDY += dy
5072
  }
5073
  }
5074
  }
@@ -5078,8 +5088,8 @@ function onScrollWheel(cm, e) {
5078
  // Prepare DOM reads needed to update the scrollbars. Done in one
5079
  // shot to minimize update/measure roundtrips.
5080
  function measureForScrollbars(cm) {
5081
- var d = cm.display, gutterW = d.gutters.offsetWidth
5082
- var docH = Math.round(cm.doc.height + paddingVert(cm.display))
5083
  return {
5084
  clientHeight: d.scroller.clientHeight,
5085
  viewHeight: d.wrapper.clientHeight,
@@ -5094,80 +5104,80 @@ function measureForScrollbars(cm) {
5094
  }
5095
 
5096
  var NativeScrollbars = function(place, scroll, cm) {
5097
- this.cm = cm
5098
- var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar")
5099
- var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
5100
- place(vert); place(horiz)
5101
 
5102
  on(vert, "scroll", function () {
5103
- if (vert.clientHeight) { scroll(vert.scrollTop, "vertical") }
5104
- })
5105
  on(horiz, "scroll", function () {
5106
- if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal") }
5107
- })
5108
 
5109
- this.checkedZeroWidth = false
5110
  // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
5111
- if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px" }
5112
  };
5113
 
5114
  NativeScrollbars.prototype.update = function (measure) {
5115
- var needsH = measure.scrollWidth > measure.clientWidth + 1
5116
- var needsV = measure.scrollHeight > measure.clientHeight + 1
5117
- var sWidth = measure.nativeBarWidth
5118
 
5119
  if (needsV) {
5120
- this.vert.style.display = "block"
5121
- this.vert.style.bottom = needsH ? sWidth + "px" : "0"
5122
- var totalHeight = measure.viewHeight - (needsH ? sWidth : 0)
5123
  // A bug in IE8 can cause this value to be negative, so guard it.
5124
  this.vert.firstChild.style.height =
5125
- Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"
5126
  } else {
5127
- this.vert.style.display = ""
5128
- this.vert.firstChild.style.height = "0"
5129
  }
5130
 
5131
  if (needsH) {
5132
- this.horiz.style.display = "block"
5133
- this.horiz.style.right = needsV ? sWidth + "px" : "0"
5134
- this.horiz.style.left = measure.barLeft + "px"
5135
- var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0)
5136
  this.horiz.firstChild.style.width =
5137
- Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px"
5138
  } else {
5139
- this.horiz.style.display = ""
5140
- this.horiz.firstChild.style.width = "0"
5141
  }
5142
 
5143
  if (!this.checkedZeroWidth && measure.clientHeight > 0) {
5144
- if (sWidth == 0) { this.zeroWidthHack() }
5145
- this.checkedZeroWidth = true
5146
  }
5147
 
5148
  return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
5149
  };
5150
 
5151
  NativeScrollbars.prototype.setScrollLeft = function (pos) {
5152
- if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos }
5153
- if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz) }
5154
  };
5155
 
5156
  NativeScrollbars.prototype.setScrollTop = function (pos) {
5157
- if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos }
5158
- if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert) }
5159
  };
5160
 
5161
  NativeScrollbars.prototype.zeroWidthHack = function () {
5162
- var w = mac && !mac_geMountainLion ? "12px" : "18px"
5163
- this.horiz.style.height = this.vert.style.width = w
5164
- this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none"
5165
- this.disableHoriz = new Delayed
5166
- this.disableVert = new Delayed
5167
  };
5168
 
5169
  NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay) {
5170
- bar.style.pointerEvents = "auto"
5171
  function maybeDisable() {
5172
  // To find out whether the scrollbar is still visible, we
5173
  // check whether the element under the pixel in the bottom
@@ -5175,18 +5185,18 @@ NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay) {
5175
  // itself (when the bar is still visible) or its filler child
5176
  // (when the bar is hidden). If it is still visible, we keep
5177
  // it enabled, if it's hidden, we disable pointer events.
5178
- var box = bar.getBoundingClientRect()
5179
- var elt = document.elementFromPoint(box.left + 1, box.bottom - 1)
5180
- if (elt != bar) { bar.style.pointerEvents = "none" }
5181
- else { delay.set(1000, maybeDisable) }
5182
  }
5183
- delay.set(1000, maybeDisable)
5184
  };
5185
 
5186
  NativeScrollbars.prototype.clear = function () {
5187
- var parent = this.horiz.parentNode
5188
- parent.removeChild(this.horiz)
5189
- parent.removeChild(this.vert)
5190
  };
5191
 
5192
  var NullScrollbars = function () {};
@@ -5197,78 +5207,78 @@ NullScrollbars.prototype.setScrollTop = function () {};
5197
  NullScrollbars.prototype.clear = function () {};
5198
 
5199
  function updateScrollbars(cm, measure) {
5200
- if (!measure) { measure = measureForScrollbars(cm) }
5201
- var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight
5202
- updateScrollbarsInner(cm, measure)
5203
  for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
5204
  if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
5205
- { updateHeightsInViewport(cm) }
5206
- updateScrollbarsInner(cm, measureForScrollbars(cm))
5207
- startWidth = cm.display.barWidth; startHeight = cm.display.barHeight
5208
  }
5209
  }
5210
 
5211
  // Re-synchronize the fake scrollbars with the actual size of the
5212
  // content.
5213
  function updateScrollbarsInner(cm, measure) {
5214
- var d = cm.display
5215
- var sizes = d.scrollbars.update(measure)
5216
 
5217
- d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"
5218
- d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"
5219
- d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"
5220
 
5221
  if (sizes.right && sizes.bottom) {
5222
- d.scrollbarFiller.style.display = "block"
5223
- d.scrollbarFiller.style.height = sizes.bottom + "px"
5224
- d.scrollbarFiller.style.width = sizes.right + "px"
5225
- } else { d.scrollbarFiller.style.display = "" }
5226
  if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
5227
- d.gutterFiller.style.display = "block"
5228
- d.gutterFiller.style.height = sizes.bottom + "px"
5229
- d.gutterFiller.style.width = measure.gutterWidth + "px"
5230
- } else { d.gutterFiller.style.display = "" }
5231
  }
5232
 
5233
- var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}
5234
 
5235
  function initScrollbars(cm) {
5236
  if (cm.display.scrollbars) {
5237
- cm.display.scrollbars.clear()
5238
  if (cm.display.scrollbars.addClass)
5239
- { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
5240
  }
5241
 
5242
  cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
5243
- cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller)
5244
  // Prevent clicks in the scrollbars from killing focus
5245
  on(node, "mousedown", function () {
5246
- if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0) }
5247
- })
5248
- node.setAttribute("cm-not-content", "true")
5249
  }, function (pos, axis) {
5250
- if (axis == "horizontal") { setScrollLeft(cm, pos) }
5251
- else { setScrollTop(cm, pos) }
5252
- }, cm)
5253
  if (cm.display.scrollbars.addClass)
5254
- { addClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
5255
  }
5256
 
5257
  // SCROLLING THINGS INTO VIEW
5258
 
5259
  // If an editor sits on the top or bottom of the window, partially
5260
  // scrolled out of view, this ensures that the cursor is visible.
5261
- function maybeScrollWindow(cm, coords) {
5262
  if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
5263
 
5264
- var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null
5265
- if (coords.top + box.top < 0) { doScroll = true }
5266
- else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false }
5267
  if (doScroll != null && !phantom) {
5268
- var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (coords.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (coords.left) + "px; width: 2px;"))
5269
- cm.display.lineSpace.appendChild(scrollNode)
5270
- scrollNode.scrollIntoView(doScroll)
5271
- cm.display.lineSpace.removeChild(scrollNode)
5272
  }
5273
  }
5274
 
@@ -5276,89 +5286,90 @@ function maybeScrollWindow(cm, coords) {
5276
  // it actually became visible (as line heights are accurately
5277
  // measured, the position of something may 'drift' during drawing).
5278
  function scrollPosIntoView(cm, pos, end, margin) {
5279
- if (margin == null) { margin = 0 }
5280
- var coords
5281
  for (var limit = 0; limit < 5; limit++) {
5282
- var changed = false
5283
- coords = cursorCoords(cm, pos)
5284
- var endCoords = !end || end == pos ? coords : cursorCoords(cm, end)
5285
- var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
5286
- Math.min(coords.top, endCoords.top) - margin,
5287
- Math.max(coords.left, endCoords.left),
5288
- Math.max(coords.bottom, endCoords.bottom) + margin)
5289
- var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft
 
5290
  if (scrollPos.scrollTop != null) {
5291
- setScrollTop(cm, scrollPos.scrollTop)
5292
- if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true }
5293
  }
5294
  if (scrollPos.scrollLeft != null) {
5295
- setScrollLeft(cm, scrollPos.scrollLeft)
5296
- if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true }
5297
  }
5298
  if (!changed) { break }
5299
  }
5300
- return coords
5301
  }
5302
 
5303
  // Scroll a given set of coordinates into view (immediately).
5304
- function scrollIntoView(cm, x1, y1, x2, y2) {
5305
- var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2)
5306
- if (scrollPos.scrollTop != null) { setScrollTop(cm, scrollPos.scrollTop) }
5307
- if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft) }
5308
  }
5309
 
5310
  // Calculate a new scroll position needed to scroll the given
5311
  // rectangle into view. Returns an object with scrollTop and
5312
  // scrollLeft properties. When these are undefined, the
5313
  // vertical/horizontal position does not need to be adjusted.
5314
- function calculateScrollPos(cm, x1, y1, x2, y2) {
5315
- var display = cm.display, snapMargin = textHeight(cm.display)
5316
- if (y1 < 0) { y1 = 0 }
5317
- var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
5318
- var screen = displayHeight(cm), result = {}
5319
- if (y2 - y1 > screen) { y2 = y1 + screen }
5320
- var docBottom = cm.doc.height + paddingVert(display)
5321
- var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin
5322
- if (y1 < screentop) {
5323
- result.scrollTop = atTop ? 0 : y1
5324
- } else if (y2 > screentop + screen) {
5325
- var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen)
5326
- if (newTop != screentop) { result.scrollTop = newTop }
5327
- }
5328
-
5329
- var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft
5330
- var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0)
5331
- var tooWide = x2 - x1 > screenw
5332
- if (tooWide) { x2 = x1 + screenw }
5333
- if (x1 < 10)
5334
- { result.scrollLeft = 0 }
5335
- else if (x1 < screenleft)
5336
- { result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10)) }
5337
- else if (x2 > screenw + screenleft - 3)
5338
- { result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw }
5339
  return result
5340
  }
5341
 
5342
  // Store a relative adjustment to the scroll position in the current
5343
  // operation (to be applied when the operation finishes).
5344
  function addToScrollPos(cm, left, top) {
5345
- if (left != null || top != null) { resolveScrollToPos(cm) }
5346
  if (left != null)
5347
- { cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left }
5348
  if (top != null)
5349
- { cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top }
5350
  }
5351
 
5352
  // Make sure that at the end of the operation the current cursor is
5353
  // shown.
5354
  function ensureCursorVisible(cm) {
5355
- resolveScrollToPos(cm)
5356
- var cur = cm.getCursor(), from = cur, to = cur
5357
  if (!cm.options.lineWrapping) {
5358
- from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur
5359
- to = Pos(cur.line, cur.ch + 1)
5360
  }
5361
- cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true}
5362
  }
5363
 
5364
  // When an operation has its scrollToPos property set, and another
@@ -5366,15 +5377,17 @@ function ensureCursorVisible(cm) {
5366
  // 'simulates' scrolling that position into view in a cheap way, so
5367
  // that the effect of intermediate scroll commands is not ignored.
5368
  function resolveScrollToPos(cm) {
5369
- var range = cm.curOp.scrollToPos
5370
- if (range) {
5371
- cm.curOp.scrollToPos = null
5372
- var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to)
5373
- var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
5374
- Math.min(from.top, to.top) - range.margin,
5375
- Math.max(from.right, to.right),
5376
- Math.max(from.bottom, to.bottom) + range.margin)
5377
- cm.scrollTo(sPos.scrollLeft, sPos.scrollTop)
 
 
5378
  }
5379
  }
5380
 
@@ -5384,7 +5397,7 @@ function resolveScrollToPos(cm) {
5384
  // error-prone). Instead, display updates are batched and then all
5385
  // combined and executed at once.
5386
 
5387
- var nextOpId = 0
5388
  // Start a new operation.
5389
  function startOperation(cm) {
5390
  cm.curOp = {
@@ -5403,159 +5416,159 @@ function startOperation(cm) {
5403
  scrollToPos: null, // Used to scroll to a specific position
5404
  focus: false,
5405
  id: ++nextOpId // Unique ID
5406
- }
5407
- pushOperation(cm.curOp)
5408
  }
5409
 
5410
  // Finish an operation, updating the display and signalling delayed events
5411
  function endOperation(cm) {
5412
- var op = cm.curOp
5413
  finishOperation(op, function (group) {
5414
  for (var i = 0; i < group.ops.length; i++)
5415
- { group.ops[i].cm.curOp = null }
5416
- endOperations(group)
5417
- })
5418
  }
5419
 
5420
  // The DOM updates done when an operation finishes are batched so
5421
  // that the minimum number of relayouts are required.
5422
  function endOperations(group) {
5423
- var ops = group.ops
5424
  for (var i = 0; i < ops.length; i++) // Read DOM
5425
- { endOperation_R1(ops[i]) }
5426
  for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
5427
- { endOperation_W1(ops[i$1]) }
5428
  for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
5429
- { endOperation_R2(ops[i$2]) }
5430
  for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
5431
- { endOperation_W2(ops[i$3]) }
5432
  for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
5433
- { endOperation_finish(ops[i$4]) }
5434
  }
5435
 
5436
  function endOperation_R1(op) {
5437
- var cm = op.cm, display = cm.display
5438
- maybeClipScrollbars(cm)
5439
- if (op.updateMaxLine) { findMaxLine(cm) }
5440
 
5441
  op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
5442
  op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
5443
  op.scrollToPos.to.line >= display.viewTo) ||
5444
- display.maxLineChanged && cm.options.lineWrapping
5445
  op.update = op.mustUpdate &&
5446
- new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate)
5447
  }
5448
 
5449
  function endOperation_W1(op) {
5450
- op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update)
5451
  }
5452
 
5453
  function endOperation_R2(op) {
5454
- var cm = op.cm, display = cm.display
5455
- if (op.updatedDisplay) { updateHeightsInViewport(cm) }
5456
 
5457
- op.barMeasure = measureForScrollbars(cm)
5458
 
5459
  // If the max line changed since it was last measured, measure it,
5460
  // and ensure the document's width matches it.
5461
  // updateDisplay_W2 will use these properties to do the actual resizing
5462
  if (display.maxLineChanged && !cm.options.lineWrapping) {
5463
- op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3
5464
- cm.display.sizerWidth = op.adjustWidthTo
5465
  op.barMeasure.scrollWidth =
5466
- Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth)
5467
- op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm))
5468
  }
5469
 
5470
  if (op.updatedDisplay || op.selectionChanged)
5471
- { op.preparedSelection = display.input.prepareSelection(op.focus) }
5472
  }
5473
 
5474
  function endOperation_W2(op) {
5475
- var cm = op.cm
5476
 
5477
  if (op.adjustWidthTo != null) {
5478
- cm.display.sizer.style.minWidth = op.adjustWidthTo + "px"
5479
  if (op.maxScrollLeft < cm.doc.scrollLeft)
5480
- { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true) }
5481
- cm.display.maxLineChanged = false
5482
  }
5483
 
5484
- var takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus())
5485
  if (op.preparedSelection)
5486
- { cm.display.input.showSelection(op.preparedSelection, takeFocus) }
5487
  if (op.updatedDisplay || op.startHeight != cm.doc.height)
5488
- { updateScrollbars(cm, op.barMeasure) }
5489
  if (op.updatedDisplay)
5490
- { setDocumentHeight(cm, op.barMeasure) }
5491
 
5492
- if (op.selectionChanged) { restartBlink(cm) }
5493
 
5494
  if (cm.state.focused && op.updateInput)
5495
- { cm.display.input.reset(op.typing) }
5496
- if (takeFocus) { ensureFocus(op.cm) }
5497
  }
5498
 
5499
  function endOperation_finish(op) {
5500
- var cm = op.cm, display = cm.display, doc = cm.doc
5501
 
5502
- if (op.updatedDisplay) { postUpdateDisplay(cm, op.update) }
5503
 
5504
  // Abort mouse wheel delta measurement, when scrolling explicitly
5505
  if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
5506
- { display.wheelStartX = display.wheelStartY = null }
5507
 
5508
  // Propagate the scroll position to the actual DOM scroller
5509
  if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
5510
- doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop))
5511
- display.scrollbars.setScrollTop(doc.scrollTop)
5512
- display.scroller.scrollTop = doc.scrollTop
5513
  }
5514
  if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
5515
- doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft))
5516
- display.scrollbars.setScrollLeft(doc.scrollLeft)
5517
- display.scroller.scrollLeft = doc.scrollLeft
5518
- alignHorizontally(cm)
5519
  }
5520
  // If we need to scroll a specific position into view, do so.
5521
  if (op.scrollToPos) {
5522
- var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
5523
- clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin)
5524
- if (op.scrollToPos.isCursor && cm.state.focused) { maybeScrollWindow(cm, coords) }
5525
  }
5526
 
5527
  // Fire events for markers that are hidden/unidden by editing or
5528
  // undoing
5529
- var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers
5530
  if (hidden) { for (var i = 0; i < hidden.length; ++i)
5531
- { if (!hidden[i].lines.length) { signal(hidden[i], "hide") } } }
5532
  if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
5533
- { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide") } } }
5534
 
5535
  if (display.wrapper.offsetHeight)
5536
- { doc.scrollTop = cm.display.scroller.scrollTop }
5537
 
5538
  // Fire change events, and delayed event handlers
5539
  if (op.changeObjs)
5540
- { signal(cm, "changes", cm, op.changeObjs) }
5541
  if (op.update)
5542
- { op.update.finish() }
5543
  }
5544
 
5545
  // Run the given function in an operation
5546
  function runInOp(cm, f) {
5547
  if (cm.curOp) { return f() }
5548
- startOperation(cm)
5549
  try { return f() }
5550
- finally { endOperation(cm) }
5551
  }
5552
  // Wraps a function in an operation. Returns the wrapped function.
5553
  function operation(cm, f) {
5554
  return function() {
5555
  if (cm.curOp) { return f.apply(cm, arguments) }
5556
- startOperation(cm)
5557
  try { return f.apply(cm, arguments) }
5558
- finally { endOperation(cm) }
5559
  }
5560
  }
5561
  // Used to add methods to editor and doc instances, wrapping them in
@@ -5563,18 +5576,18 @@ function operation(cm, f) {
5563
  function methodOp(f) {
5564
  return function() {
5565
  if (this.curOp) { return f.apply(this, arguments) }
5566
- startOperation(this)
5567
  try { return f.apply(this, arguments) }
5568
- finally { endOperation(this) }
5569
  }
5570
  }
5571
  function docMethodOp(f) {
5572
  return function() {
5573
- var cm = this.cm
5574
  if (!cm || cm.curOp) { return f.apply(this, arguments) }
5575
- startOperation(cm)
5576
  try { return f.apply(this, arguments) }
5577
- finally { endOperation(cm) }
5578
  }
5579
  }
5580
 
@@ -5585,111 +5598,111 @@ function docMethodOp(f) {
5585
  // lines are divided into visual lines. regLineChange (below)
5586
  // registers single-line changes.
5587
  function regChange(cm, from, to, lendiff) {
5588
- if (from == null) { from = cm.doc.first }
5589
- if (to == null) { to = cm.doc.first + cm.doc.size }
5590
- if (!lendiff) { lendiff = 0 }
5591
 
5592
- var display = cm.display
5593
  if (lendiff && to < display.viewTo &&
5594
  (display.updateLineNumbers == null || display.updateLineNumbers > from))
5595
- { display.updateLineNumbers = from }
5596
 
5597
- cm.curOp.viewChanged = true
5598
 
5599
  if (from >= display.viewTo) { // Change after
5600
  if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
5601
- { resetView(cm) }
5602
  } else if (to <= display.viewFrom) { // Change before
5603
  if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
5604
- resetView(cm)
5605
  } else {
5606
- display.viewFrom += lendiff
5607
- display.viewTo += lendiff
5608
  }
5609
  } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
5610
- resetView(cm)
5611
  } else if (from <= display.viewFrom) { // Top overlap
5612
- var cut = viewCuttingPoint(cm, to, to + lendiff, 1)
5613
  if (cut) {
5614
- display.view = display.view.slice(cut.index)
5615
- display.viewFrom = cut.lineN
5616
- display.viewTo += lendiff
5617
  } else {
5618
- resetView(cm)
5619
  }
5620
  } else if (to >= display.viewTo) { // Bottom overlap
5621
- var cut$1 = viewCuttingPoint(cm, from, from, -1)
5622
  if (cut$1) {
5623
- display.view = display.view.slice(0, cut$1.index)
5624
- display.viewTo = cut$1.lineN
5625
  } else {
5626
- resetView(cm)
5627
  }
5628
  } else { // Gap in the middle
5629
- var cutTop = viewCuttingPoint(cm, from, from, -1)
5630
- var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1)
5631
  if (cutTop && cutBot) {
5632
  display.view = display.view.slice(0, cutTop.index)
5633
  .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
5634
- .concat(display.view.slice(cutBot.index))
5635
- display.viewTo += lendiff
5636
  } else {
5637
- resetView(cm)
5638
  }
5639
  }
5640
 
5641
- var ext = display.externalMeasured
5642
  if (ext) {
5643
  if (to < ext.lineN)
5644
- { ext.lineN += lendiff }
5645
  else if (from < ext.lineN + ext.size)
5646
- { display.externalMeasured = null }
5647
  }
5648
  }
5649
 
5650
  // Register a change to a single line. Type must be one of "text",
5651
  // "gutter", "class", "widget"
5652
  function regLineChange(cm, line, type) {
5653
- cm.curOp.viewChanged = true
5654
- var display = cm.display, ext = cm.display.externalMeasured
5655
  if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
5656
- { display.externalMeasured = null }
5657
 
5658
  if (line < display.viewFrom || line >= display.viewTo) { return }
5659
- var lineView = display.view[findViewIndex(cm, line)]
5660
  if (lineView.node == null) { return }
5661
- var arr = lineView.changes || (lineView.changes = [])
5662
- if (indexOf(arr, type) == -1) { arr.push(type) }
5663
  }
5664
 
5665
  // Clear the view.
5666
  function resetView(cm) {
5667
- cm.display.viewFrom = cm.display.viewTo = cm.doc.first
5668
- cm.display.view = []
5669
- cm.display.viewOffset = 0
5670
  }
5671
 
5672
  function viewCuttingPoint(cm, oldN, newN, dir) {
5673
- var index = findViewIndex(cm, oldN), diff, view = cm.display.view
5674
  if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
5675
  { return {index: index, lineN: newN} }
5676
- var n = cm.display.viewFrom
5677
  for (var i = 0; i < index; i++)
5678
- { n += view[i].size }
5679
  if (n != oldN) {
5680
  if (dir > 0) {
5681
  if (index == view.length - 1) { return null }
5682
- diff = (n + view[index].size) - oldN
5683
- index++
5684
  } else {
5685
- diff = n - oldN
5686
  }
5687
- oldN += diff; newN += diff
5688
  }
5689
  while (visualLineNo(cm.doc, newN) != newN) {
5690
  if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
5691
- newN += dir * view[index - (dir < 0 ? 1 : 0)].size
5692
- index += dir
5693
  }
5694
  return {index: index, lineN: newN}
5695
  }
@@ -5697,31 +5710,31 @@ function viewCuttingPoint(cm, oldN, newN, dir) {
5697
  // Force the view to cover a given range, adding empty view element
5698
  // or clipping off existing ones as needed.
5699
  function adjustView(cm, from, to) {
5700
- var display = cm.display, view = display.view
5701
  if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
5702
- display.view = buildViewArray(cm, from, to)
5703
- display.viewFrom = from
5704
  } else {
5705
  if (display.viewFrom > from)
5706
- { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view) }
5707
  else if (display.viewFrom < from)
5708
- { display.view = display.view.slice(findViewIndex(cm, from)) }
5709
- display.viewFrom = from
5710
  if (display.viewTo < to)
5711
- { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)) }
5712
  else if (display.viewTo > to)
5713
- { display.view = display.view.slice(0, findViewIndex(cm, to)) }
5714
  }
5715
- display.viewTo = to
5716
  }
5717
 
5718
  // Count the number of lines in the view whose DOM representation is
5719
  // out of date (or nonexistent).
5720
  function countDirtyView(cm) {
5721
- var view = cm.display.view, dirty = 0
5722
  for (var i = 0; i < view.length; i++) {
5723
- var lineView = view[i]
5724
- if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty }
5725
  }
5726
  return dirty
5727
  }
@@ -5730,83 +5743,83 @@ function countDirtyView(cm) {
5730
 
5731
  function startWorker(cm, time) {
5732
  if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
5733
- { cm.state.highlight.set(time, bind(highlightWorker, cm)) }
5734
  }
5735
 
5736
  function highlightWorker(cm) {
5737
- var doc = cm.doc
5738
- if (doc.frontier < doc.first) { doc.frontier = doc.first }
5739
  if (doc.frontier >= cm.display.viewTo) { return }
5740
- var end = +new Date + cm.options.workTime
5741
- var state = copyState(doc.mode, getStateBefore(cm, doc.frontier))
5742
- var changedLines = []
5743
 
5744
  doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
5745
  if (doc.frontier >= cm.display.viewFrom) { // Visible
5746
- var oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength
5747
- var highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true)
5748
- line.styles = highlighted.styles
5749
- var oldCls = line.styleClasses, newCls = highlighted.classes
5750
- if (newCls) { line.styleClasses = newCls }
5751
- else if (oldCls) { line.styleClasses = null }
5752
  var ischange = !oldStyles || oldStyles.length != line.styles.length ||
5753
- oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass)
5754
- for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i] }
5755
- if (ischange) { changedLines.push(doc.frontier) }
5756
- line.stateAfter = tooLong ? state : copyState(doc.mode, state)
5757
  } else {
5758
  if (line.text.length <= cm.options.maxHighlightLength)
5759
- { processLine(cm, line.text, state) }
5760
- line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null
5761
  }
5762
- ++doc.frontier
5763
  if (+new Date > end) {
5764
- startWorker(cm, cm.options.workDelay)
5765
  return true
5766
  }
5767
- })
5768
  if (changedLines.length) { runInOp(cm, function () {
5769
  for (var i = 0; i < changedLines.length; i++)
5770
- { regLineChange(cm, changedLines[i], "text") }
5771
- }) }
5772
  }
5773
 
5774
  // DISPLAY DRAWING
5775
 
5776
  var DisplayUpdate = function(cm, viewport, force) {
5777
- var display = cm.display
5778
 
5779
- this.viewport = viewport
5780
  // Store some values that we'll need later (but don't want to force a relayout for)
5781
- this.visible = visibleLines(display, cm.doc, viewport)
5782
- this.editorIsHidden = !display.wrapper.offsetWidth
5783
- this.wrapperHeight = display.wrapper.clientHeight
5784
- this.wrapperWidth = display.wrapper.clientWidth
5785
- this.oldDisplayWidth = displayWidth(cm)
5786
- this.force = force
5787
- this.dims = getDimensions(cm)
5788
- this.events = []
5789
  };
5790
 
5791
  DisplayUpdate.prototype.signal = function (emitter, type) {
5792
  if (hasHandler(emitter, type))
5793
- { this.events.push(arguments) }
5794
  };
5795
  DisplayUpdate.prototype.finish = function () {
5796
  var this$1 = this;
5797
 
5798
  for (var i = 0; i < this.events.length; i++)
5799
- { signal.apply(null, this$1.events[i]) }
5800
  };
5801
 
5802
  function maybeClipScrollbars(cm) {
5803
- var display = cm.display
5804
  if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
5805
- display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth
5806
- display.heightForcer.style.height = scrollGap(cm) + "px"
5807
- display.sizer.style.marginBottom = -display.nativeBarWidth + "px"
5808
- display.sizer.style.borderRightWidth = scrollGap(cm) + "px"
5809
- display.scrollbarsClipped = true
5810
  }
5811
  }
5812
 
@@ -5814,10 +5827,10 @@ function maybeClipScrollbars(cm) {
5814
  // (returning false) when there is nothing to be done and forced is
5815
  // false.
5816
  function updateDisplayIfNeeded(cm, update) {
5817
- var display = cm.display, doc = cm.doc
5818
 
5819
  if (update.editorIsHidden) {
5820
- resetView(cm)
5821
  return false
5822
  }
5823
 
@@ -5829,101 +5842,101 @@ function updateDisplayIfNeeded(cm, update) {
5829
  { return false }
5830
 
5831
  if (maybeUpdateLineNumberWidth(cm)) {
5832
- resetView(cm)
5833
- update.dims = getDimensions(cm)
5834
  }
5835
 
5836
  // Compute a suitable new viewport (from & to)
5837
- var end = doc.first + doc.size
5838
- var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first)
5839
- var to = Math.min(end, update.visible.to + cm.options.viewportMargin)
5840
- if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom) }
5841
- if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo) }
5842
  if (sawCollapsedSpans) {
5843
- from = visualLineNo(cm.doc, from)
5844
- to = visualLineEndNo(cm.doc, to)
5845
  }
5846
 
5847
  var different = from != display.viewFrom || to != display.viewTo ||
5848
- display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth
5849
- adjustView(cm, from, to)
5850
 
5851
- display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom))
5852
  // Position the mover div to align with the current scroll position
5853
- cm.display.mover.style.top = display.viewOffset + "px"
5854
 
5855
- var toUpdate = countDirtyView(cm)
5856
  if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
5857
  (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
5858
  { return false }
5859
 
5860
  // For big changes, we hide the enclosing element during the
5861
  // update, since that speeds up the operations on most browsers.
5862
- var focused = activeElt()
5863
- if (toUpdate > 4) { display.lineDiv.style.display = "none" }
5864
- patchDisplay(cm, display.updateLineNumbers, update.dims)
5865
- if (toUpdate > 4) { display.lineDiv.style.display = "" }
5866
- display.renderedView = display.view
5867
  // There might have been a widget with a focused element that got
5868
  // hidden or updated, if so re-focus it.
5869
- if (focused && activeElt() != focused && focused.offsetHeight) { focused.focus() }
5870
 
5871
  // Prevent selection and cursors from interfering with the scroll
5872
  // width and height.
5873
- removeChildren(display.cursorDiv)
5874
- removeChildren(display.selectionDiv)
5875
- display.gutters.style.height = display.sizer.style.minHeight = 0
5876
 
5877
  if (different) {
5878
- display.lastWrapHeight = update.wrapperHeight
5879
- display.lastWrapWidth = update.wrapperWidth
5880
- startWorker(cm, 400)
5881
  }
5882
 
5883
- display.updateLineNumbers = null
5884
 
5885
  return true
5886
  }
5887
 
5888
  function postUpdateDisplay(cm, update) {
5889
- var viewport = update.viewport
5890
 
5891
  for (var first = true;; first = false) {
5892
  if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
5893
  // Clip forced viewport to actual scrollable area.
5894
  if (viewport && viewport.top != null)
5895
- { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)} }
5896
  // Updated line heights might result in the drawn area not
5897
  // actually covering the viewport. Keep looping until it does.
5898
- update.visible = visibleLines(cm.display, cm.doc, viewport)
5899
  if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
5900
  { break }
5901
  }
5902
  if (!updateDisplayIfNeeded(cm, update)) { break }
5903
- updateHeightsInViewport(cm)
5904
- var barMeasure = measureForScrollbars(cm)
5905
- updateSelection(cm)
5906
- updateScrollbars(cm, barMeasure)
5907
- setDocumentHeight(cm, barMeasure)
5908
  }
5909
 
5910
- update.signal(cm, "update", cm)
5911
  if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
5912
- update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo)
5913
- cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo
5914
  }
5915
  }
5916
 
5917
  function updateDisplaySimple(cm, viewport) {
5918
- var update = new DisplayUpdate(cm, viewport)
5919
  if (updateDisplayIfNeeded(cm, update)) {
5920
- updateHeightsInViewport(cm)
5921
- postUpdateDisplay(cm, update)
5922
- var barMeasure = measureForScrollbars(cm)
5923
- updateSelection(cm)
5924
- updateScrollbars(cm, barMeasure)
5925
- setDocumentHeight(cm, barMeasure)
5926
- update.finish()
5927
  }
5928
  }
5929
 
@@ -5932,85 +5945,85 @@ function updateDisplaySimple(cm, viewport) {
5932
  // that are not there yet, and updating the ones that are out of
5933
  // date.
5934
  function patchDisplay(cm, updateNumbersFrom, dims) {
5935
- var display = cm.display, lineNumbers = cm.options.lineNumbers
5936
- var container = display.lineDiv, cur = container.firstChild
5937
 
5938
  function rm(node) {
5939
- var next = node.nextSibling
5940
  // Works around a throw-scroll bug in OS X Webkit
5941
  if (webkit && mac && cm.display.currentWheelTarget == node)
5942
- { node.style.display = "none" }
5943
  else
5944
- { node.parentNode.removeChild(node) }
5945
  return next
5946
  }
5947
 
5948
- var view = display.view, lineN = display.viewFrom
5949
  // Loop over the elements in the view, syncing cur (the DOM nodes
5950
  // in display.lineDiv) with the view as we go.
5951
  for (var i = 0; i < view.length; i++) {
5952
- var lineView = view[i]
5953
  if (lineView.hidden) {
5954
  } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
5955
- var node = buildLineElement(cm, lineView, lineN, dims)
5956
- container.insertBefore(node, cur)
5957
  } else { // Already drawn
5958
- while (cur != lineView.node) { cur = rm(cur) }
5959
  var updateNumber = lineNumbers && updateNumbersFrom != null &&
5960
- updateNumbersFrom <= lineN && lineView.lineNumber
5961
  if (lineView.changes) {
5962
- if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false }
5963
- updateLineForChanges(cm, lineView, lineN, dims)
5964
  }
5965
  if (updateNumber) {
5966
- removeChildren(lineView.lineNumber)
5967
- lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
5968
  }
5969
- cur = lineView.node.nextSibling
5970
  }
5971
- lineN += lineView.size
5972
  }
5973
- while (cur) { cur = rm(cur) }
5974
  }
5975
 
5976
  function updateGutterSpace(cm) {
5977
- var width = cm.display.gutters.offsetWidth
5978
- cm.display.sizer.style.marginLeft = width + "px"
5979
  }
5980
 
5981
  function setDocumentHeight(cm, measure) {
5982
- cm.display.sizer.style.minHeight = measure.docHeight + "px"
5983
- cm.display.heightForcer.style.top = measure.docHeight + "px"
5984
- cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"
5985
  }
5986
 
5987
  // Rebuild the gutter elements, ensure the margin to the left of the
5988
  // code matches their width.
5989
  function updateGutters(cm) {
5990
- var gutters = cm.display.gutters, specs = cm.options.gutters
5991
- removeChildren(gutters)
5992
- var i = 0
5993
  for (; i < specs.length; ++i) {
5994
- var gutterClass = specs[i]
5995
- var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass))
5996
  if (gutterClass == "CodeMirror-linenumbers") {
5997
- cm.display.lineGutter = gElt
5998
- gElt.style.width = (cm.display.lineNumWidth || 1) + "px"
5999
  }
6000
  }
6001
- gutters.style.display = i ? "" : "none"
6002
- updateGutterSpace(cm)
6003
  }
6004
 
6005
  // Make sure the gutters options contains the element
6006
  // "CodeMirror-linenumbers" when the lineNumbers option is true.
6007
  function setGuttersForLineNumbers(options) {
6008
- var found = indexOf(options.gutters, "CodeMirror-linenumbers")
6009
  if (found == -1 && options.lineNumbers) {
6010
- options.gutters = options.gutters.concat(["CodeMirror-linenumbers"])
6011
  } else if (found > -1 && !options.lineNumbers) {
6012
- options.gutters = options.gutters.slice(0)
6013
- options.gutters.splice(found, 1)
6014
  }
6015
  }
6016
 
@@ -6020,8 +6033,8 @@ function setGuttersForLineNumbers(options) {
6020
  // which one is the primary selection (the one that's scrolled into
6021
  // view, that getCursor returns, etc).
6022
  var Selection = function(ranges, primIndex) {
6023
- this.ranges = ranges
6024
- this.primIndex = primIndex
6025
  };
6026
 
6027
  Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
@@ -6032,7 +6045,7 @@ Selection.prototype.equals = function (other) {
6032
  if (other == this) { return true }
6033
  if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
6034
  for (var i = 0; i < this.ranges.length; i++) {
6035
- var here = this$1.ranges[i], there = other.ranges[i]
6036
  if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
6037
  }
6038
  return true
@@ -6041,9 +6054,9 @@ Selection.prototype.equals = function (other) {
6041
  Selection.prototype.deepCopy = function () {
6042
  var this$1 = this;
6043
 
6044
- var out = []
6045
  for (var i = 0; i < this.ranges.length; i++)
6046
- { out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)) }
6047
  return new Selection(out, this.primIndex)
6048
  };
6049
 
@@ -6058,9 +6071,9 @@ Selection.prototype.somethingSelected = function () {
6058
  Selection.prototype.contains = function (pos, end) {
6059
  var this$1 = this;
6060
 
6061
- if (!end) { end = pos }
6062
  for (var i = 0; i < this.ranges.length; i++) {
6063
- var range = this$1.ranges[i]
6064
  if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
6065
  { return i }
6066
  }
@@ -6068,7 +6081,7 @@ Selection.prototype.contains = function (pos, end) {
6068
  };
6069
 
6070
  var Range = function(anchor, head) {
6071
- this.anchor = anchor; this.head = head
6072
  };
6073
 
6074
  Range.prototype.from = function () { return minPos(this.anchor, this.head) };
@@ -6079,16 +6092,16 @@ Range.prototype.empty = function () { return this.head.line == this.anchor.line
6079
  // build a selection out of it. 'Consumes' ranges array (modifying
6080
  // it).
6081
  function normalizeSelection(ranges, primIndex) {
6082
- var prim = ranges[primIndex]
6083
- ranges.sort(function (a, b) { return cmp(a.from(), b.from()); })
6084
- primIndex = indexOf(ranges, prim)
6085
  for (var i = 1; i < ranges.length; i++) {
6086
- var cur = ranges[i], prev = ranges[i - 1]
6087
  if (cmp(prev.to(), cur.from()) >= 0) {
6088
- var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to())
6089
- var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head
6090
- if (i <= primIndex) { --primIndex }
6091
- ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to))
6092
  }
6093
  }
6094
  return new Selection(ranges, primIndex)
@@ -6112,17 +6125,17 @@ function adjustForChange(pos, change) {
6112
  if (cmp(pos, change.from) < 0) { return pos }
6113
  if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
6114
 
6115
- var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch
6116
- if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch }
6117
  return Pos(line, ch)
6118
  }
6119
 
6120
  function computeSelAfterChange(doc, change) {
6121
- var out = []
6122
  for (var i = 0; i < doc.sel.ranges.length; i++) {
6123
- var range = doc.sel.ranges[i]
6124
  out.push(new Range(adjustForChange(range.anchor, change),
6125
- adjustForChange(range.head, change)))
6126
  }
6127
  return normalizeSelection(out, doc.sel.primIndex)
6128
  }
@@ -6137,19 +6150,19 @@ function offsetPos(pos, old, nw) {
6137
  // Used by replaceSelections to allow moving the selection to the
6138
  // start or around the replaced test. Hint may be "start" or "around".
6139
  function computeReplacedSel(doc, changes, hint) {
6140
- var out = []
6141
- var oldPrev = Pos(doc.first, 0), newPrev = oldPrev
6142
  for (var i = 0; i < changes.length; i++) {
6143
- var change = changes[i]
6144
- var from = offsetPos(change.from, oldPrev, newPrev)
6145
- var to = offsetPos(changeEnd(change), oldPrev, newPrev)
6146
- oldPrev = change.to
6147
- newPrev = to
6148
  if (hint == "around") {
6149
- var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0
6150
- out[i] = new Range(inv ? to : from, inv ? from : to)
6151
  } else {
6152
- out[i] = new Range(from, from)
6153
  }
6154
  }
6155
  return new Selection(out, doc.sel.primIndex)
@@ -6158,19 +6171,19 @@ function computeReplacedSel(doc, changes, hint) {
6158
  // Used to get the editor into a consistent state again when options change.
6159
 
6160
  function loadMode(cm) {
6161
- cm.doc.mode = getMode(cm.options, cm.doc.modeOption)
6162
- resetModeState(cm)
6163
  }
6164
 
6165
  function resetModeState(cm) {
6166
  cm.doc.iter(function (line) {
6167
- if (line.stateAfter) { line.stateAfter = null }
6168
- if (line.styles) { line.styles = null }
6169
- })
6170
- cm.doc.frontier = cm.doc.first
6171
- startWorker(cm, 100)
6172
- cm.state.modeGen++
6173
- if (cm.curOp) { regChange(cm) }
6174
  }
6175
 
6176
  // DOCUMENT DATA STRUCTURE
@@ -6184,105 +6197,117 @@ function isWholeLineUpdate(doc, change) {
6184
  }
6185
 
6186
  // Perform a change on the document data structure.
6187
- function updateDoc(doc, change, markedSpans, estimateHeight) {
6188
  function spansFor(n) {return markedSpans ? markedSpans[n] : null}
6189
  function update(line, text, spans) {
6190
- updateLine(line, text, spans, estimateHeight)
6191
- signalLater(line, "change", line, change)
6192
  }
6193
  function linesFor(start, end) {
6194
- var result = []
6195
  for (var i = start; i < end; ++i)
6196
- { result.push(new Line(text[i], spansFor(i), estimateHeight)) }
6197
  return result
6198
  }
6199
 
6200
- var from = change.from, to = change.to, text = change.text
6201
- var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line)
6202
- var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line
6203
 
6204
  // Adjust the line structure
6205
  if (change.full) {
6206
- doc.insert(0, linesFor(0, text.length))
6207
- doc.remove(text.length, doc.size - text.length)
6208
  } else if (isWholeLineUpdate(doc, change)) {
6209
  // This is a whole-line replace. Treated specially to make
6210
  // sure line objects move the way they are supposed to.
6211
- var added = linesFor(0, text.length - 1)
6212
- update(lastLine, lastLine.text, lastSpans)
6213
- if (nlines) { doc.remove(from.line, nlines) }
6214
- if (added.length) { doc.insert(from.line, added) }
6215
  } else if (firstLine == lastLine) {
6216
  if (text.length == 1) {
6217
- update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans)
6218
  } else {
6219
- var added$1 = linesFor(1, text.length - 1)
6220
- added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight))
6221
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
6222
- doc.insert(from.line + 1, added$1)
6223
  }
6224
  } else if (text.length == 1) {
6225
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0))
6226
- doc.remove(from.line + 1, nlines)
6227
  } else {
6228
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
6229
- update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans)
6230
- var added$2 = linesFor(1, text.length - 1)
6231
- if (nlines > 1) { doc.remove(from.line + 1, nlines - 1) }
6232
- doc.insert(from.line + 1, added$2)
6233
  }
6234
 
6235
- signalLater(doc, "change", doc, change)
6236
  }
6237
 
6238
  // Call f for all linked documents.
6239
  function linkedDocs(doc, f, sharedHistOnly) {
6240
  function propagate(doc, skip, sharedHist) {
6241
  if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
6242
- var rel = doc.linked[i]
6243
  if (rel.doc == skip) { continue }
6244
- var shared = sharedHist && rel.sharedHist
6245
  if (sharedHistOnly && !shared) { continue }
6246
- f(rel.doc, shared)
6247
- propagate(rel.doc, doc, shared)
6248
  } }
6249
  }
6250
- propagate(doc, null, true)
6251
  }
6252
 
6253
  // Attach a document to an editor.
6254
  function attachDoc(cm, doc) {
6255
  if (doc.cm) { throw new Error("This document is already in use.") }
6256
- cm.doc = doc
6257
- doc.cm = cm
6258
- estimateLineHeights(cm)
6259
- loadMode(cm)
6260
- if (!cm.options.lineWrapping) { findMaxLine(cm) }
6261
- cm.options.mode = doc.modeOption
6262
- regChange(cm)
 
 
 
 
 
 
 
 
 
 
 
 
6263
  }
6264
 
6265
  function History(startGen) {
6266
  // Arrays of change events and selections. Doing something adds an
6267
  // event to done and clears undo. Undoing moves events from done
6268
  // to undone, redoing moves them in the other direction.
6269
- this.done = []; this.undone = []
6270
- this.undoDepth = Infinity
6271
  // Used to track when changes can be merged into a single undo
6272
  // event
6273
- this.lastModTime = this.lastSelTime = 0
6274
- this.lastOp = this.lastSelOp = null
6275
- this.lastOrigin = this.lastSelOrigin = null
6276
  // Used by the isClean() method
6277
- this.generation = this.maxGeneration = startGen || 1
6278
  }
6279
 
6280
  // Create a history change event from an updateDoc-style change
6281
  // object.
6282
  function historyChangeFromChange(doc, change) {
6283
- var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)}
6284
- attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1)
6285
- linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true)
6286
  return histChange
6287
  }
6288
 
@@ -6290,8 +6315,8 @@ function historyChangeFromChange(doc, change) {
6290
  // a change event.
6291
  function clearSelectionEvents(array) {
6292
  while (array.length) {
6293
- var last = lst(array)
6294
- if (last.ranges) { array.pop() }
6295
  else { break }
6296
  }
6297
  }
@@ -6300,12 +6325,12 @@ function clearSelectionEvents(array) {
6300
  // events that are in the way.
6301
  function lastChangeEvent(hist, force) {
6302
  if (force) {
6303
- clearSelectionEvents(hist.done)
6304
  return lst(hist.done)
6305
  } else if (hist.done.length && !lst(hist.done).ranges) {
6306
  return lst(hist.done)
6307
  } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
6308
- hist.done.pop()
6309
  return lst(hist.done)
6310
  }
6311
  }
@@ -6314,10 +6339,10 @@ function lastChangeEvent(hist, force) {
6314
  // a single operation, or are close together with an origin that
6315
  // allows merging (starting with "+") into a single event.
6316
  function addChangeToHistory(doc, change, selAfter, opId) {
6317
- var hist = doc.history
6318
- hist.undone.length = 0
6319
- var time = +new Date, cur
6320
- var last
6321
 
6322
  if ((hist.lastOp == opId ||
6323
  hist.lastOrigin == change.origin && change.origin &&
@@ -6325,39 +6350,39 @@ function addChangeToHistory(doc, change, selAfter, opId) {
6325
  change.origin.charAt(0) == "*")) &&
6326
  (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
6327
  // Merge this change into the last event
6328
- last = lst(cur.changes)
6329
  if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
6330
  // Optimized case for simple insertion -- don't want to add
6331
  // new changesets for every character typed
6332
- last.to = changeEnd(change)
6333
  } else {
6334
  // Add new sub-event
6335
- cur.changes.push(historyChangeFromChange(doc, change))
6336
  }
6337
  } else {
6338
  // Can not be merged, start a new event.
6339
- var before = lst(hist.done)
6340
  if (!before || !before.ranges)
6341
- { pushSelectionToHistory(doc.sel, hist.done) }
6342
  cur = {changes: [historyChangeFromChange(doc, change)],
6343
- generation: hist.generation}
6344
- hist.done.push(cur)
6345
  while (hist.done.length > hist.undoDepth) {
6346
- hist.done.shift()
6347
- if (!hist.done[0].ranges) { hist.done.shift() }
6348
  }
6349
  }
6350
- hist.done.push(selAfter)
6351
- hist.generation = ++hist.maxGeneration
6352
- hist.lastModTime = hist.lastSelTime = time
6353
- hist.lastOp = hist.lastSelOp = opId
6354
- hist.lastOrigin = hist.lastSelOrigin = change.origin
6355
 
6356
- if (!last) { signal(doc, "historyAdded") }
6357
  }
6358
 
6359
  function selectionEventCanBeMerged(doc, origin, prev, sel) {
6360
- var ch = origin.charAt(0)
6361
  return ch == "*" ||
6362
  ch == "+" &&
6363
  prev.ranges.length == sel.ranges.length &&
@@ -6370,7 +6395,7 @@ function selectionEventCanBeMerged(doc, origin, prev, sel) {
6370
  // selection into the 'done' array when it was significantly
6371
  // different (in number of selected ranges, emptiness, or time).
6372
  function addSelectionToHistory(doc, sel, opId, options) {
6373
- var hist = doc.history, origin = options && options.origin
6374
 
6375
  // A new event is started when the previous origin does not match
6376
  // the current, or the origins don't allow matching. Origins
@@ -6380,52 +6405,52 @@ function addSelectionToHistory(doc, sel, opId, options) {
6380
  (origin && hist.lastSelOrigin == origin &&
6381
  (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
6382
  selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
6383
- { hist.done[hist.done.length - 1] = sel }
6384
  else
6385
- { pushSelectionToHistory(sel, hist.done) }
6386
 
6387
- hist.lastSelTime = +new Date
6388
- hist.lastSelOrigin = origin
6389
- hist.lastSelOp = opId
6390
  if (options && options.clearRedo !== false)
6391
- { clearSelectionEvents(hist.undone) }
6392
  }
6393
 
6394
  function pushSelectionToHistory(sel, dest) {
6395
- var top = lst(dest)
6396
  if (!(top && top.ranges && top.equals(sel)))
6397
- { dest.push(sel) }
6398
  }
6399
 
6400
  // Used to store marked span information in the history.
6401
  function attachLocalSpans(doc, change, from, to) {
6402
- var existing = change["spans_" + doc.id], n = 0
6403
  doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
6404
  if (line.markedSpans)
6405
- { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans }
6406
- ++n
6407
- })
6408
  }
6409
 
6410
  // When un/re-doing restores text containing marked spans, those
6411
  // that have been explicitly cleared should not be restored.
6412
  function removeClearedSpans(spans) {
6413
  if (!spans) { return null }
6414
- var out
6415
  for (var i = 0; i < spans.length; ++i) {
6416
- if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i) } }
6417
- else if (out) { out.push(spans[i]) }
6418
  }
6419
  return !out ? spans : out.length ? out : null
6420
  }
6421
 
6422
  // Retrieve and filter the old marked spans stored in a change event.
6423
  function getOldSpans(doc, change) {
6424
- var found = change["spans_" + doc.id]
6425
  if (!found) { return null }
6426
- var nw = []
6427
  for (var i = 0; i < change.text.length; ++i)
6428
- { nw.push(removeClearedSpans(found[i])) }
6429
  return nw
6430
  }
6431
 
@@ -6434,22 +6459,22 @@ function getOldSpans(doc, change) {
6434
  // existed in the history (so that deleting around a span and then
6435
  // undoing brings back the span).
6436
  function mergeOldSpans(doc, change) {
6437
- var old = getOldSpans(doc, change)
6438
- var stretched = stretchSpansOverChange(doc, change)
6439
  if (!old) { return stretched }
6440
  if (!stretched) { return old }
6441
 
6442
  for (var i = 0; i < old.length; ++i) {
6443
- var oldCur = old[i], stretchCur = stretched[i]
6444
  if (oldCur && stretchCur) {
6445
  spans: for (var j = 0; j < stretchCur.length; ++j) {
6446
- var span = stretchCur[j]
6447
  for (var k = 0; k < oldCur.length; ++k)
6448
  { if (oldCur[k].marker == span.marker) { continue spans } }
6449
- oldCur.push(span)
6450
  }
6451
  } else if (stretchCur) {
6452
- old[i] = stretchCur
6453
  }
6454
  }
6455
  return old
@@ -6458,22 +6483,22 @@ function mergeOldSpans(doc, change) {
6458
  // Used both to provide a JSON-safe object in .getHistory, and, when
6459
  // detaching a document, to split the history in two
6460
  function copyHistoryArray(events, newGroup, instantiateSel) {
6461
- var copy = []
6462
  for (var i = 0; i < events.length; ++i) {
6463
- var event = events[i]
6464
  if (event.ranges) {
6465
- copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event)
6466
  continue
6467
  }
6468
- var changes = event.changes, newChanges = []
6469
- copy.push({changes: newChanges})
6470
  for (var j = 0; j < changes.length; ++j) {
6471
- var change = changes[j], m = (void 0)
6472
- newChanges.push({from: change.from, to: change.to, text: change.text})
6473
  if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
6474
  if (indexOf(newGroup, Number(m[1])) > -1) {
6475
- lst(newChanges)[prop] = change[prop]
6476
- delete change[prop]
6477
  }
6478
  } } }
6479
  }
@@ -6491,14 +6516,14 @@ function copyHistoryArray(events, newGroup, instantiateSel) {
6491
  // Used for cursor motion and such.
6492
  function extendRange(doc, range, head, other) {
6493
  if (doc.cm && doc.cm.display.shift || doc.extend) {
6494
- var anchor = range.anchor
6495
  if (other) {
6496
- var posBefore = cmp(head, anchor) < 0
6497
  if (posBefore != (cmp(other, anchor) < 0)) {
6498
- anchor = head
6499
- head = other
6500
  } else if (posBefore != (cmp(head, other) < 0)) {
6501
- head = other
6502
  }
6503
  }
6504
  return new Range(anchor, head)
@@ -6509,29 +6534,29 @@ function extendRange(doc, range, head, other) {
6509
 
6510
  // Extend the primary selection range, discard the rest.
6511
  function extendSelection(doc, head, other, options) {
6512
- setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options)
6513
  }
6514
 
6515
  // Extend all selections (pos is an array of selections with length
6516
  // equal the number of selections)
6517
  function extendSelections(doc, heads, options) {
6518
- var out = []
6519
  for (var i = 0; i < doc.sel.ranges.length; i++)
6520
- { out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null) }
6521
- var newSel = normalizeSelection(out, doc.sel.primIndex)
6522
- setSelection(doc, newSel, options)
6523
  }
6524
 
6525
  // Updates a single range in the selection.
6526
  function replaceOneSelection(doc, i, range, options) {
6527
- var ranges = doc.sel.ranges.slice(0)
6528
- ranges[i] = range
6529
- setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options)
6530
  }
6531
 
6532
  // Reset the selection to a single range.
6533
  function setSimpleSelection(doc, anchor, head, options) {
6534
- setSelection(doc, simpleSelection(anchor, head), options)
6535
  }
6536
 
6537
  // Give beforeSelectionChange handlers a change to influence a
@@ -6542,90 +6567,90 @@ function filterSelectionChange(doc, sel, options) {
6542
  update: function(ranges) {
6543
  var this$1 = this;
6544
 
6545
- this.ranges = []
6546
  for (var i = 0; i < ranges.length; i++)
6547
  { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
6548
- clipPos(doc, ranges[i].head)) }
6549
  },
6550
  origin: options && options.origin
6551
- }
6552
- signal(doc, "beforeSelectionChange", doc, obj)
6553
- if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj) }
6554
  if (obj.ranges != sel.ranges) { return normalizeSelection(obj.ranges, obj.ranges.length - 1) }
6555
  else { return sel }
6556
  }
6557
 
6558
  function setSelectionReplaceHistory(doc, sel, options) {
6559
- var done = doc.history.done, last = lst(done)
6560
  if (last && last.ranges) {
6561
- done[done.length - 1] = sel
6562
- setSelectionNoUndo(doc, sel, options)
6563
  } else {
6564
- setSelection(doc, sel, options)
6565
  }
6566
  }
6567
 
6568
  // Set a new selection.
6569
  function setSelection(doc, sel, options) {
6570
- setSelectionNoUndo(doc, sel, options)
6571
- addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options)
6572
  }
6573
 
6574
  function setSelectionNoUndo(doc, sel, options) {
6575
  if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
6576
- { sel = filterSelectionChange(doc, sel, options) }
6577
 
6578
  var bias = options && options.bias ||
6579
- (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1)
6580
- setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true))
6581
 
6582
  if (!(options && options.scroll === false) && doc.cm)
6583
- { ensureCursorVisible(doc.cm) }
6584
  }
6585
 
6586
  function setSelectionInner(doc, sel) {
6587
  if (sel.equals(doc.sel)) { return }
6588
 
6589
- doc.sel = sel
6590
 
6591
  if (doc.cm) {
6592
- doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true
6593
- signalCursorActivity(doc.cm)
6594
  }
6595
- signalLater(doc, "cursorActivity", doc)
6596
  }
6597
 
6598
  // Verify that the selection does not partially select any atomic
6599
  // marked ranges.
6600
  function reCheckSelection(doc) {
6601
- setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll)
6602
  }
6603
 
6604
  // Return a selection that does not partially select any atomic
6605
  // ranges.
6606
  function skipAtomicInSelection(doc, sel, bias, mayClear) {
6607
- var out
6608
  for (var i = 0; i < sel.ranges.length; i++) {
6609
- var range = sel.ranges[i]
6610
- var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]
6611
- var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear)
6612
- var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear)
6613
  if (out || newAnchor != range.anchor || newHead != range.head) {
6614
- if (!out) { out = sel.ranges.slice(0, i) }
6615
- out[i] = new Range(newAnchor, newHead)
6616
  }
6617
  }
6618
  return out ? normalizeSelection(out, sel.primIndex) : sel
6619
  }
6620
 
6621
  function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
6622
- var line = getLine(doc, pos.line)
6623
  if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
6624
- var sp = line.markedSpans[i], m = sp.marker
6625
  if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
6626
  (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
6627
  if (mayClear) {
6628
- signal(m, "beforeCursorEnter")
6629
  if (m.explicitlyCleared) {
6630
  if (!line.markedSpans) { break }
6631
  else {--i; continue}
@@ -6634,16 +6659,16 @@ function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
6634
  if (!m.atomic) { continue }
6635
 
6636
  if (oldPos) {
6637
- var near = m.find(dir < 0 ? 1 : -1), diff = (void 0)
6638
  if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
6639
- { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null) }
6640
  if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
6641
  { return skipAtomicInner(doc, near, pos, dir, mayClear) }
6642
  }
6643
 
6644
- var far = m.find(dir < 0 ? -1 : 1)
6645
  if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight)
6646
- { far = movePos(doc, far, dir, far.line == pos.line ? line : null) }
6647
  return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
6648
  }
6649
  } }
@@ -6652,13 +6677,13 @@ function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
6652
 
6653
  // Ensure a given position is not inside an atomic range.
6654
  function skipAtomic(doc, pos, oldPos, bias, mayClear) {
6655
- var dir = bias || 1
6656
  var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
6657
  (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
6658
  skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
6659
- (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true))
6660
  if (!found) {
6661
- doc.cantEdit = true
6662
  return Pos(doc.first, 0)
6663
  }
6664
  return found
@@ -6677,7 +6702,7 @@ function movePos(doc, pos, dir, line) {
6677
  }
6678
 
6679
  function selectAll(cm) {
6680
- cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll)
6681
  }
6682
 
6683
  // UPDATING
@@ -6691,15 +6716,15 @@ function filterChange(doc, change, update) {
6691
  text: change.text,
6692
  origin: change.origin,
6693
  cancel: function () { return obj.canceled = true; }
6694
- }
6695
  if (update) { obj.update = function (from, to, text, origin) {
6696
- if (from) { obj.from = clipPos(doc, from) }
6697
- if (to) { obj.to = clipPos(doc, to) }
6698
- if (text) { obj.text = text }
6699
- if (origin !== undefined) { obj.origin = origin }
6700
- } }
6701
- signal(doc, "beforeChange", doc, obj)
6702
- if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj) }
6703
 
6704
  if (obj.canceled) { return null }
6705
  return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
@@ -6714,101 +6739,101 @@ function makeChange(doc, change, ignoreReadOnly) {
6714
  }
6715
 
6716
  if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
6717
- change = filterChange(doc, change, true)
6718
  if (!change) { return }
6719
  }
6720
 
6721
  // Possibly split or suppress the update based on the presence
6722
  // of read-only spans in its range.
6723
- var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to)
6724
  if (split) {
6725
  for (var i = split.length - 1; i >= 0; --i)
6726
- { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text}) }
6727
  } else {
6728
- makeChangeInner(doc, change)
6729
  }
6730
  }
6731
 
6732
  function makeChangeInner(doc, change) {
6733
  if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
6734
- var selAfter = computeSelAfterChange(doc, change)
6735
- addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN)
6736
 
6737
- makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change))
6738
- var rebased = []
6739
 
6740
  linkedDocs(doc, function (doc, sharedHist) {
6741
  if (!sharedHist && indexOf(rebased, doc.history) == -1) {
6742
- rebaseHist(doc.history, change)
6743
- rebased.push(doc.history)
6744
  }
6745
- makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change))
6746
- })
6747
  }
6748
 
6749
  // Revert a change stored in a document's history.
6750
  function makeChangeFromHistory(doc, type, allowSelectionOnly) {
6751
  if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) { return }
6752
 
6753
- var hist = doc.history, event, selAfter = doc.sel
6754
- var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done
6755
 
6756
  // Verify that there is a useable event (so that ctrl-z won't
6757
  // needlessly clear selection events)
6758
- var i = 0
6759
  for (; i < source.length; i++) {
6760
- event = source[i]
6761
  if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
6762
  { break }
6763
  }
6764
  if (i == source.length) { return }
6765
- hist.lastOrigin = hist.lastSelOrigin = null
6766
 
6767
  for (;;) {
6768
- event = source.pop()
6769
  if (event.ranges) {
6770
- pushSelectionToHistory(event, dest)
6771
  if (allowSelectionOnly && !event.equals(doc.sel)) {
6772
- setSelection(doc, event, {clearRedo: false})
6773
  return
6774
  }
6775
- selAfter = event
6776
  }
6777
  else { break }
6778
  }
6779
 
6780
  // Build up a reverse change object to add to the opposite history
6781
  // stack (redo when undoing, and vice versa).
6782
- var antiChanges = []
6783
- pushSelectionToHistory(selAfter, dest)
6784
- dest.push({changes: antiChanges, generation: hist.generation})
6785
- hist.generation = event.generation || ++hist.maxGeneration
6786
 
6787
- var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")
6788
 
6789
  var loop = function ( i ) {
6790
- var change = event.changes[i]
6791
- change.origin = type
6792
  if (filter && !filterChange(doc, change, false)) {
6793
- source.length = 0
6794
  return {}
6795
  }
6796
 
6797
- antiChanges.push(historyChangeFromChange(doc, change))
6798
 
6799
- var after = i ? computeSelAfterChange(doc, change) : lst(source)
6800
- makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change))
6801
- if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}) }
6802
- var rebased = []
6803
 
6804
  // Propagate to the linked documents
6805
  linkedDocs(doc, function (doc, sharedHist) {
6806
  if (!sharedHist && indexOf(rebased, doc.history) == -1) {
6807
- rebaseHist(doc.history, change)
6808
- rebased.push(doc.history)
6809
  }
6810
- makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change))
6811
- })
6812
  };
6813
 
6814
  for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
@@ -6822,15 +6847,15 @@ function makeChangeFromHistory(doc, type, allowSelectionOnly) {
6822
  // above or below them in the parent document.
6823
  function shiftDoc(doc, distance) {
6824
  if (distance == 0) { return }
6825
- doc.first += distance
6826
  doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
6827
  Pos(range.anchor.line + distance, range.anchor.ch),
6828
  Pos(range.head.line + distance, range.head.ch)
6829
- ); }), doc.sel.primIndex)
6830
  if (doc.cm) {
6831
- regChange(doc.cm, doc.first, doc.first - distance, distance)
6832
  for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
6833
- { regLineChange(doc.cm, l, "gutter") }
6834
  }
6835
  }
6836
 
@@ -6841,108 +6866,108 @@ function makeChangeSingleDoc(doc, change, selAfter, spans) {
6841
  { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
6842
 
6843
  if (change.to.line < doc.first) {
6844
- shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line))
6845
  return
6846
  }
6847
  if (change.from.line > doc.lastLine()) { return }
6848
 
6849
  // Clip the change to the size of this doc
6850
  if (change.from.line < doc.first) {
6851
- var shift = change.text.length - 1 - (doc.first - change.from.line)
6852
- shiftDoc(doc, shift)
6853
  change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
6854
- text: [lst(change.text)], origin: change.origin}
6855
  }
6856
- var last = doc.lastLine()
6857
  if (change.to.line > last) {
6858
  change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
6859
- text: [change.text[0]], origin: change.origin}
6860
  }
6861
 
6862
- change.removed = getBetween(doc, change.from, change.to)
6863
 
6864
- if (!selAfter) { selAfter = computeSelAfterChange(doc, change) }
6865
- if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans) }
6866
- else { updateDoc(doc, change, spans) }
6867
- setSelectionNoUndo(doc, selAfter, sel_dontScroll)
6868
  }
6869
 
6870
  // Handle the interaction of a change to a document with the editor
6871
  // that this document is part of.
6872
  function makeChangeSingleDocInEditor(cm, change, spans) {
6873
- var doc = cm.doc, display = cm.display, from = change.from, to = change.to
6874
 
6875
- var recomputeMaxLength = false, checkWidthStart = from.line
6876
  if (!cm.options.lineWrapping) {
6877
- checkWidthStart = lineNo(visualLine(getLine(doc, from.line)))
6878
  doc.iter(checkWidthStart, to.line + 1, function (line) {
6879
  if (line == display.maxLine) {
6880
- recomputeMaxLength = true
6881
  return true
6882
  }
6883
- })
6884
  }
6885
 
6886
  if (doc.sel.contains(change.from, change.to) > -1)
6887
- { signalCursorActivity(cm) }
6888
 
6889
- updateDoc(doc, change, spans, estimateHeight(cm))
6890
 
6891
  if (!cm.options.lineWrapping) {
6892
  doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
6893
- var len = lineLength(line)
6894
  if (len > display.maxLineLength) {
6895
- display.maxLine = line
6896
- display.maxLineLength = len
6897
- display.maxLineChanged = true
6898
- recomputeMaxLength = false
6899
  }
6900
- })
6901
- if (recomputeMaxLength) { cm.curOp.updateMaxLine = true }
6902
  }
6903
 
6904
  // Adjust frontier, schedule worker
6905
- doc.frontier = Math.min(doc.frontier, from.line)
6906
- startWorker(cm, 400)
6907
 
6908
- var lendiff = change.text.length - (to.line - from.line) - 1
6909
  // Remember that these lines changed, for updating the display
6910
  if (change.full)
6911
- { regChange(cm) }
6912
  else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
6913
- { regLineChange(cm, from.line, "text") }
6914
  else
6915
- { regChange(cm, from.line, to.line + 1, lendiff) }
6916
 
6917
- var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change")
6918
  if (changeHandler || changesHandler) {
6919
  var obj = {
6920
  from: from, to: to,
6921
  text: change.text,
6922
  removed: change.removed,
6923
  origin: change.origin
6924
- }
6925
- if (changeHandler) { signalLater(cm, "change", cm, obj) }
6926
- if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj) }
6927
  }
6928
- cm.display.selForContextMenu = null
6929
  }
6930
 
6931
  function replaceRange(doc, code, from, to, origin) {
6932
- if (!to) { to = from }
6933
- if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp }
6934
- if (typeof code == "string") { code = doc.splitLines(code) }
6935
- makeChange(doc, {from: from, to: to, text: code, origin: origin})
6936
  }
6937
 
6938
  // Rebasing/resetting history to deal with externally-sourced changes
6939
 
6940
  function rebaseHistSelSingle(pos, from, to, diff) {
6941
  if (to < pos.line) {
6942
- pos.line += diff
6943
  } else if (from < pos.line) {
6944
- pos.line = from
6945
- pos.ch = 0
6946
  }
6947
  }
6948
 
@@ -6955,47 +6980,47 @@ function rebaseHistSelSingle(pos, from, to, diff) {
6955
  // shared position objects being unsafely updated.
6956
  function rebaseHistArray(array, from, to, diff) {
6957
  for (var i = 0; i < array.length; ++i) {
6958
- var sub = array[i], ok = true
6959
  if (sub.ranges) {
6960
- if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true }
6961
  for (var j = 0; j < sub.ranges.length; j++) {
6962
- rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff)
6963
- rebaseHistSelSingle(sub.ranges[j].head, from, to, diff)
6964
  }
6965
  continue
6966
  }
6967
  for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
6968
- var cur = sub.changes[j$1]
6969
  if (to < cur.from.line) {
6970
- cur.from = Pos(cur.from.line + diff, cur.from.ch)
6971
- cur.to = Pos(cur.to.line + diff, cur.to.ch)
6972
  } else if (from <= cur.to.line) {
6973
- ok = false
6974
  break
6975
  }
6976
  }
6977
  if (!ok) {
6978
- array.splice(0, i + 1)
6979
- i = 0
6980
  }
6981
  }
6982
  }
6983
 
6984
  function rebaseHist(hist, change) {
6985
- var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1
6986
- rebaseHistArray(hist.done, from, to, diff)
6987
- rebaseHistArray(hist.undone, from, to, diff)
6988
  }
6989
 
6990
  // Utility for applying a change to a line by handle or number,
6991
  // returning the number and optionally registering the line as
6992
  // changed.
6993
  function changeLine(doc, handle, changeType, op) {
6994
- var no = handle, line = handle
6995
- if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)) }
6996
- else { no = lineNo(handle) }
6997
  if (no == null) { return null }
6998
- if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType) }
6999
  return line
7000
  }
7001
 
@@ -7015,14 +7040,14 @@ function changeLine(doc, handle, changeType, op) {
7015
  var LeafChunk = function(lines) {
7016
  var this$1 = this;
7017
 
7018
- this.lines = lines
7019
- this.parent = null
7020
- var height = 0
7021
  for (var i = 0; i < lines.length; ++i) {
7022
- lines[i].parent = this$1
7023
- height += lines[i].height
7024
  }
7025
- this.height = height
7026
  };
7027
 
7028
  LeafChunk.prototype.chunkSize = function () { return this.lines.length };
@@ -7032,17 +7057,17 @@ LeafChunk.prototype.removeInner = function (at, n) {
7032
  var this$1 = this;
7033
 
7034
  for (var i = at, e = at + n; i < e; ++i) {
7035
- var line = this$1.lines[i]
7036
- this$1.height -= line.height
7037
- cleanUpLine(line)
7038
- signalLater(line, "delete")
7039
  }
7040
- this.lines.splice(at, n)
7041
  };
7042
 
7043
  // Helper used to collapse a small branch into a single leaf.
7044
  LeafChunk.prototype.collapse = function (lines) {
7045
- lines.push.apply(lines, this.lines)
7046
  };
7047
 
7048
  // Insert the given array of lines at offset 'at', count them as
@@ -7050,9 +7075,9 @@ LeafChunk.prototype.collapse = function (lines) {
7050
  LeafChunk.prototype.insertInner = function (at, lines, height) {
7051
  var this$1 = this;
7052
 
7053
- this.height += height
7054
- this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at))
7055
- for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1 }
7056
  };
7057
 
7058
  // Used to iterate over a part of the tree.
@@ -7066,16 +7091,16 @@ LeafChunk.prototype.iterN = function (at, n, op) {
7066
  var BranchChunk = function(children) {
7067
  var this$1 = this;
7068
 
7069
- this.children = children
7070
- var size = 0, height = 0
7071
  for (var i = 0; i < children.length; ++i) {
7072
- var ch = children[i]
7073
- size += ch.chunkSize(); height += ch.height
7074
- ch.parent = this$1
7075
  }
7076
- this.size = size
7077
- this.height = height
7078
- this.parent = null
7079
  };
7080
 
7081
  BranchChunk.prototype.chunkSize = function () { return this.size };
@@ -7083,97 +7108,97 @@ BranchChunk.prototype.chunkSize = function () { return this.size };
7083
  BranchChunk.prototype.removeInner = function (at, n) {
7084
  var this$1 = this;
7085
 
7086
- this.size -= n
7087
  for (var i = 0; i < this.children.length; ++i) {
7088
- var child = this$1.children[i], sz = child.chunkSize()
7089
  if (at < sz) {
7090
- var rm = Math.min(n, sz - at), oldHeight = child.height
7091
- child.removeInner(at, rm)
7092
- this$1.height -= oldHeight - child.height
7093
- if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null }
7094
  if ((n -= rm) == 0) { break }
7095
- at = 0
7096
- } else { at -= sz }
7097
  }
7098
  // If the result is smaller than 25 lines, ensure that it is a
7099
  // single leaf node.
7100
  if (this.size - n < 25 &&
7101
  (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
7102
- var lines = []
7103
- this.collapse(lines)
7104
- this.children = [new LeafChunk(lines)]
7105
- this.children[0].parent = this
7106
  }
7107
  };
7108
 
7109
  BranchChunk.prototype.collapse = function (lines) {
7110
  var this$1 = this;
7111
 
7112
- for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines) }
7113
  };
7114
 
7115
  BranchChunk.prototype.insertInner = function (at, lines, height) {
7116
  var this$1 = this;
7117
 
7118
- this.size += lines.length
7119
- this.height += height
7120
  for (var i = 0; i < this.children.length; ++i) {
7121
- var child = this$1.children[i], sz = child.chunkSize()
7122
  if (at <= sz) {
7123
- child.insertInner(at, lines, height)
7124
  if (child.lines && child.lines.length > 50) {
7125
  // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
7126
  // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
7127
- var remaining = child.lines.length % 25 + 25
7128
  for (var pos = remaining; pos < child.lines.length;) {
7129
- var leaf = new LeafChunk(child.lines.slice(pos, pos += 25))
7130
- child.height -= leaf.height
7131
- this$1.children.splice(++i, 0, leaf)
7132
- leaf.parent = this$1
7133
  }
7134
- child.lines = child.lines.slice(0, remaining)
7135
- this$1.maybeSpill()
7136
  }
7137
  break
7138
  }
7139
- at -= sz
7140
  }
7141
  };
7142
 
7143
  // When a node has grown, check whether it should be split.
7144
  BranchChunk.prototype.maybeSpill = function () {
7145
  if (this.children.length <= 10) { return }
7146
- var me = this
7147
  do {
7148
- var spilled = me.children.splice(me.children.length - 5, 5)
7149
- var sibling = new BranchChunk(spilled)
7150
  if (!me.parent) { // Become the parent node
7151
- var copy = new BranchChunk(me.children)
7152
- copy.parent = me
7153
- me.children = [copy, sibling]
7154
- me = copy
7155
  } else {
7156
- me.size -= sibling.size
7157
- me.height -= sibling.height
7158
- var myIndex = indexOf(me.parent.children, me)
7159
- me.parent.children.splice(myIndex + 1, 0, sibling)
7160
  }
7161
- sibling.parent = me.parent
7162
  } while (me.children.length > 10)
7163
- me.parent.maybeSpill()
7164
  };
7165
 
7166
  BranchChunk.prototype.iterN = function (at, n, op) {
7167
  var this$1 = this;
7168
 
7169
  for (var i = 0; i < this.children.length; ++i) {
7170
- var child = this$1.children[i], sz = child.chunkSize()
7171
  if (at < sz) {
7172
- var used = Math.min(n, sz - at)
7173
  if (child.iterN(at, used, op)) { return true }
7174
  if ((n -= used) == 0) { break }
7175
- at = 0
7176
- } else { at -= sz }
7177
  }
7178
  };
7179
 
@@ -7183,70 +7208,70 @@ var LineWidget = function(doc, node, options) {
7183
  var this$1 = this;
7184
 
7185
  if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
7186
- { this$1[opt] = options[opt] } } }
7187
- this.doc = doc
7188
- this.node = node
7189
  };
7190
 
7191
  LineWidget.prototype.clear = function () {
7192
  var this$1 = this;
7193
 
7194
- var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line)
7195
  if (no == null || !ws) { return }
7196
- for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1) } }
7197
- if (!ws.length) { line.widgets = null }
7198
- var height = widgetHeight(this)
7199
- updateLineHeight(line, Math.max(0, line.height - height))
7200
  if (cm) {
7201
  runInOp(cm, function () {
7202
- adjustScrollWhenAboveVisible(cm, line, -height)
7203
- regLineChange(cm, no, "widget")
7204
- })
7205
- signalLater(cm, "lineWidgetCleared", cm, this, no)
7206
  }
7207
  };
7208
 
7209
  LineWidget.prototype.changed = function () {
7210
  var this$1 = this;
7211
 
7212
- var oldH = this.height, cm = this.doc.cm, line = this.line
7213
- this.height = null
7214
- var diff = widgetHeight(this) - oldH
7215
  if (!diff) { return }
7216
- updateLineHeight(line, line.height + diff)
7217
  if (cm) {
7218
  runInOp(cm, function () {
7219
- cm.curOp.forceUpdate = true
7220
- adjustScrollWhenAboveVisible(cm, line, diff)
7221
- signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line))
7222
- })
7223
  }
7224
  };
7225
- eventMixin(LineWidget)
7226
 
7227
  function adjustScrollWhenAboveVisible(cm, line, diff) {
7228
  if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
7229
- { addToScrollPos(cm, null, diff) }
7230
  }
7231
 
7232
  function addLineWidget(doc, handle, node, options) {
7233
- var widget = new LineWidget(doc, node, options)
7234
- var cm = doc.cm
7235
- if (cm && widget.noHScroll) { cm.display.alignWidgets = true }
7236
  changeLine(doc, handle, "widget", function (line) {
7237
- var widgets = line.widgets || (line.widgets = [])
7238
- if (widget.insertAt == null) { widgets.push(widget) }
7239
- else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget) }
7240
- widget.line = line
7241
  if (cm && !lineIsHidden(doc, line)) {
7242
- var aboveVisible = heightAtLine(line) < doc.scrollTop
7243
- updateLineHeight(line, line.height + widgetHeight(widget))
7244
- if (aboveVisible) { addToScrollPos(cm, null, widget.height) }
7245
- cm.curOp.forceUpdate = true
7246
  }
7247
  return true
7248
- })
7249
- signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle))
7250
  return widget
7251
  }
7252
 
@@ -7265,13 +7290,13 @@ function addLineWidget(doc, handle, node, options) {
7265
  // Collapsed markers have unique ids, in order to be able to order
7266
  // them, which is needed for uniquely determining an outer marker
7267
  // when they overlap (they may nest, but not partially overlap).
7268
- var nextMarkerId = 0
7269
 
7270
  var TextMarker = function(doc, type) {
7271
- this.lines = []
7272
- this.type = type
7273
- this.doc = doc
7274
- this.id = ++nextMarkerId
7275
  };
7276
 
7277
  // Clear the marker.
@@ -7279,44 +7304,44 @@ TextMarker.prototype.clear = function () {
7279
  var this$1 = this;
7280
 
7281
  if (this.explicitlyCleared) { return }
7282
- var cm = this.doc.cm, withOp = cm && !cm.curOp
7283
- if (withOp) { startOperation(cm) }
7284
  if (hasHandler(this, "clear")) {
7285
- var found = this.find()
7286
- if (found) { signalLater(this, "clear", found.from, found.to) }
7287
  }
7288
- var min = null, max = null
7289
  for (var i = 0; i < this.lines.length; ++i) {
7290
- var line = this$1.lines[i]
7291
- var span = getMarkedSpanFor(line.markedSpans, this$1)
7292
- if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text") }
7293
  else if (cm) {
7294
- if (span.to != null) { max = lineNo(line) }
7295
- if (span.from != null) { min = lineNo(line) }
7296
  }
7297
- line.markedSpans = removeMarkedSpan(line.markedSpans, span)
7298
  if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm)
7299
- { updateLineHeight(line, textHeight(cm.display)) }
7300
  }
7301
  if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
7302
- var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual)
7303
  if (len > cm.display.maxLineLength) {
7304
- cm.display.maxLine = visual
7305
- cm.display.maxLineLength = len
7306
- cm.display.maxLineChanged = true
7307
  }
7308
  } }
7309
 
7310
- if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1) }
7311
- this.lines.length = 0
7312
- this.explicitlyCleared = true
7313
  if (this.atomic && this.doc.cantEdit) {
7314
- this.doc.cantEdit = false
7315
- if (cm) { reCheckSelection(cm.doc) }
7316
  }
7317
- if (cm) { signalLater(cm, "markerCleared", cm, this, min, max) }
7318
- if (withOp) { endOperation(cm) }
7319
- if (this.parent) { this.parent.clear() }
7320
  };
7321
 
7322
  // Find the position of the marker in the document. Returns a {from,
@@ -7327,17 +7352,17 @@ TextMarker.prototype.clear = function () {
7327
  TextMarker.prototype.find = function (side, lineObj) {
7328
  var this$1 = this;
7329
 
7330
- if (side == null && this.type == "bookmark") { side = 1 }
7331
- var from, to
7332
  for (var i = 0; i < this.lines.length; ++i) {
7333
- var line = this$1.lines[i]
7334
- var span = getMarkedSpanFor(line.markedSpans, this$1)
7335
  if (span.from != null) {
7336
- from = Pos(lineObj ? line : lineNo(line), span.from)
7337
  if (side == -1) { return from }
7338
  }
7339
  if (span.to != null) {
7340
- to = Pos(lineObj ? line : lineNo(line), span.to)
7341
  if (side == 1) { return to }
7342
  }
7343
  }
@@ -7349,44 +7374,43 @@ TextMarker.prototype.find = function (side, lineObj) {
7349
  TextMarker.prototype.changed = function () {
7350
  var this$1 = this;
7351
 
7352
- var pos = this.find(-1, true), widget = this, cm = this.doc.cm
7353
  if (!pos || !cm) { return }
7354
  runInOp(cm, function () {
7355
- var line = pos.line, lineN = lineNo(pos.line)
7356
- var view = findViewForLine(cm, lineN)
7357
  if (view) {
7358
- clearLineMeasurementCacheFor(view)
7359
- cm.curOp.selectionChanged = cm.curOp.forceUpdate = true
7360
  }
7361
- cm.curOp.updateMaxLine = true
7362
  if (!lineIsHidden(widget.doc, line) && widget.height != null) {
7363
- var oldHeight = widget.height
7364
- widget.height = null
7365
- var dHeight = widgetHeight(widget) - oldHeight
7366
  if (dHeight)
7367
- { updateLineHeight(line, line.height + dHeight) }
7368
  }
7369
- signalLater(cm, "markerChanged", cm, this$1)
7370
- })
7371
  };
7372
 
7373
  TextMarker.prototype.attachLine = function (line) {
7374
  if (!this.lines.length && this.doc.cm) {
7375
- var op = this.doc.cm.curOp
7376
  if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
7377
- { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this) }
7378
  }
7379
- this.lines.push(line)
7380
  };
7381
 
7382
  TextMarker.prototype.detachLine = function (line) {
7383
- this.lines.splice(indexOf(this.lines, line), 1)
7384
  if (!this.lines.length && this.doc.cm) {
7385
- var op = this.doc.cm.curOp
7386
- ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this)
7387
  }
7388
  };
7389
- eventMixin(TextMarker)
7390
 
7391
  // Create a marker, wire it up to the right lines, and
7392
  function markText(doc, from, to, options, type) {
@@ -7397,64 +7421,63 @@ function markText(doc, from, to, options, type) {
7397
  // Ensure we are in an operation.
7398
  if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
7399
 
7400
- var marker = new TextMarker(doc, type), diff = cmp(from, to)
7401
- if (options) { copyObj(options, marker, false) }
7402
  // Don't connect empty markers unless clearWhenEmpty is false
7403
  if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
7404
  { return marker }
7405
  if (marker.replacedWith) {
7406
  // Showing up as a widget implies collapsed (widget replaces text)
7407
- marker.collapsed = true
7408
- marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget")
7409
- marker.widgetNode.setAttribute("role", "presentation") // hide from accessibility tree
7410
- if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true") }
7411
- if (options.insertLeft) { marker.widgetNode.insertLeft = true }
7412
  }
7413
  if (marker.collapsed) {
7414
  if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
7415
  from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
7416
  { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
7417
- seeCollapsedSpans()
7418
  }
7419
 
7420
  if (marker.addToHistory)
7421
- { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN) }
7422
 
7423
- var curLine = from.line, cm = doc.cm, updateMaxLine
7424
  doc.iter(curLine, to.line + 1, function (line) {
7425
  if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
7426
- { updateMaxLine = true }
7427
- if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0) }
7428
  addMarkedSpan(line, new MarkedSpan(marker,
7429
  curLine == from.line ? from.ch : null,
7430
- curLine == to.line ? to.ch : null))
7431
- ++curLine
7432
- })
7433
  // lineIsHidden depends on the presence of the spans, so needs a second pass
7434
  if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
7435
- if (lineIsHidden(doc, line)) { updateLineHeight(line, 0) }
7436
- }) }
7437
 
7438
- if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }) }
7439
 
7440
  if (marker.readOnly) {
7441
- seeReadOnlySpans()
7442
  if (doc.history.done.length || doc.history.undone.length)
7443
- { doc.clearHistory() }
7444
  }
7445
  if (marker.collapsed) {
7446
- marker.id = ++nextMarkerId
7447
- marker.atomic = true
7448
  }
7449
  if (cm) {
7450
  // Sync editor state
7451
- if (updateMaxLine) { cm.curOp.updateMaxLine = true }
7452
  if (marker.collapsed)
7453
- { regChange(cm, from.line, to.line + 1) }
7454
  else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
7455
- { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text") } }
7456
- if (marker.atomic) { reCheckSelection(cm.doc) }
7457
- signalLater(cm, "markerAdded", cm, marker)
7458
  }
7459
  return marker
7460
  }
@@ -7467,39 +7490,39 @@ function markText(doc, from, to, options, type) {
7467
  var SharedTextMarker = function(markers, primary) {
7468
  var this$1 = this;
7469
 
7470
- this.markers = markers
7471
- this.primary = primary
7472
  for (var i = 0; i < markers.length; ++i)
7473
- { markers[i].parent = this$1 }
7474
  };
7475
 
7476
  SharedTextMarker.prototype.clear = function () {
7477
  var this$1 = this;
7478
 
7479
  if (this.explicitlyCleared) { return }
7480
- this.explicitlyCleared = true
7481
  for (var i = 0; i < this.markers.length; ++i)
7482
- { this$1.markers[i].clear() }
7483
- signalLater(this, "clear")
7484
  };
7485
 
7486
  SharedTextMarker.prototype.find = function (side, lineObj) {
7487
  return this.primary.find(side, lineObj)
7488
  };
7489
- eventMixin(SharedTextMarker)
7490
 
7491
  function markTextShared(doc, from, to, options, type) {
7492
- options = copyObj(options)
7493
- options.shared = false
7494
- var markers = [markText(doc, from, to, options, type)], primary = markers[0]
7495
- var widget = options.widgetNode
7496
  linkedDocs(doc, function (doc) {
7497
- if (widget) { options.widgetNode = widget.cloneNode(true) }
7498
- markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type))
7499
  for (var i = 0; i < doc.linked.length; ++i)
7500
  { if (doc.linked[i].isParent) { return } }
7501
- primary = lst(markers)
7502
- })
7503
  return new SharedTextMarker(markers, primary)
7504
  }
7505
 
@@ -7509,25 +7532,25 @@ function findSharedMarkers(doc) {
7509
 
7510
  function copySharedMarkers(doc, markers) {
7511
  for (var i = 0; i < markers.length; i++) {
7512
- var marker = markers[i], pos = marker.find()
7513
- var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to)
7514
  if (cmp(mFrom, mTo)) {
7515
- var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type)
7516
- marker.markers.push(subMark)
7517
- subMark.parent = marker
7518
  }
7519
  }
7520
  }
7521
 
7522
  function detachSharedMarkers(markers) {
7523
  var loop = function ( i ) {
7524
- var marker = markers[i], linked = [marker.primary.doc]
7525
- linkedDocs(marker.primary.doc, function (d) { return linked.push(d); })
7526
  for (var j = 0; j < marker.markers.length; j++) {
7527
- var subMarker = marker.markers[j]
7528
  if (indexOf(linked, subMarker.doc) == -1) {
7529
- subMarker.parent = null
7530
- marker.markers.splice(j--, 1)
7531
  }
7532
  }
7533
  };
@@ -7535,29 +7558,30 @@ function detachSharedMarkers(markers) {
7535
  for (var i = 0; i < markers.length; i++) loop( i );
7536
  }
7537
 
7538
- var nextDocId = 0
7539
- var Doc = function(text, mode, firstLine, lineSep) {
7540
- if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep) }
7541
- if (firstLine == null) { firstLine = 0 }
7542
-
7543
- BranchChunk.call(this, [new LeafChunk([new Line("", null)])])
7544
- this.first = firstLine
7545
- this.scrollTop = this.scrollLeft = 0
7546
- this.cantEdit = false
7547
- this.cleanGeneration = 1
7548
- this.frontier = firstLine
7549
- var start = Pos(firstLine, 0)
7550
- this.sel = simpleSelection(start)
7551
- this.history = new History(null)
7552
- this.id = ++nextDocId
7553
- this.modeOption = mode
7554
- this.lineSep = lineSep
7555
- this.extend = false
7556
-
7557
- if (typeof text == "string") { text = this.splitLines(text) }
7558
- updateDoc(this, {from: start, to: start, text: text})
7559
- setSelection(this, simpleSelection(start), sel_dontScroll)
7560
- }
 
7561
 
7562
  Doc.prototype = createObj(BranchChunk.prototype, {
7563
  constructor: Doc,
@@ -7566,39 +7590,39 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7566
  // three, it iterates over the range given by the first two (with
7567
  // the second being non-inclusive).
7568
  iter: function(from, to, op) {
7569
- if (op) { this.iterN(from - this.first, to - from, op) }
7570
- else { this.iterN(this.first, this.first + this.size, from) }
7571
  },
7572
 
7573
  // Non-public interface for adding and removing lines.
7574
  insert: function(at, lines) {
7575
- var height = 0
7576
- for (var i = 0; i < lines.length; ++i) { height += lines[i].height }
7577
- this.insertInner(at - this.first, lines, height)
7578
  },
7579
- remove: function(at, n) { this.removeInner(at - this.first, n) },
7580
 
7581
  // From here, the methods are part of the public interface. Most
7582
  // are also available from CodeMirror (editor) instances.
7583
 
7584
  getValue: function(lineSep) {
7585
- var lines = getLines(this, this.first, this.first + this.size)
7586
  if (lineSep === false) { return lines }
7587
  return lines.join(lineSep || this.lineSeparator())
7588
  },
7589
  setValue: docMethodOp(function(code) {
7590
- var top = Pos(this.first, 0), last = this.first + this.size - 1
7591
  makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
7592
- text: this.splitLines(code), origin: "setValue", full: true}, true)
7593
- setSelection(this, simpleSelection(top))
7594
  }),
7595
  replaceRange: function(code, from, to, origin) {
7596
- from = clipPos(this, from)
7597
- to = to ? clipPos(this, to) : from
7598
- replaceRange(this, code, from, to, origin)
7599
  },
7600
  getRange: function(from, to, lineSep) {
7601
- var lines = getBetween(this, clipPos(this, from), clipPos(this, to))
7602
  if (lineSep === false) { return lines }
7603
  return lines.join(lineSep || this.lineSeparator())
7604
  },
@@ -7609,7 +7633,7 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7609
  getLineNumber: function(line) {return lineNo(line)},
7610
 
7611
  getLineHandleVisualStart: function(line) {
7612
- if (typeof line == "number") { line = getLine(this, line) }
7613
  return visualLine(line)
7614
  },
7615
 
@@ -7620,56 +7644,56 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7620
  clipPos: function(pos) {return clipPos(this, pos)},
7621
 
7622
  getCursor: function(start) {
7623
- var range = this.sel.primary(), pos
7624
- if (start == null || start == "head") { pos = range.head }
7625
- else if (start == "anchor") { pos = range.anchor }
7626
- else if (start == "end" || start == "to" || start === false) { pos = range.to() }
7627
- else { pos = range.from() }
7628
  return pos
7629
  },
7630
  listSelections: function() { return this.sel.ranges },
7631
  somethingSelected: function() {return this.sel.somethingSelected()},
7632
 
7633
  setCursor: docMethodOp(function(line, ch, options) {
7634
- setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options)
7635
  }),
7636
  setSelection: docMethodOp(function(anchor, head, options) {
7637
- setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options)
7638
  }),
7639
  extendSelection: docMethodOp(function(head, other, options) {
7640
- extendSelection(this, clipPos(this, head), other && clipPos(this, other), options)
7641
  }),
7642
  extendSelections: docMethodOp(function(heads, options) {
7643
- extendSelections(this, clipPosArray(this, heads), options)
7644
  }),
7645
  extendSelectionsBy: docMethodOp(function(f, options) {
7646
- var heads = map(this.sel.ranges, f)
7647
- extendSelections(this, clipPosArray(this, heads), options)
7648
  }),
7649
  setSelections: docMethodOp(function(ranges, primary, options) {
7650
  var this$1 = this;
7651
 
7652
  if (!ranges.length) { return }
7653
- var out = []
7654
  for (var i = 0; i < ranges.length; i++)
7655
  { out[i] = new Range(clipPos(this$1, ranges[i].anchor),
7656
- clipPos(this$1, ranges[i].head)) }
7657
- if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex) }
7658
- setSelection(this, normalizeSelection(out, primary), options)
7659
  }),
7660
  addSelection: docMethodOp(function(anchor, head, options) {
7661
- var ranges = this.sel.ranges.slice(0)
7662
- ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)))
7663
- setSelection(this, normalizeSelection(ranges, ranges.length - 1), options)
7664
  }),
7665
 
7666
  getSelection: function(lineSep) {
7667
  var this$1 = this;
7668
 
7669
- var ranges = this.sel.ranges, lines
7670
  for (var i = 0; i < ranges.length; i++) {
7671
- var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
7672
- lines = lines ? lines.concat(sel) : sel
7673
  }
7674
  if (lineSep === false) { return lines }
7675
  else { return lines.join(lineSep || this.lineSeparator()) }
@@ -7677,56 +7701,56 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7677
  getSelections: function(lineSep) {
7678
  var this$1 = this;
7679
 
7680
- var parts = [], ranges = this.sel.ranges
7681
  for (var i = 0; i < ranges.length; i++) {
7682
- var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
7683
- if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()) }
7684
- parts[i] = sel
7685
  }
7686
  return parts
7687
  },
7688
  replaceSelection: function(code, collapse, origin) {
7689
- var dup = []
7690
  for (var i = 0; i < this.sel.ranges.length; i++)
7691
- { dup[i] = code }
7692
- this.replaceSelections(dup, collapse, origin || "+input")
7693
  },
7694
  replaceSelections: docMethodOp(function(code, collapse, origin) {
7695
  var this$1 = this;
7696
 
7697
- var changes = [], sel = this.sel
7698
  for (var i = 0; i < sel.ranges.length; i++) {
7699
- var range = sel.ranges[i]
7700
- changes[i] = {from: range.from(), to: range.to(), text: this$1.splitLines(code[i]), origin: origin}
7701
  }
7702
- var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse)
7703
  for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
7704
- { makeChange(this$1, changes[i$1]) }
7705
- if (newSel) { setSelectionReplaceHistory(this, newSel) }
7706
- else if (this.cm) { ensureCursorVisible(this.cm) }
7707
  }),
7708
- undo: docMethodOp(function() {makeChangeFromHistory(this, "undo")}),
7709
- redo: docMethodOp(function() {makeChangeFromHistory(this, "redo")}),
7710
- undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true)}),
7711
- redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true)}),
7712
 
7713
- setExtending: function(val) {this.extend = val},
7714
  getExtending: function() {return this.extend},
7715
 
7716
  historySize: function() {
7717
- var hist = this.history, done = 0, undone = 0
7718
- for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done } }
7719
- for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone } }
7720
  return {undo: done, redo: undone}
7721
  },
7722
- clearHistory: function() {this.history = new History(this.history.maxGeneration)},
7723
 
7724
  markClean: function() {
7725
- this.cleanGeneration = this.changeGeneration(true)
7726
  },
7727
  changeGeneration: function(forceSplit) {
7728
  if (forceSplit)
7729
- { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null }
7730
  return this.history.generation
7731
  },
7732
  isClean: function (gen) {
@@ -7738,16 +7762,16 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7738
  undone: copyHistoryArray(this.history.undone)}
7739
  },
7740
  setHistory: function(histData) {
7741
- var hist = this.history = new History(this.history.maxGeneration)
7742
- hist.done = copyHistoryArray(histData.done.slice(0), null, true)
7743
- hist.undone = copyHistoryArray(histData.undone.slice(0), null, true)
7744
  },
7745
 
7746
  setGutterMarker: docMethodOp(function(line, gutterID, value) {
7747
  return changeLine(this, line, "gutter", function (line) {
7748
- var markers = line.gutterMarkers || (line.gutterMarkers = {})
7749
- markers[gutterID] = value
7750
- if (!value && isEmpty(markers)) { line.gutterMarkers = null }
7751
  return true
7752
  })
7753
  }),
@@ -7758,23 +7782,23 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7758
  this.iter(function (line) {
7759
  if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
7760
  changeLine(this$1, line, "gutter", function () {
7761
- line.gutterMarkers[gutterID] = null
7762
- if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null }
7763
  return true
7764
- })
7765
  }
7766
- })
7767
  }),
7768
 
7769
  lineInfo: function(line) {
7770
- var n
7771
  if (typeof line == "number") {
7772
  if (!isLine(this, line)) { return null }
7773
- n = line
7774
- line = getLine(this, line)
7775
  if (!line) { return null }
7776
  } else {
7777
- n = lineNo(line)
7778
  if (n == null) { return null }
7779
  }
7780
  return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
@@ -7786,10 +7810,10 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7786
  return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
7787
  var prop = where == "text" ? "textClass"
7788
  : where == "background" ? "bgClass"
7789
- : where == "gutter" ? "gutterClass" : "wrapClass"
7790
- if (!line[prop]) { line[prop] = cls }
7791
  else if (classTest(cls).test(line[prop])) { return false }
7792
- else { line[prop] += " " + cls }
7793
  return true
7794
  })
7795
  }),
@@ -7797,15 +7821,15 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7797
  return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
7798
  var prop = where == "text" ? "textClass"
7799
  : where == "background" ? "bgClass"
7800
- : where == "gutter" ? "gutterClass" : "wrapClass"
7801
- var cur = line[prop]
7802
  if (!cur) { return false }
7803
- else if (cls == null) { line[prop] = null }
7804
  else {
7805
- var found = cur.match(classTest(cls))
7806
  if (!found) { return false }
7807
- var end = found.index + found[0].length
7808
- line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null
7809
  }
7810
  return true
7811
  })
@@ -7814,7 +7838,7 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7814
  addLineWidget: docMethodOp(function(handle, node, options) {
7815
  return addLineWidget(this, handle, node, options)
7816
  }),
7817
- removeLineWidget: function(widget) { widget.clear() },
7818
 
7819
  markText: function(from, to, options) {
7820
  return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
@@ -7823,116 +7847,116 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7823
  var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
7824
  insertLeft: options && options.insertLeft,
7825
  clearWhenEmpty: false, shared: options && options.shared,
7826
- handleMouseEvents: options && options.handleMouseEvents}
7827
- pos = clipPos(this, pos)
7828
  return markText(this, pos, pos, realOpts, "bookmark")
7829
  },
7830
  findMarksAt: function(pos) {
7831
- pos = clipPos(this, pos)
7832
- var markers = [], spans = getLine(this, pos.line).markedSpans
7833
  if (spans) { for (var i = 0; i < spans.length; ++i) {
7834
- var span = spans[i]
7835
  if ((span.from == null || span.from <= pos.ch) &&
7836
  (span.to == null || span.to >= pos.ch))
7837
- { markers.push(span.marker.parent || span.marker) }
7838
  } }
7839
  return markers
7840
  },
7841
  findMarks: function(from, to, filter) {
7842
- from = clipPos(this, from); to = clipPos(this, to)
7843
- var found = [], lineNo = from.line
7844
  this.iter(from.line, to.line + 1, function (line) {
7845
- var spans = line.markedSpans
7846
  if (spans) { for (var i = 0; i < spans.length; i++) {
7847
- var span = spans[i]
7848
- if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
7849
- span.from == null && lineNo != from.line ||
7850
- span.from != null && lineNo == to.line && span.from >= to.ch) &&
7851
  (!filter || filter(span.marker)))
7852
- { found.push(span.marker.parent || span.marker) }
7853
  } }
7854
- ++lineNo
7855
- })
7856
  return found
7857
  },
7858
  getAllMarks: function() {
7859
- var markers = []
7860
  this.iter(function (line) {
7861
- var sps = line.markedSpans
7862
  if (sps) { for (var i = 0; i < sps.length; ++i)
7863
- { if (sps[i].from != null) { markers.push(sps[i].marker) } } }
7864
- })
7865
  return markers
7866
  },
7867
 
7868
  posFromIndex: function(off) {
7869
- var ch, lineNo = this.first, sepSize = this.lineSeparator().length
7870
  this.iter(function (line) {
7871
- var sz = line.text.length + sepSize
7872
  if (sz > off) { ch = off; return true }
7873
- off -= sz
7874
- ++lineNo
7875
- })
7876
- return clipPos(this, Pos(lineNo, ch))
7877
  },
7878
  indexFromPos: function (coords) {
7879
- coords = clipPos(this, coords)
7880
- var index = coords.ch
7881
  if (coords.line < this.first || coords.ch < 0) { return 0 }
7882
- var sepSize = this.lineSeparator().length
7883
  this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
7884
- index += line.text.length + sepSize
7885
- })
7886
  return index
7887
  },
7888
 
7889
  copy: function(copyHistory) {
7890
  var doc = new Doc(getLines(this, this.first, this.first + this.size),
7891
- this.modeOption, this.first, this.lineSep)
7892
- doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft
7893
- doc.sel = this.sel
7894
- doc.extend = false
7895
  if (copyHistory) {
7896
- doc.history.undoDepth = this.history.undoDepth
7897
- doc.setHistory(this.getHistory())
7898
  }
7899
  return doc
7900
  },
7901
 
7902
  linkedDoc: function(options) {
7903
- if (!options) { options = {} }
7904
- var from = this.first, to = this.first + this.size
7905
- if (options.from != null && options.from > from) { from = options.from }
7906
- if (options.to != null && options.to < to) { to = options.to }
7907
- var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep)
7908
  if (options.sharedHist) { copy.history = this.history
7909
- ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist})
7910
- copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}]
7911
- copySharedMarkers(copy, findSharedMarkers(this))
7912
  return copy
7913
  },
7914
  unlinkDoc: function(other) {
7915
  var this$1 = this;
7916
 
7917
- if (other instanceof CodeMirror) { other = other.doc }
7918
  if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
7919
- var link = this$1.linked[i]
7920
  if (link.doc != other) { continue }
7921
- this$1.linked.splice(i, 1)
7922
- other.unlinkDoc(this$1)
7923
- detachSharedMarkers(findSharedMarkers(this$1))
7924
  break
7925
  } }
7926
  // If the histories were shared, split them again
7927
  if (other.history == this.history) {
7928
- var splitIds = [other.id]
7929
- linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true)
7930
- other.history = new History(null)
7931
- other.history.done = copyHistoryArray(this.history.done, splitIds)
7932
- other.history.undone = copyHistoryArray(this.history.undone, splitIds)
7933
  }
7934
  },
7935
- iterLinkedDocs: function(f) {linkedDocs(this, f)},
7936
 
7937
  getMode: function() {return this.mode},
7938
  getEditor: function() {return this.cm},
@@ -7941,70 +7965,78 @@ Doc.prototype = createObj(BranchChunk.prototype, {
7941
  if (this.lineSep) { return str.split(this.lineSep) }
7942
  return splitLinesAuto(str)
7943
  },
7944
- lineSeparator: function() { return this.lineSep || "\n" }
7945
- })
 
 
 
 
 
 
 
 
7946
 
7947
  // Public alias.
7948
- Doc.prototype.eachLine = Doc.prototype.iter
7949
 
7950
  // Kludge to work around strange IE behavior where it'll sometimes
7951
  // re-fire a series of drag-related events right after the drop (#1551)
7952
- var lastDrop = 0
7953
 
7954
  function onDrop(e) {
7955
- var cm = this
7956
- clearDragCursor(cm)
7957
  if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
7958
  { return }
7959
- e_preventDefault(e)
7960
- if (ie) { lastDrop = +new Date }
7961
- var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files
7962
  if (!pos || cm.isReadOnly()) { return }
7963
  // Might be a file drop, in which case we simply extract the text
7964
  // and insert it.
7965
  if (files && files.length && window.FileReader && window.File) {
7966
- var n = files.length, text = Array(n), read = 0
7967
  var loadFile = function (file, i) {
7968
  if (cm.options.allowDropFileTypes &&
7969
  indexOf(cm.options.allowDropFileTypes, file.type) == -1)
7970
  { return }
7971
 
7972
- var reader = new FileReader
7973
  reader.onload = operation(cm, function () {
7974
- var content = reader.result
7975
- if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = "" }
7976
- text[i] = content
7977
  if (++read == n) {
7978
- pos = clipPos(cm.doc, pos)
7979
  var change = {from: pos, to: pos,
7980
  text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
7981
- origin: "paste"}
7982
- makeChange(cm.doc, change)
7983
- setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)))
7984
  }
7985
- })
7986
- reader.readAsText(file)
7987
- }
7988
- for (var i = 0; i < n; ++i) { loadFile(files[i], i) }
7989
  } else { // Normal drop
7990
  // Don't do a replace if the drop happened inside of the selected text.
7991
  if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
7992
- cm.state.draggingText(e)
7993
  // Ensure the editor is re-focused
7994
- setTimeout(function () { return cm.display.input.focus(); }, 20)
7995
  return
7996
  }
7997
  try {
7998
- var text$1 = e.dataTransfer.getData("Text")
7999
  if (text$1) {
8000
- var selected
8001
  if (cm.state.draggingText && !cm.state.draggingText.copy)
8002
- { selected = cm.listSelections() }
8003
- setSelectionNoUndo(cm.doc, simpleSelection(pos, pos))
8004
  if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
8005
- { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag") } }
8006
- cm.replaceSelection(text$1, "around", "paste")
8007
- cm.display.input.focus()
8008
  }
8009
  }
8010
  catch(e){}
@@ -8015,41 +8047,41 @@ function onDragStart(cm, e) {
8015
  if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
8016
  if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
8017
 
8018
- e.dataTransfer.setData("Text", cm.getSelection())
8019
- e.dataTransfer.effectAllowed = "copyMove"
8020
 
8021
  // Use dummy image instead of default browsers image.
8022
  // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
8023
  if (e.dataTransfer.setDragImage && !safari) {
8024
- var img = elt("img", null, null, "position: fixed; left: 0; top: 0;")
8025
- img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
8026
  if (presto) {
8027
- img.width = img.height = 1
8028
- cm.display.wrapper.appendChild(img)
8029
  // Force a relayout, or Opera won't use our image for some obscure reason
8030
- img._top = img.offsetTop
8031
  }
8032
- e.dataTransfer.setDragImage(img, 0, 0)
8033
- if (presto) { img.parentNode.removeChild(img) }
8034
  }
8035
  }
8036
 
8037
  function onDragOver(cm, e) {
8038
- var pos = posFromMouse(cm, e)
8039
  if (!pos) { return }
8040
- var frag = document.createDocumentFragment()
8041
- drawSelectionCursor(cm, pos, frag)
8042
  if (!cm.display.dragCursor) {
8043
- cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors")
8044
- cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv)
8045
  }
8046
- removeChildrenAndAdd(cm.display.dragCursor, frag)
8047
  }
8048
 
8049
  function clearDragCursor(cm) {
8050
  if (cm.display.dragCursor) {
8051
- cm.display.lineSpace.removeChild(cm.display.dragCursor)
8052
- cm.display.dragCursor = null
8053
  }
8054
  }
8055
 
@@ -8059,40 +8091,40 @@ function clearDragCursor(cm) {
8059
 
8060
  function forEachCodeMirror(f) {
8061
  if (!document.body.getElementsByClassName) { return }
8062
- var byClass = document.body.getElementsByClassName("CodeMirror")
8063
  for (var i = 0; i < byClass.length; i++) {
8064
- var cm = byClass[i].CodeMirror
8065
- if (cm) { f(cm) }
8066
  }
8067
  }
8068
 
8069
- var globalsRegistered = false
8070
  function ensureGlobalHandlers() {
8071
  if (globalsRegistered) { return }
8072
- registerGlobalHandlers()
8073
- globalsRegistered = true
8074
  }
8075
  function registerGlobalHandlers() {
8076
  // When the window resizes, we need to refresh active editors.
8077
- var resizeTimer
8078
  on(window, "resize", function () {
8079
  if (resizeTimer == null) { resizeTimer = setTimeout(function () {
8080
- resizeTimer = null
8081
- forEachCodeMirror(onResize)
8082
- }, 100) }
8083
- })
8084
  // When the window loses focus, we want to show the editor as blurred
8085
- on(window, "blur", function () { return forEachCodeMirror(onBlur); })
8086
  }
8087
  // Called when the window resizes
8088
  function onResize(cm) {
8089
- var d = cm.display
8090
  if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
8091
  { return }
8092
  // Might be a text scaling operation, clear size caches.
8093
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
8094
- d.scrollbarsClipped = false
8095
- cm.setSize()
8096
  }
8097
 
8098
  var keyNames = {
@@ -8104,16 +8136,16 @@ var keyNames = {
8104
  173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
8105
  221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
8106
  63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
8107
- }
8108
 
8109
  // Number keys
8110
- for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i) }
8111
  // Alphabetic keys
8112
- for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1) }
8113
  // Function keys
8114
- for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2 }
8115
 
8116
- var keyMap = {}
8117
 
8118
  keyMap.basic = {
8119
  "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
@@ -8122,7 +8154,7 @@ keyMap.basic = {
8122
  "Tab": "defaultTab", "Shift-Tab": "indentAuto",
8123
  "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
8124
  "Esc": "singleSelection"
8125
- }
8126
  // Note that the save and find-related commands aren't defined by
8127
  // default. User code or addons can define them. Unknown commands
8128
  // are simply ignored.
@@ -8135,7 +8167,7 @@ keyMap.pcDefault = {
8135
  "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
8136
  "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
8137
  fallthrough: "basic"
8138
- }
8139
  // Very basic readline/emacs-style bindings, which are standard on Mac.
8140
  keyMap.emacsy = {
8141
  "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
@@ -8143,7 +8175,7 @@ keyMap.emacsy = {
8143
  "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
8144
  "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
8145
  "Ctrl-O": "openLine"
8146
- }
8147
  keyMap.macDefault = {
8148
  "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
8149
  "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
@@ -8153,27 +8185,27 @@ keyMap.macDefault = {
8153
  "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
8154
  "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
8155
  fallthrough: ["basic", "emacsy"]
8156
- }
8157
- keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault
8158
 
8159
  // KEYMAP DISPATCH
8160
 
8161
  function normalizeKeyName(name) {
8162
- var parts = name.split(/-(?!$)/)
8163
- name = parts[parts.length - 1]
8164
- var alt, ctrl, shift, cmd
8165
  for (var i = 0; i < parts.length - 1; i++) {
8166
- var mod = parts[i]
8167
- if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true }
8168
- else if (/^a(lt)?$/i.test(mod)) { alt = true }
8169
- else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true }
8170
- else if (/^s(hift)?$/i.test(mod)) { shift = true }
8171
  else { throw new Error("Unrecognized modifier name: " + mod) }
8172
  }
8173
- if (alt) { name = "Alt-" + name }
8174
- if (ctrl) { name = "Ctrl-" + name }
8175
- if (cmd) { name = "Cmd-" + name }
8176
- if (shift) { name = "Shift-" + name }
8177
  return name
8178
  }
8179
 
@@ -8183,44 +8215,44 @@ function normalizeKeyName(name) {
8183
  // new normalized keymap, and then updates the old object to reflect
8184
  // this.
8185
  function normalizeKeyMap(keymap) {
8186
- var copy = {}
8187
  for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
8188
- var value = keymap[keyname]
8189
  if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
8190
  if (value == "...") { delete keymap[keyname]; continue }
8191
 
8192
- var keys = map(keyname.split(" "), normalizeKeyName)
8193
  for (var i = 0; i < keys.length; i++) {
8194
- var val = (void 0), name = (void 0)
8195
  if (i == keys.length - 1) {
8196
- name = keys.join(" ")
8197
- val = value
8198
  } else {
8199
- name = keys.slice(0, i + 1).join(" ")
8200
- val = "..."
8201
  }
8202
- var prev = copy[name]
8203
- if (!prev) { copy[name] = val }
8204
  else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
8205
  }
8206
- delete keymap[keyname]
8207
  } }
8208
- for (var prop in copy) { keymap[prop] = copy[prop] }
8209
  return keymap
8210
  }
8211
 
8212
- function lookupKey(key, map, handle, context) {
8213
- map = getKeyMap(map)
8214
- var found = map.call ? map.call(key, context) : map[key]
8215
  if (found === false) { return "nothing" }
8216
  if (found === "...") { return "multi" }
8217
  if (found != null && handle(found)) { return "handled" }
8218
 
8219
- if (map.fallthrough) {
8220
- if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
8221
- { return lookupKey(key, map.fallthrough, handle, context) }
8222
- for (var i = 0; i < map.fallthrough.length; i++) {
8223
- var result = lookupKey(key, map.fallthrough[i], handle, context)
8224
  if (result) { return result }
8225
  }
8226
  }
@@ -8229,19 +8261,19 @@ function lookupKey(key, map, handle, context) {
8229
  // Modifier key presses don't count as 'real' key presses for the
8230
  // purpose of keymap fallthrough.
8231
  function isModifierKey(value) {
8232
- var name = typeof value == "string" ? value : keyNames[value.keyCode]
8233
  return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
8234
  }
8235
 
8236
  // Look up the name of a key as indicated by an event object.
8237
  function keyName(event, noShift) {
8238
  if (presto && event.keyCode == 34 && event["char"]) { return false }
8239
- var base = keyNames[event.keyCode], name = base
8240
  if (name == null || event.altGraphKey) { return false }
8241
- if (event.altKey && base != "Alt") { name = "Alt-" + name }
8242
- if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name }
8243
- if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name }
8244
- if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name }
8245
  return name
8246
  }
8247
 
@@ -8252,26 +8284,26 @@ function getKeyMap(val) {
8252
  // Helper for deleting text near the selection(s), used to implement
8253
  // backspace, delete, and similar functionality.
8254
  function deleteNearSelection(cm, compute) {
8255
- var ranges = cm.doc.sel.ranges, kill = []
8256
  // Build up a set of ranges to kill first, merging overlapping
8257
  // ranges.
8258
  for (var i = 0; i < ranges.length; i++) {
8259
- var toKill = compute(ranges[i])
8260
  while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
8261
- var replaced = kill.pop()
8262
  if (cmp(replaced.from, toKill.from) < 0) {
8263
- toKill.from = replaced.from
8264
  break
8265
  }
8266
  }
8267
- kill.push(toKill)
8268
  }
8269
  // Next, remove those actual ranges.
8270
  runInOp(cm, function () {
8271
  for (var i = kill.length - 1; i >= 0; i--)
8272
- { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete") }
8273
- ensureCursorVisible(cm)
8274
- })
8275
  }
8276
 
8277
  // Commands are parameter-less actions that can be performed on an
@@ -8281,7 +8313,7 @@ var commands = {
8281
  singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
8282
  killLine: function (cm) { return deleteNearSelection(cm, function (range) {
8283
  if (range.empty()) {
8284
- var len = getLine(cm.doc, range.head.line).text.length
8285
  if (range.head.ch == len && range.head.line < cm.lastLine())
8286
  { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
8287
  else
@@ -8298,13 +8330,13 @@ var commands = {
8298
  from: Pos(range.from().line, 0), to: range.from()
8299
  }); }); },
8300
  delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
8301
- var top = cm.charCoords(range.head, "div").top + 5
8302
- var leftPos = cm.coordsChar({left: 0, top: top}, "div")
8303
  return {from: leftPos, to: range.from()}
8304
  }); },
8305
  delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
8306
- var top = cm.charCoords(range.head, "div").top + 5
8307
- var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
8308
  return {from: range.from(), to: rightPos }
8309
  }); },
8310
  undo: function (cm) { return cm.undo(); },
@@ -8323,16 +8355,16 @@ var commands = {
8323
  {origin: "+move", bias: -1}
8324
  ); },
8325
  goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
8326
- var top = cm.charCoords(range.head, "div").top + 5
8327
  return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
8328
  }, sel_move); },
8329
  goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
8330
- var top = cm.charCoords(range.head, "div").top + 5
8331
  return cm.coordsChar({left: 0, top: top}, "div")
8332
  }, sel_move); },
8333
  goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
8334
- var top = cm.charCoords(range.head, "div").top + 5
8335
- var pos = cm.coordsChar({left: 0, top: top}, "div")
8336
  if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
8337
  return pos
8338
  }, sel_move); },
@@ -8359,17 +8391,17 @@ var commands = {
8359
  indentLess: function (cm) { return cm.indentSelection("subtract"); },
8360
  insertTab: function (cm) { return cm.replaceSelection("\t"); },
8361
  insertSoftTab: function (cm) {
8362
- var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize
8363
  for (var i = 0; i < ranges.length; i++) {
8364
- var pos = ranges[i].from()
8365
- var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize)
8366
- spaces.push(spaceStr(tabSize - col % tabSize))
8367
  }
8368
- cm.replaceSelections(spaces)
8369
  },
8370
  defaultTab: function (cm) {
8371
- if (cm.somethingSelected()) { cm.indentSelection("add") }
8372
- else { cm.execCommand("insertTab") }
8373
  },
8374
  // Swap the two chars left and right of each selection's head.
8375
  // Move cursor behind the two swapped characters afterwards.
@@ -8379,63 +8411,63 @@ var commands = {
8379
  // Doesn't do anything on an empty line.
8380
  // Doesn't do anything with non-empty selections.
8381
  transposeChars: function (cm) { return runInOp(cm, function () {
8382
- var ranges = cm.listSelections(), newSel = []
8383
  for (var i = 0; i < ranges.length; i++) {
8384
  if (!ranges[i].empty()) { continue }
8385
- var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text
8386
  if (line) {
8387
- if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1) }
8388
  if (cur.ch > 0) {
8389
- cur = new Pos(cur.line, cur.ch + 1)
8390
  cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
8391
- Pos(cur.line, cur.ch - 2), cur, "+transpose")
8392
  } else if (cur.line > cm.doc.first) {
8393
- var prev = getLine(cm.doc, cur.line - 1).text
8394
  if (prev) {
8395
- cur = new Pos(cur.line, 1)
8396
  cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
8397
  prev.charAt(prev.length - 1),
8398
- Pos(cur.line - 1, prev.length - 1), cur, "+transpose")
8399
  }
8400
  }
8401
  }
8402
- newSel.push(new Range(cur, cur))
8403
  }
8404
- cm.setSelections(newSel)
8405
  }); },
8406
  newlineAndIndent: function (cm) { return runInOp(cm, function () {
8407
- var sels = cm.listSelections()
8408
  for (var i = sels.length - 1; i >= 0; i--)
8409
- { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input") }
8410
- sels = cm.listSelections()
8411
  for (var i$1 = 0; i$1 < sels.length; i$1++)
8412
- { cm.indentLine(sels[i$1].from().line, null, true) }
8413
- ensureCursorVisible(cm)
8414
  }); },
8415
  openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
8416
  toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
8417
- }
8418
 
8419
 
8420
  function lineStart(cm, lineN) {
8421
- var line = getLine(cm.doc, lineN)
8422
- var visual = visualLine(line)
8423
- if (visual != line) { lineN = lineNo(visual) }
8424
  return endOfLine(true, cm, visual, lineN, 1)
8425
  }
8426
  function lineEnd(cm, lineN) {
8427
- var line = getLine(cm.doc, lineN)
8428
- var visual = visualLineEnd(line)
8429
- if (visual != line) { lineN = lineNo(visual) }
8430
  return endOfLine(true, cm, line, lineN, -1)
8431
  }
8432
  function lineStartSmart(cm, pos) {
8433
- var start = lineStart(cm, pos.line)
8434
- var line = getLine(cm.doc, start.line)
8435
- var order = getOrder(line)
8436
  if (!order || order[0].level == 0) {
8437
- var firstNonWS = Math.max(0, line.text.search(/\S/))
8438
- var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch
8439
  return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
8440
  }
8441
  return start
@@ -8444,60 +8476,60 @@ function lineStartSmart(cm, pos) {
8444
  // Run a handler that was bound to a key.
8445
  function doHandleBinding(cm, bound, dropShift) {
8446
  if (typeof bound == "string") {
8447
- bound = commands[bound]
8448
  if (!bound) { return false }
8449
  }
8450
  // Ensure previous input has been read, so that the handler sees a
8451
  // consistent view of the document
8452
- cm.display.input.ensurePolled()
8453
- var prevShift = cm.display.shift, done = false
8454
  try {
8455
- if (cm.isReadOnly()) { cm.state.suppressEdits = true }
8456
- if (dropShift) { cm.display.shift = false }
8457
- done = bound(cm) != Pass
8458
  } finally {
8459
- cm.display.shift = prevShift
8460
- cm.state.suppressEdits = false
8461
  }
8462
  return done
8463
  }
8464
 
8465
  function lookupKeyForEditor(cm, name, handle) {
8466
  for (var i = 0; i < cm.state.keyMaps.length; i++) {
8467
- var result = lookupKey(name, cm.state.keyMaps[i], handle, cm)
8468
  if (result) { return result }
8469
  }
8470
  return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
8471
  || lookupKey(name, cm.options.keyMap, handle, cm)
8472
  }
8473
 
8474
- var stopSeq = new Delayed
8475
  function dispatchKey(cm, name, e, handle) {
8476
- var seq = cm.state.keySeq
8477
  if (seq) {
8478
  if (isModifierKey(name)) { return "handled" }
8479
  stopSeq.set(50, function () {
8480
  if (cm.state.keySeq == seq) {
8481
- cm.state.keySeq = null
8482
- cm.display.input.reset()
8483
  }
8484
- })
8485
- name = seq + " " + name
8486
  }
8487
- var result = lookupKeyForEditor(cm, name, handle)
8488
 
8489
  if (result == "multi")
8490
- { cm.state.keySeq = name }
8491
  if (result == "handled")
8492
- { signalLater(cm, "keyHandled", cm, name, e) }
8493
 
8494
  if (result == "handled" || result == "multi") {
8495
- e_preventDefault(e)
8496
- restartBlink(cm)
8497
  }
8498
 
8499
  if (seq && !result && /\'$/.test(name)) {
8500
- e_preventDefault(e)
8501
  return true
8502
  }
8503
  return !!result
@@ -8505,7 +8537,7 @@ function dispatchKey(cm, name, e, handle) {
8505
 
8506
  // Handle a key from the keydown event.
8507
  function handleKeyBinding(cm, e) {
8508
- var name = keyName(e, true)
8509
  if (!name) { return false }
8510
 
8511
  if (e.shiftKey && !cm.state.keySeq) {
@@ -8527,59 +8559,59 @@ function handleCharBinding(cm, e, ch) {
8527
  return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
8528
  }
8529
 
8530
- var lastStoppedKey = null
8531
  function onKeyDown(e) {
8532
- var cm = this
8533
- cm.curOp.focus = activeElt()
8534
  if (signalDOMEvent(cm, e)) { return }
8535
  // IE does strange things with escape.
8536
- if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false }
8537
- var code = e.keyCode
8538
- cm.display.shift = code == 16 || e.shiftKey
8539
- var handled = handleKeyBinding(cm, e)
8540
  if (presto) {
8541
- lastStoppedKey = handled ? code : null
8542
  // Opera has no cut event... we try to at least catch the key combo
8543
  if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
8544
- { cm.replaceSelection("", null, "cut") }
8545
  }
8546
 
8547
  // Turn mouse into crosshair when Alt is held on Mac.
8548
  if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
8549
- { showCrossHair(cm) }
8550
  }
8551
 
8552
  function showCrossHair(cm) {
8553
- var lineDiv = cm.display.lineDiv
8554
- addClass(lineDiv, "CodeMirror-crosshair")
8555
 
8556
  function up(e) {
8557
  if (e.keyCode == 18 || !e.altKey) {
8558
- rmClass(lineDiv, "CodeMirror-crosshair")
8559
- off(document, "keyup", up)
8560
- off(document, "mouseover", up)
8561
  }
8562
  }
8563
- on(document, "keyup", up)
8564
- on(document, "mouseover", up)
8565
  }
8566
 
8567
  function onKeyUp(e) {
8568
- if (e.keyCode == 16) { this.doc.sel.shift = false }
8569
- signalDOMEvent(this, e)
8570
  }
8571
 
8572
  function onKeyPress(e) {
8573
- var cm = this
8574
  if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
8575
- var keyCode = e.keyCode, charCode = e.charCode
8576
  if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
8577
  if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
8578
- var ch = String.fromCharCode(charCode == null ? keyCode : charCode)
8579
  // Some browsers fire keypress events for backspace
8580
  if (ch == "\x08") { return }
8581
  if (handleCharBinding(cm, e, ch)) { return }
8582
- cm.display.input.onKeyPress(e)
8583
  }
8584
 
8585
  // A mouse down can be a single click, double click, triple click,
@@ -8588,43 +8620,43 @@ function onKeyPress(e) {
8588
  // middle-click-paste. Or it might be a click on something we should
8589
  // not interfere with, such as a scrollbar or widget.
8590
  function onMouseDown(e) {
8591
- var cm = this, display = cm.display
8592
  if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
8593
- display.input.ensurePolled()
8594
- display.shift = e.shiftKey
8595
 
8596
  if (eventInWidget(display, e)) {
8597
  if (!webkit) {
8598
  // Briefly turn off draggability, to allow widgets to do
8599
  // normal dragging things.
8600
- display.scroller.draggable = false
8601
- setTimeout(function () { return display.scroller.draggable = true; }, 100)
8602
  }
8603
  return
8604
  }
8605
  if (clickInGutter(cm, e)) { return }
8606
- var start = posFromMouse(cm, e)
8607
- window.focus()
8608
 
8609
  switch (e_button(e)) {
8610
  case 1:
8611
  // #3261: make sure, that we're not starting a second selection
8612
  if (cm.state.selectingText)
8613
- { cm.state.selectingText(e) }
8614
  else if (start)
8615
- { leftButtonDown(cm, e, start) }
8616
  else if (e_target(e) == display.scroller)
8617
- { e_preventDefault(e) }
8618
  break
8619
  case 2:
8620
- if (webkit) { cm.state.lastMiddleDown = +new Date }
8621
- if (start) { extendSelection(cm.doc, start) }
8622
- setTimeout(function () { return display.input.focus(); }, 20)
8623
- e_preventDefault(e)
8624
  break
8625
  case 3:
8626
- if (captureRightClick) { onContextMenu(cm, e) }
8627
- else { delayBlurEvent(cm) }
8628
  break
8629
  }
8630
  }
@@ -8632,228 +8664,228 @@ function onMouseDown(e) {
8632
  var lastClick;
8633
  var lastDoubleClick;
8634
  function leftButtonDown(cm, e, start) {
8635
- if (ie) { setTimeout(bind(ensureFocus, cm), 0) }
8636
- else { cm.curOp.focus = activeElt() }
8637
 
8638
- var now = +new Date, type
8639
  if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
8640
- type = "triple"
8641
  } else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
8642
- type = "double"
8643
- lastDoubleClick = {time: now, pos: start}
8644
  } else {
8645
- type = "single"
8646
- lastClick = {time: now, pos: start}
8647
  }
8648
 
8649
- var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained
8650
  if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
8651
  type == "single" && (contained = sel.contains(start)) > -1 &&
8652
  (cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) &&
8653
  (cmp(contained.to(), start) > 0 || start.xRel < 0))
8654
- { leftButtonStartDrag(cm, e, start, modifier) }
8655
  else
8656
- { leftButtonSelect(cm, e, start, type, modifier) }
8657
  }
8658
 
8659
  // Start a text drag. When it ends, see if any dragging actually
8660
  // happen, and treat as a click if it didn't.
8661
  function leftButtonStartDrag(cm, e, start, modifier) {
8662
- var display = cm.display, startTime = +new Date
8663
  var dragEnd = operation(cm, function (e2) {
8664
- if (webkit) { display.scroller.draggable = false }
8665
- cm.state.draggingText = false
8666
- off(document, "mouseup", dragEnd)
8667
- off(display.scroller, "drop", dragEnd)
8668
  if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
8669
- e_preventDefault(e2)
8670
  if (!modifier && +new Date - 200 < startTime)
8671
- { extendSelection(cm.doc, start) }
8672
  // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
8673
  if (webkit || ie && ie_version == 9)
8674
- { setTimeout(function () {document.body.focus(); display.input.focus()}, 20) }
8675
  else
8676
- { display.input.focus() }
8677
  }
8678
- })
8679
  // Let the drag handler handle this.
8680
- if (webkit) { display.scroller.draggable = true }
8681
- cm.state.draggingText = dragEnd
8682
- dragEnd.copy = mac ? e.altKey : e.ctrlKey
8683
  // IE's approach to draggable
8684
- if (display.scroller.dragDrop) { display.scroller.dragDrop() }
8685
- on(document, "mouseup", dragEnd)
8686
- on(display.scroller, "drop", dragEnd)
8687
  }
8688
 
8689
  // Normal selection, as opposed to text dragging.
8690
  function leftButtonSelect(cm, e, start, type, addNew) {
8691
- var display = cm.display, doc = cm.doc
8692
- e_preventDefault(e)
8693
 
8694
- var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges
8695
  if (addNew && !e.shiftKey) {
8696
- ourIndex = doc.sel.contains(start)
8697
  if (ourIndex > -1)
8698
- { ourRange = ranges[ourIndex] }
8699
  else
8700
- { ourRange = new Range(start, start) }
8701
  } else {
8702
- ourRange = doc.sel.primary()
8703
- ourIndex = doc.sel.primIndex
8704
  }
8705
 
8706
  if (chromeOS ? e.shiftKey && e.metaKey : e.altKey) {
8707
- type = "rect"
8708
- if (!addNew) { ourRange = new Range(start, start) }
8709
- start = posFromMouse(cm, e, true, true)
8710
- ourIndex = -1
8711
  } else if (type == "double") {
8712
- var word = cm.findWordAt(start)
8713
  if (cm.display.shift || doc.extend)
8714
- { ourRange = extendRange(doc, ourRange, word.anchor, word.head) }
8715
  else
8716
- { ourRange = word }
8717
  } else if (type == "triple") {
8718
- var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)))
8719
  if (cm.display.shift || doc.extend)
8720
- { ourRange = extendRange(doc, ourRange, line.anchor, line.head) }
8721
  else
8722
- { ourRange = line }
8723
  } else {
8724
- ourRange = extendRange(doc, ourRange, start)
8725
  }
8726
 
8727
  if (!addNew) {
8728
- ourIndex = 0
8729
- setSelection(doc, new Selection([ourRange], 0), sel_mouse)
8730
- startSel = doc.sel
8731
  } else if (ourIndex == -1) {
8732
- ourIndex = ranges.length
8733
  setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
8734
- {scroll: false, origin: "*mouse"})
8735
  } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) {
8736
  setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
8737
- {scroll: false, origin: "*mouse"})
8738
- startSel = doc.sel
8739
  } else {
8740
- replaceOneSelection(doc, ourIndex, ourRange, sel_mouse)
8741
  }
8742
 
8743
- var lastPos = start
8744
  function extendTo(pos) {
8745
  if (cmp(lastPos, pos) == 0) { return }
8746
- lastPos = pos
8747
 
8748
  if (type == "rect") {
8749
- var ranges = [], tabSize = cm.options.tabSize
8750
- var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize)
8751
- var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize)
8752
- var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol)
8753
  for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
8754
  line <= end; line++) {
8755
- var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize)
8756
  if (left == right)
8757
- { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))) }
8758
  else if (text.length > leftPos)
8759
- { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))) }
8760
  }
8761
- if (!ranges.length) { ranges.push(new Range(start, start)) }
8762
  setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
8763
- {origin: "*mouse", scroll: false})
8764
- cm.scrollIntoView(pos)
8765
  } else {
8766
- var oldRange = ourRange
8767
- var anchor = oldRange.anchor, head = pos
8768
  if (type != "single") {
8769
- var range
8770
  if (type == "double")
8771
- { range = cm.findWordAt(pos) }
8772
  else
8773
- { range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0))) }
8774
- if (cmp(range.anchor, anchor) > 0) {
8775
- head = range.head
8776
- anchor = minPos(oldRange.from(), range.anchor)
8777
  } else {
8778
- head = range.anchor
8779
- anchor = maxPos(oldRange.to(), range.head)
8780
  }
8781
  }
8782
- var ranges$1 = startSel.ranges.slice(0)
8783
- ranges$1[ourIndex] = new Range(clipPos(doc, anchor), head)
8784
- setSelection(doc, normalizeSelection(ranges$1, ourIndex), sel_mouse)
8785
  }
8786
  }
8787
 
8788
- var editorSize = display.wrapper.getBoundingClientRect()
8789
  // Used to ensure timeout re-tries don't fire when another extend
8790
  // happened in the meantime (clearTimeout isn't reliable -- at
8791
  // least on Chrome, the timeouts still happen even when cleared,
8792
  // if the clear happens after their scheduled firing time).
8793
- var counter = 0
8794
 
8795
  function extend(e) {
8796
- var curCount = ++counter
8797
- var cur = posFromMouse(cm, e, true, type == "rect")
8798
  if (!cur) { return }
8799
  if (cmp(cur, lastPos) != 0) {
8800
- cm.curOp.focus = activeElt()
8801
- extendTo(cur)
8802
- var visible = visibleLines(display, doc)
8803
  if (cur.line >= visible.to || cur.line < visible.from)
8804
- { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e) }}), 150) }
8805
  } else {
8806
- var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0
8807
  if (outside) { setTimeout(operation(cm, function () {
8808
  if (counter != curCount) { return }
8809
- display.scroller.scrollTop += outside
8810
- extend(e)
8811
- }), 50) }
8812
  }
8813
  }
8814
 
8815
  function done(e) {
8816
- cm.state.selectingText = false
8817
- counter = Infinity
8818
- e_preventDefault(e)
8819
- display.input.focus()
8820
- off(document, "mousemove", move)
8821
- off(document, "mouseup", up)
8822
- doc.history.lastSelOrigin = null
8823
  }
8824
 
8825
  var move = operation(cm, function (e) {
8826
- if (!e_button(e)) { done(e) }
8827
- else { extend(e) }
8828
- })
8829
- var up = operation(cm, done)
8830
- cm.state.selectingText = up
8831
- on(document, "mousemove", move)
8832
- on(document, "mouseup", up)
8833
  }
8834
 
8835
 
8836
  // Determines whether an event happened in the gutter, and fires the
8837
  // handlers for the corresponding event.
8838
  function gutterEvent(cm, e, type, prevent) {
8839
- var mX, mY
8840
- try { mX = e.clientX; mY = e.clientY }
8841
  catch(e) { return false }
8842
  if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
8843
- if (prevent) { e_preventDefault(e) }
8844
 
8845
- var display = cm.display
8846
- var lineBox = display.lineDiv.getBoundingClientRect()
8847
 
8848
  if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
8849
- mY -= lineBox.top - display.viewOffset
8850
 
8851
  for (var i = 0; i < cm.options.gutters.length; ++i) {
8852
- var g = display.gutters.childNodes[i]
8853
  if (g && g.getBoundingClientRect().right >= mX) {
8854
- var line = lineAtHeight(cm.doc, mY)
8855
- var gutter = cm.options.gutters[i]
8856
- signal(cm, type, cm, line, gutter, e)
8857
  return e_defaultPrevented(e)
8858
  }
8859
  }
@@ -8871,7 +8903,7 @@ function clickInGutter(cm, e) {
8871
  function onContextMenu(cm, e) {
8872
  if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
8873
  if (signalDOMEvent(cm, e, "contextmenu")) { return }
8874
- cm.display.input.onContextMenu(e)
8875
  }
8876
 
8877
  function contextMenuInGutter(cm, e) {
@@ -8881,207 +8913,208 @@ function contextMenuInGutter(cm, e) {
8881
 
8882
  function themeChanged(cm) {
8883
  cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
8884
- cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-")
8885
- clearCaches(cm)
8886
  }
8887
 
8888
- var Init = {toString: function(){return "CodeMirror.Init"}}
8889
 
8890
- var defaults = {}
8891
- var optionHandlers = {}
8892
 
8893
  function defineOptions(CodeMirror) {
8894
- var optionHandlers = CodeMirror.optionHandlers
8895
 
8896
  function option(name, deflt, handle, notOnInit) {
8897
- CodeMirror.defaults[name] = deflt
8898
  if (handle) { optionHandlers[name] =
8899
- notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old) }} : handle }
8900
  }
8901
 
8902
- CodeMirror.defineOption = option
8903
 
8904
  // Passed to option handlers when there is no old value.
8905
- CodeMirror.Init = Init
8906
 
8907
  // These two are, on init, called from the constructor because they
8908
  // have to be initialized before the editor can start at all.
8909
- option("value", "", function (cm, val) { return cm.setValue(val); }, true)
8910
  option("mode", null, function (cm, val) {
8911
- cm.doc.modeOption = val
8912
- loadMode(cm)
8913
- }, true)
8914
 
8915
- option("indentUnit", 2, loadMode, true)
8916
- option("indentWithTabs", false)
8917
- option("smartIndent", true)
8918
  option("tabSize", 4, function (cm) {
8919
- resetModeState(cm)
8920
- clearCaches(cm)
8921
- regChange(cm)
8922
- }, true)
8923
  option("lineSeparator", null, function (cm, val) {
8924
- cm.doc.lineSep = val
8925
  if (!val) { return }
8926
- var newBreaks = [], lineNo = cm.doc.first
8927
  cm.doc.iter(function (line) {
8928
  for (var pos = 0;;) {
8929
- var found = line.text.indexOf(val, pos)
8930
  if (found == -1) { break }
8931
- pos = found + val.length
8932
- newBreaks.push(Pos(lineNo, found))
8933
  }
8934
- lineNo++
8935
- })
8936
  for (var i = newBreaks.length - 1; i >= 0; i--)
8937
- { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)) }
8938
- })
8939
- option("specialChars", /[\u0000-\u001f\u007f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
8940
- cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g")
8941
- if (old != Init) { cm.refresh() }
8942
- })
8943
- option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true)
8944
- option("electricChars", true)
8945
  option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
8946
  throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
8947
- }, true)
8948
- option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true)
8949
- option("rtlMoveVisually", !windows)
8950
- option("wholeLineUpdateBefore", true)
8951
 
8952
  option("theme", "default", function (cm) {
8953
- themeChanged(cm)
8954
- guttersChanged(cm)
8955
- }, true)
8956
  option("keyMap", "default", function (cm, val, old) {
8957
- var next = getKeyMap(val)
8958
- var prev = old != Init && getKeyMap(old)
8959
- if (prev && prev.detach) { prev.detach(cm, next) }
8960
- if (next.attach) { next.attach(cm, prev || null) }
8961
- })
8962
- option("extraKeys", null)
8963
 
8964
- option("lineWrapping", false, wrappingChanged, true)
8965
  option("gutters", [], function (cm) {
8966
- setGuttersForLineNumbers(cm.options)
8967
- guttersChanged(cm)
8968
- }, true)
8969
  option("fixedGutter", true, function (cm, val) {
8970
- cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"
8971
- cm.refresh()
8972
- }, true)
8973
- option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true)
8974
  option("scrollbarStyle", "native", function (cm) {
8975
- initScrollbars(cm)
8976
- updateScrollbars(cm)
8977
- cm.display.scrollbars.setScrollTop(cm.doc.scrollTop)
8978
- cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft)
8979
- }, true)
8980
  option("lineNumbers", false, function (cm) {
8981
- setGuttersForLineNumbers(cm.options)
8982
- guttersChanged(cm)
8983
- }, true)
8984
- option("firstLineNumber", 1, guttersChanged, true)
8985
- option("lineNumberFormatter", function (integer) { return integer; }, guttersChanged, true)
8986
- option("showCursorWhenSelecting", false, updateSelection, true)
8987
 
8988
- option("resetSelectionOnContextMenu", true)
8989
- option("lineWiseCopyCut", true)
8990
 
8991
  option("readOnly", false, function (cm, val) {
8992
  if (val == "nocursor") {
8993
- onBlur(cm)
8994
- cm.display.input.blur()
8995
- cm.display.disabled = true
8996
  } else {
8997
- cm.display.disabled = false
8998
  }
8999
- cm.display.input.readOnlyChanged(val)
9000
- })
9001
- option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset() }}, true)
9002
- option("dragDrop", true, dragDropChanged)
9003
- option("allowDropFileTypes", null)
9004
-
9005
- option("cursorBlinkRate", 530)
9006
- option("cursorScrollMargin", 0)
9007
- option("cursorHeight", 1, updateSelection, true)
9008
- option("singleCursorHeightPerLine", true, updateSelection, true)
9009
- option("workTime", 100)
9010
- option("workDelay", 100)
9011
- option("flattenSpans", true, resetModeState, true)
9012
- option("addModeClass", false, resetModeState, true)
9013
- option("pollInterval", 100)
9014
- option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; })
9015
- option("historyEventDelay", 1250)
9016
- option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true)
9017
- option("maxHighlightLength", 10000, resetModeState, true)
9018
  option("moveInputWithCursor", true, function (cm, val) {
9019
- if (!val) { cm.display.input.resetPosition() }
9020
- })
9021
 
9022
- option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; })
9023
- option("autofocus", null)
 
9024
  }
9025
 
9026
  function guttersChanged(cm) {
9027
- updateGutters(cm)
9028
- regChange(cm)
9029
- alignHorizontally(cm)
9030
  }
9031
 
9032
  function dragDropChanged(cm, value, old) {
9033
- var wasOn = old && old != Init
9034
  if (!value != !wasOn) {
9035
- var funcs = cm.display.dragFunctions
9036
- var toggle = value ? on : off
9037
- toggle(cm.display.scroller, "dragstart", funcs.start)
9038
- toggle(cm.display.scroller, "dragenter", funcs.enter)
9039
- toggle(cm.display.scroller, "dragover", funcs.over)
9040
- toggle(cm.display.scroller, "dragleave", funcs.leave)
9041
- toggle(cm.display.scroller, "drop", funcs.drop)
9042
  }
9043
  }
9044
 
9045
  function wrappingChanged(cm) {
9046
  if (cm.options.lineWrapping) {
9047
- addClass(cm.display.wrapper, "CodeMirror-wrap")
9048
- cm.display.sizer.style.minWidth = ""
9049
- cm.display.sizerWidth = null
9050
  } else {
9051
- rmClass(cm.display.wrapper, "CodeMirror-wrap")
9052
- findMaxLine(cm)
9053
  }
9054
- estimateLineHeights(cm)
9055
- regChange(cm)
9056
- clearCaches(cm)
9057
- setTimeout(function () { return updateScrollbars(cm); }, 100)
9058
  }
9059
 
9060
  // A CodeMirror instance represents an editor. This is the object
9061
  // that user code is usually dealing with.
9062
 
9063
- function CodeMirror(place, options) {
9064
  var this$1 = this;
9065
 
9066
- if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
9067
 
9068
- this.options = options = options ? copyObj(options) : {}
9069
  // Determine effective options based on given values and defaults.
9070
- copyObj(defaults, options, false)
9071
- setGuttersForLineNumbers(options)
9072
-
9073
- var doc = options.value
9074
- if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator) }
9075
- this.doc = doc
9076
-
9077
- var input = new CodeMirror.inputStyles[options.inputStyle](this)
9078
- var display = this.display = new Display(place, doc, input)
9079
- display.wrapper.CodeMirror = this
9080
- updateGutters(this)
9081
- themeChanged(this)
9082
  if (options.lineWrapping)
9083
- { this.display.wrapper.className += " CodeMirror-wrap" }
9084
- initScrollbars(this)
9085
 
9086
  this.state = {
9087
  keyMaps: [], // stores maps added by addKeyMap
@@ -9097,154 +9130,154 @@ function CodeMirror(place, options) {
9097
  highlight: new Delayed(), // stores highlight worker timeout
9098
  keySeq: null, // Unfinished key sequence
9099
  specialChars: null
9100
- }
9101
 
9102
- if (options.autofocus && !mobile) { display.input.focus() }
9103
 
9104
  // Override magic textarea content restore that IE sometimes does
9105
  // on our hidden textarea on reload
9106
- if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20) }
9107
 
9108
- registerEventHandlers(this)
9109
- ensureGlobalHandlers()
9110
 
9111
- startOperation(this)
9112
- this.curOp.forceUpdate = true
9113
- attachDoc(this, doc)
9114
 
9115
  if ((options.autofocus && !mobile) || this.hasFocus())
9116
- { setTimeout(bind(onFocus, this), 20) }
9117
  else
9118
- { onBlur(this) }
9119
 
9120
  for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
9121
- { optionHandlers[opt](this$1, options[opt], Init) } }
9122
- maybeUpdateLineNumberWidth(this)
9123
- if (options.finishInit) { options.finishInit(this) }
9124
- for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1) }
9125
- endOperation(this)
9126
  // Suppress optimizelegibility in Webkit, since it breaks text
9127
  // measuring on line wrapping boundaries.
9128
  if (webkit && options.lineWrapping &&
9129
  getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
9130
- { display.lineDiv.style.textRendering = "auto" }
9131
  }
9132
 
9133
  // The default configuration options.
9134
- CodeMirror.defaults = defaults
9135
  // Functions to run when options are changed.
9136
- CodeMirror.optionHandlers = optionHandlers
9137
 
9138
  // Attach the necessary event handlers when initializing the editor
9139
  function registerEventHandlers(cm) {
9140
- var d = cm.display
9141
- on(d.scroller, "mousedown", operation(cm, onMouseDown))
9142
  // Older IE's will not fire a second mousedown for a double click
9143
  if (ie && ie_version < 11)
9144
  { on(d.scroller, "dblclick", operation(cm, function (e) {
9145
  if (signalDOMEvent(cm, e)) { return }
9146
- var pos = posFromMouse(cm, e)
9147
  if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
9148
- e_preventDefault(e)
9149
- var word = cm.findWordAt(pos)
9150
- extendSelection(cm.doc, word.anchor, word.head)
9151
- })) }
9152
  else
9153
- { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }) }
9154
  // Some browsers fire contextmenu *after* opening the menu, at
9155
  // which point we can't mess with it anymore. Context menu is
9156
  // handled in onMouseDown for these browsers.
9157
- if (!captureRightClick) { on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); }) }
9158
 
9159
  // Used to suppress mouse event handling when a touch happens
9160
- var touchFinished, prevTouch = {end: 0}
9161
  function finishTouch() {
9162
  if (d.activeTouch) {
9163
- touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000)
9164
- prevTouch = d.activeTouch
9165
- prevTouch.end = +new Date
9166
  }
9167
  }
9168
  function isMouseLikeTouchEvent(e) {
9169
  if (e.touches.length != 1) { return false }
9170
- var touch = e.touches[0]
9171
  return touch.radiusX <= 1 && touch.radiusY <= 1
9172
  }
9173
  function farAway(touch, other) {
9174
  if (other.left == null) { return true }
9175
- var dx = other.left - touch.left, dy = other.top - touch.top
9176
  return dx * dx + dy * dy > 20 * 20
9177
  }
9178
  on(d.scroller, "touchstart", function (e) {
9179
  if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
9180
- d.input.ensurePolled()
9181
- clearTimeout(touchFinished)
9182
- var now = +new Date
9183
  d.activeTouch = {start: now, moved: false,
9184
- prev: now - prevTouch.end <= 300 ? prevTouch : null}
9185
  if (e.touches.length == 1) {
9186
- d.activeTouch.left = e.touches[0].pageX
9187
- d.activeTouch.top = e.touches[0].pageY
9188
  }
9189
  }
9190
- })
9191
  on(d.scroller, "touchmove", function () {
9192
- if (d.activeTouch) { d.activeTouch.moved = true }
9193
- })
9194
  on(d.scroller, "touchend", function (e) {
9195
- var touch = d.activeTouch
9196
  if (touch && !eventInWidget(d, e) && touch.left != null &&
9197
  !touch.moved && new Date - touch.start < 300) {
9198
- var pos = cm.coordsChar(d.activeTouch, "page"), range
9199
  if (!touch.prev || farAway(touch, touch.prev)) // Single tap
9200
- { range = new Range(pos, pos) }
9201
  else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
9202
- { range = cm.findWordAt(pos) }
9203
  else // Triple tap
9204
- { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
9205
- cm.setSelection(range.anchor, range.head)
9206
- cm.focus()
9207
- e_preventDefault(e)
9208
  }
9209
- finishTouch()
9210
- })
9211
- on(d.scroller, "touchcancel", finishTouch)
9212
 
9213
  // Sync scrolling between fake scrollbars and real scrollable
9214
  // area, ensure viewport is updated when scrolling.
9215
  on(d.scroller, "scroll", function () {
9216
  if (d.scroller.clientHeight) {
9217
- setScrollTop(cm, d.scroller.scrollTop)
9218
- setScrollLeft(cm, d.scroller.scrollLeft, true)
9219
- signal(cm, "scroll", cm)
9220
  }
9221
- })
9222
 
9223
  // Listen to wheel events in order to try and update the viewport on time.
9224
- on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); })
9225
- on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); })
9226
 
9227
  // Prevent wrapper from ever scrolling
9228
- on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; })
9229
 
9230
  d.dragFunctions = {
9231
- enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e) }},
9232
- over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
9233
  start: function (e) { return onDragStart(cm, e); },
9234
  drop: operation(cm, onDrop),
9235
- leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
9236
- }
9237
 
9238
- var inp = d.input.getField()
9239
- on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); })
9240
- on(inp, "keydown", operation(cm, onKeyDown))
9241
- on(inp, "keypress", operation(cm, onKeyPress))
9242
- on(inp, "focus", function (e) { return onFocus(cm, e); })
9243
- on(inp, "blur", function (e) { return onBlur(cm, e); })
9244
  }
9245
 
9246
- var initHooks = []
9247
- CodeMirror.defineInitHook = function (f) { return initHooks.push(f); }
9248
 
9249
  // Indent the given line. The how parameter can be "smart",
9250
  // "add"/null, "subtract", or "prev". When aggressive is false
@@ -9252,58 +9285,58 @@ CodeMirror.defineInitHook = function (f) { return initHooks.push(f); }
9252
  // lines are not indented, and places where the mode returns Pass
9253
  // are left alone.
9254
  function indentLine(cm, n, how, aggressive) {
9255
- var doc = cm.doc, state
9256
- if (how == null) { how = "add" }
9257
  if (how == "smart") {
9258
  // Fall back to "prev" when the mode doesn't have an indentation
9259
  // method.
9260
- if (!doc.mode.indent) { how = "prev" }
9261
- else { state = getStateBefore(cm, n) }
9262
  }
9263
 
9264
- var tabSize = cm.options.tabSize
9265
- var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize)
9266
- if (line.stateAfter) { line.stateAfter = null }
9267
- var curSpaceString = line.text.match(/^\s*/)[0], indentation
9268
  if (!aggressive && !/\S/.test(line.text)) {
9269
- indentation = 0
9270
- how = "not"
9271
  } else if (how == "smart") {
9272
- indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text)
9273
  if (indentation == Pass || indentation > 150) {
9274
  if (!aggressive) { return }
9275
- how = "prev"
9276
  }
9277
  }
9278
  if (how == "prev") {
9279
- if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize) }
9280
- else { indentation = 0 }
9281
  } else if (how == "add") {
9282
- indentation = curSpace + cm.options.indentUnit
9283
  } else if (how == "subtract") {
9284
- indentation = curSpace - cm.options.indentUnit
9285
  } else if (typeof how == "number") {
9286
- indentation = curSpace + how
9287
  }
9288
- indentation = Math.max(0, indentation)
9289
 
9290
- var indentString = "", pos = 0
9291
  if (cm.options.indentWithTabs)
9292
- { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t"} }
9293
- if (pos < indentation) { indentString += spaceStr(indentation - pos) }
9294
 
9295
  if (indentString != curSpaceString) {
9296
- replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input")
9297
- line.stateAfter = null
9298
  return true
9299
  } else {
9300
  // Ensure that, if the cursor was in the whitespace at the start
9301
  // of the line, it is moved to the end of that space.
9302
  for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
9303
- var range = doc.sel.ranges[i$1]
9304
  if (range.head.line == n && range.head.ch < curSpaceString.length) {
9305
- var pos$1 = Pos(n, curSpaceString.length)
9306
- replaceOneSelection(doc, i$1, new Range(pos$1, pos$1))
9307
  break
9308
  }
9309
  }
@@ -9313,66 +9346,66 @@ function indentLine(cm, n, how, aggressive) {
9313
  // This will be set to a {lineWise: bool, text: [string]} object, so
9314
  // that, when pasting, we know what kind of selections the copied
9315
  // text was made out of.
9316
- var lastCopied = null
9317
 
9318
  function setLastCopied(newLastCopied) {
9319
- lastCopied = newLastCopied
9320
  }
9321
 
9322
  function applyTextInput(cm, inserted, deleted, sel, origin) {
9323
- var doc = cm.doc
9324
- cm.display.shift = false
9325
- if (!sel) { sel = doc.sel }
9326
 
9327
- var paste = cm.state.pasteIncoming || origin == "paste"
9328
- var textLines = splitLinesAuto(inserted), multiPaste = null
9329
  // When pasing N lines into N selections, insert one line per selection
9330
  if (paste && sel.ranges.length > 1) {
9331
  if (lastCopied && lastCopied.text.join("\n") == inserted) {
9332
  if (sel.ranges.length % lastCopied.text.length == 0) {
9333
- multiPaste = []
9334
  for (var i = 0; i < lastCopied.text.length; i++)
9335
- { multiPaste.push(doc.splitLines(lastCopied.text[i])) }
9336
  }
9337
  } else if (textLines.length == sel.ranges.length) {
9338
- multiPaste = map(textLines, function (l) { return [l]; })
9339
  }
9340
  }
9341
 
9342
- var updateInput
9343
  // Normal behavior is to insert the new text into every selection
9344
  for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
9345
- var range = sel.ranges[i$1]
9346
- var from = range.from(), to = range.to()
9347
- if (range.empty()) {
9348
  if (deleted && deleted > 0) // Handle deletion
9349
- { from = Pos(from.line, from.ch - deleted) }
9350
  else if (cm.state.overwrite && !paste) // Handle overwrite
9351
- { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)) }
9352
  else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
9353
- { from = to = Pos(from.line, 0) }
9354
  }
9355
- updateInput = cm.curOp.updateInput
9356
  var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
9357
- origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")}
9358
- makeChange(cm.doc, changeEvent)
9359
- signalLater(cm, "inputRead", cm, changeEvent)
9360
  }
9361
  if (inserted && !paste)
9362
- { triggerElectric(cm, inserted) }
9363
 
9364
- ensureCursorVisible(cm)
9365
- cm.curOp.updateInput = updateInput
9366
- cm.curOp.typing = true
9367
- cm.state.pasteIncoming = cm.state.cutIncoming = false
9368
  }
9369
 
9370
  function handlePaste(e, cm) {
9371
- var pasted = e.clipboardData && e.clipboardData.getData("Text")
9372
  if (pasted) {
9373
- e.preventDefault()
9374
  if (!cm.isReadOnly() && !cm.options.disableInput)
9375
- { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }) }
9376
  return true
9377
  }
9378
  }
@@ -9380,56 +9413,56 @@ function handlePaste(e, cm) {
9380
  function triggerElectric(cm, inserted) {
9381
  // When an 'electric' character is inserted, immediately trigger a reindent
9382
  if (!cm.options.electricChars || !cm.options.smartIndent) { return }
9383
- var sel = cm.doc.sel
9384
 
9385
  for (var i = sel.ranges.length - 1; i >= 0; i--) {
9386
- var range = sel.ranges[i]
9387
- if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) { continue }
9388
- var mode = cm.getModeAt(range.head)
9389
- var indented = false
9390
  if (mode.electricChars) {
9391
  for (var j = 0; j < mode.electricChars.length; j++)
9392
  { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
9393
- indented = indentLine(cm, range.head.line, "smart")
9394
  break
9395
  } }
9396
  } else if (mode.electricInput) {
9397
- if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
9398
- { indented = indentLine(cm, range.head.line, "smart") }
9399
  }
9400
- if (indented) { signalLater(cm, "electricInput", cm, range.head.line) }
9401
  }
9402
  }
9403
 
9404
  function copyableRanges(cm) {
9405
- var text = [], ranges = []
9406
  for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
9407
- var line = cm.doc.sel.ranges[i].head.line
9408
- var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)}
9409
- ranges.push(lineRange)
9410
- text.push(cm.getRange(lineRange.anchor, lineRange.head))
9411
  }
9412
  return {text: text, ranges: ranges}
9413
  }
9414
 
9415
  function disableBrowserMagic(field, spellcheck) {
9416
- field.setAttribute("autocorrect", "off")
9417
- field.setAttribute("autocapitalize", "off")
9418
- field.setAttribute("spellcheck", !!spellcheck)
9419
  }
9420
 
9421
  function hiddenTextarea() {
9422
- var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none")
9423
- var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;")
9424
  // The textarea is kept positioned near the cursor to prevent the
9425
  // fact that it'll be scrolled into view on input from scrolling
9426
  // our fake cursor out of view. On webkit, when wrap=off, paste is
9427
  // very slow. So make the area wide instead.
9428
- if (webkit) { te.style.width = "1000px" }
9429
- else { te.setAttribute("wrap", "off") }
9430
  // If border: 0; -- iOS fails to open keyboard (issue #1287)
9431
- if (ios) { te.style.border = "1px solid black" }
9432
- disableBrowserMagic(te)
9433
  return div
9434
  }
9435
 
@@ -9441,59 +9474,59 @@ function hiddenTextarea() {
9441
  // CodeMirror.prototype, for backwards compatibility and
9442
  // convenience.
9443
 
9444
- function addEditorMethods(CodeMirror) {
9445
- var optionHandlers = CodeMirror.optionHandlers
9446
 
9447
- var helpers = CodeMirror.helpers = {}
9448
 
9449
  CodeMirror.prototype = {
9450
  constructor: CodeMirror,
9451
- focus: function(){window.focus(); this.display.input.focus()},
9452
 
9453
  setOption: function(option, value) {
9454
- var options = this.options, old = options[option]
9455
  if (options[option] == value && option != "mode") { return }
9456
- options[option] = value
9457
  if (optionHandlers.hasOwnProperty(option))
9458
- { operation(this, optionHandlers[option])(this, value, old) }
9459
- signal(this, "optionChange", this, option)
9460
  },
9461
 
9462
  getOption: function(option) {return this.options[option]},
9463
  getDoc: function() {return this.doc},
9464
 
9465
- addKeyMap: function(map, bottom) {
9466
- this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map))
9467
  },
9468
- removeKeyMap: function(map) {
9469
- var maps = this.state.keyMaps
9470
  for (var i = 0; i < maps.length; ++i)
9471
- { if (maps[i] == map || maps[i].name == map) {
9472
- maps.splice(i, 1)
9473
  return true
9474
  } }
9475
  },
9476
 
9477
  addOverlay: methodOp(function(spec, options) {
9478
- var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec)
9479
  if (mode.startState) { throw new Error("Overlays may not be stateful.") }
9480
  insertSorted(this.state.overlays,
9481
  {mode: mode, modeSpec: spec, opaque: options && options.opaque,
9482
  priority: (options && options.priority) || 0},
9483
- function (overlay) { return overlay.priority; })
9484
- this.state.modeGen++
9485
- regChange(this)
9486
  }),
9487
  removeOverlay: methodOp(function(spec) {
9488
  var this$1 = this;
9489
 
9490
- var overlays = this.state.overlays
9491
  for (var i = 0; i < overlays.length; ++i) {
9492
- var cur = overlays[i].modeSpec
9493
  if (cur == spec || typeof spec == "string" && cur.name == spec) {
9494
- overlays.splice(i, 1)
9495
- this$1.state.modeGen++
9496
- regChange(this$1)
9497
  return
9498
  }
9499
  }
@@ -9501,30 +9534,30 @@ function addEditorMethods(CodeMirror) {
9501
 
9502
  indentLine: methodOp(function(n, dir, aggressive) {
9503
  if (typeof dir != "string" && typeof dir != "number") {
9504
- if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev" }
9505
- else { dir = dir ? "add" : "subtract" }
9506
  }
9507
- if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive) }
9508
  }),
9509
  indentSelection: methodOp(function(how) {
9510
  var this$1 = this;
9511
 
9512
- var ranges = this.doc.sel.ranges, end = -1
9513
  for (var i = 0; i < ranges.length; i++) {
9514
- var range = ranges[i]
9515
- if (!range.empty()) {
9516
- var from = range.from(), to = range.to()
9517
- var start = Math.max(end, from.line)
9518
- end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1
9519
  for (var j = start; j < end; ++j)
9520
- { indentLine(this$1, j, how) }
9521
- var newRanges = this$1.doc.sel.ranges
9522
  if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
9523
- { replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll) }
9524
- } else if (range.head.line > end) {
9525
- indentLine(this$1, range.head.line, how, true)
9526
- end = range.head.line
9527
- if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1) }
9528
  }
9529
  }
9530
  }),
@@ -9540,23 +9573,23 @@ function addEditorMethods(CodeMirror) {
9540
  },
9541
 
9542
  getTokenTypeAt: function(pos) {
9543
- pos = clipPos(this.doc, pos)
9544
- var styles = getLineStyles(this, getLine(this.doc, pos.line))
9545
- var before = 0, after = (styles.length - 1) / 2, ch = pos.ch
9546
- var type
9547
- if (ch == 0) { type = styles[2] }
9548
  else { for (;;) {
9549
- var mid = (before + after) >> 1
9550
- if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid }
9551
- else if (styles[mid * 2 + 1] < ch) { before = mid + 1 }
9552
  else { type = styles[mid * 2 + 2]; break }
9553
  } }
9554
- var cut = type ? type.indexOf("overlay ") : -1
9555
  return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
9556
  },
9557
 
9558
  getModeAt: function(pos) {
9559
- var mode = this.doc.mode
9560
  if (!mode.innerMode) { return mode }
9561
  return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
9562
  },
@@ -9568,40 +9601,40 @@ function addEditorMethods(CodeMirror) {
9568
  getHelpers: function(pos, type) {
9569
  var this$1 = this;
9570
 
9571
- var found = []
9572
  if (!helpers.hasOwnProperty(type)) { return found }
9573
- var help = helpers[type], mode = this.getModeAt(pos)
9574
  if (typeof mode[type] == "string") {
9575
- if (help[mode[type]]) { found.push(help[mode[type]]) }
9576
  } else if (mode[type]) {
9577
  for (var i = 0; i < mode[type].length; i++) {
9578
- var val = help[mode[type][i]]
9579
- if (val) { found.push(val) }
9580
  }
9581
  } else if (mode.helperType && help[mode.helperType]) {
9582
- found.push(help[mode.helperType])
9583
  } else if (help[mode.name]) {
9584
- found.push(help[mode.name])
9585
  }
9586
  for (var i$1 = 0; i$1 < help._global.length; i$1++) {
9587
- var cur = help._global[i$1]
9588
  if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1)
9589
- { found.push(cur.val) }
9590
  }
9591
  return found
9592
  },
9593
 
9594
  getStateAfter: function(line, precise) {
9595
- var doc = this.doc
9596
- line = clipLine(doc, line == null ? doc.first + doc.size - 1: line)
9597
  return getStateBefore(this, line + 1, precise)
9598
  },
9599
 
9600
  cursorCoords: function(start, mode) {
9601
- var pos, range = this.doc.sel.primary()
9602
- if (start == null) { pos = range.head }
9603
- else if (typeof start == "object") { pos = clipPos(this.doc, start) }
9604
- else { pos = start ? range.from() : range.to() }
9605
  return cursorCoords(this, pos, mode || "page")
9606
  },
9607
 
@@ -9610,23 +9643,23 @@ function addEditorMethods(CodeMirror) {
9610
  },
9611
 
9612
  coordsChar: function(coords, mode) {
9613
- coords = fromCoordSystem(this, coords, mode || "page")
9614
  return coordsChar(this, coords.left, coords.top)
9615
  },
9616
 
9617
  lineAtHeight: function(height, mode) {
9618
- height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top
9619
  return lineAtHeight(this.doc, height + this.display.viewOffset)
9620
  },
9621
  heightAtLine: function(line, mode, includeWidgets) {
9622
- var end = false, lineObj
9623
  if (typeof line == "number") {
9624
- var last = this.doc.first + this.doc.size - 1
9625
- if (line < this.doc.first) { line = this.doc.first }
9626
- else if (line > last) { line = last; end = true }
9627
- lineObj = getLine(this.doc, line)
9628
  } else {
9629
- lineObj = line
9630
  }
9631
  return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
9632
  (end ? this.doc.height - heightAtLine(lineObj) : 0)
@@ -9638,38 +9671,38 @@ function addEditorMethods(CodeMirror) {
9638
  getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
9639
 
9640
  addWidget: function(pos, node, scroll, vert, horiz) {
9641
- var display = this.display
9642
- pos = cursorCoords(this, clipPos(this.doc, pos))
9643
- var top = pos.bottom, left = pos.left
9644
- node.style.position = "absolute"
9645
- node.setAttribute("cm-ignore-events", "true")
9646
- this.display.input.setUneditable(node)
9647
- display.sizer.appendChild(node)
9648
  if (vert == "over") {
9649
- top = pos.top
9650
  } else if (vert == "above" || vert == "near") {
9651
  var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
9652
- hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth)
9653
  // Default to positioning above (if specified and possible); otherwise default to positioning below
9654
  if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
9655
- { top = pos.top - node.offsetHeight }
9656
  else if (pos.bottom + node.offsetHeight <= vspace)
9657
- { top = pos.bottom }
9658
  if (left + node.offsetWidth > hspace)
9659
- { left = hspace - node.offsetWidth }
9660
  }
9661
- node.style.top = top + "px"
9662
- node.style.left = node.style.right = ""
9663
  if (horiz == "right") {
9664
- left = display.sizer.clientWidth - node.offsetWidth
9665
- node.style.right = "0px"
9666
  } else {
9667
- if (horiz == "left") { left = 0 }
9668
- else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2 }
9669
- node.style.left = left + "px"
9670
  }
9671
  if (scroll)
9672
- { scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight) }
9673
  },
9674
 
9675
  triggerOnKeyDown: methodOp(onKeyDown),
@@ -9681,16 +9714,16 @@ function addEditorMethods(CodeMirror) {
9681
  { return commands[cmd].call(null, this) }
9682
  },
9683
 
9684
- triggerElectric: methodOp(function(text) { triggerElectric(this, text) }),
9685
 
9686
  findPosH: function(from, amount, unit, visually) {
9687
  var this$1 = this;
9688
 
9689
- var dir = 1
9690
- if (amount < 0) { dir = -1; amount = -amount }
9691
- var cur = clipPos(this.doc, from)
9692
  for (var i = 0; i < amount; ++i) {
9693
- cur = findPosH(this$1.doc, cur, dir, unit, visually)
9694
  if (cur.hitSide) { break }
9695
  }
9696
  return cur
@@ -9699,36 +9732,36 @@ function addEditorMethods(CodeMirror) {
9699
  moveH: methodOp(function(dir, unit) {
9700
  var this$1 = this;
9701
 
9702
- this.extendSelectionsBy(function (range) {
9703
- if (this$1.display.shift || this$1.doc.extend || range.empty())
9704
- { return findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually) }
9705
  else
9706
- { return dir < 0 ? range.from() : range.to() }
9707
- }, sel_move)
9708
  }),
9709
 
9710
  deleteH: methodOp(function(dir, unit) {
9711
- var sel = this.doc.sel, doc = this.doc
9712
  if (sel.somethingSelected())
9713
- { doc.replaceSelection("", null, "+delete") }
9714
  else
9715
- { deleteNearSelection(this, function (range) {
9716
- var other = findPosH(doc, range.head, dir, unit, false)
9717
- return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other}
9718
- }) }
9719
  }),
9720
 
9721
  findPosV: function(from, amount, unit, goalColumn) {
9722
  var this$1 = this;
9723
 
9724
- var dir = 1, x = goalColumn
9725
- if (amount < 0) { dir = -1; amount = -amount }
9726
- var cur = clipPos(this.doc, from)
9727
  for (var i = 0; i < amount; ++i) {
9728
- var coords = cursorCoords(this$1, cur, "div")
9729
- if (x == null) { x = coords.left }
9730
- else { coords.left = x }
9731
- cur = findPosV(this$1, coords, dir, unit)
9732
  if (cur.hitSide) { break }
9733
  }
9734
  return cur
@@ -9737,37 +9770,37 @@ function addEditorMethods(CodeMirror) {
9737
  moveV: methodOp(function(dir, unit) {
9738
  var this$1 = this;
9739
 
9740
- var doc = this.doc, goals = []
9741
- var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected()
9742
- doc.extendSelectionsBy(function (range) {
9743
  if (collapse)
9744
- { return dir < 0 ? range.from() : range.to() }
9745
- var headPos = cursorCoords(this$1, range.head, "div")
9746
- if (range.goalColumn != null) { headPos.left = range.goalColumn }
9747
- goals.push(headPos.left)
9748
- var pos = findPosV(this$1, headPos, dir, unit)
9749
- if (unit == "page" && range == doc.sel.primary())
9750
- { addToScrollPos(this$1, null, charCoords(this$1, pos, "div").top - headPos.top) }
9751
  return pos
9752
- }, sel_move)
9753
  if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
9754
- { doc.sel.ranges[i].goalColumn = goals[i] } }
9755
  }),
9756
 
9757
  // Find the word at the given position (as returned by coordsChar).
9758
  findWordAt: function(pos) {
9759
- var doc = this.doc, line = getLine(doc, pos.line).text
9760
- var start = pos.ch, end = pos.ch
9761
  if (line) {
9762
- var helper = this.getHelper(pos, "wordChars")
9763
- if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end }
9764
- var startChar = line.charAt(start)
9765
  var check = isWordChar(startChar, helper)
9766
  ? function (ch) { return isWordChar(ch, helper); }
9767
  : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
9768
- : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); }
9769
- while (start > 0 && check(line.charAt(start - 1))) { --start }
9770
- while (end < line.length && check(line.charAt(end))) { ++end }
9771
  }
9772
  return new Range(Pos(pos.line, start), Pos(pos.line, end))
9773
  },
@@ -9775,92 +9808,94 @@ function addEditorMethods(CodeMirror) {
9775
  toggleOverwrite: function(value) {
9776
  if (value != null && value == this.state.overwrite) { return }
9777
  if (this.state.overwrite = !this.state.overwrite)
9778
- { addClass(this.display.cursorDiv, "CodeMirror-overwrite") }
9779
  else
9780
- { rmClass(this.display.cursorDiv, "CodeMirror-overwrite") }
9781
 
9782
- signal(this, "overwriteToggle", this, this.state.overwrite)
9783
  },
9784
  hasFocus: function() { return this.display.input.getField() == activeElt() },
9785
  isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
9786
 
9787
  scrollTo: methodOp(function(x, y) {
9788
- if (x != null || y != null) { resolveScrollToPos(this) }
9789
- if (x != null) { this.curOp.scrollLeft = x }
9790
- if (y != null) { this.curOp.scrollTop = y }
9791
  }),
9792
  getScrollInfo: function() {
9793
- var scroller = this.display.scroller
9794
  return {left: scroller.scrollLeft, top: scroller.scrollTop,
9795
  height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
9796
  width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
9797
  clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
9798
  },
9799
 
9800
- scrollIntoView: methodOp(function(range, margin) {
9801
- if (range == null) {
9802
- range = {from: this.doc.sel.primary().head, to: null}
9803
- if (margin == null) { margin = this.options.cursorScrollMargin }
9804
- } else if (typeof range == "number") {
9805
- range = {from: Pos(range, 0), to: null}
9806
- } else if (range.from == null) {
9807
- range = {from: range, to: null}
9808
- }
9809
- if (!range.to) { range.to = range.from }
9810
- range.margin = margin || 0
9811
-
9812
- if (range.from.line != null) {
9813
- resolveScrollToPos(this)
9814
- this.curOp.scrollToPos = range
9815
  } else {
9816
- var sPos = calculateScrollPos(this, Math.min(range.from.left, range.to.left),
9817
- Math.min(range.from.top, range.to.top) - range.margin,
9818
- Math.max(range.from.right, range.to.right),
9819
- Math.max(range.from.bottom, range.to.bottom) + range.margin)
9820
- this.scrollTo(sPos.scrollLeft, sPos.scrollTop)
 
 
9821
  }
9822
  }),
9823
 
9824
  setSize: methodOp(function(width, height) {
9825
  var this$1 = this;
9826
 
9827
- var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; }
9828
- if (width != null) { this.display.wrapper.style.width = interpret(width) }
9829
- if (height != null) { this.display.wrapper.style.height = interpret(height) }
9830
- if (this.options.lineWrapping) { clearLineMeasurementCache(this) }
9831
- var lineNo = this.display.viewFrom
9832
- this.doc.iter(lineNo, this.display.viewTo, function (line) {
9833
  if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
9834
- { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo, "widget"); break } } }
9835
- ++lineNo
9836
- })
9837
- this.curOp.forceUpdate = true
9838
- signal(this, "refresh", this)
9839
  }),
9840
 
9841
  operation: function(f){return runInOp(this, f)},
9842
 
9843
  refresh: methodOp(function() {
9844
- var oldHeight = this.display.cachedTextHeight
9845
- regChange(this)
9846
- this.curOp.forceUpdate = true
9847
- clearCaches(this)
9848
- this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop)
9849
- updateGutterSpace(this)
9850
  if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
9851
- { estimateLineHeights(this) }
9852
- signal(this, "refresh", this)
9853
  }),
9854
 
9855
  swapDoc: methodOp(function(doc) {
9856
- var old = this.doc
9857
- old.cm = null
9858
- attachDoc(this, doc)
9859
- clearCaches(this)
9860
- this.display.input.reset()
9861
- this.scrollTo(doc.scrollLeft, doc.scrollTop)
9862
- this.curOp.forceScroll = true
9863
- signalLater(this, "swapDoc", this, old)
9864
  return old
9865
  }),
9866
 
@@ -9868,18 +9903,18 @@ function addEditorMethods(CodeMirror) {
9868
  getWrapperElement: function(){return this.display.wrapper},
9869
  getScrollerElement: function(){return this.display.scroller},
9870
  getGutterElement: function(){return this.display.gutters}
9871
- }
9872
- eventMixin(CodeMirror)
9873
 
9874
  CodeMirror.registerHelper = function(type, name, value) {
9875
- if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []} }
9876
- helpers[type][name] = value
9877
- }
9878
  CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
9879
- CodeMirror.registerHelper(type, name, value)
9880
- helpers[type]._global.push({pred: predicate, val: value})
9881
- }
9882
- }
9883
 
9884
  // Used for horizontal relative motion. Dir is -1 or 1 (left or
9885
  // right), unit can be "char", "column" (like char, but doesn't
@@ -9891,59 +9926,59 @@ function addEditorMethods(CodeMirror) {
9891
  // position. The resulting position will have a hitSide=true
9892
  // property if it reached the end of the document.
9893
  function findPosH(doc, pos, dir, unit, visually) {
9894
- var oldPos = pos
9895
- var origDir = dir
9896
- var lineObj = getLine(doc, pos.line)
9897
  function findNextLine() {
9898
- var l = pos.line + dir
9899
  if (l < doc.first || l >= doc.first + doc.size) { return false }
9900
- pos = new Pos(l, pos.ch, pos.sticky)
9901
  return lineObj = getLine(doc, l)
9902
  }
9903
  function moveOnce(boundToLine) {
9904
- var next
9905
  if (visually) {
9906
- next = moveVisually(doc.cm, lineObj, pos, dir)
9907
  } else {
9908
- next = moveLogically(lineObj, pos, dir)
9909
  }
9910
  if (next == null) {
9911
  if (!boundToLine && findNextLine())
9912
- { pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir) }
9913
  else
9914
  { return false }
9915
  } else {
9916
- pos = next
9917
  }
9918
  return true
9919
  }
9920
 
9921
  if (unit == "char") {
9922
- moveOnce()
9923
  } else if (unit == "column") {
9924
- moveOnce(true)
9925
  } else if (unit == "word" || unit == "group") {
9926
- var sawType = null, group = unit == "group"
9927
- var helper = doc.cm && doc.cm.getHelper(pos, "wordChars")
9928
  for (var first = true;; first = false) {
9929
  if (dir < 0 && !moveOnce(!first)) { break }
9930
- var cur = lineObj.text.charAt(pos.ch) || "\n"
9931
  var type = isWordChar(cur, helper) ? "w"
9932
  : group && cur == "\n" ? "n"
9933
  : !group || /\s/.test(cur) ? null
9934
- : "p"
9935
- if (group && !first && !type) { type = "s" }
9936
  if (sawType && sawType != type) {
9937
- if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after"}
9938
  break
9939
  }
9940
 
9941
- if (type) { sawType = type }
9942
  if (dir > 0 && !moveOnce(!first)) { break }
9943
  }
9944
  }
9945
- var result = skipAtomic(doc, pos, oldPos, origDir, true)
9946
- if (equalCursorPos(oldPos, result)) { result.hitSide = true }
9947
  return result
9948
  }
9949
 
@@ -9951,21 +9986,21 @@ function findPosH(doc, pos, dir, unit, visually) {
9951
  // "page" or "line". The resulting position will have a hitSide=true
9952
  // property if it reached the end of the document.
9953
  function findPosV(cm, pos, dir, unit) {
9954
- var doc = cm.doc, x = pos.left, y
9955
  if (unit == "page") {
9956
- var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight)
9957
- var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3)
9958
- y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount
9959
 
9960
  } else if (unit == "line") {
9961
- y = dir > 0 ? pos.bottom + 3 : pos.top - 3
9962
  }
9963
- var target
9964
  for (;;) {
9965
- target = coordsChar(cm, x, y)
9966
  if (!target.outside) { break }
9967
  if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
9968
- y += dir * 5
9969
  }
9970
  return target
9971
  }
@@ -9973,399 +10008,438 @@ function findPosV(cm, pos, dir, unit) {
9973
  // CONTENTEDITABLE INPUT STYLE
9974
 
9975
  var ContentEditableInput = function(cm) {
9976
- this.cm = cm
9977
- this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null
9978
- this.polling = new Delayed()
9979
- this.composing = null
9980
- this.gracePeriod = false
9981
- this.readDOMTimeout = null
9982
  };
9983
 
9984
  ContentEditableInput.prototype.init = function (display) {
9985
  var this$1 = this;
9986
 
9987
- var input = this, cm = input.cm
9988
- var div = input.div = display.lineDiv
9989
- disableBrowserMagic(div, cm.options.spellcheck)
9990
 
9991
  on(div, "paste", function (e) {
9992
  if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
9993
  // IE doesn't fire input events, so we schedule a read for the pasted content in this way
9994
- if (ie_version <= 11) { setTimeout(operation(cm, function () {
9995
- if (!input.pollContent()) { regChange(cm) }
9996
- }), 20) }
9997
- })
9998
 
9999
  on(div, "compositionstart", function (e) {
10000
- this$1.composing = {data: e.data, done: false}
10001
- })
10002
  on(div, "compositionupdate", function (e) {
10003
- if (!this$1.composing) { this$1.composing = {data: e.data, done: false} }
10004
- })
10005
  on(div, "compositionend", function (e) {
10006
  if (this$1.composing) {
10007
- if (e.data != this$1.composing.data) { this$1.readFromDOMSoon() }
10008
- this$1.composing.done = true
10009
  }
10010
- })
10011
 
10012
- on(div, "touchstart", function () { return input.forceCompositionEnd(); })
10013
 
10014
  on(div, "input", function () {
10015
- if (!this$1.composing) { this$1.readFromDOMSoon() }
10016
- })
10017
 
10018
  function onCopyCut(e) {
10019
  if (signalDOMEvent(cm, e)) { return }
10020
  if (cm.somethingSelected()) {
10021
- setLastCopied({lineWise: false, text: cm.getSelections()})
10022
- if (e.type == "cut") { cm.replaceSelection("", null, "cut") }
10023
  } else if (!cm.options.lineWiseCopyCut) {
10024
  return
10025
  } else {
10026
- var ranges = copyableRanges(cm)
10027
- setLastCopied({lineWise: true, text: ranges.text})
10028
  if (e.type == "cut") {
10029
  cm.operation(function () {
10030
- cm.setSelections(ranges.ranges, 0, sel_dontScroll)
10031
- cm.replaceSelection("", null, "cut")
10032
- })
10033
  }
10034
  }
10035
  if (e.clipboardData) {
10036
- e.clipboardData.clearData()
10037
- var content = lastCopied.text.join("\n")
10038
  // iOS exposes the clipboard API, but seems to discard content inserted into it
10039
- e.clipboardData.setData("Text", content)
10040
  if (e.clipboardData.getData("Text") == content) {
10041
- e.preventDefault()
10042
  return
10043
  }
10044
  }
10045
  // Old-fashioned briefly-focus-a-textarea hack
10046
- var kludge = hiddenTextarea(), te = kludge.firstChild
10047
- cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild)
10048
- te.value = lastCopied.text.join("\n")
10049
- var hadFocus = document.activeElement
10050
- selectInput(te)
10051
  setTimeout(function () {
10052
- cm.display.lineSpace.removeChild(kludge)
10053
- hadFocus.focus()
10054
- if (hadFocus == div) { input.showPrimarySelection() }
10055
- }, 50)
10056
  }
10057
- on(div, "copy", onCopyCut)
10058
- on(div, "cut", onCopyCut)
10059
  };
10060
 
10061
  ContentEditableInput.prototype.prepareSelection = function () {
10062
- var result = prepareSelection(this.cm, false)
10063
- result.focus = this.cm.state.focused
10064
  return result
10065
  };
10066
 
10067
  ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
10068
  if (!info || !this.cm.display.view.length) { return }
10069
- if (info.focus || takeFocus) { this.showPrimarySelection() }
10070
- this.showMultipleSelections(info)
10071
  };
10072
 
10073
  ContentEditableInput.prototype.showPrimarySelection = function () {
10074
- var sel = window.getSelection(), prim = this.cm.doc.sel.primary()
10075
- var curAnchor = domToPos(this.cm, sel.anchorNode, sel.anchorOffset)
10076
- var curFocus = domToPos(this.cm, sel.focusNode, sel.focusOffset)
10077
  if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
10078
  cmp(minPos(curAnchor, curFocus), prim.from()) == 0 &&
10079
  cmp(maxPos(curAnchor, curFocus), prim.to()) == 0)
10080
  { return }
10081
 
10082
- var start = posToDOM(this.cm, prim.from())
10083
- var end = posToDOM(this.cm, prim.to())
10084
- if (!start && !end) { return }
 
 
 
10085
 
10086
- var view = this.cm.display.view
10087
- var old = sel.rangeCount && sel.getRangeAt(0)
10088
  if (!start) {
10089
- start = {node: view[0].measure.map[2], offset: 0}
10090
  } else if (!end) { // FIXME dangerously hacky
10091
- var measure = view[view.length - 1].measure
10092
- var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map
10093
- end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]}
10094
  }
10095
 
10096
- var rng
10097
- try { rng = range(start.node, start.offset, end.offset, end.node) }
10098
  catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
10099
  if (rng) {
10100
  if (!gecko && this.cm.state.focused) {
10101
- sel.collapse(start.node, start.offset)
10102
  if (!rng.collapsed) {
10103
- sel.removeAllRanges()
10104
- sel.addRange(rng)
10105
  }
10106
  } else {
10107
- sel.removeAllRanges()
10108
- sel.addRange(rng)
10109
  }
10110
- if (old && sel.anchorNode == null) { sel.addRange(old) }
10111
- else if (gecko) { this.startGracePeriod() }
10112
  }
10113
- this.rememberSelection()
10114
  };
10115
 
10116
  ContentEditableInput.prototype.startGracePeriod = function () {
10117
  var this$1 = this;
10118
 
10119
- clearTimeout(this.gracePeriod)
10120
  this.gracePeriod = setTimeout(function () {
10121
- this$1.gracePeriod = false
10122
  if (this$1.selectionChanged())
10123
- { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }) }
10124
- }, 20)
10125
  };
10126
 
10127
  ContentEditableInput.prototype.showMultipleSelections = function (info) {
10128
- removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors)
10129
- removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection)
10130
  };
10131
 
10132
  ContentEditableInput.prototype.rememberSelection = function () {
10133
- var sel = window.getSelection()
10134
- this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset
10135
- this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset
10136
  };
10137
 
10138
  ContentEditableInput.prototype.selectionInEditor = function () {
10139
- var sel = window.getSelection()
10140
  if (!sel.rangeCount) { return false }
10141
- var node = sel.getRangeAt(0).commonAncestorContainer
10142
  return contains(this.div, node)
10143
  };
10144
 
10145
  ContentEditableInput.prototype.focus = function () {
10146
  if (this.cm.options.readOnly != "nocursor") {
10147
  if (!this.selectionInEditor())
10148
- { this.showSelection(this.prepareSelection(), true) }
10149
- this.div.focus()
10150
  }
10151
  };
10152
- ContentEditableInput.prototype.blur = function () { this.div.blur() };
10153
  ContentEditableInput.prototype.getField = function () { return this.div };
10154
 
10155
  ContentEditableInput.prototype.supportsTouch = function () { return true };
10156
 
10157
  ContentEditableInput.prototype.receivedFocus = function () {
10158
- var input = this
10159
  if (this.selectionInEditor())
10160
- { this.pollSelection() }
10161
  else
10162
- { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }) }
10163
 
10164
  function poll() {
10165
  if (input.cm.state.focused) {
10166
- input.pollSelection()
10167
- input.polling.set(input.cm.options.pollInterval, poll)
10168
  }
10169
  }
10170
- this.polling.set(this.cm.options.pollInterval, poll)
10171
  };
10172
 
10173
  ContentEditableInput.prototype.selectionChanged = function () {
10174
- var sel = window.getSelection()
10175
  return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
10176
  sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
10177
  };
10178
 
10179
  ContentEditableInput.prototype.pollSelection = function () {
10180
- if (!this.composing && this.readDOMTimeout == null && !this.gracePeriod && this.selectionChanged()) {
10181
- var sel = window.getSelection(), cm = this.cm
10182
- this.rememberSelection()
10183
- var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset)
10184
- var head = domToPos(cm, sel.focusNode, sel.focusOffset)
10185
- if (anchor && head) { runInOp(cm, function () {
10186
- setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll)
10187
- if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true }
10188
- }) }
 
 
 
 
10189
  }
 
 
 
 
 
 
 
 
10190
  };
10191
 
10192
  ContentEditableInput.prototype.pollContent = function () {
10193
  if (this.readDOMTimeout != null) {
10194
- clearTimeout(this.readDOMTimeout)
10195
- this.readDOMTimeout = null
10196
  }
10197
 
10198
- var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary()
10199
- var from = sel.from(), to = sel.to()
10200
  if (from.ch == 0 && from.line > cm.firstLine())
10201
- { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length) }
10202
  if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
10203
- { to = Pos(to.line + 1, 0) }
10204
  if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
10205
 
10206
- var fromIndex, fromLine, fromNode
10207
  if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
10208
- fromLine = lineNo(display.view[0].line)
10209
- fromNode = display.view[0].node
10210
  } else {
10211
- fromLine = lineNo(display.view[fromIndex].line)
10212
- fromNode = display.view[fromIndex - 1].node.nextSibling
10213
  }
10214
- var toIndex = findViewIndex(cm, to.line)
10215
- var toLine, toNode
10216
  if (toIndex == display.view.length - 1) {
10217
- toLine = display.viewTo - 1
10218
- toNode = display.lineDiv.lastChild
10219
  } else {
10220
- toLine = lineNo(display.view[toIndex + 1].line) - 1
10221
- toNode = display.view[toIndex + 1].node.previousSibling
10222
  }
10223
 
10224
  if (!fromNode) { return false }
10225
- var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine))
10226
- var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length))
10227
  while (newText.length > 1 && oldText.length > 1) {
10228
- if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine-- }
10229
- else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++ }
10230
  else { break }
10231
  }
10232
 
10233
- var cutFront = 0, cutEnd = 0
10234
- var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length)
10235
  while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
10236
- { ++cutFront }
10237
- var newBot = lst(newText), oldBot = lst(oldText)
10238
  var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
10239
- oldBot.length - (oldText.length == 1 ? cutFront : 0))
10240
  while (cutEnd < maxCutEnd &&
10241
  newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
10242
- { ++cutEnd }
 
 
 
 
 
 
 
 
10243
 
10244
- newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "")
10245
- newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "")
10246
 
10247
- var chFrom = Pos(fromLine, cutFront)
10248
- var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0)
10249
  if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
10250
- replaceRange(cm.doc, newText, chFrom, chTo, "+input")
10251
  return true
10252
  }
10253
  };
10254
 
10255
  ContentEditableInput.prototype.ensurePolled = function () {
10256
- this.forceCompositionEnd()
10257
  };
10258
  ContentEditableInput.prototype.reset = function () {
10259
- this.forceCompositionEnd()
10260
  };
10261
  ContentEditableInput.prototype.forceCompositionEnd = function () {
10262
  if (!this.composing) { return }
10263
- clearTimeout(this.readDOMTimeout)
10264
- this.composing = null
10265
- if (!this.pollContent()) { regChange(this.cm) }
10266
- this.div.blur()
10267
- this.div.focus()
10268
  };
10269
  ContentEditableInput.prototype.readFromDOMSoon = function () {
10270
  var this$1 = this;
10271
 
10272
  if (this.readDOMTimeout != null) { return }
10273
  this.readDOMTimeout = setTimeout(function () {
10274
- this$1.readDOMTimeout = null
10275
  if (this$1.composing) {
10276
- if (this$1.composing.done) { this$1.composing = null }
10277
  else { return }
10278
  }
10279
- if (this$1.cm.isReadOnly() || !this$1.pollContent())
10280
- { runInOp(this$1.cm, function () { return regChange(this$1.cm); }) }
10281
- }, 80)
 
 
 
 
 
 
10282
  };
10283
 
10284
  ContentEditableInput.prototype.setUneditable = function (node) {
10285
- node.contentEditable = "false"
10286
  };
10287
 
10288
  ContentEditableInput.prototype.onKeyPress = function (e) {
10289
  if (e.charCode == 0) { return }
10290
- e.preventDefault()
10291
  if (!this.cm.isReadOnly())
10292
- { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0) }
10293
  };
10294
 
10295
  ContentEditableInput.prototype.readOnlyChanged = function (val) {
10296
- this.div.contentEditable = String(val != "nocursor")
10297
  };
10298
 
10299
  ContentEditableInput.prototype.onContextMenu = function () {};
10300
  ContentEditableInput.prototype.resetPosition = function () {};
10301
 
10302
- ContentEditableInput.prototype.needsContentAttribute = true
10303
 
10304
  function posToDOM(cm, pos) {
10305
- var view = findViewForLine(cm, pos.line)
10306
  if (!view || view.hidden) { return null }
10307
- var line = getLine(cm.doc, pos.line)
10308
- var info = mapFromLineView(view, line, pos.line)
10309
 
10310
- var order = getOrder(line), side = "left"
10311
  if (order) {
10312
- var partPos = getBidiPartAt(order, pos.ch)
10313
- side = partPos % 2 ? "right" : "left"
10314
  }
10315
- var result = nodeAndOffsetInLineMap(info.map, pos.ch, side)
10316
- result.offset = result.collapse == "right" ? result.end : result.start
10317
  return result
10318
  }
10319
 
 
 
 
 
 
 
10320
  function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
10321
 
10322
  function domTextBetween(cm, from, to, fromLine, toLine) {
10323
- var text = "", closing = false, lineSep = cm.doc.lineSeparator()
10324
  function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
 
 
 
 
 
 
 
 
 
 
 
 
10325
  function walk(node) {
10326
  if (node.nodeType == 1) {
10327
- var cmText = node.getAttribute("cm-text")
10328
  if (cmText != null) {
10329
- if (cmText == "") { text += node.textContent.replace(/\u200b/g, "") }
10330
- else { text += cmText }
10331
  return
10332
  }
10333
- var markerID = node.getAttribute("cm-marker"), range
10334
  if (markerID) {
10335
- var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID))
10336
- if (found.length && (range = found[0].find()))
10337
- { text += getBetween(cm.doc, range.from, range.to).join(lineSep) }
10338
  return
10339
  }
10340
  if (node.getAttribute("contenteditable") == "false") { return }
 
 
10341
  for (var i = 0; i < node.childNodes.length; i++)
10342
- { walk(node.childNodes[i]) }
10343
- if (/^(pre|div|p)$/i.test(node.nodeName))
10344
- { closing = true }
10345
  } else if (node.nodeType == 3) {
10346
- var val = node.nodeValue
10347
- if (!val) { return }
10348
- if (closing) {
10349
- text += lineSep
10350
- closing = false
10351
- }
10352
- text += val
10353
  }
10354
  }
10355
  for (;;) {
10356
- walk(from)
10357
  if (from == to) { break }
10358
- from = from.nextSibling
10359
  }
10360
  return text
10361
  }
10362
 
10363
  function domToPos(cm, node, offset) {
10364
- var lineNode
10365
  if (node == cm.display.lineDiv) {
10366
- lineNode = cm.display.lineDiv.childNodes[offset]
10367
  if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
10368
- node = null; offset = 0
10369
  } else {
10370
  for (lineNode = node;; lineNode = lineNode.parentNode) {
10371
  if (!lineNode || lineNode == cm.display.lineDiv) { return null }
@@ -10373,196 +10447,196 @@ function domToPos(cm, node, offset) {
10373
  }
10374
  }
10375
  for (var i = 0; i < cm.display.view.length; i++) {
10376
- var lineView = cm.display.view[i]
10377
  if (lineView.node == lineNode)
10378
  { return locateNodeInLineView(lineView, node, offset) }
10379
  }
10380
  }
10381
 
10382
  function locateNodeInLineView(lineView, node, offset) {
10383
- var wrapper = lineView.text.firstChild, bad = false
10384
  if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
10385
  if (node == wrapper) {
10386
- bad = true
10387
- node = wrapper.childNodes[offset]
10388
- offset = 0
10389
  if (!node) {
10390
- var line = lineView.rest ? lst(lineView.rest) : lineView.line
10391
  return badPos(Pos(lineNo(line), line.text.length), bad)
10392
  }
10393
  }
10394
 
10395
- var textNode = node.nodeType == 3 ? node : null, topNode = node
10396
  if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
10397
- textNode = node.firstChild
10398
- if (offset) { offset = textNode.nodeValue.length }
10399
  }
10400
- while (topNode.parentNode != wrapper) { topNode = topNode.parentNode }
10401
- var measure = lineView.measure, maps = measure.maps
10402
 
10403
  function find(textNode, topNode, offset) {
10404
  for (var i = -1; i < (maps ? maps.length : 0); i++) {
10405
- var map = i < 0 ? measure.map : maps[i]
10406
- for (var j = 0; j < map.length; j += 3) {
10407
- var curNode = map[j + 2]
10408
  if (curNode == textNode || curNode == topNode) {
10409
- var line = lineNo(i < 0 ? lineView.line : lineView.rest[i])
10410
- var ch = map[j] + offset
10411
- if (offset < 0 || curNode != textNode) { ch = map[j + (offset ? 1 : 0)] }
10412
  return Pos(line, ch)
10413
  }
10414
  }
10415
  }
10416
  }
10417
- var found = find(textNode, topNode, offset)
10418
  if (found) { return badPos(found, bad) }
10419
 
10420
  // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
10421
  for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
10422
- found = find(after, after.firstChild, 0)
10423
  if (found)
10424
  { return badPos(Pos(found.line, found.ch - dist), bad) }
10425
  else
10426
- { dist += after.textContent.length }
10427
  }
10428
  for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
10429
- found = find(before, before.firstChild, -1)
10430
  if (found)
10431
  { return badPos(Pos(found.line, found.ch + dist$1), bad) }
10432
  else
10433
- { dist$1 += before.textContent.length }
10434
  }
10435
  }
10436
 
10437
  // TEXTAREA INPUT STYLE
10438
 
10439
  var TextareaInput = function(cm) {
10440
- this.cm = cm
10441
  // See input.poll and input.reset
10442
- this.prevInput = ""
10443
 
10444
  // Flag that indicates whether we expect input to appear real soon
10445
  // now (after some event like 'keypress' or 'input') and are
10446
  // polling intensively.
10447
- this.pollingFast = false
10448
  // Self-resetting timeout for the poller
10449
- this.polling = new Delayed()
10450
  // Tracks when input.reset has punted to just putting a short
10451
  // string into the textarea instead of the full selection.
10452
- this.inaccurateSelection = false
10453
  // Used to work around IE issue with selection being forgotten when focus moves away from textarea
10454
- this.hasSelection = false
10455
- this.composing = null
10456
  };
10457
 
10458
  TextareaInput.prototype.init = function (display) {
10459
  var this$1 = this;
10460
 
10461
- var input = this, cm = this.cm
10462
 
10463
  // Wraps and hides input textarea
10464
- var div = this.wrapper = hiddenTextarea()
10465
  // The semihidden textarea that is focused when the editor is
10466
  // focused, and receives input.
10467
- var te = this.textarea = div.firstChild
10468
- display.wrapper.insertBefore(div, display.wrapper.firstChild)
10469
 
10470
  // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
10471
- if (ios) { te.style.width = "0px" }
10472
 
10473
  on(te, "input", function () {
10474
- if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null }
10475
- input.poll()
10476
- })
10477
 
10478
  on(te, "paste", function (e) {
10479
  if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
10480
 
10481
- cm.state.pasteIncoming = true
10482
- input.fastPoll()
10483
- })
10484
 
10485
  function prepareCopyCut(e) {
10486
  if (signalDOMEvent(cm, e)) { return }
10487
  if (cm.somethingSelected()) {
10488
- setLastCopied({lineWise: false, text: cm.getSelections()})
10489
  if (input.inaccurateSelection) {
10490
- input.prevInput = ""
10491
- input.inaccurateSelection = false
10492
- te.value = lastCopied.text.join("\n")
10493
- selectInput(te)
10494
  }
10495
  } else if (!cm.options.lineWiseCopyCut) {
10496
  return
10497
  } else {
10498
- var ranges = copyableRanges(cm)
10499
- setLastCopied({lineWise: true, text: ranges.text})
10500
  if (e.type == "cut") {
10501
- cm.setSelections(ranges.ranges, null, sel_dontScroll)
10502
  } else {
10503
- input.prevInput = ""
10504
- te.value = ranges.text.join("\n")
10505
- selectInput(te)
10506
  }
10507
  }
10508
- if (e.type == "cut") { cm.state.cutIncoming = true }
10509
  }
10510
- on(te, "cut", prepareCopyCut)
10511
- on(te, "copy", prepareCopyCut)
10512
 
10513
  on(display.scroller, "paste", function (e) {
10514
  if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
10515
- cm.state.pasteIncoming = true
10516
- input.focus()
10517
- })
10518
 
10519
  // Prevent normal selection in the editor (we handle our own)
10520
  on(display.lineSpace, "selectstart", function (e) {
10521
- if (!eventInWidget(display, e)) { e_preventDefault(e) }
10522
- })
10523
 
10524
  on(te, "compositionstart", function () {
10525
- var start = cm.getCursor("from")
10526
- if (input.composing) { input.composing.range.clear() }
10527
  input.composing = {
10528
  start: start,
10529
  range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
10530
- }
10531
- })
10532
  on(te, "compositionend", function () {
10533
  if (input.composing) {
10534
- input.poll()
10535
- input.composing.range.clear()
10536
- input.composing = null
10537
  }
10538
- })
10539
  };
10540
 
10541
  TextareaInput.prototype.prepareSelection = function () {
10542
  // Redraw the selection and/or cursor
10543
- var cm = this.cm, display = cm.display, doc = cm.doc
10544
- var result = prepareSelection(cm)
10545
 
10546
  // Move the hidden textarea near the cursor to prevent scrolling artifacts
10547
  if (cm.options.moveInputWithCursor) {
10548
- var headPos = cursorCoords(cm, doc.sel.primary().head, "div")
10549
- var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect()
10550
  result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
10551
- headPos.top + lineOff.top - wrapOff.top))
10552
  result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
10553
- headPos.left + lineOff.left - wrapOff.left))
10554
  }
10555
 
10556
  return result
10557
  };
10558
 
10559
  TextareaInput.prototype.showSelection = function (drawn) {
10560
- var cm = this.cm, display = cm.display
10561
- removeChildrenAndAdd(display.cursorDiv, drawn.cursors)
10562
- removeChildrenAndAdd(display.selectionDiv, drawn.selection)
10563
  if (drawn.teTop != null) {
10564
- this.wrapper.style.top = drawn.teTop + "px"
10565
- this.wrapper.style.left = drawn.teLeft + "px"
10566
  }
10567
  };
10568
 
@@ -10570,21 +10644,21 @@ TextareaInput.prototype.showSelection = function (drawn) {
10570
  // when not typing and nothing is selected)
10571
  TextareaInput.prototype.reset = function (typing) {
10572
  if (this.contextMenuPending) { return }
10573
- var minimal, selected, cm = this.cm, doc = cm.doc
10574
  if (cm.somethingSelected()) {
10575
- this.prevInput = ""
10576
- var range = doc.sel.primary()
10577
  minimal = hasCopyEvent &&
10578
- (range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000)
10579
- var content = minimal ? "-" : selected || cm.getSelection()
10580
- this.textarea.value = content
10581
- if (cm.state.focused) { selectInput(this.textarea) }
10582
- if (ie && ie_version >= 9) { this.hasSelection = content }
10583
  } else if (!typing) {
10584
- this.prevInput = this.textarea.value = ""
10585
- if (ie && ie_version >= 9) { this.hasSelection = null }
10586
  }
10587
- this.inaccurateSelection = minimal
10588
  };
10589
 
10590
  TextareaInput.prototype.getField = function () { return this.textarea };
@@ -10593,18 +10667,18 @@ TextareaInput.prototype.supportsTouch = function () { return false };
10593
 
10594
  TextareaInput.prototype.focus = function () {
10595
  if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
10596
- try { this.textarea.focus() }
10597
  catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
10598
  }
10599
  };
10600
 
10601
- TextareaInput.prototype.blur = function () { this.textarea.blur() };
10602
 
10603
  TextareaInput.prototype.resetPosition = function () {
10604
- this.wrapper.style.top = this.wrapper.style.left = 0
10605
  };
10606
 
10607
- TextareaInput.prototype.receivedFocus = function () { this.slowPoll() };
10608
 
10609
  // Poll for input changes, using the normal rate of polling. This
10610
  // runs as long as the editor is focused.
@@ -10613,23 +10687,23 @@ TextareaInput.prototype.slowPoll = function () {
10613
 
10614
  if (this.pollingFast) { return }
10615
  this.polling.set(this.cm.options.pollInterval, function () {
10616
- this$1.poll()
10617
- if (this$1.cm.state.focused) { this$1.slowPoll() }
10618
- })
10619
  };
10620
 
10621
  // When an event has just come in that is likely to add or change
10622
  // something in the input textarea, we poll faster, to ensure that
10623
  // the change appears on the screen quickly.
10624
  TextareaInput.prototype.fastPoll = function () {
10625
- var missed = false, input = this
10626
- input.pollingFast = true
10627
  function p() {
10628
- var changed = input.poll()
10629
- if (!changed && !missed) {missed = true; input.polling.set(60, p)}
10630
- else {input.pollingFast = false; input.slowPoll()}
10631
  }
10632
- input.polling.set(20, p)
10633
  };
10634
 
10635
  // Read input from the textarea, and update the document to match.
@@ -10641,7 +10715,7 @@ TextareaInput.prototype.fastPoll = function () {
10641
  TextareaInput.prototype.poll = function () {
10642
  var this$1 = this;
10643
 
10644
- var cm = this.cm, input = this.textarea, prevInput = this.prevInput
10645
  // Since this is called a *lot*, try to bail out as cheaply as
10646
  // possible when it is clear that nothing happened. hasSelection
10647
  // will be the case when there is a lot of text in the textarea,
@@ -10651,7 +10725,7 @@ TextareaInput.prototype.poll = function () {
10651
  cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
10652
  { return false }
10653
 
10654
- var text = input.value
10655
  // If nothing changed, bail.
10656
  if (text == prevInput && !cm.somethingSelected()) { return false }
10657
  // Work around nonsensical selection resetting in IE9/10, and
@@ -10659,286 +10733,287 @@ TextareaInput.prototype.poll = function () {
10659
  // some key combos in Mac (#2689).
10660
  if (ie && ie_version >= 9 && this.hasSelection === text ||
10661
  mac && /[\uf700-\uf7ff]/.test(text)) {
10662
- cm.display.input.reset()
10663
  return false
10664
  }
10665
 
10666
  if (cm.doc.sel == cm.display.selForContextMenu) {
10667
- var first = text.charCodeAt(0)
10668
- if (first == 0x200b && !prevInput) { prevInput = "\u200b" }
10669
  if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
10670
  }
10671
  // Find the part of the input that is actually new
10672
- var same = 0, l = Math.min(prevInput.length, text.length)
10673
- while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same }
10674
 
10675
  runInOp(cm, function () {
10676
  applyTextInput(cm, text.slice(same), prevInput.length - same,
10677
- null, this$1.composing ? "*compose" : null)
10678
 
10679
  // Don't leave long text in the textarea, since it makes further polling slow
10680
- if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = "" }
10681
- else { this$1.prevInput = text }
10682
 
10683
  if (this$1.composing) {
10684
- this$1.composing.range.clear()
10685
  this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
10686
- {className: "CodeMirror-composing"})
10687
  }
10688
- })
10689
  return true
10690
  };
10691
 
10692
  TextareaInput.prototype.ensurePolled = function () {
10693
- if (this.pollingFast && this.poll()) { this.pollingFast = false }
10694
  };
10695
 
10696
  TextareaInput.prototype.onKeyPress = function () {
10697
- if (ie && ie_version >= 9) { this.hasSelection = null }
10698
- this.fastPoll()
10699
  };
10700
 
10701
  TextareaInput.prototype.onContextMenu = function (e) {
10702
- var input = this, cm = input.cm, display = cm.display, te = input.textarea
10703
- var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop
10704
  if (!pos || presto) { return } // Opera is difficult.
10705
 
10706
  // Reset the current text selection only if the click is done outside of the selection
10707
  // and 'resetSelectionOnContextMenu' option is true.
10708
- var reset = cm.options.resetSelectionOnContextMenu
10709
  if (reset && cm.doc.sel.contains(pos) == -1)
10710
- { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll) }
10711
-
10712
- var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText
10713
- input.wrapper.style.cssText = "position: absolute"
10714
- var wrapperBox = input.wrapper.getBoundingClientRect()
10715
- te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"
10716
- var oldScrollY
10717
- if (webkit) { oldScrollY = window.scrollY } // Work around Chrome issue (#2712)
10718
- display.input.focus()
10719
- if (webkit) { window.scrollTo(null, oldScrollY) }
10720
- display.input.reset()
10721
  // Adds "Select all" to context menu in FF
10722
- if (!cm.somethingSelected()) { te.value = input.prevInput = " " }
10723
- input.contextMenuPending = true
10724
- display.selForContextMenu = cm.doc.sel
10725
- clearTimeout(display.detectingSelectAll)
10726
 
10727
  // Select-all will be greyed out if there's nothing to select, so
10728
  // this adds a zero-width space so that we can later check whether
10729
  // it got selected.
10730
  function prepareSelectAllHack() {
10731
  if (te.selectionStart != null) {
10732
- var selected = cm.somethingSelected()
10733
- var extval = "\u200b" + (selected ? te.value : "")
10734
- te.value = "\u21da" // Used to catch context-menu undo
10735
- te.value = extval
10736
- input.prevInput = selected ? "" : "\u200b"
10737
- te.selectionStart = 1; te.selectionEnd = extval.length
10738
  // Re-set this, in case some other handler touched the
10739
  // selection in the meantime.
10740
- display.selForContextMenu = cm.doc.sel
10741
  }
10742
  }
10743
  function rehide() {
10744
- input.contextMenuPending = false
10745
- input.wrapper.style.cssText = oldWrapperCSS
10746
- te.style.cssText = oldCSS
10747
- if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos) }
10748
 
10749
  // Try to detect the user choosing select-all
10750
  if (te.selectionStart != null) {
10751
- if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack() }
10752
  var i = 0, poll = function () {
10753
  if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
10754
  te.selectionEnd > 0 && input.prevInput == "\u200b") {
10755
- operation(cm, selectAll)(cm)
10756
  } else if (i++ < 10) {
10757
- display.detectingSelectAll = setTimeout(poll, 500)
10758
  } else {
10759
- display.selForContextMenu = null
10760
- display.input.reset()
10761
  }
10762
- }
10763
- display.detectingSelectAll = setTimeout(poll, 200)
10764
  }
10765
  }
10766
 
10767
- if (ie && ie_version >= 9) { prepareSelectAllHack() }
10768
  if (captureRightClick) {
10769
- e_stop(e)
10770
  var mouseup = function () {
10771
- off(window, "mouseup", mouseup)
10772
- setTimeout(rehide, 20)
10773
- }
10774
- on(window, "mouseup", mouseup)
10775
  } else {
10776
- setTimeout(rehide, 50)
10777
  }
10778
  };
10779
 
10780
  TextareaInput.prototype.readOnlyChanged = function (val) {
10781
- if (!val) { this.reset() }
10782
  };
10783
 
10784
  TextareaInput.prototype.setUneditable = function () {};
10785
 
10786
- TextareaInput.prototype.needsContentAttribute = false
10787
 
10788
  function fromTextArea(textarea, options) {
10789
- options = options ? copyObj(options) : {}
10790
- options.value = textarea.value
10791
  if (!options.tabindex && textarea.tabIndex)
10792
- { options.tabindex = textarea.tabIndex }
10793
  if (!options.placeholder && textarea.placeholder)
10794
- { options.placeholder = textarea.placeholder }
10795
  // Set autofocus to true if this textarea is focused, or if it has
10796
  // autofocus and no other element is focused.
10797
  if (options.autofocus == null) {
10798
- var hasFocus = activeElt()
10799
  options.autofocus = hasFocus == textarea ||
10800
- textarea.getAttribute("autofocus") != null && hasFocus == document.body
10801
  }
10802
 
10803
- function save() {textarea.value = cm.getValue()}
10804
 
10805
- var realSubmit
10806
  if (textarea.form) {
10807
- on(textarea.form, "submit", save)
10808
  // Deplorable hack to make the submit method do the right thing.
10809
  if (!options.leaveSubmitMethodAlone) {
10810
- var form = textarea.form
10811
- realSubmit = form.submit
10812
  try {
10813
  var wrappedSubmit = form.submit = function () {
10814
- save()
10815
- form.submit = realSubmit
10816
- form.submit()
10817
- form.submit = wrappedSubmit
10818
- }
10819
  } catch(e) {}
10820
  }
10821
  }
10822
 
10823
  options.finishInit = function (cm) {
10824
- cm.save = save
10825
- cm.getTextArea = function () { return textarea; }
10826
  cm.toTextArea = function () {
10827
- cm.toTextArea = isNaN // Prevent this from being ran twice
10828
- save()
10829
- textarea.parentNode.removeChild(cm.getWrapperElement())
10830
- textarea.style.display = ""
10831
  if (textarea.form) {
10832
- off(textarea.form, "submit", save)
10833
  if (typeof textarea.form.submit == "function")
10834
- { textarea.form.submit = realSubmit }
10835
  }
10836
- }
10837
- }
10838
 
10839
- textarea.style.display = "none"
10840
- var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
10841
- options)
10842
  return cm
10843
  }
10844
 
10845
  function addLegacyProps(CodeMirror) {
10846
- CodeMirror.off = off
10847
- CodeMirror.on = on
10848
- CodeMirror.wheelEventPixels = wheelEventPixels
10849
- CodeMirror.Doc = Doc
10850
- CodeMirror.splitLines = splitLinesAuto
10851
- CodeMirror.countColumn = countColumn
10852
- CodeMirror.findColumn = findColumn
10853
- CodeMirror.isWordChar = isWordCharBasic
10854
- CodeMirror.Pass = Pass
10855
- CodeMirror.signal = signal
10856
- CodeMirror.Line = Line
10857
- CodeMirror.changeEnd = changeEnd
10858
- CodeMirror.scrollbarModel = scrollbarModel
10859
- CodeMirror.Pos = Pos
10860
- CodeMirror.cmpPos = cmp
10861
- CodeMirror.modes = modes
10862
- CodeMirror.mimeModes = mimeModes
10863
- CodeMirror.resolveMode = resolveMode
10864
- CodeMirror.getMode = getMode
10865
- CodeMirror.modeExtensions = modeExtensions
10866
- CodeMirror.extendMode = extendMode
10867
- CodeMirror.copyState = copyState
10868
- CodeMirror.startState = startState
10869
- CodeMirror.innerMode = innerMode
10870
- CodeMirror.commands = commands
10871
- CodeMirror.keyMap = keyMap
10872
- CodeMirror.keyName = keyName
10873
- CodeMirror.isModifierKey = isModifierKey
10874
- CodeMirror.lookupKey = lookupKey
10875
- CodeMirror.normalizeKeyMap = normalizeKeyMap
10876
- CodeMirror.StringStream = StringStream
10877
- CodeMirror.SharedTextMarker = SharedTextMarker
10878
- CodeMirror.TextMarker = TextMarker
10879
- CodeMirror.LineWidget = LineWidget
10880
- CodeMirror.e_preventDefault = e_preventDefault
10881
- CodeMirror.e_stopPropagation = e_stopPropagation
10882
- CodeMirror.e_stop = e_stop
10883
- CodeMirror.addClass = addClass
10884
- CodeMirror.contains = contains
10885
- CodeMirror.rmClass = rmClass
10886
- CodeMirror.keyNames = keyNames
10887
  }
10888
 
10889
  // EDITOR CONSTRUCTOR
10890
 
10891
- defineOptions(CodeMirror)
10892
 
10893
- addEditorMethods(CodeMirror)
10894
 
10895
  // Set up methods on CodeMirror's prototype to redirect to the editor's document.
10896
- var dontDelegate = "iter insert remove copy getEditor constructor".split(" ")
10897
  for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
10898
- { CodeMirror.prototype[prop] = (function(method) {
10899
  return function() {return method.apply(this.doc, arguments)}
10900
- })(Doc.prototype[prop]) } }
10901
 
10902
- eventMixin(Doc)
10903
 
10904
  // INPUT HANDLING
10905
 
10906
- CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}
10907
 
10908
  // MODE DEFINITION AND QUERYING
10909
 
10910
  // Extra arguments are stored as the mode's dependencies, which is
10911
  // used by (legacy) mechanisms like loadmode.js to automatically
10912
  // load a mode. (Preferred mechanism is the require/define calls.)
10913
- CodeMirror.defineMode = function(name/*, mode, …*/) {
10914
- if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name }
10915
- defineMode.apply(this, arguments)
10916
- }
10917
 
10918
- CodeMirror.defineMIME = defineMIME
10919
 
10920
  // Minimal default mode.
10921
- CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); })
10922
- CodeMirror.defineMIME("text/plain", "null")
10923
 
10924
  // EXTENSIONS
10925
 
10926
- CodeMirror.defineExtension = function (name, func) {
10927
- CodeMirror.prototype[name] = func
10928
- }
10929
- CodeMirror.defineDocExtension = function (name, func) {
10930
- Doc.prototype[name] = func
10931
- }
10932
 
10933
- CodeMirror.fromTextArea = fromTextArea
10934
 
10935
- addLegacyProps(CodeMirror)
10936
 
10937
- CodeMirror.version = "5.24.2"
10938
 
10939
- return CodeMirror;
10940
 
10941
  })));
 
10942
  },{}],16:[function(require,module,exports){
10943
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
10944
  // Distributed under an MIT license: http://codemirror.net/LICENSE
@@ -11609,7 +11684,7 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
11609
  "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali",
11610
  "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "spell-out", "square",
11611
  "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
11612
- "subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "table",
11613
  "table-caption", "table-cell", "table-column", "table-column-group",
11614
  "table-footer-group", "table-header-group", "table-row", "table-row-group",
11615
  "tamil",
@@ -12563,6 +12638,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
12563
  if (type == "variable") {register(value); return cont(classNameAfter);}
12564
  }
12565
  function classNameAfter(type, value) {
 
12566
  if (value == "extends" || value == "implements" || (isTS && type == ","))
12567
  return cont(isTS ? typeexpr : expression, classNameAfter);
12568
  if (type == "{") return cont(pushlex("}"), classBody, poplex);
@@ -12590,6 +12666,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
12590
  function classfield(type, value) {
12591
  if (value == "?") return cont(classfield)
12592
  if (type == ":") return cont(typeexpr, maybeAssign)
 
12593
  return pass(functiondef)
12594
  }
12595
  function afterExport(type, value) {
@@ -13662,10 +13739,15 @@ module.exports = {
13662
  prettyPrint: style_html
13663
  };
13664
  },{}],21:[function(require,module,exports){
 
 
13665
  module.exports = require("./stream/stream")
 
13666
  },{"./stream/stream":22}],22:[function(require,module,exports){
13667
  "use strict"
13668
 
 
 
13669
  var guid = 0, HALT = {}
13670
  function createStream() {
13671
  function stream() {
@@ -13680,7 +13762,7 @@ function createStream() {
13680
  }
13681
  function initStream(stream) {
13682
  stream.constructor = createStream
13683
- stream._state = {id: guid++, value: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], endStream: undefined}
13684
  stream.map = stream["fantasy-land/map"] = map, stream["fantasy-land/ap"] = ap, stream["fantasy-land/of"] = createStream
13685
  stream.valueOf = valueOf, stream.toJSON = toJSON, stream.toString = valueOf
13686
 
@@ -13689,7 +13771,10 @@ function initStream(stream) {
13689
  if (!stream._state.endStream) {
13690
  var endStream = createStream()
13691
  endStream.map(function(value) {
13692
- if (value === true) unregisterStream(stream), unregisterStream(endStream)
 
 
 
13693
  return value
13694
  })
13695
  stream._state.endStream = endStream
@@ -13701,6 +13786,7 @@ function initStream(stream) {
13701
  function updateStream(stream, value) {
13702
  updateState(stream, value)
13703
  for (var id in stream._state.deps) updateDependency(stream._state.deps[id], false)
 
13704
  finalize(stream)
13705
  }
13706
  function updateState(stream, value) {
@@ -13722,7 +13808,7 @@ function finalize(stream) {
13722
  }
13723
 
13724
  function combine(fn, streams) {
13725
- if (!streams.every(valid)) throw new Error("Ensure that each item passed to m.prop.combine/m.prop.merge is a stream")
13726
  return initDependency(createStream(), streams, function() {
13727
  return fn.apply(this, streams.concat([streams.filter(changed)]))
13728
  })
@@ -13773,13 +13859,51 @@ function merge(streams) {
13773
  return streams.map(function(s) {return s()})
13774
  }, streams)
13775
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13776
  createStream["fantasy-land/of"] = createStream
13777
  createStream.merge = merge
13778
  createStream.combine = combine
 
 
13779
  createStream.HALT = HALT
13780
 
13781
  if (typeof module !== "undefined") module["exports"] = createStream
13782
- else window.stream = createStream
 
 
 
13783
 
13784
  },{}]},{},[11]);
13785
  })();
1718
  // at http://marijnhaverbeke.nl/blog/#cm-internals .
1719
 
1720
  (function (global, factory) {
1721
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
1722
+ typeof define === 'function' && define.amd ? define(factory) :
1723
+ (global.CodeMirror = factory());
1724
  }(this, (function () { 'use strict';
1725
 
1726
  // Kludges for bugs and behavior differences that can't be feature
1727
  // detected are enabled based on userAgent etc sniffing.
1728
+ var userAgent = navigator.userAgent;
1729
+ var platform = navigator.platform;
1730
+
1731
+ var gecko = /gecko\/\d/i.test(userAgent);
1732
+ var ie_upto10 = /MSIE \d/.test(userAgent);
1733
+ var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
1734
+ var edge = /Edge\/(\d+)/.exec(userAgent);
1735
+ var ie = ie_upto10 || ie_11up || edge;
1736
+ var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
1737
+ var webkit = !edge && /WebKit\//.test(userAgent);
1738
+ var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
1739
+ var chrome = !edge && /Chrome\//.test(userAgent);
1740
+ var presto = /Opera\//.test(userAgent);
1741
+ var safari = /Apple Computer/.test(navigator.vendor);
1742
+ var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
1743
+ var phantom = /PhantomJS/.test(userAgent);
1744
+
1745
+ var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
1746
+ var android = /Android/.test(userAgent);
1747
  // This is woefully incomplete. Suggestions for alternative methods welcome.
1748
+ var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
1749
+ var mac = ios || /Mac/.test(platform);
1750
+ var chromeOS = /\bCrOS\b/.test(userAgent);
1751
+ var windows = /win/i.test(platform);
1752
+
1753
+ var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
1754
+ if (presto_version) { presto_version = Number(presto_version[1]); }
1755
+ if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
1756
  // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
1757
+ var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
1758
+ var captureRightClick = gecko || (ie && ie_version >= 9);
1759
 
1760
  function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
1761
 
1762
  var rmClass = function(node, cls) {
1763
+ var current = node.className;
1764
+ var match = classTest(cls).exec(current);
1765
  if (match) {
1766
+ var after = current.slice(match.index + match[0].length);
1767
+ node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
1768
  }
1769
+ };
1770
 
1771
  function removeChildren(e) {
1772
  for (var count = e.childNodes.length; count > 0; --count)
1773
+ { e.removeChild(e.firstChild); }
1774
  return e
1775
  }
1776
 
1779
  }
1780
 
1781
  function elt(tag, content, className, style) {
1782
+ var e = document.createElement(tag);
1783
+ if (className) { e.className = className; }
1784
+ if (style) { e.style.cssText = style; }
1785
+ if (typeof content == "string") { e.appendChild(document.createTextNode(content)); }
1786
+ else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]); } }
1787
+ return e
1788
+ }
1789
+ // wrapper for elt, which removes the elt from the accessibility tree
1790
+ function eltP(tag, content, className, style) {
1791
+ var e = elt(tag, content, className, style);
1792
+ e.setAttribute("role", "presentation");
1793
  return e
1794
  }
1795
 
1796
+ var range;
1797
  if (document.createRange) { range = function(node, start, end, endNode) {
1798
+ var r = document.createRange();
1799
+ r.setEnd(endNode || node, end);
1800
+ r.setStart(node, start);
1801
  return r
1802
+ }; }
1803
  else { range = function(node, start, end) {
1804
+ var r = document.body.createTextRange();
1805
+ try { r.moveToElementText(node.parentNode); }
1806
  catch(e) { return r }
1807
+ r.collapse(true);
1808
+ r.moveEnd("character", end);
1809
+ r.moveStart("character", start);
1810
  return r
1811
+ }; }
1812
 
1813
  function contains(parent, child) {
1814
  if (child.nodeType == 3) // Android browser always returns false when child is a textnode
1815
+ { child = child.parentNode; }
1816
  if (parent.contains)
1817
  { return parent.contains(child) }
1818
  do {
1819
+ if (child.nodeType == 11) { child = child.host; }
1820
  if (child == parent) { return true }
1821
  } while (child = child.parentNode)
1822
  }
1825
  // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
1826
  // IE < 10 will throw when accessed while the page is loading or in an iframe.
1827
  // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
1828
+ var activeElement;
1829
  try {
1830
+ activeElement = document.activeElement;
1831
  } catch(e) {
1832
+ activeElement = document.body || null;
1833
  }
1834
+ while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
1835
+ { activeElement = activeElement.shadowRoot.activeElement; }
1836
  return activeElement
1837
  }
1838
 
1839
  function addClass(node, cls) {
1840
+ var current = node.className;
1841
+ if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls; }
1842
  }
1843
  function joinClasses(a, b) {
1844
+ var as = a.split(" ");
1845
  for (var i = 0; i < as.length; i++)
1846
+ { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i]; } }
1847
  return b
1848
  }
1849
 
1850
+ var selectInput = function(node) { node.select(); };
1851
  if (ios) // Mobile Safari apparently has a bug where select() is broken.
1852
+ { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; }
1853
  else if (ie) // Suppress mysterious IE10 errors
1854
+ { selectInput = function(node) { try { node.select(); } catch(_e) {} }; }
1855
 
1856
  function bind(f) {
1857
+ var args = Array.prototype.slice.call(arguments, 1);
1858
  return function(){return f.apply(null, args)}
1859
  }
1860
 
1861
  function copyObj(obj, target, overwrite) {
1862
+ if (!target) { target = {}; }
1863
  for (var prop in obj)
1864
  { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
1865
+ { target[prop] = obj[prop]; } }
1866
  return target
1867
  }
1868
 
1870
  // Used mostly to find indentation.
1871
  function countColumn(string, end, tabSize, startIndex, startValue) {
1872
  if (end == null) {
1873
+ end = string.search(/[^\s\u00a0]/);
1874
+ if (end == -1) { end = string.length; }
1875
  }
1876
  for (var i = startIndex || 0, n = startValue || 0;;) {
1877
+ var nextTab = string.indexOf("\t", i);
1878
  if (nextTab < 0 || nextTab >= end)
1879
  { return n + (end - i) }
1880
+ n += nextTab - i;
1881
+ n += tabSize - (n % tabSize);
1882
+ i = nextTab + 1;
1883
  }
1884
  }
1885
 
1886
+ var Delayed = function() {this.id = null;};
1887
  Delayed.prototype.set = function (ms, f) {
1888
+ clearTimeout(this.id);
1889
+ this.id = setTimeout(f, ms);
1890
  };
1891
 
1892
  function indexOf(array, elt) {
1896
  }
1897
 
1898
  // Number of pixels added to scroller and sizer to hide scrollbar
1899
+ var scrollerGap = 30;
1900
 
1901
  // Returned or thrown by various protocols to signal 'I'm not
1902
  // handling this'.
1903
+ var Pass = {toString: function(){return "CodeMirror.Pass"}};
1904
 
1905
  // Reused option objects for setSelection & friends
1906
  var sel_dontScroll = {scroll: false};
1907
  var sel_mouse = {origin: "*mouse"};
1908
  var sel_move = {origin: "+move"};
1909
+
1910
  // The inverse of countColumn -- find the offset that corresponds to
1911
  // a particular column.
1912
  function findColumn(string, goal, tabSize) {
1913
  for (var pos = 0, col = 0;;) {
1914
+ var nextTab = string.indexOf("\t", pos);
1915
+ if (nextTab == -1) { nextTab = string.length; }
1916
+ var skipped = nextTab - pos;
1917
  if (nextTab == string.length || col + skipped >= goal)
1918
  { return pos + Math.min(skipped, goal - col) }
1919
+ col += nextTab - pos;
1920
+ col += tabSize - (col % tabSize);
1921
+ pos = nextTab + 1;
1922
  if (col >= goal) { return pos }
1923
  }
1924
  }
1925
 
1926
+ var spaceStrs = [""];
1927
  function spaceStr(n) {
1928
  while (spaceStrs.length <= n)
1929
+ { spaceStrs.push(lst(spaceStrs) + " "); }
1930
  return spaceStrs[n]
1931
  }
1932
 
1933
  function lst(arr) { return arr[arr.length-1] }
1934
 
1935
  function map(array, f) {
1936
+ var out = [];
1937
+ for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i); }
1938
  return out
1939
  }
1940
 
1941
  function insertSorted(array, value, score) {
1942
+ var pos = 0, priority = score(value);
1943
+ while (pos < array.length && score(array[pos]) <= priority) { pos++; }
1944
+ array.splice(pos, 0, value);
1945
  }
1946
 
1947
  function nothing() {}
1948
 
1949
  function createObj(base, props) {
1950
+ var inst;
1951
  if (Object.create) {
1952
+ inst = Object.create(base);
1953
  } else {
1954
+ nothing.prototype = base;
1955
+ inst = new nothing();
1956
  }
1957
+ if (props) { copyObj(props, inst); }
1958
  return inst
1959
  }
1960
 
1961
+ var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
1962
  function isWordCharBasic(ch) {
1963
  return /\w/.test(ch) || ch > "\x80" &&
1964
  (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
1979
  // as editing and measuring is concerned. This is not fully correct,
1980
  // since some scripts/fonts/browsers also treat other configurations
1981
  // of code points as a group.
1982
+ var extendingChars = /[\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]/;
1983
  function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
1984
 
1985
  // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
1986
  function skipExtendingChars(str, pos, dir) {
1987
+ while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir; }
1988
  return pos
1989
  }
1990
 
1993
  function findFirst(pred, from, to) {
1994
  for (;;) {
1995
  if (Math.abs(from - to) <= 1) { return pred(from) ? from : to }
1996
+ var mid = Math.floor((from + to) / 2);
1997
+ if (pred(mid)) { to = mid; }
1998
+ else { from = mid; }
1999
  }
2000
  }
2001
 
2004
  // display-related state.
2005
 
2006
  function Display(place, doc, input) {
2007
+ var d = this;
2008
+ this.input = input;
2009
 
2010
  // Covers bottom-right square when both scrollbars are present.
2011
+ d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
2012
+ d.scrollbarFiller.setAttribute("cm-not-content", "true");
2013
  // Covers bottom of gutter when coverGutterNextToScrollbar is on
2014
  // and h scrollbar is present.
2015
+ d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
2016
+ d.gutterFiller.setAttribute("cm-not-content", "true");
2017
  // Will contain the actual code, positioned to cover the viewport.
2018
+ d.lineDiv = eltP("div", null, "CodeMirror-code");
2019
  // Elements are added to these to represent selection and cursors.
2020
+ d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
2021
+ d.cursorDiv = elt("div", null, "CodeMirror-cursors");
2022
  // A visibility: hidden element used to find the size of things.
2023
+ d.measure = elt("div", null, "CodeMirror-measure");
2024
  // When lines outside of the viewport are measured, they are drawn in this.
2025
+ d.lineMeasure = elt("div", null, "CodeMirror-measure");
2026
  // Wraps everything that needs to exist inside the vertically-padded coordinate system
2027
+ d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
2028
+ null, "position: relative; outline: none");
2029
+ var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
2030
  // Moved around its parent to cover visible view.
2031
+ d.mover = elt("div", [lines], null, "position: relative");
2032
  // Set to the height of the document, allowing scrolling.
2033
+ d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
2034
+ d.sizerWidth = null;
2035
  // Behavior of elts with overflow: auto and padding is
2036
  // inconsistent across browsers. This is used to ensure the
2037
  // scrollable area is big enough.
2038
+ d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
2039
  // Will contain the gutters, if any.
2040
+ d.gutters = elt("div", null, "CodeMirror-gutters");
2041
+ d.lineGutter = null;
2042
  // Actual scrollable element.
2043
+ d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
2044
+ d.scroller.setAttribute("tabIndex", "-1");
2045
  // The element in which the editor lives.
2046
+ d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
2047
 
2048
  // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
2049
+ if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
2050
+ if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true; }
2051
 
2052
  if (place) {
2053
+ if (place.appendChild) { place.appendChild(d.wrapper); }
2054
+ else { place(d.wrapper); }
2055
  }
2056
 
2057
  // Current rendered range (may be bigger than the view window).
2058
+ d.viewFrom = d.viewTo = doc.first;
2059
+ d.reportedViewFrom = d.reportedViewTo = doc.first;
2060
  // Information about the rendered lines.
2061
+ d.view = [];
2062
+ d.renderedView = null;
2063
  // Holds info about a single rendered line when it was rendered
2064
  // for measurement, while not in view.
2065
+ d.externalMeasured = null;
2066
  // Empty space (in pixels) above the view
2067
+ d.viewOffset = 0;
2068
+ d.lastWrapHeight = d.lastWrapWidth = 0;
2069
+ d.updateLineNumbers = null;
2070
 
2071
+ d.nativeBarWidth = d.barHeight = d.barWidth = 0;
2072
+ d.scrollbarsClipped = false;
2073
 
2074
  // Used to only resize the line number gutter when necessary (when
2075
  // the amount of lines crosses a boundary that makes its width change)
2076
+ d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
2077
  // Set to true when a non-horizontal-scrolling line widget is
2078
  // added. As an optimization, line widget aligning is skipped when
2079
  // this is false.
2080
+ d.alignWidgets = false;
2081
 
2082
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
2083
 
2084
  // Tracks the maximum line length so that the horizontal scrollbar
2085
  // can be kept static when scrolling.
2086
+ d.maxLine = null;
2087
+ d.maxLineLength = 0;
2088
+ d.maxLineChanged = false;
2089
 
2090
  // Used for measuring wheel scrolling granularity
2091
+ d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
2092
 
2093
  // True when shift is held down.
2094
+ d.shift = false;
2095
 
2096
  // Used to track whether anything happened since the context menu
2097
  // was opened.
2098
+ d.selForContextMenu = null;
2099
 
2100
+ d.activeTouch = null;
2101
 
2102
+ input.init(d);
2103
  }
2104
 
2105
  // Find the line object corresponding to the given line number.
2106
  function getLine(doc, n) {
2107
+ n -= doc.first;
2108
  if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
2109
+ var chunk = doc;
2110
  while (!chunk.lines) {
2111
  for (var i = 0;; ++i) {
2112
+ var child = chunk.children[i], sz = child.chunkSize();
2113
  if (n < sz) { chunk = child; break }
2114
+ n -= sz;
2115
  }
2116
  }
2117
  return chunk.lines[n]
2120
  // Get the part of a document between two positions, as an array of
2121
  // strings.
2122
  function getBetween(doc, start, end) {
2123
+ var out = [], n = start.line;
2124
  doc.iter(start.line, end.line + 1, function (line) {
2125
+ var text = line.text;
2126
+ if (n == end.line) { text = text.slice(0, end.ch); }
2127
+ if (n == start.line) { text = text.slice(start.ch); }
2128
+ out.push(text);
2129
+ ++n;
2130
+ });
2131
  return out
2132
  }
2133
  // Get the lines between from and to, as array of strings.
2134
  function getLines(doc, from, to) {
2135
+ var out = [];
2136
+ doc.iter(from, to, function (line) { out.push(line.text); }); // iter aborts when callback returns truthy value
2137
  return out
2138
  }
2139
 
2140
  // Update the height of a line, propagating the height change
2141
  // upwards to parent nodes.
2142
  function updateLineHeight(line, height) {
2143
+ var diff = height - line.height;
2144
+ if (diff) { for (var n = line; n; n = n.parent) { n.height += diff; } }
2145
  }
2146
 
2147
  // Given a line object, find its line number by walking up through
2148
  // its parent links.
2149
  function lineNo(line) {
2150
  if (line.parent == null) { return null }
2151
+ var cur = line.parent, no = indexOf(cur.lines, line);
2152
  for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
2153
  for (var i = 0;; ++i) {
2154
  if (chunk.children[i] == cur) { break }
2155
+ no += chunk.children[i].chunkSize();
2156
  }
2157
  }
2158
  return no + cur.first
2161
  // Find the line at the given vertical position, using the height
2162
  // information in the document tree.
2163
  function lineAtHeight(chunk, h) {
2164
+ var n = chunk.first;
2165
  outer: do {
2166
  for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
2167
+ var child = chunk.children[i$1], ch = child.height;
2168
  if (h < ch) { chunk = child; continue outer }
2169
+ h -= ch;
2170
+ n += child.chunkSize();
2171
  }
2172
  return n
2173
  } while (!chunk.lines)
2174
+ var i = 0;
2175
  for (; i < chunk.lines.length; ++i) {
2176
+ var line = chunk.lines[i], lh = line.height;
2177
  if (h < lh) { break }
2178
+ h -= lh;
2179
  }
2180
  return n + i
2181
  }
2191
  if ( sticky === void 0 ) sticky = null;
2192
 
2193
  if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
2194
+ this.line = line;
2195
+ this.ch = ch;
2196
+ this.sticky = sticky;
2197
  }
2198
 
2199
  // Compare two positions, return 0 if they are the same, a negative
2211
  function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
2212
  function clipPos(doc, pos) {
2213
  if (pos.line < doc.first) { return Pos(doc.first, 0) }
2214
+ var last = doc.first + doc.size - 1;
2215
  if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
2216
  return clipToLen(pos, getLine(doc, pos.line).text.length)
2217
  }
2218
  function clipToLen(pos, linelen) {
2219
+ var ch = pos.ch;
2220
  if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
2221
  else if (ch < 0) { return Pos(pos.line, 0) }
2222
  else { return pos }
2223
  }
2224
  function clipPosArray(doc, array) {
2225
+ var out = [];
2226
+ for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]); }
2227
  return out
2228
  }
2229
 
2230
  // Optimize some code when these features are not used.
2231
  var sawReadOnlySpans = false;
2232
  var sawCollapsedSpans = false;
2233
+
2234
  function seeReadOnlySpans() {
2235
+ sawReadOnlySpans = true;
2236
  }
2237
 
2238
  function seeCollapsedSpans() {
2239
+ sawCollapsedSpans = true;
2240
  }
2241
 
2242
  // TEXTMARKER SPANS
2243
 
2244
  function MarkedSpan(marker, from, to) {
2245
+ this.marker = marker;
2246
+ this.from = from; this.to = to;
2247
  }
2248
 
2249
  // Search an array of spans for a span matching the given marker.
2250
  function getMarkedSpanFor(spans, marker) {
2251
  if (spans) { for (var i = 0; i < spans.length; ++i) {
2252
+ var span = spans[i];
2253
  if (span.marker == marker) { return span }
2254
  } }
2255
  }
2256
  // Remove a span from an array, returning undefined if no spans are
2257
  // left (we don't store arrays for lines without spans).
2258
  function removeMarkedSpan(spans, span) {
2259
+ var r;
2260
  for (var i = 0; i < spans.length; ++i)
2261
+ { if (spans[i] != span) { (r || (r = [])).push(spans[i]); } }
2262
  return r
2263
  }
2264
  // Add a span to a line.
2265
  function addMarkedSpan(line, span) {
2266
+ line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
2267
+ span.marker.attachLine(line);
2268
  }
2269
 
2270
  // Used for the algorithm that adjusts markers for a change in the
2272
  // character position, returning an array of remaining chunks (or
2273
  // undefined if nothing remains).
2274
  function markedSpansBefore(old, startCh, isInsert) {
2275
+ var nw;
2276
  if (old) { for (var i = 0; i < old.length; ++i) {
2277
+ var span = old[i], marker = span.marker;
2278
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
2279
  if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
2280
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
 
2281
  }
2282
  } }
2283
  return nw
2284
  }
2285
  function markedSpansAfter(old, endCh, isInsert) {
2286
+ var nw;
2287
  if (old) { for (var i = 0; i < old.length; ++i) {
2288
+ var span = old[i], marker = span.marker;
2289
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
2290
  if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
2291
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
2292
+ span.to == null ? null : span.to - endCh));
 
2293
  }
2294
  } }
2295
  return nw
2303
  // arrays with one element for each line in (after) the change.
2304
  function stretchSpansOverChange(doc, change) {
2305
  if (change.full) { return null }
2306
+ var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
2307
+ var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
2308
  if (!oldFirst && !oldLast) { return null }
2309
 
2310
+ var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
2311
  // Get the spans that 'stick out' on both sides
2312
+ var first = markedSpansBefore(oldFirst, startCh, isInsert);
2313
+ var last = markedSpansAfter(oldLast, endCh, isInsert);
2314
 
2315
  // Next, merge those two ends
2316
+ var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
2317
  if (first) {
2318
  // Fix up .to properties of first
2319
  for (var i = 0; i < first.length; ++i) {
2320
+ var span = first[i];
2321
  if (span.to == null) {
2322
+ var found = getMarkedSpanFor(last, span.marker);
2323
+ if (!found) { span.to = startCh; }
2324
+ else if (sameLine) { span.to = found.to == null ? null : found.to + offset; }
2325
  }
2326
  }
2327
  }
2328
  if (last) {
2329
  // Fix up .from in last (or move them into first in case of sameLine)
2330
  for (var i$1 = 0; i$1 < last.length; ++i$1) {
2331
+ var span$1 = last[i$1];
2332
+ if (span$1.to != null) { span$1.to += offset; }
2333
  if (span$1.from == null) {
2334
+ var found$1 = getMarkedSpanFor(first, span$1.marker);
2335
  if (!found$1) {
2336
+ span$1.from = offset;
2337
+ if (sameLine) { (first || (first = [])).push(span$1); }
2338
  }
2339
  } else {
2340
+ span$1.from += offset;
2341
+ if (sameLine) { (first || (first = [])).push(span$1); }
2342
  }
2343
  }
2344
  }
2345
  // Make sure we didn't create any zero-length spans
2346
+ if (first) { first = clearEmptySpans(first); }
2347
+ if (last && last != first) { last = clearEmptySpans(last); }
2348
 
2349
+ var newMarkers = [first];
2350
  if (!sameLine) {
2351
  // Fill gap with whole-line-spans
2352
+ var gap = change.text.length - 2, gapMarkers;
2353
  if (gap > 0 && first)
2354
  { for (var i$2 = 0; i$2 < first.length; ++i$2)
2355
  { if (first[i$2].to == null)
2356
+ { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } }
2357
  for (var i$3 = 0; i$3 < gap; ++i$3)
2358
+ { newMarkers.push(gapMarkers); }
2359
+ newMarkers.push(last);
2360
  }
2361
  return newMarkers
2362
  }
2365
  // option of false.
2366
  function clearEmptySpans(spans) {
2367
  for (var i = 0; i < spans.length; ++i) {
2368
+ var span = spans[i];
2369
  if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
2370
+ { spans.splice(i--, 1); }
2371
  }
2372
  if (!spans.length) { return null }
2373
  return spans
2375
 
2376
  // Used to 'clip' out readOnly ranges when making a change.
2377
  function removeReadOnlyRanges(doc, from, to) {
2378
+ var markers = null;
2379
  doc.iter(from.line, to.line + 1, function (line) {
2380
  if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
2381
+ var mark = line.markedSpans[i].marker;
2382
  if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
2383
+ { (markers || (markers = [])).push(mark); }
2384
  } }
2385
+ });
2386
  if (!markers) { return null }
2387
+ var parts = [{from: from, to: to}];
2388
  for (var i = 0; i < markers.length; ++i) {
2389
+ var mk = markers[i], m = mk.find(0);
2390
  for (var j = 0; j < parts.length; ++j) {
2391
+ var p = parts[j];
2392
  if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
2393
+ var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
2394
  if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
2395
+ { newParts.push({from: p.from, to: m.from}); }
2396
  if (dto > 0 || !mk.inclusiveRight && !dto)
2397
+ { newParts.push({from: m.to, to: p.to}); }
2398
+ parts.splice.apply(parts, newParts);
2399
+ j += newParts.length - 3;
2400
  }
2401
  }
2402
  return parts
2404
 
2405
  // Connect or disconnect spans from a line.
2406
  function detachMarkedSpans(line) {
2407
+ var spans = line.markedSpans;
2408
  if (!spans) { return }
2409
  for (var i = 0; i < spans.length; ++i)
2410
+ { spans[i].marker.detachLine(line); }
2411
+ line.markedSpans = null;
2412
  }
2413
  function attachMarkedSpans(line, spans) {
2414
  if (!spans) { return }
2415
  for (var i = 0; i < spans.length; ++i)
2416
+ { spans[i].marker.attachLine(line); }
2417
+ line.markedSpans = spans;
2418
  }
2419
 
2420
  // Helpers used when computing which overlapping collapsed span
2426
  // spans is larger (and thus includes the other). Falls back to
2427
  // comparing ids when the spans cover exactly the same range.
2428
  function compareCollapsedMarkers(a, b) {
2429
+ var lenDiff = a.lines.length - b.lines.length;
2430
  if (lenDiff != 0) { return lenDiff }
2431
+ var aPos = a.find(), bPos = b.find();
2432
+ var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
2433
  if (fromCmp) { return -fromCmp }
2434
+ var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
2435
  if (toCmp) { return toCmp }
2436
  return b.id - a.id
2437
  }
2439
  // Find out whether a line ends or starts in a collapsed span. If
2440
  // so, return the marker for that span.
2441
  function collapsedSpanAtSide(line, start) {
2442
+ var sps = sawCollapsedSpans && line.markedSpans, found;
2443
  if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
2444
+ sp = sps[i];
2445
  if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
2446
  (!found || compareCollapsedMarkers(found, sp.marker) < 0))
2447
+ { found = sp.marker; }
2448
  } }
2449
  return found
2450
  }
2454
  // Test whether there exists a collapsed span that partially
2455
  // overlaps (covers the start or end, but not both) of a new span.
2456
  // Such overlap is not allowed.
2457
+ function conflictingCollapsedRange(doc, lineNo$$1, from, to, marker) {
2458
+ var line = getLine(doc, lineNo$$1);
2459
+ var sps = sawCollapsedSpans && line.markedSpans;
2460
  if (sps) { for (var i = 0; i < sps.length; ++i) {
2461
+ var sp = sps[i];
2462
  if (!sp.marker.collapsed) { continue }
2463
+ var found = sp.marker.find(0);
2464
+ var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
2465
+ var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
2466
  if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
2467
  if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
2468
  fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
2475
  // visual line. This finds the start of the visual line that the
2476
  // given line is part of (usually that is the line itself).
2477
  function visualLine(line) {
2478
+ var merged;
2479
  while (merged = collapsedSpanAtStart(line))
2480
+ { line = merged.find(-1, true).line; }
2481
  return line
2482
  }
2483
 
2484
  function visualLineEnd(line) {
2485
+ var merged;
2486
  while (merged = collapsedSpanAtEnd(line))
2487
+ { line = merged.find(1, true).line; }
2488
  return line
2489
  }
2490
 
2491
  // Returns an array of logical lines that continue the visual line
2492
  // started by the argument, or undefined if there are no such lines.
2493
  function visualLineContinued(line) {
2494
+ var merged, lines;
2495
  while (merged = collapsedSpanAtEnd(line)) {
2496
  line = merged.find(1, true).line
2497
+ ;(lines || (lines = [])).push(line);
2498
  }
2499
  return lines
2500
  }
2502
  // Get the line number of the start of the visual line that the
2503
  // given line number is part of.
2504
  function visualLineNo(doc, lineN) {
2505
+ var line = getLine(doc, lineN), vis = visualLine(line);
2506
  if (line == vis) { return lineN }
2507
  return lineNo(vis)
2508
  }
2511
  // the given line.
2512
  function visualLineEndNo(doc, lineN) {
2513
  if (lineN > doc.lastLine()) { return lineN }
2514
+ var line = getLine(doc, lineN), merged;
2515
  if (!lineIsHidden(doc, line)) { return lineN }
2516
  while (merged = collapsedSpanAtEnd(line))
2517
+ { line = merged.find(1, true).line; }
2518
  return lineNo(line) + 1
2519
  }
2520
 
2522
  // are part of a visual line that starts with another line, or when
2523
  // they are entirely covered by collapsed, non-widget span.
2524
  function lineIsHidden(doc, line) {
2525
+ var sps = sawCollapsedSpans && line.markedSpans;
2526
  if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
2527
+ sp = sps[i];
2528
  if (!sp.marker.collapsed) { continue }
2529
  if (sp.from == null) { return true }
2530
  if (sp.marker.widgetNode) { continue }
2534
  }
2535
  function lineIsHiddenInner(doc, line, span) {
2536
  if (span.to == null) {
2537
+ var end = span.marker.find(1, true);
2538
  return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
2539
  }
2540
  if (span.marker.inclusiveRight && span.to == line.text.length)
2541
  { return true }
2542
  for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
2543
+ sp = line.markedSpans[i];
2544
  if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
2545
  (sp.to == null || sp.to != span.from) &&
2546
  (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
2550
 
2551
  // Find the height above the given line.
2552
  function heightAtLine(lineObj) {
2553
+ lineObj = visualLine(lineObj);
2554
 
2555
+ var h = 0, chunk = lineObj.parent;
2556
  for (var i = 0; i < chunk.lines.length; ++i) {
2557
+ var line = chunk.lines[i];
2558
  if (line == lineObj) { break }
2559
+ else { h += line.height; }
2560
  }
2561
  for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
2562
  for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
2563
+ var cur = p.children[i$1];
2564
  if (cur == chunk) { break }
2565
+ else { h += cur.height; }
2566
  }
2567
  }
2568
  return h
2573
  // other lines onto it.
2574
  function lineLength(line) {
2575
  if (line.height == 0) { return 0 }
2576
+ var len = line.text.length, merged, cur = line;
2577
  while (merged = collapsedSpanAtStart(cur)) {
2578
+ var found = merged.find(0, true);
2579
+ cur = found.from.line;
2580
+ len += found.from.ch - found.to.ch;
2581
  }
2582
+ cur = line;
2583
  while (merged = collapsedSpanAtEnd(cur)) {
2584
+ var found$1 = merged.find(0, true);
2585
+ len -= cur.text.length - found$1.from.ch;
2586
+ cur = found$1.to.line;
2587
+ len += cur.text.length - found$1.to.ch;
2588
  }
2589
  return len
2590
  }
2591
 
2592
  // Find the longest line in the document.
2593
  function findMaxLine(cm) {
2594
+ var d = cm.display, doc = cm.doc;
2595
+ d.maxLine = getLine(doc, doc.first);
2596
+ d.maxLineLength = lineLength(d.maxLine);
2597
+ d.maxLineChanged = true;
2598
  doc.iter(function (line) {
2599
+ var len = lineLength(line);
2600
  if (len > d.maxLineLength) {
2601
+ d.maxLineLength = len;
2602
+ d.maxLine = line;
2603
  }
2604
+ });
2605
  }
2606
 
2607
  // BIDI HELPERS
2608
 
2609
  function iterateBidiSections(order, from, to, f) {
2610
  if (!order) { return f(from, to, "ltr") }
2611
+ var found = false;
2612
  for (var i = 0; i < order.length; ++i) {
2613
+ var part = order[i];
2614
  if (part.from < to && part.to > from || from == to && part.to == from) {
2615
+ f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
2616
+ found = true;
2617
  }
2618
  }
2619
+ if (!found) { f(from, to, "ltr"); }
2620
  }
2621
 
2622
+ var bidiOther = null;
2623
  function getBidiPartAt(order, ch, sticky) {
2624
+ var found;
2625
+ bidiOther = null;
2626
  for (var i = 0; i < order.length; ++i) {
2627
+ var cur = order[i];
2628
  if (cur.from < ch && cur.to > ch) { return i }
2629
  if (cur.to == ch) {
2630
+ if (cur.from != cur.to && sticky == "before") { found = i; }
2631
+ else { bidiOther = i; }
2632
  }
2633
  if (cur.from == ch) {
2634
+ if (cur.from != cur.to && sticky != "before") { found = i; }
2635
+ else { bidiOther = i; }
2636
  }
2637
  }
2638
  return found != null ? found : bidiOther
2663
  // objects) in the order in which they occur visually.
2664
  var bidiOrdering = (function() {
2665
  // Character types for codepoints 0 to 0xff
2666
+ var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
2667
  // Character types for codepoints 0x600 to 0x6f9
2668
+ var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
2669
  function charType(code) {
2670
  if (code <= 0xf7) { return lowTypes.charAt(code) }
2671
  else if (0x590 <= code && code <= 0x5f4) { return "R" }
2676
  else { return "L" }
2677
  }
2678
 
2679
+ var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
2680
+ var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
 
 
2681
 
2682
  function BidiSpan(level, from, to) {
2683
+ this.level = level;
2684
+ this.from = from; this.to = to;
2685
  }
2686
 
2687
+ return function(str, direction) {
2688
+ var outerType = direction == "ltr" ? "L" : "R";
2689
+
2690
+ if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
2691
+ var len = str.length, types = [];
2692
  for (var i = 0; i < len; ++i)
2693
+ { types.push(charType(str.charCodeAt(i))); }
2694
 
2695
  // W1. Examine each non-spacing mark (NSM) in the level run, and
2696
  // change the type of the NSM to the type of the previous
2697
  // character. If the NSM is at the start of the level run, it will
2698
  // get the type of sor.
2699
  for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
2700
+ var type = types[i$1];
2701
+ if (type == "m") { types[i$1] = prev; }
2702
+ else { prev = type; }
2703
  }
2704
 
2705
  // W2. Search backwards from each instance of a European number
2708
  // number.
2709
  // W3. Change all ALs to R.
2710
  for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
2711
+ var type$1 = types[i$2];
2712
+ if (type$1 == "1" && cur == "r") { types[i$2] = "n"; }
2713
+ else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R"; } }
2714
  }
2715
 
2716
  // W4. A single European separator between two European numbers
2717
  // changes to a European number. A single common separator between
2718
  // two numbers of the same type changes to that type.
2719
  for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
2720
+ var type$2 = types[i$3];
2721
+ if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1"; }
2722
  else if (type$2 == "," && prev$1 == types[i$3+1] &&
2723
+ (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1; }
2724
+ prev$1 = type$2;
2725
  }
2726
 
2727
  // W5. A sequence of European terminators adjacent to European
2729
  // W6. Otherwise, separators and terminators change to Other
2730
  // Neutral.
2731
  for (var i$4 = 0; i$4 < len; ++i$4) {
2732
+ var type$3 = types[i$4];
2733
+ if (type$3 == ",") { types[i$4] = "N"; }
2734
  else if (type$3 == "%") {
2735
+ var end = (void 0);
2736
  for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
2737
+ var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
2738
+ for (var j = i$4; j < end; ++j) { types[j] = replace; }
2739
+ i$4 = end - 1;
2740
  }
2741
  }
2742
 
2744
  // until the first strong type (R, L, or sor) is found. If an L is
2745
  // found, then change the type of the European number to L.
2746
  for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
2747
+ var type$4 = types[i$5];
2748
+ if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L"; }
2749
+ else if (isStrong.test(type$4)) { cur$1 = type$4; }
2750
  }
2751
 
2752
  // N1. A sequence of neutrals takes the direction of the
2757
  // N2. Any remaining neutrals take the embedding direction.
2758
  for (var i$6 = 0; i$6 < len; ++i$6) {
2759
  if (isNeutral.test(types[i$6])) {
2760
+ var end$1 = (void 0);
2761
  for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
2762
+ var before = (i$6 ? types[i$6-1] : outerType) == "L";
2763
+ var after = (end$1 < len ? types[end$1] : outerType) == "L";
2764
+ var replace$1 = before == after ? (before ? "L" : "R") : outerType;
2765
+ for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1; }
2766
+ i$6 = end$1 - 1;
2767
  }
2768
  }
2769
 
2772
  // levels (0, 1, 2) in an implementation that doesn't take
2773
  // explicit embedding into account, we can build up the order on
2774
  // the fly, without following the level-based algorithm.
2775
+ var order = [], m;
2776
  for (var i$7 = 0; i$7 < len;) {
2777
  if (countsAsLeft.test(types[i$7])) {
2778
+ var start = i$7;
2779
  for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
2780
+ order.push(new BidiSpan(0, start, i$7));
2781
  } else {
2782
+ var pos = i$7, at = order.length;
2783
  for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
2784
  for (var j$2 = pos; j$2 < i$7;) {
2785
  if (countsAsNum.test(types[j$2])) {
2786
+ if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)); }
2787
+ var nstart = j$2;
2788
  for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
2789
+ order.splice(at, 0, new BidiSpan(2, nstart, j$2));
2790
+ pos = j$2;
2791
+ } else { ++j$2; }
2792
  }
2793
+ if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)); }
2794
  }
2795
  }
2796
  if (order[0].level == 1 && (m = str.match(/^\s+/))) {
2797
+ order[0].from = m[0].length;
2798
+ order.unshift(new BidiSpan(0, 0, m[0].length));
2799
  }
2800
  if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
2801
+ lst(order).to -= m[0].length;
2802
+ order.push(new BidiSpan(0, len - m[0].length, len));
2803
  }
2804
 
2805
+ return direction == "rtl" ? order.reverse() : order
2806
  }
2807
+ })();
2808
 
2809
  // Get the bidi ordering for the given line (and cache it). Returns
2810
  // false for lines that are fully left-to-right, and an array of
2811
  // BidiSpan objects otherwise.
2812
+ function getOrder(line, direction) {
2813
+ var order = line.order;
2814
+ if (order == null) { order = line.order = bidiOrdering(line.text, direction); }
2815
  return order
2816
  }
2817
 
2818
  function moveCharLogically(line, ch, dir) {
2819
+ var target = skipExtendingChars(line.text, ch + dir, dir);
2820
  return target < 0 || target > line.text.length ? null : target
2821
  }
2822
 
2823
  function moveLogically(line, start, dir) {
2824
+ var ch = moveCharLogically(line, start.ch, dir);
2825
  return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
2826
  }
2827
 
2828
  function endOfLine(visually, cm, lineObj, lineNo, dir) {
2829
  if (visually) {
2830
+ var order = getOrder(lineObj, cm.doc.direction);
2831
  if (order) {
2832
+ var part = dir < 0 ? lst(order) : order[0];
2833
+ var moveInStorageOrder = (dir < 0) == (part.level == 1);
2834
+ var sticky = moveInStorageOrder ? "after" : "before";
2835
+ var ch;
2836
  // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
2837
  // it could be that the last bidi part is not on the last visual line,
2838
  // since visual lines contain content order-consecutive chunks.
2840
  // in the rtl chunk that is on the last line (that is, the same line
2841
  // as the last (content-order) character).
2842
  if (part.level > 0) {
2843
+ var prep = prepareMeasureForLine(cm, lineObj);
2844
+ ch = dir < 0 ? lineObj.text.length - 1 : 0;
2845
+ var targetTop = measureCharPrepared(cm, prep, ch).top;
2846
+ ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch);
2847
+ if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1, true); }
2848
+ } else { ch = dir < 0 ? part.to : part.from; }
2849
  return new Pos(lineNo, ch, sticky)
2850
  }
2851
  }
2853
  }
2854
 
2855
  function moveVisually(cm, line, start, dir) {
2856
+ var bidi = getOrder(line, cm.doc.direction);
2857
  if (!bidi) { return moveLogically(line, start, dir) }
2858
  if (start.ch >= line.text.length) {
2859
+ start.ch = line.text.length;
2860
+ start.sticky = "before";
2861
  } else if (start.ch <= 0) {
2862
+ start.ch = 0;
2863
+ start.sticky = "after";
2864
  }
2865
+ var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos];
2866
+ if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
2867
+ // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
2868
  // nothing interesting happens.
2869
  return moveLogically(line, start, dir)
2870
  }
2871
 
2872
+ var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); };
2873
+ var prep;
2874
  var getWrappedLineExtent = function (ch) {
2875
  if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
2876
+ prep = prep || prepareMeasureForLine(cm, line);
2877
  return wrappedLineExtentChar(cm, line, prep, ch)
2878
+ };
2879
+ var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
2880
+
2881
+ if (cm.doc.direction == "rtl" || part.level == 1) {
2882
+ var moveInStorageOrder = (part.level == 1) == (dir < 0);
2883
+ var ch = mv(start, moveInStorageOrder ? 1 : -1);
2884
+ if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
2885
+ // Case 2: We move within an rtl part or in an rtl editor on the same visual line
2886
+ var sticky = moveInStorageOrder ? "before" : "after";
2887
  return new Pos(start.line, ch, sticky)
2888
  }
2889
  }
2894
  var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
2895
  var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
2896
  ? new Pos(start.line, mv(ch, 1), "before")
2897
+ : new Pos(start.line, ch, "after"); };
2898
 
2899
  for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
2900
+ var part = bidi[partPos];
2901
+ var moveInStorageOrder = (dir > 0) == (part.level != 1);
2902
+ var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);
2903
  if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
2904
+ ch = moveInStorageOrder ? part.from : mv(part.to, -1);
2905
  if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
2906
  }
2907
+ };
2908
 
2909
  // Case 3a: Look for other bidi parts on the same visual line
2910
+ var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);
2911
  if (res) { return res }
2912
 
2913
  // Case 3b: Look for other bidi parts on the next visual line
2914
+ var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);
2915
  if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
2916
+ res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
2917
  if (res) { return res }
2918
  }
2919
 
2926
  // Lightweight event framework. on/off also work on DOM nodes,
2927
  // registering native DOM handlers.
2928
 
2929
+ var noHandlers = [];
2930
 
2931
  var on = function(emitter, type, f) {
2932
  if (emitter.addEventListener) {
2933
+ emitter.addEventListener(type, f, false);
2934
  } else if (emitter.attachEvent) {
2935
+ emitter.attachEvent("on" + type, f);
2936
  } else {
2937
+ var map$$1 = emitter._handlers || (emitter._handlers = {});
2938
+ map$$1[type] = (map$$1[type] || noHandlers).concat(f);
2939
  }
2940
+ };
2941
 
2942
  function getHandlers(emitter, type) {
2943
  return emitter._handlers && emitter._handlers[type] || noHandlers
2945
 
2946
  function off(emitter, type, f) {
2947
  if (emitter.removeEventListener) {
2948
+ emitter.removeEventListener(type, f, false);
2949
  } else if (emitter.detachEvent) {
2950
+ emitter.detachEvent("on" + type, f);
2951
  } else {
2952
+ var map$$1 = emitter._handlers, arr = map$$1 && map$$1[type];
2953
  if (arr) {
2954
+ var index = indexOf(arr, f);
2955
  if (index > -1)
2956
+ { map$$1[type] = arr.slice(0, index).concat(arr.slice(index + 1)); }
2957
  }
2958
  }
2959
  }
2960
 
2961
  function signal(emitter, type /*, values...*/) {
2962
+ var handlers = getHandlers(emitter, type);
2963
  if (!handlers.length) { return }
2964
+ var args = Array.prototype.slice.call(arguments, 2);
2965
+ for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args); }
2966
  }
2967
 
2968
  // The DOM events that CodeMirror handles can be overridden by
2970
  // and preventDefault-ing the event in that handler.
2971
  function signalDOMEvent(cm, e, override) {
2972
  if (typeof e == "string")
2973
+ { e = {type: e, preventDefault: function() { this.defaultPrevented = true; }}; }
2974
+ signal(cm, override || e.type, cm, e);
2975
  return e_defaultPrevented(e) || e.codemirrorIgnore
2976
  }
2977
 
2978
  function signalCursorActivity(cm) {
2979
+ var arr = cm._handlers && cm._handlers.cursorActivity;
2980
  if (!arr) { return }
2981
+ var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
2982
  for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
2983
+ { set.push(arr[i]); } }
2984
  }
2985
 
2986
  function hasHandler(emitter, type) {
2990
  // Add on and off methods to a constructor's prototype, to make
2991
  // registering events on such objects more convenient.
2992
  function eventMixin(ctor) {
2993
+ ctor.prototype.on = function(type, f) {on(this, type, f);};
2994
+ ctor.prototype.off = function(type, f) {off(this, type, f);};
2995
  }
2996
 
2997
  // Due to the fact that we still support jurassic IE versions, some
2998
  // compatibility wrappers are needed.
2999
 
3000
  function e_preventDefault(e) {
3001
+ if (e.preventDefault) { e.preventDefault(); }
3002
+ else { e.returnValue = false; }
3003
  }
3004
  function e_stopPropagation(e) {
3005
+ if (e.stopPropagation) { e.stopPropagation(); }
3006
+ else { e.cancelBubble = true; }
3007
  }
3008
  function e_defaultPrevented(e) {
3009
  return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
3010
  }
3011
+ function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
3012
 
3013
  function e_target(e) {return e.target || e.srcElement}
3014
  function e_button(e) {
3015
+ var b = e.which;
3016
  if (b == null) {
3017
+ if (e.button & 1) { b = 1; }
3018
+ else if (e.button & 2) { b = 3; }
3019
+ else if (e.button & 4) { b = 2; }
3020
  }
3021
+ if (mac && e.ctrlKey && b == 1) { b = 3; }
3022
  return b
3023
  }
3024
 
3027
  // There is *some* kind of drag-and-drop support in IE6-8, but I
3028
  // couldn't get it to work yet.
3029
  if (ie && ie_version < 9) { return false }
3030
+ var div = elt('div');
3031
  return "draggable" in div || "dragDrop" in div
3032
+ }();
3033
 
3034
+ var zwspSupported;
3035
  function zeroWidthElement(measure) {
3036
  if (zwspSupported == null) {
3037
+ var test = elt("span", "\u200b");
3038
+ removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
3039
  if (measure.firstChild.offsetHeight != 0)
3040
+ { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); }
3041
  }
3042
  var node = zwspSupported ? elt("span", "\u200b") :
3043
+ elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
3044
+ node.setAttribute("cm-text", "");
3045
  return node
3046
  }
3047
 
3048
  // Feature-detect IE's crummy client rect reporting for bidi text
3049
+ var badBidiRects;
3050
  function hasBadBidiRects(measure) {
3051
  if (badBidiRects != null) { return badBidiRects }
3052
+ var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
3053
+ var r0 = range(txt, 0, 1).getBoundingClientRect();
3054
+ var r1 = range(txt, 1, 2).getBoundingClientRect();
3055
+ removeChildren(measure);
3056
  if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
3057
  return badBidiRects = (r1.right - r0.right < 3)
3058
  }
3060
  // See if "".split is the broken IE version, if so, provide an
3061
  // alternative way to split lines.
3062
  var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
3063
+ var pos = 0, result = [], l = string.length;
3064
  while (pos <= l) {
3065
+ var nl = string.indexOf("\n", pos);
3066
+ if (nl == -1) { nl = string.length; }
3067
+ var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
3068
+ var rt = line.indexOf("\r");
3069
  if (rt != -1) {
3070
+ result.push(line.slice(0, rt));
3071
+ pos += rt + 1;
3072
  } else {
3073
+ result.push(line);
3074
+ pos = nl + 1;
3075
  }
3076
  }
3077
  return result
3078
+ } : function (string) { return string.split(/\r\n?|\n/); };
3079
 
3080
  var hasSelection = window.getSelection ? function (te) {
3081
  try { return te.selectionStart != te.selectionEnd }
3082
  catch(e) { return false }
3083
  } : function (te) {
3084
+ var range$$1;
3085
+ try {range$$1 = te.ownerDocument.selection.createRange();}
3086
  catch(e) {}
3087
+ if (!range$$1 || range$$1.parentElement() != te) { return false }
3088
+ return range$$1.compareEndPoints("StartToEnd", range$$1) != 0
3089
+ };
3090
 
3091
  var hasCopyEvent = (function () {
3092
+ var e = elt("div");
3093
  if ("oncopy" in e) { return true }
3094
+ e.setAttribute("oncopy", "return;");
3095
  return typeof e.oncopy == "function"
3096
+ })();
3097
 
3098
+ var badZoomedRects = null;
3099
  function hasBadZoomedRects(measure) {
3100
  if (badZoomedRects != null) { return badZoomedRects }
3101
+ var node = removeChildrenAndAdd(measure, elt("span", "x"));
3102
+ var normal = node.getBoundingClientRect();
3103
+ var fromRange = range(node, 0, 1).getBoundingClientRect();
3104
  return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
3105
  }
3106
 
3107
+ // Known modes, by name and by MIME
3108
  var modes = {};
3109
  var mimeModes = {};
3110
+
3111
  // Extra arguments are stored as the mode's dependencies, which is
3112
  // used by (legacy) mechanisms like loadmode.js to automatically
3113
  // load a mode. (Preferred mechanism is the require/define calls.)
3114
  function defineMode(name, mode) {
3115
  if (arguments.length > 2)
3116
+ { mode.dependencies = Array.prototype.slice.call(arguments, 2); }
3117
+ modes[name] = mode;
3118
  }
3119
 
3120
  function defineMIME(mime, spec) {
3121
+ mimeModes[mime] = spec;
3122
  }
3123
 
3124
  // Given a MIME type, a {name, ...options} config object, or a name
3125
  // string, return a mode config object.
3126
  function resolveMode(spec) {
3127
  if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
3128
+ spec = mimeModes[spec];
3129
  } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
3130
+ var found = mimeModes[spec.name];
3131
+ if (typeof found == "string") { found = {name: found}; }
3132
+ spec = createObj(found, spec);
3133
+ spec.name = found.name;
3134
  } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
3135
  return resolveMode("application/xml")
3136
  } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
3143
  // Given a mode spec (anything that resolveMode accepts), find and
3144
  // initialize an actual mode object.
3145
  function getMode(options, spec) {
3146
+ spec = resolveMode(spec);
3147
+ var mfactory = modes[spec.name];
3148
  if (!mfactory) { return getMode(options, "text/plain") }
3149
+ var modeObj = mfactory(options, spec);
3150
  if (modeExtensions.hasOwnProperty(spec.name)) {
3151
+ var exts = modeExtensions[spec.name];
3152
  for (var prop in exts) {
3153
  if (!exts.hasOwnProperty(prop)) { continue }
3154
+ if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }
3155
+ modeObj[prop] = exts[prop];
3156
  }
3157
  }
3158
+ modeObj.name = spec.name;
3159
+ if (spec.helperType) { modeObj.helperType = spec.helperType; }
3160
  if (spec.modeProps) { for (var prop$1 in spec.modeProps)
3161
+ { modeObj[prop$1] = spec.modeProps[prop$1]; } }
3162
 
3163
  return modeObj
3164
  }
3165
 
3166
  // This can be used to attach properties to mode objects from
3167
  // outside the actual mode definition.
3168
+ var modeExtensions = {};
3169
  function extendMode(mode, properties) {
3170
+ var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
3171
+ copyObj(properties, exts);
3172
  }
3173
 
3174
  function copyState(mode, state) {
3175
  if (state === true) { return state }
3176
  if (mode.copyState) { return mode.copyState(state) }
3177
+ var nstate = {};
3178
  for (var n in state) {
3179
+ var val = state[n];
3180
+ if (val instanceof Array) { val = val.concat([]); }
3181
+ nstate[n] = val;
3182
  }
3183
  return nstate
3184
  }
3186
  // Given a mode and a state (for that mode), find the inner mode and
3187
  // state at the position that the state refers to.
3188
  function innerMode(mode, state) {
3189
+ var info;
3190
  while (mode.innerMode) {
3191
+ info = mode.innerMode(state);
3192
  if (!info || info.mode == mode) { break }
3193
+ state = info.state;
3194
+ mode = info.mode;
3195
  }
3196
  return info || {mode: mode, state: state}
3197
  }
3206
  // parsers more succinct.
3207
 
3208
  var StringStream = function(string, tabSize) {
3209
+ this.pos = this.start = 0;
3210
+ this.string = string;
3211
+ this.tabSize = tabSize || 8;
3212
+ this.lastColumnPos = this.lastColumnValue = 0;
3213
+ this.lineStart = 0;
3214
  };
3215
 
3216
  StringStream.prototype.eol = function () {return this.pos >= this.string.length};
3221
  { return this.string.charAt(this.pos++) }
3222
  };
3223
  StringStream.prototype.eat = function (match) {
3224
+ var ch = this.string.charAt(this.pos);
3225
+ var ok;
3226
+ if (typeof match == "string") { ok = ch == match; }
3227
+ else { ok = ch && (match.test ? match.test(ch) : match(ch)); }
3228
  if (ok) {++this.pos; return ch}
3229
  };
3230
  StringStream.prototype.eatWhile = function (match) {
3231
+ var start = this.pos;
3232
  while (this.eat(match)){}
3233
  return this.pos > start
3234
  };
3235
  StringStream.prototype.eatSpace = function () {
3236
  var this$1 = this;
3237
 
3238
+ var start = this.pos;
3239
+ while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos; }
3240
  return this.pos > start
3241
  };
3242
+ StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};
3243
  StringStream.prototype.skipTo = function (ch) {
3244
+ var found = this.string.indexOf(ch, this.pos);
3245
  if (found > -1) {this.pos = found; return true}
3246
  };
3247
+ StringStream.prototype.backUp = function (n) {this.pos -= n;};
3248
  StringStream.prototype.column = function () {
3249
  if (this.lastColumnPos < this.start) {
3250
+ this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
3251
+ this.lastColumnPos = this.start;
3252
  }
3253
  return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
3254
  };
3258
  };
3259
  StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
3260
  if (typeof pattern == "string") {
3261
+ var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };
3262
+ var substr = this.string.substr(this.pos, pattern.length);
3263
  if (cased(substr) == cased(pattern)) {
3264
+ if (consume !== false) { this.pos += pattern.length; }
3265
  return true
3266
  }
3267
  } else {
3268
+ var match = this.string.slice(this.pos).match(pattern);
3269
  if (match && match.index > 0) { return null }
3270
+ if (match && consume !== false) { this.pos += match[0].length; }
3271
  return match
3272
  }
3273
  };
3274
  StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
3275
  StringStream.prototype.hideFirstChars = function (n, inner) {
3276
+ this.lineStart += n;
3277
  try { return inner() }
3278
+ finally { this.lineStart -= n; }
3279
  };
3280
 
3281
  // Compute a style array (an array starting with a mode generation
3285
  function highlightLine(cm, line, state, forceToEnd) {
3286
  // A styles array always starts with a number identifying the
3287
  // mode/overlays that it is based on (for easy invalidation).
3288
+ var st = [cm.state.modeGen], lineClasses = {};
3289
  // Compute the base array of styles
3290
  runMode(cm, line.text, cm.doc.mode, state, function (end, style) { return st.push(end, style); },
3291
+ lineClasses, forceToEnd);
3292
 
3293
  // Run overlays, adjust style array.
3294
  var loop = function ( o ) {
3295
+ var overlay = cm.state.overlays[o], i = 1, at = 0;
3296
  runMode(cm, line.text, overlay.mode, true, function (end, style) {
3297
+ var start = i;
3298
  // Ensure there's a token end at the current position, and that i points at it
3299
  while (at < end) {
3300
+ var i_end = st[i];
3301
  if (i_end > end)
3302
+ { st.splice(i, 1, end, st[i+1], i_end); }
3303
+ i += 2;
3304
+ at = Math.min(end, i_end);
3305
  }
3306
  if (!style) { return }
3307
  if (overlay.opaque) {
3308
+ st.splice(start, i - start, end, "overlay " + style);
3309
+ i = start + 2;
3310
  } else {
3311
  for (; start < i; start += 2) {
3312
+ var cur = st[start+1];
3313
+ st[start+1] = (cur ? cur + " " : "") + "overlay " + style;
3314
  }
3315
  }
3316
+ }, lineClasses);
3317
  };
3318
 
3319
  for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
3323
 
3324
  function getLineStyles(cm, line, updateFrontier) {
3325
  if (!line.styles || line.styles[0] != cm.state.modeGen) {
3326
+ var state = getStateBefore(cm, lineNo(line));
3327
+ var result = highlightLine(cm, line, line.text.length > cm.options.maxHighlightLength ? copyState(cm.doc.mode, state) : state);
3328
+ line.stateAfter = state;
3329
+ line.styles = result.styles;
3330
+ if (result.classes) { line.styleClasses = result.classes; }
3331
+ else if (line.styleClasses) { line.styleClasses = null; }
3332
+ if (updateFrontier === cm.doc.frontier) { cm.doc.frontier++; }
3333
  }
3334
  return line.styles
3335
  }
3336
 
3337
  function getStateBefore(cm, n, precise) {
3338
+ var doc = cm.doc, display = cm.display;
3339
  if (!doc.mode.startState) { return true }
3340
+ var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
3341
+ if (!state) { state = startState(doc.mode); }
3342
+ else { state = copyState(doc.mode, state); }
3343
  doc.iter(pos, n, function (line) {
3344
+ processLine(cm, line.text, state);
3345
+ var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
3346
+ line.stateAfter = save ? copyState(doc.mode, state) : null;
3347
+ ++pos;
3348
+ });
3349
+ if (precise) { doc.frontier = pos; }
3350
  return state
3351
  }
3352
 
3354
  // update state, but don't save a style array. Used for lines that
3355
  // aren't currently visible.
3356
  function processLine(cm, text, state, startAt) {
3357
+ var mode = cm.doc.mode;
3358
+ var stream = new StringStream(text, cm.options.tabSize);
3359
+ stream.start = stream.pos = startAt || 0;
3360
+ if (text == "") { callBlankLine(mode, state); }
3361
  while (!stream.eol()) {
3362
+ readToken(mode, stream, state);
3363
+ stream.start = stream.pos;
3364
  }
3365
  }
3366
 
3367
  function callBlankLine(mode, state) {
3368
  if (mode.blankLine) { return mode.blankLine(state) }
3369
  if (!mode.innerMode) { return }
3370
+ var inner = innerMode(mode, state);
3371
  if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
3372
  }
3373
 
3374
  function readToken(mode, stream, state, inner) {
3375
  for (var i = 0; i < 10; i++) {
3376
+ if (inner) { inner[0] = innerMode(mode, state).mode; }
3377
+ var style = mode.token(stream, state);
3378
  if (stream.pos > stream.start) { return style }
3379
  }
3380
  throw new Error("Mode " + mode.name + " failed to advance stream.")
3387
  string: stream.current(),
3388
  type: style || null,
3389
  state: copy ? copyState(doc.mode, state) : state
3390
+ }); };
3391
 
3392
+ var doc = cm.doc, mode = doc.mode, style;
3393
+ pos = clipPos(doc, pos);
3394
+ var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise);
3395
+ var stream = new StringStream(line.text, cm.options.tabSize), tokens;
3396
+ if (asArray) { tokens = []; }
3397
  while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
3398
+ stream.start = stream.pos;
3399
+ style = readToken(mode, stream, state);
3400
+ if (asArray) { tokens.push(getObj(true)); }
3401
  }
3402
  return asArray ? tokens : getObj()
3403
  }
3404
 
3405
  function extractLineClasses(type, output) {
3406
  if (type) { for (;;) {
3407
+ var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
3408
  if (!lineClass) { break }
3409
+ type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
3410
+ var prop = lineClass[1] ? "bgClass" : "textClass";
3411
  if (output[prop] == null)
3412
+ { output[prop] = lineClass[2]; }
3413
  else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
3414
+ { output[prop] += " " + lineClass[2]; }
3415
  } }
3416
  return type
3417
  }
3418
 
3419
  // Run the given mode's parser over a line, calling f for each token.
3420
  function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
3421
+ var flattenSpans = mode.flattenSpans;
3422
+ if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans; }
3423
+ var curStart = 0, curStyle = null;
3424
+ var stream = new StringStream(text, cm.options.tabSize), style;
3425
+ var inner = cm.options.addModeClass && [null];
3426
+ if (text == "") { extractLineClasses(callBlankLine(mode, state), lineClasses); }
3427
  while (!stream.eol()) {
3428
  if (stream.pos > cm.options.maxHighlightLength) {
3429
+ flattenSpans = false;
3430
+ if (forceToEnd) { processLine(cm, text, state, stream.pos); }
3431
+ stream.pos = text.length;
3432
+ style = null;
3433
  } else {
3434
+ style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses);
3435
  }
3436
  if (inner) {
3437
+ var mName = inner[0].name;
3438
+ if (mName) { style = "m-" + (style ? mName + " " + style : mName); }
3439
  }
3440
  if (!flattenSpans || curStyle != style) {
3441
  while (curStart < stream.start) {
3442
+ curStart = Math.min(stream.start, curStart + 5000);
3443
+ f(curStart, curStyle);
3444
  }
3445
+ curStyle = style;
3446
  }
3447
+ stream.start = stream.pos;
3448
  }
3449
  while (curStart < stream.pos) {
3450
  // Webkit seems to refuse to render text nodes longer than 57444
3451
  // characters, and returns inaccurate measurements in nodes
3452
  // starting around 5000 chars.
3453
+ var pos = Math.min(stream.pos, curStart + 5000);
3454
+ f(pos, curStyle);
3455
+ curStart = pos;
3456
  }
3457
  }
3458
 
3462
  // smallest indentation, which tends to need the least context to
3463
  // parse correctly.
3464
  function findStartLine(cm, n, precise) {
3465
+ var minindent, minline, doc = cm.doc;
3466
+ var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
3467
  for (var search = n; search > lim; --search) {
3468
  if (search <= doc.first) { return doc.first }
3469
+ var line = getLine(doc, search - 1);
3470
  if (line.stateAfter && (!precise || search <= doc.frontier)) { return search }
3471
+ var indented = countColumn(line.text, null, cm.options.tabSize);
3472
  if (minline == null || minindent > indented) {
3473
+ minline = search - 1;
3474
+ minindent = indented;
3475
  }
3476
  }
3477
  return minline
3482
  // Line objects. These hold state related to a line, including
3483
  // highlighting info (the styles array).
3484
  var Line = function(text, markedSpans, estimateHeight) {
3485
+ this.text = text;
3486
+ attachMarkedSpans(this, markedSpans);
3487
+ this.height = estimateHeight ? estimateHeight(this) : 1;
3488
  };
3489
 
3490
  Line.prototype.lineNo = function () { return lineNo(this) };
3491
+ eventMixin(Line);
3492
 
3493
  // Change the content (text, markers) of a line. Automatically
3494
  // invalidates cached information and tries to re-estimate the
3495
  // line's height.
3496
  function updateLine(line, text, markedSpans, estimateHeight) {
3497
+ line.text = text;
3498
+ if (line.stateAfter) { line.stateAfter = null; }
3499
+ if (line.styles) { line.styles = null; }
3500
+ if (line.order != null) { line.order = null; }
3501
+ detachMarkedSpans(line);
3502
+ attachMarkedSpans(line, markedSpans);
3503
+ var estHeight = estimateHeight ? estimateHeight(line) : 1;
3504
+ if (estHeight != line.height) { updateLineHeight(line, estHeight); }
3505
  }
3506
 
3507
  // Detach a line from the document tree and its markers.
3508
  function cleanUpLine(line) {
3509
+ line.parent = null;
3510
+ detachMarkedSpans(line);
3511
  }
3512
 
3513
  // Convert a style as returned by a mode (either null, or a string
3517
  var styleToClassCacheWithMode = {};
3518
  function interpretTokenStyle(style, options) {
3519
  if (!style || /^\s*$/.test(style)) { return null }
3520
+ var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
3521
  return cache[style] ||
3522
  (cache[style] = style.replace(/\S+/g, "cm-$&"))
3523
  }
3531
  // The padding-right forces the element to have a 'border', which
3532
  // is needed on Webkit to be able to get line-level bounding
3533
  // rectangles for it (in measureChar).
3534
+ var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
3535
+ var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
3536
  col: 0, pos: 0, cm: cm,
3537
  trailingSpace: false,
3538
+ splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")};
3539
+ lineView.measure = {};
 
 
 
3540
 
3541
  // Iterate over the logical lines that make up this visual line.
3542
  for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
3543
+ var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0);
3544
+ builder.pos = 0;
3545
+ builder.addToken = buildToken;
3546
  // Optionally wire in some hacks into the token-rendering
3547
  // algorithm, to deal with browser quirks.
3548
+ if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
3549
+ { builder.addToken = buildTokenBadBidi(builder.addToken, order); }
3550
+ builder.map = [];
3551
+ var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
3552
+ insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
3553
  if (line.styleClasses) {
3554
  if (line.styleClasses.bgClass)
3555
+ { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || ""); }
3556
  if (line.styleClasses.textClass)
3557
+ { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || ""); }
3558
  }
3559
 
3560
  // Ensure at least a single node is present, for measuring.
3561
  if (builder.map.length == 0)
3562
+ { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))); }
3563
 
3564
  // Store the map and a cache object for the current logical line
3565
  if (i == 0) {
3566
+ lineView.measure.map = builder.map;
3567
+ lineView.measure.cache = {};
3568
  } else {
3569
+ (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
3570
+ ;(lineView.measure.caches || (lineView.measure.caches = [])).push({});
3571
  }
3572
  }
3573
 
3574
  // See issue #2901
3575
  if (webkit) {
3576
+ var last = builder.content.lastChild;
3577
  if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
3578
+ { builder.content.className = "cm-tab-wrap-hack"; }
3579
  }
3580
 
3581
+ signal(cm, "renderLine", cm, lineView.line, builder.pre);
3582
  if (builder.pre.className)
3583
+ { builder.textClass = joinClasses(builder.pre.className, builder.textClass || ""); }
3584
 
3585
  return builder
3586
  }
3587
 
3588
  function defaultSpecialCharPlaceholder(ch) {
3589
+ var token = elt("span", "\u2022", "cm-invalidchar");
3590
+ token.title = "\\u" + ch.charCodeAt(0).toString(16);
3591
+ token.setAttribute("aria-label", token.title);
3592
  return token
3593
  }
3594
 
3596
  // the line map. Takes care to render special characters separately.
3597
  function buildToken(builder, text, style, startStyle, endStyle, title, css) {
3598
  if (!text) { return }
3599
+ var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
3600
+ var special = builder.cm.state.specialChars, mustWrap = false;
3601
+ var content;
3602
  if (!special.test(text)) {
3603
+ builder.col += text.length;
3604
+ content = document.createTextNode(displayText);
3605
+ builder.map.push(builder.pos, builder.pos + text.length, content);
3606
+ if (ie && ie_version < 9) { mustWrap = true; }
3607
+ builder.pos += text.length;
3608
  } else {
3609
+ content = document.createDocumentFragment();
3610
+ var pos = 0;
3611
  while (true) {
3612
+ special.lastIndex = pos;
3613
+ var m = special.exec(text);
3614
+ var skipped = m ? m.index - pos : text.length - pos;
3615
  if (skipped) {
3616
+ var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
3617
+ if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); }
3618
+ else { content.appendChild(txt); }
3619
+ builder.map.push(builder.pos, builder.pos + skipped, txt);
3620
+ builder.col += skipped;
3621
+ builder.pos += skipped;
3622
  }
3623
  if (!m) { break }
3624
+ pos += skipped + 1;
3625
+ var txt$1 = (void 0);
3626
  if (m[0] == "\t") {
3627
+ var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
3628
+ txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
3629
+ txt$1.setAttribute("role", "presentation");
3630
+ txt$1.setAttribute("cm-text", "\t");
3631
+ builder.col += tabWidth;
3632
  } else if (m[0] == "\r" || m[0] == "\n") {
3633
+ txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
3634
+ txt$1.setAttribute("cm-text", m[0]);
3635
+ builder.col += 1;
3636
  } else {
3637
+ txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
3638
+ txt$1.setAttribute("cm-text", m[0]);
3639
+ if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); }
3640
+ else { content.appendChild(txt$1); }
3641
+ builder.col += 1;
3642
  }
3643
+ builder.map.push(builder.pos, builder.pos + 1, txt$1);
3644
+ builder.pos++;
3645
  }
3646
  }
3647
+ builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
3648
  if (style || startStyle || endStyle || mustWrap || css) {
3649
+ var fullStyle = style || "";
3650
+ if (startStyle) { fullStyle += startStyle; }
3651
+ if (endStyle) { fullStyle += endStyle; }
3652
+ var token = elt("span", [content], fullStyle, css);
3653
+ if (title) { token.title = title; }
3654
  return builder.content.appendChild(token)
3655
  }
3656
+ builder.content.appendChild(content);
3657
  }
3658
 
3659
  function splitSpaces(text, trailingBefore) {
3660
  if (text.length > 1 && !/ /.test(text)) { return text }
3661
+ var spaceBefore = trailingBefore, result = "";
3662
  for (var i = 0; i < text.length; i++) {
3663
+ var ch = text.charAt(i);
3664
  if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
3665
+ { ch = "\u00a0"; }
3666
+ result += ch;
3667
+ spaceBefore = ch == " ";
3668
  }
3669
  return result
3670
  }
3673
  // right-to-left text.
3674
  function buildTokenBadBidi(inner, order) {
3675
  return function (builder, text, style, startStyle, endStyle, title, css) {
3676
+ style = style ? style + " cm-force-border" : "cm-force-border";
3677
+ var start = builder.pos, end = start + text.length;
3678
  for (;;) {
3679
  // Find the part that overlaps with the start of this text
3680
+ var part = (void 0);
3681
  for (var i = 0; i < order.length; i++) {
3682
+ part = order[i];
3683
  if (part.to > start && part.from <= start) { break }
3684
  }
3685
  if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, title, css) }
3686
+ inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css);
3687
+ startStyle = null;
3688
+ text = text.slice(part.to - start);
3689
+ start = part.to;
3690
  }
3691
  }
3692
  }
3693
 
3694
  function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
3695
+ var widget = !ignoreWidget && marker.widgetNode;
3696
+ if (widget) { builder.map.push(builder.pos, builder.pos + size, widget); }
3697
  if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
3698
  if (!widget)
3699
+ { widget = builder.content.appendChild(document.createElement("span")); }
3700
+ widget.setAttribute("cm-marker", marker.id);
3701
  }
3702
  if (widget) {
3703
+ builder.cm.display.input.setUneditable(widget);
3704
+ builder.content.appendChild(widget);
3705
  }
3706
+ builder.pos += size;
3707
+ builder.trailingSpace = false;
3708
  }
3709
 
3710
  // Outputs a number of spans to make up a line, taking highlighting
3711
  // and marked text into account.
3712
  function insertLineContent(line, builder, styles) {
3713
+ var spans = line.markedSpans, allText = line.text, at = 0;
3714
  if (!spans) {
3715
  for (var i$1 = 1; i$1 < styles.length; i$1+=2)
3716
+ { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)); }
3717
  return
3718
  }
3719
 
3720
+ var len = allText.length, pos = 0, i = 1, text = "", style, css;
3721
+ var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
3722
  for (;;) {
3723
  if (nextChange == pos) { // Update current marker set
3724
+ spanStyle = spanEndStyle = spanStartStyle = title = css = "";
3725
+ collapsed = null; nextChange = Infinity;
3726
+ var foundBookmarks = [], endStyles = (void 0);
3727
  for (var j = 0; j < spans.length; ++j) {
3728
+ var sp = spans[j], m = sp.marker;
3729
  if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
3730
+ foundBookmarks.push(m);
3731
  } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
3732
  if (sp.to != null && sp.to != pos && nextChange > sp.to) {
3733
+ nextChange = sp.to;
3734
+ spanEndStyle = "";
3735
  }
3736
+ if (m.className) { spanStyle += " " + m.className; }
3737
+ if (m.css) { css = (css ? css + ";" : "") + m.css; }
3738
+ if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle; }
3739
+ if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to); }
3740
+ if (m.title && !title) { title = m.title; }
3741
  if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
3742
+ { collapsed = sp; }
3743
  } else if (sp.from > pos && nextChange > sp.from) {
3744
+ nextChange = sp.from;
3745
  }
3746
  }
3747
  if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
3748
+ { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1]; } } }
3749
 
3750
  if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
3751
+ { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]); } }
3752
  if (collapsed && (collapsed.from || 0) == pos) {
3753
  buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
3754
+ collapsed.marker, collapsed.from == null);
3755
  if (collapsed.to == null) { return }
3756
+ if (collapsed.to == pos) { collapsed = false; }
3757
  }
3758
  }
3759
  if (pos >= len) { break }
3760
 
3761
+ var upto = Math.min(len, nextChange);
3762
  while (true) {
3763
  if (text) {
3764
+ var end = pos + text.length;
3765
  if (!collapsed) {
3766
+ var tokenText = end > upto ? text.slice(0, upto - pos) : text;
3767
  builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
3768
+ spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css);
3769
  }
3770
  if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
3771
+ pos = end;
3772
+ spanStartStyle = "";
3773
  }
3774
+ text = allText.slice(at, at = styles[i++]);
3775
+ style = interpretTokenStyle(styles[i++], builder.cm.options);
3776
  }
3777
  }
3778
  }
3783
  // logical lines, if those are connected by collapsed ranges.
3784
  function LineView(doc, line, lineN) {
3785
  // The starting line
3786
+ this.line = line;
3787
  // Continuing lines, if any
3788
+ this.rest = visualLineContinued(line);
3789
  // Number of logical lines in this visual line
3790
+ this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
3791
+ this.node = this.text = null;
3792
+ this.hidden = lineIsHidden(doc, line);
3793
  }
3794
 
3795
  // Create a range of LineView objects for the given lines.
3796
  function buildViewArray(cm, from, to) {
3797
+ var array = [], nextPos;
3798
  for (var pos = from; pos < to; pos = nextPos) {
3799
+ var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
3800
+ nextPos = pos + view.size;
3801
+ array.push(view);
3802
  }
3803
  return array
3804
  }
3805
 
3806
+ var operationGroup = null;
3807
 
3808
  function pushOperation(op) {
3809
  if (operationGroup) {
3810
+ operationGroup.ops.push(op);
3811
  } else {
3812
  op.ownsGroup = operationGroup = {
3813
  ops: [op],
3814
  delayedCallbacks: []
3815
+ };
3816
  }
3817
  }
3818
 
3819
  function fireCallbacksForOps(group) {
3820
  // Calls delayed callbacks and cursorActivity handlers until no
3821
  // new ones appear
3822
+ var callbacks = group.delayedCallbacks, i = 0;
3823
  do {
3824
  for (; i < callbacks.length; i++)
3825
+ { callbacks[i].call(null); }
3826
  for (var j = 0; j < group.ops.length; j++) {
3827
+ var op = group.ops[j];
3828
  if (op.cursorActivityHandlers)
3829
  { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
3830
+ { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } }
3831
  }
3832
  } while (i < callbacks.length)
3833
  }
3834
 
3835
  function finishOperation(op, endCb) {
3836
+ var group = op.ownsGroup;
3837
  if (!group) { return }
3838
 
3839
+ try { fireCallbacksForOps(group); }
3840
  finally {
3841
+ operationGroup = null;
3842
+ endCb(group);
3843
  }
3844
  }
3845
 
3846
+ var orphanDelayedCallbacks = null;
3847
 
3848
  // Often, we want to signal events at a point where we are in the
3849
  // middle of some work, but don't want the handler to start calling
3853
  // them to be executed when the last operation ends, or, if no
3854
  // operation is active, when a timeout fires.
3855
  function signalLater(emitter, type /*, values...*/) {
3856
+ var arr = getHandlers(emitter, type);
3857
  if (!arr.length) { return }
3858
+ var args = Array.prototype.slice.call(arguments, 2), list;
3859
  if (operationGroup) {
3860
+ list = operationGroup.delayedCallbacks;
3861
  } else if (orphanDelayedCallbacks) {
3862
+ list = orphanDelayedCallbacks;
3863
  } else {
3864
+ list = orphanDelayedCallbacks = [];
3865
+ setTimeout(fireOrphanDelayed, 0);
3866
  }
3867
  var loop = function ( i ) {
3868
+ list.push(function () { return arr[i].apply(null, args); });
3869
  };
3870
 
3871
  for (var i = 0; i < arr.length; ++i)
3873
  }
3874
 
3875
  function fireOrphanDelayed() {
3876
+ var delayed = orphanDelayedCallbacks;
3877
+ orphanDelayedCallbacks = null;
3878
+ for (var i = 0; i < delayed.length; ++i) { delayed[i](); }
3879
  }
3880
 
3881
  // When an aspect of a line changes, a string is added to
3883
  // DOM structure.
3884
  function updateLineForChanges(cm, lineView, lineN, dims) {
3885
  for (var j = 0; j < lineView.changes.length; j++) {
3886
+ var type = lineView.changes[j];
3887
+ if (type == "text") { updateLineText(cm, lineView); }
3888
+ else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims); }
3889
+ else if (type == "class") { updateLineClasses(cm, lineView); }
3890
+ else if (type == "widget") { updateLineWidgets(cm, lineView, dims); }
3891
  }
3892
+ lineView.changes = null;
3893
  }
3894
 
3895
  // Lines with gutter elements, widgets or a background class need to
3896
  // be wrapped, and have the extra elements added to the wrapper div
3897
  function ensureLineWrapped(lineView) {
3898
  if (lineView.node == lineView.text) {
3899
+ lineView.node = elt("div", null, null, "position: relative");
3900
  if (lineView.text.parentNode)
3901
+ { lineView.text.parentNode.replaceChild(lineView.node, lineView.text); }
3902
+ lineView.node.appendChild(lineView.text);
3903
+ if (ie && ie_version < 8) { lineView.node.style.zIndex = 2; }
3904
  }
3905
  return lineView.node
3906
  }
3907
 
3908
+ function updateLineBackground(cm, lineView) {
3909
+ var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
3910
+ if (cls) { cls += " CodeMirror-linebackground"; }
3911
  if (lineView.background) {
3912
+ if (cls) { lineView.background.className = cls; }
3913
+ else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
3914
  } else if (cls) {
3915
+ var wrap = ensureLineWrapped(lineView);
3916
+ lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
3917
+ cm.display.input.setUneditable(lineView.background);
3918
  }
3919
  }
3920
 
3921
  // Wrapper around buildLineContent which will reuse the structure
3922
  // in display.externalMeasured when possible.
3923
  function getLineContent(cm, lineView) {
3924
+ var ext = cm.display.externalMeasured;
3925
  if (ext && ext.line == lineView.line) {
3926
+ cm.display.externalMeasured = null;
3927
+ lineView.measure = ext.measure;
3928
  return ext.built
3929
  }
3930
  return buildLineContent(cm, lineView)
3934
  // classes because the mode may output tokens that influence these
3935
  // classes.
3936
  function updateLineText(cm, lineView) {
3937
+ var cls = lineView.text.className;
3938
+ var built = getLineContent(cm, lineView);
3939
+ if (lineView.text == lineView.node) { lineView.node = built.pre; }
3940
+ lineView.text.parentNode.replaceChild(built.pre, lineView.text);
3941
+ lineView.text = built.pre;
3942
  if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
3943
+ lineView.bgClass = built.bgClass;
3944
+ lineView.textClass = built.textClass;
3945
+ updateLineClasses(cm, lineView);
3946
  } else if (cls) {
3947
+ lineView.text.className = cls;
3948
  }
3949
  }
3950
 
3951
+ function updateLineClasses(cm, lineView) {
3952
+ updateLineBackground(cm, lineView);
3953
  if (lineView.line.wrapClass)
3954
+ { ensureLineWrapped(lineView).className = lineView.line.wrapClass; }
3955
  else if (lineView.node != lineView.text)
3956
+ { lineView.node.className = ""; }
3957
+ var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
3958
+ lineView.text.className = textClass || "";
3959
  }
3960
 
3961
  function updateLineGutter(cm, lineView, lineN, dims) {
3962
  if (lineView.gutter) {
3963
+ lineView.node.removeChild(lineView.gutter);
3964
+ lineView.gutter = null;
3965
  }
3966
  if (lineView.gutterBackground) {
3967
+ lineView.node.removeChild(lineView.gutterBackground);
3968
+ lineView.gutterBackground = null;
3969
  }
3970
  if (lineView.line.gutterClass) {
3971
+ var wrap = ensureLineWrapped(lineView);
3972
  lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
3973
+ ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"));
3974
+ cm.display.input.setUneditable(lineView.gutterBackground);
3975
+ wrap.insertBefore(lineView.gutterBackground, lineView.text);
3976
  }
3977
+ var markers = lineView.line.gutterMarkers;
3978
  if (cm.options.lineNumbers || markers) {
3979
+ var wrap$1 = ensureLineWrapped(lineView);
3980
+ var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"));
3981
+ cm.display.input.setUneditable(gutterWrap);
3982
+ wrap$1.insertBefore(gutterWrap, lineView.text);
3983
  if (lineView.line.gutterClass)
3984
+ { gutterWrap.className += " " + lineView.line.gutterClass; }
3985
  if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
3986
  { lineView.lineNumber = gutterWrap.appendChild(
3987
  elt("div", lineNumberFor(cm.options, lineN),
3988
  "CodeMirror-linenumber CodeMirror-gutter-elt",
3989
+ ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))); }
3990
  if (markers) { for (var k = 0; k < cm.options.gutters.length; ++k) {
3991
+ var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
3992
  if (found)
3993
  { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
3994
+ ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))); }
3995
  } }
3996
  }
3997
  }
3998
 
3999
  function updateLineWidgets(cm, lineView, dims) {
4000
+ if (lineView.alignable) { lineView.alignable = null; }
4001
  for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
4002
+ next = node.nextSibling;
4003
  if (node.className == "CodeMirror-linewidget")
4004
+ { lineView.node.removeChild(node); }
4005
  }
4006
+ insertLineWidgets(cm, lineView, dims);
4007
  }
4008
 
4009
  // Build a line's DOM representation from scratch
4010
  function buildLineElement(cm, lineView, lineN, dims) {
4011
+ var built = getLineContent(cm, lineView);
4012
+ lineView.text = lineView.node = built.pre;
4013
+ if (built.bgClass) { lineView.bgClass = built.bgClass; }
4014
+ if (built.textClass) { lineView.textClass = built.textClass; }
4015
+
4016
+ updateLineClasses(cm, lineView);
4017
+ updateLineGutter(cm, lineView, lineN, dims);
4018
+ insertLineWidgets(cm, lineView, dims);
4019
  return lineView.node
4020
  }
4021
 
4022
  // A lineView may contain multiple logical lines (when merged by
4023
  // collapsed spans). The widgets for all of them need to be drawn.
4024
  function insertLineWidgets(cm, lineView, dims) {
4025
+ insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
4026
  if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
4027
+ { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } }
4028
  }
4029
 
4030
  function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
4031
  if (!line.widgets) { return }
4032
+ var wrap = ensureLineWrapped(lineView);
4033
  for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
4034
+ var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
4035
+ if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true"); }
4036
+ positionLineWidget(widget, node, lineView, dims);
4037
+ cm.display.input.setUneditable(node);
4038
  if (allowAbove && widget.above)
4039
+ { wrap.insertBefore(node, lineView.gutter || lineView.text); }
4040
  else
4041
+ { wrap.appendChild(node); }
4042
+ signalLater(widget, "redraw");
4043
  }
4044
  }
4045
 
4046
  function positionLineWidget(widget, node, lineView, dims) {
4047
  if (widget.noHScroll) {
4048
+ (lineView.alignable || (lineView.alignable = [])).push(node);
4049
+ var width = dims.wrapperWidth;
4050
+ node.style.left = dims.fixedPos + "px";
4051
  if (!widget.coverGutter) {
4052
+ width -= dims.gutterTotalWidth;
4053
+ node.style.paddingLeft = dims.gutterTotalWidth + "px";
4054
  }
4055
+ node.style.width = width + "px";
4056
  }
4057
  if (widget.coverGutter) {
4058
+ node.style.zIndex = 5;
4059
+ node.style.position = "relative";
4060
+ if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px"; }
4061
  }
4062
  }
4063
 
4064
  function widgetHeight(widget) {
4065
  if (widget.height != null) { return widget.height }
4066
+ var cm = widget.doc.cm;
4067
  if (!cm) { return 0 }
4068
  if (!contains(document.body, widget.node)) {
4069
+ var parentStyle = "position: relative;";
4070
  if (widget.coverGutter)
4071
+ { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; }
4072
  if (widget.noHScroll)
4073
+ { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; }
4074
+ removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
4075
  }
4076
  return widget.height = widget.node.parentNode.offsetHeight
4077
  }
4091
  function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
4092
  function paddingH(display) {
4093
  if (display.cachedPaddingH) { return display.cachedPaddingH }
4094
+ var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
4095
+ var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
4096
+ var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
4097
+ if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data; }
4098
  return data
4099
  }
4100
 
4111
  // line. When lineWrapping is on, there might be more than one
4112
  // height.
4113
  function ensureLineHeights(cm, lineView, rect) {
4114
+ var wrapping = cm.options.lineWrapping;
4115
+ var curWidth = wrapping && displayWidth(cm);
4116
  if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
4117
+ var heights = lineView.measure.heights = [];
4118
  if (wrapping) {
4119
+ lineView.measure.width = curWidth;
4120
+ var rects = lineView.text.firstChild.getClientRects();
4121
  for (var i = 0; i < rects.length - 1; i++) {
4122
+ var cur = rects[i], next = rects[i + 1];
4123
  if (Math.abs(cur.bottom - next.bottom) > 2)
4124
+ { heights.push((cur.bottom + next.top) / 2 - rect.top); }
4125
  }
4126
  }
4127
+ heights.push(rect.bottom - rect.top);
4128
  }
4129
  }
4130
 
4145
  // Render a line into the hidden node display.externalMeasured. Used
4146
  // when measurement is needed for a line that's not in the viewport.
4147
  function updateExternalMeasurement(cm, line) {
4148
+ line = visualLine(line);
4149
+ var lineN = lineNo(line);
4150
+ var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
4151
+ view.lineN = lineN;
4152
+ var built = view.built = buildLineContent(cm, view);
4153
+ view.text = built.pre;
4154
+ removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
4155
  return view
4156
  }
4157
 
4165
  function findViewForLine(cm, lineN) {
4166
  if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
4167
  { return cm.display.view[findViewIndex(cm, lineN)] }
4168
+ var ext = cm.display.externalMeasured;
4169
  if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
4170
  { return ext }
4171
  }
4176
  // measurements in a row, can thus ensure that the set-up work is
4177
  // only done once.
4178
  function prepareMeasureForLine(cm, line) {
4179
+ var lineN = lineNo(line);
4180
+ var view = findViewForLine(cm, lineN);
4181
  if (view && !view.text) {
4182
+ view = null;
4183
  } else if (view && view.changes) {
4184
+ updateLineForChanges(cm, view, lineN, getDimensions(cm));
4185
+ cm.curOp.forceUpdate = true;
4186
  }
4187
  if (!view)
4188
+ { view = updateExternalMeasurement(cm, line); }
4189
 
4190
+ var info = mapFromLineView(view, line, lineN);
4191
  return {
4192
  line: line, view: view, rect: null,
4193
  map: info.map, cache: info.cache, before: info.before,
4198
  // Given a prepared measurement object, measures the position of an
4199
  // actual character (or fetches it from the cache).
4200
  function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
4201
+ if (prepared.before) { ch = -1; }
4202
+ var key = ch + (bias || ""), found;
4203
  if (prepared.cache.hasOwnProperty(key)) {
4204
+ found = prepared.cache[key];
4205
  } else {
4206
  if (!prepared.rect)
4207
+ { prepared.rect = prepared.view.text.getBoundingClientRect(); }
4208
  if (!prepared.hasHeights) {
4209
+ ensureLineHeights(cm, prepared.view, prepared.rect);
4210
+ prepared.hasHeights = true;
4211
  }
4212
+ found = measureCharInner(cm, prepared, ch, bias);
4213
+ if (!found.bogus) { prepared.cache[key] = found; }
4214
  }
4215
  return {left: found.left, right: found.right,
4216
  top: varHeight ? found.rtop : found.top,
4217
  bottom: varHeight ? found.rbottom : found.bottom}
4218
  }
4219
 
4220
+ var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
4221
 
4222
+ function nodeAndOffsetInLineMap(map$$1, ch, bias) {
4223
+ var node, start, end, collapse, mStart, mEnd;
4224
  // First, search the line map for the text node corresponding to,
4225
  // or closest to, the target character.
4226
+ for (var i = 0; i < map$$1.length; i += 3) {
4227
+ mStart = map$$1[i];
4228
+ mEnd = map$$1[i + 1];
4229
  if (ch < mStart) {
4230
+ start = 0; end = 1;
4231
+ collapse = "left";
4232
  } else if (ch < mEnd) {
4233
+ start = ch - mStart;
4234
+ end = start + 1;
4235
+ } else if (i == map$$1.length - 3 || ch == mEnd && map$$1[i + 3] > ch) {
4236
+ end = mEnd - mStart;
4237
+ start = end - 1;
4238
+ if (ch >= mEnd) { collapse = "right"; }
4239
  }
4240
  if (start != null) {
4241
+ node = map$$1[i + 2];
4242
  if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
4243
+ { collapse = bias; }
4244
  if (bias == "left" && start == 0)
4245
+ { while (i && map$$1[i - 2] == map$$1[i - 3] && map$$1[i - 1].insertLeft) {
4246
+ node = map$$1[(i -= 3) + 2];
4247
+ collapse = "left";
4248
  } }
4249
  if (bias == "right" && start == mEnd - mStart)
4250
+ { while (i < map$$1.length - 3 && map$$1[i + 3] == map$$1[i + 4] && !map$$1[i + 5].insertLeft) {
4251
+ node = map$$1[(i += 3) + 2];
4252
+ collapse = "right";
4253
  } }
4254
  break
4255
  }
4258
  }
4259
 
4260
  function getUsefulRect(rects, bias) {
4261
+ var rect = nullRect;
4262
  if (bias == "left") { for (var i = 0; i < rects.length; i++) {
4263
  if ((rect = rects[i]).left != rect.right) { break }
4264
  } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
4268
  }
4269
 
4270
  function measureCharInner(cm, prepared, ch, bias) {
4271
+ var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
4272
+ var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
4273
 
4274
+ var rect;
4275
  if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
4276
  for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
4277
+ while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start; }
4278
+ while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end; }
4279
  if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
4280
+ { rect = node.parentNode.getBoundingClientRect(); }
4281
  else
4282
+ { rect = getUsefulRect(range(node, start, end).getClientRects(), bias); }
4283
  if (rect.left || rect.right || start == 0) { break }
4284
+ end = start;
4285
+ start = start - 1;
4286
+ collapse = "right";
4287
  }
4288
+ if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect); }
4289
  } else { // If it is a widget, simply get the box for the whole widget.
4290
+ if (start > 0) { collapse = bias = "right"; }
4291
+ var rects;
4292
  if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
4293
+ { rect = rects[bias == "right" ? rects.length - 1 : 0]; }
4294
  else
4295
+ { rect = node.getBoundingClientRect(); }
4296
  }
4297
  if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
4298
+ var rSpan = node.parentNode.getClientRects()[0];
4299
  if (rSpan)
4300
+ { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom}; }
4301
  else
4302
+ { rect = nullRect; }
4303
  }
4304
 
4305
+ var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
4306
+ var mid = (rtop + rbot) / 2;
4307
+ var heights = prepared.view.measure.heights;
4308
+ var i = 0;
4309
  for (; i < heights.length - 1; i++)
4310
  { if (mid < heights[i]) { break } }
4311
+ var top = i ? heights[i - 1] : 0, bot = heights[i];
4312
  var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
4313
  right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
4314
+ top: top, bottom: bot};
4315
+ if (!rect.left && !rect.right) { result.bogus = true; }
4316
+ if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
4317
 
4318
  return result
4319
  }
4324
  if (!window.screen || screen.logicalXDPI == null ||
4325
  screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
4326
  { return rect }
4327
+ var scaleX = screen.logicalXDPI / screen.deviceXDPI;
4328
+ var scaleY = screen.logicalYDPI / screen.deviceYDPI;
4329
  return {left: rect.left * scaleX, right: rect.right * scaleX,
4330
  top: rect.top * scaleY, bottom: rect.bottom * scaleY}
4331
  }
4332
 
4333
  function clearLineMeasurementCacheFor(lineView) {
4334
  if (lineView.measure) {
4335
+ lineView.measure.cache = {};
4336
+ lineView.measure.heights = null;
4337
  if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
4338
+ { lineView.measure.caches[i] = {}; } }
4339
  }
4340
  }
4341
 
4342
  function clearLineMeasurementCache(cm) {
4343
+ cm.display.externalMeasure = null;
4344
+ removeChildren(cm.display.lineMeasure);
4345
  for (var i = 0; i < cm.display.view.length; i++)
4346
+ { clearLineMeasurementCacheFor(cm.display.view[i]); }
4347
  }
4348
 
4349
  function clearCaches(cm) {
4350
+ clearLineMeasurementCache(cm);
4351
+ cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
4352
+ if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true; }
4353
+ cm.display.lineNumChars = null;
4354
  }
4355
 
4356
  function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft }
4362
  // or "page".
4363
  function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
4364
  if (!includeWidgets && lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above) {
4365
+ var size = widgetHeight(lineObj.widgets[i]);
4366
+ rect.top += size; rect.bottom += size;
4367
  } } }
4368
  if (context == "line") { return rect }
4369
+ if (!context) { context = "local"; }
4370
+ var yOff = heightAtLine(lineObj);
4371
+ if (context == "local") { yOff += paddingTop(cm.display); }
4372
+ else { yOff -= cm.display.viewOffset; }
4373
  if (context == "page" || context == "window") {
4374
+ var lOff = cm.display.lineSpace.getBoundingClientRect();
4375
+ yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
4376
+ var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
4377
+ rect.left += xOff; rect.right += xOff;
4378
  }
4379
+ rect.top += yOff; rect.bottom += yOff;
4380
  return rect
4381
  }
4382
 
4384
  // Context may be "window", "page", "div", or "local"./null.
4385
  function fromCoordSystem(cm, coords, context) {
4386
  if (context == "div") { return coords }
4387
+ var left = coords.left, top = coords.top;
4388
  // First move into "page" coordinate system
4389
  if (context == "page") {
4390
+ left -= pageScrollX();
4391
+ top -= pageScrollY();
4392
  } else if (context == "local" || !context) {
4393
+ var localBox = cm.display.sizer.getBoundingClientRect();
4394
+ left += localBox.left;
4395
+ top += localBox.top;
4396
  }
4397
 
4398
+ var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
4399
  return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
4400
  }
4401
 
4402
  function charCoords(cm, pos, context, lineObj, bias) {
4403
+ if (!lineObj) { lineObj = getLine(cm.doc, pos.line); }
4404
  return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
4405
  }
4406
 
4421
  // Every position after the last character on a line is considered to stick
4422
  // to the last character on the line.
4423
  function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
4424
+ lineObj = lineObj || getLine(cm.doc, pos.line);
4425
+ if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
4426
  function get(ch, right) {
4427
+ var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
4428
+ if (right) { m.left = m.right; } else { m.right = m.left; }
4429
  return intoCoordSystem(cm, lineObj, m, context)
4430
  }
4431
+ var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky;
4432
  if (ch >= lineObj.text.length) {
4433
+ ch = lineObj.text.length;
4434
+ sticky = "before";
4435
  } else if (ch <= 0) {
4436
+ ch = 0;
4437
+ sticky = "after";
4438
  }
4439
  if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
4440
 
4441
  function getBidi(ch, partPos, invert) {
4442
+ var part = order[partPos], right = (part.level % 2) != 0;
4443
  return get(invert ? ch - 1 : ch, right != invert)
4444
  }
4445
+ var partPos = getBidiPartAt(order, ch, sticky);
4446
+ var other = bidiOther;
4447
+ var val = getBidi(ch, partPos, sticky == "before");
4448
+ if (other != null) { val.other = getBidi(ch, other, sticky != "before"); }
4449
  return val
4450
  }
4451
 
4452
  // Used to cheaply estimate the coordinates for a position. Used for
4453
  // intermediate scroll updates.
4454
  function estimateCoords(cm, pos) {
4455
+ var left = 0;
4456
+ pos = clipPos(cm.doc, pos);
4457
+ if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch; }
4458
+ var lineObj = getLine(cm.doc, pos.line);
4459
+ var top = heightAtLine(lineObj) + paddingTop(cm.display);
4460
  return {left: left, right: left, top: top, bottom: top + lineObj.height}
4461
  }
4462
 
4467
  // is true, that means the coordinates lie outside the line's
4468
  // vertical range.
4469
  function PosWithInfo(line, ch, sticky, outside, xRel) {
4470
+ var pos = Pos(line, ch, sticky);
4471
+ pos.xRel = xRel;
4472
+ if (outside) { pos.outside = true; }
4473
  return pos
4474
  }
4475
 
4476
  // Compute the character position closest to the given coordinates.
4477
  // Input must be lineSpace-local ("div" coordinate system).
4478
  function coordsChar(cm, x, y) {
4479
+ var doc = cm.doc;
4480
+ y += cm.display.viewOffset;
4481
  if (y < 0) { return PosWithInfo(doc.first, 0, null, true, -1) }
4482
+ var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
4483
  if (lineN > last)
4484
  { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1) }
4485
+ if (x < 0) { x = 0; }
4486
 
4487
+ var lineObj = getLine(doc, lineN);
4488
  for (;;) {
4489
+ var found = coordsCharInner(cm, lineObj, lineN, x, y);
4490
+ var merged = collapsedSpanAtEnd(lineObj);
4491
+ var mergedPos = merged && merged.find(0, true);
4492
  if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
4493
+ { lineN = lineNo(lineObj = mergedPos.to.line); }
4494
  else
4495
  { return found }
4496
  }
4497
  }
4498
 
4499
  function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
4500
+ var measure = function (ch) { return intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, ch), "line"); };
4501
+ var end = lineObj.text.length;
4502
+ var begin = findFirst(function (ch) { return measure(ch - 1).bottom <= y; }, end, 0);
4503
+ end = findFirst(function (ch) { return measure(ch).top > y; }, begin, end);
4504
  return {begin: begin, end: end}
4505
  }
4506
 
4507
  function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
4508
+ var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
4509
  return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
4510
  }
4511
 
4512
+ function coordsCharInner(cm, lineObj, lineNo$$1, x, y) {
4513
+ y -= heightAtLine(lineObj);
4514
+ var begin = 0, end = lineObj.text.length;
4515
+ var preparedMeasure = prepareMeasureForLine(cm, lineObj);
4516
+ var pos;
4517
+ var order = getOrder(lineObj, cm.doc.direction);
4518
  if (order) {
4519
  if (cm.options.lineWrapping) {
4520
+ var assign;
4521
+ ((assign = wrappedLineExtent(cm, lineObj, preparedMeasure, y), begin = assign.begin, end = assign.end, assign));
4522
  }
4523
+ pos = new Pos(lineNo$$1, begin);
4524
+ var beginLeft = cursorCoords(cm, pos, "line", lineObj, preparedMeasure).left;
4525
+ var dir = beginLeft < x ? 1 : -1;
4526
+ var prevDiff, diff = beginLeft - x, prevPos;
4527
  do {
4528
+ prevDiff = diff;
4529
+ prevPos = pos;
4530
+ pos = moveVisually(cm, lineObj, pos, dir);
4531
  if (pos == null || pos.ch < begin || end <= (pos.sticky == "before" ? pos.ch - 1 : pos.ch)) {
4532
+ pos = prevPos;
4533
  break
4534
  }
4535
+ diff = cursorCoords(cm, pos, "line", lineObj, preparedMeasure).left - x;
4536
  } while ((dir < 0) != (diff < 0) && (Math.abs(diff) <= Math.abs(prevDiff)))
4537
  if (Math.abs(diff) > Math.abs(prevDiff)) {
4538
  if ((diff < 0) == (prevDiff < 0)) { throw new Error("Broke out of infinite loop in coordsCharInner") }
4539
+ pos = prevPos;
4540
  }
4541
  } else {
4542
  var ch = findFirst(function (ch) {
4543
+ var box = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, ch), "line");
4544
  if (box.top > y) {
4545
  // For the cursor stickiness
4546
+ end = Math.min(ch, end);
4547
  return true
4548
  }
4549
  else if (box.bottom <= y) { return false }
4550
  else if (box.left > x) { return true }
4551
  else if (box.right < x) { return false }
4552
  else { return (x - box.left < box.right - x) }
4553
+ }, begin, end);
4554
+ ch = skipExtendingChars(lineObj.text, ch, 1);
4555
+ pos = new Pos(lineNo$$1, ch, ch == end ? "before" : "after");
4556
  }
4557
+ var coords = cursorCoords(cm, pos, "line", lineObj, preparedMeasure);
4558
+ if (y < coords.top || coords.bottom < y) { pos.outside = true; }
4559
+ pos.xRel = x < coords.left ? -1 : (x > coords.right ? 1 : 0);
4560
  return pos
4561
  }
4562
 
4563
+ var measureText;
4564
  // Compute the default text height.
4565
  function textHeight(display) {
4566
  if (display.cachedTextHeight != null) { return display.cachedTextHeight }
4567
  if (measureText == null) {
4568
+ measureText = elt("pre");
4569
  // Measure a bunch of lines, for browsers that compute
4570
  // fractional heights.
4571
  for (var i = 0; i < 49; ++i) {
4572
+ measureText.appendChild(document.createTextNode("x"));
4573
+ measureText.appendChild(elt("br"));
4574
  }
4575
+ measureText.appendChild(document.createTextNode("x"));
4576
  }
4577
+ removeChildrenAndAdd(display.measure, measureText);
4578
+ var height = measureText.offsetHeight / 50;
4579
+ if (height > 3) { display.cachedTextHeight = height; }
4580
+ removeChildren(display.measure);
4581
  return height || 1
4582
  }
4583
 
4584
  // Compute the default character width.
4585
  function charWidth(display) {
4586
  if (display.cachedCharWidth != null) { return display.cachedCharWidth }
4587
+ var anchor = elt("span", "xxxxxxxxxx");
4588
+ var pre = elt("pre", [anchor]);
4589
+ removeChildrenAndAdd(display.measure, pre);
4590
+ var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
4591
+ if (width > 2) { display.cachedCharWidth = width; }
4592
  return width || 10
4593
  }
4594
 
4595
  // Do a bulk-read of the DOM positions and sizes needed to draw the
4596
  // view, so that we don't interleave reading and writing to the DOM.
4597
  function getDimensions(cm) {
4598
+ var d = cm.display, left = {}, width = {};
4599
+ var gutterLeft = d.gutters.clientLeft;
4600
  for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
4601
+ left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
4602
+ width[cm.options.gutters[i]] = n.clientWidth;
4603
  }
4604
  return {fixedPos: compensateForHScroll(d),
4605
  gutterTotalWidth: d.gutters.offsetWidth,
4619
  // first approximation until the line becomes visible (and is thus
4620
  // properly measurable).
4621
  function estimateHeight(cm) {
4622
+ var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
4623
+ var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
4624
  return function (line) {
4625
  if (lineIsHidden(cm.doc, line)) { return 0 }
4626
 
4627
+ var widgetsHeight = 0;
4628
  if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
4629
+ if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height; }
4630
  } }
4631
 
4632
  if (wrapping)
4637
  }
4638
 
4639
  function estimateLineHeights(cm) {
4640
+ var doc = cm.doc, est = estimateHeight(cm);
4641
  doc.iter(function (line) {
4642
+ var estHeight = est(line);
4643
+ if (estHeight != line.height) { updateLineHeight(line, estHeight); }
4644
+ });
4645
  }
4646
 
4647
  // Given a mouse event, find the corresponding position. If liberal
4650
  // selections, and tries to estimate a character position even for
4651
  // coordinates beyond the right of the text.
4652
  function posFromMouse(cm, e, liberal, forRect) {
4653
+ var display = cm.display;
4654
  if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
4655
 
4656
+ var x, y, space = display.lineSpace.getBoundingClientRect();
4657
  // Fails unpredictably on IE[67] when mouse is dragged around quickly.
4658
+ try { x = e.clientX - space.left; y = e.clientY - space.top; }
4659
  catch (e) { return null }
4660
+ var coords = coordsChar(cm, x, y), line;
4661
  if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
4662
+ var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
4663
+ coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
4664
  }
4665
  return coords
4666
  }
4669
  // when the line isn't visible.
4670
  function findViewIndex(cm, n) {
4671
  if (n >= cm.display.viewTo) { return null }
4672
+ n -= cm.display.viewFrom;
4673
  if (n < 0) { return null }
4674
+ var view = cm.display.view;
4675
  for (var i = 0; i < view.length; i++) {
4676
+ n -= view[i].size;
4677
  if (n < 0) { return i }
4678
  }
4679
  }
4680
 
4681
  function updateSelection(cm) {
4682
+ cm.display.input.showSelection(cm.display.input.prepareSelection());
4683
  }
4684
 
4685
  function prepareSelection(cm, primary) {
4686
+ var doc = cm.doc, result = {};
4687
+ var curFragment = result.cursors = document.createDocumentFragment();
4688
+ var selFragment = result.selection = document.createDocumentFragment();
4689
 
4690
  for (var i = 0; i < doc.sel.ranges.length; i++) {
4691
  if (primary === false && i == doc.sel.primIndex) { continue }
4692
+ var range$$1 = doc.sel.ranges[i];
4693
+ if (range$$1.from().line >= cm.display.viewTo || range$$1.to().line < cm.display.viewFrom) { continue }
4694
+ var collapsed = range$$1.empty();
4695
  if (collapsed || cm.options.showCursorWhenSelecting)
4696
+ { drawSelectionCursor(cm, range$$1.head, curFragment); }
4697
  if (!collapsed)
4698
+ { drawSelectionRange(cm, range$$1, selFragment); }
4699
  }
4700
  return result
4701
  }
4702
 
4703
  // Draws a cursor for the given range
4704
  function drawSelectionCursor(cm, head, output) {
4705
+ var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
4706
 
4707
+ var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
4708
+ cursor.style.left = pos.left + "px";
4709
+ cursor.style.top = pos.top + "px";
4710
+ cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
4711
 
4712
  if (pos.other) {
4713
  // Secondary cursor, shown when on a 'jump' in bi-directional text
4714
+ var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
4715
+ otherCursor.style.display = "";
4716
+ otherCursor.style.left = pos.other.left + "px";
4717
+ otherCursor.style.top = pos.other.top + "px";
4718
+ otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
4719
  }
4720
  }
4721
 
4722
  // Draws the given range as a highlighted selection
4723
+ function drawSelectionRange(cm, range$$1, output) {
4724
+ var display = cm.display, doc = cm.doc;
4725
+ var fragment = document.createDocumentFragment();
4726
+ var padding = paddingH(cm.display), leftSide = padding.left;
4727
+ var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
4728
 
4729
  function add(left, top, width, bottom) {
4730
+ if (top < 0) { top = 0; }
4731
+ top = Math.round(top);
4732
+ bottom = Math.round(bottom);
4733
+ fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")));
4734
  }
4735
 
4736
  function drawForLine(line, fromArg, toArg) {
4737
+ var lineObj = getLine(doc, line);
4738
+ var lineLen = lineObj.text.length;
4739
+ var start, end;
4740
  function coords(ch, bias) {
4741
  return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
4742
  }
4743
 
4744
+ iterateBidiSections(getOrder(lineObj, doc.direction), fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir) {
4745
+ var leftPos = coords(from, "left"), rightPos, left, right;
4746
  if (from == to) {
4747
+ rightPos = leftPos;
4748
+ left = right = leftPos.left;
4749
  } else {
4750
+ rightPos = coords(to - 1, "right");
4751
+ if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
4752
+ left = leftPos.left;
4753
+ right = rightPos.right;
4754
  }
4755
+ if (fromArg == null && from == 0) { left = leftSide; }
4756
  if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
4757
+ add(left, leftPos.top, null, leftPos.bottom);
4758
+ left = leftSide;
4759
+ if (leftPos.bottom < rightPos.top) { add(left, leftPos.bottom, null, rightPos.top); }
4760
  }
4761
+ if (toArg == null && to == lineLen) { right = rightSide; }
4762
  if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
4763
+ { start = leftPos; }
4764
  if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
4765
+ { end = rightPos; }
4766
+ if (left < leftSide + 1) { left = leftSide; }
4767
+ add(left, rightPos.top, right - left, rightPos.bottom);
4768
+ });
4769
  return {start: start, end: end}
4770
  }
4771
 
4772
+ var sFrom = range$$1.from(), sTo = range$$1.to();
4773
  if (sFrom.line == sTo.line) {
4774
+ drawForLine(sFrom.line, sFrom.ch, sTo.ch);
4775
  } else {
4776
+ var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
4777
+ var singleVLine = visualLine(fromLine) == visualLine(toLine);
4778
+ var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
4779
+ var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
4780
  if (singleVLine) {
4781
  if (leftEnd.top < rightStart.top - 2) {
4782
+ add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
4783
+ add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
4784
  } else {
4785
+ add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
4786
  }
4787
  }
4788
  if (leftEnd.bottom < rightStart.top)
4789
+ { add(leftSide, leftEnd.bottom, null, rightStart.top); }
4790
  }
4791
 
4792
+ output.appendChild(fragment);
4793
  }
4794
 
4795
  // Cursor-blinking
4796
  function restartBlink(cm) {
4797
  if (!cm.state.focused) { return }
4798
+ var display = cm.display;
4799
+ clearInterval(display.blinker);
4800
+ var on = true;
4801
+ display.cursorDiv.style.visibility = "";
4802
  if (cm.options.cursorBlinkRate > 0)
4803
  { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
4804
+ cm.options.cursorBlinkRate); }
4805
  else if (cm.options.cursorBlinkRate < 0)
4806
+ { display.cursorDiv.style.visibility = "hidden"; }
4807
  }
4808
 
4809
  function ensureFocus(cm) {
4810
+ if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
4811
  }
4812
 
4813
  function delayBlurEvent(cm) {
4814
+ cm.state.delayingBlurEvent = true;
4815
  setTimeout(function () { if (cm.state.delayingBlurEvent) {
4816
+ cm.state.delayingBlurEvent = false;
4817
+ onBlur(cm);
4818
+ } }, 100);
4819
  }
4820
 
4821
  function onFocus(cm, e) {
4822
+ if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false; }
4823
 
4824
  if (cm.options.readOnly == "nocursor") { return }
4825
  if (!cm.state.focused) {
4826
+ signal(cm, "focus", cm, e);
4827
+ cm.state.focused = true;
4828
+ addClass(cm.display.wrapper, "CodeMirror-focused");
4829
  // This test prevents this from firing when a context
4830
  // menu is closed (since the input reset would kill the
4831
  // select-all detection hack)
4832
  if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
4833
+ cm.display.input.reset();
4834
+ if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20); } // Issue #1730
4835
  }
4836
+ cm.display.input.receivedFocus();
4837
  }
4838
+ restartBlink(cm);
4839
  }
4840
  function onBlur(cm, e) {
4841
  if (cm.state.delayingBlurEvent) { return }
4842
 
4843
  if (cm.state.focused) {
4844
+ signal(cm, "blur", cm, e);
4845
+ cm.state.focused = false;
4846
+ rmClass(cm.display.wrapper, "CodeMirror-focused");
4847
  }
4848
+ clearInterval(cm.display.blinker);
4849
+ setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false; } }, 150);
4850
  }
4851
 
4852
  // Re-align line numbers and gutter marks to compensate for
4853
  // horizontal scrolling.
4854
  function alignHorizontally(cm) {
4855
+ var display = cm.display, view = display.view;
4856
  if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
4857
+ var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
4858
+ var gutterW = display.gutters.offsetWidth, left = comp + "px";
4859
  for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
4860
  if (cm.options.fixedGutter) {
4861
  if (view[i].gutter)
4862
+ { view[i].gutter.style.left = left; }
4863
  if (view[i].gutterBackground)
4864
+ { view[i].gutterBackground.style.left = left; }
4865
  }
4866
+ var align = view[i].alignable;
4867
  if (align) { for (var j = 0; j < align.length; j++)
4868
+ { align[j].style.left = left; } }
4869
  } }
4870
  if (cm.options.fixedGutter)
4871
+ { display.gutters.style.left = (comp + gutterW) + "px"; }
4872
  }
4873
 
4874
  // Used to ensure that the line number gutter is still the right
4876
  // is needed.
4877
  function maybeUpdateLineNumberWidth(cm) {
4878
  if (!cm.options.lineNumbers) { return false }
4879
+ var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
4880
  if (last.length != display.lineNumChars) {
4881
  var test = display.measure.appendChild(elt("div", [elt("div", last)],
4882
+ "CodeMirror-linenumber CodeMirror-gutter-elt"));
4883
+ var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
4884
+ display.lineGutter.style.width = "";
4885
+ display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
4886
+ display.lineNumWidth = display.lineNumInnerWidth + padding;
4887
+ display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
4888
+ display.lineGutter.style.width = display.lineNumWidth + "px";
4889
+ updateGutterSpace(cm);
4890
  return true
4891
  }
4892
  return false
4895
  // Read the actual heights of the rendered lines, and update their
4896
  // stored heights to match.
4897
  function updateHeightsInViewport(cm) {
4898
+ var display = cm.display;
4899
+ var prevBottom = display.lineDiv.offsetTop;
4900
  for (var i = 0; i < display.view.length; i++) {
4901
+ var cur = display.view[i], height = (void 0);
4902
  if (cur.hidden) { continue }
4903
  if (ie && ie_version < 8) {
4904
+ var bot = cur.node.offsetTop + cur.node.offsetHeight;
4905
+ height = bot - prevBottom;
4906
+ prevBottom = bot;
4907
  } else {
4908
+ var box = cur.node.getBoundingClientRect();
4909
+ height = box.bottom - box.top;
4910
  }
4911
+ var diff = cur.line.height - height;
4912
+ if (height < 2) { height = textHeight(display); }
4913
  if (diff > .001 || diff < -.001) {
4914
+ updateLineHeight(cur.line, height);
4915
+ updateWidgetHeight(cur.line);
4916
  if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
4917
+ { updateWidgetHeight(cur.rest[j]); } }
4918
  }
4919
  }
4920
  }
4923
  // given line.
4924
  function updateWidgetHeight(line) {
4925
  if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i)
4926
+ { line.widgets[i].height = line.widgets[i].node.parentNode.offsetHeight; } }
4927
  }
4928
 
4929
  // Compute the lines that are visible in a given viewport (defaults
4930
  // the the current scroll position). viewport may contain top,
4931
  // height, and ensure (see op.scrollToPos) properties.
4932
  function visibleLines(display, doc, viewport) {
4933
+ var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
4934
+ top = Math.floor(top - paddingTop(display));
4935
+ var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
4936
 
4937
+ var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
4938
  // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
4939
  // forces those lines into the viewport (if possible).
4940
  if (viewport && viewport.ensure) {
4941
+ var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
4942
  if (ensureFrom < from) {
4943
+ from = ensureFrom;
4944
+ to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
4945
  } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
4946
+ from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
4947
+ to = ensureTo;
4948
  }
4949
  }
4950
  return {from: from, to: Math.max(to, from + 1)}
4954
  // covers the visible area.
4955
  function setScrollTop(cm, val) {
4956
  if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
4957
+ cm.doc.scrollTop = val;
4958
+ if (!gecko) { updateDisplaySimple(cm, {top: val}); }
4959
+ if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val; }
4960
+ cm.display.scrollbars.setScrollTop(val);
4961
+ if (gecko) { updateDisplaySimple(cm); }
4962
+ startWorker(cm, 100);
4963
  }
4964
  // Sync scroller and scrollbar, ensure the gutter elements are
4965
  // aligned.
4966
  function setScrollLeft(cm, val, isScroller) {
4967
  if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) { return }
4968
+ val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
4969
+ cm.doc.scrollLeft = val;
4970
+ alignHorizontally(cm);
4971
+ if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val; }
4972
+ cm.display.scrollbars.setScrollLeft(val);
4973
  }
4974
 
4975
  // Since the delta values reported on mouse wheel events are
4989
  // know one. These don't have to be accurate -- the result of them
4990
  // being wrong would just be a slight flicker on the first wheel
4991
  // scroll (if it is large enough).
4992
+ if (ie) { wheelPixelsPerUnit = -.53; }
4993
+ else if (gecko) { wheelPixelsPerUnit = 15; }
4994
+ else if (chrome) { wheelPixelsPerUnit = -.7; }
4995
+ else if (safari) { wheelPixelsPerUnit = -1/3; }
4996
 
4997
  function wheelEventDelta(e) {
4998
+ var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
4999
+ if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail; }
5000
+ if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail; }
5001
+ else if (dy == null) { dy = e.wheelDelta; }
5002
  return {x: dx, y: dy}
5003
  }
5004
  function wheelEventPixels(e) {
5005
+ var delta = wheelEventDelta(e);
5006
+ delta.x *= wheelPixelsPerUnit;
5007
+ delta.y *= wheelPixelsPerUnit;
5008
  return delta
5009
  }
5010
 
5011
  function onScrollWheel(cm, e) {
5012
+ var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
5013
 
5014
+ var display = cm.display, scroll = display.scroller;
5015
  // Quit if there's nothing to scroll here
5016
+ var canScrollX = scroll.scrollWidth > scroll.clientWidth;
5017
+ var canScrollY = scroll.scrollHeight > scroll.clientHeight;
5018
  if (!(dx && canScrollX || dy && canScrollY)) { return }
5019
 
5020
  // Webkit browsers on OS X abort momentum scrolls when the target
5025
  outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
5026
  for (var i = 0; i < view.length; i++) {
5027
  if (view[i].node == cur) {
5028
+ cm.display.currentWheelTarget = cur;
5029
  break outer
5030
  }
5031
  }
5040
  // better than glitching out.
5041
  if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
5042
  if (dy && canScrollY)
5043
+ { setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight))); }
5044
+ setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
5045
  // Only prevent default scrolling if vertical scrolling is
5046
  // actually possible. Otherwise, it causes vertical scroll
5047
  // jitter on OSX trackpads when deltaX is small and deltaY
5048
  // is large (issue #3579)
5049
  if (!dy || (dy && canScrollY))
5050
+ { e_preventDefault(e); }
5051
+ display.wheelStartX = null; // Abort measurement, if in progress
5052
  return
5053
  }
5054
 
5055
  // 'Project' the visible viewport to cover the area that is being
5056
  // scrolled into view (if we know enough to estimate it).
5057
  if (dy && wheelPixelsPerUnit != null) {
5058
+ var pixels = dy * wheelPixelsPerUnit;
5059
+ var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
5060
+ if (pixels < 0) { top = Math.max(0, top + pixels - 50); }
5061
+ else { bot = Math.min(cm.doc.height, bot + pixels + 50); }
5062
+ updateDisplaySimple(cm, {top: top, bottom: bot});
5063
  }
5064
 
5065
  if (wheelSamples < 20) {
5066
  if (display.wheelStartX == null) {
5067
+ display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
5068
+ display.wheelDX = dx; display.wheelDY = dy;
5069
  setTimeout(function () {
5070
  if (display.wheelStartX == null) { return }
5071
+ var movedX = scroll.scrollLeft - display.wheelStartX;
5072
+ var movedY = scroll.scrollTop - display.wheelStartY;
5073
  var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
5074
+ (movedX && display.wheelDX && movedX / display.wheelDX);
5075
+ display.wheelStartX = display.wheelStartY = null;
5076
  if (!sample) { return }
5077
+ wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
5078
+ ++wheelSamples;
5079
+ }, 200);
5080
  } else {
5081
+ display.wheelDX += dx; display.wheelDY += dy;
5082
  }
5083
  }
5084
  }
5088
  // Prepare DOM reads needed to update the scrollbars. Done in one
5089
  // shot to minimize update/measure roundtrips.
5090
  function measureForScrollbars(cm) {
5091
+ var d = cm.display, gutterW = d.gutters.offsetWidth;
5092
+ var docH = Math.round(cm.doc.height + paddingVert(cm.display));
5093
  return {
5094
  clientHeight: d.scroller.clientHeight,
5095
  viewHeight: d.wrapper.clientHeight,
5104
  }
5105
 
5106
  var NativeScrollbars = function(place, scroll, cm) {
5107
+ this.cm = cm;
5108
+ var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
5109
+ var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
5110
+ place(vert); place(horiz);
5111
 
5112
  on(vert, "scroll", function () {
5113
+ if (vert.clientHeight) { scroll(vert.scrollTop, "vertical"); }
5114
+ });
5115
  on(horiz, "scroll", function () {
5116
+ if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal"); }
5117
+ });
5118
 
5119
+ this.checkedZeroWidth = false;
5120
  // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
5121
+ if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; }
5122
  };
5123
 
5124
  NativeScrollbars.prototype.update = function (measure) {
5125
+ var needsH = measure.scrollWidth > measure.clientWidth + 1;
5126
+ var needsV = measure.scrollHeight > measure.clientHeight + 1;
5127
+ var sWidth = measure.nativeBarWidth;
5128
 
5129
  if (needsV) {
5130
+ this.vert.style.display = "block";
5131
+ this.vert.style.bottom = needsH ? sWidth + "px" : "0";
5132
+ var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
5133
  // A bug in IE8 can cause this value to be negative, so guard it.
5134
  this.vert.firstChild.style.height =
5135
+ Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
5136
  } else {
5137
+ this.vert.style.display = "";
5138
+ this.vert.firstChild.style.height = "0";
5139
  }
5140
 
5141
  if (needsH) {
5142
+ this.horiz.style.display = "block";
5143
+ this.horiz.style.right = needsV ? sWidth + "px" : "0";
5144
+ this.horiz.style.left = measure.barLeft + "px";
5145
+ var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
5146
  this.horiz.firstChild.style.width =
5147
+ Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
5148
  } else {
5149
+ this.horiz.style.display = "";
5150
+ this.horiz.firstChild.style.width = "0";
5151
  }
5152
 
5153
  if (!this.checkedZeroWidth && measure.clientHeight > 0) {
5154
+ if (sWidth == 0) { this.zeroWidthHack(); }
5155
+ this.checkedZeroWidth = true;
5156
  }
5157
 
5158
  return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
5159
  };
5160
 
5161
  NativeScrollbars.prototype.setScrollLeft = function (pos) {
5162
+ if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos; }
5163
+ if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz); }
5164
  };
5165
 
5166
  NativeScrollbars.prototype.setScrollTop = function (pos) {
5167
+ if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos; }
5168
+ if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert); }
5169
  };
5170
 
5171
  NativeScrollbars.prototype.zeroWidthHack = function () {
5172
+ var w = mac && !mac_geMountainLion ? "12px" : "18px";
5173
+ this.horiz.style.height = this.vert.style.width = w;
5174
+ this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
5175
+ this.disableHoriz = new Delayed;
5176
+ this.disableVert = new Delayed;
5177
  };
5178
 
5179
  NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay) {
5180
+ bar.style.pointerEvents = "auto";
5181
  function maybeDisable() {
5182
  // To find out whether the scrollbar is still visible, we
5183
  // check whether the element under the pixel in the bottom
5185
  // itself (when the bar is still visible) or its filler child
5186
  // (when the bar is hidden). If it is still visible, we keep
5187
  // it enabled, if it's hidden, we disable pointer events.
5188
+ var box = bar.getBoundingClientRect();
5189
+ var elt$$1 = document.elementFromPoint(box.left + 1, box.bottom - 1);
5190
+ if (elt$$1 != bar) { bar.style.pointerEvents = "none"; }
5191
+ else { delay.set(1000, maybeDisable); }
5192
  }
5193
+ delay.set(1000, maybeDisable);
5194
  };
5195
 
5196
  NativeScrollbars.prototype.clear = function () {
5197
+ var parent = this.horiz.parentNode;
5198
+ parent.removeChild(this.horiz);
5199
+ parent.removeChild(this.vert);
5200
  };
5201
 
5202
  var NullScrollbars = function () {};
5207
  NullScrollbars.prototype.clear = function () {};
5208
 
5209
  function updateScrollbars(cm, measure) {
5210
+ if (!measure) { measure = measureForScrollbars(cm); }
5211
+ var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
5212
+ updateScrollbarsInner(cm, measure);
5213
  for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
5214
  if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
5215
+ { updateHeightsInViewport(cm); }
5216
+ updateScrollbarsInner(cm, measureForScrollbars(cm));
5217
+ startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
5218
  }
5219
  }
5220
 
5221
  // Re-synchronize the fake scrollbars with the actual size of the
5222
  // content.
5223
  function updateScrollbarsInner(cm, measure) {
5224
+ var d = cm.display;
5225
+ var sizes = d.scrollbars.update(measure);
5226
 
5227
+ d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
5228
+ d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
5229
+ d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
5230
 
5231
  if (sizes.right && sizes.bottom) {
5232
+ d.scrollbarFiller.style.display = "block";
5233
+ d.scrollbarFiller.style.height = sizes.bottom + "px";
5234
+ d.scrollbarFiller.style.width = sizes.right + "px";
5235
+ } else { d.scrollbarFiller.style.display = ""; }
5236
  if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
5237
+ d.gutterFiller.style.display = "block";
5238
+ d.gutterFiller.style.height = sizes.bottom + "px";
5239
+ d.gutterFiller.style.width = measure.gutterWidth + "px";
5240
+ } else { d.gutterFiller.style.display = ""; }
5241
  }
5242
 
5243
+ var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
5244
 
5245
  function initScrollbars(cm) {
5246
  if (cm.display.scrollbars) {
5247
+ cm.display.scrollbars.clear();
5248
  if (cm.display.scrollbars.addClass)
5249
+ { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
5250
  }
5251
 
5252
  cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
5253
+ cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
5254
  // Prevent clicks in the scrollbars from killing focus
5255
  on(node, "mousedown", function () {
5256
+ if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0); }
5257
+ });
5258
+ node.setAttribute("cm-not-content", "true");
5259
  }, function (pos, axis) {
5260
+ if (axis == "horizontal") { setScrollLeft(cm, pos); }
5261
+ else { setScrollTop(cm, pos); }
5262
+ }, cm);
5263
  if (cm.display.scrollbars.addClass)
5264
+ { addClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
5265
  }
5266
 
5267
  // SCROLLING THINGS INTO VIEW
5268
 
5269
  // If an editor sits on the top or bottom of the window, partially
5270
  // scrolled out of view, this ensures that the cursor is visible.
5271
+ function maybeScrollWindow(cm, rect) {
5272
  if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
5273
 
5274
+ var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
5275
+ if (rect.top + box.top < 0) { doScroll = true; }
5276
+ else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false; }
5277
  if (doScroll != null && !phantom) {
5278
+ var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;"));
5279
+ cm.display.lineSpace.appendChild(scrollNode);
5280
+ scrollNode.scrollIntoView(doScroll);
5281
+ cm.display.lineSpace.removeChild(scrollNode);
5282
  }
5283
  }
5284
 
5286
  // it actually became visible (as line heights are accurately
5287
  // measured, the position of something may 'drift' during drawing).
5288
  function scrollPosIntoView(cm, pos, end, margin) {
5289
+ if (margin == null) { margin = 0; }
5290
+ var rect;
5291
  for (var limit = 0; limit < 5; limit++) {
5292
+ var changed = false;
5293
+ var coords = cursorCoords(cm, pos);
5294
+ var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
5295
+ rect = {left: Math.min(coords.left, endCoords.left),
5296
+ top: Math.min(coords.top, endCoords.top) - margin,
5297
+ right: Math.max(coords.left, endCoords.left),
5298
+ bottom: Math.max(coords.bottom, endCoords.bottom) + margin};
5299
+ var scrollPos = calculateScrollPos(cm, rect);
5300
+ var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
5301
  if (scrollPos.scrollTop != null) {
5302
+ setScrollTop(cm, scrollPos.scrollTop);
5303
+ if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; }
5304
  }
5305
  if (scrollPos.scrollLeft != null) {
5306
+ setScrollLeft(cm, scrollPos.scrollLeft);
5307
+ if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; }
5308
  }
5309
  if (!changed) { break }
5310
  }
5311
+ return rect
5312
  }
5313
 
5314
  // Scroll a given set of coordinates into view (immediately).
5315
+ function scrollIntoView(cm, rect) {
5316
+ var scrollPos = calculateScrollPos(cm, rect);
5317
+ if (scrollPos.scrollTop != null) { setScrollTop(cm, scrollPos.scrollTop); }
5318
+ if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft); }
5319
  }
5320
 
5321
  // Calculate a new scroll position needed to scroll the given
5322
  // rectangle into view. Returns an object with scrollTop and
5323
  // scrollLeft properties. When these are undefined, the
5324
  // vertical/horizontal position does not need to be adjusted.
5325
+ function calculateScrollPos(cm, rect) {
5326
+ var display = cm.display, snapMargin = textHeight(cm.display);
5327
+ if (rect.top < 0) { rect.top = 0; }
5328
+ var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
5329
+ var screen = displayHeight(cm), result = {};
5330
+ if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; }
5331
+ var docBottom = cm.doc.height + paddingVert(display);
5332
+ var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin;
5333
+ if (rect.top < screentop) {
5334
+ result.scrollTop = atTop ? 0 : rect.top;
5335
+ } else if (rect.bottom > screentop + screen) {
5336
+ var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);
5337
+ if (newTop != screentop) { result.scrollTop = newTop; }
5338
+ }
5339
+
5340
+ var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
5341
+ var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
5342
+ var tooWide = rect.right - rect.left > screenw;
5343
+ if (tooWide) { rect.right = rect.left + screenw; }
5344
+ if (rect.left < 10)
5345
+ { result.scrollLeft = 0; }
5346
+ else if (rect.left < screenleft)
5347
+ { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)); }
5348
+ else if (rect.right > screenw + screenleft - 3)
5349
+ { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; }
5350
  return result
5351
  }
5352
 
5353
  // Store a relative adjustment to the scroll position in the current
5354
  // operation (to be applied when the operation finishes).
5355
  function addToScrollPos(cm, left, top) {
5356
+ if (left != null || top != null) { resolveScrollToPos(cm); }
5357
  if (left != null)
5358
+ { cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left; }
5359
  if (top != null)
5360
+ { cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top; }
5361
  }
5362
 
5363
  // Make sure that at the end of the operation the current cursor is
5364
  // shown.
5365
  function ensureCursorVisible(cm) {
5366
+ resolveScrollToPos(cm);
5367
+ var cur = cm.getCursor(), from = cur, to = cur;
5368
  if (!cm.options.lineWrapping) {
5369
+ from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur;
5370
+ to = Pos(cur.line, cur.ch + 1);
5371
  }
5372
+ cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin};
5373
  }
5374
 
5375
  // When an operation has its scrollToPos property set, and another
5377
  // 'simulates' scrolling that position into view in a cheap way, so
5378
  // that the effect of intermediate scroll commands is not ignored.
5379
  function resolveScrollToPos(cm) {
5380
+ var range$$1 = cm.curOp.scrollToPos;
5381
+ if (range$$1) {
5382
+ cm.curOp.scrollToPos = null;
5383
+ var from = estimateCoords(cm, range$$1.from), to = estimateCoords(cm, range$$1.to);
5384
+ var sPos = calculateScrollPos(cm, {
5385
+ left: Math.min(from.left, to.left),
5386
+ top: Math.min(from.top, to.top) - range$$1.margin,
5387
+ right: Math.max(from.right, to.right),
5388
+ bottom: Math.max(from.bottom, to.bottom) + range$$1.margin
5389
+ });
5390
+ cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
5391
  }
5392
  }
5393
 
5397
  // error-prone). Instead, display updates are batched and then all
5398
  // combined and executed at once.
5399
 
5400
+ var nextOpId = 0;
5401
  // Start a new operation.
5402
  function startOperation(cm) {
5403
  cm.curOp = {
5416
  scrollToPos: null, // Used to scroll to a specific position
5417
  focus: false,
5418
  id: ++nextOpId // Unique ID
5419
+ };
5420
+ pushOperation(cm.curOp);
5421
  }
5422
 
5423
  // Finish an operation, updating the display and signalling delayed events
5424
  function endOperation(cm) {
5425
+ var op = cm.curOp;
5426
  finishOperation(op, function (group) {
5427
  for (var i = 0; i < group.ops.length; i++)
5428
+ { group.ops[i].cm.curOp = null; }
5429
+ endOperations(group);
5430
+ });
5431
  }
5432
 
5433
  // The DOM updates done when an operation finishes are batched so
5434
  // that the minimum number of relayouts are required.
5435
  function endOperations(group) {
5436
+ var ops = group.ops;
5437
  for (var i = 0; i < ops.length; i++) // Read DOM
5438
+ { endOperation_R1(ops[i]); }
5439
  for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
5440
+ { endOperation_W1(ops[i$1]); }
5441
  for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
5442
+ { endOperation_R2(ops[i$2]); }
5443
  for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
5444
+ { endOperation_W2(ops[i$3]); }
5445
  for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
5446
+ { endOperation_finish(ops[i$4]); }
5447
  }
5448
 
5449
  function endOperation_R1(op) {
5450
+ var cm = op.cm, display = cm.display;
5451
+ maybeClipScrollbars(cm);
5452
+ if (op.updateMaxLine) { findMaxLine(cm); }
5453
 
5454
  op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
5455
  op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
5456
  op.scrollToPos.to.line >= display.viewTo) ||
5457
+ display.maxLineChanged && cm.options.lineWrapping;
5458
  op.update = op.mustUpdate &&
5459
+ new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
5460
  }
5461
 
5462
  function endOperation_W1(op) {
5463
+ op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
5464
  }
5465
 
5466
  function endOperation_R2(op) {
5467
+ var cm = op.cm, display = cm.display;
5468
+ if (op.updatedDisplay) { updateHeightsInViewport(cm); }
5469
 
5470
+ op.barMeasure = measureForScrollbars(cm);
5471
 
5472
  // If the max line changed since it was last measured, measure it,
5473
  // and ensure the document's width matches it.
5474
  // updateDisplay_W2 will use these properties to do the actual resizing
5475
  if (display.maxLineChanged && !cm.options.lineWrapping) {
5476
+ op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
5477
+ cm.display.sizerWidth = op.adjustWidthTo;
5478
  op.barMeasure.scrollWidth =
5479
+ Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
5480
+ op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
5481
  }
5482
 
5483
  if (op.updatedDisplay || op.selectionChanged)
5484
+ { op.preparedSelection = display.input.prepareSelection(op.focus); }
5485
  }
5486
 
5487
  function endOperation_W2(op) {
5488
+ var cm = op.cm;
5489
 
5490
  if (op.adjustWidthTo != null) {
5491
+ cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
5492
  if (op.maxScrollLeft < cm.doc.scrollLeft)
5493
+ { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); }
5494
+ cm.display.maxLineChanged = false;
5495
  }
5496
 
5497
+ var takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus());
5498
  if (op.preparedSelection)
5499
+ { cm.display.input.showSelection(op.preparedSelection, takeFocus); }
5500
  if (op.updatedDisplay || op.startHeight != cm.doc.height)
5501
+ { updateScrollbars(cm, op.barMeasure); }
5502
  if (op.updatedDisplay)
5503
+ { setDocumentHeight(cm, op.barMeasure); }
5504
 
5505
+ if (op.selectionChanged) { restartBlink(cm); }
5506
 
5507
  if (cm.state.focused && op.updateInput)
5508
+ { cm.display.input.reset(op.typing); }
5509
+ if (takeFocus) { ensureFocus(op.cm); }
5510
  }
5511
 
5512
  function endOperation_finish(op) {
5513
+ var cm = op.cm, display = cm.display, doc = cm.doc;
5514
 
5515
+ if (op.updatedDisplay) { postUpdateDisplay(cm, op.update); }
5516
 
5517
  // Abort mouse wheel delta measurement, when scrolling explicitly
5518
  if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
5519
+ { display.wheelStartX = display.wheelStartY = null; }
5520
 
5521
  // Propagate the scroll position to the actual DOM scroller
5522
  if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
5523
+ doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
5524
+ display.scrollbars.setScrollTop(doc.scrollTop);
5525
+ display.scroller.scrollTop = doc.scrollTop;
5526
  }
5527
  if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
5528
+ doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft));
5529
+ display.scrollbars.setScrollLeft(doc.scrollLeft);
5530
+ display.scroller.scrollLeft = doc.scrollLeft;
5531
+ alignHorizontally(cm);
5532
  }
5533
  // If we need to scroll a specific position into view, do so.
5534
  if (op.scrollToPos) {
5535
+ var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
5536
+ clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
5537
+ maybeScrollWindow(cm, rect);
5538
  }
5539
 
5540
  // Fire events for markers that are hidden/unidden by editing or
5541
  // undoing
5542
+ var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
5543
  if (hidden) { for (var i = 0; i < hidden.length; ++i)
5544
+ { if (!hidden[i].lines.length) { signal(hidden[i], "hide"); } } }
5545
  if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
5546
+ { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide"); } } }
5547
 
5548
  if (display.wrapper.offsetHeight)
5549
+ { doc.scrollTop = cm.display.scroller.scrollTop; }
5550
 
5551
  // Fire change events, and delayed event handlers
5552
  if (op.changeObjs)
5553
+ { signal(cm, "changes", cm, op.changeObjs); }
5554
  if (op.update)
5555
+ { op.update.finish(); }
5556
  }
5557
 
5558
  // Run the given function in an operation
5559
  function runInOp(cm, f) {
5560
  if (cm.curOp) { return f() }
5561
+ startOperation(cm);
5562
  try { return f() }
5563
+ finally { endOperation(cm); }
5564
  }
5565
  // Wraps a function in an operation. Returns the wrapped function.
5566
  function operation(cm, f) {
5567
  return function() {
5568
  if (cm.curOp) { return f.apply(cm, arguments) }
5569
+ startOperation(cm);
5570
  try { return f.apply(cm, arguments) }
5571
+ finally { endOperation(cm); }
5572
  }
5573
  }
5574
  // Used to add methods to editor and doc instances, wrapping them in
5576
  function methodOp(f) {
5577
  return function() {
5578
  if (this.curOp) { return f.apply(this, arguments) }
5579
+ startOperation(this);
5580
  try { return f.apply(this, arguments) }
5581
+ finally { endOperation(this); }
5582
  }
5583
  }
5584
  function docMethodOp(f) {
5585
  return function() {
5586
+ var cm = this.cm;
5587
  if (!cm || cm.curOp) { return f.apply(this, arguments) }
5588
+ startOperation(cm);
5589
  try { return f.apply(this, arguments) }
5590
+ finally { endOperation(cm); }
5591
  }
5592
  }
5593
 
5598
  // lines are divided into visual lines. regLineChange (below)
5599
  // registers single-line changes.
5600
  function regChange(cm, from, to, lendiff) {
5601
+ if (from == null) { from = cm.doc.first; }
5602
+ if (to == null) { to = cm.doc.first + cm.doc.size; }
5603
+ if (!lendiff) { lendiff = 0; }
5604
 
5605
+ var display = cm.display;
5606
  if (lendiff && to < display.viewTo &&
5607
  (display.updateLineNumbers == null || display.updateLineNumbers > from))
5608
+ { display.updateLineNumbers = from; }
5609
 
5610
+ cm.curOp.viewChanged = true;
5611
 
5612
  if (from >= display.viewTo) { // Change after
5613
  if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
5614
+ { resetView(cm); }
5615
  } else if (to <= display.viewFrom) { // Change before
5616
  if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
5617
+ resetView(cm);
5618
  } else {
5619
+ display.viewFrom += lendiff;
5620
+ display.viewTo += lendiff;
5621
  }
5622
  } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
5623
+ resetView(cm);
5624
  } else if (from <= display.viewFrom) { // Top overlap
5625
+ var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
5626
  if (cut) {
5627
+ display.view = display.view.slice(cut.index);
5628
+ display.viewFrom = cut.lineN;
5629
+ display.viewTo += lendiff;
5630
  } else {
5631
+ resetView(cm);
5632
  }
5633
  } else if (to >= display.viewTo) { // Bottom overlap
5634
+ var cut$1 = viewCuttingPoint(cm, from, from, -1);
5635
  if (cut$1) {
5636
+ display.view = display.view.slice(0, cut$1.index);
5637
+ display.viewTo = cut$1.lineN;
5638
  } else {
5639
+ resetView(cm);
5640
  }
5641
  } else { // Gap in the middle
5642
+ var cutTop = viewCuttingPoint(cm, from, from, -1);
5643
+ var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
5644
  if (cutTop && cutBot) {
5645
  display.view = display.view.slice(0, cutTop.index)
5646
  .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
5647
+ .concat(display.view.slice(cutBot.index));
5648
+ display.viewTo += lendiff;
5649
  } else {
5650
+ resetView(cm);
5651
  }
5652
  }
5653
 
5654
+ var ext = display.externalMeasured;
5655
  if (ext) {
5656
  if (to < ext.lineN)
5657
+ { ext.lineN += lendiff; }
5658
  else if (from < ext.lineN + ext.size)
5659
+ { display.externalMeasured = null; }
5660
  }
5661
  }
5662
 
5663
  // Register a change to a single line. Type must be one of "text",
5664
  // "gutter", "class", "widget"
5665
  function regLineChange(cm, line, type) {
5666
+ cm.curOp.viewChanged = true;
5667
+ var display = cm.display, ext = cm.display.externalMeasured;
5668
  if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
5669
+ { display.externalMeasured = null; }
5670
 
5671
  if (line < display.viewFrom || line >= display.viewTo) { return }
5672
+ var lineView = display.view[findViewIndex(cm, line)];
5673
  if (lineView.node == null) { return }
5674
+ var arr = lineView.changes || (lineView.changes = []);
5675
+ if (indexOf(arr, type) == -1) { arr.push(type); }
5676
  }
5677
 
5678
  // Clear the view.
5679
  function resetView(cm) {
5680
+ cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
5681
+ cm.display.view = [];
5682
+ cm.display.viewOffset = 0;
5683
  }
5684
 
5685
  function viewCuttingPoint(cm, oldN, newN, dir) {
5686
+ var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
5687
  if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
5688
  { return {index: index, lineN: newN} }
5689
+ var n = cm.display.viewFrom;
5690
  for (var i = 0; i < index; i++)
5691
+ { n += view[i].size; }
5692
  if (n != oldN) {
5693
  if (dir > 0) {
5694
  if (index == view.length - 1) { return null }
5695
+ diff = (n + view[index].size) - oldN;
5696
+ index++;
5697
  } else {
5698
+ diff = n - oldN;
5699
  }
5700
+ oldN += diff; newN += diff;
5701
  }
5702
  while (visualLineNo(cm.doc, newN) != newN) {
5703
  if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
5704
+ newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
5705
+ index += dir;
5706
  }
5707
  return {index: index, lineN: newN}
5708
  }
5710
  // Force the view to cover a given range, adding empty view element
5711
  // or clipping off existing ones as needed.
5712
  function adjustView(cm, from, to) {
5713
+ var display = cm.display, view = display.view;
5714
  if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
5715
+ display.view = buildViewArray(cm, from, to);
5716
+ display.viewFrom = from;
5717
  } else {
5718
  if (display.viewFrom > from)
5719
+ { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view); }
5720
  else if (display.viewFrom < from)
5721
+ { display.view = display.view.slice(findViewIndex(cm, from)); }
5722
+ display.viewFrom = from;
5723
  if (display.viewTo < to)
5724
+ { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)); }
5725
  else if (display.viewTo > to)
5726
+ { display.view = display.view.slice(0, findViewIndex(cm, to)); }
5727
  }
5728
+ display.viewTo = to;
5729
  }
5730
 
5731
  // Count the number of lines in the view whose DOM representation is
5732
  // out of date (or nonexistent).
5733
  function countDirtyView(cm) {
5734
+ var view = cm.display.view, dirty = 0;
5735
  for (var i = 0; i < view.length; i++) {
5736
+ var lineView = view[i];
5737
+ if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty; }
5738
  }
5739
  return dirty
5740
  }
5743
 
5744
  function startWorker(cm, time) {
5745
  if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
5746
+ { cm.state.highlight.set(time, bind(highlightWorker, cm)); }
5747
  }
5748
 
5749
  function highlightWorker(cm) {
5750
+ var doc = cm.doc;
5751
+ if (doc.frontier < doc.first) { doc.frontier = doc.first; }
5752
  if (doc.frontier >= cm.display.viewTo) { return }
5753
+ var end = +new Date + cm.options.workTime;
5754
+ var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
5755
+ var changedLines = [];
5756
 
5757
  doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
5758
  if (doc.frontier >= cm.display.viewFrom) { // Visible
5759
+ var oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength;
5760
+ var highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true);
5761
+ line.styles = highlighted.styles;
5762
+ var oldCls = line.styleClasses, newCls = highlighted.classes;
5763
+ if (newCls) { line.styleClasses = newCls; }
5764
+ else if (oldCls) { line.styleClasses = null; }
5765
  var ischange = !oldStyles || oldStyles.length != line.styles.length ||
5766
+ oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
5767
+ for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i]; }
5768
+ if (ischange) { changedLines.push(doc.frontier); }
5769
+ line.stateAfter = tooLong ? state : copyState(doc.mode, state);
5770
  } else {
5771
  if (line.text.length <= cm.options.maxHighlightLength)
5772
+ { processLine(cm, line.text, state); }
5773
+ line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
5774
  }
5775
+ ++doc.frontier;
5776
  if (+new Date > end) {
5777
+ startWorker(cm, cm.options.workDelay);
5778
  return true
5779
  }
5780
+ });
5781
  if (changedLines.length) { runInOp(cm, function () {
5782
  for (var i = 0; i < changedLines.length; i++)
5783
+ { regLineChange(cm, changedLines[i], "text"); }
5784
+ }); }
5785
  }
5786
 
5787
  // DISPLAY DRAWING
5788
 
5789
  var DisplayUpdate = function(cm, viewport, force) {
5790
+ var display = cm.display;
5791
 
5792
+ this.viewport = viewport;
5793
  // Store some values that we'll need later (but don't want to force a relayout for)
5794
+ this.visible = visibleLines(display, cm.doc, viewport);
5795
+ this.editorIsHidden = !display.wrapper.offsetWidth;
5796
+ this.wrapperHeight = display.wrapper.clientHeight;
5797
+ this.wrapperWidth = display.wrapper.clientWidth;
5798
+ this.oldDisplayWidth = displayWidth(cm);
5799
+ this.force = force;
5800
+ this.dims = getDimensions(cm);
5801
+ this.events = [];
5802
  };
5803
 
5804
  DisplayUpdate.prototype.signal = function (emitter, type) {
5805
  if (hasHandler(emitter, type))
5806
+ { this.events.push(arguments); }
5807
  };
5808
  DisplayUpdate.prototype.finish = function () {
5809
  var this$1 = this;
5810
 
5811
  for (var i = 0; i < this.events.length; i++)
5812
+ { signal.apply(null, this$1.events[i]); }
5813
  };
5814
 
5815
  function maybeClipScrollbars(cm) {
5816
+ var display = cm.display;
5817
  if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
5818
+ display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
5819
+ display.heightForcer.style.height = scrollGap(cm) + "px";
5820
+ display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
5821
+ display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
5822
+ display.scrollbarsClipped = true;
5823
  }
5824
  }
5825
 
5827
  // (returning false) when there is nothing to be done and forced is
5828
  // false.
5829
  function updateDisplayIfNeeded(cm, update) {
5830
+ var display = cm.display, doc = cm.doc;
5831
 
5832
  if (update.editorIsHidden) {
5833
+ resetView(cm);
5834
  return false
5835
  }
5836
 
5842
  { return false }
5843
 
5844
  if (maybeUpdateLineNumberWidth(cm)) {
5845
+ resetView(cm);
5846
+ update.dims = getDimensions(cm);
5847
  }
5848
 
5849
  // Compute a suitable new viewport (from & to)
5850
+ var end = doc.first + doc.size;
5851
+ var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
5852
+ var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
5853
+ if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); }
5854
+ if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); }
5855
  if (sawCollapsedSpans) {
5856
+ from = visualLineNo(cm.doc, from);
5857
+ to = visualLineEndNo(cm.doc, to);
5858
  }
5859
 
5860
  var different = from != display.viewFrom || to != display.viewTo ||
5861
+ display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
5862
+ adjustView(cm, from, to);
5863
 
5864
+ display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
5865
  // Position the mover div to align with the current scroll position
5866
+ cm.display.mover.style.top = display.viewOffset + "px";
5867
 
5868
+ var toUpdate = countDirtyView(cm);
5869
  if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
5870
  (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
5871
  { return false }
5872
 
5873
  // For big changes, we hide the enclosing element during the
5874
  // update, since that speeds up the operations on most browsers.
5875
+ var focused = activeElt();
5876
+ if (toUpdate > 4) { display.lineDiv.style.display = "none"; }
5877
+ patchDisplay(cm, display.updateLineNumbers, update.dims);
5878
+ if (toUpdate > 4) { display.lineDiv.style.display = ""; }
5879
+ display.renderedView = display.view;
5880
  // There might have been a widget with a focused element that got
5881
  // hidden or updated, if so re-focus it.
5882
+ if (focused && activeElt() != focused && focused.offsetHeight) { focused.focus(); }
5883
 
5884
  // Prevent selection and cursors from interfering with the scroll
5885
  // width and height.
5886
+ removeChildren(display.cursorDiv);
5887
+ removeChildren(display.selectionDiv);
5888
+ display.gutters.style.height = display.sizer.style.minHeight = 0;
5889
 
5890
  if (different) {
5891
+ display.lastWrapHeight = update.wrapperHeight;
5892
+ display.lastWrapWidth = update.wrapperWidth;
5893
+ startWorker(cm, 400);
5894
  }
5895
 
5896
+ display.updateLineNumbers = null;
5897
 
5898
  return true
5899
  }
5900
 
5901
  function postUpdateDisplay(cm, update) {
5902
+ var viewport = update.viewport;
5903
 
5904
  for (var first = true;; first = false) {
5905
  if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
5906
  // Clip forced viewport to actual scrollable area.
5907
  if (viewport && viewport.top != null)
5908
+ { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; }
5909
  // Updated line heights might result in the drawn area not
5910
  // actually covering the viewport. Keep looping until it does.
5911
+ update.visible = visibleLines(cm.display, cm.doc, viewport);
5912
  if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
5913
  { break }
5914
  }
5915
  if (!updateDisplayIfNeeded(cm, update)) { break }
5916
+ updateHeightsInViewport(cm);
5917
+ var barMeasure = measureForScrollbars(cm);
5918
+ updateSelection(cm);
5919
+ updateScrollbars(cm, barMeasure);
5920
+ setDocumentHeight(cm, barMeasure);
5921
  }
5922
 
5923
+ update.signal(cm, "update", cm);
5924
  if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
5925
+ update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
5926
+ cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
5927
  }
5928
  }
5929
 
5930
  function updateDisplaySimple(cm, viewport) {
5931
+ var update = new DisplayUpdate(cm, viewport);
5932
  if (updateDisplayIfNeeded(cm, update)) {
5933
+ updateHeightsInViewport(cm);
5934
+ postUpdateDisplay(cm, update);
5935
+ var barMeasure = measureForScrollbars(cm);
5936
+ updateSelection(cm);
5937
+ updateScrollbars(cm, barMeasure);
5938
+ setDocumentHeight(cm, barMeasure);
5939
+ update.finish();
5940
  }
5941
  }
5942
 
5945
  // that are not there yet, and updating the ones that are out of
5946
  // date.
5947
  function patchDisplay(cm, updateNumbersFrom, dims) {
5948
+ var display = cm.display, lineNumbers = cm.options.lineNumbers;
5949
+ var container = display.lineDiv, cur = container.firstChild;
5950
 
5951
  function rm(node) {
5952
+ var next = node.nextSibling;
5953
  // Works around a throw-scroll bug in OS X Webkit
5954
  if (webkit && mac && cm.display.currentWheelTarget == node)
5955
+ { node.style.display = "none"; }
5956
  else
5957
+ { node.parentNode.removeChild(node); }
5958
  return next
5959
  }
5960
 
5961
+ var view = display.view, lineN = display.viewFrom;
5962
  // Loop over the elements in the view, syncing cur (the DOM nodes
5963
  // in display.lineDiv) with the view as we go.
5964
  for (var i = 0; i < view.length; i++) {
5965
+ var lineView = view[i];
5966
  if (lineView.hidden) {
5967
  } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
5968
+ var node = buildLineElement(cm, lineView, lineN, dims);
5969
+ container.insertBefore(node, cur);
5970
  } else { // Already drawn
5971
+ while (cur != lineView.node) { cur = rm(cur); }
5972
  var updateNumber = lineNumbers && updateNumbersFrom != null &&
5973
+ updateNumbersFrom <= lineN && lineView.lineNumber;
5974
  if (lineView.changes) {
5975
+ if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false; }
5976
+ updateLineForChanges(cm, lineView, lineN, dims);
5977
  }
5978
  if (updateNumber) {
5979
+ removeChildren(lineView.lineNumber);
5980
+ lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
5981
  }
5982
+ cur = lineView.node.nextSibling;
5983
  }
5984
+ lineN += lineView.size;
5985
  }
5986
+ while (cur) { cur = rm(cur); }
5987
  }
5988
 
5989
  function updateGutterSpace(cm) {
5990
+ var width = cm.display.gutters.offsetWidth;
5991
+ cm.display.sizer.style.marginLeft = width + "px";
5992
  }
5993
 
5994
  function setDocumentHeight(cm, measure) {
5995
+ cm.display.sizer.style.minHeight = measure.docHeight + "px";
5996
+ cm.display.heightForcer.style.top = measure.docHeight + "px";
5997
+ cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px";
5998
  }
5999
 
6000
  // Rebuild the gutter elements, ensure the margin to the left of the
6001
  // code matches their width.
6002
  function updateGutters(cm) {
6003
+ var gutters = cm.display.gutters, specs = cm.options.gutters;
6004
+ removeChildren(gutters);
6005
+ var i = 0;
6006
  for (; i < specs.length; ++i) {
6007
+ var gutterClass = specs[i];
6008
+ var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
6009
  if (gutterClass == "CodeMirror-linenumbers") {
6010
+ cm.display.lineGutter = gElt;
6011
+ gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
6012
  }
6013
  }
6014
+ gutters.style.display = i ? "" : "none";
6015
+ updateGutterSpace(cm);
6016
  }
6017
 
6018
  // Make sure the gutters options contains the element
6019
  // "CodeMirror-linenumbers" when the lineNumbers option is true.
6020
  function setGuttersForLineNumbers(options) {
6021
+ var found = indexOf(options.gutters, "CodeMirror-linenumbers");
6022
  if (found == -1 && options.lineNumbers) {
6023
+ options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
6024
  } else if (found > -1 && !options.lineNumbers) {
6025
+ options.gutters = options.gutters.slice(0);
6026
+ options.gutters.splice(found, 1);
6027
  }
6028
  }
6029
 
6033
  // which one is the primary selection (the one that's scrolled into
6034
  // view, that getCursor returns, etc).
6035
  var Selection = function(ranges, primIndex) {
6036
+ this.ranges = ranges;
6037
+ this.primIndex = primIndex;
6038
  };
6039
 
6040
  Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
6045
  if (other == this) { return true }
6046
  if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
6047
  for (var i = 0; i < this.ranges.length; i++) {
6048
+ var here = this$1.ranges[i], there = other.ranges[i];
6049
  if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
6050
  }
6051
  return true
6054
  Selection.prototype.deepCopy = function () {
6055
  var this$1 = this;
6056
 
6057
+ var out = [];
6058
  for (var i = 0; i < this.ranges.length; i++)
6059
+ { out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)); }
6060
  return new Selection(out, this.primIndex)
6061
  };
6062
 
6071
  Selection.prototype.contains = function (pos, end) {
6072
  var this$1 = this;
6073
 
6074
+ if (!end) { end = pos; }
6075
  for (var i = 0; i < this.ranges.length; i++) {
6076
+ var range = this$1.ranges[i];
6077
  if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
6078
  { return i }
6079
  }
6081
  };
6082
 
6083
  var Range = function(anchor, head) {
6084
+ this.anchor = anchor; this.head = head;
6085
  };
6086
 
6087
  Range.prototype.from = function () { return minPos(this.anchor, this.head) };
6092
  // build a selection out of it. 'Consumes' ranges array (modifying
6093
  // it).
6094
  function normalizeSelection(ranges, primIndex) {
6095
+ var prim = ranges[primIndex];
6096
+ ranges.sort(function (a, b) { return cmp(a.from(), b.from()); });
6097
+ primIndex = indexOf(ranges, prim);
6098
  for (var i = 1; i < ranges.length; i++) {
6099
+ var cur = ranges[i], prev = ranges[i - 1];
6100
  if (cmp(prev.to(), cur.from()) >= 0) {
6101
+ var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
6102
+ var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
6103
+ if (i <= primIndex) { --primIndex; }
6104
+ ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
6105
  }
6106
  }
6107
  return new Selection(ranges, primIndex)
6125
  if (cmp(pos, change.from) < 0) { return pos }
6126
  if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
6127
 
6128
+ var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
6129
+ if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; }
6130
  return Pos(line, ch)
6131
  }
6132
 
6133
  function computeSelAfterChange(doc, change) {
6134
+ var out = [];
6135
  for (var i = 0; i < doc.sel.ranges.length; i++) {
6136
+ var range = doc.sel.ranges[i];
6137
  out.push(new Range(adjustForChange(range.anchor, change),
6138
+ adjustForChange(range.head, change)));
6139
  }
6140
  return normalizeSelection(out, doc.sel.primIndex)
6141
  }
6150
  // Used by replaceSelections to allow moving the selection to the
6151
  // start or around the replaced test. Hint may be "start" or "around".
6152
  function computeReplacedSel(doc, changes, hint) {
6153
+ var out = [];
6154
+ var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
6155
  for (var i = 0; i < changes.length; i++) {
6156
+ var change = changes[i];
6157
+ var from = offsetPos(change.from, oldPrev, newPrev);
6158
+ var to = offsetPos(changeEnd(change), oldPrev, newPrev);
6159
+ oldPrev = change.to;
6160
+ newPrev = to;
6161
  if (hint == "around") {
6162
+ var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
6163
+ out[i] = new Range(inv ? to : from, inv ? from : to);
6164
  } else {
6165
+ out[i] = new Range(from, from);
6166
  }
6167
  }
6168
  return new Selection(out, doc.sel.primIndex)
6171
  // Used to get the editor into a consistent state again when options change.
6172
 
6173
  function loadMode(cm) {
6174
+ cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
6175
+ resetModeState(cm);
6176
  }
6177
 
6178
  function resetModeState(cm) {
6179
  cm.doc.iter(function (line) {
6180
+ if (line.stateAfter) { line.stateAfter = null; }
6181
+ if (line.styles) { line.styles = null; }
6182
+ });
6183
+ cm.doc.frontier = cm.doc.first;
6184
+ startWorker(cm, 100);
6185
+ cm.state.modeGen++;
6186
+ if (cm.curOp) { regChange(cm); }
6187
  }
6188
 
6189
  // DOCUMENT DATA STRUCTURE
6197
  }
6198
 
6199
  // Perform a change on the document data structure.
6200
+ function updateDoc(doc, change, markedSpans, estimateHeight$$1) {
6201
  function spansFor(n) {return markedSpans ? markedSpans[n] : null}
6202
  function update(line, text, spans) {
6203
+ updateLine(line, text, spans, estimateHeight$$1);
6204
+ signalLater(line, "change", line, change);
6205
  }
6206
  function linesFor(start, end) {
6207
+ var result = [];
6208
  for (var i = start; i < end; ++i)
6209
+ { result.push(new Line(text[i], spansFor(i), estimateHeight$$1)); }
6210
  return result
6211
  }
6212
 
6213
+ var from = change.from, to = change.to, text = change.text;
6214
+ var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
6215
+ var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
6216
 
6217
  // Adjust the line structure
6218
  if (change.full) {
6219
+ doc.insert(0, linesFor(0, text.length));
6220
+ doc.remove(text.length, doc.size - text.length);
6221
  } else if (isWholeLineUpdate(doc, change)) {
6222
  // This is a whole-line replace. Treated specially to make
6223
  // sure line objects move the way they are supposed to.
6224
+ var added = linesFor(0, text.length - 1);
6225
+ update(lastLine, lastLine.text, lastSpans);
6226
+ if (nlines) { doc.remove(from.line, nlines); }
6227
+ if (added.length) { doc.insert(from.line, added); }
6228
  } else if (firstLine == lastLine) {
6229
  if (text.length == 1) {
6230
+ update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
6231
  } else {
6232
+ var added$1 = linesFor(1, text.length - 1);
6233
+ added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight$$1));
6234
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
6235
+ doc.insert(from.line + 1, added$1);
6236
  }
6237
  } else if (text.length == 1) {
6238
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
6239
+ doc.remove(from.line + 1, nlines);
6240
  } else {
6241
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
6242
+ update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
6243
+ var added$2 = linesFor(1, text.length - 1);
6244
+ if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); }
6245
+ doc.insert(from.line + 1, added$2);
6246
  }
6247
 
6248
+ signalLater(doc, "change", doc, change);
6249
  }
6250
 
6251
  // Call f for all linked documents.
6252
  function linkedDocs(doc, f, sharedHistOnly) {
6253
  function propagate(doc, skip, sharedHist) {
6254
  if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
6255
+ var rel = doc.linked[i];
6256
  if (rel.doc == skip) { continue }
6257
+ var shared = sharedHist && rel.sharedHist;
6258
  if (sharedHistOnly && !shared) { continue }
6259
+ f(rel.doc, shared);
6260
+ propagate(rel.doc, doc, shared);
6261
  } }
6262
  }
6263
+ propagate(doc, null, true);
6264
  }
6265
 
6266
  // Attach a document to an editor.
6267
  function attachDoc(cm, doc) {
6268
  if (doc.cm) { throw new Error("This document is already in use.") }
6269
+ cm.doc = doc;
6270
+ doc.cm = cm;
6271
+ estimateLineHeights(cm);
6272
+ loadMode(cm);
6273
+ setDirectionClass(cm);
6274
+ if (!cm.options.lineWrapping) { findMaxLine(cm); }
6275
+ cm.options.mode = doc.modeOption;
6276
+ regChange(cm);
6277
+ }
6278
+
6279
+ function setDirectionClass(cm) {
6280
+ (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
6281
+ }
6282
+
6283
+ function directionChanged(cm) {
6284
+ runInOp(cm, function () {
6285
+ setDirectionClass(cm);
6286
+ regChange(cm);
6287
+ });
6288
  }
6289
 
6290
  function History(startGen) {
6291
  // Arrays of change events and selections. Doing something adds an
6292
  // event to done and clears undo. Undoing moves events from done
6293
  // to undone, redoing moves them in the other direction.
6294
+ this.done = []; this.undone = [];
6295
+ this.undoDepth = Infinity;
6296
  // Used to track when changes can be merged into a single undo
6297
  // event
6298
+ this.lastModTime = this.lastSelTime = 0;
6299
+ this.lastOp = this.lastSelOp = null;
6300
+ this.lastOrigin = this.lastSelOrigin = null;
6301
  // Used by the isClean() method
6302
+ this.generation = this.maxGeneration = startGen || 1;
6303
  }
6304
 
6305
  // Create a history change event from an updateDoc-style change
6306
  // object.
6307
  function historyChangeFromChange(doc, change) {
6308
+ var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
6309
+ attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
6310
+ linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true);
6311
  return histChange
6312
  }
6313
 
6315
  // a change event.
6316
  function clearSelectionEvents(array) {
6317
  while (array.length) {
6318
+ var last = lst(array);
6319
+ if (last.ranges) { array.pop(); }
6320
  else { break }
6321
  }
6322
  }
6325
  // events that are in the way.
6326
  function lastChangeEvent(hist, force) {
6327
  if (force) {
6328
+ clearSelectionEvents(hist.done);
6329
  return lst(hist.done)
6330
  } else if (hist.done.length && !lst(hist.done).ranges) {
6331
  return lst(hist.done)
6332
  } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
6333
+ hist.done.pop();
6334
  return lst(hist.done)
6335
  }
6336
  }
6339
  // a single operation, or are close together with an origin that
6340
  // allows merging (starting with "+") into a single event.
6341
  function addChangeToHistory(doc, change, selAfter, opId) {
6342
+ var hist = doc.history;
6343
+ hist.undone.length = 0;
6344
+ var time = +new Date, cur;
6345
+ var last;
6346
 
6347
  if ((hist.lastOp == opId ||
6348
  hist.lastOrigin == change.origin && change.origin &&
6350
  change.origin.charAt(0) == "*")) &&
6351
  (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
6352
  // Merge this change into the last event
6353
+ last = lst(cur.changes);
6354
  if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
6355
  // Optimized case for simple insertion -- don't want to add
6356
  // new changesets for every character typed
6357
+ last.to = changeEnd(change);
6358
  } else {
6359
  // Add new sub-event
6360
+ cur.changes.push(historyChangeFromChange(doc, change));
6361
  }
6362
  } else {
6363
  // Can not be merged, start a new event.
6364
+ var before = lst(hist.done);
6365
  if (!before || !before.ranges)
6366
+ { pushSelectionToHistory(doc.sel, hist.done); }
6367
  cur = {changes: [historyChangeFromChange(doc, change)],
6368
+ generation: hist.generation};
6369
+ hist.done.push(cur);
6370
  while (hist.done.length > hist.undoDepth) {
6371
+ hist.done.shift();
6372
+ if (!hist.done[0].ranges) { hist.done.shift(); }
6373
  }
6374
  }
6375
+ hist.done.push(selAfter);
6376
+ hist.generation = ++hist.maxGeneration;
6377
+ hist.lastModTime = hist.lastSelTime = time;
6378
+ hist.lastOp = hist.lastSelOp = opId;
6379
+ hist.lastOrigin = hist.lastSelOrigin = change.origin;
6380
 
6381
+ if (!last) { signal(doc, "historyAdded"); }
6382
  }
6383
 
6384
  function selectionEventCanBeMerged(doc, origin, prev, sel) {
6385
+ var ch = origin.charAt(0);
6386
  return ch == "*" ||
6387
  ch == "+" &&
6388
  prev.ranges.length == sel.ranges.length &&
6395
  // selection into the 'done' array when it was significantly
6396
  // different (in number of selected ranges, emptiness, or time).
6397
  function addSelectionToHistory(doc, sel, opId, options) {
6398
+ var hist = doc.history, origin = options && options.origin;
6399
 
6400
  // A new event is started when the previous origin does not match
6401
  // the current, or the origins don't allow matching. Origins
6405
  (origin && hist.lastSelOrigin == origin &&
6406
  (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
6407
  selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
6408
+ { hist.done[hist.done.length - 1] = sel; }
6409
  else
6410
+ { pushSelectionToHistory(sel, hist.done); }
6411
 
6412
+ hist.lastSelTime = +new Date;
6413
+ hist.lastSelOrigin = origin;
6414
+ hist.lastSelOp = opId;
6415
  if (options && options.clearRedo !== false)
6416
+ { clearSelectionEvents(hist.undone); }
6417
  }
6418
 
6419
  function pushSelectionToHistory(sel, dest) {
6420
+ var top = lst(dest);
6421
  if (!(top && top.ranges && top.equals(sel)))
6422
+ { dest.push(sel); }
6423
  }
6424
 
6425
  // Used to store marked span information in the history.
6426
  function attachLocalSpans(doc, change, from, to) {
6427
+ var existing = change["spans_" + doc.id], n = 0;
6428
  doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
6429
  if (line.markedSpans)
6430
+ { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; }
6431
+ ++n;
6432
+ });
6433
  }
6434
 
6435
  // When un/re-doing restores text containing marked spans, those
6436
  // that have been explicitly cleared should not be restored.
6437
  function removeClearedSpans(spans) {
6438
  if (!spans) { return null }
6439
+ var out;
6440
  for (var i = 0; i < spans.length; ++i) {
6441
+ if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } }
6442
+ else if (out) { out.push(spans[i]); }
6443
  }
6444
  return !out ? spans : out.length ? out : null
6445
  }
6446
 
6447
  // Retrieve and filter the old marked spans stored in a change event.
6448
  function getOldSpans(doc, change) {
6449
+ var found = change["spans_" + doc.id];
6450
  if (!found) { return null }
6451
+ var nw = [];
6452
  for (var i = 0; i < change.text.length; ++i)
6453
+ { nw.push(removeClearedSpans(found[i])); }
6454
  return nw
6455
  }
6456
 
6459
  // existed in the history (so that deleting around a span and then
6460
  // undoing brings back the span).
6461
  function mergeOldSpans(doc, change) {
6462
+ var old = getOldSpans(doc, change);
6463
+ var stretched = stretchSpansOverChange(doc, change);
6464
  if (!old) { return stretched }
6465
  if (!stretched) { return old }
6466
 
6467
  for (var i = 0; i < old.length; ++i) {
6468
+ var oldCur = old[i], stretchCur = stretched[i];
6469
  if (oldCur && stretchCur) {
6470
  spans: for (var j = 0; j < stretchCur.length; ++j) {
6471
+ var span = stretchCur[j];
6472
  for (var k = 0; k < oldCur.length; ++k)
6473
  { if (oldCur[k].marker == span.marker) { continue spans } }
6474
+ oldCur.push(span);
6475
  }
6476
  } else if (stretchCur) {
6477
+ old[i] = stretchCur;
6478
  }
6479
  }
6480
  return old
6483
  // Used both to provide a JSON-safe object in .getHistory, and, when
6484
  // detaching a document, to split the history in two
6485
  function copyHistoryArray(events, newGroup, instantiateSel) {
6486
+ var copy = [];
6487
  for (var i = 0; i < events.length; ++i) {
6488
+ var event = events[i];
6489
  if (event.ranges) {
6490
+ copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
6491
  continue
6492
  }
6493
+ var changes = event.changes, newChanges = [];
6494
+ copy.push({changes: newChanges});
6495
  for (var j = 0; j < changes.length; ++j) {
6496
+ var change = changes[j], m = (void 0);
6497
+ newChanges.push({from: change.from, to: change.to, text: change.text});
6498
  if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
6499
  if (indexOf(newGroup, Number(m[1])) > -1) {
6500
+ lst(newChanges)[prop] = change[prop];
6501
+ delete change[prop];
6502
  }
6503
  } } }
6504
  }
6516
  // Used for cursor motion and such.
6517
  function extendRange(doc, range, head, other) {
6518
  if (doc.cm && doc.cm.display.shift || doc.extend) {
6519
+ var anchor = range.anchor;
6520
  if (other) {
6521
+ var posBefore = cmp(head, anchor) < 0;
6522
  if (posBefore != (cmp(other, anchor) < 0)) {
6523
+ anchor = head;
6524
+ head = other;
6525
  } else if (posBefore != (cmp(head, other) < 0)) {
6526
+ head = other;
6527
  }
6528
  }
6529
  return new Range(anchor, head)
6534
 
6535
  // Extend the primary selection range, discard the rest.
6536
  function extendSelection(doc, head, other, options) {
6537
+ setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options);
6538
  }
6539
 
6540
  // Extend all selections (pos is an array of selections with length
6541
  // equal the number of selections)
6542
  function extendSelections(doc, heads, options) {
6543
+ var out = [];
6544
  for (var i = 0; i < doc.sel.ranges.length; i++)
6545
+ { out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null); }
6546
+ var newSel = normalizeSelection(out, doc.sel.primIndex);
6547
+ setSelection(doc, newSel, options);
6548
  }
6549
 
6550
  // Updates a single range in the selection.
6551
  function replaceOneSelection(doc, i, range, options) {
6552
+ var ranges = doc.sel.ranges.slice(0);
6553
+ ranges[i] = range;
6554
+ setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
6555
  }
6556
 
6557
  // Reset the selection to a single range.
6558
  function setSimpleSelection(doc, anchor, head, options) {
6559
+ setSelection(doc, simpleSelection(anchor, head), options);
6560
  }
6561
 
6562
  // Give beforeSelectionChange handlers a change to influence a
6567
  update: function(ranges) {
6568
  var this$1 = this;
6569
 
6570
+ this.ranges = [];
6571
  for (var i = 0; i < ranges.length; i++)
6572
  { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
6573
+ clipPos(doc, ranges[i].head)); }
6574
  },
6575
  origin: options && options.origin
6576
+ };
6577
+ signal(doc, "beforeSelectionChange", doc, obj);
6578
+ if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); }
6579
  if (obj.ranges != sel.ranges) { return normalizeSelection(obj.ranges, obj.ranges.length - 1) }
6580
  else { return sel }
6581
  }
6582
 
6583
  function setSelectionReplaceHistory(doc, sel, options) {
6584
+ var done = doc.history.done, last = lst(done);
6585
  if (last && last.ranges) {
6586
+ done[done.length - 1] = sel;
6587
+ setSelectionNoUndo(doc, sel, options);
6588
  } else {
6589
+ setSelection(doc, sel, options);
6590
  }
6591
  }
6592
 
6593
  // Set a new selection.
6594
  function setSelection(doc, sel, options) {
6595
+ setSelectionNoUndo(doc, sel, options);
6596
+ addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
6597
  }
6598
 
6599
  function setSelectionNoUndo(doc, sel, options) {
6600
  if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
6601
+ { sel = filterSelectionChange(doc, sel, options); }
6602
 
6603
  var bias = options && options.bias ||
6604
+ (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
6605
+ setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
6606
 
6607
  if (!(options && options.scroll === false) && doc.cm)
6608
+ { ensureCursorVisible(doc.cm); }
6609
  }
6610
 
6611
  function setSelectionInner(doc, sel) {
6612
  if (sel.equals(doc.sel)) { return }
6613
 
6614
+ doc.sel = sel;
6615
 
6616
  if (doc.cm) {
6617
+ doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
6618
+ signalCursorActivity(doc.cm);
6619
  }
6620
+ signalLater(doc, "cursorActivity", doc);
6621
  }
6622
 
6623
  // Verify that the selection does not partially select any atomic
6624
  // marked ranges.
6625
  function reCheckSelection(doc) {
6626
+ setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll);
6627
  }
6628
 
6629
  // Return a selection that does not partially select any atomic
6630
  // ranges.
6631
  function skipAtomicInSelection(doc, sel, bias, mayClear) {
6632
+ var out;
6633
  for (var i = 0; i < sel.ranges.length; i++) {
6634
+ var range = sel.ranges[i];
6635
+ var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
6636
+ var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
6637
+ var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
6638
  if (out || newAnchor != range.anchor || newHead != range.head) {
6639
+ if (!out) { out = sel.ranges.slice(0, i); }
6640
+ out[i] = new Range(newAnchor, newHead);
6641
  }
6642
  }
6643
  return out ? normalizeSelection(out, sel.primIndex) : sel
6644
  }
6645
 
6646
  function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
6647
+ var line = getLine(doc, pos.line);
6648
  if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
6649
+ var sp = line.markedSpans[i], m = sp.marker;
6650
  if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
6651
  (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
6652
  if (mayClear) {
6653
+ signal(m, "beforeCursorEnter");
6654
  if (m.explicitlyCleared) {
6655
  if (!line.markedSpans) { break }
6656
  else {--i; continue}
6659
  if (!m.atomic) { continue }
6660
 
6661
  if (oldPos) {
6662
+ var near = m.find(dir < 0 ? 1 : -1), diff = (void 0);
6663
  if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
6664
+ { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); }
6665
  if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
6666
  { return skipAtomicInner(doc, near, pos, dir, mayClear) }
6667
  }
6668
 
6669
+ var far = m.find(dir < 0 ? -1 : 1);
6670
  if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight)
6671
+ { far = movePos(doc, far, dir, far.line == pos.line ? line : null); }
6672
  return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
6673
  }
6674
  } }
6677
 
6678
  // Ensure a given position is not inside an atomic range.
6679
  function skipAtomic(doc, pos, oldPos, bias, mayClear) {
6680
+ var dir = bias || 1;
6681
  var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
6682
  (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
6683
  skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
6684
+ (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true));
6685
  if (!found) {
6686
+ doc.cantEdit = true;
6687
  return Pos(doc.first, 0)
6688
  }
6689
  return found
6702
  }
6703
 
6704
  function selectAll(cm) {
6705
+ cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
6706
  }
6707
 
6708
  // UPDATING
6716
  text: change.text,
6717
  origin: change.origin,
6718
  cancel: function () { return obj.canceled = true; }
6719
+ };
6720
  if (update) { obj.update = function (from, to, text, origin) {
6721
+ if (from) { obj.from = clipPos(doc, from); }
6722
+ if (to) { obj.to = clipPos(doc, to); }
6723
+ if (text) { obj.text = text; }
6724
+ if (origin !== undefined) { obj.origin = origin; }
6725
+ }; }
6726
+ signal(doc, "beforeChange", doc, obj);
6727
+ if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); }
6728
 
6729
  if (obj.canceled) { return null }
6730
  return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
6739
  }
6740
 
6741
  if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
6742
+ change = filterChange(doc, change, true);
6743
  if (!change) { return }
6744
  }
6745
 
6746
  // Possibly split or suppress the update based on the presence
6747
  // of read-only spans in its range.
6748
+ var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
6749
  if (split) {
6750
  for (var i = split.length - 1; i >= 0; --i)
6751
+ { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text}); }
6752
  } else {
6753
+ makeChangeInner(doc, change);
6754
  }
6755
  }
6756
 
6757
  function makeChangeInner(doc, change) {
6758
  if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
6759
+ var selAfter = computeSelAfterChange(doc, change);
6760
+ addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
6761
 
6762
+ makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
6763
+ var rebased = [];
6764
 
6765
  linkedDocs(doc, function (doc, sharedHist) {
6766
  if (!sharedHist && indexOf(rebased, doc.history) == -1) {
6767
+ rebaseHist(doc.history, change);
6768
+ rebased.push(doc.history);
6769
  }
6770
+ makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
6771
+ });
6772
  }
6773
 
6774
  // Revert a change stored in a document's history.
6775
  function makeChangeFromHistory(doc, type, allowSelectionOnly) {
6776
  if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) { return }
6777
 
6778
+ var hist = doc.history, event, selAfter = doc.sel;
6779
+ var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
6780
 
6781
  // Verify that there is a useable event (so that ctrl-z won't
6782
  // needlessly clear selection events)
6783
+ var i = 0;
6784
  for (; i < source.length; i++) {
6785
+ event = source[i];
6786
  if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
6787
  { break }
6788
  }
6789
  if (i == source.length) { return }
6790
+ hist.lastOrigin = hist.lastSelOrigin = null;
6791
 
6792
  for (;;) {
6793
+ event = source.pop();
6794
  if (event.ranges) {
6795
+ pushSelectionToHistory(event, dest);
6796
  if (allowSelectionOnly && !event.equals(doc.sel)) {
6797
+ setSelection(doc, event, {clearRedo: false});
6798
  return
6799
  }
6800
+ selAfter = event;
6801
  }
6802
  else { break }
6803
  }
6804
 
6805
  // Build up a reverse change object to add to the opposite history
6806
  // stack (redo when undoing, and vice versa).
6807
+ var antiChanges = [];
6808
+ pushSelectionToHistory(selAfter, dest);
6809
+ dest.push({changes: antiChanges, generation: hist.generation});
6810
+ hist.generation = event.generation || ++hist.maxGeneration;
6811
 
6812
+ var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
6813
 
6814
  var loop = function ( i ) {
6815
+ var change = event.changes[i];
6816
+ change.origin = type;
6817
  if (filter && !filterChange(doc, change, false)) {
6818
+ source.length = 0;
6819
  return {}
6820
  }
6821
 
6822
+ antiChanges.push(historyChangeFromChange(doc, change));
6823
 
6824
+ var after = i ? computeSelAfterChange(doc, change) : lst(source);
6825
+ makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
6826
+ if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); }
6827
+ var rebased = [];
6828
 
6829
  // Propagate to the linked documents
6830
  linkedDocs(doc, function (doc, sharedHist) {
6831
  if (!sharedHist && indexOf(rebased, doc.history) == -1) {
6832
+ rebaseHist(doc.history, change);
6833
+ rebased.push(doc.history);
6834
  }
6835
+ makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
6836
+ });
6837
  };
6838
 
6839
  for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
6847
  // above or below them in the parent document.
6848
  function shiftDoc(doc, distance) {
6849
  if (distance == 0) { return }
6850
+ doc.first += distance;
6851
  doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
6852
  Pos(range.anchor.line + distance, range.anchor.ch),
6853
  Pos(range.head.line + distance, range.head.ch)
6854
+ ); }), doc.sel.primIndex);
6855
  if (doc.cm) {
6856
+ regChange(doc.cm, doc.first, doc.first - distance, distance);
6857
  for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
6858
+ { regLineChange(doc.cm, l, "gutter"); }
6859
  }
6860
  }
6861
 
6866
  { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
6867
 
6868
  if (change.to.line < doc.first) {
6869
+ shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
6870
  return
6871
  }
6872
  if (change.from.line > doc.lastLine()) { return }
6873
 
6874
  // Clip the change to the size of this doc
6875
  if (change.from.line < doc.first) {
6876
+ var shift = change.text.length - 1 - (doc.first - change.from.line);
6877
+ shiftDoc(doc, shift);
6878
  change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
6879
+ text: [lst(change.text)], origin: change.origin};
6880
  }
6881
+ var last = doc.lastLine();
6882
  if (change.to.line > last) {
6883
  change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
6884
+ text: [change.text[0]], origin: change.origin};
6885
  }
6886
 
6887
+ change.removed = getBetween(doc, change.from, change.to);
6888
 
6889
+ if (!selAfter) { selAfter = computeSelAfterChange(doc, change); }
6890
+ if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); }
6891
+ else { updateDoc(doc, change, spans); }
6892
+ setSelectionNoUndo(doc, selAfter, sel_dontScroll);
6893
  }
6894
 
6895
  // Handle the interaction of a change to a document with the editor
6896
  // that this document is part of.
6897
  function makeChangeSingleDocInEditor(cm, change, spans) {
6898
+ var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
6899
 
6900
+ var recomputeMaxLength = false, checkWidthStart = from.line;
6901
  if (!cm.options.lineWrapping) {
6902
+ checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
6903
  doc.iter(checkWidthStart, to.line + 1, function (line) {
6904
  if (line == display.maxLine) {
6905
+ recomputeMaxLength = true;
6906
  return true
6907
  }
6908
+ });
6909
  }
6910
 
6911
  if (doc.sel.contains(change.from, change.to) > -1)
6912
+ { signalCursorActivity(cm); }
6913
 
6914
+ updateDoc(doc, change, spans, estimateHeight(cm));
6915
 
6916
  if (!cm.options.lineWrapping) {
6917
  doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
6918
+ var len = lineLength(line);
6919
  if (len > display.maxLineLength) {
6920
+ display.maxLine = line;
6921
+ display.maxLineLength = len;
6922
+ display.maxLineChanged = true;
6923
+ recomputeMaxLength = false;
6924
  }
6925
+ });
6926
+ if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; }
6927
  }
6928
 
6929
  // Adjust frontier, schedule worker
6930
+ doc.frontier = Math.min(doc.frontier, from.line);
6931
+ startWorker(cm, 400);
6932
 
6933
+ var lendiff = change.text.length - (to.line - from.line) - 1;
6934
  // Remember that these lines changed, for updating the display
6935
  if (change.full)
6936
+ { regChange(cm); }
6937
  else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
6938
+ { regLineChange(cm, from.line, "text"); }
6939
  else
6940
+ { regChange(cm, from.line, to.line + 1, lendiff); }
6941
 
6942
+ var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
6943
  if (changeHandler || changesHandler) {
6944
  var obj = {
6945
  from: from, to: to,
6946
  text: change.text,
6947
  removed: change.removed,
6948
  origin: change.origin
6949
+ };
6950
+ if (changeHandler) { signalLater(cm, "change", cm, obj); }
6951
+ if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); }
6952
  }
6953
+ cm.display.selForContextMenu = null;
6954
  }
6955
 
6956
  function replaceRange(doc, code, from, to, origin) {
6957
+ if (!to) { to = from; }
6958
+ if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; }
6959
+ if (typeof code == "string") { code = doc.splitLines(code); }
6960
+ makeChange(doc, {from: from, to: to, text: code, origin: origin});
6961
  }
6962
 
6963
  // Rebasing/resetting history to deal with externally-sourced changes
6964
 
6965
  function rebaseHistSelSingle(pos, from, to, diff) {
6966
  if (to < pos.line) {
6967
+ pos.line += diff;
6968
  } else if (from < pos.line) {
6969
+ pos.line = from;
6970
+ pos.ch = 0;
6971
  }
6972
  }
6973
 
6980
  // shared position objects being unsafely updated.
6981
  function rebaseHistArray(array, from, to, diff) {
6982
  for (var i = 0; i < array.length; ++i) {
6983
+ var sub = array[i], ok = true;
6984
  if (sub.ranges) {
6985
+ if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
6986
  for (var j = 0; j < sub.ranges.length; j++) {
6987
+ rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
6988
+ rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
6989
  }
6990
  continue
6991
  }
6992
  for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
6993
+ var cur = sub.changes[j$1];
6994
  if (to < cur.from.line) {
6995
+ cur.from = Pos(cur.from.line + diff, cur.from.ch);
6996
+ cur.to = Pos(cur.to.line + diff, cur.to.ch);
6997
  } else if (from <= cur.to.line) {
6998
+ ok = false;
6999
  break
7000
  }
7001
  }
7002
  if (!ok) {
7003
+ array.splice(0, i + 1);
7004
+ i = 0;
7005
  }
7006
  }
7007
  }
7008
 
7009
  function rebaseHist(hist, change) {
7010
+ var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
7011
+ rebaseHistArray(hist.done, from, to, diff);
7012
+ rebaseHistArray(hist.undone, from, to, diff);
7013
  }
7014
 
7015
  // Utility for applying a change to a line by handle or number,
7016
  // returning the number and optionally registering the line as
7017
  // changed.
7018
  function changeLine(doc, handle, changeType, op) {
7019
+ var no = handle, line = handle;
7020
+ if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); }
7021
+ else { no = lineNo(handle); }
7022
  if (no == null) { return null }
7023
+ if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); }
7024
  return line
7025
  }
7026
 
7040
  var LeafChunk = function(lines) {
7041
  var this$1 = this;
7042
 
7043
+ this.lines = lines;
7044
+ this.parent = null;
7045
+ var height = 0;
7046
  for (var i = 0; i < lines.length; ++i) {
7047
+ lines[i].parent = this$1;
7048
+ height += lines[i].height;
7049
  }
7050
+ this.height = height;
7051
  };
7052
 
7053
  LeafChunk.prototype.chunkSize = function () { return this.lines.length };
7057
  var this$1 = this;
7058
 
7059
  for (var i = at, e = at + n; i < e; ++i) {
7060
+ var line = this$1.lines[i];
7061
+ this$1.height -= line.height;
7062
+ cleanUpLine(line);
7063
+ signalLater(line, "delete");
7064
  }
7065
+ this.lines.splice(at, n);
7066
  };
7067
 
7068
  // Helper used to collapse a small branch into a single leaf.
7069
  LeafChunk.prototype.collapse = function (lines) {
7070
+ lines.push.apply(lines, this.lines);
7071
  };
7072
 
7073
  // Insert the given array of lines at offset 'at', count them as
7075
  LeafChunk.prototype.insertInner = function (at, lines, height) {
7076
  var this$1 = this;
7077
 
7078
+ this.height += height;
7079
+ this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
7080
+ for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1; }
7081
  };
7082
 
7083
  // Used to iterate over a part of the tree.
7091
  var BranchChunk = function(children) {
7092
  var this$1 = this;
7093
 
7094
+ this.children = children;
7095
+ var size = 0, height = 0;
7096
  for (var i = 0; i < children.length; ++i) {
7097
+ var ch = children[i];
7098
+ size += ch.chunkSize(); height += ch.height;
7099
+ ch.parent = this$1;
7100
  }
7101
+ this.size = size;
7102
+ this.height = height;
7103
+ this.parent = null;
7104
  };
7105
 
7106
  BranchChunk.prototype.chunkSize = function () { return this.size };
7108
  BranchChunk.prototype.removeInner = function (at, n) {
7109
  var this$1 = this;
7110
 
7111
+ this.size -= n;
7112
  for (var i = 0; i < this.children.length; ++i) {
7113
+ var child = this$1.children[i], sz = child.chunkSize();
7114
  if (at < sz) {
7115
+ var rm = Math.min(n, sz - at), oldHeight = child.height;
7116
+ child.removeInner(at, rm);
7117
+ this$1.height -= oldHeight - child.height;
7118
+ if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null; }
7119
  if ((n -= rm) == 0) { break }
7120
+ at = 0;
7121
+ } else { at -= sz; }
7122
  }
7123
  // If the result is smaller than 25 lines, ensure that it is a
7124
  // single leaf node.
7125
  if (this.size - n < 25 &&
7126
  (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
7127
+ var lines = [];
7128
+ this.collapse(lines);
7129
+ this.children = [new LeafChunk(lines)];
7130
+ this.children[0].parent = this;
7131
  }
7132
  };
7133
 
7134
  BranchChunk.prototype.collapse = function (lines) {
7135
  var this$1 = this;
7136
 
7137
+ for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines); }
7138
  };
7139
 
7140
  BranchChunk.prototype.insertInner = function (at, lines, height) {
7141
  var this$1 = this;
7142
 
7143
+ this.size += lines.length;
7144
+ this.height += height;
7145
  for (var i = 0; i < this.children.length; ++i) {
7146
+ var child = this$1.children[i], sz = child.chunkSize();
7147
  if (at <= sz) {
7148
+ child.insertInner(at, lines, height);
7149
  if (child.lines && child.lines.length > 50) {
7150
  // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
7151
  // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
7152
+ var remaining = child.lines.length % 25 + 25;
7153
  for (var pos = remaining; pos < child.lines.length;) {
7154
+ var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
7155
+ child.height -= leaf.height;
7156
+ this$1.children.splice(++i, 0, leaf);
7157
+ leaf.parent = this$1;
7158
  }
7159
+ child.lines = child.lines.slice(0, remaining);
7160
+ this$1.maybeSpill();
7161
  }
7162
  break
7163
  }
7164
+ at -= sz;
7165
  }
7166
  };
7167
 
7168
  // When a node has grown, check whether it should be split.
7169
  BranchChunk.prototype.maybeSpill = function () {
7170
  if (this.children.length <= 10) { return }
7171
+ var me = this;
7172
  do {
7173
+ var spilled = me.children.splice(me.children.length - 5, 5);
7174
+ var sibling = new BranchChunk(spilled);
7175
  if (!me.parent) { // Become the parent node
7176
+ var copy = new BranchChunk(me.children);
7177
+ copy.parent = me;
7178
+ me.children = [copy, sibling];
7179
+ me = copy;
7180
  } else {
7181
+ me.size -= sibling.size;
7182
+ me.height -= sibling.height;
7183
+ var myIndex = indexOf(me.parent.children, me);
7184
+ me.parent.children.splice(myIndex + 1, 0, sibling);
7185
  }
7186
+ sibling.parent = me.parent;
7187
  } while (me.children.length > 10)
7188
+ me.parent.maybeSpill();
7189
  };
7190
 
7191
  BranchChunk.prototype.iterN = function (at, n, op) {
7192
  var this$1 = this;
7193
 
7194
  for (var i = 0; i < this.children.length; ++i) {
7195
+ var child = this$1.children[i], sz = child.chunkSize();
7196
  if (at < sz) {
7197
+ var used = Math.min(n, sz - at);
7198
  if (child.iterN(at, used, op)) { return true }
7199
  if ((n -= used) == 0) { break }
7200
+ at = 0;
7201
+ } else { at -= sz; }
7202
  }
7203
  };
7204
 
7208
  var this$1 = this;
7209
 
7210
  if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
7211
+ { this$1[opt] = options[opt]; } } }
7212
+ this.doc = doc;
7213
+ this.node = node;
7214
  };
7215
 
7216
  LineWidget.prototype.clear = function () {
7217
  var this$1 = this;
7218
 
7219
+ var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
7220
  if (no == null || !ws) { return }
7221
+ for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1); } }
7222
+ if (!ws.length) { line.widgets = null; }
7223
+ var height = widgetHeight(this);
7224
+ updateLineHeight(line, Math.max(0, line.height - height));
7225
  if (cm) {
7226
  runInOp(cm, function () {
7227
+ adjustScrollWhenAboveVisible(cm, line, -height);
7228
+ regLineChange(cm, no, "widget");
7229
+ });
7230
+ signalLater(cm, "lineWidgetCleared", cm, this, no);
7231
  }
7232
  };
7233
 
7234
  LineWidget.prototype.changed = function () {
7235
  var this$1 = this;
7236
 
7237
+ var oldH = this.height, cm = this.doc.cm, line = this.line;
7238
+ this.height = null;
7239
+ var diff = widgetHeight(this) - oldH;
7240
  if (!diff) { return }
7241
+ updateLineHeight(line, line.height + diff);
7242
  if (cm) {
7243
  runInOp(cm, function () {
7244
+ cm.curOp.forceUpdate = true;
7245
+ adjustScrollWhenAboveVisible(cm, line, diff);
7246
+ signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
7247
+ });
7248
  }
7249
  };
7250
+ eventMixin(LineWidget);
7251
 
7252
  function adjustScrollWhenAboveVisible(cm, line, diff) {
7253
  if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
7254
+ { addToScrollPos(cm, null, diff); }
7255
  }
7256
 
7257
  function addLineWidget(doc, handle, node, options) {
7258
+ var widget = new LineWidget(doc, node, options);
7259
+ var cm = doc.cm;
7260
+ if (cm && widget.noHScroll) { cm.display.alignWidgets = true; }
7261
  changeLine(doc, handle, "widget", function (line) {
7262
+ var widgets = line.widgets || (line.widgets = []);
7263
+ if (widget.insertAt == null) { widgets.push(widget); }
7264
+ else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget); }
7265
+ widget.line = line;
7266
  if (cm && !lineIsHidden(doc, line)) {
7267
+ var aboveVisible = heightAtLine(line) < doc.scrollTop;
7268
+ updateLineHeight(line, line.height + widgetHeight(widget));
7269
+ if (aboveVisible) { addToScrollPos(cm, null, widget.height); }
7270
+ cm.curOp.forceUpdate = true;
7271
  }
7272
  return true
7273
+ });
7274
+ signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle));
7275
  return widget
7276
  }
7277
 
7290
  // Collapsed markers have unique ids, in order to be able to order
7291
  // them, which is needed for uniquely determining an outer marker
7292
  // when they overlap (they may nest, but not partially overlap).
7293
+ var nextMarkerId = 0;
7294
 
7295
  var TextMarker = function(doc, type) {
7296
+ this.lines = [];
7297
+ this.type = type;
7298
+ this.doc = doc;
7299
+ this.id = ++nextMarkerId;
7300
  };
7301
 
7302
  // Clear the marker.
7304
  var this$1 = this;
7305
 
7306
  if (this.explicitlyCleared) { return }
7307
+ var cm = this.doc.cm, withOp = cm && !cm.curOp;
7308
+ if (withOp) { startOperation(cm); }
7309
  if (hasHandler(this, "clear")) {
7310
+ var found = this.find();
7311
+ if (found) { signalLater(this, "clear", found.from, found.to); }
7312
  }
7313
+ var min = null, max = null;
7314
  for (var i = 0; i < this.lines.length; ++i) {
7315
+ var line = this$1.lines[i];
7316
+ var span = getMarkedSpanFor(line.markedSpans, this$1);
7317
+ if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text"); }
7318
  else if (cm) {
7319
+ if (span.to != null) { max = lineNo(line); }
7320
+ if (span.from != null) { min = lineNo(line); }
7321
  }
7322
+ line.markedSpans = removeMarkedSpan(line.markedSpans, span);
7323
  if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm)
7324
+ { updateLineHeight(line, textHeight(cm.display)); }
7325
  }
7326
  if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
7327
+ var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual);
7328
  if (len > cm.display.maxLineLength) {
7329
+ cm.display.maxLine = visual;
7330
+ cm.display.maxLineLength = len;
7331
+ cm.display.maxLineChanged = true;
7332
  }
7333
  } }
7334
 
7335
+ if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1); }
7336
+ this.lines.length = 0;
7337
+ this.explicitlyCleared = true;
7338
  if (this.atomic && this.doc.cantEdit) {
7339
+ this.doc.cantEdit = false;
7340
+ if (cm) { reCheckSelection(cm.doc); }
7341
  }
7342
+ if (cm) { signalLater(cm, "markerCleared", cm, this, min, max); }
7343
+ if (withOp) { endOperation(cm); }
7344
+ if (this.parent) { this.parent.clear(); }
7345
  };
7346
 
7347
  // Find the position of the marker in the document. Returns a {from,
7352
  TextMarker.prototype.find = function (side, lineObj) {
7353
  var this$1 = this;
7354
 
7355
+ if (side == null && this.type == "bookmark") { side = 1; }
7356
+ var from, to;
7357
  for (var i = 0; i < this.lines.length; ++i) {
7358
+ var line = this$1.lines[i];
7359
+ var span = getMarkedSpanFor(line.markedSpans, this$1);
7360
  if (span.from != null) {
7361
+ from = Pos(lineObj ? line : lineNo(line), span.from);
7362
  if (side == -1) { return from }
7363
  }
7364
  if (span.to != null) {
7365
+ to = Pos(lineObj ? line : lineNo(line), span.to);
7366
  if (side == 1) { return to }
7367
  }
7368
  }
7374
  TextMarker.prototype.changed = function () {
7375
  var this$1 = this;
7376
 
7377
+ var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
7378
  if (!pos || !cm) { return }
7379
  runInOp(cm, function () {
7380
+ var line = pos.line, lineN = lineNo(pos.line);
7381
+ var view = findViewForLine(cm, lineN);
7382
  if (view) {
7383
+ clearLineMeasurementCacheFor(view);
7384
+ cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
7385
  }
7386
+ cm.curOp.updateMaxLine = true;
7387
  if (!lineIsHidden(widget.doc, line) && widget.height != null) {
7388
+ var oldHeight = widget.height;
7389
+ widget.height = null;
7390
+ var dHeight = widgetHeight(widget) - oldHeight;
7391
  if (dHeight)
7392
+ { updateLineHeight(line, line.height + dHeight); }
7393
  }
7394
+ signalLater(cm, "markerChanged", cm, this$1);
7395
+ });
7396
  };
7397
 
7398
  TextMarker.prototype.attachLine = function (line) {
7399
  if (!this.lines.length && this.doc.cm) {
7400
+ var op = this.doc.cm.curOp;
7401
  if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
7402
+ { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this); }
7403
  }
7404
+ this.lines.push(line);
7405
  };
7406
 
7407
  TextMarker.prototype.detachLine = function (line) {
7408
+ this.lines.splice(indexOf(this.lines, line), 1);
7409
  if (!this.lines.length && this.doc.cm) {
7410
+ var op = this.doc.cm.curOp;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
 
7411
  }
7412
  };
7413
+ eventMixin(TextMarker);
7414
 
7415
  // Create a marker, wire it up to the right lines, and
7416
  function markText(doc, from, to, options, type) {
7421
  // Ensure we are in an operation.
7422
  if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
7423
 
7424
+ var marker = new TextMarker(doc, type), diff = cmp(from, to);
7425
+ if (options) { copyObj(options, marker, false); }
7426
  // Don't connect empty markers unless clearWhenEmpty is false
7427
  if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
7428
  { return marker }
7429
  if (marker.replacedWith) {
7430
  // Showing up as a widget implies collapsed (widget replaces text)
7431
+ marker.collapsed = true;
7432
+ marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
7433
+ if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
7434
+ if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
 
7435
  }
7436
  if (marker.collapsed) {
7437
  if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
7438
  from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
7439
  { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
7440
+ seeCollapsedSpans();
7441
  }
7442
 
7443
  if (marker.addToHistory)
7444
+ { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
7445
 
7446
+ var curLine = from.line, cm = doc.cm, updateMaxLine;
7447
  doc.iter(curLine, to.line + 1, function (line) {
7448
  if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
7449
+ { updateMaxLine = true; }
7450
+ if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
7451
  addMarkedSpan(line, new MarkedSpan(marker,
7452
  curLine == from.line ? from.ch : null,
7453
+ curLine == to.line ? to.ch : null));
7454
+ ++curLine;
7455
+ });
7456
  // lineIsHidden depends on the presence of the spans, so needs a second pass
7457
  if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
7458
+ if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
7459
+ }); }
7460
 
7461
+ if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
7462
 
7463
  if (marker.readOnly) {
7464
+ seeReadOnlySpans();
7465
  if (doc.history.done.length || doc.history.undone.length)
7466
+ { doc.clearHistory(); }
7467
  }
7468
  if (marker.collapsed) {
7469
+ marker.id = ++nextMarkerId;
7470
+ marker.atomic = true;
7471
  }
7472
  if (cm) {
7473
  // Sync editor state
7474
+ if (updateMaxLine) { cm.curOp.updateMaxLine = true; }
7475
  if (marker.collapsed)
7476
+ { regChange(cm, from.line, to.line + 1); }
7477
  else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
7478
+ { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } }
7479
+ if (marker.atomic) { reCheckSelection(cm.doc); }
7480
+ signalLater(cm, "markerAdded", cm, marker);
7481
  }
7482
  return marker
7483
  }
7490
  var SharedTextMarker = function(markers, primary) {
7491
  var this$1 = this;
7492
 
7493
+ this.markers = markers;
7494
+ this.primary = primary;
7495
  for (var i = 0; i < markers.length; ++i)
7496
+ { markers[i].parent = this$1; }
7497
  };
7498
 
7499
  SharedTextMarker.prototype.clear = function () {
7500
  var this$1 = this;
7501
 
7502
  if (this.explicitlyCleared) { return }
7503
+ this.explicitlyCleared = true;
7504
  for (var i = 0; i < this.markers.length; ++i)
7505
+ { this$1.markers[i].clear(); }
7506
+ signalLater(this, "clear");
7507
  };
7508
 
7509
  SharedTextMarker.prototype.find = function (side, lineObj) {
7510
  return this.primary.find(side, lineObj)
7511
  };
7512
+ eventMixin(SharedTextMarker);
7513
 
7514
  function markTextShared(doc, from, to, options, type) {
7515
+ options = copyObj(options);
7516
+ options.shared = false;
7517
+ var markers = [markText(doc, from, to, options, type)], primary = markers[0];
7518
+ var widget = options.widgetNode;
7519
  linkedDocs(doc, function (doc) {
7520
+ if (widget) { options.widgetNode = widget.cloneNode(true); }
7521
+ markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
7522
  for (var i = 0; i < doc.linked.length; ++i)
7523
  { if (doc.linked[i].isParent) { return } }
7524
+ primary = lst(markers);
7525
+ });
7526
  return new SharedTextMarker(markers, primary)
7527
  }
7528
 
7532
 
7533
  function copySharedMarkers(doc, markers) {
7534
  for (var i = 0; i < markers.length; i++) {
7535
+ var marker = markers[i], pos = marker.find();
7536
+ var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
7537
  if (cmp(mFrom, mTo)) {
7538
+ var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
7539
+ marker.markers.push(subMark);
7540
+ subMark.parent = marker;
7541
  }
7542
  }
7543
  }
7544
 
7545
  function detachSharedMarkers(markers) {
7546
  var loop = function ( i ) {
7547
+ var marker = markers[i], linked = [marker.primary.doc];
7548
+ linkedDocs(marker.primary.doc, function (d) { return linked.push(d); });
7549
  for (var j = 0; j < marker.markers.length; j++) {
7550
+ var subMarker = marker.markers[j];
7551
  if (indexOf(linked, subMarker.doc) == -1) {
7552
+ subMarker.parent = null;
7553
+ marker.markers.splice(j--, 1);
7554
  }
7555
  }
7556
  };
7558
  for (var i = 0; i < markers.length; i++) loop( i );
7559
  }
7560
 
7561
+ var nextDocId = 0;
7562
+ var Doc = function(text, mode, firstLine, lineSep, direction) {
7563
+ if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
7564
+ if (firstLine == null) { firstLine = 0; }
7565
+
7566
+ BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
7567
+ this.first = firstLine;
7568
+ this.scrollTop = this.scrollLeft = 0;
7569
+ this.cantEdit = false;
7570
+ this.cleanGeneration = 1;
7571
+ this.frontier = firstLine;
7572
+ var start = Pos(firstLine, 0);
7573
+ this.sel = simpleSelection(start);
7574
+ this.history = new History(null);
7575
+ this.id = ++nextDocId;
7576
+ this.modeOption = mode;
7577
+ this.lineSep = lineSep;
7578
+ this.direction = (direction == "rtl") ? "rtl" : "ltr";
7579
+ this.extend = false;
7580
+
7581
+ if (typeof text == "string") { text = this.splitLines(text); }
7582
+ updateDoc(this, {from: start, to: start, text: text});
7583
+ setSelection(this, simpleSelection(start), sel_dontScroll);
7584
+ };
7585
 
7586
  Doc.prototype = createObj(BranchChunk.prototype, {
7587
  constructor: Doc,
7590
  // three, it iterates over the range given by the first two (with
7591
  // the second being non-inclusive).
7592
  iter: function(from, to, op) {
7593
+ if (op) { this.iterN(from - this.first, to - from, op); }
7594
+ else { this.iterN(this.first, this.first + this.size, from); }
7595
  },
7596
 
7597
  // Non-public interface for adding and removing lines.
7598
  insert: function(at, lines) {
7599
+ var height = 0;
7600
+ for (var i = 0; i < lines.length; ++i) { height += lines[i].height; }
7601
+ this.insertInner(at - this.first, lines, height);
7602
  },
7603
+ remove: function(at, n) { this.removeInner(at - this.first, n); },
7604
 
7605
  // From here, the methods are part of the public interface. Most
7606
  // are also available from CodeMirror (editor) instances.
7607
 
7608
  getValue: function(lineSep) {
7609
+ var lines = getLines(this, this.first, this.first + this.size);
7610
  if (lineSep === false) { return lines }
7611
  return lines.join(lineSep || this.lineSeparator())
7612
  },
7613
  setValue: docMethodOp(function(code) {
7614
+ var top = Pos(this.first, 0), last = this.first + this.size - 1;
7615
  makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
7616
+ text: this.splitLines(code), origin: "setValue", full: true}, true);
7617
+ setSelection(this, simpleSelection(top));
7618
  }),
7619
  replaceRange: function(code, from, to, origin) {
7620
+ from = clipPos(this, from);
7621
+ to = to ? clipPos(this, to) : from;
7622
+ replaceRange(this, code, from, to, origin);
7623
  },
7624
  getRange: function(from, to, lineSep) {
7625
+ var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
7626
  if (lineSep === false) { return lines }
7627
  return lines.join(lineSep || this.lineSeparator())
7628
  },
7633
  getLineNumber: function(line) {return lineNo(line)},
7634
 
7635
  getLineHandleVisualStart: function(line) {
7636
+ if (typeof line == "number") { line = getLine(this, line); }
7637
  return visualLine(line)
7638
  },
7639
 
7644
  clipPos: function(pos) {return clipPos(this, pos)},
7645
 
7646
  getCursor: function(start) {
7647
+ var range$$1 = this.sel.primary(), pos;
7648
+ if (start == null || start == "head") { pos = range$$1.head; }
7649
+ else if (start == "anchor") { pos = range$$1.anchor; }
7650
+ else if (start == "end" || start == "to" || start === false) { pos = range$$1.to(); }
7651
+ else { pos = range$$1.from(); }
7652
  return pos
7653
  },
7654
  listSelections: function() { return this.sel.ranges },
7655
  somethingSelected: function() {return this.sel.somethingSelected()},
7656
 
7657
  setCursor: docMethodOp(function(line, ch, options) {
7658
+ setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
7659
  }),
7660
  setSelection: docMethodOp(function(anchor, head, options) {
7661
+ setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
7662
  }),
7663
  extendSelection: docMethodOp(function(head, other, options) {
7664
+ extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
7665
  }),
7666
  extendSelections: docMethodOp(function(heads, options) {
7667
+ extendSelections(this, clipPosArray(this, heads), options);
7668
  }),
7669
  extendSelectionsBy: docMethodOp(function(f, options) {
7670
+ var heads = map(this.sel.ranges, f);
7671
+ extendSelections(this, clipPosArray(this, heads), options);
7672
  }),
7673
  setSelections: docMethodOp(function(ranges, primary, options) {
7674
  var this$1 = this;
7675
 
7676
  if (!ranges.length) { return }
7677
+ var out = [];
7678
  for (var i = 0; i < ranges.length; i++)
7679
  { out[i] = new Range(clipPos(this$1, ranges[i].anchor),
7680
+ clipPos(this$1, ranges[i].head)); }
7681
+ if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex); }
7682
+ setSelection(this, normalizeSelection(out, primary), options);
7683
  }),
7684
  addSelection: docMethodOp(function(anchor, head, options) {
7685
+ var ranges = this.sel.ranges.slice(0);
7686
+ ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
7687
+ setSelection(this, normalizeSelection(ranges, ranges.length - 1), options);
7688
  }),
7689
 
7690
  getSelection: function(lineSep) {
7691
  var this$1 = this;
7692
 
7693
+ var ranges = this.sel.ranges, lines;
7694
  for (var i = 0; i < ranges.length; i++) {
7695
+ var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
7696
+ lines = lines ? lines.concat(sel) : sel;
7697
  }
7698
  if (lineSep === false) { return lines }
7699
  else { return lines.join(lineSep || this.lineSeparator()) }
7701
  getSelections: function(lineSep) {
7702
  var this$1 = this;
7703
 
7704
+ var parts = [], ranges = this.sel.ranges;
7705
  for (var i = 0; i < ranges.length; i++) {
7706
+ var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
7707
+ if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()); }
7708
+ parts[i] = sel;
7709
  }
7710
  return parts
7711
  },
7712
  replaceSelection: function(code, collapse, origin) {
7713
+ var dup = [];
7714
  for (var i = 0; i < this.sel.ranges.length; i++)
7715
+ { dup[i] = code; }
7716
+ this.replaceSelections(dup, collapse, origin || "+input");
7717
  },
7718
  replaceSelections: docMethodOp(function(code, collapse, origin) {
7719
  var this$1 = this;
7720
 
7721
+ var changes = [], sel = this.sel;
7722
  for (var i = 0; i < sel.ranges.length; i++) {
7723
+ var range$$1 = sel.ranges[i];
7724
+ changes[i] = {from: range$$1.from(), to: range$$1.to(), text: this$1.splitLines(code[i]), origin: origin};
7725
  }
7726
+ var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
7727
  for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
7728
+ { makeChange(this$1, changes[i$1]); }
7729
+ if (newSel) { setSelectionReplaceHistory(this, newSel); }
7730
+ else if (this.cm) { ensureCursorVisible(this.cm); }
7731
  }),
7732
+ undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
7733
+ redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
7734
+ undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
7735
+ redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
7736
 
7737
+ setExtending: function(val) {this.extend = val;},
7738
  getExtending: function() {return this.extend},
7739
 
7740
  historySize: function() {
7741
+ var hist = this.history, done = 0, undone = 0;
7742
+ for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done; } }
7743
+ for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone; } }
7744
  return {undo: done, redo: undone}
7745
  },
7746
+ clearHistory: function() {this.history = new History(this.history.maxGeneration);},
7747
 
7748
  markClean: function() {
7749
+ this.cleanGeneration = this.changeGeneration(true);
7750
  },
7751
  changeGeneration: function(forceSplit) {
7752
  if (forceSplit)
7753
+ { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null; }
7754
  return this.history.generation
7755
  },
7756
  isClean: function (gen) {
7762
  undone: copyHistoryArray(this.history.undone)}
7763
  },
7764
  setHistory: function(histData) {
7765
+ var hist = this.history = new History(this.history.maxGeneration);
7766
+ hist.done = copyHistoryArray(histData.done.slice(0), null, true);
7767
+ hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
7768
  },
7769
 
7770
  setGutterMarker: docMethodOp(function(line, gutterID, value) {
7771
  return changeLine(this, line, "gutter", function (line) {
7772
+ var markers = line.gutterMarkers || (line.gutterMarkers = {});
7773
+ markers[gutterID] = value;
7774
+ if (!value && isEmpty(markers)) { line.gutterMarkers = null; }
7775
  return true
7776
  })
7777
  }),
7782
  this.iter(function (line) {
7783
  if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
7784
  changeLine(this$1, line, "gutter", function () {
7785
+ line.gutterMarkers[gutterID] = null;
7786
+ if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null; }
7787
  return true
7788
+ });
7789
  }
7790
+ });
7791
  }),
7792
 
7793
  lineInfo: function(line) {
7794
+ var n;
7795
  if (typeof line == "number") {
7796
  if (!isLine(this, line)) { return null }
7797
+ n = line;
7798
+ line = getLine(this, line);
7799
  if (!line) { return null }
7800
  } else {
7801
+ n = lineNo(line);
7802
  if (n == null) { return null }
7803
  }
7804
  return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
7810
  return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
7811
  var prop = where == "text" ? "textClass"
7812
  : where == "background" ? "bgClass"
7813
+ : where == "gutter" ? "gutterClass" : "wrapClass";
7814
+ if (!line[prop]) { line[prop] = cls; }
7815
  else if (classTest(cls).test(line[prop])) { return false }
7816
+ else { line[prop] += " " + cls; }
7817
  return true
7818
  })
7819
  }),
7821
  return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
7822
  var prop = where == "text" ? "textClass"
7823
  : where == "background" ? "bgClass"
7824
+ : where == "gutter" ? "gutterClass" : "wrapClass";
7825
+ var cur = line[prop];
7826
  if (!cur) { return false }
7827
+ else if (cls == null) { line[prop] = null; }
7828
  else {
7829
+ var found = cur.match(classTest(cls));
7830
  if (!found) { return false }
7831
+ var end = found.index + found[0].length;
7832
+ line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
7833
  }
7834
  return true
7835
  })
7838
  addLineWidget: docMethodOp(function(handle, node, options) {
7839
  return addLineWidget(this, handle, node, options)
7840
  }),
7841
+ removeLineWidget: function(widget) { widget.clear(); },
7842
 
7843
  markText: function(from, to, options) {
7844
  return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
7847
  var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
7848
  insertLeft: options && options.insertLeft,
7849
  clearWhenEmpty: false, shared: options && options.shared,
7850
+ handleMouseEvents: options && options.handleMouseEvents};
7851
+ pos = clipPos(this, pos);
7852
  return markText(this, pos, pos, realOpts, "bookmark")
7853
  },
7854
  findMarksAt: function(pos) {
7855
+ pos = clipPos(this, pos);
7856
+ var markers = [], spans = getLine(this, pos.line).markedSpans;
7857
  if (spans) { for (var i = 0; i < spans.length; ++i) {
7858
+ var span = spans[i];
7859
  if ((span.from == null || span.from <= pos.ch) &&
7860
  (span.to == null || span.to >= pos.ch))
7861
+ { markers.push(span.marker.parent || span.marker); }
7862
  } }
7863
  return markers
7864
  },
7865
  findMarks: function(from, to, filter) {
7866
+ from = clipPos(this, from); to = clipPos(this, to);
7867
+ var found = [], lineNo$$1 = from.line;
7868
  this.iter(from.line, to.line + 1, function (line) {
7869
+ var spans = line.markedSpans;
7870
  if (spans) { for (var i = 0; i < spans.length; i++) {
7871
+ var span = spans[i];
7872
+ if (!(span.to != null && lineNo$$1 == from.line && from.ch >= span.to ||
7873
+ span.from == null && lineNo$$1 != from.line ||
7874
+ span.from != null && lineNo$$1 == to.line && span.from >= to.ch) &&
7875
  (!filter || filter(span.marker)))
7876
+ { found.push(span.marker.parent || span.marker); }
7877
  } }
7878
+ ++lineNo$$1;
7879
+ });
7880
  return found
7881
  },
7882
  getAllMarks: function() {
7883
+ var markers = [];
7884
  this.iter(function (line) {
7885
+ var sps = line.markedSpans;
7886
  if (sps) { for (var i = 0; i < sps.length; ++i)
7887
+ { if (sps[i].from != null) { markers.push(sps[i].marker); } } }
7888
+ });
7889
  return markers
7890
  },
7891
 
7892
  posFromIndex: function(off) {
7893
+ var ch, lineNo$$1 = this.first, sepSize = this.lineSeparator().length;
7894
  this.iter(function (line) {
7895
+ var sz = line.text.length + sepSize;
7896
  if (sz > off) { ch = off; return true }
7897
+ off -= sz;
7898
+ ++lineNo$$1;
7899
+ });
7900
+ return clipPos(this, Pos(lineNo$$1, ch))
7901
  },
7902
  indexFromPos: function (coords) {
7903
+ coords = clipPos(this, coords);
7904
+ var index = coords.ch;
7905
  if (coords.line < this.first || coords.ch < 0) { return 0 }
7906
+ var sepSize = this.lineSeparator().length;
7907
  this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
7908
+ index += line.text.length + sepSize;
7909
+ });
7910
  return index
7911
  },
7912
 
7913
  copy: function(copyHistory) {
7914
  var doc = new Doc(getLines(this, this.first, this.first + this.size),
7915
+ this.modeOption, this.first, this.lineSep, this.direction);
7916
+ doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
7917
+ doc.sel = this.sel;
7918
+ doc.extend = false;
7919
  if (copyHistory) {
7920
+ doc.history.undoDepth = this.history.undoDepth;
7921
+ doc.setHistory(this.getHistory());
7922
  }
7923
  return doc
7924
  },
7925
 
7926
  linkedDoc: function(options) {
7927
+ if (!options) { options = {}; }
7928
+ var from = this.first, to = this.first + this.size;
7929
+ if (options.from != null && options.from > from) { from = options.from; }
7930
+ if (options.to != null && options.to < to) { to = options.to; }
7931
+ var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
7932
  if (options.sharedHist) { copy.history = this.history
7933
+ ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
7934
+ copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
7935
+ copySharedMarkers(copy, findSharedMarkers(this));
7936
  return copy
7937
  },
7938
  unlinkDoc: function(other) {
7939
  var this$1 = this;
7940
 
7941
+ if (other instanceof CodeMirror$1) { other = other.doc; }
7942
  if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
7943
+ var link = this$1.linked[i];
7944
  if (link.doc != other) { continue }
7945
+ this$1.linked.splice(i, 1);
7946
+ other.unlinkDoc(this$1);
7947
+ detachSharedMarkers(findSharedMarkers(this$1));
7948
  break
7949
  } }
7950
  // If the histories were shared, split them again
7951
  if (other.history == this.history) {
7952
+ var splitIds = [other.id];
7953
+ linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true);
7954
+ other.history = new History(null);
7955
+ other.history.done = copyHistoryArray(this.history.done, splitIds);
7956
+ other.history.undone = copyHistoryArray(this.history.undone, splitIds);
7957
  }
7958
  },
7959
+ iterLinkedDocs: function(f) {linkedDocs(this, f);},
7960
 
7961
  getMode: function() {return this.mode},
7962
  getEditor: function() {return this.cm},
7965
  if (this.lineSep) { return str.split(this.lineSep) }
7966
  return splitLinesAuto(str)
7967
  },
7968
+ lineSeparator: function() { return this.lineSep || "\n" },
7969
+
7970
+ setDirection: docMethodOp(function (dir) {
7971
+ if (dir != "rtl") { dir = "ltr"; }
7972
+ if (dir == this.direction) { return }
7973
+ this.direction = dir;
7974
+ this.iter(function (line) { return line.order = null; });
7975
+ if (this.cm) { directionChanged(this.cm); }
7976
+ })
7977
+ });
7978
 
7979
  // Public alias.
7980
+ Doc.prototype.eachLine = Doc.prototype.iter;
7981
 
7982
  // Kludge to work around strange IE behavior where it'll sometimes
7983
  // re-fire a series of drag-related events right after the drop (#1551)
7984
+ var lastDrop = 0;
7985
 
7986
  function onDrop(e) {
7987
+ var cm = this;
7988
+ clearDragCursor(cm);
7989
  if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
7990
  { return }
7991
+ e_preventDefault(e);
7992
+ if (ie) { lastDrop = +new Date; }
7993
+ var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
7994
  if (!pos || cm.isReadOnly()) { return }
7995
  // Might be a file drop, in which case we simply extract the text
7996
  // and insert it.
7997
  if (files && files.length && window.FileReader && window.File) {
7998
+ var n = files.length, text = Array(n), read = 0;
7999
  var loadFile = function (file, i) {
8000
  if (cm.options.allowDropFileTypes &&
8001
  indexOf(cm.options.allowDropFileTypes, file.type) == -1)
8002
  { return }
8003
 
8004
+ var reader = new FileReader;
8005
  reader.onload = operation(cm, function () {
8006
+ var content = reader.result;
8007
+ if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = ""; }
8008
+ text[i] = content;
8009
  if (++read == n) {
8010
+ pos = clipPos(cm.doc, pos);
8011
  var change = {from: pos, to: pos,
8012
  text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
8013
+ origin: "paste"};
8014
+ makeChange(cm.doc, change);
8015
+ setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
8016
  }
8017
+ });
8018
+ reader.readAsText(file);
8019
+ };
8020
+ for (var i = 0; i < n; ++i) { loadFile(files[i], i); }
8021
  } else { // Normal drop
8022
  // Don't do a replace if the drop happened inside of the selected text.
8023
  if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
8024
+ cm.state.draggingText(e);
8025
  // Ensure the editor is re-focused
8026
+ setTimeout(function () { return cm.display.input.focus(); }, 20);
8027
  return
8028
  }
8029
  try {
8030
+ var text$1 = e.dataTransfer.getData("Text");
8031
  if (text$1) {
8032
+ var selected;
8033
  if (cm.state.draggingText && !cm.state.draggingText.copy)
8034
+ { selected = cm.listSelections(); }
8035
+ setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
8036
  if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
8037
+ { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag"); } }
8038
+ cm.replaceSelection(text$1, "around", "paste");
8039
+ cm.display.input.focus();
8040
  }
8041
  }
8042
  catch(e){}
8047
  if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
8048
  if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
8049
 
8050
+ e.dataTransfer.setData("Text", cm.getSelection());
8051
+ e.dataTransfer.effectAllowed = "copyMove";
8052
 
8053
  // Use dummy image instead of default browsers image.
8054
  // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
8055
  if (e.dataTransfer.setDragImage && !safari) {
8056
+ var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
8057
+ img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
8058
  if (presto) {
8059
+ img.width = img.height = 1;
8060
+ cm.display.wrapper.appendChild(img);
8061
  // Force a relayout, or Opera won't use our image for some obscure reason
8062
+ img._top = img.offsetTop;
8063
  }
8064
+ e.dataTransfer.setDragImage(img, 0, 0);
8065
+ if (presto) { img.parentNode.removeChild(img); }
8066
  }
8067
  }
8068
 
8069
  function onDragOver(cm, e) {
8070
+ var pos = posFromMouse(cm, e);
8071
  if (!pos) { return }
8072
+ var frag = document.createDocumentFragment();
8073
+ drawSelectionCursor(cm, pos, frag);
8074
  if (!cm.display.dragCursor) {
8075
+ cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
8076
+ cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
8077
  }
8078
+ removeChildrenAndAdd(cm.display.dragCursor, frag);
8079
  }
8080
 
8081
  function clearDragCursor(cm) {
8082
  if (cm.display.dragCursor) {
8083
+ cm.display.lineSpace.removeChild(cm.display.dragCursor);
8084
+ cm.display.dragCursor = null;
8085
  }
8086
  }
8087
 
8091
 
8092
  function forEachCodeMirror(f) {
8093
  if (!document.body.getElementsByClassName) { return }
8094
+ var byClass = document.body.getElementsByClassName("CodeMirror");
8095
  for (var i = 0; i < byClass.length; i++) {
8096
+ var cm = byClass[i].CodeMirror;
8097
+ if (cm) { f(cm); }
8098
  }
8099
  }
8100
 
8101
+ var globalsRegistered = false;
8102
  function ensureGlobalHandlers() {
8103
  if (globalsRegistered) { return }
8104
+ registerGlobalHandlers();
8105
+ globalsRegistered = true;
8106
  }
8107
  function registerGlobalHandlers() {
8108
  // When the window resizes, we need to refresh active editors.
8109
+ var resizeTimer;
8110
  on(window, "resize", function () {
8111
  if (resizeTimer == null) { resizeTimer = setTimeout(function () {
8112
+ resizeTimer = null;
8113
+ forEachCodeMirror(onResize);
8114
+ }, 100); }
8115
+ });
8116
  // When the window loses focus, we want to show the editor as blurred
8117
+ on(window, "blur", function () { return forEachCodeMirror(onBlur); });
8118
  }
8119
  // Called when the window resizes
8120
  function onResize(cm) {
8121
+ var d = cm.display;
8122
  if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
8123
  { return }
8124
  // Might be a text scaling operation, clear size caches.
8125
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
8126
+ d.scrollbarsClipped = false;
8127
+ cm.setSize();
8128
  }
8129
 
8130
  var keyNames = {
8136
  173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
8137
  221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
8138
  63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
8139
+ };
8140
 
8141
  // Number keys
8142
+ for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i); }
8143
  // Alphabetic keys
8144
+ for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1); }
8145
  // Function keys
8146
+ for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2; }
8147
 
8148
+ var keyMap = {};
8149
 
8150
  keyMap.basic = {
8151
  "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
8154
  "Tab": "defaultTab", "Shift-Tab": "indentAuto",
8155
  "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
8156
  "Esc": "singleSelection"
8157
+ };
8158
  // Note that the save and find-related commands aren't defined by
8159
  // default. User code or addons can define them. Unknown commands
8160
  // are simply ignored.
8167
  "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
8168
  "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
8169
  fallthrough: "basic"
8170
+ };
8171
  // Very basic readline/emacs-style bindings, which are standard on Mac.
8172
  keyMap.emacsy = {
8173
  "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
8175
  "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
8176
  "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
8177
  "Ctrl-O": "openLine"
8178
+ };
8179
  keyMap.macDefault = {
8180
  "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
8181
  "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
8185
  "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
8186
  "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
8187
  fallthrough: ["basic", "emacsy"]
8188
+ };
8189
+ keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
8190
 
8191
  // KEYMAP DISPATCH
8192
 
8193
  function normalizeKeyName(name) {
8194
+ var parts = name.split(/-(?!$)/);
8195
+ name = parts[parts.length - 1];
8196
+ var alt, ctrl, shift, cmd;
8197
  for (var i = 0; i < parts.length - 1; i++) {
8198
+ var mod = parts[i];
8199
+ if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true; }
8200
+ else if (/^a(lt)?$/i.test(mod)) { alt = true; }
8201
+ else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; }
8202
+ else if (/^s(hift)?$/i.test(mod)) { shift = true; }
8203
  else { throw new Error("Unrecognized modifier name: " + mod) }
8204
  }
8205
+ if (alt) { name = "Alt-" + name; }
8206
+ if (ctrl) { name = "Ctrl-" + name; }
8207
+ if (cmd) { name = "Cmd-" + name; }
8208
+ if (shift) { name = "Shift-" + name; }
8209
  return name
8210
  }
8211
 
8215
  // new normalized keymap, and then updates the old object to reflect
8216
  // this.
8217
  function normalizeKeyMap(keymap) {
8218
+ var copy = {};
8219
  for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
8220
+ var value = keymap[keyname];
8221
  if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
8222
  if (value == "...") { delete keymap[keyname]; continue }
8223
 
8224
+ var keys = map(keyname.split(" "), normalizeKeyName);
8225
  for (var i = 0; i < keys.length; i++) {
8226
+ var val = (void 0), name = (void 0);
8227
  if (i == keys.length - 1) {
8228
+ name = keys.join(" ");
8229
+ val = value;
8230
  } else {
8231
+ name = keys.slice(0, i + 1).join(" ");
8232
+ val = "...";
8233
  }
8234
+ var prev = copy[name];
8235
+ if (!prev) { copy[name] = val; }
8236
  else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
8237
  }
8238
+ delete keymap[keyname];
8239
  } }
8240
+ for (var prop in copy) { keymap[prop] = copy[prop]; }
8241
  return keymap
8242
  }
8243
 
8244
+ function lookupKey(key, map$$1, handle, context) {
8245
+ map$$1 = getKeyMap(map$$1);
8246
+ var found = map$$1.call ? map$$1.call(key, context) : map$$1[key];
8247
  if (found === false) { return "nothing" }
8248
  if (found === "...") { return "multi" }
8249
  if (found != null && handle(found)) { return "handled" }
8250
 
8251
+ if (map$$1.fallthrough) {
8252
+ if (Object.prototype.toString.call(map$$1.fallthrough) != "[object Array]")
8253
+ { return lookupKey(key, map$$1.fallthrough, handle, context) }
8254
+ for (var i = 0; i < map$$1.fallthrough.length; i++) {
8255
+ var result = lookupKey(key, map$$1.fallthrough[i], handle, context);
8256
  if (result) { return result }
8257
  }
8258
  }
8261
  // Modifier key presses don't count as 'real' key presses for the
8262
  // purpose of keymap fallthrough.
8263
  function isModifierKey(value) {
8264
+ var name = typeof value == "string" ? value : keyNames[value.keyCode];
8265
  return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
8266
  }
8267
 
8268
  // Look up the name of a key as indicated by an event object.
8269
  function keyName(event, noShift) {
8270
  if (presto && event.keyCode == 34 && event["char"]) { return false }
8271
+ var base = keyNames[event.keyCode], name = base;
8272
  if (name == null || event.altGraphKey) { return false }
8273
+ if (event.altKey && base != "Alt") { name = "Alt-" + name; }
8274
+ if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name; }
8275
+ if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name; }
8276
+ if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name; }
8277
  return name
8278
  }
8279
 
8284
  // Helper for deleting text near the selection(s), used to implement
8285
  // backspace, delete, and similar functionality.
8286
  function deleteNearSelection(cm, compute) {
8287
+ var ranges = cm.doc.sel.ranges, kill = [];
8288
  // Build up a set of ranges to kill first, merging overlapping
8289
  // ranges.
8290
  for (var i = 0; i < ranges.length; i++) {
8291
+ var toKill = compute(ranges[i]);
8292
  while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
8293
+ var replaced = kill.pop();
8294
  if (cmp(replaced.from, toKill.from) < 0) {
8295
+ toKill.from = replaced.from;
8296
  break
8297
  }
8298
  }
8299
+ kill.push(toKill);
8300
  }
8301
  // Next, remove those actual ranges.
8302
  runInOp(cm, function () {
8303
  for (var i = kill.length - 1; i >= 0; i--)
8304
+ { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); }
8305
+ ensureCursorVisible(cm);
8306
+ });
8307
  }
8308
 
8309
  // Commands are parameter-less actions that can be performed on an
8313
  singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
8314
  killLine: function (cm) { return deleteNearSelection(cm, function (range) {
8315
  if (range.empty()) {
8316
+ var len = getLine(cm.doc, range.head.line).text.length;
8317
  if (range.head.ch == len && range.head.line < cm.lastLine())
8318
  { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
8319
  else
8330
  from: Pos(range.from().line, 0), to: range.from()
8331
  }); }); },
8332
  delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
8333
+ var top = cm.charCoords(range.head, "div").top + 5;
8334
+ var leftPos = cm.coordsChar({left: 0, top: top}, "div");
8335
  return {from: leftPos, to: range.from()}
8336
  }); },
8337
  delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
8338
+ var top = cm.charCoords(range.head, "div").top + 5;
8339
+ var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
8340
  return {from: range.from(), to: rightPos }
8341
  }); },
8342
  undo: function (cm) { return cm.undo(); },
8355
  {origin: "+move", bias: -1}
8356
  ); },
8357
  goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
8358
+ var top = cm.charCoords(range.head, "div").top + 5;
8359
  return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
8360
  }, sel_move); },
8361
  goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
8362
+ var top = cm.charCoords(range.head, "div").top + 5;
8363
  return cm.coordsChar({left: 0, top: top}, "div")
8364
  }, sel_move); },
8365
  goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
8366
+ var top = cm.charCoords(range.head, "div").top + 5;
8367
+ var pos = cm.coordsChar({left: 0, top: top}, "div");
8368
  if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
8369
  return pos
8370
  }, sel_move); },
8391
  indentLess: function (cm) { return cm.indentSelection("subtract"); },
8392
  insertTab: function (cm) { return cm.replaceSelection("\t"); },
8393
  insertSoftTab: function (cm) {
8394
+ var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
8395
  for (var i = 0; i < ranges.length; i++) {
8396
+ var pos = ranges[i].from();
8397
+ var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
8398
+ spaces.push(spaceStr(tabSize - col % tabSize));
8399
  }
8400
+ cm.replaceSelections(spaces);
8401
  },
8402
  defaultTab: function (cm) {
8403
+ if (cm.somethingSelected()) { cm.indentSelection("add"); }
8404
+ else { cm.execCommand("insertTab"); }
8405
  },
8406
  // Swap the two chars left and right of each selection's head.
8407
  // Move cursor behind the two swapped characters afterwards.
8411
  // Doesn't do anything on an empty line.
8412
  // Doesn't do anything with non-empty selections.
8413
  transposeChars: function (cm) { return runInOp(cm, function () {
8414
+ var ranges = cm.listSelections(), newSel = [];
8415
  for (var i = 0; i < ranges.length; i++) {
8416
  if (!ranges[i].empty()) { continue }
8417
+ var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
8418
  if (line) {
8419
+ if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1); }
8420
  if (cur.ch > 0) {
8421
+ cur = new Pos(cur.line, cur.ch + 1);
8422
  cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
8423
+ Pos(cur.line, cur.ch - 2), cur, "+transpose");
8424
  } else if (cur.line > cm.doc.first) {
8425
+ var prev = getLine(cm.doc, cur.line - 1).text;
8426
  if (prev) {
8427
+ cur = new Pos(cur.line, 1);
8428
  cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
8429
  prev.charAt(prev.length - 1),
8430
+ Pos(cur.line - 1, prev.length - 1), cur, "+transpose");
8431
  }
8432
  }
8433
  }
8434
+ newSel.push(new Range(cur, cur));
8435
  }
8436
+ cm.setSelections(newSel);
8437
  }); },
8438
  newlineAndIndent: function (cm) { return runInOp(cm, function () {
8439
+ var sels = cm.listSelections();
8440
  for (var i = sels.length - 1; i >= 0; i--)
8441
+ { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input"); }
8442
+ sels = cm.listSelections();
8443
  for (var i$1 = 0; i$1 < sels.length; i$1++)
8444
+ { cm.indentLine(sels[i$1].from().line, null, true); }
8445
+ ensureCursorVisible(cm);
8446
  }); },
8447
  openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
8448
  toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
8449
+ };
8450
 
8451
 
8452
  function lineStart(cm, lineN) {
8453
+ var line = getLine(cm.doc, lineN);
8454
+ var visual = visualLine(line);
8455
+ if (visual != line) { lineN = lineNo(visual); }
8456
  return endOfLine(true, cm, visual, lineN, 1)
8457
  }
8458
  function lineEnd(cm, lineN) {
8459
+ var line = getLine(cm.doc, lineN);
8460
+ var visual = visualLineEnd(line);
8461
+ if (visual != line) { lineN = lineNo(visual); }
8462
  return endOfLine(true, cm, line, lineN, -1)
8463
  }
8464
  function lineStartSmart(cm, pos) {
8465
+ var start = lineStart(cm, pos.line);
8466
+ var line = getLine(cm.doc, start.line);
8467
+ var order = getOrder(line, cm.doc.direction);
8468
  if (!order || order[0].level == 0) {
8469
+ var firstNonWS = Math.max(0, line.text.search(/\S/));
8470
+ var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
8471
  return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
8472
  }
8473
  return start
8476
  // Run a handler that was bound to a key.
8477
  function doHandleBinding(cm, bound, dropShift) {
8478
  if (typeof bound == "string") {
8479
+ bound = commands[bound];
8480
  if (!bound) { return false }
8481
  }
8482
  // Ensure previous input has been read, so that the handler sees a
8483
  // consistent view of the document
8484
+ cm.display.input.ensurePolled();
8485
+ var prevShift = cm.display.shift, done = false;
8486
  try {
8487
+ if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
8488
+ if (dropShift) { cm.display.shift = false; }
8489
+ done = bound(cm) != Pass;
8490
  } finally {
8491
+ cm.display.shift = prevShift;
8492
+ cm.state.suppressEdits = false;
8493
  }
8494
  return done
8495
  }
8496
 
8497
  function lookupKeyForEditor(cm, name, handle) {
8498
  for (var i = 0; i < cm.state.keyMaps.length; i++) {
8499
+ var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
8500
  if (result) { return result }
8501
  }
8502
  return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
8503
  || lookupKey(name, cm.options.keyMap, handle, cm)
8504
  }
8505
 
8506
+ var stopSeq = new Delayed;
8507
  function dispatchKey(cm, name, e, handle) {
8508
+ var seq = cm.state.keySeq;
8509
  if (seq) {
8510
  if (isModifierKey(name)) { return "handled" }
8511
  stopSeq.set(50, function () {
8512
  if (cm.state.keySeq == seq) {
8513
+ cm.state.keySeq = null;
8514
+ cm.display.input.reset();
8515
  }
8516
+ });
8517
+ name = seq + " " + name;
8518
  }
8519
+ var result = lookupKeyForEditor(cm, name, handle);
8520
 
8521
  if (result == "multi")
8522
+ { cm.state.keySeq = name; }
8523
  if (result == "handled")
8524
+ { signalLater(cm, "keyHandled", cm, name, e); }
8525
 
8526
  if (result == "handled" || result == "multi") {
8527
+ e_preventDefault(e);
8528
+ restartBlink(cm);
8529
  }
8530
 
8531
  if (seq && !result && /\'$/.test(name)) {
8532
+ e_preventDefault(e);
8533
  return true
8534
  }
8535
  return !!result
8537
 
8538
  // Handle a key from the keydown event.
8539
  function handleKeyBinding(cm, e) {
8540
+ var name = keyName(e, true);
8541
  if (!name) { return false }
8542
 
8543
  if (e.shiftKey && !cm.state.keySeq) {
8559
  return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
8560
  }
8561
 
8562
+ var lastStoppedKey = null;
8563
  function onKeyDown(e) {
8564
+ var cm = this;
8565
+ cm.curOp.focus = activeElt();
8566
  if (signalDOMEvent(cm, e)) { return }
8567
  // IE does strange things with escape.
8568
+ if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
8569
+ var code = e.keyCode;
8570
+ cm.display.shift = code == 16 || e.shiftKey;
8571
+ var handled = handleKeyBinding(cm, e);
8572
  if (presto) {
8573
+ lastStoppedKey = handled ? code : null;
8574
  // Opera has no cut event... we try to at least catch the key combo
8575
  if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
8576
+ { cm.replaceSelection("", null, "cut"); }
8577
  }
8578
 
8579
  // Turn mouse into crosshair when Alt is held on Mac.
8580
  if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
8581
+ { showCrossHair(cm); }
8582
  }
8583
 
8584
  function showCrossHair(cm) {
8585
+ var lineDiv = cm.display.lineDiv;
8586
+ addClass(lineDiv, "CodeMirror-crosshair");
8587
 
8588
  function up(e) {
8589
  if (e.keyCode == 18 || !e.altKey) {
8590
+ rmClass(lineDiv, "CodeMirror-crosshair");
8591
+ off(document, "keyup", up);
8592
+ off(document, "mouseover", up);
8593
  }
8594
  }
8595
+ on(document, "keyup", up);
8596
+ on(document, "mouseover", up);
8597
  }
8598
 
8599
  function onKeyUp(e) {
8600
+ if (e.keyCode == 16) { this.doc.sel.shift = false; }
8601
+ signalDOMEvent(this, e);
8602
  }
8603
 
8604
  function onKeyPress(e) {
8605
+ var cm = this;
8606
  if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
8607
+ var keyCode = e.keyCode, charCode = e.charCode;
8608
  if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
8609
  if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
8610
+ var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
8611
  // Some browsers fire keypress events for backspace
8612
  if (ch == "\x08") { return }
8613
  if (handleCharBinding(cm, e, ch)) { return }
8614
+ cm.display.input.onKeyPress(e);
8615
  }
8616
 
8617
  // A mouse down can be a single click, double click, triple click,
8620
  // middle-click-paste. Or it might be a click on something we should
8621
  // not interfere with, such as a scrollbar or widget.
8622
  function onMouseDown(e) {
8623
+ var cm = this, display = cm.display;
8624
  if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
8625
+ display.input.ensurePolled();
8626
+ display.shift = e.shiftKey;
8627
 
8628
  if (eventInWidget(display, e)) {
8629
  if (!webkit) {
8630
  // Briefly turn off draggability, to allow widgets to do
8631
  // normal dragging things.
8632
+ display.scroller.draggable = false;
8633
+ setTimeout(function () { return display.scroller.draggable = true; }, 100);
8634
  }
8635
  return
8636
  }
8637
  if (clickInGutter(cm, e)) { return }
8638
+ var start = posFromMouse(cm, e);
8639
+ window.focus();
8640
 
8641
  switch (e_button(e)) {
8642
  case 1:
8643
  // #3261: make sure, that we're not starting a second selection
8644
  if (cm.state.selectingText)
8645
+ { cm.state.selectingText(e); }
8646
  else if (start)
8647
+ { leftButtonDown(cm, e, start); }
8648
  else if (e_target(e) == display.scroller)
8649
+ { e_preventDefault(e); }
8650
  break
8651
  case 2:
8652
+ if (webkit) { cm.state.lastMiddleDown = +new Date; }
8653
+ if (start) { extendSelection(cm.doc, start); }
8654
+ setTimeout(function () { return display.input.focus(); }, 20);
8655
+ e_preventDefault(e);
8656
  break
8657
  case 3:
8658
+ if (captureRightClick) { onContextMenu(cm, e); }
8659
+ else { delayBlurEvent(cm); }
8660
  break
8661
  }
8662
  }
8664
  var lastClick;
8665
  var lastDoubleClick;
8666
  function leftButtonDown(cm, e, start) {
8667
+ if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
8668
+ else { cm.curOp.focus = activeElt(); }
8669
 
8670
+ var now = +new Date, type;
8671
  if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
8672
+ type = "triple";
8673
  } else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
8674
+ type = "double";
8675
+ lastDoubleClick = {time: now, pos: start};
8676
  } else {
8677
+ type = "single";
8678
+ lastClick = {time: now, pos: start};
8679
  }
8680
 
8681
+ var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained;
8682
  if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
8683
  type == "single" && (contained = sel.contains(start)) > -1 &&
8684
  (cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) &&
8685
  (cmp(contained.to(), start) > 0 || start.xRel < 0))
8686
+ { leftButtonStartDrag(cm, e, start, modifier); }
8687
  else
8688
+ { leftButtonSelect(cm, e, start, type, modifier); }
8689
  }
8690
 
8691
  // Start a text drag. When it ends, see if any dragging actually
8692
  // happen, and treat as a click if it didn't.
8693
  function leftButtonStartDrag(cm, e, start, modifier) {
8694
+ var display = cm.display, startTime = +new Date;
8695
  var dragEnd = operation(cm, function (e2) {
8696
+ if (webkit) { display.scroller.draggable = false; }
8697
+ cm.state.draggingText = false;
8698
+ off(document, "mouseup", dragEnd);
8699
+ off(display.scroller, "drop", dragEnd);
8700
  if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
8701
+ e_preventDefault(e2);
8702
  if (!modifier && +new Date - 200 < startTime)
8703
+ { extendSelection(cm.doc, start); }
8704
  // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
8705
  if (webkit || ie && ie_version == 9)
8706
+ { setTimeout(function () {document.body.focus(); display.input.focus();}, 20); }
8707
  else
8708
+ { display.input.focus(); }
8709
  }
8710
+ });
8711
  // Let the drag handler handle this.
8712
+ if (webkit) { display.scroller.draggable = true; }
8713
+ cm.state.draggingText = dragEnd;
8714
+ dragEnd.copy = mac ? e.altKey : e.ctrlKey;
8715
  // IE's approach to draggable
8716
+ if (display.scroller.dragDrop) { display.scroller.dragDrop(); }
8717
+ on(document, "mouseup", dragEnd);
8718
+ on(display.scroller, "drop", dragEnd);
8719
  }
8720
 
8721
  // Normal selection, as opposed to text dragging.
8722
  function leftButtonSelect(cm, e, start, type, addNew) {
8723
+ var display = cm.display, doc = cm.doc;
8724
+ e_preventDefault(e);
8725
 
8726
+ var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
8727
  if (addNew && !e.shiftKey) {
8728
+ ourIndex = doc.sel.contains(start);
8729
  if (ourIndex > -1)
8730
+ { ourRange = ranges[ourIndex]; }
8731
  else
8732
+ { ourRange = new Range(start, start); }
8733
  } else {
8734
+ ourRange = doc.sel.primary();
8735
+ ourIndex = doc.sel.primIndex;
8736
  }
8737
 
8738
  if (chromeOS ? e.shiftKey && e.metaKey : e.altKey) {
8739
+ type = "rect";
8740
+ if (!addNew) { ourRange = new Range(start, start); }
8741
+ start = posFromMouse(cm, e, true, true);
8742
+ ourIndex = -1;
8743
  } else if (type == "double") {
8744
+ var word = cm.findWordAt(start);
8745
  if (cm.display.shift || doc.extend)
8746
+ { ourRange = extendRange(doc, ourRange, word.anchor, word.head); }
8747
  else
8748
+ { ourRange = word; }
8749
  } else if (type == "triple") {
8750
+ var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
8751
  if (cm.display.shift || doc.extend)
8752
+ { ourRange = extendRange(doc, ourRange, line.anchor, line.head); }
8753
  else
8754
+ { ourRange = line; }
8755
  } else {
8756
+ ourRange = extendRange(doc, ourRange, start);
8757
  }
8758
 
8759
  if (!addNew) {
8760
+ ourIndex = 0;
8761
+ setSelection(doc, new Selection([ourRange], 0), sel_mouse);
8762
+ startSel = doc.sel;
8763
  } else if (ourIndex == -1) {
8764
+ ourIndex = ranges.length;
8765
  setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
8766
+ {scroll: false, origin: "*mouse"});
8767
  } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) {
8768
  setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
8769
+ {scroll: false, origin: "*mouse"});
8770
+ startSel = doc.sel;
8771
  } else {
8772
+ replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
8773
  }
8774
 
8775
+ var lastPos = start;
8776
  function extendTo(pos) {
8777
  if (cmp(lastPos, pos) == 0) { return }
8778
+ lastPos = pos;
8779
 
8780
  if (type == "rect") {
8781
+ var ranges = [], tabSize = cm.options.tabSize;
8782
+ var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
8783
+ var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
8784
+ var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
8785
  for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
8786
  line <= end; line++) {
8787
+ var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
8788
  if (left == right)
8789
+ { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
8790
  else if (text.length > leftPos)
8791
+ { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
8792
  }
8793
+ if (!ranges.length) { ranges.push(new Range(start, start)); }
8794
  setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
8795
+ {origin: "*mouse", scroll: false});
8796
+ cm.scrollIntoView(pos);
8797
  } else {
8798
+ var oldRange = ourRange;
8799
+ var anchor = oldRange.anchor, head = pos;
8800
  if (type != "single") {
8801
+ var range$$1;
8802
  if (type == "double")
8803
+ { range$$1 = cm.findWordAt(pos); }
8804
  else
8805
+ { range$$1 = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0))); }
8806
+ if (cmp(range$$1.anchor, anchor) > 0) {
8807
+ head = range$$1.head;
8808
+ anchor = minPos(oldRange.from(), range$$1.anchor);
8809
  } else {
8810
+ head = range$$1.anchor;
8811
+ anchor = maxPos(oldRange.to(), range$$1.head);
8812
  }
8813
  }
8814
+ var ranges$1 = startSel.ranges.slice(0);
8815
+ ranges$1[ourIndex] = new Range(clipPos(doc, anchor), head);
8816
+ setSelection(doc, normalizeSelection(ranges$1, ourIndex), sel_mouse);
8817
  }
8818
  }
8819
 
8820
+ var editorSize = display.wrapper.getBoundingClientRect();
8821
  // Used to ensure timeout re-tries don't fire when another extend
8822
  // happened in the meantime (clearTimeout isn't reliable -- at
8823
  // least on Chrome, the timeouts still happen even when cleared,
8824
  // if the clear happens after their scheduled firing time).
8825
+ var counter = 0;
8826
 
8827
  function extend(e) {
8828
+ var curCount = ++counter;
8829
+ var cur = posFromMouse(cm, e, true, type == "rect");
8830
  if (!cur) { return }
8831
  if (cmp(cur, lastPos) != 0) {
8832
+ cm.curOp.focus = activeElt();
8833
+ extendTo(cur);
8834
+ var visible = visibleLines(display, doc);
8835
  if (cur.line >= visible.to || cur.line < visible.from)
8836
+ { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
8837
  } else {
8838
+ var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
8839
  if (outside) { setTimeout(operation(cm, function () {
8840
  if (counter != curCount) { return }
8841
+ display.scroller.scrollTop += outside;
8842
+ extend(e);
8843
+ }), 50); }
8844
  }
8845
  }
8846
 
8847
  function done(e) {
8848
+ cm.state.selectingText = false;
8849
+ counter = Infinity;
8850
+ e_preventDefault(e);
8851
+ display.input.focus();
8852
+ off(document, "mousemove", move);
8853
+ off(document, "mouseup", up);
8854
+ doc.history.lastSelOrigin = null;
8855
  }
8856
 
8857
  var move = operation(cm, function (e) {
8858
+ if (!e_button(e)) { done(e); }
8859
+ else { extend(e); }
8860
+ });
8861
+ var up = operation(cm, done);
8862
+ cm.state.selectingText = up;
8863
+ on(document, "mousemove", move);
8864
+ on(document, "mouseup", up);
8865
  }
8866
 
8867
 
8868
  // Determines whether an event happened in the gutter, and fires the
8869
  // handlers for the corresponding event.
8870
  function gutterEvent(cm, e, type, prevent) {
8871
+ var mX, mY;
8872
+ try { mX = e.clientX; mY = e.clientY; }
8873
  catch(e) { return false }
8874
  if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
8875
+ if (prevent) { e_preventDefault(e); }
8876
 
8877
+ var display = cm.display;
8878
+ var lineBox = display.lineDiv.getBoundingClientRect();
8879
 
8880
  if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
8881
+ mY -= lineBox.top - display.viewOffset;
8882
 
8883
  for (var i = 0; i < cm.options.gutters.length; ++i) {
8884
+ var g = display.gutters.childNodes[i];
8885
  if (g && g.getBoundingClientRect().right >= mX) {
8886
+ var line = lineAtHeight(cm.doc, mY);
8887
+ var gutter = cm.options.gutters[i];
8888
+ signal(cm, type, cm, line, gutter, e);
8889
  return e_defaultPrevented(e)
8890
  }
8891
  }
8903
  function onContextMenu(cm, e) {
8904
  if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
8905
  if (signalDOMEvent(cm, e, "contextmenu")) { return }
8906
+ cm.display.input.onContextMenu(e);
8907
  }
8908
 
8909
  function contextMenuInGutter(cm, e) {
8913
 
8914
  function themeChanged(cm) {
8915
  cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
8916
+ cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
8917
+ clearCaches(cm);
8918
  }
8919
 
8920
+ var Init = {toString: function(){return "CodeMirror.Init"}};
8921
 
8922
+ var defaults = {};
8923
+ var optionHandlers = {};
8924
 
8925
  function defineOptions(CodeMirror) {
8926
+ var optionHandlers = CodeMirror.optionHandlers;
8927
 
8928
  function option(name, deflt, handle, notOnInit) {
8929
+ CodeMirror.defaults[name] = deflt;
8930
  if (handle) { optionHandlers[name] =
8931
+ notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; }
8932
  }
8933
 
8934
+ CodeMirror.defineOption = option;
8935
 
8936
  // Passed to option handlers when there is no old value.
8937
+ CodeMirror.Init = Init;
8938
 
8939
  // These two are, on init, called from the constructor because they
8940
  // have to be initialized before the editor can start at all.
8941
+ option("value", "", function (cm, val) { return cm.setValue(val); }, true);
8942
  option("mode", null, function (cm, val) {
8943
+ cm.doc.modeOption = val;
8944
+ loadMode(cm);
8945
+ }, true);
8946
 
8947
+ option("indentUnit", 2, loadMode, true);
8948
+ option("indentWithTabs", false);
8949
+ option("smartIndent", true);
8950
  option("tabSize", 4, function (cm) {
8951
+ resetModeState(cm);
8952
+ clearCaches(cm);
8953
+ regChange(cm);
8954
+ }, true);
8955
  option("lineSeparator", null, function (cm, val) {
8956
+ cm.doc.lineSep = val;
8957
  if (!val) { return }
8958
+ var newBreaks = [], lineNo = cm.doc.first;
8959
  cm.doc.iter(function (line) {
8960
  for (var pos = 0;;) {
8961
+ var found = line.text.indexOf(val, pos);
8962
  if (found == -1) { break }
8963
+ pos = found + val.length;
8964
+ newBreaks.push(Pos(lineNo, found));
8965
  }
8966
+ lineNo++;
8967
+ });
8968
  for (var i = newBreaks.length - 1; i >= 0; i--)
8969
+ { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
8970
+ });
8971
+ option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
8972
+ cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
8973
+ if (old != Init) { cm.refresh(); }
8974
+ });
8975
+ option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true);
8976
+ option("electricChars", true);
8977
  option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
8978
  throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
8979
+ }, true);
8980
+ option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true);
8981
+ option("rtlMoveVisually", !windows);
8982
+ option("wholeLineUpdateBefore", true);
8983
 
8984
  option("theme", "default", function (cm) {
8985
+ themeChanged(cm);
8986
+ guttersChanged(cm);
8987
+ }, true);
8988
  option("keyMap", "default", function (cm, val, old) {
8989
+ var next = getKeyMap(val);
8990
+ var prev = old != Init && getKeyMap(old);
8991
+ if (prev && prev.detach) { prev.detach(cm, next); }
8992
+ if (next.attach) { next.attach(cm, prev || null); }
8993
+ });
8994
+ option("extraKeys", null);
8995
 
8996
+ option("lineWrapping", false, wrappingChanged, true);
8997
  option("gutters", [], function (cm) {
8998
+ setGuttersForLineNumbers(cm.options);
8999
+ guttersChanged(cm);
9000
+ }, true);
9001
  option("fixedGutter", true, function (cm, val) {
9002
+ cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
9003
+ cm.refresh();
9004
+ }, true);
9005
+ option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true);
9006
  option("scrollbarStyle", "native", function (cm) {
9007
+ initScrollbars(cm);
9008
+ updateScrollbars(cm);
9009
+ cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
9010
+ cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
9011
+ }, true);
9012
  option("lineNumbers", false, function (cm) {
9013
+ setGuttersForLineNumbers(cm.options);
9014
+ guttersChanged(cm);
9015
+ }, true);
9016
+ option("firstLineNumber", 1, guttersChanged, true);
9017
+ option("lineNumberFormatter", function (integer) { return integer; }, guttersChanged, true);
9018
+ option("showCursorWhenSelecting", false, updateSelection, true);
9019
 
9020
+ option("resetSelectionOnContextMenu", true);
9021
+ option("lineWiseCopyCut", true);
9022
 
9023
  option("readOnly", false, function (cm, val) {
9024
  if (val == "nocursor") {
9025
+ onBlur(cm);
9026
+ cm.display.input.blur();
9027
+ cm.display.disabled = true;
9028
  } else {
9029
+ cm.display.disabled = false;
9030
  }
9031
+ cm.display.input.readOnlyChanged(val);
9032
+ });
9033
+ option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset(); }}, true);
9034
+ option("dragDrop", true, dragDropChanged);
9035
+ option("allowDropFileTypes", null);
9036
+
9037
+ option("cursorBlinkRate", 530);
9038
+ option("cursorScrollMargin", 0);
9039
+ option("cursorHeight", 1, updateSelection, true);
9040
+ option("singleCursorHeightPerLine", true, updateSelection, true);
9041
+ option("workTime", 100);
9042
+ option("workDelay", 100);
9043
+ option("flattenSpans", true, resetModeState, true);
9044
+ option("addModeClass", false, resetModeState, true);
9045
+ option("pollInterval", 100);
9046
+ option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; });
9047
+ option("historyEventDelay", 1250);
9048
+ option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true);
9049
+ option("maxHighlightLength", 10000, resetModeState, true);
9050
  option("moveInputWithCursor", true, function (cm, val) {
9051
+ if (!val) { cm.display.input.resetPosition(); }
9052
+ });
9053
 
9054
+ option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; });
9055
+ option("autofocus", null);
9056
+ option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true);
9057
  }
9058
 
9059
  function guttersChanged(cm) {
9060
+ updateGutters(cm);
9061
+ regChange(cm);
9062
+ alignHorizontally(cm);
9063
  }
9064
 
9065
  function dragDropChanged(cm, value, old) {
9066
+ var wasOn = old && old != Init;
9067
  if (!value != !wasOn) {
9068
+ var funcs = cm.display.dragFunctions;
9069
+ var toggle = value ? on : off;
9070
+ toggle(cm.display.scroller, "dragstart", funcs.start);
9071
+ toggle(cm.display.scroller, "dragenter", funcs.enter);
9072
+ toggle(cm.display.scroller, "dragover", funcs.over);
9073
+ toggle(cm.display.scroller, "dragleave", funcs.leave);
9074
+ toggle(cm.display.scroller, "drop", funcs.drop);
9075
  }
9076
  }
9077
 
9078
  function wrappingChanged(cm) {
9079
  if (cm.options.lineWrapping) {
9080
+ addClass(cm.display.wrapper, "CodeMirror-wrap");
9081
+ cm.display.sizer.style.minWidth = "";
9082
+ cm.display.sizerWidth = null;
9083
  } else {
9084
+ rmClass(cm.display.wrapper, "CodeMirror-wrap");
9085
+ findMaxLine(cm);
9086
  }
9087
+ estimateLineHeights(cm);
9088
+ regChange(cm);
9089
+ clearCaches(cm);
9090
+ setTimeout(function () { return updateScrollbars(cm); }, 100);
9091
  }
9092
 
9093
  // A CodeMirror instance represents an editor. This is the object
9094
  // that user code is usually dealing with.
9095
 
9096
+ function CodeMirror$1(place, options) {
9097
  var this$1 = this;
9098
 
9099
+ if (!(this instanceof CodeMirror$1)) { return new CodeMirror$1(place, options) }
9100
 
9101
+ this.options = options = options ? copyObj(options) : {};
9102
  // Determine effective options based on given values and defaults.
9103
+ copyObj(defaults, options, false);
9104
+ setGuttersForLineNumbers(options);
9105
+
9106
+ var doc = options.value;
9107
+ if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); }
9108
+ this.doc = doc;
9109
+
9110
+ var input = new CodeMirror$1.inputStyles[options.inputStyle](this);
9111
+ var display = this.display = new Display(place, doc, input);
9112
+ display.wrapper.CodeMirror = this;
9113
+ updateGutters(this);
9114
+ themeChanged(this);
9115
  if (options.lineWrapping)
9116
+ { this.display.wrapper.className += " CodeMirror-wrap"; }
9117
+ initScrollbars(this);
9118
 
9119
  this.state = {
9120
  keyMaps: [], // stores maps added by addKeyMap
9130
  highlight: new Delayed(), // stores highlight worker timeout
9131
  keySeq: null, // Unfinished key sequence
9132
  specialChars: null
9133
+ };
9134
 
9135
+ if (options.autofocus && !mobile) { display.input.focus(); }
9136
 
9137
  // Override magic textarea content restore that IE sometimes does
9138
  // on our hidden textarea on reload
9139
+ if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); }
9140
 
9141
+ registerEventHandlers(this);
9142
+ ensureGlobalHandlers();
9143
 
9144
+ startOperation(this);
9145
+ this.curOp.forceUpdate = true;
9146
+ attachDoc(this, doc);
9147
 
9148
  if ((options.autofocus && !mobile) || this.hasFocus())
9149
+ { setTimeout(bind(onFocus, this), 20); }
9150
  else
9151
+ { onBlur(this); }
9152
 
9153
  for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
9154
+ { optionHandlers[opt](this$1, options[opt], Init); } }
9155
+ maybeUpdateLineNumberWidth(this);
9156
+ if (options.finishInit) { options.finishInit(this); }
9157
+ for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1); }
9158
+ endOperation(this);
9159
  // Suppress optimizelegibility in Webkit, since it breaks text
9160
  // measuring on line wrapping boundaries.
9161
  if (webkit && options.lineWrapping &&
9162
  getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
9163
+ { display.lineDiv.style.textRendering = "auto"; }
9164
  }
9165
 
9166
  // The default configuration options.
9167
+ CodeMirror$1.defaults = defaults;
9168
  // Functions to run when options are changed.
9169
+ CodeMirror$1.optionHandlers = optionHandlers;
9170
 
9171
  // Attach the necessary event handlers when initializing the editor
9172
  function registerEventHandlers(cm) {
9173
+ var d = cm.display;
9174
+ on(d.scroller, "mousedown", operation(cm, onMouseDown));
9175
  // Older IE's will not fire a second mousedown for a double click
9176
  if (ie && ie_version < 11)
9177
  { on(d.scroller, "dblclick", operation(cm, function (e) {
9178
  if (signalDOMEvent(cm, e)) { return }
9179
+ var pos = posFromMouse(cm, e);
9180
  if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
9181
+ e_preventDefault(e);
9182
+ var word = cm.findWordAt(pos);
9183
+ extendSelection(cm.doc, word.anchor, word.head);
9184
+ })); }
9185
  else
9186
+ { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); }
9187
  // Some browsers fire contextmenu *after* opening the menu, at
9188
  // which point we can't mess with it anymore. Context menu is
9189
  // handled in onMouseDown for these browsers.
9190
+ if (!captureRightClick) { on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); }); }
9191
 
9192
  // Used to suppress mouse event handling when a touch happens
9193
+ var touchFinished, prevTouch = {end: 0};
9194
  function finishTouch() {
9195
  if (d.activeTouch) {
9196
+ touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000);
9197
+ prevTouch = d.activeTouch;
9198
+ prevTouch.end = +new Date;
9199
  }
9200
  }
9201
  function isMouseLikeTouchEvent(e) {
9202
  if (e.touches.length != 1) { return false }
9203
+ var touch = e.touches[0];
9204
  return touch.radiusX <= 1 && touch.radiusY <= 1
9205
  }
9206
  function farAway(touch, other) {
9207
  if (other.left == null) { return true }
9208
+ var dx = other.left - touch.left, dy = other.top - touch.top;
9209
  return dx * dx + dy * dy > 20 * 20
9210
  }
9211
  on(d.scroller, "touchstart", function (e) {
9212
  if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
9213
+ d.input.ensurePolled();
9214
+ clearTimeout(touchFinished);
9215
+ var now = +new Date;
9216
  d.activeTouch = {start: now, moved: false,
9217
+ prev: now - prevTouch.end <= 300 ? prevTouch : null};
9218
  if (e.touches.length == 1) {
9219
+ d.activeTouch.left = e.touches[0].pageX;
9220
+ d.activeTouch.top = e.touches[0].pageY;
9221
  }
9222
  }
9223
+ });
9224
  on(d.scroller, "touchmove", function () {
9225
+ if (d.activeTouch) { d.activeTouch.moved = true; }
9226
+ });
9227
  on(d.scroller, "touchend", function (e) {
9228
+ var touch = d.activeTouch;
9229
  if (touch && !eventInWidget(d, e) && touch.left != null &&
9230
  !touch.moved && new Date - touch.start < 300) {
9231
+ var pos = cm.coordsChar(d.activeTouch, "page"), range;
9232
  if (!touch.prev || farAway(touch, touch.prev)) // Single tap
9233
+ { range = new Range(pos, pos); }
9234
  else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
9235
+ { range = cm.findWordAt(pos); }
9236
  else // Triple tap
9237
+ { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); }
9238
+ cm.setSelection(range.anchor, range.head);
9239
+ cm.focus();
9240
+ e_preventDefault(e);
9241
  }
9242
+ finishTouch();
9243
+ });
9244
+ on(d.scroller, "touchcancel", finishTouch);
9245
 
9246
  // Sync scrolling between fake scrollbars and real scrollable
9247
  // area, ensure viewport is updated when scrolling.
9248
  on(d.scroller, "scroll", function () {
9249
  if (d.scroller.clientHeight) {
9250
+ setScrollTop(cm, d.scroller.scrollTop);
9251
+ setScrollLeft(cm, d.scroller.scrollLeft, true);
9252
+ signal(cm, "scroll", cm);
9253
  }
9254
+ });
9255
 
9256
  // Listen to wheel events in order to try and update the viewport on time.
9257
+ on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); });
9258
+ on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); });
9259
 
9260
  // Prevent wrapper from ever scrolling
9261
+ on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
9262
 
9263
  d.dragFunctions = {
9264
+ enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }},
9265
+ over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }},
9266
  start: function (e) { return onDragStart(cm, e); },
9267
  drop: operation(cm, onDrop),
9268
+ leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }}
9269
+ };
9270
 
9271
+ var inp = d.input.getField();
9272
+ on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); });
9273
+ on(inp, "keydown", operation(cm, onKeyDown));
9274
+ on(inp, "keypress", operation(cm, onKeyPress));
9275
+ on(inp, "focus", function (e) { return onFocus(cm, e); });
9276
+ on(inp, "blur", function (e) { return onBlur(cm, e); });
9277
  }
9278
 
9279
+ var initHooks = [];
9280
+ CodeMirror$1.defineInitHook = function (f) { return initHooks.push(f); };
9281
 
9282
  // Indent the given line. The how parameter can be "smart",
9283
  // "add"/null, "subtract", or "prev". When aggressive is false
9285
  // lines are not indented, and places where the mode returns Pass
9286
  // are left alone.
9287
  function indentLine(cm, n, how, aggressive) {
9288
+ var doc = cm.doc, state;
9289
+ if (how == null) { how = "add"; }
9290
  if (how == "smart") {
9291
  // Fall back to "prev" when the mode doesn't have an indentation
9292
  // method.
9293
+ if (!doc.mode.indent) { how = "prev"; }
9294
+ else { state = getStateBefore(cm, n); }
9295
  }
9296
 
9297
+ var tabSize = cm.options.tabSize;
9298
+ var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
9299
+ if (line.stateAfter) { line.stateAfter = null; }
9300
+ var curSpaceString = line.text.match(/^\s*/)[0], indentation;
9301
  if (!aggressive && !/\S/.test(line.text)) {
9302
+ indentation = 0;
9303
+ how = "not";
9304
  } else if (how == "smart") {
9305
+ indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
9306
  if (indentation == Pass || indentation > 150) {
9307
  if (!aggressive) { return }
9308
+ how = "prev";
9309
  }
9310
  }
9311
  if (how == "prev") {
9312
+ if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); }
9313
+ else { indentation = 0; }
9314
  } else if (how == "add") {
9315
+ indentation = curSpace + cm.options.indentUnit;
9316
  } else if (how == "subtract") {
9317
+ indentation = curSpace - cm.options.indentUnit;
9318
  } else if (typeof how == "number") {
9319
+ indentation = curSpace + how;
9320
  }
9321
+ indentation = Math.max(0, indentation);
9322
 
9323
+ var indentString = "", pos = 0;
9324
  if (cm.options.indentWithTabs)
9325
+ { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} }
9326
+ if (pos < indentation) { indentString += spaceStr(indentation - pos); }
9327
 
9328
  if (indentString != curSpaceString) {
9329
+ replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
9330
+ line.stateAfter = null;
9331
  return true
9332
  } else {
9333
  // Ensure that, if the cursor was in the whitespace at the start
9334
  // of the line, it is moved to the end of that space.
9335
  for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
9336
+ var range = doc.sel.ranges[i$1];
9337
  if (range.head.line == n && range.head.ch < curSpaceString.length) {
9338
+ var pos$1 = Pos(n, curSpaceString.length);
9339
+ replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));
9340
  break
9341
  }
9342
  }
9346
  // This will be set to a {lineWise: bool, text: [string]} object, so
9347
  // that, when pasting, we know what kind of selections the copied
9348
  // text was made out of.
9349
+ var lastCopied = null;
9350
 
9351
  function setLastCopied(newLastCopied) {
9352
+ lastCopied = newLastCopied;
9353
  }
9354
 
9355
  function applyTextInput(cm, inserted, deleted, sel, origin) {
9356
+ var doc = cm.doc;
9357
+ cm.display.shift = false;
9358
+ if (!sel) { sel = doc.sel; }
9359
 
9360
+ var paste = cm.state.pasteIncoming || origin == "paste";
9361
+ var textLines = splitLinesAuto(inserted), multiPaste = null;
9362
  // When pasing N lines into N selections, insert one line per selection
9363
  if (paste && sel.ranges.length > 1) {
9364
  if (lastCopied && lastCopied.text.join("\n") == inserted) {
9365
  if (sel.ranges.length % lastCopied.text.length == 0) {
9366
+ multiPaste = [];
9367
  for (var i = 0; i < lastCopied.text.length; i++)
9368
+ { multiPaste.push(doc.splitLines(lastCopied.text[i])); }
9369
  }
9370
  } else if (textLines.length == sel.ranges.length) {
9371
+ multiPaste = map(textLines, function (l) { return [l]; });
9372
  }
9373
  }
9374
 
9375
+ var updateInput;
9376
  // Normal behavior is to insert the new text into every selection
9377
  for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
9378
+ var range$$1 = sel.ranges[i$1];
9379
+ var from = range$$1.from(), to = range$$1.to();
9380
+ if (range$$1.empty()) {
9381
  if (deleted && deleted > 0) // Handle deletion
9382
+ { from = Pos(from.line, from.ch - deleted); }
9383
  else if (cm.state.overwrite && !paste) // Handle overwrite
9384
+ { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); }
9385
  else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
9386
+ { from = to = Pos(from.line, 0); }
9387
  }
9388
+ updateInput = cm.curOp.updateInput;
9389
  var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
9390
+ origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")};
9391
+ makeChange(cm.doc, changeEvent);
9392
+ signalLater(cm, "inputRead", cm, changeEvent);
9393
  }
9394
  if (inserted && !paste)
9395
+ { triggerElectric(cm, inserted); }
9396
 
9397
+ ensureCursorVisible(cm);
9398
+ cm.curOp.updateInput = updateInput;
9399
+ cm.curOp.typing = true;
9400
+ cm.state.pasteIncoming = cm.state.cutIncoming = false;
9401
  }
9402
 
9403
  function handlePaste(e, cm) {
9404
+ var pasted = e.clipboardData && e.clipboardData.getData("Text");
9405
  if (pasted) {
9406
+ e.preventDefault();
9407
  if (!cm.isReadOnly() && !cm.options.disableInput)
9408
+ { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }); }
9409
  return true
9410
  }
9411
  }
9413
  function triggerElectric(cm, inserted) {
9414
  // When an 'electric' character is inserted, immediately trigger a reindent
9415
  if (!cm.options.electricChars || !cm.options.smartIndent) { return }
9416
+ var sel = cm.doc.sel;
9417
 
9418
  for (var i = sel.ranges.length - 1; i >= 0; i--) {
9419
+ var range$$1 = sel.ranges[i];
9420
+ if (range$$1.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range$$1.head.line)) { continue }
9421
+ var mode = cm.getModeAt(range$$1.head);
9422
+ var indented = false;
9423
  if (mode.electricChars) {
9424
  for (var j = 0; j < mode.electricChars.length; j++)
9425
  { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
9426
+ indented = indentLine(cm, range$$1.head.line, "smart");
9427
  break
9428
  } }
9429
  } else if (mode.electricInput) {
9430
+ if (mode.electricInput.test(getLine(cm.doc, range$$1.head.line).text.slice(0, range$$1.head.ch)))
9431
+ { indented = indentLine(cm, range$$1.head.line, "smart"); }
9432
  }
9433
+ if (indented) { signalLater(cm, "electricInput", cm, range$$1.head.line); }
9434
  }
9435
  }
9436
 
9437
  function copyableRanges(cm) {
9438
+ var text = [], ranges = [];
9439
  for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
9440
+ var line = cm.doc.sel.ranges[i].head.line;
9441
+ var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
9442
+ ranges.push(lineRange);
9443
+ text.push(cm.getRange(lineRange.anchor, lineRange.head));
9444
  }
9445
  return {text: text, ranges: ranges}
9446
  }
9447
 
9448
  function disableBrowserMagic(field, spellcheck) {
9449
+ field.setAttribute("autocorrect", "off");
9450
+ field.setAttribute("autocapitalize", "off");
9451
+ field.setAttribute("spellcheck", !!spellcheck);
9452
  }
9453
 
9454
  function hiddenTextarea() {
9455
+ var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none");
9456
+ var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
9457
  // The textarea is kept positioned near the cursor to prevent the
9458
  // fact that it'll be scrolled into view on input from scrolling
9459
  // our fake cursor out of view. On webkit, when wrap=off, paste is
9460
  // very slow. So make the area wide instead.
9461
+ if (webkit) { te.style.width = "1000px"; }
9462
+ else { te.setAttribute("wrap", "off"); }
9463
  // If border: 0; -- iOS fails to open keyboard (issue #1287)
9464
+ if (ios) { te.style.border = "1px solid black"; }
9465
+ disableBrowserMagic(te);
9466
  return div
9467
  }
9468
 
9474
  // CodeMirror.prototype, for backwards compatibility and
9475
  // convenience.
9476
 
9477
+ var addEditorMethods = function(CodeMirror) {
9478
+ var optionHandlers = CodeMirror.optionHandlers;
9479
 
9480
+ var helpers = CodeMirror.helpers = {};
9481
 
9482
  CodeMirror.prototype = {
9483
  constructor: CodeMirror,
9484
+ focus: function(){window.focus(); this.display.input.focus();},
9485
 
9486
  setOption: function(option, value) {
9487
+ var options = this.options, old = options[option];
9488
  if (options[option] == value && option != "mode") { return }
9489
+ options[option] = value;
9490
  if (optionHandlers.hasOwnProperty(option))
9491
+ { operation(this, optionHandlers[option])(this, value, old); }
9492
+ signal(this, "optionChange", this, option);
9493
  },
9494
 
9495
  getOption: function(option) {return this.options[option]},
9496
  getDoc: function() {return this.doc},
9497
 
9498
+ addKeyMap: function(map$$1, bottom) {
9499
+ this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map$$1));
9500
  },
9501
+ removeKeyMap: function(map$$1) {
9502
+ var maps = this.state.keyMaps;
9503
  for (var i = 0; i < maps.length; ++i)
9504
+ { if (maps[i] == map$$1 || maps[i].name == map$$1) {
9505
+ maps.splice(i, 1);
9506
  return true
9507
  } }
9508
  },
9509
 
9510
  addOverlay: methodOp(function(spec, options) {
9511
+ var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
9512
  if (mode.startState) { throw new Error("Overlays may not be stateful.") }
9513
  insertSorted(this.state.overlays,
9514
  {mode: mode, modeSpec: spec, opaque: options && options.opaque,
9515
  priority: (options && options.priority) || 0},
9516
+ function (overlay) { return overlay.priority; });
9517
+ this.state.modeGen++;
9518
+ regChange(this);
9519
  }),
9520
  removeOverlay: methodOp(function(spec) {
9521
  var this$1 = this;
9522
 
9523
+ var overlays = this.state.overlays;
9524
  for (var i = 0; i < overlays.length; ++i) {
9525
+ var cur = overlays[i].modeSpec;
9526
  if (cur == spec || typeof spec == "string" && cur.name == spec) {
9527
+ overlays.splice(i, 1);
9528
+ this$1.state.modeGen++;
9529
+ regChange(this$1);
9530
  return
9531
  }
9532
  }
9534
 
9535
  indentLine: methodOp(function(n, dir, aggressive) {
9536
  if (typeof dir != "string" && typeof dir != "number") {
9537
+ if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; }
9538
+ else { dir = dir ? "add" : "subtract"; }
9539
  }
9540
+ if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); }
9541
  }),
9542
  indentSelection: methodOp(function(how) {
9543
  var this$1 = this;
9544
 
9545
+ var ranges = this.doc.sel.ranges, end = -1;
9546
  for (var i = 0; i < ranges.length; i++) {
9547
+ var range$$1 = ranges[i];
9548
+ if (!range$$1.empty()) {
9549
+ var from = range$$1.from(), to = range$$1.to();
9550
+ var start = Math.max(end, from.line);
9551
+ end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
9552
  for (var j = start; j < end; ++j)
9553
+ { indentLine(this$1, j, how); }
9554
+ var newRanges = this$1.doc.sel.ranges;
9555
  if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
9556
+ { replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); }
9557
+ } else if (range$$1.head.line > end) {
9558
+ indentLine(this$1, range$$1.head.line, how, true);
9559
+ end = range$$1.head.line;
9560
+ if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1); }
9561
  }
9562
  }
9563
  }),
9573
  },
9574
 
9575
  getTokenTypeAt: function(pos) {
9576
+ pos = clipPos(this.doc, pos);
9577
+ var styles = getLineStyles(this, getLine(this.doc, pos.line));
9578
+ var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
9579
+ var type;
9580
+ if (ch == 0) { type = styles[2]; }
9581
  else { for (;;) {
9582
+ var mid = (before + after) >> 1;
9583
+ if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; }
9584
+ else if (styles[mid * 2 + 1] < ch) { before = mid + 1; }
9585
  else { type = styles[mid * 2 + 2]; break }
9586
  } }
9587
+ var cut = type ? type.indexOf("overlay ") : -1;
9588
  return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
9589
  },
9590
 
9591
  getModeAt: function(pos) {
9592
+ var mode = this.doc.mode;
9593
  if (!mode.innerMode) { return mode }
9594
  return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
9595
  },
9601
  getHelpers: function(pos, type) {
9602
  var this$1 = this;
9603
 
9604
+ var found = [];
9605
  if (!helpers.hasOwnProperty(type)) { return found }
9606
+ var help = helpers[type], mode = this.getModeAt(pos);
9607
  if (typeof mode[type] == "string") {
9608
+ if (help[mode[type]]) { found.push(help[mode[type]]); }
9609
  } else if (mode[type]) {
9610
  for (var i = 0; i < mode[type].length; i++) {
9611
+ var val = help[mode[type][i]];
9612
+ if (val) { found.push(val); }
9613
  }
9614
  } else if (mode.helperType && help[mode.helperType]) {
9615
+ found.push(help[mode.helperType]);
9616
  } else if (help[mode.name]) {
9617
+ found.push(help[mode.name]);
9618
  }
9619
  for (var i$1 = 0; i$1 < help._global.length; i$1++) {
9620
+ var cur = help._global[i$1];
9621
  if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1)
9622
+ { found.push(cur.val); }
9623
  }
9624
  return found
9625
  },
9626
 
9627
  getStateAfter: function(line, precise) {
9628
+ var doc = this.doc;
9629
+ line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
9630
  return getStateBefore(this, line + 1, precise)
9631
  },
9632
 
9633
  cursorCoords: function(start, mode) {
9634
+ var pos, range$$1 = this.doc.sel.primary();
9635
+ if (start == null) { pos = range$$1.head; }
9636
+ else if (typeof start == "object") { pos = clipPos(this.doc, start); }
9637
+ else { pos = start ? range$$1.from() : range$$1.to(); }
9638
  return cursorCoords(this, pos, mode || "page")
9639
  },
9640
 
9643
  },
9644
 
9645
  coordsChar: function(coords, mode) {
9646
+ coords = fromCoordSystem(this, coords, mode || "page");
9647
  return coordsChar(this, coords.left, coords.top)
9648
  },
9649
 
9650
  lineAtHeight: function(height, mode) {
9651
+ height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
9652
  return lineAtHeight(this.doc, height + this.display.viewOffset)
9653
  },
9654
  heightAtLine: function(line, mode, includeWidgets) {
9655
+ var end = false, lineObj;
9656
  if (typeof line == "number") {
9657
+ var last = this.doc.first + this.doc.size - 1;
9658
+ if (line < this.doc.first) { line = this.doc.first; }
9659
+ else if (line > last) { line = last; end = true; }
9660
+ lineObj = getLine(this.doc, line);
9661
  } else {
9662
+ lineObj = line;
9663
  }
9664
  return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
9665
  (end ? this.doc.height - heightAtLine(lineObj) : 0)
9671
  getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
9672
 
9673
  addWidget: function(pos, node, scroll, vert, horiz) {
9674
+ var display = this.display;
9675
+ pos = cursorCoords(this, clipPos(this.doc, pos));
9676
+ var top = pos.bottom, left = pos.left;
9677
+ node.style.position = "absolute";
9678
+ node.setAttribute("cm-ignore-events", "true");
9679
+ this.display.input.setUneditable(node);
9680
+ display.sizer.appendChild(node);
9681
  if (vert == "over") {
9682
+ top = pos.top;
9683
  } else if (vert == "above" || vert == "near") {
9684
  var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
9685
+ hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
9686
  // Default to positioning above (if specified and possible); otherwise default to positioning below
9687
  if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
9688
+ { top = pos.top - node.offsetHeight; }
9689
  else if (pos.bottom + node.offsetHeight <= vspace)
9690
+ { top = pos.bottom; }
9691
  if (left + node.offsetWidth > hspace)
9692
+ { left = hspace - node.offsetWidth; }
9693
  }
9694
+ node.style.top = top + "px";
9695
+ node.style.left = node.style.right = "";
9696
  if (horiz == "right") {
9697
+ left = display.sizer.clientWidth - node.offsetWidth;
9698
+ node.style.right = "0px";
9699
  } else {
9700
+ if (horiz == "left") { left = 0; }
9701
+ else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; }
9702
+ node.style.left = left + "px";
9703
  }
9704
  if (scroll)
9705
+ { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); }
9706
  },
9707
 
9708
  triggerOnKeyDown: methodOp(onKeyDown),
9714
  { return commands[cmd].call(null, this) }
9715
  },
9716
 
9717
+ triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
9718
 
9719
  findPosH: function(from, amount, unit, visually) {
9720
  var this$1 = this;
9721
 
9722
+ var dir = 1;
9723
+ if (amount < 0) { dir = -1; amount = -amount; }
9724
+ var cur = clipPos(this.doc, from);
9725
  for (var i = 0; i < amount; ++i) {
9726
+ cur = findPosH(this$1.doc, cur, dir, unit, visually);
9727
  if (cur.hitSide) { break }
9728
  }
9729
  return cur
9732
  moveH: methodOp(function(dir, unit) {
9733
  var this$1 = this;
9734
 
9735
+ this.extendSelectionsBy(function (range$$1) {
9736
+ if (this$1.display.shift || this$1.doc.extend || range$$1.empty())
9737
+ { return findPosH(this$1.doc, range$$1.head, dir, unit, this$1.options.rtlMoveVisually) }
9738
  else
9739
+ { return dir < 0 ? range$$1.from() : range$$1.to() }
9740
+ }, sel_move);
9741
  }),
9742
 
9743
  deleteH: methodOp(function(dir, unit) {
9744
+ var sel = this.doc.sel, doc = this.doc;
9745
  if (sel.somethingSelected())
9746
+ { doc.replaceSelection("", null, "+delete"); }
9747
  else
9748
+ { deleteNearSelection(this, function (range$$1) {
9749
+ var other = findPosH(doc, range$$1.head, dir, unit, false);
9750
+ return dir < 0 ? {from: other, to: range$$1.head} : {from: range$$1.head, to: other}
9751
+ }); }
9752
  }),
9753
 
9754
  findPosV: function(from, amount, unit, goalColumn) {
9755
  var this$1 = this;
9756
 
9757
+ var dir = 1, x = goalColumn;
9758
+ if (amount < 0) { dir = -1; amount = -amount; }
9759
+ var cur = clipPos(this.doc, from);
9760
  for (var i = 0; i < amount; ++i) {
9761
+ var coords = cursorCoords(this$1, cur, "div");
9762
+ if (x == null) { x = coords.left; }
9763
+ else { coords.left = x; }
9764
+ cur = findPosV(this$1, coords, dir, unit);
9765
  if (cur.hitSide) { break }
9766
  }
9767
  return cur
9770
  moveV: methodOp(function(dir, unit) {
9771
  var this$1 = this;
9772
 
9773
+ var doc = this.doc, goals = [];
9774
+ var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();
9775
+ doc.extendSelectionsBy(function (range$$1) {
9776
  if (collapse)
9777
+ { return dir < 0 ? range$$1.from() : range$$1.to() }
9778
+ var headPos = cursorCoords(this$1, range$$1.head, "div");
9779
+ if (range$$1.goalColumn != null) { headPos.left = range$$1.goalColumn; }
9780
+ goals.push(headPos.left);
9781
+ var pos = findPosV(this$1, headPos, dir, unit);
9782
+ if (unit == "page" && range$$1 == doc.sel.primary())
9783
+ { addToScrollPos(this$1, null, charCoords(this$1, pos, "div").top - headPos.top); }
9784
  return pos
9785
+ }, sel_move);
9786
  if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
9787
+ { doc.sel.ranges[i].goalColumn = goals[i]; } }
9788
  }),
9789
 
9790
  // Find the word at the given position (as returned by coordsChar).
9791
  findWordAt: function(pos) {
9792
+ var doc = this.doc, line = getLine(doc, pos.line).text;
9793
+ var start = pos.ch, end = pos.ch;
9794
  if (line) {
9795
+ var helper = this.getHelper(pos, "wordChars");
9796
+ if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; }
9797
+ var startChar = line.charAt(start);
9798
  var check = isWordChar(startChar, helper)
9799
  ? function (ch) { return isWordChar(ch, helper); }
9800
  : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
9801
+ : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); };
9802
+ while (start > 0 && check(line.charAt(start - 1))) { --start; }
9803
+ while (end < line.length && check(line.charAt(end))) { ++end; }
9804
  }
9805
  return new Range(Pos(pos.line, start), Pos(pos.line, end))
9806
  },
9808
  toggleOverwrite: function(value) {
9809
  if (value != null && value == this.state.overwrite) { return }
9810
  if (this.state.overwrite = !this.state.overwrite)
9811
+ { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
9812
  else
9813
+ { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
9814
 
9815
+ signal(this, "overwriteToggle", this, this.state.overwrite);
9816
  },
9817
  hasFocus: function() { return this.display.input.getField() == activeElt() },
9818
  isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
9819
 
9820
  scrollTo: methodOp(function(x, y) {
9821
+ if (x != null || y != null) { resolveScrollToPos(this); }
9822
+ if (x != null) { this.curOp.scrollLeft = x; }
9823
+ if (y != null) { this.curOp.scrollTop = y; }
9824
  }),
9825
  getScrollInfo: function() {
9826
+ var scroller = this.display.scroller;
9827
  return {left: scroller.scrollLeft, top: scroller.scrollTop,
9828
  height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
9829
  width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
9830
  clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
9831
  },
9832
 
9833
+ scrollIntoView: methodOp(function(range$$1, margin) {
9834
+ if (range$$1 == null) {
9835
+ range$$1 = {from: this.doc.sel.primary().head, to: null};
9836
+ if (margin == null) { margin = this.options.cursorScrollMargin; }
9837
+ } else if (typeof range$$1 == "number") {
9838
+ range$$1 = {from: Pos(range$$1, 0), to: null};
9839
+ } else if (range$$1.from == null) {
9840
+ range$$1 = {from: range$$1, to: null};
9841
+ }
9842
+ if (!range$$1.to) { range$$1.to = range$$1.from; }
9843
+ range$$1.margin = margin || 0;
9844
+
9845
+ if (range$$1.from.line != null) {
9846
+ resolveScrollToPos(this);
9847
+ this.curOp.scrollToPos = range$$1;
9848
  } else {
9849
+ var sPos = calculateScrollPos(this, {
9850
+ left: Math.min(range$$1.from.left, range$$1.to.left),
9851
+ top: Math.min(range$$1.from.top, range$$1.to.top) - range$$1.margin,
9852
+ right: Math.max(range$$1.from.right, range$$1.to.right),
9853
+ bottom: Math.max(range$$1.from.bottom, range$$1.to.bottom) + range$$1.margin
9854
+ });
9855
+ this.scrollTo(sPos.scrollLeft, sPos.scrollTop);
9856
  }
9857
  }),
9858
 
9859
  setSize: methodOp(function(width, height) {
9860
  var this$1 = this;
9861
 
9862
+ var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; };
9863
+ if (width != null) { this.display.wrapper.style.width = interpret(width); }
9864
+ if (height != null) { this.display.wrapper.style.height = interpret(height); }
9865
+ if (this.options.lineWrapping) { clearLineMeasurementCache(this); }
9866
+ var lineNo$$1 = this.display.viewFrom;
9867
+ this.doc.iter(lineNo$$1, this.display.viewTo, function (line) {
9868
  if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
9869
+ { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo$$1, "widget"); break } } }
9870
+ ++lineNo$$1;
9871
+ });
9872
+ this.curOp.forceUpdate = true;
9873
+ signal(this, "refresh", this);
9874
  }),
9875
 
9876
  operation: function(f){return runInOp(this, f)},
9877
 
9878
  refresh: methodOp(function() {
9879
+ var oldHeight = this.display.cachedTextHeight;
9880
+ regChange(this);
9881
+ this.curOp.forceUpdate = true;
9882
+ clearCaches(this);
9883
+ this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop);
9884
+ updateGutterSpace(this);
9885
  if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
9886
+ { estimateLineHeights(this); }
9887
+ signal(this, "refresh", this);
9888
  }),
9889
 
9890
  swapDoc: methodOp(function(doc) {
9891
+ var old = this.doc;
9892
+ old.cm = null;
9893
+ attachDoc(this, doc);
9894
+ clearCaches(this);
9895
+ this.display.input.reset();
9896
+ this.scrollTo(doc.scrollLeft, doc.scrollTop);
9897
+ this.curOp.forceScroll = true;
9898
+ signalLater(this, "swapDoc", this, old);
9899
  return old
9900
  }),
9901
 
9903
  getWrapperElement: function(){return this.display.wrapper},
9904
  getScrollerElement: function(){return this.display.scroller},
9905
  getGutterElement: function(){return this.display.gutters}
9906
+ };
9907
+ eventMixin(CodeMirror);
9908
 
9909
  CodeMirror.registerHelper = function(type, name, value) {
9910
+ if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; }
9911
+ helpers[type][name] = value;
9912
+ };
9913
  CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
9914
+ CodeMirror.registerHelper(type, name, value);
9915
+ helpers[type]._global.push({pred: predicate, val: value});
9916
+ };
9917
+ };
9918
 
9919
  // Used for horizontal relative motion. Dir is -1 or 1 (left or
9920
  // right), unit can be "char", "column" (like char, but doesn't
9926
  // position. The resulting position will have a hitSide=true
9927
  // property if it reached the end of the document.
9928
  function findPosH(doc, pos, dir, unit, visually) {
9929
+ var oldPos = pos;
9930
+ var origDir = dir;
9931
+ var lineObj = getLine(doc, pos.line);
9932
  function findNextLine() {
9933
+ var l = pos.line + dir;
9934
  if (l < doc.first || l >= doc.first + doc.size) { return false }
9935
+ pos = new Pos(l, pos.ch, pos.sticky);
9936
  return lineObj = getLine(doc, l)
9937
  }
9938
  function moveOnce(boundToLine) {
9939
+ var next;
9940
  if (visually) {
9941
+ next = moveVisually(doc.cm, lineObj, pos, dir);
9942
  } else {
9943
+ next = moveLogically(lineObj, pos, dir);
9944
  }
9945
  if (next == null) {
9946
  if (!boundToLine && findNextLine())
9947
+ { pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir); }
9948
  else
9949
  { return false }
9950
  } else {
9951
+ pos = next;
9952
  }
9953
  return true
9954
  }
9955
 
9956
  if (unit == "char") {
9957
+ moveOnce();
9958
  } else if (unit == "column") {
9959
+ moveOnce(true);
9960
  } else if (unit == "word" || unit == "group") {
9961
+ var sawType = null, group = unit == "group";
9962
+ var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
9963
  for (var first = true;; first = false) {
9964
  if (dir < 0 && !moveOnce(!first)) { break }
9965
+ var cur = lineObj.text.charAt(pos.ch) || "\n";
9966
  var type = isWordChar(cur, helper) ? "w"
9967
  : group && cur == "\n" ? "n"
9968
  : !group || /\s/.test(cur) ? null
9969
+ : "p";
9970
+ if (group && !first && !type) { type = "s"; }
9971
  if (sawType && sawType != type) {
9972
+ if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";}
9973
  break
9974
  }
9975
 
9976
+ if (type) { sawType = type; }
9977
  if (dir > 0 && !moveOnce(!first)) { break }
9978
  }
9979
  }
9980
+ var result = skipAtomic(doc, pos, oldPos, origDir, true);
9981
+ if (equalCursorPos(oldPos, result)) { result.hitSide = true; }
9982
  return result
9983
  }
9984
 
9986
  // "page" or "line". The resulting position will have a hitSide=true
9987
  // property if it reached the end of the document.
9988
  function findPosV(cm, pos, dir, unit) {
9989
+ var doc = cm.doc, x = pos.left, y;
9990
  if (unit == "page") {
9991
+ var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
9992
+ var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);
9993
+ y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
9994
 
9995
  } else if (unit == "line") {
9996
+ y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
9997
  }
9998
+ var target;
9999
  for (;;) {
10000
+ target = coordsChar(cm, x, y);
10001
  if (!target.outside) { break }
10002
  if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
10003
+ y += dir * 5;
10004
  }
10005
  return target
10006
  }
10008
  // CONTENTEDITABLE INPUT STYLE
10009
 
10010
  var ContentEditableInput = function(cm) {
10011
+ this.cm = cm;
10012
+ this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
10013
+ this.polling = new Delayed();
10014
+ this.composing = null;
10015
+ this.gracePeriod = false;
10016
+ this.readDOMTimeout = null;
10017
  };
10018
 
10019
  ContentEditableInput.prototype.init = function (display) {
10020
  var this$1 = this;
10021
 
10022
+ var input = this, cm = input.cm;
10023
+ var div = input.div = display.lineDiv;
10024
+ disableBrowserMagic(div, cm.options.spellcheck);
10025
 
10026
  on(div, "paste", function (e) {
10027
  if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
10028
  // IE doesn't fire input events, so we schedule a read for the pasted content in this way
10029
+ if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20); }
10030
+ });
 
 
10031
 
10032
  on(div, "compositionstart", function (e) {
10033
+ this$1.composing = {data: e.data, done: false};
10034
+ });
10035
  on(div, "compositionupdate", function (e) {
10036
+ if (!this$1.composing) { this$1.composing = {data: e.data, done: false}; }
10037
+ });
10038
  on(div, "compositionend", function (e) {
10039
  if (this$1.composing) {
10040
+ if (e.data != this$1.composing.data) { this$1.readFromDOMSoon(); }
10041
+ this$1.composing.done = true;
10042
  }
10043
+ });
10044
 
10045
+ on(div, "touchstart", function () { return input.forceCompositionEnd(); });
10046
 
10047
  on(div, "input", function () {
10048
+ if (!this$1.composing) { this$1.readFromDOMSoon(); }
10049
+ });
10050
 
10051
  function onCopyCut(e) {
10052
  if (signalDOMEvent(cm, e)) { return }
10053
  if (cm.somethingSelected()) {
10054
+ setLastCopied({lineWise: false, text: cm.getSelections()});
10055
+ if (e.type == "cut") { cm.replaceSelection("", null, "cut"); }
10056
  } else if (!cm.options.lineWiseCopyCut) {
10057
  return
10058
  } else {
10059
+ var ranges = copyableRanges(cm);
10060
+ setLastCopied({lineWise: true, text: ranges.text});
10061
  if (e.type == "cut") {
10062
  cm.operation(function () {
10063
+ cm.setSelections(ranges.ranges, 0, sel_dontScroll);
10064
+ cm.replaceSelection("", null, "cut");
10065
+ });
10066
  }
10067
  }
10068
  if (e.clipboardData) {
10069
+ e.clipboardData.clearData();
10070
+ var content = lastCopied.text.join("\n");
10071
  // iOS exposes the clipboard API, but seems to discard content inserted into it
10072
+ e.clipboardData.setData("Text", content);
10073
  if (e.clipboardData.getData("Text") == content) {
10074
+ e.preventDefault();
10075
  return
10076
  }
10077
  }
10078
  // Old-fashioned briefly-focus-a-textarea hack
10079
+ var kludge = hiddenTextarea(), te = kludge.firstChild;
10080
+ cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
10081
+ te.value = lastCopied.text.join("\n");
10082
+ var hadFocus = document.activeElement;
10083
+ selectInput(te);
10084
  setTimeout(function () {
10085
+ cm.display.lineSpace.removeChild(kludge);
10086
+ hadFocus.focus();
10087
+ if (hadFocus == div) { input.showPrimarySelection(); }
10088
+ }, 50);
10089
  }
10090
+ on(div, "copy", onCopyCut);
10091
+ on(div, "cut", onCopyCut);
10092
  };
10093
 
10094
  ContentEditableInput.prototype.prepareSelection = function () {
10095
+ var result = prepareSelection(this.cm, false);
10096
+ result.focus = this.cm.state.focused;
10097
  return result
10098
  };
10099
 
10100
  ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
10101
  if (!info || !this.cm.display.view.length) { return }
10102
+ if (info.focus || takeFocus) { this.showPrimarySelection(); }
10103
+ this.showMultipleSelections(info);
10104
  };
10105
 
10106
  ContentEditableInput.prototype.showPrimarySelection = function () {
10107
+ var sel = window.getSelection(), prim = this.cm.doc.sel.primary();
10108
+ var curAnchor = domToPos(this.cm, sel.anchorNode, sel.anchorOffset);
10109
+ var curFocus = domToPos(this.cm, sel.focusNode, sel.focusOffset);
10110
  if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
10111
  cmp(minPos(curAnchor, curFocus), prim.from()) == 0 &&
10112
  cmp(maxPos(curAnchor, curFocus), prim.to()) == 0)
10113
  { return }
10114
 
10115
+ var start = posToDOM(this.cm, prim.from());
10116
+ var end = posToDOM(this.cm, prim.to());
10117
+ if (!start && !end) {
10118
+ sel.removeAllRanges();
10119
+ return
10120
+ }
10121
 
10122
+ var view = this.cm.display.view;
10123
+ var old = sel.rangeCount && sel.getRangeAt(0);
10124
  if (!start) {
10125
+ start = {node: view[0].measure.map[2], offset: 0};
10126
  } else if (!end) { // FIXME dangerously hacky
10127
+ var measure = view[view.length - 1].measure;
10128
+ var map$$1 = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
10129
+ end = {node: map$$1[map$$1.length - 1], offset: map$$1[map$$1.length - 2] - map$$1[map$$1.length - 3]};
10130
  }
10131
 
10132
+ var rng;
10133
+ try { rng = range(start.node, start.offset, end.offset, end.node); }
10134
  catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
10135
  if (rng) {
10136
  if (!gecko && this.cm.state.focused) {
10137
+ sel.collapse(start.node, start.offset);
10138
  if (!rng.collapsed) {
10139
+ sel.removeAllRanges();
10140
+ sel.addRange(rng);
10141
  }
10142
  } else {
10143
+ sel.removeAllRanges();
10144
+ sel.addRange(rng);
10145
  }
10146
+ if (old && sel.anchorNode == null) { sel.addRange(old); }
10147
+ else if (gecko) { this.startGracePeriod(); }
10148
  }
10149
+ this.rememberSelection();
10150
  };
10151
 
10152
  ContentEditableInput.prototype.startGracePeriod = function () {
10153
  var this$1 = this;
10154
 
10155
+ clearTimeout(this.gracePeriod);
10156
  this.gracePeriod = setTimeout(function () {
10157
+ this$1.gracePeriod = false;
10158
  if (this$1.selectionChanged())
10159
+ { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }); }
10160
+ }, 20);
10161
  };
10162
 
10163
  ContentEditableInput.prototype.showMultipleSelections = function (info) {
10164
+ removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
10165
+ removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
10166
  };
10167
 
10168
  ContentEditableInput.prototype.rememberSelection = function () {
10169
+ var sel = window.getSelection();
10170
+ this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
10171
+ this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
10172
  };
10173
 
10174
  ContentEditableInput.prototype.selectionInEditor = function () {
10175
+ var sel = window.getSelection();
10176
  if (!sel.rangeCount) { return false }
10177
+ var node = sel.getRangeAt(0).commonAncestorContainer;
10178
  return contains(this.div, node)
10179
  };
10180
 
10181
  ContentEditableInput.prototype.focus = function () {
10182
  if (this.cm.options.readOnly != "nocursor") {
10183
  if (!this.selectionInEditor())
10184
+ { this.showSelection(this.prepareSelection(), true); }
10185
+ this.div.focus();
10186
  }
10187
  };
10188
+ ContentEditableInput.prototype.blur = function () { this.div.blur(); };
10189
  ContentEditableInput.prototype.getField = function () { return this.div };
10190
 
10191
  ContentEditableInput.prototype.supportsTouch = function () { return true };
10192
 
10193
  ContentEditableInput.prototype.receivedFocus = function () {
10194
+ var input = this;
10195
  if (this.selectionInEditor())
10196
+ { this.pollSelection(); }
10197
  else
10198
+ { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }); }
10199
 
10200
  function poll() {
10201
  if (input.cm.state.focused) {
10202
+ input.pollSelection();
10203
+ input.polling.set(input.cm.options.pollInterval, poll);
10204
  }
10205
  }
10206
+ this.polling.set(this.cm.options.pollInterval, poll);
10207
  };
10208
 
10209
  ContentEditableInput.prototype.selectionChanged = function () {
10210
+ var sel = window.getSelection();
10211
  return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
10212
  sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
10213
  };
10214
 
10215
  ContentEditableInput.prototype.pollSelection = function () {
10216
+ if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
10217
+ var sel = window.getSelection(), cm = this.cm;
10218
+ // On Android Chrome (version 56, at least), backspacing into an
10219
+ // uneditable block element will put the cursor in that element,
10220
+ // and then, because it's not editable, hide the virtual keyboard.
10221
+ // Because Android doesn't allow us to actually detect backspace
10222
+ // presses in a sane way, this code checks for when that happens
10223
+ // and simulates a backspace press in this case.
10224
+ if (android && chrome && this.cm.options.gutters.length && isInGutter(sel.anchorNode)) {
10225
+ this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs});
10226
+ this.blur();
10227
+ this.focus();
10228
+ return
10229
  }
10230
+ if (this.composing) { return }
10231
+ this.rememberSelection();
10232
+ var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
10233
+ var head = domToPos(cm, sel.focusNode, sel.focusOffset);
10234
+ if (anchor && head) { runInOp(cm, function () {
10235
+ setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
10236
+ if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true; }
10237
+ }); }
10238
  };
10239
 
10240
  ContentEditableInput.prototype.pollContent = function () {
10241
  if (this.readDOMTimeout != null) {
10242
+ clearTimeout(this.readDOMTimeout);
10243
+ this.readDOMTimeout = null;
10244
  }
10245
 
10246
+ var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
10247
+ var from = sel.from(), to = sel.to();
10248
  if (from.ch == 0 && from.line > cm.firstLine())
10249
+ { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length); }
10250
  if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
10251
+ { to = Pos(to.line + 1, 0); }
10252
  if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
10253
 
10254
+ var fromIndex, fromLine, fromNode;
10255
  if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
10256
+ fromLine = lineNo(display.view[0].line);
10257
+ fromNode = display.view[0].node;
10258
  } else {
10259
+ fromLine = lineNo(display.view[fromIndex].line);
10260
+ fromNode = display.view[fromIndex - 1].node.nextSibling;
10261
  }
10262
+ var toIndex = findViewIndex(cm, to.line);
10263
+ var toLine, toNode;
10264
  if (toIndex == display.view.length - 1) {
10265
+ toLine = display.viewTo - 1;
10266
+ toNode = display.lineDiv.lastChild;
10267
  } else {
10268
+ toLine = lineNo(display.view[toIndex + 1].line) - 1;
10269
+ toNode = display.view[toIndex + 1].node.previousSibling;
10270
  }
10271
 
10272
  if (!fromNode) { return false }
10273
+ var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
10274
+ var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
10275
  while (newText.length > 1 && oldText.length > 1) {
10276
+ if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
10277
+ else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
10278
  else { break }
10279
  }
10280
 
10281
+ var cutFront = 0, cutEnd = 0;
10282
+ var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
10283
  while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
10284
+ { ++cutFront; }
10285
+ var newBot = lst(newText), oldBot = lst(oldText);
10286
  var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
10287
+ oldBot.length - (oldText.length == 1 ? cutFront : 0));
10288
  while (cutEnd < maxCutEnd &&
10289
  newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
10290
+ { ++cutEnd; }
10291
+ // Try to move start of change to start of selection if ambiguous
10292
+ if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
10293
+ while (cutFront && cutFront > from.ch &&
10294
+ newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
10295
+ cutFront--;
10296
+ cutEnd++;
10297
+ }
10298
+ }
10299
 
10300
+ newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
10301
+ newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
10302
 
10303
+ var chFrom = Pos(fromLine, cutFront);
10304
+ var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
10305
  if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
10306
+ replaceRange(cm.doc, newText, chFrom, chTo, "+input");
10307
  return true
10308
  }
10309
  };
10310
 
10311
  ContentEditableInput.prototype.ensurePolled = function () {
10312
+ this.forceCompositionEnd();
10313
  };
10314
  ContentEditableInput.prototype.reset = function () {
10315
+ this.forceCompositionEnd();
10316
  };
10317
  ContentEditableInput.prototype.forceCompositionEnd = function () {
10318
  if (!this.composing) { return }
10319
+ clearTimeout(this.readDOMTimeout);
10320
+ this.composing = null;
10321
+ this.updateFromDOM();
10322
+ this.div.blur();
10323
+ this.div.focus();
10324
  };
10325
  ContentEditableInput.prototype.readFromDOMSoon = function () {
10326
  var this$1 = this;
10327
 
10328
  if (this.readDOMTimeout != null) { return }
10329
  this.readDOMTimeout = setTimeout(function () {
10330
+ this$1.readDOMTimeout = null;
10331
  if (this$1.composing) {
10332
+ if (this$1.composing.done) { this$1.composing = null; }
10333
  else { return }
10334
  }
10335
+ this$1.updateFromDOM();
10336
+ }, 80);
10337
+ };
10338
+
10339
+ ContentEditableInput.prototype.updateFromDOM = function () {
10340
+ var this$1 = this;
10341
+
10342
+ if (this.cm.isReadOnly() || !this.pollContent())
10343
+ { runInOp(this.cm, function () { return regChange(this$1.cm); }); }
10344
  };
10345
 
10346
  ContentEditableInput.prototype.setUneditable = function (node) {
10347
+ node.contentEditable = "false";
10348
  };
10349
 
10350
  ContentEditableInput.prototype.onKeyPress = function (e) {
10351
  if (e.charCode == 0) { return }
10352
+ e.preventDefault();
10353
  if (!this.cm.isReadOnly())
10354
+ { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); }
10355
  };
10356
 
10357
  ContentEditableInput.prototype.readOnlyChanged = function (val) {
10358
+ this.div.contentEditable = String(val != "nocursor");
10359
  };
10360
 
10361
  ContentEditableInput.prototype.onContextMenu = function () {};
10362
  ContentEditableInput.prototype.resetPosition = function () {};
10363
 
10364
+ ContentEditableInput.prototype.needsContentAttribute = true;
10365
 
10366
  function posToDOM(cm, pos) {
10367
+ var view = findViewForLine(cm, pos.line);
10368
  if (!view || view.hidden) { return null }
10369
+ var line = getLine(cm.doc, pos.line);
10370
+ var info = mapFromLineView(view, line, pos.line);
10371
 
10372
+ var order = getOrder(line, cm.doc.direction), side = "left";
10373
  if (order) {
10374
+ var partPos = getBidiPartAt(order, pos.ch);
10375
+ side = partPos % 2 ? "right" : "left";
10376
  }
10377
+ var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
10378
+ result.offset = result.collapse == "right" ? result.end : result.start;
10379
  return result
10380
  }
10381
 
10382
+ function isInGutter(node) {
10383
+ for (var scan = node; scan; scan = scan.parentNode)
10384
+ { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
10385
+ return false
10386
+ }
10387
+
10388
  function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
10389
 
10390
  function domTextBetween(cm, from, to, fromLine, toLine) {
10391
+ var text = "", closing = false, lineSep = cm.doc.lineSeparator();
10392
  function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
10393
+ function close() {
10394
+ if (closing) {
10395
+ text += lineSep;
10396
+ closing = false;
10397
+ }
10398
+ }
10399
+ function addText(str) {
10400
+ if (str) {
10401
+ close();
10402
+ text += str;
10403
+ }
10404
+ }
10405
  function walk(node) {
10406
  if (node.nodeType == 1) {
10407
+ var cmText = node.getAttribute("cm-text");
10408
  if (cmText != null) {
10409
+ addText(cmText || node.textContent.replace(/\u200b/g, ""));
 
10410
  return
10411
  }
10412
+ var markerID = node.getAttribute("cm-marker"), range$$1;
10413
  if (markerID) {
10414
+ var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
10415
+ if (found.length && (range$$1 = found[0].find()))
10416
+ { addText(getBetween(cm.doc, range$$1.from, range$$1.to).join(lineSep)); }
10417
  return
10418
  }
10419
  if (node.getAttribute("contenteditable") == "false") { return }
10420
+ var isBlock = /^(pre|div|p)$/i.test(node.nodeName);
10421
+ if (isBlock) { close(); }
10422
  for (var i = 0; i < node.childNodes.length; i++)
10423
+ { walk(node.childNodes[i]); }
10424
+ if (isBlock) { closing = true; }
 
10425
  } else if (node.nodeType == 3) {
10426
+ addText(node.nodeValue);
 
 
 
 
 
 
10427
  }
10428
  }
10429
  for (;;) {
10430
+ walk(from);
10431
  if (from == to) { break }
10432
+ from = from.nextSibling;
10433
  }
10434
  return text
10435
  }
10436
 
10437
  function domToPos(cm, node, offset) {
10438
+ var lineNode;
10439
  if (node == cm.display.lineDiv) {
10440
+ lineNode = cm.display.lineDiv.childNodes[offset];
10441
  if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
10442
+ node = null; offset = 0;
10443
  } else {
10444
  for (lineNode = node;; lineNode = lineNode.parentNode) {
10445
  if (!lineNode || lineNode == cm.display.lineDiv) { return null }
10447
  }
10448
  }
10449
  for (var i = 0; i < cm.display.view.length; i++) {
10450
+ var lineView = cm.display.view[i];
10451
  if (lineView.node == lineNode)
10452
  { return locateNodeInLineView(lineView, node, offset) }
10453
  }
10454
  }
10455
 
10456
  function locateNodeInLineView(lineView, node, offset) {
10457
+ var wrapper = lineView.text.firstChild, bad = false;
10458
  if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
10459
  if (node == wrapper) {
10460
+ bad = true;
10461
+ node = wrapper.childNodes[offset];
10462
+ offset = 0;
10463
  if (!node) {
10464
+ var line = lineView.rest ? lst(lineView.rest) : lineView.line;
10465
  return badPos(Pos(lineNo(line), line.text.length), bad)
10466
  }
10467
  }
10468
 
10469
+ var textNode = node.nodeType == 3 ? node : null, topNode = node;
10470
  if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
10471
+ textNode = node.firstChild;
10472
+ if (offset) { offset = textNode.nodeValue.length; }
10473
  }
10474
+ while (topNode.parentNode != wrapper) { topNode = topNode.parentNode; }
10475
+ var measure = lineView.measure, maps = measure.maps;
10476
 
10477
  function find(textNode, topNode, offset) {
10478
  for (var i = -1; i < (maps ? maps.length : 0); i++) {
10479
+ var map$$1 = i < 0 ? measure.map : maps[i];
10480
+ for (var j = 0; j < map$$1.length; j += 3) {
10481
+ var curNode = map$$1[j + 2];
10482
  if (curNode == textNode || curNode == topNode) {
10483
+ var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
10484
+ var ch = map$$1[j] + offset;
10485
+ if (offset < 0 || curNode != textNode) { ch = map$$1[j + (offset ? 1 : 0)]; }
10486
  return Pos(line, ch)
10487
  }
10488
  }
10489
  }
10490
  }
10491
+ var found = find(textNode, topNode, offset);
10492
  if (found) { return badPos(found, bad) }
10493
 
10494
  // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
10495
  for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
10496
+ found = find(after, after.firstChild, 0);
10497
  if (found)
10498
  { return badPos(Pos(found.line, found.ch - dist), bad) }
10499
  else
10500
+ { dist += after.textContent.length; }
10501
  }
10502
  for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
10503
+ found = find(before, before.firstChild, -1);
10504
  if (found)
10505
  { return badPos(Pos(found.line, found.ch + dist$1), bad) }
10506
  else
10507
+ { dist$1 += before.textContent.length; }
10508
  }
10509
  }
10510
 
10511
  // TEXTAREA INPUT STYLE
10512
 
10513
  var TextareaInput = function(cm) {
10514
+ this.cm = cm;
10515
  // See input.poll and input.reset
10516
+ this.prevInput = "";
10517
 
10518
  // Flag that indicates whether we expect input to appear real soon
10519
  // now (after some event like 'keypress' or 'input') and are
10520
  // polling intensively.
10521
+ this.pollingFast = false;
10522
  // Self-resetting timeout for the poller
10523
+ this.polling = new Delayed();
10524
  // Tracks when input.reset has punted to just putting a short
10525
  // string into the textarea instead of the full selection.
10526
+ this.inaccurateSelection = false;
10527
  // Used to work around IE issue with selection being forgotten when focus moves away from textarea
10528
+ this.hasSelection = false;
10529
+ this.composing = null;
10530
  };
10531
 
10532
  TextareaInput.prototype.init = function (display) {
10533
  var this$1 = this;
10534
 
10535
+ var input = this, cm = this.cm;
10536
 
10537
  // Wraps and hides input textarea
10538
+ var div = this.wrapper = hiddenTextarea();
10539
  // The semihidden textarea that is focused when the editor is
10540
  // focused, and receives input.
10541
+ var te = this.textarea = div.firstChild;
10542
+ display.wrapper.insertBefore(div, display.wrapper.firstChild);
10543
 
10544
  // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
10545
+ if (ios) { te.style.width = "0px"; }
10546
 
10547
  on(te, "input", function () {
10548
+ if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null; }
10549
+ input.poll();
10550
+ });
10551
 
10552
  on(te, "paste", function (e) {
10553
  if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
10554
 
10555
+ cm.state.pasteIncoming = true;
10556
+ input.fastPoll();
10557
+ });
10558
 
10559
  function prepareCopyCut(e) {
10560
  if (signalDOMEvent(cm, e)) { return }
10561
  if (cm.somethingSelected()) {
10562
+ setLastCopied({lineWise: false, text: cm.getSelections()});
10563
  if (input.inaccurateSelection) {
10564
+ input.prevInput = "";
10565
+ input.inaccurateSelection = false;
10566
+ te.value = lastCopied.text.join("\n");
10567
+ selectInput(te);
10568
  }
10569
  } else if (!cm.options.lineWiseCopyCut) {
10570
  return
10571
  } else {
10572
+ var ranges = copyableRanges(cm);
10573
+ setLastCopied({lineWise: true, text: ranges.text});
10574
  if (e.type == "cut") {
10575
+ cm.setSelections(ranges.ranges, null, sel_dontScroll);
10576
  } else {
10577
+ input.prevInput = "";
10578
+ te.value = ranges.text.join("\n");
10579
+ selectInput(te);
10580
  }
10581
  }
10582
+ if (e.type == "cut") { cm.state.cutIncoming = true; }
10583
  }
10584
+ on(te, "cut", prepareCopyCut);
10585
+ on(te, "copy", prepareCopyCut);
10586
 
10587
  on(display.scroller, "paste", function (e) {
10588
  if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
10589
+ cm.state.pasteIncoming = true;
10590
+ input.focus();
10591
+ });
10592
 
10593
  // Prevent normal selection in the editor (we handle our own)
10594
  on(display.lineSpace, "selectstart", function (e) {
10595
+ if (!eventInWidget(display, e)) { e_preventDefault(e); }
10596
+ });
10597
 
10598
  on(te, "compositionstart", function () {
10599
+ var start = cm.getCursor("from");
10600
+ if (input.composing) { input.composing.range.clear(); }
10601
  input.composing = {
10602
  start: start,
10603
  range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
10604
+ };
10605
+ });
10606
  on(te, "compositionend", function () {
10607
  if (input.composing) {
10608
+ input.poll();
10609
+ input.composing.range.clear();
10610
+ input.composing = null;
10611
  }
10612
+ });
10613
  };
10614
 
10615
  TextareaInput.prototype.prepareSelection = function () {
10616
  // Redraw the selection and/or cursor
10617
+ var cm = this.cm, display = cm.display, doc = cm.doc;
10618
+ var result = prepareSelection(cm);
10619
 
10620
  // Move the hidden textarea near the cursor to prevent scrolling artifacts
10621
  if (cm.options.moveInputWithCursor) {
10622
+ var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
10623
+ var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
10624
  result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
10625
+ headPos.top + lineOff.top - wrapOff.top));
10626
  result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
10627
+ headPos.left + lineOff.left - wrapOff.left));
10628
  }
10629
 
10630
  return result
10631
  };
10632
 
10633
  TextareaInput.prototype.showSelection = function (drawn) {
10634
+ var cm = this.cm, display = cm.display;
10635
+ removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
10636
+ removeChildrenAndAdd(display.selectionDiv, drawn.selection);
10637
  if (drawn.teTop != null) {
10638
+ this.wrapper.style.top = drawn.teTop + "px";
10639
+ this.wrapper.style.left = drawn.teLeft + "px";
10640
  }
10641
  };
10642
 
10644
  // when not typing and nothing is selected)
10645
  TextareaInput.prototype.reset = function (typing) {
10646
  if (this.contextMenuPending) { return }
10647
+ var minimal, selected, cm = this.cm, doc = cm.doc;
10648
  if (cm.somethingSelected()) {
10649
+ this.prevInput = "";
10650
+ var range$$1 = doc.sel.primary();
10651
  minimal = hasCopyEvent &&
10652
+ (range$$1.to().line - range$$1.from().line > 100 || (selected = cm.getSelection()).length > 1000);
10653
+ var content = minimal ? "-" : selected || cm.getSelection();
10654
+ this.textarea.value = content;
10655
+ if (cm.state.focused) { selectInput(this.textarea); }
10656
+ if (ie && ie_version >= 9) { this.hasSelection = content; }
10657
  } else if (!typing) {
10658
+ this.prevInput = this.textarea.value = "";
10659
+ if (ie && ie_version >= 9) { this.hasSelection = null; }
10660
  }
10661
+ this.inaccurateSelection = minimal;
10662
  };
10663
 
10664
  TextareaInput.prototype.getField = function () { return this.textarea };
10667
 
10668
  TextareaInput.prototype.focus = function () {
10669
  if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
10670
+ try { this.textarea.focus(); }
10671
  catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
10672
  }
10673
  };
10674
 
10675
+ TextareaInput.prototype.blur = function () { this.textarea.blur(); };
10676
 
10677
  TextareaInput.prototype.resetPosition = function () {
10678
+ this.wrapper.style.top = this.wrapper.style.left = 0;
10679
  };
10680
 
10681
+ TextareaInput.prototype.receivedFocus = function () { this.slowPoll(); };
10682
 
10683
  // Poll for input changes, using the normal rate of polling. This
10684
  // runs as long as the editor is focused.
10687
 
10688
  if (this.pollingFast) { return }
10689
  this.polling.set(this.cm.options.pollInterval, function () {
10690
+ this$1.poll();
10691
+ if (this$1.cm.state.focused) { this$1.slowPoll(); }
10692
+ });
10693
  };
10694
 
10695
  // When an event has just come in that is likely to add or change
10696
  // something in the input textarea, we poll faster, to ensure that
10697
  // the change appears on the screen quickly.
10698
  TextareaInput.prototype.fastPoll = function () {
10699
+ var missed = false, input = this;
10700
+ input.pollingFast = true;
10701
  function p() {
10702
+ var changed = input.poll();
10703
+ if (!changed && !missed) {missed = true; input.polling.set(60, p);}
10704
+ else {input.pollingFast = false; input.slowPoll();}
10705
  }
10706
+ input.polling.set(20, p);
10707
  };
10708
 
10709
  // Read input from the textarea, and update the document to match.
10715
  TextareaInput.prototype.poll = function () {
10716
  var this$1 = this;
10717
 
10718
+ var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
10719
  // Since this is called a *lot*, try to bail out as cheaply as
10720
  // possible when it is clear that nothing happened. hasSelection
10721
  // will be the case when there is a lot of text in the textarea,
10725
  cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
10726
  { return false }
10727
 
10728
+ var text = input.value;
10729
  // If nothing changed, bail.
10730
  if (text == prevInput && !cm.somethingSelected()) { return false }
10731
  // Work around nonsensical selection resetting in IE9/10, and
10733
  // some key combos in Mac (#2689).
10734
  if (ie && ie_version >= 9 && this.hasSelection === text ||
10735
  mac && /[\uf700-\uf7ff]/.test(text)) {
10736
+ cm.display.input.reset();
10737
  return false
10738
  }
10739
 
10740
  if (cm.doc.sel == cm.display.selForContextMenu) {
10741
+ var first = text.charCodeAt(0);
10742
+ if (first == 0x200b && !prevInput) { prevInput = "\u200b"; }
10743
  if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
10744
  }
10745
  // Find the part of the input that is actually new
10746
+ var same = 0, l = Math.min(prevInput.length, text.length);
10747
+ while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same; }
10748
 
10749
  runInOp(cm, function () {
10750
  applyTextInput(cm, text.slice(same), prevInput.length - same,
10751
+ null, this$1.composing ? "*compose" : null);
10752
 
10753
  // Don't leave long text in the textarea, since it makes further polling slow
10754
+ if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = ""; }
10755
+ else { this$1.prevInput = text; }
10756
 
10757
  if (this$1.composing) {
10758
+ this$1.composing.range.clear();
10759
  this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
10760
+ {className: "CodeMirror-composing"});
10761
  }
10762
+ });
10763
  return true
10764
  };
10765
 
10766
  TextareaInput.prototype.ensurePolled = function () {
10767
+ if (this.pollingFast && this.poll()) { this.pollingFast = false; }
10768
  };
10769
 
10770
  TextareaInput.prototype.onKeyPress = function () {
10771
+ if (ie && ie_version >= 9) { this.hasSelection = null; }
10772
+ this.fastPoll();
10773
  };
10774
 
10775
  TextareaInput.prototype.onContextMenu = function (e) {
10776
+ var input = this, cm = input.cm, display = cm.display, te = input.textarea;
10777
+ var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
10778
  if (!pos || presto) { return } // Opera is difficult.
10779
 
10780
  // Reset the current text selection only if the click is done outside of the selection
10781
  // and 'resetSelectionOnContextMenu' option is true.
10782
+ var reset = cm.options.resetSelectionOnContextMenu;
10783
  if (reset && cm.doc.sel.contains(pos) == -1)
10784
+ { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); }
10785
+
10786
+ var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
10787
+ input.wrapper.style.cssText = "position: absolute";
10788
+ var wrapperBox = input.wrapper.getBoundingClientRect();
10789
+ te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
10790
+ var oldScrollY;
10791
+ if (webkit) { oldScrollY = window.scrollY; } // Work around Chrome issue (#2712)
10792
+ display.input.focus();
10793
+ if (webkit) { window.scrollTo(null, oldScrollY); }
10794
+ display.input.reset();
10795
  // Adds "Select all" to context menu in FF
10796
+ if (!cm.somethingSelected()) { te.value = input.prevInput = " "; }
10797
+ input.contextMenuPending = true;
10798
+ display.selForContextMenu = cm.doc.sel;
10799
+ clearTimeout(display.detectingSelectAll);
10800
 
10801
  // Select-all will be greyed out if there's nothing to select, so
10802
  // this adds a zero-width space so that we can later check whether
10803
  // it got selected.
10804
  function prepareSelectAllHack() {
10805
  if (te.selectionStart != null) {
10806
+ var selected = cm.somethingSelected();
10807
+ var extval = "\u200b" + (selected ? te.value : "");
10808
+ te.value = "\u21da"; // Used to catch context-menu undo
10809
+ te.value = extval;
10810
+ input.prevInput = selected ? "" : "\u200b";
10811
+ te.selectionStart = 1; te.selectionEnd = extval.length;
10812
  // Re-set this, in case some other handler touched the
10813
  // selection in the meantime.
10814
+ display.selForContextMenu = cm.doc.sel;
10815
  }
10816
  }
10817
  function rehide() {
10818
+ input.contextMenuPending = false;
10819
+ input.wrapper.style.cssText = oldWrapperCSS;
10820
+ te.style.cssText = oldCSS;
10821
+ if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); }
10822
 
10823
  // Try to detect the user choosing select-all
10824
  if (te.selectionStart != null) {
10825
+ if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack(); }
10826
  var i = 0, poll = function () {
10827
  if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
10828
  te.selectionEnd > 0 && input.prevInput == "\u200b") {
10829
+ operation(cm, selectAll)(cm);
10830
  } else if (i++ < 10) {
10831
+ display.detectingSelectAll = setTimeout(poll, 500);
10832
  } else {
10833
+ display.selForContextMenu = null;
10834
+ display.input.reset();
10835
  }
10836
+ };
10837
+ display.detectingSelectAll = setTimeout(poll, 200);
10838
  }
10839
  }
10840
 
10841
+ if (ie && ie_version >= 9) { prepareSelectAllHack(); }
10842
  if (captureRightClick) {
10843
+ e_stop(e);
10844
  var mouseup = function () {
10845
+ off(window, "mouseup", mouseup);
10846
+ setTimeout(rehide, 20);
10847
+ };
10848
+ on(window, "mouseup", mouseup);
10849
  } else {
10850
+ setTimeout(rehide, 50);
10851
  }
10852
  };
10853
 
10854
  TextareaInput.prototype.readOnlyChanged = function (val) {
10855
+ if (!val) { this.reset(); }
10856
  };
10857
 
10858
  TextareaInput.prototype.setUneditable = function () {};
10859
 
10860
+ TextareaInput.prototype.needsContentAttribute = false;
10861
 
10862
  function fromTextArea(textarea, options) {
10863
+ options = options ? copyObj(options) : {};
10864
+ options.value = textarea.value;
10865
  if (!options.tabindex && textarea.tabIndex)
10866
+ { options.tabindex = textarea.tabIndex; }
10867
  if (!options.placeholder && textarea.placeholder)
10868
+ { options.placeholder = textarea.placeholder; }
10869
  // Set autofocus to true if this textarea is focused, or if it has
10870
  // autofocus and no other element is focused.
10871
  if (options.autofocus == null) {
10872
+ var hasFocus = activeElt();
10873
  options.autofocus = hasFocus == textarea ||
10874
+ textarea.getAttribute("autofocus") != null && hasFocus == document.body;
10875
  }
10876
 
10877
+ function save() {textarea.value = cm.getValue();}
10878
 
10879
+ var realSubmit;
10880
  if (textarea.form) {
10881
+ on(textarea.form, "submit", save);
10882
  // Deplorable hack to make the submit method do the right thing.
10883
  if (!options.leaveSubmitMethodAlone) {
10884
+ var form = textarea.form;
10885
+ realSubmit = form.submit;
10886
  try {
10887
  var wrappedSubmit = form.submit = function () {
10888
+ save();
10889
+ form.submit = realSubmit;
10890
+ form.submit();
10891
+ form.submit = wrappedSubmit;
10892
+ };
10893
  } catch(e) {}
10894
  }
10895
  }
10896
 
10897
  options.finishInit = function (cm) {
10898
+ cm.save = save;
10899
+ cm.getTextArea = function () { return textarea; };
10900
  cm.toTextArea = function () {
10901
+ cm.toTextArea = isNaN; // Prevent this from being ran twice
10902
+ save();
10903
+ textarea.parentNode.removeChild(cm.getWrapperElement());
10904
+ textarea.style.display = "";
10905
  if (textarea.form) {
10906
+ off(textarea.form, "submit", save);
10907
  if (typeof textarea.form.submit == "function")
10908
+ { textarea.form.submit = realSubmit; }
10909
  }
10910
+ };
10911
+ };
10912
 
10913
+ textarea.style.display = "none";
10914
+ var cm = CodeMirror$1(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
10915
+ options);
10916
  return cm
10917
  }
10918
 
10919
  function addLegacyProps(CodeMirror) {
10920
+ CodeMirror.off = off;
10921
+ CodeMirror.on = on;
10922
+ CodeMirror.wheelEventPixels = wheelEventPixels;
10923
+ CodeMirror.Doc = Doc;
10924
+ CodeMirror.splitLines = splitLinesAuto;
10925
+ CodeMirror.countColumn = countColumn;
10926
+ CodeMirror.findColumn = findColumn;
10927
+ CodeMirror.isWordChar = isWordCharBasic;
10928
+ CodeMirror.Pass = Pass;
10929
+ CodeMirror.signal = signal;
10930
+ CodeMirror.Line = Line;
10931
+ CodeMirror.changeEnd = changeEnd;
10932
+ CodeMirror.scrollbarModel = scrollbarModel;
10933
+ CodeMirror.Pos = Pos;
10934
+ CodeMirror.cmpPos = cmp;
10935
+ CodeMirror.modes = modes;
10936
+ CodeMirror.mimeModes = mimeModes;
10937
+ CodeMirror.resolveMode = resolveMode;
10938
+ CodeMirror.getMode = getMode;
10939
+ CodeMirror.modeExtensions = modeExtensions;
10940
+ CodeMirror.extendMode = extendMode;
10941
+ CodeMirror.copyState = copyState;
10942
+ CodeMirror.startState = startState;
10943
+ CodeMirror.innerMode = innerMode;
10944
+ CodeMirror.commands = commands;
10945
+ CodeMirror.keyMap = keyMap;
10946
+ CodeMirror.keyName = keyName;
10947
+ CodeMirror.isModifierKey = isModifierKey;
10948
+ CodeMirror.lookupKey = lookupKey;
10949
+ CodeMirror.normalizeKeyMap = normalizeKeyMap;
10950
+ CodeMirror.StringStream = StringStream;
10951
+ CodeMirror.SharedTextMarker = SharedTextMarker;
10952
+ CodeMirror.TextMarker = TextMarker;
10953
+ CodeMirror.LineWidget = LineWidget;
10954
+ CodeMirror.e_preventDefault = e_preventDefault;
10955
+ CodeMirror.e_stopPropagation = e_stopPropagation;
10956
+ CodeMirror.e_stop = e_stop;
10957
+ CodeMirror.addClass = addClass;
10958
+ CodeMirror.contains = contains;
10959
+ CodeMirror.rmClass = rmClass;
10960
+ CodeMirror.keyNames = keyNames;
10961
  }
10962
 
10963
  // EDITOR CONSTRUCTOR
10964
 
10965
+ defineOptions(CodeMirror$1);
10966
 
10967
+ addEditorMethods(CodeMirror$1);
10968
 
10969
  // Set up methods on CodeMirror's prototype to redirect to the editor's document.
10970
+ var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
10971
  for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
10972
+ { CodeMirror$1.prototype[prop] = (function(method) {
10973
  return function() {return method.apply(this.doc, arguments)}
10974
+ })(Doc.prototype[prop]); } }
10975
 
10976
+ eventMixin(Doc);
10977
 
10978
  // INPUT HANDLING
10979
 
10980
+ CodeMirror$1.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
10981
 
10982
  // MODE DEFINITION AND QUERYING
10983
 
10984
  // Extra arguments are stored as the mode's dependencies, which is
10985
  // used by (legacy) mechanisms like loadmode.js to automatically
10986
  // load a mode. (Preferred mechanism is the require/define calls.)
10987
+ CodeMirror$1.defineMode = function(name/*, mode, …*/) {
10988
+ if (!CodeMirror$1.defaults.mode && name != "null") { CodeMirror$1.defaults.mode = name; }
10989
+ defineMode.apply(this, arguments);
10990
+ };
10991
 
10992
+ CodeMirror$1.defineMIME = defineMIME;
10993
 
10994
  // Minimal default mode.
10995
+ CodeMirror$1.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });
10996
+ CodeMirror$1.defineMIME("text/plain", "null");
10997
 
10998
  // EXTENSIONS
10999
 
11000
+ CodeMirror$1.defineExtension = function (name, func) {
11001
+ CodeMirror$1.prototype[name] = func;
11002
+ };
11003
+ CodeMirror$1.defineDocExtension = function (name, func) {
11004
+ Doc.prototype[name] = func;
11005
+ };
11006
 
11007
+ CodeMirror$1.fromTextArea = fromTextArea;
11008
 
11009
+ addLegacyProps(CodeMirror$1);
11010
 
11011
+ CodeMirror$1.version = "5.25.0";
11012
 
11013
+ return CodeMirror$1;
11014
 
11015
  })));
11016
+
11017
  },{}],16:[function(require,module,exports){
11018
  // CodeMirror, copyright (c) by Marijn Haverbeke and others
11019
  // Distributed under an MIT license: http://codemirror.net/LICENSE
11684
  "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali",
11685
  "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "spell-out", "square",
11686
  "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
11687
+ "subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "system-ui", "table",
11688
  "table-caption", "table-cell", "table-column", "table-column-group",
11689
  "table-footer-group", "table-header-group", "table-row", "table-row-group",
11690
  "tamil",
12638
  if (type == "variable") {register(value); return cont(classNameAfter);}
12639
  }
12640
  function classNameAfter(type, value) {
12641
+ if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, classNameAfter)
12642
  if (value == "extends" || value == "implements" || (isTS && type == ","))
12643
  return cont(isTS ? typeexpr : expression, classNameAfter);
12644
  if (type == "{") return cont(pushlex("}"), classBody, poplex);
12666
  function classfield(type, value) {
12667
  if (value == "?") return cont(classfield)
12668
  if (type == ":") return cont(typeexpr, maybeAssign)
12669
+ if (value == "=") return cont(expressionNoComma)
12670
  return pass(functiondef)
12671
  }
12672
  function afterExport(type, value) {
13739
  prettyPrint: style_html
13740
  };
13741
  },{}],21:[function(require,module,exports){
13742
+ "use strict"
13743
+
13744
  module.exports = require("./stream/stream")
13745
+
13746
  },{"./stream/stream":22}],22:[function(require,module,exports){
13747
  "use strict"
13748
 
13749
+ ;(function() {
13750
+
13751
  var guid = 0, HALT = {}
13752
  function createStream() {
13753
  function stream() {
13762
  }
13763
  function initStream(stream) {
13764
  stream.constructor = createStream
13765
+ stream._state = {id: guid++, value: undefined, state: 0, derive: undefined, recover: undefined, deps: {}, parents: [], endStream: undefined, unregister: undefined}
13766
  stream.map = stream["fantasy-land/map"] = map, stream["fantasy-land/ap"] = ap, stream["fantasy-land/of"] = createStream
13767
  stream.valueOf = valueOf, stream.toJSON = toJSON, stream.toString = valueOf
13768
 
13771
  if (!stream._state.endStream) {
13772
  var endStream = createStream()
13773
  endStream.map(function(value) {
13774
+ if (value === true) {
13775
+ unregisterStream(stream)
13776
+ endStream._state.unregister = function(){unregisterStream(endStream)}
13777
+ }
13778
  return value
13779
  })
13780
  stream._state.endStream = endStream
13786
  function updateStream(stream, value) {
13787
  updateState(stream, value)
13788
  for (var id in stream._state.deps) updateDependency(stream._state.deps[id], false)
13789
+ if (stream._state.unregister != null) stream._state.unregister()
13790
  finalize(stream)
13791
  }
13792
  function updateState(stream, value) {
13808
  }
13809
 
13810
  function combine(fn, streams) {
13811
+ if (!streams.every(valid)) throw new Error("Ensure that each item passed to stream.combine/stream.merge is a stream")
13812
  return initDependency(createStream(), streams, function() {
13813
  return fn.apply(this, streams.concat([streams.filter(changed)]))
13814
  })
13859
  return streams.map(function(s) {return s()})
13860
  }, streams)
13861
  }
13862
+
13863
+ function scan(reducer, seed, stream) {
13864
+ var newStream = combine(function (s) {
13865
+ return seed = reducer(seed, s._state.value)
13866
+ }, [stream])
13867
+
13868
+ if (newStream._state.state === 0) newStream(seed)
13869
+
13870
+ return newStream
13871
+ }
13872
+
13873
+ function scanMerge(tuples, seed) {
13874
+ var streams = tuples.map(function(tuple) {
13875
+ var stream = tuple[0]
13876
+ if (stream._state.state === 0) stream(undefined)
13877
+ return stream
13878
+ })
13879
+
13880
+ var newStream = combine(function() {
13881
+ var changed = arguments[arguments.length - 1]
13882
+
13883
+ streams.forEach(function(stream, idx) {
13884
+ if (changed.indexOf(stream) > -1) {
13885
+ seed = tuples[idx][1](seed, stream._state.value)
13886
+ }
13887
+ })
13888
+
13889
+ return seed
13890
+ }, streams)
13891
+
13892
+ return newStream
13893
+ }
13894
+
13895
  createStream["fantasy-land/of"] = createStream
13896
  createStream.merge = merge
13897
  createStream.combine = combine
13898
+ createStream.scan = scan
13899
+ createStream.scanMerge = scanMerge
13900
  createStream.HALT = HALT
13901
 
13902
  if (typeof module !== "undefined") module["exports"] = createStream
13903
+ else if (typeof window.m === "function" && !("stream" in window.m)) window.m.stream = createStream
13904
+ else window.m = {stream : createStream}
13905
+
13906
+ }());
13907
 
13908
  },{}]},{},[11]);
13909
  })();
assets/js/forms-admin.min.js CHANGED
@@ -1,9 +1,9 @@
1
- !function(){var e=void 0,t=void 0;!function t(r,n,i){function o(l,s){if(!n[l]){if(!r[l]){var c="function"==typeof e&&e;if(!s&&c)return c(l,!0);if(a)return a(l,!0);var u=new Error("Cannot find module '"+l+"'");throw u.code="MODULE_NOT_FOUND",u}var d=n[l]={exports:{}};r[l][0].call(d.exports,function(e){var t=r[l][1][e];return o(t?t:e)},d,d.exports,t,r,n,i)}return n[l].exports}for(var a="function"==typeof e&&e,l=0;l<i.length;l++)o(i[l]);return o}({1:[function(e,t,r){"use strict";var n=function(e,t){var r={};return r.showType=function(r){var n=r.type();return n=n.charAt(0).toUpperCase()+n.slice(1),e("div",[e("label",t.fieldType),e("span",n)])},r.label=function(r){return e("div",[e("label",t.fieldLabel),e("input.widefat",{type:"text",value:r.label(),onchange:e.withAttr("value",r.label),placeholder:r.title()})])},r.value=function(r){var n="hidden"===r.type();return e("div",[e("label",[n?t.value:t.initialValue," ",n?"":e("small",{style:"float: right; font-weight: normal;"},t.optional)]),e("input.widefat",{type:"text",value:r.value(),onchange:e.withAttr("value",r.value)}),n?"":e("p.help",t.valueHelp)])},r.numberMinMax=function(r){return e("div",[e("div.row",[e("div.col.col-3",[e("label",t.min),e("input",{type:"number",onchange:e.withAttr("value",r.min)})]),e("div.col.col-3",[e("label",t.max),e("input",{type:"number",onchange:e.withAttr("value",r.max)})])])])},r.isRequired=function(r){var n={type:"checkbox",checked:r.required(),onchange:e.withAttr("checked",r.required)},i=void 0;return r.forceRequired()&&(n.required=!0,n.disabled=!0,i=e("p.help",t.forceRequired)),e("div",[e("label.cb-wrap",[e("input",n),t.isFieldRequired]),i])},r.placeholder=function(r){return e("div",[e("label",[t.placeholder," ",e("small",{style:"float: right; font-weight: normal;"},t.optional)]),e("input.widefat",{type:"text",value:r.placeholder(),onchange:e.withAttr("value",r.placeholder),placeholder:""}),e("p.help",t.placeholderHelp)])},r.useParagraphs=function(r){return e("div",[e("label.cb-wrap",[e("input",{type:"checkbox",checked:r.wrap(),onchange:e.withAttr("checked",r.wrap)}),t.wrapInParagraphTags])])},r.choiceType=function(r){var n=[e("option",{value:"select",selected:"select"===r.type()&&"selected"},t.dropdown),e("option",{value:"radio",selected:"radio"===r.type()&&"selected"},t.radioButtons)];return r.acceptsMultipleValues&&n.push(e("option",{value:"checkbox",selected:"checkbox"===r.type()&&"selected"},t.checkboxes)),e("div",[e("label",t.choiceType),e("select",{value:r.type(),onchange:e.withAttr("value",r.type)},n)])},r.choices=function(r){var n=[];return n.push(e("div",[e("label",t.choices),e("div.limit-height",[e("table",[r.choices().map(function(n,i){return e("tr",{"data-id":i},[e("td.cb",e("input",{name:"selected",type:"checkbox"===r.type()?"checkbox":"radio",onchange:e.withAttr("value",r.selectChoice.bind(r)),checked:n.selected(),value:n.value(),title:t.preselect})),e("td.stretch",e("input.widefat",{type:"text",value:n.label(),placeholder:n.title(),onchange:e.withAttr("value",n.label)})),e("td",e("span",{title:t.remove,class:"dashicons dashicons-no-alt hover-activated",onclick:function(e){this.choices().splice(e,1)}.bind(r,i)},""))])})])])])),n},r};t.exports=n},{}],2:[function(e,t,r){"use strict";var n=function t(r,n){var t={},i=e("./field-forms-rows.js")(r,n);return t.render=function(e){var r=e.type();if("function"==typeof t[r])return t[r](e);switch(r){case"select":case"radio":case"checkbox":return t.choice(e)}return t.text(e)},t.text=function(e){return[i.label(e),i.placeholder(e),i.value(e),i.isRequired(e),i.useParagraphs(e)]},t.choice=function(e){var t=[i.label(e),i.choiceType(e),i.choices(e)];return"select"===e.type()&&t.push(i.placeholder(e)),t.push(i.useParagraphs(e)),"select"!==e.type()&&"radio"!==e.type()||t.push(i.isRequired(e)),t},t.hidden=function(e){return e.placeholder(""),e.label(""),e.wrap(!1),[i.showType(e),i.value(e)]},t.submit=function(e){return e.label(""),e.placeholder(""),[i.value(e),i.useParagraphs(e)]},t.number=function(e){return[t.text(e),i.numberMinMax(e)]},t};t.exports=n},{"./field-forms-rows.js":1}],3:[function(e,t,r){"use strict";var n=e("html"),i=function(e){e.dom.checked&&e.dom.setAttribute("checked","true"),e.dom.value&&e.dom.setAttribute("value",e.dom.value),e.dom.selected&&e.dom.setAttribute("selected","true")},o=function(e){function t(t){var i=void 0,o=void 0,a=void 0,l=document.createElement("div");return i=t.label().length>0?e("label",{},t.label()):"",o="function"==typeof r[t.type()]?r[t.type()](t):r.default(t),a=t.wrap()?e("p",[i,o]):[i,o],e.render(l,a),n.prettyPrint(l.innerHTML)+"\n"}var r={};return r.select=function(t){var r={name:t.name(),required:t.required()},n=!1,o=t.choices().map(function(t){return t.selected()&&(n=!0),e("option",{value:t.value()!==t.label()?t.value():void 0,selected:t.selected(),oncreate:i},t.label())}),a=t.placeholder();return a.length>0&&o.unshift(e("option",{disabled:!0,value:"",selected:!n,oncreate:i},a)),e("select",r,o)},r.checkbox=function(t){return t.choices().map(function(r){var n=t.name()+("checkbox"===t.type()?"[]":""),o=t.required()&&"radio"===t.type();return e("label",[e("input",{name:n,type:t.type(),value:r.value(),checked:r.selected(),required:o,oncreate:i})," ",e("span",r.label())])})},r.radio=r.checkbox,r.default=function(t){var r={type:t.type()};return t.name()&&(r.name=t.name()),t.min()&&(r.min=t.min()),t.max()&&(r.max=t.max()),t.value().length>0&&(r.value=t.value()),t.placeholder().length>0&&(r.placeholder=t.placeholder()),r.required=t.required(),r.oncreate=i,e("input",r)},t};t.exports=o},{html:20}],4:[function(e,t,r){"use strict";var n=function(t,r,n,i,o,a){function l(e){d=i.get(e),d&&d.choices().length>0&&d.value(d.choices().map(function(e){return e.label()}).join("|")),t.redraw()}function s(){}function c(){var e=f(d);n.insert(e),l(""),t.redraw()}function u(){var e=i.getCategories(),r=i.getAll(),n=t("div.available-fields.small-margin",[t("h4",a.chooseField),e.map(function(e){var n=r.filter(function(t){return t.category===e});if(n.length)return t("div.tiny-margin",[t("strong",e),n.map(function(e){var r="button";e.forceRequired()&&(r+=" is-required");var n=e.inFormContent();return null!==n&&(r+=" "+(n?"in-form":"not-in-form")),t("button",{className:r,type:"button",onclick:t.withAttr("value",l),value:e.index},e.title())})])})]),o=null;return d&&(o=h(t("div.field-wizard",[t("h3",[d.title(),d.forceRequired()?t("span.red","*"):"",d.name().length?t("code",d.name()):""]),d.help().length?t("p",t.trust(d.help())):"",p.render(d),t("p",[t("button",{class:"button-primary",type:"button",onkeydown:function(e){e=e||window.event,13==e.keyCode&&c()},onclick:c},a.addToForm)])]),l)),[n,o]}var d,f=e("./field-generator.js")(t),h=e("./overlay.js")(t,a),p=e("./field-forms.js")(t,a);return n.on("blur",t.redraw),{view:u,controller:s}};t.exports=n},{"./field-forms.js":2,"./field-generator.js":3,"./overlay.js":10}],5:[function(e,t,r){"use strict";var n=function(e,t){function r(){u.forEach(e.deregister)}function n(t,r,n){var i=e.register(t,r);n||u.push(i)}function i(e){var t={phone:"tel",dropdown:"select",checkboxes:"checkbox",birthday:"text"};return void 0!==t[e]?t[e]:e}function o(e){var r=t.listFields,o=i(e.field_type),a={name:e.tag,title:e.name,required:e.required,forceRequired:e.required,type:o,choices:e.choices,acceptsMultipleValues:!1};return"address"!==a.type?n(r,a,!1):(n(r,{name:a.name+"[addr1]",type:"text",mailchimpType:"address",title:t.streetAddress}),n(r,{name:a.name+"[city]",type:"text",mailchimpType:"address",title:t.city}),n(r,{name:a.name+"[state]",type:"text",mailchimpType:"address",title:t.state}),n(r,{name:a.name+"[zip]",type:"text",mailchimpType:"address",title:t.zip}),n(r,{name:a.name+"[country]",type:"select",mailchimpType:"address",title:t.country,choices:mc4wp_vars.countries})),!0}function a(e){var r=t.interestCategories,o=i(e.field_type);n(r,{title:e.name,name:"INTERESTS["+e.id+"]",type:o,choices:e.interests,acceptsMultipleValues:"checkbox"===o},!1)}function l(e){e.merge_fields=e.merge_fields.sort(function(e,t){return"EMAIL"===e.tag||e.public&&!t.public?-1:!e.public&&t.public?1:0}),e.merge_fields.forEach(o),e.interest_categories.forEach(a)}function s(e){r(),e.forEach(l)}function c(e){var r,i=t.formFields;n(i,{name:"",value:t.subscribe,type:"submit",title:t.submitButton},!0),r={};for(var o in e)r[e[o].id]=e[o].name;n(i,{name:"_mc4wp_lists",type:"checkbox",title:t.listChoice,choices:r,help:t.listChoiceDescription,acceptsMultipleValues:!0},!0),r={subscribe:"Subscribe",unsubscribe:"Unsubscribe"},n(i,{name:"_mc4wp_action",type:"radio",title:t.formAction,choices:r,value:"subscribe",help:t.formActionDescription},!0)}var u=[];return{registerCustomFields:c,registerListFields:l,registerListsFields:s}};t.exports=n},{}],6:[function(e,t,r){"use strict";var n=e("mithril/stream");t.exports=function(e,t){function r(e){return"function"==typeof e.map?e.map(function(e){return new p({label:e})}):Object.keys(e).map(function(t){return new p({label:e[t],value:t})})}function i(n,i){var o,a=c("name",i.name).shift();return a?void(!a.forceRequired()&&i.forceRequired&&a.forceRequired(!0)):(i.choices&&(i.choices=r(i.choices),i.value&&(i.choices=i.choices.map(function(e){return e.value()===i.value&&e.selected(!0),e}))),f.indexOf(n)<0&&f.push(n),o=new h(i),o.category=n,d.push(o),u&&window.clearTimeout(u),u=window.setTimeout(e.redraw,200),t.trigger("fields.change"),o)}function o(t){var r=d.indexOf(t);r>-1&&(delete d[r],e.redraw())}function a(e){return d[e]}function l(){return d=d.map(function(e,t){return e.index=t,e})}function s(){return f}function c(e,t){return d.filter(function(r){return r[e]()===t})}var u,d=[],f=[],h=function(e){this.name=n(e.name),this.title=n(e.title||e.name),this.type=n(e.type),this.mailchimpType=n(e.mailchimpType||""),this.label=n(e.title||""),this.value=n(e.value||""),this.placeholder=n(e.placeholder||""),this.required=n(e.required||!1),this.forceRequired=n(e.forceRequired||!1),this.wrap=n(e.wrap||!0),this.min=n(e.min||null),this.max=n(e.max||null),this.help=n(e.help||""),this.choices=n(e.choices||[]),this.inFormContent=n(null),this.acceptsMultipleValues=e.acceptsMultipleValues,this.selectChoice=function(e){var t=this;this.choices(this.choices().map(function(r){return r.value()===e?r.selected(!0):"checkbox"!==t.type()&&r.selected(!1),r}))}},p=function(e){this.label=n(e.label),this.title=n(e.title||e.label),this.selected=n(e.selected||!1),this.value=n(e.value||e.label)};return{get:a,getAll:l,getCategories:s,deregister:o,register:i,getAllWhere:c}}},{"mithril/stream":21}],7:[function(e,t,r){"use strict";var n=e("codemirror");e("codemirror/mode/xml/xml"),e("codemirror/mode/javascript/javascript"),e("codemirror/mode/css/css"),e("codemirror/mode/htmlmixed/htmlmixed"),e("codemirror/addon/fold/xml-fold"),e("codemirror/addon/edit/matchtags"),e("codemirror/addon/edit/closetag.js");var i=function(e){function t(){return o&&(i.innerHTML=a.getValue().toLowerCase(),o=!1),i}var r,i=document.createElement("form"),o=!1,a={};return i.innerHTML=e.value.toLowerCase(),n&&(r=n.fromTextArea(e,{selectionPointer:!0,matchTags:{bothTags:!0},mode:"htmlmixed",htmlMode:!0,autoCloseTags:!0,autoRefresh:!0}),window.dispatchEvent&&r.on("change",function(){if("function"==typeof Event){var t=new Event("change",{bubbles:!0});e.dispatchEvent(t)}})),window.addEventListener("load",function(){n.signal(r,"change")}),e.addEventListener("change",function(){o=!0}),a.getValue=function(){return r?r.getValue():e.value},a.query=function(e){return t().querySelectorAll(e.toLowerCase())},a.containsField=function(e){return null!==t().elements.namedItem(e.toLowerCase())},a.insert=function(t){r?(r.replaceSelection(t),r.focus()):e.value+=t},a.on=function(t,n){return r?(t="input"===t?"changes":t,r.on(t,n)):e.addEventListener(t,n)},a.refresh=function(){r&&r.refresh()},a};t.exports=i},{codemirror:15,"codemirror/addon/edit/closetag.js":12,"codemirror/addon/edit/matchtags":13,"codemirror/addon/fold/xml-fold":14,"codemirror/mode/css/css":16,"codemirror/mode/htmlmixed/htmlmixed":17,"codemirror/mode/javascript/javascript":18,"codemirror/mode/xml/xml":19}],8:[function(e,t,r){"use strict";var n=function(e,t,r,n,i,o){function a(){n.getAll().forEach(function(e){if(!(e.name().length<=0)){var r=e.name();"checkbox"===e.type()&&(r+="[]");var n=t.containsField(r);if(e.inFormContent(n),"address"===e.mailchimpType()){e.originalRequiredValue=void 0===e.originalRequiredValue?e.forceRequired():e.originalRequiredValue;var i=e.name().replace(/\[(\w+)\]/g,"");t.query('[name^="'+i+'"]').length>0?(void 0===e.originalRequiredValue&&(e.originalRequiredValue=e.forceRequired()),e.forceRequired(!0)):e.forceRequired(e.originalRequiredValue)}}}),l(),e.redraw()}function l(){var e=n.getAllWhere("forceRequired",!0).map(function(e){return e.name().toUpperCase().replace(/\[(\w+)\]/g,".$1")}),r=t.query("[required]");Array.prototype.forEach.call(r,function(t){var r=t.name.toUpperCase();"_"!==r[0]&&(r=r.replace(/\[(\w+)\]/g,".$1"),e.indexOf(r)===-1&&e.push(r))}),s.value=e.join(",")}var s=document.getElementById("required-fields");t.on("change",o.debounce(a,500)),i.on("fields.change",o.debounce(a,500))};t.exports=n},{}],9:[function(e,t,r){"use strict";function n(e,t){l[e]=t,o()}function i(e){delete l[e],o()}function o(){var e="";for(var t in l)e+='<div class="notice notice-warning inline"><p>'+l[t]+"</p></div>";var r=document.querySelector(".mc4wp-notices");if(!r){r=document.createElement("div"),r.className="mc4wp-notices";var n=document.querySelector("h1, h2");n.parentNode.insertBefore(r,n.nextSibling)}r.innerHTML=e}function a(e,t){var r=function(){e.getValue().toLowerCase().indexOf('name="groupings')>-1?n("deprecated_groupings","Your form contains old style <code>GROUPINGS</code> fields. <br /><br />Please remove these fields from your form and then re-add them through the available field buttons to make sure your data is getting through to MailChimp correctly."):i("deprecated_groupings")},o=function(){var r=t.getAllWhere("forceRequired",!0),o=r.filter(function(t){return!e.containsField(t.name().toUpperCase())}),a="<strong>Heads up!</strong> Your form is missing list fields that are required in MailChimp. Either add these fields to your form or mark them as optional in MailChimp.";a+='<br /><ul class="ul-square" style="margin-bottom: 0;"><li>'+o.map(function(e){return e.title()}).join("</li><li>")+"</li></ul>",o.length>0?n("required_fields_missing",a):i("required_fields_missing")};r(),e.on("focus",r),e.on("blur",r),o(),e.on("blur",o),e.on("focus",o)}var l={};t.exports={init:a}},{}],10:[function(e,t,r){"use strict";var n=function(e,t){function r(){document.removeEventListener("keydown",n),window.removeEventListener("resize",i),l()}function n(e){e=e||window.event,27==e.keyCode&&r(),13==e.keyCode&&e.preventDefault()}function i(){if(a){var e=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,t=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,r=(e-a.clientWidth-40)/2,n=(t-a.clientHeight-40)/2;a.style.left=(r>0?r:0)+"px",a.style.top=(n>0?n:0)+"px"}}function o(e){a=e.dom,i()}var a=void 0,l=void 0;return function(a,s){return l=s,document.addEventListener("keydown",n),window.addEventListener("resize",i),[e("div.overlay-wrap",e("div.overlay",{oncreate:o},[e("span",{class:"close dashicons dashicons-no",title:t.close,onclick:r}),a])),e("div.overlay-background",{title:t.close,onclick:r})]}};t.exports=n},{}],11:[function(e,t,r){"use strict";var n=window.mc4wp_forms_i18n,i=window.mc4wp.deps.mithril,o=mc4wp.events,a=mc4wp.settings,l=mc4wp.helpers,s=mc4wp.tabs,c=e("./admin/form-watcher.js"),u=e("./admin/form-editor.js"),d=e("./admin/field-helper.js"),f=e("./admin/fields-factory.js"),h=e("./admin/fields.js")(i,o),p=document.getElementById("mc4wp-form-content"),m=window.formEditor=new u(p),g=(new c(i,formEditor,a,h,o,l),new d(i,s,formEditor,h,o,n)),v=e("./admin/notices");i.mount(document.getElementById("mc4wp-field-wizard"),g);var y=new f(h,n);o.on("selectedLists.change",y.registerListsFields),y.registerListsFields(a.getSelectedLists()),y.registerCustomFields(mc4wp_vars.mailchimp.lists),window.setTimeout(function(){i.redraw()},2e3),v.init(m,h),window.mc4wp=window.mc4wp||{},window.mc4wp.forms=window.mc4wp.forms||{},window.mc4wp.forms.editor=m,window.mc4wp.forms.fields=h},{"./admin/field-helper.js":4,"./admin/fields-factory.js":5,"./admin/fields.js":6,"./admin/form-editor.js":7,"./admin/form-watcher.js":8,"./admin/notices":9}],12:[function(e,r,n){!function(i){"object"==typeof n&&"object"==typeof r?i(e("../../lib/codemirror"),e("../fold/xml-fold")):"function"==typeof t&&t.amd?t(["../../lib/codemirror","../fold/xml-fold"],i):i(CodeMirror)}(function(e){function t(t){if(t.getOption("disableInput"))return e.Pass;for(var r=t.listSelections(),n=[],s=0;s<r.length;s++){if(!r[s].empty())return e.Pass;var c=r[s].head,u=t.getTokenAt(c),d=e.innerMode(t.getMode(),u.state),f=d.state;if("xml"!=d.mode.name||!f.tagName)return e.Pass;var h=t.getOption("autoCloseTags"),p="html"==d.mode.configuration,m="object"==typeof h&&h.dontCloseTags||p&&a,g="object"==typeof h&&h.indentTags||p&&l,v=f.tagName;u.end>c.ch&&(v=v.slice(0,v.length-u.end+c.ch));var y=v.toLowerCase();if(!v||"string"==u.type&&(u.end!=c.ch||!/[\"\']/.test(u.string.charAt(u.string.length-1))||1==u.string.length)||"tag"==u.type&&"closeTag"==f.type||u.string.indexOf("/")==u.string.length-1||m&&i(m,y)>-1||o(t,v,c,f,!0))return e.Pass;var b=g&&i(g,y)>-1;n[s]={indent:b,text:">"+(b?"\n\n":"")+"</"+v+">",newPos:b?e.Pos(c.line+1,0):e.Pos(c.line,c.ch+1)}}for(var s=r.length-1;s>=0;s--){var w=n[s];t.replaceRange(w.text,r[s].head,r[s].anchor,"+insert");var x=t.listSelections().slice(0);x[s]={head:w.newPos,anchor:w.newPos},t.setSelections(x),w.indent&&(t.indentLine(w.newPos.line,null,!0),t.indentLine(w.newPos.line+1,null,!0))}}function r(t,r){for(var n=t.listSelections(),i=[],a=r?"/":"</",l=0;l<n.length;l++){if(!n[l].empty())return e.Pass;var s=n[l].head,c=t.getTokenAt(s),u=e.innerMode(t.getMode(),c.state),d=u.state;if(r&&("string"==c.type||"<"!=c.string.charAt(0)||c.start!=s.ch-1))return e.Pass;var f;if("xml"!=u.mode.name)if("htmlmixed"==t.getMode().name&&"javascript"==u.mode.name)f=a+"script";else{if("htmlmixed"!=t.getMode().name||"css"!=u.mode.name)return e.Pass;f=a+"style"}else{if(!d.context||!d.context.tagName||o(t,d.context.tagName,s,d))return e.Pass;f=a+d.context.tagName}">"!=t.getLine(s.line).charAt(c.end)&&(f+=">"),i[l]=f}t.replaceSelections(i),n=t.listSelections();for(var l=0;l<n.length;l++)(l==n.length-1||n[l].head.line<n[l+1].head.line)&&t.indentLine(n[l].head.line)}function n(t){return t.getOption("disableInput")?e.Pass:r(t,!0)}function i(e,t){if(e.indexOf)return e.indexOf(t);for(var r=0,n=e.length;r<n;++r)if(e[r]==t)return r;return-1}function o(t,r,n,i,o){if(!e.scanForClosingTag)return!1;var a=Math.min(t.lastLine()+1,n.line+500),l=e.scanForClosingTag(t,n,null,a);if(!l||l.tag!=r)return!1;for(var s=i.context,c=o?1:0;s&&s.tagName==r;s=s.prev)++c;n=l.to;for(var u=1;u<c;u++){var d=e.scanForClosingTag(t,n,null,a);if(!d||d.tag!=r)return!1;n=d.to}return!0}e.defineOption("autoCloseTags",!1,function(r,i,o){if(o!=e.Init&&o&&r.removeKeyMap("autoCloseTags"),i){var a={name:"autoCloseTags"};("object"!=typeof i||i.whenClosing)&&(a["'/'"]=function(e){return n(e)}),("object"!=typeof i||i.whenOpening)&&(a["'>'"]=function(e){return t(e)}),r.addKeyMap(a)}});var a=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],l=["applet","blockquote","body","button","div","dl","fieldset","form","frameset","h1","h2","h3","h4","h5","h6","head","html","iframe","layer","legend","object","ol","p","select","table","ul"];e.commands.closeTag=function(e){return r(e)}})},{"../../lib/codemirror":15,"../fold/xml-fold":14}],13:[function(e,r,n){!function(i){"object"==typeof n&&"object"==typeof r?i(e("../../lib/codemirror"),e("../fold/xml-fold")):"function"==typeof t&&t.amd?t(["../../lib/codemirror","../fold/xml-fold"],i):i(CodeMirror)}(function(e){"use strict";function t(e){e.state.tagHit&&e.state.tagHit.clear(),e.state.tagOther&&e.state.tagOther.clear(),e.state.tagHit=e.state.tagOther=null}function r(r){r.state.failedTagMatch=!1,r.operation(function(){if(t(r),!r.somethingSelected()){var n=r.getCursor(),i=r.getViewport();i.from=Math.min(i.from,n.line),i.to=Math.max(n.line+1,i.to);var o=e.findMatchingTag(r,n,i);if(o){if(r.state.matchBothTags){var a="open"==o.at?o.open:o.close;a&&(r.state.tagHit=r.markText(a.from,a.to,{className:"CodeMirror-matchingtag"}))}var l="close"==o.at?o.open:o.close;l?r.state.tagOther=r.markText(l.from,l.to,{className:"CodeMirror-matchingtag"}):r.state.failedTagMatch=!0}}})}function n(e){e.state.failedTagMatch&&r(e)}e.defineOption("matchTags",!1,function(i,o,a){a&&a!=e.Init&&(i.off("cursorActivity",r),i.off("viewportChange",n),t(i)),o&&(i.state.matchBothTags="object"==typeof o&&o.bothTags,i.on("cursorActivity",r),i.on("viewportChange",n),r(i))}),e.commands.toMatchingTag=function(t){var r=e.findMatchingTag(t,t.getCursor());if(r){var n="close"==r.at?r.open:r.close;n&&t.extendSelection(n.to,n.from)}}})},{"../../lib/codemirror":15,"../fold/xml-fold":14}],14:[function(e,r,n){!function(i){"object"==typeof n&&"object"==typeof r?i(e("../../lib/codemirror")):"function"==typeof t&&t.amd?t(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){"use strict";function t(e,t){return e.line-t.line||e.ch-t.ch}function r(e,t,r,n){this.line=t,this.ch=r,this.cm=e,this.text=e.getLine(t),this.min=n?Math.max(n.from,e.firstLine()):e.firstLine(),this.max=n?Math.min(n.to-1,e.lastLine()):e.lastLine()}function n(e,t){var r=e.cm.getTokenTypeAt(f(e.line,t));return r&&/\btag\b/.test(r)}function i(e){if(!(e.line>=e.max))return e.ch=0,e.text=e.cm.getLine(++e.line),!0}function o(e){if(!(e.line<=e.min))return e.text=e.cm.getLine(--e.line),e.ch=e.text.length,!0}function a(e){for(;;){var t=e.text.indexOf(">",e.ch);if(t==-1){if(i(e))continue;return}{if(n(e,t+1)){var r=e.text.lastIndexOf("/",t),o=r>-1&&!/\S/.test(e.text.slice(r+1,t));return e.ch=t+1,o?"selfClose":"regular"}e.ch=t+1}}}function l(e){for(;;){var t=e.ch?e.text.lastIndexOf("<",e.ch-1):-1;if(t==-1){if(o(e))continue;return}if(n(e,t+1)){p.lastIndex=t,e.ch=t;var r=p.exec(e.text);if(r&&r.index==t)return r}else e.ch=t}}function s(e){for(;;){p.lastIndex=e.ch;var t=p.exec(e.text);if(!t){if(i(e))continue;return}{if(n(e,t.index+1))return e.ch=t.index+t[0].length,t;e.ch=t.index+1}}}function c(e){for(;;){var t=e.ch?e.text.lastIndexOf(">",e.ch-1):-1;if(t==-1){if(o(e))continue;return}{if(n(e,t+1)){var r=e.text.lastIndexOf("/",t),i=r>-1&&!/\S/.test(e.text.slice(r+1,t));return e.ch=t+1,i?"selfClose":"regular"}e.ch=t}}}function u(e,t){for(var r=[];;){var n,i=s(e),o=e.line,l=e.ch-(i?i[0].length:0);if(!i||!(n=a(e)))return;if("selfClose"!=n)if(i[1]){for(var c=r.length-1;c>=0;--c)if(r[c]==i[2]){r.length=c;break}if(c<0&&(!t||t==i[2]))return{tag:i[2],from:f(o,l),to:f(e.line,e.ch)}}else r.push(i[2])}}function d(e,t){for(var r=[];;){var n=c(e);if(!n)return;if("selfClose"!=n){var i=e.line,o=e.ch,a=l(e);if(!a)return;if(a[1])r.push(a[2]);else{for(var s=r.length-1;s>=0;--s)if(r[s]==a[2]){r.length=s;break}if(s<0&&(!t||t==a[2]))return{tag:a[2],from:f(e.line,e.ch),to:f(i,o)}}}else l(e)}}var f=e.Pos,h="A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",p=new RegExp("<(/?)(["+h+"]["+h+"-:.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*)","g");e.registerHelper("fold","xml",function(e,t){for(var n=new r(e,t.line,0);;){var i,o=s(n);if(!o||n.line!=t.line||!(i=a(n)))return;if(!o[1]&&"selfClose"!=i){var l=f(n.line,n.ch),c=u(n,o[2]);return c&&{from:l,to:c.from}}}}),e.findMatchingTag=function(e,n,i){var o=new r(e,n.line,n.ch,i);if(o.text.indexOf(">")!=-1||o.text.indexOf("<")!=-1){var s=a(o),c=s&&f(o.line,o.ch),h=s&&l(o);if(s&&h&&!(t(o,n)>0)){var p={from:f(o.line,o.ch),to:c,tag:h[2]};return"selfClose"==s?{open:p,close:null,at:"open"}:h[1]?{open:d(o,h[2]),close:p,at:"close"}:(o=new r(e,c.line,c.ch,i),{open:p,close:u(o,h[2]),at:"open"})}}},e.findEnclosingTag=function(e,t,n){for(var i=new r(e,t.line,t.ch,n);;){var o=d(i);if(!o)break;var a=new r(e,t.line,t.ch,n),l=u(a,o.tag);if(l)return{open:o,close:l}}},e.scanForClosingTag=function(e,t,n,i){return u(new r(e,t.line,t.ch,i?{from:0,to:i}:null),n)}})},{"../../lib/codemirror":15}],15:[function(e,r,n){!function(e,i){"object"==typeof n&&void 0!==r?r.exports=i():"function"==typeof t&&t.amd?t(i):e.CodeMirror=i()}(this,function(){"use strict";function e(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function t(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function r(e,r){return t(e).appendChild(r)}function n(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o<t.length;++o)i.appendChild(t[o]);return i}function i(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do{if(11==t.nodeType&&(t=t.host),t==e)return!0}while(t=t.parentNode)}function o(){var e;try{e=document.activeElement}catch(t){e=document.body||null}for(;e&&e.root&&e.root.activeElement;)e=e.root.activeElement;return e}function a(t,r){var n=t.className;e(r).test(n)||(t.className+=(n?" ":"")+r)}function l(t,r){for(var n=t.split(" "),i=0;i<n.length;i++)n[i]&&!e(n[i]).test(r)&&(r+=" "+n[i]);return r}function s(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function c(e,t,r){t||(t={});for(var n in e)!e.hasOwnProperty(n)||r===!1&&t.hasOwnProperty(n)||(t[n]=e[n]);return t}function u(e,t,r,n,i){null==t&&(t=e.search(/[^\s\u00a0]/))==-1&&(t=e.length);for(var o=n||0,a=i||0;;){var l=e.indexOf("\t",o);if(l<0||l>=t)return a+(t-o);a+=l-o,a+=r-a%r,o=l+1}}function d(e,t){for(var r=0;r<e.length;++r)if(e[r]==t)return r;return-1}function f(e,t,r){for(var n=0,i=0;;){var o=e.indexOf("\t",n);o==-1&&(o=e.length);var a=o-n;if(o==e.length||i+a>=t)return n+Math.min(a,t-i);if(i+=o-n,i+=r-i%r,n=o+1,i>=t)return n}}function h(e){for(;xa.length<=e;)xa.push(p(xa)+" ");return xa[e]}function p(e){return e[e.length-1]}function m(e,t){for(var r=[],n=0;n<e.length;n++)r[n]=t(e[n],n);return r}function g(e,t,r){for(var n=0,i=r(t);n<e.length&&r(e[n])<=i;)n++;e.splice(n,0,t)}function v(){}function y(e,t){var r;return Object.create?r=Object.create(e):(v.prototype=e,r=new v),t&&c(t,r),r}function b(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||ka.test(e))}function w(e,t){return t?!!(t.source.indexOf("\\w")>-1&&b(e))||t.test(e):b(e)}function x(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function k(e){return e.charCodeAt(0)>=768&&Ca.test(e)}function C(e,t,r){for(;(r<0?t>0:t<e.length)&&k(e.charAt(t));)t+=r;return t}function S(e,t,r){for(;;){if(Math.abs(t-r)<=1)return e(t)?t:r;var n=Math.floor((t+r)/2);e(n)?r=n:t=n}}function T(e,t,r){var i=this;this.input=r,i.scrollbarFiller=n("div",null,"CodeMirror-scrollbar-filler"),i.scrollbarFiller.setAttribute("cm-not-content","true"),i.gutterFiller=n("div",null,"CodeMirror-gutter-filler"),i.gutterFiller.setAttribute("cm-not-content","true"),i.lineDiv=n("div",null,"CodeMirror-code"),i.selectionDiv=n("div",null,null,"position: relative; z-index: 1"),i.cursorDiv=n("div",null,"CodeMirror-cursors"),i.measure=n("div",null,"CodeMirror-measure"),i.lineMeasure=n("div",null,"CodeMirror-measure"),i.lineSpace=n("div",[i.measure,i.lineMeasure,i.selectionDiv,i.cursorDiv,i.lineDiv],null,"position: relative; outline: none"),i.mover=n("div",[n("div",[i.lineSpace],"CodeMirror-lines")],null,"position: relative"),i.sizer=n("div",[i.mover],"CodeMirror-sizer"),i.sizerWidth=null,i.heightForcer=n("div",null,null,"position: absolute; height: "+ga+"px; width: 1px;"),i.gutters=n("div",null,"CodeMirror-gutters"),i.lineGutter=null,i.scroller=n("div",[i.sizer,i.heightForcer,i.gutters],"CodeMirror-scroll"),i.scroller.setAttribute("tabIndex","-1"),i.wrapper=n("div",[i.scrollbarFiller,i.gutterFiller,i.scroller],"CodeMirror"),Go&&$o<8&&(i.gutters.style.zIndex=-1,i.scroller.style.paddingRight=0),Yo||qo&&na||(i.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(i.wrapper):e(i.wrapper)),i.viewFrom=i.viewTo=t.first,i.reportedViewFrom=i.reportedViewTo=t.first,i.view=[],i.renderedView=null,i.externalMeasured=null,i.viewOffset=0,i.lastWrapHeight=i.lastWrapWidth=0,i.updateLineNumbers=null,i.nativeBarWidth=i.barHeight=i.barWidth=0,i.scrollbarsClipped=!1,i.lineNumWidth=i.lineNumInnerWidth=i.lineNumChars=null,i.alignWidgets=!1,i.cachedCharWidth=i.cachedTextHeight=i.cachedPaddingH=null,i.maxLine=null,i.maxLineLength=0,i.maxLineChanged=!1,i.wheelDX=i.wheelDY=i.wheelStartX=i.wheelStartY=null,i.shift=!1,i.selForContextMenu=null,i.activeTouch=null,r.init(i)}function L(e,t){if((t-=e.first)<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(t<o){r=i;break}t-=o}return r.lines[t]}function M(e,t,r){var n=[],i=t.line;return e.iter(t.line,r.line+1,function(e){var o=e.text;i==r.line&&(o=o.slice(0,r.ch)),i==t.line&&(o=o.slice(t.ch)),n.push(o),++i}),n}function A(e,t,r){var n=[];return e.iter(t,r,function(e){n.push(e.text)}),n}function _(e,t){var r=t-e.height;if(r)for(var n=e;n;n=n.parent)n.height+=r}function O(e){if(null==e.parent)return null;for(var t=e.parent,r=d(t.lines,e),n=t.parent;n;t=n,n=n.parent)for(var i=0;n.children[i]!=t;++i)r+=n.children[i].chunkSize();return r+t.first}function N(e,t){var r=e.first;e:do{for(var n=0;n<e.children.length;++n){var i=e.children[n],o=i.height;if(t<o){e=i;continue e}t-=o,r+=i.chunkSize()}return r}while(!e.lines);for(var a=0;a<e.lines.length;++a){var l=e.lines[a],s=l.height;if(t<s)break;t-=s}return r+a}function W(e,t){return t>=e.first&&t<e.first+e.size}function E(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function z(e,t,r){if(void 0===r&&(r=null),!(this instanceof z))return new z(e,t,r);this.line=e,this.ch=t,this.sticky=r}function D(e,t){return e.line-t.line||e.ch-t.ch}function P(e,t){return e.sticky==t.sticky&&0==D(e,t)}function H(e){return z(e.line,e.ch)}function I(e,t){return D(e,t)<0?t:e}function F(e,t){return D(e,t)<0?e:t}function j(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function R(e,t){if(t.line<e.first)return z(e.first,0);var r=e.first+e.size-1;return t.line>r?z(r,L(e,r).text.length):B(t,L(e,t.line).text.length)}function B(e,t){var r=e.ch;return null==r||r>t?z(e.line,t):r<0?z(e.line,0):e}function q(e,t){for(var r=[],n=0;n<t.length;n++)r[n]=R(e,t[n]);return r}function K(){Sa=!0}function U(){Ta=!0}function V(e,t,r){this.marker=e,this.from=t,this.to=r}function G(e,t){if(e)for(var r=0;r<e.length;++r){var n=e[r];if(n.marker==t)return n}}function $(e,t){for(var r,n=0;n<e.length;++n)e[n]!=t&&(r||(r=[])).push(e[n]);return r}function Y(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}function X(e,t,r){var n;if(e)for(var i=0;i<e.length;++i){var o=e[i],a=o.marker,l=null==o.from||(a.inclusiveLeft?o.from<=t:o.from<t);if(l||o.from==t&&"bookmark"==a.type&&(!r||!o.marker.insertLeft)){var s=null==o.to||(a.inclusiveRight?o.to>=t:o.to>t);(n||(n=[])).push(new V(a,o.from,s?null:o.to))}}return n}function Z(e,t,r){var n;if(e)for(var i=0;i<e.length;++i){var o=e[i],a=o.marker,l=null==o.to||(a.inclusiveRight?o.to>=t:o.to>t);if(l||o.from==t&&"bookmark"==a.type&&(!r||o.marker.insertLeft)){var s=null==o.from||(a.inclusiveLeft?o.from<=t:o.from<t);(n||(n=[])).push(new V(a,s?null:o.from-t,null==o.to?null:o.to-t))}}return n}function J(e,t){if(t.full)return null;var r=W(e,t.from.line)&&L(e,t.from.line).markedSpans,n=W(e,t.to.line)&&L(e,t.to.line).markedSpans;if(!r&&!n)return null;var i=t.from.ch,o=t.to.ch,a=0==D(t.from,t.to),l=X(r,i,a),s=Z(n,o,a),c=1==t.text.length,u=p(t.text).length+(c?i:0);if(l)for(var d=0;d<l.length;++d){var f=l[d];if(null==f.to){var h=G(s,f.marker);h?c&&(f.to=null==h.to?null:h.to+u):f.to=i}}
2
- if(s)for(var m=0;m<s.length;++m){var g=s[m];if(null!=g.to&&(g.to+=u),null==g.from){var v=G(l,g.marker);v||(g.from=u,c&&(l||(l=[])).push(g))}else g.from+=u,c&&(l||(l=[])).push(g)}l&&(l=Q(l)),s&&s!=l&&(s=Q(s));var y=[l];if(!c){var b,w=t.text.length-2;if(w>0&&l)for(var x=0;x<l.length;++x)null==l[x].to&&(b||(b=[])).push(new V(l[x].marker,null,null));for(var k=0;k<w;++k)y.push(b);y.push(s)}return y}function Q(e){for(var t=0;t<e.length;++t){var r=e[t];null!=r.from&&r.from==r.to&&r.marker.clearWhenEmpty!==!1&&e.splice(t--,1)}return e.length?e:null}function ee(e,t,r){var n=null;if(e.iter(t.line,r.line+1,function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var r=e.markedSpans[t].marker;!r.readOnly||n&&d(n,r)!=-1||(n||(n=[])).push(r)}}),!n)return null;for(var i=[{from:t,to:r}],o=0;o<n.length;++o)for(var a=n[o],l=a.find(0),s=0;s<i.length;++s){var c=i[s];if(!(D(c.to,l.from)<0||D(c.from,l.to)>0)){var u=[s,1],f=D(c.from,l.from),h=D(c.to,l.to);(f<0||!a.inclusiveLeft&&!f)&&u.push({from:c.from,to:l.from}),(h>0||!a.inclusiveRight&&!h)&&u.push({from:l.to,to:c.to}),i.splice.apply(i,u),s+=u.length-3}}return i}function te(e){var t=e.markedSpans;if(t){for(var r=0;r<t.length;++r)t[r].marker.detachLine(e);e.markedSpans=null}}function re(e,t){if(t){for(var r=0;r<t.length;++r)t[r].marker.attachLine(e);e.markedSpans=t}}function ne(e){return e.inclusiveLeft?-1:0}function ie(e){return e.inclusiveRight?1:0}function oe(e,t){var r=e.lines.length-t.lines.length;if(0!=r)return r;var n=e.find(),i=t.find(),o=D(n.from,i.from)||ne(e)-ne(t);if(o)return-o;var a=D(n.to,i.to)||ie(e)-ie(t);return a?a:t.id-e.id}function ae(e,t){var r,n=Ta&&e.markedSpans;if(n)for(var i=void 0,o=0;o<n.length;++o)i=n[o],i.marker.collapsed&&null==(t?i.from:i.to)&&(!r||oe(r,i.marker)<0)&&(r=i.marker);return r}function le(e){return ae(e,!0)}function se(e){return ae(e,!1)}function ce(e,t,r,n,i){var o=L(e,t),a=Ta&&o.markedSpans;if(a)for(var l=0;l<a.length;++l){var s=a[l];if(s.marker.collapsed){var c=s.marker.find(0),u=D(c.from,r)||ne(s.marker)-ne(i),d=D(c.to,n)||ie(s.marker)-ie(i);if(!(u>=0&&d<=0||u<=0&&d>=0)&&(u<=0&&(s.marker.inclusiveRight&&i.inclusiveLeft?D(c.to,r)>=0:D(c.to,r)>0)||u>=0&&(s.marker.inclusiveRight&&i.inclusiveLeft?D(c.from,n)<=0:D(c.from,n)<0)))return!0}}}function ue(e){for(var t;t=le(e);)e=t.find(-1,!0).line;return e}function de(e){for(var t;t=se(e);)e=t.find(1,!0).line;return e}function fe(e){for(var t,r;t=se(e);)e=t.find(1,!0).line,(r||(r=[])).push(e);return r}function he(e,t){var r=L(e,t),n=ue(r);return r==n?t:O(n)}function pe(e,t){if(t>e.lastLine())return t;var r,n=L(e,t);if(!me(e,n))return t;for(;r=se(n);)n=r.find(1,!0).line;return O(n)+1}function me(e,t){var r=Ta&&t.markedSpans;if(r)for(var n=void 0,i=0;i<r.length;++i)if(n=r[i],n.marker.collapsed){if(null==n.from)return!0;if(!n.marker.widgetNode&&0==n.from&&n.marker.inclusiveLeft&&ge(e,t,n))return!0}}function ge(e,t,r){if(null==r.to){var n=r.marker.find(1,!0);return ge(e,n.line,G(n.line.markedSpans,r.marker))}if(r.marker.inclusiveRight&&r.to==t.text.length)return!0;for(var i=void 0,o=0;o<t.markedSpans.length;++o)if(i=t.markedSpans[o],i.marker.collapsed&&!i.marker.widgetNode&&i.from==r.to&&(null==i.to||i.to!=r.from)&&(i.marker.inclusiveLeft||r.marker.inclusiveRight)&&ge(e,t,i))return!0}function ve(e){e=ue(e);for(var t=0,r=e.parent,n=0;n<r.lines.length;++n){var i=r.lines[n];if(i==e)break;t+=i.height}for(var o=r.parent;o;r=o,o=r.parent)for(var a=0;a<o.children.length;++a){var l=o.children[a];if(l==r)break;t+=l.height}return t}function ye(e){if(0==e.height)return 0;for(var t,r=e.text.length,n=e;t=le(n);){var i=t.find(0,!0);n=i.from.line,r+=i.from.ch-i.to.ch}for(n=e;t=se(n);){var o=t.find(0,!0);r-=n.text.length-o.from.ch,n=o.to.line,r+=n.text.length-o.to.ch}return r}function be(e){var t=e.display,r=e.doc;t.maxLine=L(r,r.first),t.maxLineLength=ye(t.maxLine),t.maxLineChanged=!0,r.iter(function(e){var r=ye(e);r>t.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function we(e,t,r,n){if(!e)return n(t,r,"ltr");for(var i=!1,o=0;o<e.length;++o){var a=e[o];(a.from<r&&a.to>t||t==r&&a.to==t)&&(n(Math.max(a.from,t),Math.min(a.to,r),1==a.level?"rtl":"ltr"),i=!0)}i||n(t,r,"ltr")}function xe(e,t,r){var n;La=null;for(var i=0;i<e.length;++i){var o=e[i];if(o.from<t&&o.to>t)return i;o.to==t&&(o.from!=o.to&&"before"==r?n=i:La=i),o.from==t&&(o.from!=o.to&&"before"!=r?n=i:La=i)}return null!=n?n:La}function ke(e){var t=e.order;return null==t&&(t=e.order=Ma(e.text)),t}function Ce(e,t,r){var n=C(e.text,t+r,r);return n<0||n>e.text.length?null:n}function Se(e,t,r){var n=Ce(e,t.ch,r);return null==n?null:new z(t.line,n,r<0?"after":"before")}function Te(e,t,r,n,i){if(e){var o=ke(r);if(o){var a,l=i<0?p(o):o[0],s=i<0==(1==l.level),c=s?"after":"before";if(l.level>0){var u=Yt(t,r);a=i<0?r.text.length-1:0;var d=Xt(t,u,a).top;a=S(function(e){return Xt(t,u,e).top==d},i<0==(1==l.level)?l.from:l.to-1,a),"before"==c&&(a=Ce(r,a,1,!0))}else a=i<0?l.to:l.from;return new z(n,a,c)}}return new z(n,i<0?r.text.length:0,i<0?"before":"after")}function Le(e,t,r,n){var i=ke(t);if(!i)return Se(t,r,n);r.ch>=t.text.length?(r.ch=t.text.length,r.sticky="before"):r.ch<=0&&(r.ch=0,r.sticky="after");var o=xe(i,r.ch,r.sticky),a=i[o];if(a.level%2==0&&(n>0?a.to>r.ch:a.from<r.ch))return Se(t,r,n);var l,s=function(e,r){return Ce(t,e instanceof z?e.ch:e,r)},c=function(r){return e.options.lineWrapping?(l=l||Yt(e,t),pr(e,t,l,r)):{begin:0,end:t.text.length}},u=c("before"==r.sticky?s(r,-1):r.ch);if(a.level%2==1){var d=s(r,-n);if(null!=d&&(n>0?d>=a.from&&d>=u.begin:d<=a.to&&d<=u.end)){var f=n<0?"before":"after";return new z(r.line,d,f)}}var h=function(e,t,n){for(var o=function(e,t){return t?new z(r.line,s(e,1),"before"):new z(r.line,e,"after")};e>=0&&e<i.length;e+=t){var a=i[e],l=t>0==(1!=a.level),c=l?n.begin:s(n.end,-1);if(a.from<=c&&c<a.to)return o(c,l);if(c=l?a.from:s(a.to,-1),n.begin<=c&&c<n.end)return o(c,l)}},p=h(o+n,n,u);if(p)return p;var m=n>0?u.end:s(u.begin,-1);return null==m||n>0&&m==t.text.length||!(p=h(n>0?0:i.length-1,n,c(m)))?null:p}function Me(e,t){return e._handlers&&e._handlers[t]||Aa}function Ae(e,t,r){if(e.removeEventListener)e.removeEventListener(t,r,!1);else if(e.detachEvent)e.detachEvent("on"+t,r);else{var n=e._handlers,i=n&&n[t];if(i){var o=d(i,r);o>-1&&(n[t]=i.slice(0,o).concat(i.slice(o+1)))}}}function _e(e,t){var r=Me(e,t);if(r.length)for(var n=Array.prototype.slice.call(arguments,2),i=0;i<r.length;++i)r[i].apply(null,n)}function Oe(e,t,r){return"string"==typeof t&&(t={type:t,preventDefault:function(){this.defaultPrevented=!0}}),_e(e,r||t.type,e,t),Pe(t)||t.codemirrorIgnore}function Ne(e){var t=e._handlers&&e._handlers.cursorActivity;if(t)for(var r=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]),n=0;n<t.length;++n)d(r,t[n])==-1&&r.push(t[n])}function We(e,t){return Me(e,t).length>0}function Ee(e){e.prototype.on=function(e,t){_a(this,e,t)},e.prototype.off=function(e,t){Ae(this,e,t)}}function ze(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function De(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function Pe(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function He(e){ze(e),De(e)}function Ie(e){return e.target||e.srcElement}function Fe(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),ia&&e.ctrlKey&&1==t&&(t=3),t}function je(e){if(null==pa){var t=n("span","​");r(e,n("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(pa=t.offsetWidth<=1&&t.offsetHeight>2&&!(Go&&$o<8))}var i=pa?n("span","​"):n("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return i.setAttribute("cm-text",""),i}function Re(e){if(null!=ma)return ma;var n=r(e,document.createTextNode("AخA")),i=sa(n,0,1).getBoundingClientRect(),o=sa(n,1,2).getBoundingClientRect();return t(e),!(!i||i.left==i.right)&&(ma=o.right-i.right<3)}function Be(e){if(null!=za)return za;var t=r(e,n("span","x")),i=t.getBoundingClientRect(),o=sa(t,0,1).getBoundingClientRect();return za=Math.abs(i.left-o.left)>1}function qe(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),Da[e]=t}function Ke(e,t){Pa[e]=t}function Ue(e){if("string"==typeof e&&Pa.hasOwnProperty(e))e=Pa[e];else if(e&&"string"==typeof e.name&&Pa.hasOwnProperty(e.name)){var t=Pa[e.name];"string"==typeof t&&(t={name:t}),e=y(t,e),e.name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return Ue("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return Ue("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function Ve(e,t){t=Ue(t);var r=Da[t.name];if(!r)return Ve(e,"text/plain");var n=r(e,t);if(Ha.hasOwnProperty(t.name)){var i=Ha[t.name];for(var o in i)i.hasOwnProperty(o)&&(n.hasOwnProperty(o)&&(n["_"+o]=n[o]),n[o]=i[o])}if(n.name=t.name,t.helperType&&(n.helperType=t.helperType),t.modeProps)for(var a in t.modeProps)n[a]=t.modeProps[a];return n}function Ge(e,t){c(t,Ha.hasOwnProperty(e)?Ha[e]:Ha[e]={})}function $e(e,t){if(t===!0)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r}function Ye(e,t){for(var r;e.innerMode&&((r=e.innerMode(t))&&r.mode!=e);)t=r.state,e=r.mode;return r||{mode:e,state:t}}function Xe(e,t,r){return!e.startState||e.startState(t,r)}function Ze(e,t,r,n){var i=[e.state.modeGen],o={};ot(e,t.text,e.doc.mode,r,function(e,t){return i.push(e,t)},o,n);for(var a=0;a<e.state.overlays.length;++a)!function(r){var n=e.state.overlays[r],a=1,l=0;ot(e,t.text,n.mode,!0,function(e,t){for(var r=a;l<e;){var o=i[a];o>e&&i.splice(a,1,e,i[a+1],o),a+=2,l=Math.min(e,o)}if(t)if(n.opaque)i.splice(r,a-r,e,"overlay "+t),a=r+2;else for(;r<a;r+=2){var s=i[r+1];i[r+1]=(s?s+" ":"")+"overlay "+t}},o)}(a);return{styles:i,classes:o.bgClass||o.textClass?o:null}}function Je(e,t,r){if(!t.styles||t.styles[0]!=e.state.modeGen){var n=Qe(e,O(t)),i=Ze(e,t,t.text.length>e.options.maxHighlightLength?$e(e.doc.mode,n):n);t.stateAfter=n,t.styles=i.styles,i.classes?t.styleClasses=i.classes:t.styleClasses&&(t.styleClasses=null),r===e.doc.frontier&&e.doc.frontier++}return t.styles}function Qe(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return!0;var o=at(e,t,r),a=o>n.first&&L(n,o-1).stateAfter;return a=a?$e(n.mode,a):Xe(n.mode),n.iter(o,t,function(r){et(e,r.text,a);var l=o==t-1||o%5==0||o>=i.viewFrom&&o<i.viewTo;r.stateAfter=l?$e(n.mode,a):null,++o}),r&&(n.frontier=o),a}function et(e,t,r,n){var i=e.doc.mode,o=new Ia(t,e.options.tabSize);for(o.start=o.pos=n||0,""==t&&tt(i,r);!o.eol();)rt(i,o,r),o.start=o.pos}function tt(e,t){if(e.blankLine)return e.blankLine(t);if(e.innerMode){var r=Ye(e,t);return r.mode.blankLine?r.mode.blankLine(r.state):void 0}}function rt(e,t,r,n){for(var i=0;i<10;i++){n&&(n[0]=Ye(e,r).mode);var o=e.token(t,r);if(t.pos>t.start)return o}throw new Error("Mode "+e.name+" failed to advance stream.")}function nt(e,t,r,n){var i,o=function(e){return{start:d.start,end:d.pos,string:d.current(),type:i||null,state:e?$e(a.mode,u):u}},a=e.doc,l=a.mode;t=R(a,t);var s,c=L(a,t.line),u=Qe(e,t.line,r),d=new Ia(c.text,e.options.tabSize);for(n&&(s=[]);(n||d.pos<t.ch)&&!d.eol();)d.start=d.pos,i=rt(l,d,u),n&&s.push(o(!0));return n?s:o()}function it(e,t){if(e)for(;;){var r=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!r)break;e=e.slice(0,r.index)+e.slice(r.index+r[0].length);var n=r[1]?"bgClass":"textClass";null==t[n]?t[n]=r[2]:new RegExp("(?:^|s)"+r[2]+"(?:$|s)").test(t[n])||(t[n]+=" "+r[2])}return e}function ot(e,t,r,n,i,o,a){var l=r.flattenSpans;null==l&&(l=e.options.flattenSpans);var s,c=0,u=null,d=new Ia(t,e.options.tabSize),f=e.options.addModeClass&&[null];for(""==t&&it(tt(r,n),o);!d.eol();){if(d.pos>e.options.maxHighlightLength?(l=!1,a&&et(e,t,n,d.pos),d.pos=t.length,s=null):s=it(rt(r,d,n,f),o),f){var h=f[0].name;h&&(s="m-"+(s?h+" "+s:h))}if(!l||u!=s){for(;c<d.start;)c=Math.min(d.start,c+5e3),i(c,u);u=s}d.start=d.pos}for(;c<d.pos;){var p=Math.min(d.pos,c+5e3);i(p,u),c=p}}function at(e,t,r){for(var n,i,o=e.doc,a=r?-1:t-(e.doc.mode.innerMode?1e3:100),l=t;l>a;--l){if(l<=o.first)return o.first;var s=L(o,l-1);if(s.stateAfter&&(!r||l<=o.frontier))return l;var c=u(s.text,null,e.options.tabSize);(null==i||n>c)&&(i=l-1,n=c)}return i}function lt(e,t,r,n){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),te(e),re(e,r);var i=n?n(e):1;i!=e.height&&_(e,i)}function st(e){e.parent=null,te(e)}function ct(e,t){if(!e||/^\s*$/.test(e))return null;var r=t.addModeClass?Ba:Ra;return r[e]||(r[e]=e.replace(/\S+/g,"cm-$&"))}function ut(e,t){var r=n("span",null,null,Yo?"padding-right: .1px":null),i={pre:n("pre",[r],"CodeMirror-line"),content:r,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:(Go||Yo)&&e.getOption("lineWrapping")};r.setAttribute("role","presentation"),i.pre.setAttribute("role","presentation"),t.measure={};for(var o=0;o<=(t.rest?t.rest.length:0);o++){var a=o?t.rest[o-1]:t.line,s=void 0;i.pos=0,i.addToken=ft,Re(e.display.measure)&&(s=ke(a))&&(i.addToken=pt(i.addToken,s)),i.map=[];gt(a,i,Je(e,a,t!=e.display.externalMeasured&&O(a))),a.styleClasses&&(a.styleClasses.bgClass&&(i.bgClass=l(a.styleClasses.bgClass,i.bgClass||"")),a.styleClasses.textClass&&(i.textClass=l(a.styleClasses.textClass,i.textClass||""))),0==i.map.length&&i.map.push(0,0,i.content.appendChild(je(e.display.measure))),0==o?(t.measure.map=i.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(i.map),(t.measure.caches||(t.measure.caches=[])).push({}))}if(Yo){var c=i.content.lastChild;(/\bcm-tab\b/.test(c.className)||c.querySelector&&c.querySelector(".cm-tab"))&&(i.content.className="cm-tab-wrap-hack")}return _e(e,"renderLine",e,t.line,i.pre),i.pre.className&&(i.textClass=l(i.pre.className,i.textClass||"")),i}function dt(e){var t=n("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function ft(e,t,r,i,o,a,l){if(t){var s,c=e.splitSpaces?ht(t,e.trailingSpace):t,u=e.cm.state.specialChars,d=!1;if(u.test(t)){s=document.createDocumentFragment();for(var f=0;;){u.lastIndex=f;var p=u.exec(t),m=p?p.index-f:t.length-f;if(m){var g=document.createTextNode(c.slice(f,f+m));Go&&$o<9?s.appendChild(n("span",[g])):s.appendChild(g),e.map.push(e.pos,e.pos+m,g),e.col+=m,e.pos+=m}if(!p)break;f+=m+1;var v=void 0;if("\t"==p[0]){var y=e.cm.options.tabSize,b=y-e.col%y;v=s.appendChild(n("span",h(b),"cm-tab")),v.setAttribute("role","presentation"),v.setAttribute("cm-text","\t"),e.col+=b}else"\r"==p[0]||"\n"==p[0]?(v=s.appendChild(n("span","\r"==p[0]?"␍":"␤","cm-invalidchar")),v.setAttribute("cm-text",p[0]),e.col+=1):(v=e.cm.options.specialCharPlaceholder(p[0]),v.setAttribute("cm-text",p[0]),Go&&$o<9?s.appendChild(n("span",[v])):s.appendChild(v),e.col+=1);e.map.push(e.pos,e.pos+1,v),e.pos++}}else e.col+=t.length,s=document.createTextNode(c),e.map.push(e.pos,e.pos+t.length,s),Go&&$o<9&&(d=!0),e.pos+=t.length;if(e.trailingSpace=32==c.charCodeAt(t.length-1),r||i||o||d||l){var w=r||"";i&&(w+=i),o&&(w+=o);var x=n("span",[s],w,l);return a&&(x.title=a),e.content.appendChild(x)}e.content.appendChild(s)}}function ht(e,t){if(e.length>1&&!/ /.test(e))return e;for(var r=t,n="",i=0;i<e.length;i++){var o=e.charAt(i);" "!=o||!r||i!=e.length-1&&32!=e.charCodeAt(i+1)||(o=" "),n+=o,r=" "==o}return n}function pt(e,t){return function(r,n,i,o,a,l,s){i=i?i+" cm-force-border":"cm-force-border";for(var c=r.pos,u=c+n.length;;){for(var d=void 0,f=0;f<t.length&&(d=t[f],!(d.to>c&&d.from<=c));f++);if(d.to>=u)return e(r,n,i,o,a,l,s);e(r,n.slice(0,d.to-c),i,o,null,l,s),o=null,n=n.slice(d.to-c),c=d.to}}}function mt(e,t,r,n){var i=!n&&r.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!n&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",r.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t,e.trailingSpace=!1}function gt(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var a,l,s,c,u,d,f,h=i.length,p=0,m=1,g="",v=0;;){if(v==p){s=c=u=d=l="",f=null,v=1/0;for(var y=[],b=void 0,w=0;w<n.length;++w){var x=n[w],k=x.marker;"bookmark"==k.type&&x.from==p&&k.widgetNode?y.push(k):x.from<=p&&(null==x.to||x.to>p||k.collapsed&&x.to==p&&x.from==p)?(null!=x.to&&x.to!=p&&v>x.to&&(v=x.to,c=""),k.className&&(s+=" "+k.className),k.css&&(l=(l?l+";":"")+k.css),k.startStyle&&x.from==p&&(u+=" "+k.startStyle),k.endStyle&&x.to==v&&(b||(b=[])).push(k.endStyle,x.to),k.title&&!d&&(d=k.title),k.collapsed&&(!f||oe(f.marker,k)<0)&&(f=x)):x.from>p&&v>x.from&&(v=x.from)}if(b)for(var C=0;C<b.length;C+=2)b[C+1]==v&&(c+=" "+b[C]);if(!f||f.from==p)for(var S=0;S<y.length;++S)mt(t,0,y[S]);if(f&&(f.from||0)==p){if(mt(t,(null==f.to?h+1:f.to)-p,f.marker,null==f.from),null==f.to)return;f.to==p&&(f=!1)}}if(p>=h)break;for(var T=Math.min(h,v);;){if(g){var L=p+g.length;if(!f){var M=L>T?g.slice(0,T-p):g;t.addToken(t,M,a?a+s:s,u,p+M.length==v?c:"",d,l)}if(L>=T){g=g.slice(T-p),p=T;break}p=L,u=""}g=i.slice(o,o=r[m++]),a=ct(r[m++],t.cm.options)}}else for(var A=1;A<r.length;A+=2)t.addToken(t,i.slice(o,o=r[A]),ct(r[A+1],t.cm.options))}function vt(e,t,r){this.line=t,this.rest=fe(t),this.size=this.rest?O(p(this.rest))-r+1:1,this.node=this.text=null,this.hidden=me(e,t)}function yt(e,t,r){for(var n,i=[],o=t;o<r;o=n){var a=new vt(e.doc,L(e.doc,o),o);n=o+a.size,i.push(a)}return i}function bt(e){qa?qa.ops.push(e):e.ownsGroup=qa={ops:[e],delayedCallbacks:[]}}function wt(e){var t=e.delayedCallbacks,r=0;do{for(;r<t.length;r++)t[r].call(null);for(var n=0;n<e.ops.length;n++){var i=e.ops[n];if(i.cursorActivityHandlers)for(;i.cursorActivityCalled<i.cursorActivityHandlers.length;)i.cursorActivityHandlers[i.cursorActivityCalled++].call(null,i.cm)}}while(r<t.length)}function xt(e,t){var r=e.ownsGroup;if(r)try{wt(r)}finally{qa=null,t(r)}}function kt(e,t){var r=Me(e,t);if(r.length){var n,i=Array.prototype.slice.call(arguments,2);qa?n=qa.delayedCallbacks:Ka?n=Ka:(n=Ka=[],setTimeout(Ct,0));for(var o=0;o<r.length;++o)!function(e){n.push(function(){return r[e].apply(null,i)})}(o)}}function Ct(){var e=Ka;Ka=null;for(var t=0;t<e.length;++t)e[t]()}function St(e,t,r,n){for(var i=0;i<t.changes.length;i++){var o=t.changes[i];"text"==o?At(e,t):"gutter"==o?Ot(e,t,r,n):"class"==o?_t(t):"widget"==o&&Nt(e,t,n)}t.changes=null}function Tt(e){return e.node==e.text&&(e.node=n("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),Go&&$o<8&&(e.node.style.zIndex=2)),e.node}function Lt(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=Tt(e);e.background=r.insertBefore(n("div",null,t),r.firstChild)}}function Mt(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):ut(e,t)}function At(e,t){var r=t.text.className,n=Mt(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,_t(t)):r&&(t.text.className=r)}function _t(e){Lt(e),e.line.wrapClass?Tt(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function Ot(e,t,r,i){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var o=Tt(t);t.gutterBackground=n("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px; width: "+i.gutterTotalWidth+"px"),o.insertBefore(t.gutterBackground,t.text)}var a=t.line.gutterMarkers;if(e.options.lineNumbers||a){var l=Tt(t),s=t.gutter=n("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?i.fixedPos:-i.gutterTotalWidth)+"px");if(e.display.input.setUneditable(s),l.insertBefore(s,t.text),t.line.gutterClass&&(s.className+=" "+t.line.gutterClass),!e.options.lineNumbers||a&&a["CodeMirror-linenumbers"]||(t.lineNumber=s.appendChild(n("div",E(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+i.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),a)for(var c=0;c<e.options.gutters.length;++c){var u=e.options.gutters[c],d=a.hasOwnProperty(u)&&a[u];d&&s.appendChild(n("div",[d],"CodeMirror-gutter-elt","left: "+i.gutterLeft[u]+"px; width: "+i.gutterWidth[u]+"px"))}}}function Nt(e,t,r){t.alignable&&(t.alignable=null);for(var n=t.node.firstChild,i=void 0;n;n=i)i=n.nextSibling,"CodeMirror-linewidget"==n.className&&t.node.removeChild(n);Et(e,t,r)}function Wt(e,t,r,n){var i=Mt(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),_t(t),Ot(e,t,r,n),Et(e,t,n),t.node}function Et(e,t,r){if(zt(e,t.line,t,r,!0),t.rest)for(var n=0;n<t.rest.length;n++)zt(e,t.rest[n],t,r,!1)}function zt(e,t,r,i,o){if(t.widgets)for(var a=Tt(r),l=0,s=t.widgets;l<s.length;++l){var c=s[l],u=n("div",[c.node],"CodeMirror-linewidget");c.handleMouseEvents||u.setAttribute("cm-ignore-events","true"),Dt(c,u,r,i),e.display.input.setUneditable(u),o&&c.above?a.insertBefore(u,r.gutter||r.text):a.appendChild(u),kt(c,"redraw")}}function Dt(e,t,r,n){if(e.noHScroll){(r.alignable||(r.alignable=[])).push(t);var i=n.wrapperWidth;t.style.left=n.fixedPos+"px",e.coverGutter||(i-=n.gutterTotalWidth,t.style.paddingLeft=n.gutterTotalWidth+"px"),t.style.width=i+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-n.gutterTotalWidth+"px"))}function Pt(e){if(null!=e.height)return e.height;var t=e.doc.cm;if(!t)return 0;if(!i(document.body,e.node)){var o="position: relative;";e.coverGutter&&(o+="margin-left: -"+t.display.gutters.offsetWidth+"px;"),e.noHScroll&&(o+="width: "+t.display.wrapper.clientWidth+"px;"),r(t.display.measure,n("div",[e.node],null,o))}return e.height=e.node.parentNode.offsetHeight}function Ht(e,t){for(var r=Ie(t);r!=e.wrapper;r=r.parentNode)if(!r||1==r.nodeType&&"true"==r.getAttribute("cm-ignore-events")||r.parentNode==e.sizer&&r!=e.mover)return!0}function It(e){return e.lineSpace.offsetTop}function Ft(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function jt(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=r(e.measure,n("pre","x")),i=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,o={left:parseInt(i.paddingLeft),right:parseInt(i.paddingRight)};return isNaN(o.left)||isNaN(o.right)||(e.cachedPaddingH=o),o}function Rt(e){return ga-e.display.nativeBarWidth}function Bt(e){return e.display.scroller.clientWidth-Rt(e)-e.display.barWidth}function qt(e){return e.display.scroller.clientHeight-Rt(e)-e.display.barHeight}function Kt(e,t,r){var n=e.options.lineWrapping,i=n&&Bt(e);if(!t.measure.heights||n&&t.measure.width!=i){var o=t.measure.heights=[];if(n){t.measure.width=i;for(var a=t.text.firstChild.getClientRects(),l=0;l<a.length-1;l++){var s=a[l],c=a[l+1];Math.abs(s.bottom-c.bottom)>2&&o.push((s.bottom+c.top)/2-r.top)}}o.push(r.bottom-r.top)}}function Ut(e,t,r){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var n=0;n<e.rest.length;n++)if(e.rest[n]==t)return{map:e.measure.maps[n],cache:e.measure.caches[n]};for(var i=0;i<e.rest.length;i++)if(O(e.rest[i])>r)return{map:e.measure.maps[i],cache:e.measure.caches[i],before:!0}}function Vt(e,t){t=ue(t);var n=O(t),i=e.display.externalMeasured=new vt(e.doc,t,n);i.lineN=n;var o=i.built=ut(e,i);return i.text=o.pre,r(e.display.lineMeasure,o.pre),i}function Gt(e,t,r,n){return Xt(e,Yt(e,t),r,n)}function $t(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[Cr(e,t)];var r=e.display.externalMeasured;return r&&t>=r.lineN&&t<r.lineN+r.size?r:void 0}function Yt(e,t){var r=O(t),n=$t(e,r);n&&!n.text?n=null:n&&n.changes&&(St(e,n,r,yr(e)),e.curOp.forceUpdate=!0),n||(n=Vt(e,t));var i=Ut(n,t,r);return{line:t,view:n,rect:null,map:i.map,cache:i.cache,before:i.before,hasHeights:!1}}function Xt(e,t,r,n,i){t.before&&(r=-1);var o,a=r+(n||"");return t.cache.hasOwnProperty(a)?o=t.cache[a]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(Kt(e,t.view,t.rect),t.hasHeights=!0),o=Qt(e,t,r,n),o.bogus||(t.cache[a]=o)),{left:o.left,right:o.right,top:i?o.rtop:o.top,bottom:i?o.rbottom:o.bottom}}function Zt(e,t,r){for(var n,i,o,a,l,s,c=0;c<e.length;c+=3)if(l=e[c],s=e[c+1],t<l?(i=0,o=1,a="left"):t<s?(i=t-l,o=i+1):(c==e.length-3||t==s&&e[c+3]>t)&&(o=s-l,i=o-1,t>=s&&(a="right")),null!=i){if(n=e[c+2],l==s&&r==(n.insertLeft?"left":"right")&&(a=r),"left"==r&&0==i)for(;c&&e[c-2]==e[c-3]&&e[c-1].insertLeft;)n=e[2+(c-=3)],a="left";if("right"==r&&i==s-l)for(;c<e.length-3&&e[c+3]==e[c+4]&&!e[c+5].insertLeft;)n=e[2+(c+=3)],a="right";break}return{node:n,start:i,end:o,collapse:a,coverStart:l,coverEnd:s}}function Jt(e,t){var r=Ua;if("left"==t)for(var n=0;n<e.length&&(r=e[n]).left==r.right;n++);else for(var i=e.length-1;i>=0&&(r=e[i]).left==r.right;i--);return r}function Qt(e,t,r,n){var i,o=Zt(t.map,r,n),a=o.node,l=o.start,s=o.end,c=o.collapse;if(3==a.nodeType){for(var u=0;u<4;u++){for(;l&&k(t.line.text.charAt(o.coverStart+l));)--l;for(;o.coverStart+s<o.coverEnd&&k(t.line.text.charAt(o.coverStart+s));)++s;if(i=Go&&$o<9&&0==l&&s==o.coverEnd-o.coverStart?a.parentNode.getBoundingClientRect():Jt(sa(a,l,s).getClientRects(),n),i.left||i.right||0==l)break;s=l,l-=1,c="right"}Go&&$o<11&&(i=er(e.display.measure,i))}else{l>0&&(c=n="right");var d;i=e.options.lineWrapping&&(d=a.getClientRects()).length>1?d["right"==n?d.length-1:0]:a.getBoundingClientRect()}if(Go&&$o<9&&!l&&(!i||!i.left&&!i.right)){var f=a.parentNode.getClientRects()[0];i=f?{left:f.left,right:f.left+vr(e.display),top:f.top,bottom:f.bottom}:Ua}for(var h=i.top-t.rect.top,p=i.bottom-t.rect.top,m=(h+p)/2,g=t.view.measure.heights,v=0;v<g.length-1&&!(m<g[v]);v++);var y=v?g[v-1]:0,b=g[v],w={left:("right"==c?i.right:i.left)-t.rect.left,right:("left"==c?i.left:i.right)-t.rect.left,top:y,bottom:b};return i.left||i.right||(w.bogus=!0),e.options.singleCursorHeightPerLine||(w.rtop=h,w.rbottom=p),w}function er(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!Be(e))return t;var r=screen.logicalXDPI/screen.deviceXDPI,n=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*r,right:t.right*r,top:t.top*n,bottom:t.bottom*n}}function tr(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}function rr(e){e.display.externalMeasure=null,t(e.display.lineMeasure);for(var r=0;r<e.display.view.length;r++)tr(e.display.view[r])}function nr(e){rr(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function ir(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function or(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function ar(e,t,r,n,i){if(!i&&t.widgets)for(var o=0;o<t.widgets.length;++o)if(t.widgets[o].above){var a=Pt(t.widgets[o]);r.top+=a,r.bottom+=a}if("line"==n)return r;n||(n="local");var l=ve(t);if("local"==n?l+=It(e.display):l-=e.display.viewOffset,"page"==n||"window"==n){var s=e.display.lineSpace.getBoundingClientRect();l+=s.top+("window"==n?0:or());var c=s.left+("window"==n?0:ir());r.left+=c,r.right+=c}return r.top+=l,r.bottom+=l,r}function lr(e,t,r){if("div"==r)return t;var n=t.left,i=t.top;if("page"==r)n-=ir(),i-=or();else if("local"==r||!r){var o=e.display.sizer.getBoundingClientRect();n+=o.left,i+=o.top}var a=e.display.lineSpace.getBoundingClientRect();return{left:n-a.left,top:i-a.top}}function sr(e,t,r,n,i){return n||(n=L(e.doc,t.line)),ar(e,n,Gt(e,n,t.ch,i),r)}function cr(e,t,r,n,i,o){function a(t,a){var l=Xt(e,i,t,a?"right":"left",o);return a?l.left=l.right:l.right=l.left,ar(e,n,l,r)}function l(e,t,r){var n=s[t],i=n.level%2!=0;return a(r?e-1:e,i!=r)}n=n||L(e.doc,t.line),i||(i=Yt(e,n));var s=ke(n),c=t.ch,u=t.sticky;if(c>=n.text.length?(c=n.text.length,u="before"):c<=0&&(c=0,u="after"),!s)return a("before"==u?c-1:c,"before"==u);var d=xe(s,c,u),f=La,h=l(c,d,"before"==u);return null!=f&&(h.other=l(c,f,"before"!=u)),h}function ur(e,t){var r=0;t=R(e.doc,t),e.options.lineWrapping||(r=vr(e.display)*t.ch);var n=L(e.doc,t.line),i=ve(n)+It(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function dr(e,t,r,n,i){var o=z(e,t,r);return o.xRel=i,n&&(o.outside=!0),o}function fr(e,t,r){var n=e.doc;if((r+=e.display.viewOffset)<0)return dr(n.first,0,null,!0,-1);var i=N(n,r),o=n.first+n.size-1;if(i>o)return dr(n.first+n.size-1,L(n,o).text.length,null,!0,1);t<0&&(t=0);for(var a=L(n,i);;){var l=mr(e,a,i,t,r),s=se(a),c=s&&s.find(0,!0);if(!s||!(l.ch>c.from.ch||l.ch==c.from.ch&&l.xRel>0))return l;i=O(a=c.to.line)}}function hr(e,t,r,n){var i=function(n){return ar(e,t,Xt(e,r,n),"line")},o=t.text.length,a=S(function(e){return i(e-1).bottom<=n},o,0);return o=S(function(e){return i(e).top>n},a,o),{begin:a,end:o}}function pr(e,t,r,n){return hr(e,t,r,ar(e,t,Xt(e,r,n),"line").top)}function mr(e,t,r,n,i){i-=ve(t);var o,a=0,l=t.text.length,s=Yt(e,t);if(ke(t)){if(e.options.lineWrapping){var c;c=hr(e,t,s,i),a=c.begin,l=c.end}o=new z(r,a);var u,d,f=cr(e,o,"line",t,s).left,h=f<n?1:-1,p=f-n;do{if(u=p,d=o,null==(o=Le(e,t,o,h))||o.ch<a||l<=("before"==o.sticky?o.ch-1:o.ch)){o=d;break}p=cr(e,o,"line",t,s).left-n}while(h<0!=p<0&&Math.abs(p)<=Math.abs(u));if(Math.abs(p)>Math.abs(u)){if(p<0==u<0)throw new Error("Broke out of infinite loop in coordsCharInner");o=d}}else{var m=S(function(r){var o=ar(e,t,Xt(e,s,r),"line");return o.top>i?(l=Math.min(r,l),!0):!(o.bottom<=i)&&(o.left>n||!(o.right<n)&&n-o.left<o.right-n)},a,l);m=C(t.text,m,1),o=new z(r,m,m==l?"before":"after")}var g=cr(e,o,"line",t,s);return(i<g.top||g.bottom<i)&&(o.outside=!0),o.xRel=n<g.left?-1:n>g.right?1:0,o}function gr(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==ja){ja=n("pre");for(var i=0;i<49;++i)ja.appendChild(document.createTextNode("x")),ja.appendChild(n("br"));ja.appendChild(document.createTextNode("x"))}r(e.measure,ja);var o=ja.offsetHeight/50;return o>3&&(e.cachedTextHeight=o),t(e.measure),o||1}function vr(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=n("span","xxxxxxxxxx"),i=n("pre",[t]);r(e.measure,i);var o=t.getBoundingClientRect(),a=(o.right-o.left)/10;return a>2&&(e.cachedCharWidth=a),a||10}function yr(e){for(var t=e.display,r={},n={},i=t.gutters.clientLeft,o=t.gutters.firstChild,a=0;o;o=o.nextSibling,++a)r[e.options.gutters[a]]=o.offsetLeft+o.clientLeft+i,n[e.options.gutters[a]]=o.clientWidth;return{fixedPos:br(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:r,gutterWidth:n,wrapperWidth:t.wrapper.clientWidth}}function br(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function wr(e){var t=gr(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/vr(e.display)-3);return function(i){if(me(e.doc,i))return 0;var o=0;if(i.widgets)for(var a=0;a<i.widgets.length;a++)i.widgets[a].height&&(o+=i.widgets[a].height);return r?o+(Math.ceil(i.text.length/n)||1)*t:o+t}}function xr(e){var t=e.doc,r=wr(e);t.iter(function(e){var t=r(e);t!=e.height&&_(e,t)})}function kr(e,t,r,n){var i=e.display;if(!r&&"true"==Ie(t).getAttribute("cm-not-content"))return null;var o,a,l=i.lineSpace.getBoundingClientRect();try{o=t.clientX-l.left,a=t.clientY-l.top}catch(e){return null}var s,c=fr(e,o,a);if(n&&1==c.xRel&&(s=L(e.doc,c.line).text).length==c.ch){var d=u(s,s.length,e.options.tabSize)-s.length;c=z(c.line,Math.max(0,Math.round((o-jt(e.display).left)/vr(e.display))-d))}return c}function Cr(e,t){if(t>=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;for(var r=e.display.view,n=0;n<r.length;n++)if((t-=r[n].size)<0)return n}function Sr(e){
3
- e.display.input.showSelection(e.display.input.prepareSelection())}function Tr(e,t){for(var r=e.doc,n={},i=n.cursors=document.createDocumentFragment(),o=n.selection=document.createDocumentFragment(),a=0;a<r.sel.ranges.length;a++)if(t!==!1||a!=r.sel.primIndex){var l=r.sel.ranges[a];if(!(l.from().line>=e.display.viewTo||l.to().line<e.display.viewFrom)){var s=l.empty();(s||e.options.showCursorWhenSelecting)&&Lr(e,l.head,i),s||Mr(e,l,o)}}return n}function Lr(e,t,r){var i=cr(e,t,"div",null,null,!e.options.singleCursorHeightPerLine),o=r.appendChild(n("div"," ","CodeMirror-cursor"));if(o.style.left=i.left+"px",o.style.top=i.top+"px",o.style.height=Math.max(0,i.bottom-i.top)*e.options.cursorHeight+"px",i.other){var a=r.appendChild(n("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));a.style.display="",a.style.left=i.other.left+"px",a.style.top=i.other.top+"px",a.style.height=.85*(i.other.bottom-i.other.top)+"px"}}function Mr(e,t,r){function i(e,t,r,i){t<0&&(t=0),t=Math.round(t),i=Math.round(i),s.appendChild(n("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px;\n top: "+t+"px; width: "+(null==r?d-e:r)+"px;\n height: "+(i-t)+"px"))}function o(t,r,n){function o(r,n){return sr(e,z(t,r),"div",c,n)}var a,s,c=L(l,t),f=c.text.length;return we(ke(c),r||0,null==n?f:n,function(e,t,l){var c,h,p,m=o(e,"left");if(e==t)c=m,h=p=m.left;else{if(c=o(t-1,"right"),"rtl"==l){var g=m;m=c,c=g}h=m.left,p=c.right}null==r&&0==e&&(h=u),c.top-m.top>3&&(i(h,m.top,null,m.bottom),h=u,m.bottom<c.top&&i(h,m.bottom,null,c.top)),null==n&&t==f&&(p=d),(!a||m.top<a.top||m.top==a.top&&m.left<a.left)&&(a=m),(!s||c.bottom>s.bottom||c.bottom==s.bottom&&c.right>s.right)&&(s=c),h<u+1&&(h=u),i(h,c.top,p-h,c.bottom)}),{start:a,end:s}}var a=e.display,l=e.doc,s=document.createDocumentFragment(),c=jt(e.display),u=c.left,d=Math.max(a.sizerWidth,Bt(e)-a.sizer.offsetLeft)-c.right,f=t.from(),h=t.to();if(f.line==h.line)o(f.line,f.ch,h.ch);else{var p=L(l,f.line),m=L(l,h.line),g=ue(p)==ue(m),v=o(f.line,f.ch,g?p.text.length+1:null).end,y=o(h.line,g?0:null,h.ch).start;g&&(v.top<y.top-2?(i(v.right,v.top,null,v.bottom),i(u,y.top,y.left,y.bottom)):i(v.right,v.top,y.left-v.right,v.bottom)),v.bottom<y.top&&i(u,v.bottom,null,y.top)}r.appendChild(s)}function Ar(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var r=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0?t.blinker=setInterval(function(){return t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function _r(e){e.state.focused||(e.display.input.focus(),Nr(e))}function Or(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,Wr(e))},100)}function Nr(e,t){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(_e(e,"focus",e,t),e.state.focused=!0,a(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),Yo&&setTimeout(function(){return e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),Ar(e))}function Wr(e,t){e.state.delayingBlurEvent||(e.state.focused&&(_e(e,"blur",e,t),e.state.focused=!1,da(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function Er(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=br(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",a=0;a<r.length;a++)if(!r[a].hidden){e.options.fixedGutter&&(r[a].gutter&&(r[a].gutter.style.left=o),r[a].gutterBackground&&(r[a].gutterBackground.style.left=o));var l=r[a].alignable;if(l)for(var s=0;s<l.length;s++)l[s].style.left=o}e.options.fixedGutter&&(t.gutters.style.left=n+i+"px")}}function zr(e){if(!e.options.lineNumbers)return!1;var t=e.doc,r=E(e.options,t.first+t.size-1),i=e.display;if(r.length!=i.lineNumChars){var o=i.measure.appendChild(n("div",[n("div",r)],"CodeMirror-linenumber CodeMirror-gutter-elt")),a=o.firstChild.offsetWidth,l=o.offsetWidth-a;return i.lineGutter.style.width="",i.lineNumInnerWidth=Math.max(a,i.lineGutter.offsetWidth-l)+1,i.lineNumWidth=i.lineNumInnerWidth+l,i.lineNumChars=i.lineNumInnerWidth?r.length:-1,i.lineGutter.style.width=i.lineNumWidth+"px",Ln(e),!0}return!1}function Dr(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;n<t.view.length;n++){var i=t.view[n],o=void 0;if(!i.hidden){if(Go&&$o<8){var a=i.node.offsetTop+i.node.offsetHeight;o=a-r,r=a}else{var l=i.node.getBoundingClientRect();o=l.bottom-l.top}var s=i.line.height-o;if(o<2&&(o=gr(t)),(s>.001||s<-.001)&&(_(i.line,o),Pr(i.line),i.rest))for(var c=0;c<i.rest.length;c++)Pr(i.rest[c])}}}function Pr(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t)e.widgets[t].height=e.widgets[t].node.parentNode.offsetHeight}function Hr(e,t,r){var n=r&&null!=r.top?Math.max(0,r.top):e.scroller.scrollTop;n=Math.floor(n-It(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=N(t,n),a=N(t,i);if(r&&r.ensure){var l=r.ensure.from.line,s=r.ensure.to.line;l<o?(o=l,a=N(t,ve(L(t,l))+e.wrapper.clientHeight)):Math.min(s,t.lastLine())>=a&&(o=N(t,ve(L(t,s))-e.wrapper.clientHeight),a=s)}return{from:o,to:Math.max(a,o+1)}}function Ir(e,t){Math.abs(e.doc.scrollTop-t)<2||(e.doc.scrollTop=t,qo||Sn(e,{top:t}),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t),e.display.scrollbars.setScrollTop(t),qo&&Sn(e),bn(e,100))}function Fr(e,t,r){(r?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)||(t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),e.doc.scrollLeft=t,Er(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function jr(e){var t=e.wheelDeltaX,r=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==r&&e.detail&&e.axis==e.VERTICAL_AXIS?r=e.detail:null==r&&(r=e.wheelDelta),{x:t,y:r}}function Rr(e){var t=jr(e);return t.x*=Ga,t.y*=Ga,t}function Br(e,t){var r=jr(t),n=r.x,i=r.y,o=e.display,a=o.scroller,l=a.scrollWidth>a.clientWidth,s=a.scrollHeight>a.clientHeight;if(n&&l||i&&s){if(i&&ia&&Yo)e:for(var c=t.target,u=o.view;c!=a;c=c.parentNode)for(var d=0;d<u.length;d++)if(u[d].node==c){e.display.currentWheelTarget=c;break e}if(n&&!qo&&!Jo&&null!=Ga)return i&&s&&Ir(e,Math.max(0,Math.min(a.scrollTop+i*Ga,a.scrollHeight-a.clientHeight))),Fr(e,Math.max(0,Math.min(a.scrollLeft+n*Ga,a.scrollWidth-a.clientWidth))),(!i||i&&s)&&ze(t),void(o.wheelStartX=null);if(i&&null!=Ga){var f=i*Ga,h=e.doc.scrollTop,p=h+o.wrapper.clientHeight;f<0?h=Math.max(0,h+f-50):p=Math.min(e.doc.height,p+f+50),Sn(e,{top:h,bottom:p})}Va<20&&(null==o.wheelStartX?(o.wheelStartX=a.scrollLeft,o.wheelStartY=a.scrollTop,o.wheelDX=n,o.wheelDY=i,setTimeout(function(){if(null!=o.wheelStartX){var e=a.scrollLeft-o.wheelStartX,t=a.scrollTop-o.wheelStartY,r=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,r&&(Ga=(Ga*Va+r)/(Va+1),++Va)}},200)):(o.wheelDX+=n,o.wheelDY+=i))}}function qr(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Ft(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?r:0,docHeight:n,scrollHeight:n+Rt(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}function Kr(e,t){t||(t=qr(e));var r=e.display.barWidth,n=e.display.barHeight;Ur(e,t);for(var i=0;i<4&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&Dr(e),Ur(e,qr(e)),r=e.display.barWidth,n=e.display.barHeight}function Ur(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",r.heightForcer.style.borderBottom=n.bottom+"px solid transparent",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}function Vr(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&da(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new Xa[e.options.scrollbarStyle](function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),_a(t,"mousedown",function(){e.state.focused&&setTimeout(function(){return e.display.input.focus()},0)}),t.setAttribute("cm-not-content","true")},function(t,r){"horizontal"==r?Fr(e,t):Ir(e,t)},e),e.display.scrollbars.addClass&&a(e.display.wrapper,e.display.scrollbars.addClass)}function Gr(e,t){if(!Oe(e,"scrollCursorIntoView")){var r=e.display,i=r.sizer.getBoundingClientRect(),o=null;if(t.top+i.top<0?o=!0:t.bottom+i.top>(window.innerHeight||document.documentElement.clientHeight)&&(o=!1),null!=o&&!ta){var a=n("div","​",null,"position: absolute;\n top: "+(t.top-r.viewOffset-It(e.display))+"px;\n height: "+(t.bottom-t.top+Rt(e)+r.barHeight)+"px;\n left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(a),a.scrollIntoView(o),e.display.lineSpace.removeChild(a)}}}function $r(e,t,r,n){null==n&&(n=0);for(var i,o=0;o<5;o++){var a=!1;i=cr(e,t);var l=r&&r!=t?cr(e,r):i,s=Xr(e,Math.min(i.left,l.left),Math.min(i.top,l.top)-n,Math.max(i.left,l.left),Math.max(i.bottom,l.bottom)+n),c=e.doc.scrollTop,u=e.doc.scrollLeft;if(null!=s.scrollTop&&(Ir(e,s.scrollTop),Math.abs(e.doc.scrollTop-c)>1&&(a=!0)),null!=s.scrollLeft&&(Fr(e,s.scrollLeft),Math.abs(e.doc.scrollLeft-u)>1&&(a=!0)),!a)break}return i}function Yr(e,t,r,n,i){var o=Xr(e,t,r,n,i);null!=o.scrollTop&&Ir(e,o.scrollTop),null!=o.scrollLeft&&Fr(e,o.scrollLeft)}function Xr(e,t,r,n,i){var o=e.display,a=gr(e.display);r<0&&(r=0);var l=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,s=qt(e),c={};i-r>s&&(i=r+s);var u=e.doc.height+Ft(o),d=r<a,f=i>u-a;if(r<l)c.scrollTop=d?0:r;else if(i>l+s){var h=Math.min(r,(f?u:i)-s);h!=l&&(c.scrollTop=h)}var p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLeft,m=Bt(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),g=n-t>m;return g&&(n=t+m),t<10?c.scrollLeft=0:t<p?c.scrollLeft=Math.max(0,t-(g?0:10)):n>m+p-3&&(c.scrollLeft=n+(g?0:10)-m),c}function Zr(e,t,r){null==t&&null==r||Qr(e),null!=t&&(e.curOp.scrollLeft=(null==e.curOp.scrollLeft?e.doc.scrollLeft:e.curOp.scrollLeft)+t),null!=r&&(e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+r)}function Jr(e){Qr(e);var t=e.getCursor(),r=t,n=t;e.options.lineWrapping||(r=t.ch?z(t.line,t.ch-1):t,n=z(t.line,t.ch+1)),e.curOp.scrollToPos={from:r,to:n,margin:e.options.cursorScrollMargin,isCursor:!0}}function Qr(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var r=ur(e,t.from),n=ur(e,t.to),i=Xr(e,Math.min(r.left,n.left),Math.min(r.top,n.top)-t.margin,Math.max(r.right,n.right),Math.max(r.bottom,n.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function en(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Za},bt(e.curOp)}function tn(e){xt(e.curOp,function(e){for(var t=0;t<e.ops.length;t++)e.ops[t].cm.curOp=null;rn(e)})}function rn(e){for(var t=e.ops,r=0;r<t.length;r++)nn(t[r]);for(var n=0;n<t.length;n++)on(t[n]);for(var i=0;i<t.length;i++)an(t[i]);for(var o=0;o<t.length;o++)ln(t[o]);for(var a=0;a<t.length;a++)sn(t[a])}function nn(e){var t=e.cm,r=t.display;xn(t),e.updateMaxLine&&be(t),e.mustUpdate=e.viewChanged||e.forceUpdate||null!=e.scrollTop||e.scrollToPos&&(e.scrollToPos.from.line<r.viewFrom||e.scrollToPos.to.line>=r.viewTo)||r.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new Ja(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function on(e){e.updatedDisplay=e.mustUpdate&&kn(e.cm,e.update)}function an(e){var t=e.cm,r=t.display;e.updatedDisplay&&Dr(t),e.barMeasure=qr(t),r.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Gt(t,r.maxLine,r.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(r.scroller.clientWidth,r.sizer.offsetLeft+e.adjustWidthTo+Rt(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,r.sizer.offsetLeft+e.adjustWidthTo-Bt(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=r.input.prepareSelection(e.focus))}function ln(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft<t.doc.scrollLeft&&Fr(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0),t.display.maxLineChanged=!1);var r=e.focus&&e.focus==o()&&(!document.hasFocus||document.hasFocus());e.preparedSelection&&t.display.input.showSelection(e.preparedSelection,r),(e.updatedDisplay||e.startHeight!=t.doc.height)&&Kr(t,e.barMeasure),e.updatedDisplay&&Mn(t,e.barMeasure),e.selectionChanged&&Ar(t),t.state.focused&&e.updateInput&&t.display.input.reset(e.typing),r&&_r(e.cm)}function sn(e){var t=e.cm,r=t.display,n=t.doc;if(e.updatedDisplay&&Cn(t,e.update),null==r.wheelStartX||null==e.scrollTop&&null==e.scrollLeft&&!e.scrollToPos||(r.wheelStartX=r.wheelStartY=null),null==e.scrollTop||r.scroller.scrollTop==e.scrollTop&&!e.forceScroll||(n.scrollTop=Math.max(0,Math.min(r.scroller.scrollHeight-r.scroller.clientHeight,e.scrollTop)),r.scrollbars.setScrollTop(n.scrollTop),r.scroller.scrollTop=n.scrollTop),null==e.scrollLeft||r.scroller.scrollLeft==e.scrollLeft&&!e.forceScroll||(n.scrollLeft=Math.max(0,Math.min(r.scroller.scrollWidth-r.scroller.clientWidth,e.scrollLeft)),r.scrollbars.setScrollLeft(n.scrollLeft),r.scroller.scrollLeft=n.scrollLeft,Er(t)),e.scrollToPos){var i=$r(t,R(n,e.scrollToPos.from),R(n,e.scrollToPos.to),e.scrollToPos.margin);e.scrollToPos.isCursor&&t.state.focused&&Gr(t,i)}var o=e.maybeHiddenMarkers,a=e.maybeUnhiddenMarkers;if(o)for(var l=0;l<o.length;++l)o[l].lines.length||_e(o[l],"hide");if(a)for(var s=0;s<a.length;++s)a[s].lines.length&&_e(a[s],"unhide");r.wrapper.offsetHeight&&(n.scrollTop=t.display.scroller.scrollTop),e.changeObjs&&_e(t,"changes",t,e.changeObjs),e.update&&e.update.finish()}function cn(e,t){if(e.curOp)return t();en(e);try{return t()}finally{tn(e)}}function un(e,t){return function(){if(e.curOp)return t.apply(e,arguments);en(e);try{return t.apply(e,arguments)}finally{tn(e)}}}function dn(e){return function(){if(this.curOp)return e.apply(this,arguments);en(this);try{return e.apply(this,arguments)}finally{tn(this)}}}function fn(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);en(t);try{return e.apply(this,arguments)}finally{tn(t)}}}function hn(e,t,r,n){null==t&&(t=e.doc.first),null==r&&(r=e.doc.first+e.doc.size),n||(n=0);var i=e.display;if(n&&r<i.viewTo&&(null==i.updateLineNumbers||i.updateLineNumbers>t)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Ta&&he(e.doc,t)<i.viewTo&&mn(e);else if(r<=i.viewFrom)Ta&&pe(e.doc,r+n)>i.viewFrom?mn(e):(i.viewFrom+=n,i.viewTo+=n);else if(t<=i.viewFrom&&r>=i.viewTo)mn(e);else if(t<=i.viewFrom){var o=gn(e,r,r+n,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=n):mn(e)}else if(r>=i.viewTo){var a=gn(e,t,t,-1);a?(i.view=i.view.slice(0,a.index),i.viewTo=a.lineN):mn(e)}else{var l=gn(e,t,t,-1),s=gn(e,r,r+n,1);l&&s?(i.view=i.view.slice(0,l.index).concat(yt(e,l.lineN,s.lineN)).concat(i.view.slice(s.index)),i.viewTo+=n):mn(e)}var c=i.externalMeasured;c&&(r<c.lineN?c.lineN+=n:t<c.lineN+c.size&&(i.externalMeasured=null))}function pn(e,t,r){e.curOp.viewChanged=!0;var n=e.display,i=e.display.externalMeasured;if(i&&t>=i.lineN&&t<i.lineN+i.size&&(n.externalMeasured=null),!(t<n.viewFrom||t>=n.viewTo)){var o=n.view[Cr(e,t)];if(null!=o.node){var a=o.changes||(o.changes=[]);d(a,r)==-1&&a.push(r)}}}function mn(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function gn(e,t,r,n){var i,o=Cr(e,t),a=e.display.view;if(!Ta||r==e.doc.first+e.doc.size)return{index:o,lineN:r};for(var l=e.display.viewFrom,s=0;s<o;s++)l+=a[s].size;if(l!=t){if(n>0){if(o==a.length-1)return null;i=l+a[o].size-t,o++}else i=l-t;t+=i,r+=i}for(;he(e.doc,r)!=r;){if(o==(n<0?0:a.length-1))return null;r+=n*a[o-(n<0?1:0)].size,o+=n}return{index:o,lineN:r}}function vn(e,t,r){var n=e.display;0==n.view.length||t>=n.viewTo||r<=n.viewFrom?(n.view=yt(e,t,r),n.viewFrom=t):(n.viewFrom>t?n.view=yt(e,t,n.viewFrom).concat(n.view):n.viewFrom<t&&(n.view=n.view.slice(Cr(e,t))),n.viewFrom=t,n.viewTo<r?n.view=n.view.concat(yt(e,n.viewTo,r)):n.viewTo>r&&(n.view=n.view.slice(0,Cr(e,r)))),n.viewTo=r}function yn(e){for(var t=e.display.view,r=0,n=0;n<t.length;n++){var i=t[n];i.hidden||i.node&&!i.changes||++r}return r}function bn(e,t){e.doc.mode.startState&&e.doc.frontier<e.display.viewTo&&e.state.highlight.set(t,s(wn,e))}function wn(e){var t=e.doc;if(t.frontier<t.first&&(t.frontier=t.first),!(t.frontier>=e.display.viewTo)){var r=+new Date+e.options.workTime,n=$e(t.mode,Qe(e,t.frontier)),i=[];t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(t.frontier>=e.display.viewFrom){var a=o.styles,l=o.text.length>e.options.maxHighlightLength,s=Ze(e,o,l?$e(t.mode,n):n,!0);o.styles=s.styles;var c=o.styleClasses,u=s.classes;u?o.styleClasses=u:c&&(o.styleClasses=null);for(var d=!a||a.length!=o.styles.length||c!=u&&(!c||!u||c.bgClass!=u.bgClass||c.textClass!=u.textClass),f=0;!d&&f<a.length;++f)d=a[f]!=o.styles[f];d&&i.push(t.frontier),o.stateAfter=l?n:$e(t.mode,n)}else o.text.length<=e.options.maxHighlightLength&&et(e,o.text,n),o.stateAfter=t.frontier%5==0?$e(t.mode,n):null;if(++t.frontier,+new Date>r)return bn(e,e.options.workDelay),!0}),i.length&&cn(e,function(){for(var t=0;t<i.length;t++)pn(e,i[t],"text")})}}function xn(e){var t=e.display;!t.scrollbarsClipped&&t.scroller.offsetWidth&&(t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth,t.heightForcer.style.height=Rt(e)+"px",t.sizer.style.marginBottom=-t.nativeBarWidth+"px",t.sizer.style.borderRightWidth=Rt(e)+"px",t.scrollbarsClipped=!0)}function kn(e,r){var n=e.display,i=e.doc;if(r.editorIsHidden)return mn(e),!1;if(!r.force&&r.visible.from>=n.viewFrom&&r.visible.to<=n.viewTo&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo)&&n.renderedView==n.view&&0==yn(e))return!1;zr(e)&&(mn(e),r.dims=yr(e));var a=i.first+i.size,l=Math.max(r.visible.from-e.options.viewportMargin,i.first),s=Math.min(a,r.visible.to+e.options.viewportMargin);n.viewFrom<l&&l-n.viewFrom<20&&(l=Math.max(i.first,n.viewFrom)),n.viewTo>s&&n.viewTo-s<20&&(s=Math.min(a,n.viewTo)),Ta&&(l=he(e.doc,l),s=pe(e.doc,s));var c=l!=n.viewFrom||s!=n.viewTo||n.lastWrapHeight!=r.wrapperHeight||n.lastWrapWidth!=r.wrapperWidth;vn(e,l,s),n.viewOffset=ve(L(e.doc,n.viewFrom)),e.display.mover.style.top=n.viewOffset+"px";var u=yn(e);if(!c&&0==u&&!r.force&&n.renderedView==n.view&&(null==n.updateLineNumbers||n.updateLineNumbers>=n.viewTo))return!1;var d=o();return u>4&&(n.lineDiv.style.display="none"),Tn(e,n.updateLineNumbers,r.dims),u>4&&(n.lineDiv.style.display=""),n.renderedView=n.view,d&&o()!=d&&d.offsetHeight&&d.focus(),t(n.cursorDiv),t(n.selectionDiv),n.gutters.style.height=n.sizer.style.minHeight=0,c&&(n.lastWrapHeight=r.wrapperHeight,n.lastWrapWidth=r.wrapperWidth,bn(e,400)),n.updateLineNumbers=null,!0}function Cn(e,t){for(var r=t.viewport,n=!0;(n&&e.options.lineWrapping&&t.oldDisplayWidth!=Bt(e)||(r&&null!=r.top&&(r={top:Math.min(e.doc.height+Ft(e.display)-qt(e),r.top)}),t.visible=Hr(e.display,e.doc,r),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&kn(e,t);n=!1){Dr(e);var i=qr(e);Sr(e),Kr(e,i),Mn(e,i)}t.signal(e,"update",e),e.display.viewFrom==e.display.reportedViewFrom&&e.display.viewTo==e.display.reportedViewTo||(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function Sn(e,t){var r=new Ja(e,t);if(kn(e,r)){Dr(e),Cn(e,r);var n=qr(e);Sr(e),Kr(e,n),Mn(e,n),r.finish()}}function Tn(e,r,n){function i(t){var r=t.nextSibling;return Yo&&ia&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),r}for(var o=e.display,a=e.options.lineNumbers,l=o.lineDiv,s=l.firstChild,c=o.view,u=o.viewFrom,f=0;f<c.length;f++){var h=c[f];if(h.hidden);else if(h.node&&h.node.parentNode==l){for(;s!=h.node;)s=i(s);var p=a&&null!=r&&r<=u&&h.lineNumber;h.changes&&(d(h.changes,"gutter")>-1&&(p=!1),St(e,h,u,n)),p&&(t(h.lineNumber),h.lineNumber.appendChild(document.createTextNode(E(e.options,u)))),s=h.node.nextSibling}else{var m=Wt(e,h,u,n);l.insertBefore(m,s)}u+=h.size}for(;s;)s=i(s)}function Ln(e){var t=e.display.gutters.offsetWidth;e.display.sizer.style.marginLeft=t+"px"}function Mn(e,t){e.display.sizer.style.minHeight=t.docHeight+"px",e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=t.docHeight+e.display.barHeight+Rt(e)+"px"}function An(e){var r=e.display.gutters,i=e.options.gutters;t(r);for(var o=0;o<i.length;++o){var a=i[o],l=r.appendChild(n("div",null,"CodeMirror-gutter "+a));"CodeMirror-linenumbers"==a&&(e.display.lineGutter=l,l.style.width=(e.display.lineNumWidth||1)+"px")}r.style.display=o?"":"none",Ln(e)}function _n(e){var t=d(e.gutters,"CodeMirror-linenumbers");t==-1&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function On(e,t){var r=e[t];e.sort(function(e,t){return D(e.from(),t.from())}),t=d(e,r);for(var n=1;n<e.length;n++){var i=e[n],o=e[n-1];if(D(o.to(),i.from())>=0){var a=F(o.from(),i.from()),l=I(o.to(),i.to()),s=o.empty()?i.from()==i.head:o.from()==o.head;n<=t&&--t,e.splice(--n,2,new el(s?l:a,s?a:l))}}return new Qa(e,t)}function Nn(e,t){return new Qa([new el(e,t||e)],0)}function Wn(e){return e.text?z(e.from.line+e.text.length-1,p(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function En(e,t){if(D(e,t.from)<0)return e;if(D(e,t.to)<=0)return Wn(t);var r=e.line+t.text.length-(t.to.line-t.from.line)-1,n=e.ch;return e.line==t.to.line&&(n+=Wn(t).ch-t.to.ch),z(r,n)}function zn(e,t){for(var r=[],n=0;n<e.sel.ranges.length;n++){var i=e.sel.ranges[n];r.push(new el(En(i.anchor,t),En(i.head,t)))}return On(r,e.sel.primIndex)}function Dn(e,t,r){return e.line==t.line?z(r.line,e.ch-t.ch+r.ch):z(r.line+(e.line-t.line),e.ch)}function Pn(e,t,r){for(var n=[],i=z(e.first,0),o=i,a=0;a<t.length;a++){var l=t[a],s=Dn(l.from,i,o),c=Dn(Wn(l),i,o);if(i=l.to,o=c,"around"==r){var u=e.sel.ranges[a],d=D(u.head,u.anchor)<0;n[a]=new el(d?c:s,d?s:c)}else n[a]=new el(s,s)}return new Qa(n,e.sel.primIndex)}function Hn(e){e.doc.mode=Ve(e.options,e.doc.modeOption),In(e)}function In(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,bn(e,100),e.state.modeGen++,e.curOp&&hn(e)}function Fn(e,t){return 0==t.from.ch&&0==t.to.ch&&""==p(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function jn(e,t,r,n){function i(e){return r?r[e]:null}function o(e,r,i){lt(e,r,i,n),kt(e,"change",e,t)}function a(e,t){for(var r=[],o=e;o<t;++o)r.push(new Fa(c[o],i(o),n));return r}var l=t.from,s=t.to,c=t.text,u=L(e,l.line),d=L(e,s.line),f=p(c),h=i(c.length-1),m=s.line-l.line;if(t.full)e.insert(0,a(0,c.length)),e.remove(c.length,e.size-c.length);else if(Fn(e,t)){var g=a(0,c.length-1);o(d,d.text,h),m&&e.remove(l.line,m),g.length&&e.insert(l.line,g)}else if(u==d)if(1==c.length)o(u,u.text.slice(0,l.ch)+f+u.text.slice(s.ch),h);else{var v=a(1,c.length-1);v.push(new Fa(f+u.text.slice(s.ch),h,n)),o(u,u.text.slice(0,l.ch)+c[0],i(0)),e.insert(l.line+1,v)}else if(1==c.length)o(u,u.text.slice(0,l.ch)+c[0]+d.text.slice(s.ch),i(0)),e.remove(l.line+1,m);else{o(u,u.text.slice(0,l.ch)+c[0],i(0)),o(d,f+d.text.slice(s.ch),h);var y=a(1,c.length-1);m>1&&e.remove(l.line+1,m-1),e.insert(l.line+1,y)}kt(e,"change",e,t)}function Rn(e,t,r){function n(e,i,o){if(e.linked)for(var a=0;a<e.linked.length;++a){var l=e.linked[a];if(l.doc!=i){var s=o&&l.sharedHist;r&&!s||(t(l.doc,s),n(l.doc,e,s))}}}n(e,null,!0)}function Bn(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,xr(e),Hn(e),e.options.lineWrapping||be(e),e.options.mode=t.modeOption,hn(e)}function qn(e){this.done=[],this.undone=[],this.undoDepth=1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=this.lastSelOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e||1}function Kn(e,t){var r={from:H(t.from),to:Wn(t),text:M(e,t.from,t.to)};return Zn(e,r,t.from.line,t.to.line+1),Rn(e,function(e){return Zn(e,r,t.from.line,t.to.line+1)},!0),r}function Un(e){for(;e.length;){if(!p(e).ranges)break;e.pop()}}function Vn(e,t){return t?(Un(e.done),p(e.done)):e.done.length&&!p(e.done).ranges?p(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),p(e.done)):void 0}function Gn(e,t,r,n){var i=e.history;i.undone.length=0;var o,a,l=+new Date;if((i.lastOp==n||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&e.cm&&i.lastModTime>l-e.cm.options.historyEventDelay||"*"==t.origin.charAt(0)))&&(o=Vn(i,i.lastOp==n)))a=p(o.changes),0==D(t.from,t.to)&&0==D(t.from,a.to)?a.to=Wn(t):o.changes.push(Kn(e,t));else{var s=p(i.done);for(s&&s.ranges||Xn(e.sel,i.done),o={changes:[Kn(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(r),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=l,i.lastOp=i.lastSelOp=n,i.lastOrigin=i.lastSelOrigin=t.origin,a||_e(e,"historyAdded")}function $n(e,t,r,n){var i=t.charAt(0);return"*"==i||"+"==i&&r.ranges.length==n.ranges.length&&r.somethingSelected()==n.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function Yn(e,t,r,n){var i=e.history,o=n&&n.origin;r==i.lastSelOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||$n(e,o,p(i.done),t))?i.done[i.done.length-1]=t:Xn(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=r,n&&n.clearRedo!==!1&&Un(i.undone)}function Xn(e,t){var r=p(t);r&&r.ranges&&r.equals(e)||t.push(e)}function Zn(e,t,r,n){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,r),Math.min(e.first+e.size,n),function(r){r.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=r.markedSpans),++o})}function Jn(e){if(!e)return null;for(var t,r=0;r<e.length;++r)e[r].marker.explicitlyCleared?t||(t=e.slice(0,r)):t&&t.push(e[r]);return t?t.length?t:null:e}function Qn(e,t){var r=t["spans_"+e.id];if(!r)return null;for(var n=[],i=0;i<t.text.length;++i)n.push(Jn(r[i]));return n}function ei(e,t){var r=Qn(e,t),n=J(e,t);if(!r)return n;if(!n)return r;for(var i=0;i<r.length;++i){var o=r[i],a=n[i];if(o&&a)e:for(var l=0;l<a.length;++l){for(var s=a[l],c=0;c<o.length;++c)if(o[c].marker==s.marker)continue e;o.push(s)}else a&&(r[i]=a)}return r}function ti(e,t,r){for(var n=[],i=0;i<e.length;++i){var o=e[i];if(o.ranges)n.push(r?Qa.prototype.deepCopy.call(o):o);else{var a=o.changes,l=[];n.push({changes:l});for(var s=0;s<a.length;++s){var c=a[s],u=void 0;if(l.push({from:c.from,to:c.to,text:c.text}),t)for(var f in c)(u=f.match(/^spans_(\d+)$/))&&d(t,Number(u[1]))>-1&&(p(l)[f]=c[f],delete c[f])}}}return n}function ri(e,t,r,n){if(e.cm&&e.cm.display.shift||e.extend){var i=t.anchor;if(n){var o=D(r,i)<0;o!=D(n,i)<0?(i=r,r=n):o!=D(r,n)<0&&(r=n)}return new el(i,r)}return new el(n||r,r)}function ni(e,t,r,n){ci(e,new Qa([ri(e,e.sel.primary(),t,r)],0),n)}function ii(e,t,r){for(var n=[],i=0;i<e.sel.ranges.length;i++)n[i]=ri(e,e.sel.ranges[i],t[i],null);ci(e,On(n,e.sel.primIndex),r)}function oi(e,t,r,n){var i=e.sel.ranges.slice(0);i[t]=r,ci(e,On(i,e.sel.primIndex),n)}function ai(e,t,r,n){ci(e,Nn(t,r),n)}function li(e,t,r){var n={ranges:t.ranges,update:function(t){var r=this;this.ranges=[];for(var n=0;n<t.length;n++)r.ranges[n]=new el(R(e,t[n].anchor),R(e,t[n].head))},origin:r&&r.origin};return _e(e,"beforeSelectionChange",e,n),e.cm&&_e(e.cm,"beforeSelectionChange",e.cm,n),n.ranges!=t.ranges?On(n.ranges,n.ranges.length-1):t}function si(e,t,r){var n=e.history.done,i=p(n);i&&i.ranges?(n[n.length-1]=t,ui(e,t,r)):ci(e,t,r)}function ci(e,t,r){ui(e,t,r),Yn(e,e.sel,e.cm?e.cm.curOp.id:NaN,r)}function ui(e,t,r){(We(e,"beforeSelectionChange")||e.cm&&We(e.cm,"beforeSelectionChange"))&&(t=li(e,t,r)),di(e,hi(e,t,r&&r.bias||(D(t.primary().head,e.sel.primary().head)<0?-1:1),!0)),r&&r.scroll===!1||!e.cm||Jr(e.cm)}function di(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=!0,Ne(e.cm)),kt(e,"cursorActivity",e))}function fi(e){di(e,hi(e,e.sel,null,!1),ya)}function hi(e,t,r,n){for(var i,o=0;o<t.ranges.length;o++){var a=t.ranges[o],l=t.ranges.length==e.sel.ranges.length&&e.sel.ranges[o],s=mi(e,a.anchor,l&&l.anchor,r,n),c=mi(e,a.head,l&&l.head,r,n);(i||s!=a.anchor||c!=a.head)&&(i||(i=t.ranges.slice(0,o)),i[o]=new el(s,c))}return i?On(i,t.primIndex):t}function pi(e,t,r,n,i){var o=L(e,t.line);if(o.markedSpans)for(var a=0;a<o.markedSpans.length;++a){var l=o.markedSpans[a],s=l.marker;if((null==l.from||(s.inclusiveLeft?l.from<=t.ch:l.from<t.ch))&&(null==l.to||(s.inclusiveRight?l.to>=t.ch:l.to>t.ch))){if(i&&(_e(s,"beforeCursorEnter"),s.explicitlyCleared)){if(o.markedSpans){--a;continue}break}if(!s.atomic)continue;if(r){var c=s.find(n<0?1:-1),u=void 0;if((n<0?s.inclusiveRight:s.inclusiveLeft)&&(c=gi(e,c,-n,c&&c.line==t.line?o:null)),c&&c.line==t.line&&(u=D(c,r))&&(n<0?u<0:u>0))return pi(e,c,t,n,i)}var d=s.find(n<0?-1:1);return(n<0?s.inclusiveLeft:s.inclusiveRight)&&(d=gi(e,d,n,d.line==t.line?o:null)),d?pi(e,d,t,n,i):null}}return t}function mi(e,t,r,n,i){var o=n||1,a=pi(e,t,r,o,i)||!i&&pi(e,t,r,o,!0)||pi(e,t,r,-o,i)||!i&&pi(e,t,r,-o,!0);return a?a:(e.cantEdit=!0,z(e.first,0))}function gi(e,t,r,n){return r<0&&0==t.ch?t.line>e.first?R(e,z(t.line-1)):null:r>0&&t.ch==(n||L(e,t.line)).text.length?t.line<e.first+e.size-1?z(t.line+1,0):null:new z(t.line,t.ch+r)}function vi(e){e.setSelection(z(e.firstLine(),0),z(e.lastLine()),ya)}function yi(e,t,r){var n={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){return n.canceled=!0}};return r&&(n.update=function(t,r,i,o){t&&(n.from=R(e,t)),r&&(n.to=R(e,r)),i&&(n.text=i),void 0!==o&&(n.origin=o)}),_e(e,"beforeChange",e,n),e.cm&&_e(e.cm,"beforeChange",e.cm,n),n.canceled?null:{from:n.from,to:n.to,text:n.text,origin:n.origin}}function bi(e,t,r){if(e.cm){if(!e.cm.curOp)return un(e.cm,bi)(e,t,r);if(e.cm.state.suppressEdits)return}if(!(We(e,"beforeChange")||e.cm&&We(e.cm,"beforeChange"))||(t=yi(e,t,!0))){var n=Sa&&!r&&ee(e,t.from,t.to);if(n)for(var i=n.length-1;i>=0;--i)wi(e,{from:n[i].from,to:n[i].to,text:i?[""]:t.text});else wi(e,t)}}function wi(e,t){if(1!=t.text.length||""!=t.text[0]||0!=D(t.from,t.to)){var r=zn(e,t);Gn(e,t,r,e.cm?e.cm.curOp.id:NaN),Ci(e,t,r,J(e,t));var n=[];Rn(e,function(e,r){r||d(n,e.history)!=-1||(Ai(e.history,t),n.push(e.history)),Ci(e,t,null,J(e,t))})}}function xi(e,t,r){if(!e.cm||!e.cm.state.suppressEdits||r){for(var n,i=e.history,o=e.sel,a="undo"==t?i.done:i.undone,l="undo"==t?i.undone:i.done,s=0;s<a.length&&(n=a[s],r?!n.ranges||n.equals(e.sel):n.ranges);s++);if(s!=a.length){for(i.lastOrigin=i.lastSelOrigin=null;n=a.pop(),n.ranges;){if(Xn(n,l),r&&!n.equals(e.sel))return void ci(e,n,{clearRedo:!1});o=n}var c=[];Xn(o,l),l.push({changes:c,generation:i.generation}),i.generation=n.generation||++i.maxGeneration;for(var u=We(e,"beforeChange")||e.cm&&We(e.cm,"beforeChange"),f=n.changes.length-1;f>=0;--f){var h=function(r){var i=n.changes[r];if(i.origin=t,u&&!yi(e,i,!1))return a.length=0,{};c.push(Kn(e,i)),
4
- Ci(e,i,r?zn(e,i):p(a),ei(e,i)),!r&&e.cm&&e.cm.scrollIntoView({from:i.from,to:Wn(i)});var o=[];Rn(e,function(e,t){t||d(o,e.history)!=-1||(Ai(e.history,i),o.push(e.history)),Ci(e,i,null,ei(e,i))})}(f);if(h)return h.v}}}}function ki(e,t){if(0!=t&&(e.first+=t,e.sel=new Qa(m(e.sel.ranges,function(e){return new el(z(e.anchor.line+t,e.anchor.ch),z(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){hn(e.cm,e.first,e.first-t,t);for(var r=e.cm.display,n=r.viewFrom;n<r.viewTo;n++)pn(e.cm,n,"gutter")}}function Ci(e,t,r,n){if(e.cm&&!e.cm.curOp)return un(e.cm,Ci)(e,t,r,n);if(t.to.line<e.first)return void ki(e,t.text.length-1-(t.to.line-t.from.line));if(!(t.from.line>e.lastLine())){if(t.from.line<e.first){var i=t.text.length-1-(e.first-t.from.line);ki(e,i),t={from:z(e.first,0),to:z(t.to.line+i,t.to.ch),text:[p(t.text)],origin:t.origin}}var o=e.lastLine();t.to.line>o&&(t={from:t.from,to:z(o,L(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=M(e,t.from,t.to),r||(r=zn(e,t)),e.cm?Si(e.cm,t,n):jn(e,t,n),ui(e,r,ya)}}function Si(e,t,r){var n=e.doc,i=e.display,o=t.from,a=t.to,l=!1,s=o.line;e.options.lineWrapping||(s=O(ue(L(n,o.line))),n.iter(s,a.line+1,function(e){if(e==i.maxLine)return l=!0,!0})),n.sel.contains(t.from,t.to)>-1&&Ne(e),jn(n,t,r,wr(e)),e.options.lineWrapping||(n.iter(s,o.line+t.text.length,function(e){var t=ye(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,l=!1)}),l&&(e.curOp.updateMaxLine=!0)),n.frontier=Math.min(n.frontier,o.line),bn(e,400);var c=t.text.length-(a.line-o.line)-1;t.full?hn(e):o.line!=a.line||1!=t.text.length||Fn(e.doc,t)?hn(e,o.line,a.line+1,c):pn(e,o.line,"text");var u=We(e,"changes"),d=We(e,"change");if(d||u){var f={from:o,to:a,text:t.text,removed:t.removed,origin:t.origin};d&&kt(e,"change",e,f),u&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(f)}e.display.selForContextMenu=null}function Ti(e,t,r,n,i){if(n||(n=r),D(n,r)<0){var o=n;n=r,r=o}"string"==typeof t&&(t=e.splitLines(t)),bi(e,{from:r,to:n,text:t,origin:i})}function Li(e,t,r,n){r<e.line?e.line+=n:t<e.line&&(e.line=t,e.ch=0)}function Mi(e,t,r,n){for(var i=0;i<e.length;++i){var o=e[i],a=!0;if(o.ranges){o.copied||(o=e[i]=o.deepCopy(),o.copied=!0);for(var l=0;l<o.ranges.length;l++)Li(o.ranges[l].anchor,t,r,n),Li(o.ranges[l].head,t,r,n)}else{for(var s=0;s<o.changes.length;++s){var c=o.changes[s];if(r<c.from.line)c.from=z(c.from.line+n,c.from.ch),c.to=z(c.to.line+n,c.to.ch);else if(t<=c.to.line){a=!1;break}}a||(e.splice(0,i+1),i=0)}}}function Ai(e,t){var r=t.from.line,n=t.to.line,i=t.text.length-(n-r)-1;Mi(e.done,r,n,i),Mi(e.undone,r,n,i)}function _i(e,t,r,n){var i=t,o=t;return"number"==typeof t?o=L(e,j(e,t)):i=O(t),null==i?null:(n(o,i)&&e.cm&&pn(e.cm,i,r),o)}function Oi(e,t,r){ve(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Zr(e,null,r)}function Ni(e,t,r,n){var i=new nl(e,r,n),o=e.cm;return o&&i.noHScroll&&(o.display.alignWidgets=!0),_i(e,t,"widget",function(t){var r=t.widgets||(t.widgets=[]);if(null==i.insertAt?r.push(i):r.splice(Math.min(r.length-1,Math.max(0,i.insertAt)),0,i),i.line=t,o&&!me(e,t)){var n=ve(t)<e.scrollTop;_(t,t.height+Pt(i)),n&&Zr(o,null,i.height),o.curOp.forceUpdate=!0}return!0}),kt(o,"lineWidgetAdded",o,i,"number"==typeof t?t:O(t)),i}function Wi(e,t,r,i,o){if(i&&i.shared)return Ei(e,t,r,i,o);if(e.cm&&!e.cm.curOp)return un(e.cm,Wi)(e,t,r,i,o);var a=new ol(e,o),l=D(t,r);if(i&&c(i,a,!1),l>0||0==l&&a.clearWhenEmpty!==!1)return a;if(a.replacedWith&&(a.collapsed=!0,a.widgetNode=n("span",[a.replacedWith],"CodeMirror-widget"),a.widgetNode.setAttribute("role","presentation"),i.handleMouseEvents||a.widgetNode.setAttribute("cm-ignore-events","true"),i.insertLeft&&(a.widgetNode.insertLeft=!0)),a.collapsed){if(ce(e,t.line,t,r,a)||t.line!=r.line&&ce(e,r.line,t,r,a))throw new Error("Inserting collapsed marker partially overlapping an existing one");U()}a.addToHistory&&Gn(e,{from:t,to:r,origin:"markText"},e.sel,NaN);var s,u=t.line,d=e.cm;if(e.iter(u,r.line+1,function(e){d&&a.collapsed&&!d.options.lineWrapping&&ue(e)==d.display.maxLine&&(s=!0),a.collapsed&&u!=t.line&&_(e,0),Y(e,new V(a,u==t.line?t.ch:null,u==r.line?r.ch:null)),++u}),a.collapsed&&e.iter(t.line,r.line+1,function(t){me(e,t)&&_(t,0)}),a.clearOnEnter&&_a(a,"beforeCursorEnter",function(){return a.clear()}),a.readOnly&&(K(),(e.history.done.length||e.history.undone.length)&&e.clearHistory()),a.collapsed&&(a.id=++il,a.atomic=!0),d){if(s&&(d.curOp.updateMaxLine=!0),a.collapsed)hn(d,t.line,r.line+1);else if(a.className||a.title||a.startStyle||a.endStyle||a.css)for(var f=t.line;f<=r.line;f++)pn(d,f,"text");a.atomic&&fi(d.doc),kt(d,"markerAdded",d,a)}return a}function Ei(e,t,r,n,i){n=c(n),n.shared=!1;var o=[Wi(e,t,r,n,i)],a=o[0],l=n.widgetNode;return Rn(e,function(e){l&&(n.widgetNode=l.cloneNode(!0)),o.push(Wi(e,R(e,t),R(e,r),n,i));for(var s=0;s<e.linked.length;++s)if(e.linked[s].isParent)return;a=p(o)}),new al(o,a)}function zi(e){return e.findMarks(z(e.first,0),e.clipPos(z(e.lastLine())),function(e){return e.parent})}function Di(e,t){for(var r=0;r<t.length;r++){var n=t[r],i=n.find(),o=e.clipPos(i.from),a=e.clipPos(i.to);if(D(o,a)){var l=Wi(e,o,a,n.primary,n.primary.type);n.markers.push(l),l.parent=n}}}function Pi(e){for(var t=0;t<e.length;t++)!function(t){var r=e[t],n=[r.primary.doc];Rn(r.primary.doc,function(e){return n.push(e)});for(var i=0;i<r.markers.length;i++){var o=r.markers[i];d(n,o.doc)==-1&&(o.parent=null,r.markers.splice(i--,1))}}(t)}function Hi(e){var t=this;if(ji(t),!Oe(t,e)&&!Ht(t.display,e)){ze(e),Go&&(cl=+new Date);var r=kr(t,e,!0),n=e.dataTransfer.files;if(r&&!t.isReadOnly())if(n&&n.length&&window.FileReader&&window.File)for(var i=n.length,o=Array(i),a=0,l=0;l<i;++l)!function(e,n){if(!t.options.allowDropFileTypes||d(t.options.allowDropFileTypes,e.type)!=-1){var l=new FileReader;l.onload=un(t,function(){var e=l.result;if(/[\x00-\x08\x0e-\x1f]{2}/.test(e)&&(e=""),o[n]=e,++a==i){r=R(t.doc,r);var s={from:r,to:r,text:t.doc.splitLines(o.join(t.doc.lineSeparator())),origin:"paste"};bi(t.doc,s),si(t.doc,Nn(r,Wn(s)))}}),l.readAsText(e)}}(n[l],l);else{if(t.state.draggingText&&t.doc.sel.contains(r)>-1)return t.state.draggingText(e),void setTimeout(function(){return t.display.input.focus()},20);try{var s=e.dataTransfer.getData("Text");if(s){var c;if(t.state.draggingText&&!t.state.draggingText.copy&&(c=t.listSelections()),ui(t.doc,Nn(r,r)),c)for(var u=0;u<c.length;++u)Ti(t.doc,"",c[u].anchor,c[u].head,"drag");t.replaceSelection(s,"around","paste"),t.display.input.focus()}}catch(e){}}}}function Ii(e,t){if(Go&&(!e.state.draggingText||+new Date-cl<100))return void He(t);if(!Oe(e,t)&&!Ht(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setDragImage&&!Qo)){var r=n("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",Jo&&(r.width=r.height=1,e.display.wrapper.appendChild(r),r._top=r.offsetTop),t.dataTransfer.setDragImage(r,0,0),Jo&&r.parentNode.removeChild(r)}}function Fi(e,t){var i=kr(e,t);if(i){var o=document.createDocumentFragment();Lr(e,i,o),e.display.dragCursor||(e.display.dragCursor=n("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)),r(e.display.dragCursor,o)}}function ji(e){e.display.dragCursor&&(e.display.lineSpace.removeChild(e.display.dragCursor),e.display.dragCursor=null)}function Ri(e){if(document.body.getElementsByClassName)for(var t=document.body.getElementsByClassName("CodeMirror"),r=0;r<t.length;r++){var n=t[r].CodeMirror;n&&e(n)}}function Bi(){ul||(qi(),ul=!0)}function qi(){var e;_a(window,"resize",function(){null==e&&(e=setTimeout(function(){e=null,Ri(Ki)},100))}),_a(window,"blur",function(){return Ri(Wr)})}function Ki(e){var t=e.display;t.lastWrapHeight==t.wrapper.clientHeight&&t.lastWrapWidth==t.wrapper.clientWidth||(t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize())}function Ui(e){var t=e.split(/-(?!$)/);e=t[t.length-1];for(var r,n,i,o,a=0;a<t.length-1;a++){var l=t[a];if(/^(cmd|meta|m)$/i.test(l))o=!0;else if(/^a(lt)?$/i.test(l))r=!0;else if(/^(c|ctrl|control)$/i.test(l))n=!0;else{if(!/^s(hift)?$/i.test(l))throw new Error("Unrecognized modifier name: "+l);i=!0}}return r&&(e="Alt-"+e),n&&(e="Ctrl-"+e),o&&(e="Cmd-"+e),i&&(e="Shift-"+e),e}function Vi(e){var t={};for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];if(/^(name|fallthrough|(de|at)tach)$/.test(r))continue;if("..."==n){delete e[r];continue}for(var i=m(r.split(" "),Ui),o=0;o<i.length;o++){var a=void 0,l=void 0;o==i.length-1?(l=i.join(" "),a=n):(l=i.slice(0,o+1).join(" "),a="...");var s=t[l];if(s){if(s!=a)throw new Error("Inconsistent bindings for "+l)}else t[l]=a}delete e[r]}for(var c in t)e[c]=t[c];return e}function Gi(e,t,r,n){t=Xi(t);var i=t.call?t.call(e,n):t[e];if(i===!1)return"nothing";if("..."===i)return"multi";if(null!=i&&r(i))return"handled";if(t.fallthrough){if("[object Array]"!=Object.prototype.toString.call(t.fallthrough))return Gi(e,t.fallthrough,r,n);for(var o=0;o<t.fallthrough.length;o++){var a=Gi(e,t.fallthrough[o],r,n);if(a)return a}}}function $i(e){var t="string"==typeof e?e:dl[e.keyCode];return"Ctrl"==t||"Alt"==t||"Shift"==t||"Mod"==t}function Yi(e,t){if(Jo&&34==e.keyCode&&e.char)return!1;var r=dl[e.keyCode],n=r;return null!=n&&!e.altGraphKey&&(e.altKey&&"Alt"!=r&&(n="Alt-"+n),(ca?e.metaKey:e.ctrlKey)&&"Ctrl"!=r&&(n="Ctrl-"+n),(ca?e.ctrlKey:e.metaKey)&&"Cmd"!=r&&(n="Cmd-"+n),!t&&e.shiftKey&&"Shift"!=r&&(n="Shift-"+n),n)}function Xi(e){return"string"==typeof e?ml[e]:e}function Zi(e,t){for(var r=e.doc.sel.ranges,n=[],i=0;i<r.length;i++){for(var o=t(r[i]);n.length&&D(o.from,p(n).to)<=0;){var a=n.pop();if(D(a.from,o.from)<0){o.from=a.from;break}}n.push(o)}cn(e,function(){for(var t=n.length-1;t>=0;t--)Ti(e.doc,"",n[t].from,n[t].to,"+delete");Jr(e)})}function Ji(e,t){var r=L(e.doc,t),n=ue(r);return n!=r&&(t=O(n)),Te(!0,e,n,t,1)}function Qi(e,t){var r=L(e.doc,t),n=de(r);return n!=r&&(t=O(n)),Te(!0,e,r,t,-1)}function eo(e,t){var r=Ji(e,t.line),n=L(e.doc,r.line),i=ke(n);if(!i||0==i[0].level){var o=Math.max(0,n.text.search(/\S/)),a=t.line==r.line&&t.ch<=o&&t.ch;return z(r.line,a?0:o,r.sticky)}return r}function to(e,t,r){if("string"==typeof t&&!(t=yl[t]))return!1;e.display.input.ensurePolled();var n=e.display.shift,i=!1;try{e.isReadOnly()&&(e.state.suppressEdits=!0),r&&(e.display.shift=!1),i=t(e)!=va}finally{e.display.shift=n,e.state.suppressEdits=!1}return i}function ro(e,t,r){for(var n=0;n<e.state.keyMaps.length;n++){var i=Gi(t,e.state.keyMaps[n],r,e);if(i)return i}return e.options.extraKeys&&Gi(t,e.options.extraKeys,r,e)||Gi(t,e.options.keyMap,r,e)}function no(e,t,r,n){var i=e.state.keySeq;if(i){if($i(t))return"handled";bl.set(50,function(){e.state.keySeq==i&&(e.state.keySeq=null,e.display.input.reset())}),t=i+" "+t}var o=ro(e,t,n);return"multi"==o&&(e.state.keySeq=t),"handled"==o&&kt(e,"keyHandled",e,t,r),"handled"!=o&&"multi"!=o||(ze(r),Ar(e)),i&&!o&&/\'$/.test(t)?(ze(r),!0):!!o}function io(e,t){var r=Yi(t,!0);return!!r&&(t.shiftKey&&!e.state.keySeq?no(e,"Shift-"+r,t,function(t){return to(e,t,!0)})||no(e,r,t,function(t){if("string"==typeof t?/^go[A-Z]/.test(t):t.motion)return to(e,t)}):no(e,r,t,function(t){return to(e,t)}))}function oo(e,t,r){return no(e,"'"+r+"'",t,function(t){return to(e,t,!0)})}function ao(e){var t=this;if(t.curOp.focus=o(),!Oe(t,e)){Go&&$o<11&&27==e.keyCode&&(e.returnValue=!1);var r=e.keyCode;t.display.shift=16==r||e.shiftKey;var n=io(t,e);Jo&&(wl=n?r:null,!n&&88==r&&!Ea&&(ia?e.metaKey:e.ctrlKey)&&t.replaceSelection("",null,"cut")),18!=r||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||lo(t)}}function lo(e){function t(e){18!=e.keyCode&&e.altKey||(da(r,"CodeMirror-crosshair"),Ae(document,"keyup",t),Ae(document,"mouseover",t))}var r=e.display.lineDiv;a(r,"CodeMirror-crosshair"),_a(document,"keyup",t),_a(document,"mouseover",t)}function so(e){16==e.keyCode&&(this.doc.sel.shift=!1),Oe(this,e)}function co(e){var t=this;if(!(Ht(t.display,e)||Oe(t,e)||e.ctrlKey&&!e.altKey||ia&&e.metaKey)){var r=e.keyCode,n=e.charCode;if(Jo&&r==wl)return wl=null,void ze(e);if(!Jo||e.which&&!(e.which<10)||!io(t,e)){var i=String.fromCharCode(null==n?r:n);"\b"!=i&&(oo(t,e,i)||t.display.input.onKeyPress(e))}}}function uo(e){var t=this,r=t.display;if(!(Oe(t,e)||r.activeTouch&&r.input.supportsTouch())){if(r.input.ensurePolled(),r.shift=e.shiftKey,Ht(r,e))return void(Yo||(r.scroller.draggable=!1,setTimeout(function(){return r.scroller.draggable=!0},100)));if(!go(t,e)){var n=kr(t,e);switch(window.focus(),Fe(e)){case 1:t.state.selectingText?t.state.selectingText(e):n?fo(t,e,n):Ie(e)==r.scroller&&ze(e);break;case 2:Yo&&(t.state.lastMiddleDown=+new Date),n&&ni(t.doc,n),setTimeout(function(){return r.input.focus()},20),ze(e);break;case 3:ua?vo(t,e):Or(t)}}}}function fo(e,t,r){Go?setTimeout(s(_r,e),0):e.curOp.focus=o();var n,i=+new Date;vl&&vl.time>i-400&&0==D(vl.pos,r)?n="triple":gl&&gl.time>i-400&&0==D(gl.pos,r)?(n="double",vl={time:i,pos:r}):(n="single",gl={time:i,pos:r});var a,l=e.doc.sel,c=ia?t.metaKey:t.ctrlKey;e.options.dragDrop&&Oa&&!e.isReadOnly()&&"single"==n&&(a=l.contains(r))>-1&&(D((a=l.ranges[a]).from(),r)<0||r.xRel>0)&&(D(a.to(),r)>0||r.xRel<0)?ho(e,t,r,c):po(e,t,r,n,c)}function ho(e,t,r,n){var i=e.display,o=+new Date,a=un(e,function(l){Yo&&(i.scroller.draggable=!1),e.state.draggingText=!1,Ae(document,"mouseup",a),Ae(i.scroller,"drop",a),Math.abs(t.clientX-l.clientX)+Math.abs(t.clientY-l.clientY)<10&&(ze(l),!n&&+new Date-200<o&&ni(e.doc,r),Yo||Go&&9==$o?setTimeout(function(){document.body.focus(),i.input.focus()},20):i.input.focus())});Yo&&(i.scroller.draggable=!0),e.state.draggingText=a,a.copy=ia?t.altKey:t.ctrlKey,i.scroller.dragDrop&&i.scroller.dragDrop(),_a(document,"mouseup",a),_a(i.scroller,"drop",a)}function po(e,t,r,n,i){function a(t){if(0!=D(b,t))if(b=t,"rect"==n){for(var i=[],o=e.options.tabSize,a=u(L(d,r.line).text,r.ch,o),l=u(L(d,t.line).text,t.ch,o),s=Math.min(a,l),c=Math.max(a,l),g=Math.min(r.line,t.line),v=Math.min(e.lastLine(),Math.max(r.line,t.line));g<=v;g++){var y=L(d,g).text,w=f(y,s,o);s==c?i.push(new el(z(g,w),z(g,w))):y.length>w&&i.push(new el(z(g,w),z(g,f(y,c,o))))}i.length||i.push(new el(r,r)),ci(d,On(m.ranges.slice(0,p).concat(i),p),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var x=h,k=x.anchor,C=t;if("single"!=n){var S;S="double"==n?e.findWordAt(t):new el(z(t.line,0),R(d,z(t.line+1,0))),D(S.anchor,k)>0?(C=S.head,k=F(x.from(),S.anchor)):(C=S.anchor,k=I(x.to(),S.head))}var T=m.ranges.slice(0);T[p]=new el(R(d,k),C),ci(d,On(T,p),ba)}}function l(t){var r=++x,i=kr(e,t,!0,"rect"==n);if(i)if(0!=D(i,b)){e.curOp.focus=o(),a(i);var s=Hr(c,d);(i.line>=s.to||i.line<s.from)&&setTimeout(un(e,function(){x==r&&l(t)}),150)}else{var u=t.clientY<w.top?-20:t.clientY>w.bottom?20:0;u&&setTimeout(un(e,function(){x==r&&(c.scroller.scrollTop+=u,l(t))}),50)}}function s(t){e.state.selectingText=!1,x=1/0,ze(t),c.input.focus(),Ae(document,"mousemove",k),Ae(document,"mouseup",C),d.history.lastSelOrigin=null}var c=e.display,d=e.doc;ze(t);var h,p,m=d.sel,g=m.ranges;if(i&&!t.shiftKey?(p=d.sel.contains(r),h=p>-1?g[p]:new el(r,r)):(h=d.sel.primary(),p=d.sel.primIndex),oa?t.shiftKey&&t.metaKey:t.altKey)n="rect",i||(h=new el(r,r)),r=kr(e,t,!0,!0),p=-1;else if("double"==n){var v=e.findWordAt(r);h=e.display.shift||d.extend?ri(d,h,v.anchor,v.head):v}else if("triple"==n){var y=new el(z(r.line,0),R(d,z(r.line+1,0)));h=e.display.shift||d.extend?ri(d,h,y.anchor,y.head):y}else h=ri(d,h,r);i?p==-1?(p=g.length,ci(d,On(g.concat([h]),p),{scroll:!1,origin:"*mouse"})):g.length>1&&g[p].empty()&&"single"==n&&!t.shiftKey?(ci(d,On(g.slice(0,p).concat(g.slice(p+1)),0),{scroll:!1,origin:"*mouse"}),m=d.sel):oi(d,p,h,ba):(p=0,ci(d,new Qa([h],0),ba),m=d.sel);var b=r,w=c.wrapper.getBoundingClientRect(),x=0,k=un(e,function(e){Fe(e)?l(e):s(e)}),C=un(e,s);e.state.selectingText=C,_a(document,"mousemove",k),_a(document,"mouseup",C)}function mo(e,t,r,n){var i,o;try{i=t.clientX,o=t.clientY}catch(e){return!1}if(i>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;n&&ze(t);var a=e.display,l=a.lineDiv.getBoundingClientRect();if(o>l.bottom||!We(e,r))return Pe(t);o-=l.top-a.viewOffset;for(var s=0;s<e.options.gutters.length;++s){var c=a.gutters.childNodes[s];if(c&&c.getBoundingClientRect().right>=i){return _e(e,r,e,N(e.doc,o),e.options.gutters[s],t),Pe(t)}}}function go(e,t){return mo(e,t,"gutterClick",!0)}function vo(e,t){Ht(e.display,t)||yo(e,t)||Oe(e,t,"contextmenu")||e.display.input.onContextMenu(t)}function yo(e,t){return!!We(e,"gutterContextMenu")&&mo(e,t,"gutterContextMenu",!1)}function bo(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),nr(e)}function wo(e){An(e),hn(e),Er(e)}function xo(e,t,r){if(!t!=!(r&&r!=xl)){var n=e.display.dragFunctions,i=t?_a:Ae;i(e.display.scroller,"dragstart",n.start),i(e.display.scroller,"dragenter",n.enter),i(e.display.scroller,"dragover",n.over),i(e.display.scroller,"dragleave",n.leave),i(e.display.scroller,"drop",n.drop)}}function ko(e){e.options.lineWrapping?(a(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(da(e.display.wrapper,"CodeMirror-wrap"),be(e)),xr(e),hn(e),nr(e),setTimeout(function(){return Kr(e)},100)}function Co(e,t){var r=this;if(!(this instanceof Co))return new Co(e,t);this.options=t=t?c(t):{},c(kl,t,!1),_n(t);var n=t.value;"string"==typeof n&&(n=new sl(n,t.mode,null,t.lineSeparator)),this.doc=n;var i=new Co.inputStyles[t.inputStyle](this),o=this.display=new T(e,n,i);o.wrapper.CodeMirror=this,An(this),bo(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),Vr(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,selectingText:!1,draggingText:!1,highlight:new ha,keySeq:null,specialChars:null},t.autofocus&&!na&&o.input.focus(),Go&&$o<11&&setTimeout(function(){return r.display.input.reset(!0)},20),So(this),Bi(),en(this),this.curOp.forceUpdate=!0,Bn(this,n),t.autofocus&&!na||this.hasFocus()?setTimeout(s(Nr,this),20):Wr(this);for(var a in Cl)Cl.hasOwnProperty(a)&&Cl[a](r,t[a],xl);zr(this),t.finishInit&&t.finishInit(this);for(var l=0;l<Sl.length;++l)Sl[l](r);tn(this),Yo&&t.lineWrapping&&"optimizelegibility"==getComputedStyle(o.lineDiv).textRendering&&(o.lineDiv.style.textRendering="auto")}function So(e){function t(){i.activeTouch&&(o=setTimeout(function(){return i.activeTouch=null},1e3),a=i.activeTouch,a.end=+new Date)}function r(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}function n(e,t){if(null==t.left)return!0;var r=t.left-e.left,n=t.top-e.top;return r*r+n*n>400}var i=e.display;_a(i.scroller,"mousedown",un(e,uo)),Go&&$o<11?_a(i.scroller,"dblclick",un(e,function(t){if(!Oe(e,t)){var r=kr(e,t);if(r&&!go(e,t)&&!Ht(e.display,t)){ze(t);var n=e.findWordAt(r);ni(e.doc,n.anchor,n.head)}}})):_a(i.scroller,"dblclick",function(t){return Oe(e,t)||ze(t)}),ua||_a(i.scroller,"contextmenu",function(t){return vo(e,t)});var o,a={end:0};_a(i.scroller,"touchstart",function(t){if(!Oe(e,t)&&!r(t)){i.input.ensurePolled(),clearTimeout(o);var n=+new Date;i.activeTouch={start:n,moved:!1,prev:n-a.end<=300?a:null},1==t.touches.length&&(i.activeTouch.left=t.touches[0].pageX,i.activeTouch.top=t.touches[0].pageY)}}),_a(i.scroller,"touchmove",function(){i.activeTouch&&(i.activeTouch.moved=!0)}),_a(i.scroller,"touchend",function(r){var o=i.activeTouch;if(o&&!Ht(i,r)&&null!=o.left&&!o.moved&&new Date-o.start<300){var a,l=e.coordsChar(i.activeTouch,"page");a=!o.prev||n(o,o.prev)?new el(l,l):!o.prev.prev||n(o,o.prev.prev)?e.findWordAt(l):new el(z(l.line,0),R(e.doc,z(l.line+1,0))),e.setSelection(a.anchor,a.head),e.focus(),ze(r)}t()}),_a(i.scroller,"touchcancel",t),_a(i.scroller,"scroll",function(){i.scroller.clientHeight&&(Ir(e,i.scroller.scrollTop),Fr(e,i.scroller.scrollLeft,!0),_e(e,"scroll",e))}),_a(i.scroller,"mousewheel",function(t){return Br(e,t)}),_a(i.scroller,"DOMMouseScroll",function(t){return Br(e,t)}),_a(i.wrapper,"scroll",function(){return i.wrapper.scrollTop=i.wrapper.scrollLeft=0}),i.dragFunctions={enter:function(t){Oe(e,t)||He(t)},over:function(t){Oe(e,t)||(Fi(e,t),He(t))},start:function(t){return Ii(e,t)},drop:un(e,Hi),leave:function(t){Oe(e,t)||ji(e)}};var l=i.input.getField();_a(l,"keyup",function(t){return so.call(e,t)}),_a(l,"keydown",un(e,ao)),_a(l,"keypress",un(e,co)),_a(l,"focus",function(t){return Nr(e,t)}),_a(l,"blur",function(t){return Wr(e,t)})}function To(e,t,r,n){var i,o=e.doc;null==r&&(r="add"),"smart"==r&&(o.mode.indent?i=Qe(e,t):r="prev");var a=e.options.tabSize,l=L(o,t),s=u(l.text,null,a);l.stateAfter&&(l.stateAfter=null);var c,d=l.text.match(/^\s*/)[0];if(n||/\S/.test(l.text)){if("smart"==r&&((c=o.mode.indent(i,l.text.slice(d.length),l.text))==va||c>150)){if(!n)return;r="prev"}}else c=0,r="not";"prev"==r?c=t>o.first?u(L(o,t-1).text,null,a):0:"add"==r?c=s+e.options.indentUnit:"subtract"==r?c=s-e.options.indentUnit:"number"==typeof r&&(c=s+r),c=Math.max(0,c);var f="",p=0;if(e.options.indentWithTabs)for(var m=Math.floor(c/a);m;--m)p+=a,f+="\t";if(p<c&&(f+=h(c-p)),f!=d)return Ti(o,f,z(t,0),z(t,d.length),"+input"),l.stateAfter=null,!0;for(var g=0;g<o.sel.ranges.length;g++){var v=o.sel.ranges[g];if(v.head.line==t&&v.head.ch<d.length){var y=z(t,d.length);oi(o,g,new el(y,y));break}}}function Lo(e){Tl=e}function Mo(e,t,r,n,i){var o=e.doc;e.display.shift=!1,n||(n=o.sel);var a=e.state.pasteIncoming||"paste"==i,l=Na(t),s=null;if(a&&n.ranges.length>1)if(Tl&&Tl.text.join("\n")==t){if(n.ranges.length%Tl.text.length==0){s=[];for(var c=0;c<Tl.text.length;c++)s.push(o.splitLines(Tl.text[c]))}}else l.length==n.ranges.length&&(s=m(l,function(e){return[e]}));for(var u,d=n.ranges.length-1;d>=0;d--){var f=n.ranges[d],h=f.from(),g=f.to();f.empty()&&(r&&r>0?h=z(h.line,h.ch-r):e.state.overwrite&&!a?g=z(g.line,Math.min(L(o,g.line).text.length,g.ch+p(l).length)):Tl&&Tl.lineWise&&Tl.text.join("\n")==t&&(h=g=z(h.line,0))),u=e.curOp.updateInput;var v={from:h,to:g,text:s?s[d%s.length]:l,origin:i||(a?"paste":e.state.cutIncoming?"cut":"+input")};bi(e.doc,v),kt(e,"inputRead",e,v)}t&&!a&&_o(e,t),Jr(e),e.curOp.updateInput=u,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function Ao(e,t){var r=e.clipboardData&&e.clipboardData.getData("Text");if(r)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||cn(t,function(){return Mo(t,r,0,null,"paste")}),!0}function _o(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var r=e.doc.sel,n=r.ranges.length-1;n>=0;n--){var i=r.ranges[n];if(!(i.head.ch>100||n&&r.ranges[n-1].head.line==i.head.line)){var o=e.getModeAt(i.head),a=!1;if(o.electricChars){for(var l=0;l<o.electricChars.length;l++)if(t.indexOf(o.electricChars.charAt(l))>-1){a=To(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(L(e.doc,i.head.line).text.slice(0,i.head.ch))&&(a=To(e,i.head.line,"smart"));a&&kt(e,"electricInput",e,i.head.line)}}}function Oo(e){for(var t=[],r=[],n=0;n<e.doc.sel.ranges.length;n++){var i=e.doc.sel.ranges[n].head.line,o={anchor:z(i,0),head:z(i+1,0)};r.push(o),t.push(e.getRange(o.anchor,o.head))}return{text:t,ranges:r}}function No(e,t){e.setAttribute("autocorrect","off"),e.setAttribute("autocapitalize","off"),e.setAttribute("spellcheck",!!t)}function Wo(){var e=n("textarea",null,null,"position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"),t=n("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return Yo?e.style.width="1000px":e.setAttribute("wrap","off"),ra&&(e.style.border="1px solid black"),No(e),t}function Eo(e,t,r,n,i){function o(){var n=t.line+r;return!(n<e.first||n>=e.first+e.size)&&(t=new z(n,t.ch,t.sticky),c=L(e,n))}function a(n){var a;if(null==(a=i?Le(e.cm,c,t,r):Se(c,t,r))){if(n||!o())return!1;t=Te(i,e.cm,c,t.line,r)}else t=a;return!0}var l=t,s=r,c=L(e,t.line);if("char"==n)a();else if("column"==n)a(!0);else if("word"==n||"group"==n)for(var u=null,d="group"==n,f=e.cm&&e.cm.getHelper(t,"wordChars"),h=!0;!(r<0)||a(!h);h=!1){var p=c.text.charAt(t.ch)||"\n",m=w(p,f)?"w":d&&"\n"==p?"n":!d||/\s/.test(p)?null:"p";if(!d||h||m||(m="s"),u&&u!=m){r<0&&(r=1,a(),t.sticky="after");break}if(m&&(u=m),r>0&&!a(!h))break}var g=mi(e,t,l,s,!0);return P(l,g)&&(g.hitSide=!0),g}function zo(e,t,r,n){var i,o=e.doc,a=t.left;if("page"==n){var l=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),s=Math.max(l-.5*gr(e.display),3);i=(r>0?t.bottom:t.top)+r*s}else"line"==n&&(i=r>0?t.bottom+3:t.top-3);for(var c;c=fr(e,a,i),c.outside;){if(r<0?i<=0:i>=o.height){c.hitSide=!0;break}i+=5*r}return c}function Do(e,t){var r=$t(e,t.line);if(!r||r.hidden)return null;var n=L(e.doc,t.line),i=Ut(r,n,t.line),o=ke(n),a="left";if(o){a=xe(o,t.ch)%2?"right":"left"}var l=Zt(i.map,t.ch,a);return l.offset="right"==l.collapse?l.end:l.start,l}function Po(e,t){return t&&(e.bad=!0),e}function Ho(e,t,r,n,i){function o(e){return function(t){return t.id==e}}function a(t){if(1==t.nodeType){var r=t.getAttribute("cm-text");if(null!=r)return void(l+=""==r?t.textContent.replace(/\u200b/g,""):r);var u,d=t.getAttribute("cm-marker");if(d){var f=e.findMarks(z(n,0),z(i+1,0),o(+d));return void(f.length&&(u=f[0].find())&&(l+=M(e.doc,u.from,u.to).join(c)))}if("false"==t.getAttribute("contenteditable"))return;for(var h=0;h<t.childNodes.length;h++)a(t.childNodes[h]);/^(pre|div|p)$/i.test(t.nodeName)&&(s=!0)}else if(3==t.nodeType){var p=t.nodeValue;if(!p)return;s&&(l+=c,s=!1),l+=p}}for(var l="",s=!1,c=e.doc.lineSeparator();a(t),t!=r;)t=t.nextSibling;return l}function Io(e,t,r){var n;if(t==e.display.lineDiv){if(!(n=e.display.lineDiv.childNodes[r]))return Po(e.clipPos(z(e.display.viewTo-1)),!0);t=null,r=0}else for(n=t;;n=n.parentNode){if(!n||n==e.display.lineDiv)return null;if(n.parentNode&&n.parentNode==e.display.lineDiv)break}for(var i=0;i<e.display.view.length;i++){var o=e.display.view[i];if(o.node==n)return Fo(o,t,r)}}function Fo(e,t,r){function n(t,r,n){for(var i=-1;i<(d?d.length:0);i++)for(var o=i<0?u.map:d[i],a=0;a<o.length;a+=3){var l=o[a+2];if(l==t||l==r){var s=O(i<0?e.line:e.rest[i]),c=o[a]+n;return(n<0||l!=t)&&(c=o[a+(n?1:0)]),z(s,c)}}}var o=e.text.firstChild,a=!1;if(!t||!i(o,t))return Po(z(O(e.line),0),!0);if(t==o&&(a=!0,t=o.childNodes[r],r=0,!t)){var l=e.rest?p(e.rest):e.line;return Po(z(O(l),l.text.length),a)}var s=3==t.nodeType?t:null,c=t;for(s||1!=t.childNodes.length||3!=t.firstChild.nodeType||(s=t.firstChild,r&&(r=s.nodeValue.length));c.parentNode!=o;)c=c.parentNode;var u=e.measure,d=u.maps,f=n(s,c,r);if(f)return Po(f,a);for(var h=c.nextSibling,m=s?s.nodeValue.length-r:0;h;h=h.nextSibling){if(f=n(h,h.firstChild,0))return Po(z(f.line,f.ch-m),a);m+=h.textContent.length}for(var g=c.previousSibling,v=r;g;g=g.previousSibling){if(f=n(g,g.firstChild,-1))return Po(z(f.line,f.ch+v),a);v+=g.textContent.length}}function jo(e,t){function r(){e.value=s.getValue()}if(t=t?c(t):{},t.value=e.value,!t.tabindex&&e.tabIndex&&(t.tabindex=e.tabIndex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder),null==t.autofocus){var n=o();t.autofocus=n==e||null!=e.getAttribute("autofocus")&&n==document.body}var i;if(e.form&&(_a(e.form,"submit",r),!t.leaveSubmitMethodAlone)){var a=e.form;i=a.submit;try{var l=a.submit=function(){r(),a.submit=i,a.submit(),a.submit=l}}catch(e){}}t.finishInit=function(t){t.save=r,t.getTextArea=function(){return e},t.toTextArea=function(){t.toTextArea=isNaN,r(),e.parentNode.removeChild(t.getWrapperElement()),e.style.display="",e.form&&(Ae(e.form,"submit",r),"function"==typeof e.form.submit&&(e.form.submit=i))}},e.style.display="none";var s=Co(function(t){return e.parentNode.insertBefore(t,e.nextSibling)},t);return s}var Ro=navigator.userAgent,Bo=navigator.platform,qo=/gecko\/\d/i.test(Ro),Ko=/MSIE \d/.test(Ro),Uo=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ro),Vo=/Edge\/(\d+)/.exec(Ro),Go=Ko||Uo||Vo,$o=Go&&(Ko?document.documentMode||6:+(Vo||Uo)[1]),Yo=!Vo&&/WebKit\//.test(Ro),Xo=Yo&&/Qt\/\d+\.\d+/.test(Ro),Zo=!Vo&&/Chrome\//.test(Ro),Jo=/Opera\//.test(Ro),Qo=/Apple Computer/.test(navigator.vendor),ea=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(Ro),ta=/PhantomJS/.test(Ro),ra=!Vo&&/AppleWebKit/.test(Ro)&&/Mobile\/\w+/.test(Ro),na=ra||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(Ro),ia=ra||/Mac/.test(Bo),oa=/\bCrOS\b/.test(Ro),aa=/win/i.test(Bo),la=Jo&&Ro.match(/Version\/(\d*\.\d*)/);la&&(la=Number(la[1])),la&&la>=15&&(Jo=!1,Yo=!0);var sa,ca=ia&&(Xo||Jo&&(null==la||la<12.11)),ua=qo||Go&&$o>=9,da=function(t,r){var n=t.className,i=e(r).exec(n);if(i){var o=n.slice(i.index+i[0].length);t.className=n.slice(0,i.index)+(o?i[1]+o:"")}};sa=document.createRange?function(e,t,r,n){var i=document.createRange();return i.setEnd(n||e,r),i.setStart(e,t),i}:function(e,t,r){var n=document.body.createTextRange();try{n.moveToElementText(e.parentNode)}catch(e){return n}return n.collapse(!0),n.moveEnd("character",r),n.moveStart("character",t),n};var fa=function(e){e.select()};ra?fa=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:Go&&(fa=function(e){try{e.select()}catch(e){}});var ha=function(){this.id=null};ha.prototype.set=function(e,t){clearTimeout(this.id),this.id=setTimeout(t,e)};var pa,ma,ga=30,va={toString:function(){return"CodeMirror.Pass"}},ya={scroll:!1},ba={origin:"*mouse"},wa={origin:"+move"},xa=[""],ka=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Ca=/[\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]/,Sa=!1,Ta=!1,La=null,Ma=function(){function e(e){return e<=247?r.charAt(e):1424<=e&&e<=1524?"R":1536<=e&&e<=1785?n.charAt(e-1536):1774<=e&&e<=2220?"r":8192<=e&&e<=8203?"w":8204==e?"b":"L"}function t(e,t,r){this.level=e,this.from=t,this.to=r}
5
- var r="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",n="nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111",i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,o=/[stwN]/,a=/[LRr]/,l=/[Lb1n]/,s=/[1n]/;return function(r){if(!i.test(r))return!1;for(var n=r.length,c=[],u=0;u<n;++u)c.push(e(r.charCodeAt(u)));for(var d=0,f="L";d<n;++d){var h=c[d];"m"==h?c[d]=f:f=h}for(var m=0,g="L";m<n;++m){var v=c[m];"1"==v&&"r"==g?c[m]="n":a.test(v)&&(g=v,"r"==v&&(c[m]="R"))}for(var y=1,b=c[0];y<n-1;++y){var w=c[y];"+"==w&&"1"==b&&"1"==c[y+1]?c[y]="1":","!=w||b!=c[y+1]||"1"!=b&&"n"!=b||(c[y]=b),b=w}for(var x=0;x<n;++x){var k=c[x];if(","==k)c[x]="N";else if("%"==k){var C=void 0;for(C=x+1;C<n&&"%"==c[C];++C);for(var S=x&&"!"==c[x-1]||C<n&&"1"==c[C]?"1":"N",T=x;T<C;++T)c[T]=S;x=C-1}}for(var L=0,M="L";L<n;++L){var A=c[L];"L"==M&&"1"==A?c[L]="L":a.test(A)&&(M=A)}for(var _=0;_<n;++_)if(o.test(c[_])){var O=void 0;for(O=_+1;O<n&&o.test(c[O]);++O);for(var N="L"==(_?c[_-1]:"L"),W="L"==(O<n?c[O]:"L"),E=N||W?"L":"R",z=_;z<O;++z)c[z]=E;_=O-1}for(var D,P=[],H=0;H<n;)if(l.test(c[H])){var I=H;for(++H;H<n&&l.test(c[H]);++H);P.push(new t(0,I,H))}else{var F=H,j=P.length;for(++H;H<n&&"L"!=c[H];++H);for(var R=F;R<H;)if(s.test(c[R])){F<R&&P.splice(j,0,new t(1,F,R));var B=R;for(++R;R<H&&s.test(c[R]);++R);P.splice(j,0,new t(2,B,R)),F=R}else++R;F<H&&P.splice(j,0,new t(1,F,H))}return 1==P[0].level&&(D=r.match(/^\s+/))&&(P[0].from=D[0].length,P.unshift(new t(0,0,D[0].length))),1==p(P).level&&(D=r.match(/\s+$/))&&(p(P).to-=D[0].length,P.push(new t(0,n-D[0].length,n))),P}}(),Aa=[],_a=function(e,t,r){if(e.addEventListener)e.addEventListener(t,r,!1);else if(e.attachEvent)e.attachEvent("on"+t,r);else{var n=e._handlers||(e._handlers={});n[t]=(n[t]||Aa).concat(r)}},Oa=function(){if(Go&&$o<9)return!1;var e=n("div");return"draggable"in e||"dragDrop"in e}(),Na=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,r=[],n=e.length;t<=n;){var i=e.indexOf("\n",t);i==-1&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),a=o.indexOf("\r");a!=-1?(r.push(o.slice(0,a)),t+=a+1):(r.push(o),t=i+1)}return r}:function(e){return e.split(/\r\n?|\n/)},Wa=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:function(e){var t;try{t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},Ea=function(){var e=n("div");return"oncopy"in e||(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)}(),za=null,Da={},Pa={},Ha={},Ia=function(e,t){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0};Ia.prototype.eol=function(){return this.pos>=this.string.length},Ia.prototype.sol=function(){return this.pos==this.lineStart},Ia.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},Ia.prototype.next=function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},Ia.prototype.eat=function(e){var t=this.string.charAt(this.pos);if("string"==typeof e?t==e:t&&(e.test?e.test(t):e(t)))return++this.pos,t},Ia.prototype.eatWhile=function(e){for(var t=this.pos;this.eat(e););return this.pos>t},Ia.prototype.eatSpace=function(){for(var e=this,t=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++e.pos;return this.pos>t},Ia.prototype.skipToEnd=function(){this.pos=this.string.length},Ia.prototype.skipTo=function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},Ia.prototype.backUp=function(e){this.pos-=e},Ia.prototype.column=function(){return this.lastColumnPos<this.start&&(this.lastColumnValue=u(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?u(this.string,this.lineStart,this.tabSize):0)},Ia.prototype.indentation=function(){return u(this.string,null,this.tabSize)-(this.lineStart?u(this.string,this.lineStart,this.tabSize):0)},Ia.prototype.match=function(e,t,r){if("string"!=typeof e){var n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}var i=function(e){return r?e.toLowerCase():e};if(i(this.string.substr(this.pos,e.length))==i(e))return t!==!1&&(this.pos+=e.length),!0},Ia.prototype.current=function(){return this.string.slice(this.start,this.pos)},Ia.prototype.hideFirstChars=function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}};var Fa=function(e,t,r){this.text=e,re(this,t),this.height=r?r(this):1};Fa.prototype.lineNo=function(){return O(this)},Ee(Fa);var ja,Ra={},Ba={},qa=null,Ka=null,Ua={left:0,right:0,top:0,bottom:0},Va=0,Ga=null;Go?Ga=-.53:qo?Ga=15:Zo?Ga=-.7:Qo&&(Ga=-1/3);var $a=function(e,t,r){this.cm=r;var i=this.vert=n("div",[n("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),o=this.horiz=n("div",[n("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(i),e(o),_a(i,"scroll",function(){i.clientHeight&&t(i.scrollTop,"vertical")}),_a(o,"scroll",function(){o.clientWidth&&t(o.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,Go&&$o<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};$a.prototype.update=function(e){var t=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,n=e.nativeBarWidth;if(r){this.vert.style.display="block",this.vert.style.bottom=t?n+"px":"0";var i=e.viewHeight-(t?n: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=r?n+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(r?n:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+o)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&e.clientHeight>0&&(0==n&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:r?n:0,bottom:t?n:0}},$a.prototype.setScrollLeft=function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz)},$a.prototype.setScrollTop=function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert)},$a.prototype.zeroWidthHack=function(){var e=ia&&!ea?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new ha,this.disableVert=new ha},$a.prototype.enableZeroWidthBar=function(e,t){function r(){var n=e.getBoundingClientRect();document.elementFromPoint(n.left+1,n.bottom-1)!=e?e.style.pointerEvents="none":t.set(1e3,r)}e.style.pointerEvents="auto",t.set(1e3,r)},$a.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)};var Ya=function(){};Ya.prototype.update=function(){return{bottom:0,right:0}},Ya.prototype.setScrollLeft=function(){},Ya.prototype.setScrollTop=function(){},Ya.prototype.clear=function(){};var Xa={native:$a,null:Ya},Za=0,Ja=function(e,t,r){var n=e.display;this.viewport=t,this.visible=Hr(n,e.doc,t),this.editorIsHidden=!n.wrapper.offsetWidth,this.wrapperHeight=n.wrapper.clientHeight,this.wrapperWidth=n.wrapper.clientWidth,this.oldDisplayWidth=Bt(e),this.force=r,this.dims=yr(e),this.events=[]};Ja.prototype.signal=function(e,t){We(e,t)&&this.events.push(arguments)},Ja.prototype.finish=function(){for(var e=this,t=0;t<this.events.length;t++)_e.apply(null,e.events[t])};var Qa=function(e,t){this.ranges=e,this.primIndex=t};Qa.prototype.primary=function(){return this.ranges[this.primIndex]},Qa.prototype.equals=function(e){var t=this;if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var r=0;r<this.ranges.length;r++){var n=t.ranges[r],i=e.ranges[r];if(!P(n.anchor,i.anchor)||!P(n.head,i.head))return!1}return!0},Qa.prototype.deepCopy=function(){for(var e=this,t=[],r=0;r<this.ranges.length;r++)t[r]=new el(H(e.ranges[r].anchor),H(e.ranges[r].head));return new Qa(t,this.primIndex)},Qa.prototype.somethingSelected=function(){for(var e=this,t=0;t<this.ranges.length;t++)if(!e.ranges[t].empty())return!0;return!1},Qa.prototype.contains=function(e,t){var r=this;t||(t=e);for(var n=0;n<this.ranges.length;n++){var i=r.ranges[n];if(D(t,i.from())>=0&&D(e,i.to())<=0)return n}return-1};var el=function(e,t){this.anchor=e,this.head=t};el.prototype.from=function(){return F(this.anchor,this.head)},el.prototype.to=function(){return I(this.anchor,this.head)},el.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch};var tl=function(e){var t=this;this.lines=e,this.parent=null;for(var r=0,n=0;n<e.length;++n)e[n].parent=t,r+=e[n].height;this.height=r};tl.prototype.chunkSize=function(){return this.lines.length},tl.prototype.removeInner=function(e,t){for(var r=this,n=e,i=e+t;n<i;++n){var o=r.lines[n];r.height-=o.height,st(o),kt(o,"delete")}this.lines.splice(e,t)},tl.prototype.collapse=function(e){e.push.apply(e,this.lines)},tl.prototype.insertInner=function(e,t,r){var n=this;this.height+=r,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var i=0;i<t.length;++i)t[i].parent=n},tl.prototype.iterN=function(e,t,r){for(var n=this,i=e+t;e<i;++e)if(r(n.lines[e]))return!0};var rl=function(e){var t=this;this.children=e;for(var r=0,n=0,i=0;i<e.length;++i){var o=e[i];r+=o.chunkSize(),n+=o.height,o.parent=t}this.size=r,this.height=n,this.parent=null};rl.prototype.chunkSize=function(){return this.size},rl.prototype.removeInner=function(e,t){var r=this;this.size-=t;for(var n=0;n<this.children.length;++n){var i=r.children[n],o=i.chunkSize();if(e<o){var a=Math.min(t,o-e),l=i.height;if(i.removeInner(e,a),r.height-=l-i.height,o==a&&(r.children.splice(n--,1),i.parent=null),0==(t-=a))break;e=0}else e-=o}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof tl))){var s=[];this.collapse(s),this.children=[new tl(s)],this.children[0].parent=this}},rl.prototype.collapse=function(e){for(var t=this,r=0;r<this.children.length;++r)t.children[r].collapse(e)},rl.prototype.insertInner=function(e,t,r){var n=this;this.size+=t.length,this.height+=r;for(var i=0;i<this.children.length;++i){var o=n.children[i],a=o.chunkSize();if(e<=a){if(o.insertInner(e,t,r),o.lines&&o.lines.length>50){for(var l=o.lines.length%25+25,s=l;s<o.lines.length;){var c=new tl(o.lines.slice(s,s+=25));o.height-=c.height,n.children.splice(++i,0,c),c.parent=n}o.lines=o.lines.slice(0,l),n.maybeSpill()}break}e-=a}},rl.prototype.maybeSpill=function(){if(!(this.children.length<=10)){var e=this;do{var t=e.children.splice(e.children.length-5,5),r=new rl(t);if(e.parent){e.size-=r.size,e.height-=r.height;var n=d(e.parent.children,e);e.parent.children.splice(n+1,0,r)}else{var i=new rl(e.children);i.parent=e,e.children=[i,r],e=i}r.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},rl.prototype.iterN=function(e,t,r){for(var n=this,i=0;i<this.children.length;++i){var o=n.children[i],a=o.chunkSize();if(e<a){var l=Math.min(t,a-e);if(o.iterN(e,l,r))return!0;if(0==(t-=l))break;e=0}else e-=a}};var nl=function(e,t,r){var n=this;if(r)for(var i in r)r.hasOwnProperty(i)&&(n[i]=r[i]);this.doc=e,this.node=t};nl.prototype.clear=function(){var e=this,t=this.doc.cm,r=this.line.widgets,n=this.line,i=O(n);if(null!=i&&r){for(var o=0;o<r.length;++o)r[o]==e&&r.splice(o--,1);r.length||(n.widgets=null);var a=Pt(this);_(n,Math.max(0,n.height-a)),t&&(cn(t,function(){Oi(t,n,-a),pn(t,i,"widget")}),kt(t,"lineWidgetCleared",t,this,i))}},nl.prototype.changed=function(){var e=this,t=this.height,r=this.doc.cm,n=this.line;this.height=null;var i=Pt(this)-t;i&&(_(n,n.height+i),r&&cn(r,function(){r.curOp.forceUpdate=!0,Oi(r,n,i),kt(r,"lineWidgetChanged",r,e,O(n))}))},Ee(nl);var il=0,ol=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++il};ol.prototype.clear=function(){var e=this;if(!this.explicitlyCleared){var t=this.doc.cm,r=t&&!t.curOp;if(r&&en(t),We(this,"clear")){var n=this.find();n&&kt(this,"clear",n.from,n.to)}for(var i=null,o=null,a=0;a<this.lines.length;++a){var l=e.lines[a],s=G(l.markedSpans,e);t&&!e.collapsed?pn(t,O(l),"text"):t&&(null!=s.to&&(o=O(l)),null!=s.from&&(i=O(l))),l.markedSpans=$(l.markedSpans,s),null==s.from&&e.collapsed&&!me(e.doc,l)&&t&&_(l,gr(t.display))}if(t&&this.collapsed&&!t.options.lineWrapping)for(var c=0;c<this.lines.length;++c){var u=ue(e.lines[c]),d=ye(u);d>t.display.maxLineLength&&(t.display.maxLine=u,t.display.maxLineLength=d,t.display.maxLineChanged=!0)}null!=i&&t&&this.collapsed&&hn(t,i,o+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,t&&fi(t.doc)),t&&kt(t,"markerCleared",t,this,i,o),r&&tn(t),this.parent&&this.parent.clear()}},ol.prototype.find=function(e,t){var r=this;null==e&&"bookmark"==this.type&&(e=1);for(var n,i,o=0;o<this.lines.length;++o){var a=r.lines[o],l=G(a.markedSpans,r);if(null!=l.from&&(n=z(t?a:O(a),l.from),e==-1))return n;if(null!=l.to&&(i=z(t?a:O(a),l.to),1==e))return i}return n&&{from:n,to:i}},ol.prototype.changed=function(){var e=this,t=this.find(-1,!0),r=this,n=this.doc.cm;t&&n&&cn(n,function(){var i=t.line,o=O(t.line),a=$t(n,o);if(a&&(tr(a),n.curOp.selectionChanged=n.curOp.forceUpdate=!0),n.curOp.updateMaxLine=!0,!me(r.doc,i)&&null!=r.height){var l=r.height;r.height=null;var s=Pt(r)-l;s&&_(i,i.height+s)}kt(n,"markerChanged",n,e)})},ol.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;t.maybeHiddenMarkers&&d(t.maybeHiddenMarkers,this)!=-1||(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},ol.prototype.detachLine=function(e){if(this.lines.splice(d(this.lines,e),1),!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}},Ee(ol);var al=function(e,t){var r=this;this.markers=e,this.primary=t;for(var n=0;n<e.length;++n)e[n].parent=r};al.prototype.clear=function(){var e=this;if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var t=0;t<this.markers.length;++t)e.markers[t].clear();kt(this,"clear")}},al.prototype.find=function(e,t){return this.primary.find(e,t)},Ee(al);var ll=0,sl=function(e,t,r,n){if(!(this instanceof sl))return new sl(e,t,r,n);null==r&&(r=0),rl.call(this,[new tl([new Fa("",null)])]),this.first=r,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.frontier=r;var i=z(r,0);this.sel=Nn(i),this.history=new qn(null),this.id=++ll,this.modeOption=t,this.lineSep=n,this.extend=!1,"string"==typeof e&&(e=this.splitLines(e)),jn(this,{from:i,to:i,text:e}),ci(this,Nn(i),ya)};sl.prototype=y(rl.prototype,{constructor:sl,iter:function(e,t,r){r?this.iterN(e-this.first,t-e,r):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var r=0,n=0;n<t.length;++n)r+=t[n].height;this.insertInner(e-this.first,t,r)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=A(this,this.first,this.first+this.size);return e===!1?t:t.join(e||this.lineSeparator())},setValue:fn(function(e){var t=z(this.first,0),r=this.first+this.size-1;bi(this,{from:t,to:z(r,L(this,r).text.length),text:this.splitLines(e),origin:"setValue",full:!0},!0),ci(this,Nn(t))}),replaceRange:function(e,t,r,n){t=R(this,t),r=r?R(this,r):t,Ti(this,e,t,r,n)},getRange:function(e,t,r){var n=M(this,R(this,e),R(this,t));return r===!1?n:n.join(r||this.lineSeparator())},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){if(W(this,e))return L(this,e)},getLineNumber:function(e){return O(e)},getLineHandleVisualStart:function(e){return"number"==typeof e&&(e=L(this,e)),ue(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return R(this,e)},getCursor:function(e){var t=this.sel.primary();return null==e||"head"==e?t.head:"anchor"==e?t.anchor:"end"==e||"to"==e||e===!1?t.to():t.from()},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:fn(function(e,t,r){ai(this,R(this,"number"==typeof e?z(e,t||0):e),null,r)}),setSelection:fn(function(e,t,r){ai(this,R(this,e),R(this,t||e),r)}),extendSelection:fn(function(e,t,r){ni(this,R(this,e),t&&R(this,t),r)}),extendSelections:fn(function(e,t){ii(this,q(this,e),t)}),extendSelectionsBy:fn(function(e,t){ii(this,q(this,m(this.sel.ranges,e)),t)}),setSelections:fn(function(e,t,r){var n=this;if(e.length){for(var i=[],o=0;o<e.length;o++)i[o]=new el(R(n,e[o].anchor),R(n,e[o].head));null==t&&(t=Math.min(e.length-1,this.sel.primIndex)),ci(this,On(i,t),r)}}),addSelection:fn(function(e,t,r){var n=this.sel.ranges.slice(0);n.push(new el(R(this,e),R(this,t||e))),ci(this,On(n,n.length-1),r)}),getSelection:function(e){for(var t,r=this,n=this.sel.ranges,i=0;i<n.length;i++){var o=M(r,n[i].from(),n[i].to());t=t?t.concat(o):o}return e===!1?t:t.join(e||this.lineSeparator())},getSelections:function(e){for(var t=this,r=[],n=this.sel.ranges,i=0;i<n.length;i++){var o=M(t,n[i].from(),n[i].to());e!==!1&&(o=o.join(e||t.lineSeparator())),r[i]=o}return r},replaceSelection:function(e,t,r){for(var n=[],i=0;i<this.sel.ranges.length;i++)n[i]=e;this.replaceSelections(n,t,r||"+input")},replaceSelections:fn(function(e,t,r){for(var n=this,i=[],o=this.sel,a=0;a<o.ranges.length;a++){var l=o.ranges[a];i[a]={from:l.from(),to:l.to(),text:n.splitLines(e[a]),origin:r}}for(var s=t&&"end"!=t&&Pn(this,i,t),c=i.length-1;c>=0;c--)bi(n,i[c]);s?si(this,s):this.cm&&Jr(this.cm)}),undo:fn(function(){xi(this,"undo")}),redo:fn(function(){xi(this,"redo")}),undoSelection:fn(function(){xi(this,"undo",!0)}),redoSelection:fn(function(){xi(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,r=0,n=0;n<e.done.length;n++)e.done[n].ranges||++t;for(var i=0;i<e.undone.length;i++)e.undone[i].ranges||++r;return{undo:t,redo:r}},clearHistory:function(){this.history=new qn(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){return e&&(this.history.lastOp=this.history.lastSelOp=this.history.lastOrigin=null),this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:ti(this.history.done),undone:ti(this.history.undone)}},setHistory:function(e){var t=this.history=new qn(this.history.maxGeneration);t.done=ti(e.done.slice(0),null,!0),t.undone=ti(e.undone.slice(0),null,!0)},setGutterMarker:fn(function(e,t,r){return _i(this,e,"gutter",function(e){var n=e.gutterMarkers||(e.gutterMarkers={});return n[t]=r,!r&&x(n)&&(e.gutterMarkers=null),!0})}),clearGutter:fn(function(e){var t=this;this.iter(function(r){r.gutterMarkers&&r.gutterMarkers[e]&&_i(t,r,"gutter",function(){return r.gutterMarkers[e]=null,x(r.gutterMarkers)&&(r.gutterMarkers=null),!0})})}),lineInfo:function(e){var t;if("number"==typeof e){if(!W(this,e))return null;if(t=e,!(e=L(this,e)))return null}else if(null==(t=O(e)))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}},addLineClass:fn(function(t,r,n){return _i(this,t,"gutter"==r?"gutter":"class",function(t){var i="text"==r?"textClass":"background"==r?"bgClass":"gutter"==r?"gutterClass":"wrapClass";if(t[i]){if(e(n).test(t[i]))return!1;t[i]+=" "+n}else t[i]=n;return!0})}),removeLineClass:fn(function(t,r,n){return _i(this,t,"gutter"==r?"gutter":"class",function(t){var i="text"==r?"textClass":"background"==r?"bgClass":"gutter"==r?"gutterClass":"wrapClass",o=t[i];if(!o)return!1;if(null==n)t[i]=null;else{var a=o.match(e(n));if(!a)return!1;var l=a.index+a[0].length;t[i]=o.slice(0,a.index)+(a.index&&l!=o.length?" ":"")+o.slice(l)||null}return!0})}),addLineWidget:fn(function(e,t,r){return Ni(this,e,t,r)}),removeLineWidget:function(e){e.clear()},markText:function(e,t,r){return Wi(this,R(this,e),R(this,t),r,r&&r.type||"range")},setBookmark:function(e,t){var r={replacedWith:t&&(null==t.nodeType?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared,handleMouseEvents:t&&t.handleMouseEvents};return e=R(this,e),Wi(this,e,e,r,"bookmark")},findMarksAt:function(e){e=R(this,e);var t=[],r=L(this,e.line).markedSpans;if(r)for(var n=0;n<r.length;++n){var i=r[n];(null==i.from||i.from<=e.ch)&&(null==i.to||i.to>=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,r){e=R(this,e),t=R(this,t);var n=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var a=o.markedSpans;if(a)for(var l=0;l<a.length;l++){var s=a[l];null!=s.to&&i==e.line&&e.ch>=s.to||null==s.from&&i!=e.line||null!=s.from&&i==t.line&&s.from>=t.ch||r&&!r(s.marker)||n.push(s.marker.parent||s.marker)}++i}),n},getAllMarks:function(){var e=[];return this.iter(function(t){var r=t.markedSpans;if(r)for(var n=0;n<r.length;++n)null!=r[n].from&&e.push(r[n].marker)}),e},posFromIndex:function(e){var t,r=this.first,n=this.lineSeparator().length;return this.iter(function(i){var o=i.text.length+n;if(o>e)return t=e,!0;e-=o,++r}),R(this,z(r,t))},indexFromPos:function(e){e=R(this,e);var t=e.ch;if(e.line<this.first||e.ch<0)return 0;var r=this.lineSeparator().length;return this.iter(this.first,e.line,function(e){t+=e.text.length+r}),t},copy:function(e){var t=new sl(A(this,this.first,this.first+this.size),this.modeOption,this.first,this.lineSep);return t.scrollTop=this.scrollTop,t.scrollLeft=this.scrollLeft,t.sel=this.sel,t.extend=!1,e&&(t.history.undoDepth=this.history.undoDepth,t.setHistory(this.getHistory())),t},linkedDoc:function(e){e||(e={});var t=this.first,r=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.to<r&&(r=e.to);var n=new sl(A(this,t,r),e.mode||this.modeOption,t,this.lineSep);return e.sharedHist&&(n.history=this.history),(this.linked||(this.linked=[])).push({doc:n,sharedHist:e.sharedHist}),n.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}],Di(n,zi(this)),n},unlinkDoc:function(e){var t=this;if(e instanceof Co&&(e=e.doc),this.linked)for(var r=0;r<this.linked.length;++r){var n=t.linked[r];if(n.doc==e){t.linked.splice(r,1),e.unlinkDoc(t),Pi(zi(t));break}}if(e.history==this.history){var i=[e.id];Rn(e,function(e){return i.push(e.id)},!0),e.history=new qn(null),e.history.done=ti(this.history.done,i),e.history.undone=ti(this.history.undone,i)}},iterLinkedDocs:function(e){Rn(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm},splitLines:function(e){return this.lineSep?e.split(this.lineSep):Na(e)},lineSeparator:function(){return this.lineSep||"\n"}}),sl.prototype.eachLine=sl.prototype.iter;for(var cl=0,ul=!1,dl={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",106:"*",107:"=",109:"-",110:".",111:"/",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"},fl=0;fl<10;fl++)dl[fl+48]=dl[fl+96]=String(fl);for(var hl=65;hl<=90;hl++)dl[hl]=String.fromCharCode(hl);for(var pl=1;pl<=12;pl++)dl[pl+111]=dl[pl+63235]="F"+pl;var ml={};ml.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"},ml.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"},ml.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","Ctrl-O":"openLine"},ml.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"]},ml.default=ia?ml.macDefault:ml.pcDefault;var gl,vl,yl={selectAll:vi,singleSelection:function(e){return e.setSelection(e.getCursor("anchor"),e.getCursor("head"),ya)},killLine:function(e){return Zi(e,function(t){if(t.empty()){var r=L(e.doc,t.head.line).text.length;return t.head.ch==r&&t.head.line<e.lastLine()?{from:t.head,to:z(t.head.line+1,0)}:{from:t.head,to:z(t.head.line,r)}}return{from:t.from(),to:t.to()}})},deleteLine:function(e){return Zi(e,function(t){return{from:z(t.from().line,0),to:R(e.doc,z(t.to().line+1,0))}})},delLineLeft:function(e){return Zi(e,function(e){return{from:z(e.from().line,0),to:e.from()}})},delWrappedLineLeft:function(e){return Zi(e,function(t){var r=e.charCoords(t.head,"div").top+5;return{from:e.coordsChar({left:0,top:r},"div"),to:t.from()}})},delWrappedLineRight:function(e){return Zi(e,function(t){var r=e.charCoords(t.head,"div").top+5,n=e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:r},"div");return{from:t.from(),to:n}})},undo:function(e){return e.undo()},redo:function(e){return e.redo()},undoSelection:function(e){return e.undoSelection()},redoSelection:function(e){return e.redoSelection()},goDocStart:function(e){return e.extendSelection(z(e.firstLine(),0))},goDocEnd:function(e){return e.extendSelection(z(e.lastLine()))},goLineStart:function(e){return e.extendSelectionsBy(function(t){return Ji(e,t.head.line)},{origin:"+move",bias:1})},goLineStartSmart:function(e){return e.extendSelectionsBy(function(t){return eo(e,t.head)},{origin:"+move",bias:1})},goLineEnd:function(e){return e.extendSelectionsBy(function(t){return Qi(e,t.head.line)},{origin:"+move",bias:-1})},goLineRight:function(e){return e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:r},"div")},wa)},goLineLeft:function(e){return e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:r},"div")},wa)},goLineLeftSmart:function(e){return e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5,n=e.coordsChar({left:0,top:r},"div");return n.ch<e.getLine(n.line).search(/\S/)?eo(e,t.head):n},wa)},goLineUp:function(e){return e.moveV(-1,"line")},goLineDown:function(e){return e.moveV(1,"line")},goPageUp:function(e){return e.moveV(-1,"page")},goPageDown:function(e){return e.moveV(1,"page")},goCharLeft:function(e){return e.moveH(-1,"char")},goCharRight:function(e){return e.moveH(1,"char")},goColumnLeft:function(e){return e.moveH(-1,"column")},goColumnRight:function(e){return e.moveH(1,"column")},goWordLeft:function(e){return e.moveH(-1,"word")},goGroupRight:function(e){return e.moveH(1,"group")},goGroupLeft:function(e){return e.moveH(-1,"group")},goWordRight:function(e){return e.moveH(1,"word")},delCharBefore:function(e){return e.deleteH(-1,"char")},delCharAfter:function(e){return e.deleteH(1,"char")},delWordBefore:function(e){return e.deleteH(-1,"word")},delWordAfter:function(e){return e.deleteH(1,"word")},delGroupBefore:function(e){return e.deleteH(-1,"group")},delGroupAfter:function(e){return e.deleteH(1,"group")},indentAuto:function(e){return e.indentSelection("smart")},indentMore:function(e){return e.indentSelection("add")},indentLess:function(e){return e.indentSelection("subtract")},insertTab:function(e){return e.replaceSelection("\t")},insertSoftTab:function(e){for(var t=[],r=e.listSelections(),n=e.options.tabSize,i=0;i<r.length;i++){var o=r[i].from(),a=u(e.getLine(o.line),o.ch,n);t.push(h(n-a%n))}e.replaceSelections(t)},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:function(e){return cn(e,function(){for(var t=e.listSelections(),r=[],n=0;n<t.length;n++)if(t[n].empty()){var i=t[n].head,o=L(e.doc,i.line).text;if(o)if(i.ch==o.length&&(i=new z(i.line,i.ch-1)),i.ch>0)i=new z(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),z(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var a=L(e.doc,i.line-1).text;a&&(i=new z(i.line,1),e.replaceRange(o.charAt(0)+e.doc.lineSeparator()+a.charAt(a.length-1),z(i.line-1,a.length-1),i,"+transpose"))}r.push(new el(i,i))}e.setSelections(r)})},newlineAndIndent:function(e){return cn(e,function(){for(var t=e.listSelections(),r=t.length-1;r>=0;r--)e.replaceRange(e.doc.lineSeparator(),t[r].anchor,t[r].head,"+input");t=e.listSelections();for(var n=0;n<t.length;n++)e.indentLine(t[n].from().line,null,!0);Jr(e)})},openLine:function(e){return e.replaceSelection("\n","start")},toggleOverwrite:function(e){return e.toggleOverwrite()}},bl=new ha,wl=null,xl={toString:function(){return"CodeMirror.Init"}},kl={},Cl={};Co.defaults=kl,Co.optionHandlers=Cl;var Sl=[];Co.defineInitHook=function(e){return Sl.push(e)};var Tl=null,Ll=function(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new ha,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};Ll.prototype.init=function(e){function t(e){if(!Oe(i,e)){if(i.somethingSelected())Lo({lineWise:!1,text:i.getSelections()}),"cut"==e.type&&i.replaceSelection("",null,"cut");else{if(!i.options.lineWiseCopyCut)return;var t=Oo(i);Lo({lineWise:!0,text:t.text}),"cut"==e.type&&i.operation(function(){i.setSelections(t.ranges,0,ya),i.replaceSelection("",null,"cut")})}if(e.clipboardData){e.clipboardData.clearData();var r=Tl.text.join("\n");if(e.clipboardData.setData("Text",r),e.clipboardData.getData("Text")==r)return void e.preventDefault()}var a=Wo(),l=a.firstChild;i.display.lineSpace.insertBefore(a,i.display.lineSpace.firstChild),l.value=Tl.text.join("\n");var s=document.activeElement;fa(l),setTimeout(function(){i.display.lineSpace.removeChild(a),s.focus(),s==o&&n.showPrimarySelection()},50)}}var r=this,n=this,i=n.cm,o=n.div=e.lineDiv;No(o,i.options.spellcheck),_a(o,"paste",function(e){Oe(i,e)||Ao(e,i)||$o<=11&&setTimeout(un(i,function(){n.pollContent()||hn(i)}),20)}),
6
- _a(o,"compositionstart",function(e){r.composing={data:e.data,done:!1}}),_a(o,"compositionupdate",function(e){r.composing||(r.composing={data:e.data,done:!1})}),_a(o,"compositionend",function(e){r.composing&&(e.data!=r.composing.data&&r.readFromDOMSoon(),r.composing.done=!0)}),_a(o,"touchstart",function(){return n.forceCompositionEnd()}),_a(o,"input",function(){r.composing||r.readFromDOMSoon()}),_a(o,"copy",t),_a(o,"cut",t)},Ll.prototype.prepareSelection=function(){var e=Tr(this.cm,!1);return e.focus=this.cm.state.focused,e},Ll.prototype.showSelection=function(e,t){e&&this.cm.display.view.length&&((e.focus||t)&&this.showPrimarySelection(),this.showMultipleSelections(e))},Ll.prototype.showPrimarySelection=function(){var e=window.getSelection(),t=this.cm.doc.sel.primary(),r=Io(this.cm,e.anchorNode,e.anchorOffset),n=Io(this.cm,e.focusNode,e.focusOffset);if(!r||r.bad||!n||n.bad||0!=D(F(r,n),t.from())||0!=D(I(r,n),t.to())){var i=Do(this.cm,t.from()),o=Do(this.cm,t.to());if(i||o){var a=this.cm.display.view,l=e.rangeCount&&e.getRangeAt(0);if(i){if(!o){var s=a[a.length-1].measure,c=s.maps?s.maps[s.maps.length-1]:s.map;o={node:c[c.length-1],offset:c[c.length-2]-c[c.length-3]}}}else i={node:a[0].measure.map[2],offset:0};var u;try{u=sa(i.node,i.offset,o.offset,o.node)}catch(e){}u&&(!qo&&this.cm.state.focused?(e.collapse(i.node,i.offset),u.collapsed||(e.removeAllRanges(),e.addRange(u))):(e.removeAllRanges(),e.addRange(u)),l&&null==e.anchorNode?e.addRange(l):qo&&this.startGracePeriod()),this.rememberSelection()}}},Ll.prototype.startGracePeriod=function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout(function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation(function(){return e.cm.curOp.selectionChanged=!0})},20)},Ll.prototype.showMultipleSelections=function(e){r(this.cm.display.cursorDiv,e.cursors),r(this.cm.display.selectionDiv,e.selection)},Ll.prototype.rememberSelection=function(){var e=window.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},Ll.prototype.selectionInEditor=function(){var e=window.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return i(this.div,t)},Ll.prototype.focus=function(){"nocursor"!=this.cm.options.readOnly&&(this.selectionInEditor()||this.showSelection(this.prepareSelection(),!0),this.div.focus())},Ll.prototype.blur=function(){this.div.blur()},Ll.prototype.getField=function(){return this.div},Ll.prototype.supportsTouch=function(){return!0},Ll.prototype.receivedFocus=function(){function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))}var t=this;this.selectionInEditor()?this.pollSelection():cn(this.cm,function(){return t.cm.curOp.selectionChanged=!0}),this.polling.set(this.cm.options.pollInterval,e)},Ll.prototype.selectionChanged=function(){var e=window.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},Ll.prototype.pollSelection=function(){if(!this.composing&&null==this.readDOMTimeout&&!this.gracePeriod&&this.selectionChanged()){var e=window.getSelection(),t=this.cm;this.rememberSelection();var r=Io(t,e.anchorNode,e.anchorOffset),n=Io(t,e.focusNode,e.focusOffset);r&&n&&cn(t,function(){ci(t.doc,Nn(r,n),ya),(r.bad||n.bad)&&(t.curOp.selectionChanged=!0)})}},Ll.prototype.pollContent=function(){null!=this.readDOMTimeout&&(clearTimeout(this.readDOMTimeout),this.readDOMTimeout=null);var e=this.cm,t=e.display,r=e.doc.sel.primary(),n=r.from(),i=r.to();if(0==n.ch&&n.line>e.firstLine()&&(n=z(n.line-1,L(e.doc,n.line-1).length)),i.ch==L(e.doc,i.line).text.length&&i.line<e.lastLine()&&(i=z(i.line+1,0)),n.line<t.viewFrom||i.line>t.viewTo-1)return!1;var o,a,l;n.line==t.viewFrom||0==(o=Cr(e,n.line))?(a=O(t.view[0].line),l=t.view[0].node):(a=O(t.view[o].line),l=t.view[o-1].node.nextSibling);var s,c,u=Cr(e,i.line);if(u==t.view.length-1?(s=t.viewTo-1,c=t.lineDiv.lastChild):(s=O(t.view[u+1].line)-1,c=t.view[u+1].node.previousSibling),!l)return!1;for(var d=e.doc.splitLines(Ho(e,l,c,a,s)),f=M(e.doc,z(a,0),z(s,L(e.doc,s).text.length));d.length>1&&f.length>1;)if(p(d)==p(f))d.pop(),f.pop(),s--;else{if(d[0]!=f[0])break;d.shift(),f.shift(),a++}for(var h=0,m=0,g=d[0],v=f[0],y=Math.min(g.length,v.length);h<y&&g.charCodeAt(h)==v.charCodeAt(h);)++h;for(var b=p(d),w=p(f),x=Math.min(b.length-(1==d.length?h:0),w.length-(1==f.length?h:0));m<x&&b.charCodeAt(b.length-m-1)==w.charCodeAt(w.length-m-1);)++m;d[d.length-1]=b.slice(0,b.length-m).replace(/^\u200b+/,""),d[0]=d[0].slice(h).replace(/\u200b+$/,"");var k=z(a,h),C=z(s,f.length?p(f).length-m:0);return d.length>1||d[0]||D(k,C)?(Ti(e.doc,d,k,C,"+input"),!0):void 0},Ll.prototype.ensurePolled=function(){this.forceCompositionEnd()},Ll.prototype.reset=function(){this.forceCompositionEnd()},Ll.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.pollContent()||hn(this.cm),this.div.blur(),this.div.focus())},Ll.prototype.readFromDOMSoon=function(){var e=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout(function(){if(e.readDOMTimeout=null,e.composing){if(!e.composing.done)return;e.composing=null}!e.cm.isReadOnly()&&e.pollContent()||cn(e.cm,function(){return hn(e.cm)})},80))},Ll.prototype.setUneditable=function(e){e.contentEditable="false"},Ll.prototype.onKeyPress=function(e){0!=e.charCode&&(e.preventDefault(),this.cm.isReadOnly()||un(this.cm,Mo)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))},Ll.prototype.readOnlyChanged=function(e){this.div.contentEditable=String("nocursor"!=e)},Ll.prototype.onContextMenu=function(){},Ll.prototype.resetPosition=function(){},Ll.prototype.needsContentAttribute=!0;var Ml=function(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new ha,this.inaccurateSelection=!1,this.hasSelection=!1,this.composing=null};Ml.prototype.init=function(e){function t(e){if(!Oe(i,e)){if(i.somethingSelected())Lo({lineWise:!1,text:i.getSelections()}),n.inaccurateSelection&&(n.prevInput="",n.inaccurateSelection=!1,a.value=Tl.text.join("\n"),fa(a));else{if(!i.options.lineWiseCopyCut)return;var t=Oo(i);Lo({lineWise:!0,text:t.text}),"cut"==e.type?i.setSelections(t.ranges,null,ya):(n.prevInput="",a.value=t.text.join("\n"),fa(a))}"cut"==e.type&&(i.state.cutIncoming=!0)}}var r=this,n=this,i=this.cm,o=this.wrapper=Wo(),a=this.textarea=o.firstChild;e.wrapper.insertBefore(o,e.wrapper.firstChild),ra&&(a.style.width="0px"),_a(a,"input",function(){Go&&$o>=9&&r.hasSelection&&(r.hasSelection=null),n.poll()}),_a(a,"paste",function(e){Oe(i,e)||Ao(e,i)||(i.state.pasteIncoming=!0,n.fastPoll())}),_a(a,"cut",t),_a(a,"copy",t),_a(e.scroller,"paste",function(t){Ht(e,t)||Oe(i,t)||(i.state.pasteIncoming=!0,n.focus())}),_a(e.lineSpace,"selectstart",function(t){Ht(e,t)||ze(t)}),_a(a,"compositionstart",function(){var e=i.getCursor("from");n.composing&&n.composing.range.clear(),n.composing={start:e,range:i.markText(e,i.getCursor("to"),{className:"CodeMirror-composing"})}}),_a(a,"compositionend",function(){n.composing&&(n.poll(),n.composing.range.clear(),n.composing=null)})},Ml.prototype.prepareSelection=function(){var e=this.cm,t=e.display,r=e.doc,n=Tr(e);if(e.options.moveInputWithCursor){var i=cr(e,r.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),a=t.lineDiv.getBoundingClientRect();n.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+a.top-o.top)),n.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+a.left-o.left))}return n},Ml.prototype.showSelection=function(e){var t=this.cm,n=t.display;r(n.cursorDiv,e.cursors),r(n.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},Ml.prototype.reset=function(e){if(!this.contextMenuPending){var t,r,n=this.cm,i=n.doc;if(n.somethingSelected()){this.prevInput="";var o=i.sel.primary();t=Ea&&(o.to().line-o.from().line>100||(r=n.getSelection()).length>1e3);var a=t?"-":r||n.getSelection();this.textarea.value=a,n.state.focused&&fa(this.textarea),Go&&$o>=9&&(this.hasSelection=a)}else e||(this.prevInput=this.textarea.value="",Go&&$o>=9&&(this.hasSelection=null));this.inaccurateSelection=t}},Ml.prototype.getField=function(){return this.textarea},Ml.prototype.supportsTouch=function(){return!1},Ml.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!na||o()!=this.textarea))try{this.textarea.focus()}catch(e){}},Ml.prototype.blur=function(){this.textarea.blur()},Ml.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},Ml.prototype.receivedFocus=function(){this.slowPoll()},Ml.prototype.slowPoll=function(){var e=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},Ml.prototype.fastPoll=function(){function e(){r.poll()||t?(r.pollingFast=!1,r.slowPoll()):(t=!0,r.polling.set(60,e))}var t=!1,r=this;r.pollingFast=!0,r.polling.set(20,e)},Ml.prototype.poll=function(){var e=this,t=this.cm,r=this.textarea,n=this.prevInput;if(this.contextMenuPending||!t.state.focused||Wa(r)&&!n&&!this.composing||t.isReadOnly()||t.options.disableInput||t.state.keySeq)return!1;var i=r.value;if(i==n&&!t.somethingSelected())return!1;if(Go&&$o>=9&&this.hasSelection===i||ia&&/[\uf700-\uf7ff]/.test(i))return t.display.input.reset(),!1;if(t.doc.sel==t.display.selForContextMenu){var o=i.charCodeAt(0);if(8203!=o||n||(n="​"),8666==o)return this.reset(),this.cm.execCommand("undo")}for(var a=0,l=Math.min(n.length,i.length);a<l&&n.charCodeAt(a)==i.charCodeAt(a);)++a;return cn(t,function(){Mo(t,i.slice(a),n.length-a,null,e.composing?"*compose":null),i.length>1e3||i.indexOf("\n")>-1?r.value=e.prevInput="":e.prevInput=i,e.composing&&(e.composing.range.clear(),e.composing.range=t.markText(e.composing.start,t.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},Ml.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},Ml.prototype.onKeyPress=function(){Go&&$o>=9&&(this.hasSelection=null),this.fastPoll()},Ml.prototype.onContextMenu=function(e){function t(){if(null!=a.selectionStart){var e=i.somethingSelected(),t="​"+(e?a.value:"");a.value="⇚",a.value=t,n.prevInput=e?"":"​",a.selectionStart=1,a.selectionEnd=t.length,o.selForContextMenu=i.doc.sel}}function r(){if(n.contextMenuPending=!1,n.wrapper.style.cssText=u,a.style.cssText=c,Go&&$o<9&&o.scrollbars.setScrollTop(o.scroller.scrollTop=s),null!=a.selectionStart){(!Go||Go&&$o<9)&&t();var e=0,r=function(){o.selForContextMenu==i.doc.sel&&0==a.selectionStart&&a.selectionEnd>0&&"​"==n.prevInput?un(i,vi)(i):e++<10?o.detectingSelectAll=setTimeout(r,500):(o.selForContextMenu=null,o.input.reset())};o.detectingSelectAll=setTimeout(r,200)}}var n=this,i=n.cm,o=i.display,a=n.textarea,l=kr(i,e),s=o.scroller.scrollTop;if(l&&!Jo){i.options.resetSelectionOnContextMenu&&i.doc.sel.contains(l)==-1&&un(i,ci)(i.doc,Nn(l),ya);var c=a.style.cssText,u=n.wrapper.style.cssText;n.wrapper.style.cssText="position: absolute";var d=n.wrapper.getBoundingClientRect();a.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(e.clientY-d.top-5)+"px; left: "+(e.clientX-d.left-5)+"px;\n z-index: 1000; background: "+(Go?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";var f;if(Yo&&(f=window.scrollY),o.input.focus(),Yo&&window.scrollTo(null,f),o.input.reset(),i.somethingSelected()||(a.value=n.prevInput=" "),n.contextMenuPending=!0,o.selForContextMenu=i.doc.sel,clearTimeout(o.detectingSelectAll),Go&&$o>=9&&t(),ua){He(e);var h=function(){Ae(window,"mouseup",h),setTimeout(r,20)};_a(window,"mouseup",h)}else setTimeout(r,50)}},Ml.prototype.readOnlyChanged=function(e){e||this.reset()},Ml.prototype.setUneditable=function(){},Ml.prototype.needsContentAttribute=!1,function(e){function t(t,n,i,o){e.defaults[t]=n,i&&(r[t]=o?function(e,t,r){r!=xl&&i(e,t,r)}:i)}var r=e.optionHandlers;e.defineOption=t,e.Init=xl,t("value","",function(e,t){return e.setValue(t)},!0),t("mode",null,function(e,t){e.doc.modeOption=t,Hn(e)},!0),t("indentUnit",2,Hn,!0),t("indentWithTabs",!1),t("smartIndent",!0),t("tabSize",4,function(e){In(e),nr(e),hn(e)},!0),t("lineSeparator",null,function(e,t){if(e.doc.lineSep=t,t){var r=[],n=e.doc.first;e.doc.iter(function(e){for(var i=0;;){var o=e.text.indexOf(t,i);if(o==-1)break;i=o+t.length,r.push(z(n,o))}n++});for(var i=r.length-1;i>=0;i--)Ti(e.doc,t,r[i],z(r[i].line,r[i].ch+t.length))}}),t("specialChars",/[\u0000-\u001f\u007f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g,function(e,t,r){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),r!=xl&&e.refresh()}),t("specialCharPlaceholder",dt,function(e){return e.refresh()},!0),t("electricChars",!0),t("inputStyle",na?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),t("spellcheck",!1,function(e,t){return e.getInputField().spellcheck=t},!0),t("rtlMoveVisually",!aa),t("wholeLineUpdateBefore",!0),t("theme","default",function(e){bo(e),wo(e)},!0),t("keyMap","default",function(e,t,r){var n=Xi(t),i=r!=xl&&Xi(r);i&&i.detach&&i.detach(e,n),n.attach&&n.attach(e,i||null)}),t("extraKeys",null),t("lineWrapping",!1,ko,!0),t("gutters",[],function(e){_n(e.options),wo(e)},!0),t("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?br(e.display)+"px":"0",e.refresh()},!0),t("coverGutterNextToScrollbar",!1,function(e){return Kr(e)},!0),t("scrollbarStyle","native",function(e){Vr(e),Kr(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),t("lineNumbers",!1,function(e){_n(e.options),wo(e)},!0),t("firstLineNumber",1,wo,!0),t("lineNumberFormatter",function(e){return e},wo,!0),t("showCursorWhenSelecting",!1,Sr,!0),t("resetSelectionOnContextMenu",!0),t("lineWiseCopyCut",!0),t("readOnly",!1,function(e,t){"nocursor"==t?(Wr(e),e.display.input.blur(),e.display.disabled=!0):e.display.disabled=!1,e.display.input.readOnlyChanged(t)}),t("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),t("dragDrop",!0,xo),t("allowDropFileTypes",null),t("cursorBlinkRate",530),t("cursorScrollMargin",0),t("cursorHeight",1,Sr,!0),t("singleCursorHeightPerLine",!0,Sr,!0),t("workTime",100),t("workDelay",100),t("flattenSpans",!0,In,!0),t("addModeClass",!1,In,!0),t("pollInterval",100),t("undoDepth",200,function(e,t){return e.doc.history.undoDepth=t}),t("historyEventDelay",1250),t("viewportMargin",10,function(e){return e.refresh()},!0),t("maxHighlightLength",1e4,In,!0),t("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),t("tabindex",null,function(e,t){return e.display.input.getField().tabIndex=t||""}),t("autofocus",null)}(Co),function(e){var t=e.optionHandlers,r=e.helpers={};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,r){var n=this.options,i=n[e];n[e]==r&&"mode"!=e||(n[e]=r,t.hasOwnProperty(e)&&un(this,t[e])(this,r,i),_e(this,"optionChange",this,e))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](Xi(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,r=0;r<t.length;++r)if(t[r]==e||t[r].name==e)return t.splice(r,1),!0},addOverlay:dn(function(t,r){var n=t.token?t:e.getMode(this.options,t);if(n.startState)throw new Error("Overlays may not be stateful.");g(this.state.overlays,{mode:n,modeSpec:t,opaque:r&&r.opaque,priority:r&&r.priority||0},function(e){return e.priority}),this.state.modeGen++,hn(this)}),removeOverlay:dn(function(e){for(var t=this,r=this.state.overlays,n=0;n<r.length;++n){var i=r[n].modeSpec;if(i==e||"string"==typeof e&&i.name==e)return r.splice(n,1),t.state.modeGen++,void hn(t)}}),indentLine:dn(function(e,t,r){"string"!=typeof t&&"number"!=typeof t&&(t=null==t?this.options.smartIndent?"smart":"prev":t?"add":"subtract"),W(this.doc,e)&&To(this,e,t,r)}),indentSelection:dn(function(e){for(var t=this,r=this.doc.sel.ranges,n=-1,i=0;i<r.length;i++){var o=r[i];if(o.empty())o.head.line>n&&(To(t,o.head.line,e,!0),n=o.head.line,i==t.doc.sel.primIndex&&Jr(t));else{var a=o.from(),l=o.to(),s=Math.max(n,a.line);n=Math.min(t.lastLine(),l.line-(l.ch?0:1))+1;for(var c=s;c<n;++c)To(t,c,e);var u=t.doc.sel.ranges;0==a.ch&&r.length==u.length&&u[i].from().ch>0&&oi(t.doc,i,new el(a,u[i].to()),ya)}}}),getTokenAt:function(e,t){return nt(this,e,t)},getLineTokens:function(e,t){return nt(this,z(e),t,!0)},getTokenTypeAt:function(e){e=R(this.doc,e);var t,r=Je(this,L(this.doc,e.line)),n=0,i=(r.length-1)/2,o=e.ch;if(0==o)t=r[2];else for(;;){var a=n+i>>1;if((a?r[2*a-1]:0)>=o)i=a;else{if(!(r[2*a+1]<o)){t=r[2*a+2];break}n=a+1}}var l=t?t.indexOf("overlay "):-1;return l<0?t:0==l?null:t.slice(0,l-1)},getModeAt:function(t){var r=this.doc.mode;return r.innerMode?e.innerMode(r,this.getTokenAt(t).state).mode:r},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var n=this,i=[];if(!r.hasOwnProperty(t))return i;var o=r[t],a=this.getModeAt(e);if("string"==typeof a[t])o[a[t]]&&i.push(o[a[t]]);else if(a[t])for(var l=0;l<a[t].length;l++){var s=o[a[t][l]];s&&i.push(s)}else a.helperType&&o[a.helperType]?i.push(o[a.helperType]):o[a.name]&&i.push(o[a.name]);for(var c=0;c<o._global.length;c++){var u=o._global[c];u.pred(a,n)&&d(i,u.val)==-1&&i.push(u.val)}return i},getStateAfter:function(e,t){var r=this.doc;return e=j(r,null==e?r.first+r.size-1:e),Qe(this,e+1,t)},cursorCoords:function(e,t){var r,n=this.doc.sel.primary();return r=null==e?n.head:"object"==typeof e?R(this.doc,e):e?n.from():n.to(),cr(this,r,t||"page")},charCoords:function(e,t){return sr(this,R(this.doc,e),t||"page")},coordsChar:function(e,t){return e=lr(this,e,t||"page"),fr(this,e.left,e.top)},lineAtHeight:function(e,t){return e=lr(this,{top:e,left:0},t||"page").top,N(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,t,r){var n,i=!1;if("number"==typeof e){var o=this.doc.first+this.doc.size-1;e<this.doc.first?e=this.doc.first:e>o&&(e=o,i=!0),n=L(this.doc,e)}else n=e;return ar(this,n,{top:0,left:0},t||"page",r||i).top+(i?this.doc.height-ve(n):0)},defaultTextHeight:function(){return gr(this.display)},defaultCharWidth:function(){return vr(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,r,n,i){var o=this.display;e=cr(this,R(this.doc,e));var a=e.bottom,l=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),o.sizer.appendChild(t),"over"==n)a=e.top;else if("above"==n||"near"==n){var s=Math.max(o.wrapper.clientHeight,this.doc.height),c=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==n||e.bottom+t.offsetHeight>s)&&e.top>t.offsetHeight?a=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=s&&(a=e.bottom),l+t.offsetWidth>c&&(l=c-t.offsetWidth)}t.style.top=a+"px",t.style.left=t.style.right="","right"==i?(l=o.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?l=0:"middle"==i&&(l=(o.sizer.clientWidth-t.offsetWidth)/2),t.style.left=l+"px"),r&&Yr(this,l,a,l+t.offsetWidth,a+t.offsetHeight)},triggerOnKeyDown:dn(ao),triggerOnKeyPress:dn(co),triggerOnKeyUp:so,execCommand:function(e){if(yl.hasOwnProperty(e))return yl[e].call(null,this)},triggerElectric:dn(function(e){_o(this,e)}),findPosH:function(e,t,r,n){var i=this,o=1;t<0&&(o=-1,t=-t);for(var a=R(this.doc,e),l=0;l<t&&(a=Eo(i.doc,a,o,r,n),!a.hitSide);++l);return a},moveH:dn(function(e,t){var r=this;this.extendSelectionsBy(function(n){return r.display.shift||r.doc.extend||n.empty()?Eo(r.doc,n.head,e,t,r.options.rtlMoveVisually):e<0?n.from():n.to()},wa)}),deleteH:dn(function(e,t){var r=this.doc.sel,n=this.doc;r.somethingSelected()?n.replaceSelection("",null,"+delete"):Zi(this,function(r){var i=Eo(n,r.head,e,t,!1);return e<0?{from:i,to:r.head}:{from:r.head,to:i}})}),findPosV:function(e,t,r,n){var i=this,o=1,a=n;t<0&&(o=-1,t=-t);for(var l=R(this.doc,e),s=0;s<t;++s){var c=cr(i,l,"div");if(null==a?a=c.left:c.left=a,l=zo(i,c,o,r),l.hitSide)break}return l},moveV:dn(function(e,t){var r=this,n=this.doc,i=[],o=!this.display.shift&&!n.extend&&n.sel.somethingSelected();if(n.extendSelectionsBy(function(a){if(o)return e<0?a.from():a.to();var l=cr(r,a.head,"div");null!=a.goalColumn&&(l.left=a.goalColumn),i.push(l.left);var s=zo(r,l,e,t);return"page"==t&&a==n.sel.primary()&&Zr(r,null,sr(r,s,"div").top-l.top),s},wa),i.length)for(var a=0;a<n.sel.ranges.length;a++)n.sel.ranges[a].goalColumn=i[a]}),findWordAt:function(e){var t=this.doc,r=L(t,e.line).text,n=e.ch,i=e.ch;if(r){var o=this.getHelper(e,"wordChars");"before"!=e.sticky&&i!=r.length||!n?++i:--n;for(var a=r.charAt(n),l=w(a,o)?function(e){return w(e,o)}:/\s/.test(a)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!w(e)};n>0&&l(r.charAt(n-1));)--n;for(;i<r.length&&l(r.charAt(i));)++i}return new el(z(e.line,n),z(e.line,i))},toggleOverwrite:function(e){null!=e&&e==this.state.overwrite||((this.state.overwrite=!this.state.overwrite)?a(this.display.cursorDiv,"CodeMirror-overwrite"):da(this.display.cursorDiv,"CodeMirror-overwrite"),_e(this,"overwriteToggle",this,this.state.overwrite))},hasFocus:function(){return this.display.input.getField()==o()},isReadOnly:function(){return!(!this.options.readOnly&&!this.doc.cantEdit)},scrollTo:dn(function(e,t){null==e&&null==t||Qr(this),null!=e&&(this.curOp.scrollLeft=e),null!=t&&(this.curOp.scrollTop=t)}),getScrollInfo:function(){var e=this.display.scroller;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-Rt(this)-this.display.barHeight,width:e.scrollWidth-Rt(this)-this.display.barWidth,clientHeight:qt(this),clientWidth:Bt(this)}},scrollIntoView:dn(function(e,t){if(null==e?(e={from:this.doc.sel.primary().head,to:null},null==t&&(t=this.options.cursorScrollMargin)):"number"==typeof e?e={from:z(e,0),to:null}:null==e.from&&(e={from:e,to:null}),e.to||(e.to=e.from),e.margin=t||0,null!=e.from.line)Qr(this),this.curOp.scrollToPos=e;else{var r=Xr(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(r.scrollLeft,r.scrollTop)}}),setSize:dn(function(e,t){var r=this,n=function(e){return"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e};null!=e&&(this.display.wrapper.style.width=n(e)),null!=t&&(this.display.wrapper.style.height=n(t)),this.options.lineWrapping&&rr(this);var i=this.display.viewFrom;this.doc.iter(i,this.display.viewTo,function(e){if(e.widgets)for(var t=0;t<e.widgets.length;t++)if(e.widgets[t].noHScroll){pn(r,i,"widget");break}++i}),this.curOp.forceUpdate=!0,_e(this,"refresh",this)}),operation:function(e){return cn(this,e)},refresh:dn(function(){var e=this.display.cachedTextHeight;hn(this),this.curOp.forceUpdate=!0,nr(this),this.scrollTo(this.doc.scrollLeft,this.doc.scrollTop),Ln(this),(null==e||Math.abs(e-gr(this.display))>.5)&&xr(this),_e(this,"refresh",this)}),swapDoc:dn(function(e){var t=this.doc;return t.cm=null,Bn(this,e),nr(this),this.display.input.reset(),this.scrollTo(e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,kt(this,"swapDoc",this,t),t}),getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},Ee(e),e.registerHelper=function(t,n,i){r.hasOwnProperty(t)||(r[t]=e[t]={_global:[]}),r[t][n]=i},e.registerGlobalHelper=function(t,n,i,o){e.registerHelper(t,n,o),r[t]._global.push({pred:i,val:o})}}(Co);var Al="iter insert remove copy getEditor constructor".split(" ");for(var _l in sl.prototype)sl.prototype.hasOwnProperty(_l)&&d(Al,_l)<0&&(Co.prototype[_l]=function(e){return function(){return e.apply(this.doc,arguments)}}(sl.prototype[_l]));return Ee(sl),Co.inputStyles={textarea:Ml,contenteditable:Ll},Co.defineMode=function(e){Co.defaults.mode||"null"==e||(Co.defaults.mode=e),qe.apply(this,arguments)},Co.defineMIME=Ke,Co.defineMode("null",function(){return{token:function(e){return e.skipToEnd()}}}),Co.defineMIME("text/plain","null"),Co.defineExtension=function(e,t){Co.prototype[e]=t},Co.defineDocExtension=function(e,t){sl.prototype[e]=t},Co.fromTextArea=jo,function(e){e.off=Ae,e.on=_a,e.wheelEventPixels=Rr,e.Doc=sl,e.splitLines=Na,e.countColumn=u,e.findColumn=f,e.isWordChar=b,e.Pass=va,e.signal=_e,e.Line=Fa,e.changeEnd=Wn,e.scrollbarModel=Xa,e.Pos=z,e.cmpPos=D,e.modes=Da,e.mimeModes=Pa,e.resolveMode=Ue,e.getMode=Ve,e.modeExtensions=Ha,e.extendMode=Ge,e.copyState=$e,e.startState=Xe,e.innerMode=Ye,e.commands=yl,e.keyMap=ml,e.keyName=Yi,e.isModifierKey=$i,e.lookupKey=Gi,e.normalizeKeyMap=Vi,e.StringStream=Ia,e.SharedTextMarker=al,e.TextMarker=ol,e.LineWidget=nl,e.e_preventDefault=ze,e.e_stopPropagation=De,e.e_stop=He,e.addClass=a,e.contains=i,e.rmClass=da,e.keyNames=dl}(Co),Co.version="5.24.2",Co})},{}],16:[function(e,r,n){!function(i){"object"==typeof n&&"object"==typeof r?i(e("../../lib/codemirror")):"function"==typeof t&&t.amd?t(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){"use strict";function t(e){for(var t={},r=0;r<e.length;++r)t[e[r].toLowerCase()]=!0;return t}function r(e,t){for(var r,n=!1;null!=(r=e.next());){if(n&&"/"==r){t.tokenize=null;break}n="*"==r}return["comment","comment"]}e.defineMode("css",function(t,r){function n(e,t){return p=t,e}function i(e,t){var r=e.next();if(v[r]){var i=v[r](e,t);if(i!==!1)return i}return"@"==r?(e.eatWhile(/[\w\\\-]/),n("def",e.current())):"="==r||("~"==r||"|"==r)&&e.eat("=")?n(null,"compare"):'"'==r||"'"==r?(t.tokenize=o(r),t.tokenize(e,t)):"#"==r?(e.eatWhile(/[\w\\\-]/),n("atom","hash")):"!"==r?(e.match(/^\s*\w*/),n("keyword","important")):/\d/.test(r)||"."==r&&e.eat(/\d/)?(e.eatWhile(/[\w.%]/),n("number","unit")):"-"!==r?/[,+>*\/]/.test(r)?n(null,"select-op"):"."==r&&e.match(/^-?[_a-z][_a-z0-9-]*/i)?n("qualifier","qualifier"):/[:;{}\[\]\(\)]/.test(r)?n(null,r):"u"==r&&e.match(/rl(-prefix)?\(/)||"d"==r&&e.match("omain(")||"r"==r&&e.match("egexp(")?(e.backUp(1),t.tokenize=a,n("property","word")):/[\w\\\-]/.test(r)?(e.eatWhile(/[\w\\\-]/),n("property","word")):n(null,null):/[\d.]/.test(e.peek())?(e.eatWhile(/[\w.%]/),n("number","unit")):e.match(/^-[\w\\\-]+/)?(e.eatWhile(/[\w\\\-]/),e.match(/^\s*:/,!1)?n("variable-2","variable-definition"):n("variable-2","variable")):e.match(/^\w+-/)?n("meta","meta"):void 0}function o(e){return function(t,r){for(var i,o=!1;null!=(i=t.next());){if(i==e&&!o){")"==e&&t.backUp(1);break}o=!o&&"\\"==i}return(i==e||!o&&")"!=e)&&(r.tokenize=null),n("string","string")}}function a(e,t){return e.next(),e.match(/\s*[\"\')]/,!1)?t.tokenize=null:t.tokenize=o(")"),n(null,"(")}function l(e,t,r){this.type=e,this.indent=t,this.prev=r}function s(e,t,r,n){return e.context=new l(r,t.indentation()+(n===!1?0:g),e.context),r}function c(e){return e.context.prev&&(e.context=e.context.prev),e.context.type}function u(e,t,r){return N[r.context.type](e,t,r)}function d(e,t,r,n){for(var i=n||1;i>0;i--)r.context=r.context.prev;return u(e,t,r)}function f(e){var t=e.current().toLowerCase();m=M.hasOwnProperty(t)?"atom":L.hasOwnProperty(t)?"keyword":"variable"}var h=r.inline;r.propertyKeywords||(r=e.resolveMode("text/css"));var p,m,g=t.indentUnit,v=r.tokenHooks,y=r.documentTypes||{},b=r.mediaTypes||{},w=r.mediaFeatures||{},x=r.mediaValueKeywords||{},k=r.propertyKeywords||{},C=r.nonStandardPropertyKeywords||{},S=r.fontProperties||{},T=r.counterDescriptors||{},L=r.colorKeywords||{},M=r.valueKeywords||{},A=r.allowNested,_=r.lineComment,O=r.supportsAtComponent===!0,N={};return N.top=function(e,t,r){if("{"==e)return s(r,t,"block");if("}"==e&&r.context.prev)return c(r);if(O&&/@component/.test(e))return s(r,t,"atComponentBlock");if(/^@(-moz-)?document$/.test(e))return s(r,t,"documentTypes");if(/^@(media|supports|(-moz-)?document|import)$/.test(e))return s(r,t,"atBlock");if(/^@(font-face|counter-style)/.test(e))return r.stateArg=e,"restricted_atBlock_before";if(/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(e))return"keyframes";if(e&&"@"==e.charAt(0))return s(r,t,"at");if("hash"==e)m="builtin";else if("word"==e)m="tag";else{if("variable-definition"==e)return"maybeprop";if("interpolation"==e)return s(r,t,"interpolation");if(":"==e)return"pseudo";if(A&&"("==e)return s(r,t,"parens")}return r.context.type},N.block=function(e,t,r){if("word"==e){var n=t.current().toLowerCase();return k.hasOwnProperty(n)?(m="property","maybeprop"):C.hasOwnProperty(n)?(m="string-2","maybeprop"):A?(m=t.match(/^\s*:(?:\s|$)/,!1)?"property":"tag","block"):(m+=" error","maybeprop")}return"meta"==e?"block":A||"hash"!=e&&"qualifier"!=e?N.top(e,t,r):(m="error","block")},N.maybeprop=function(e,t,r){return":"==e?s(r,t,"prop"):u(e,t,r)},N.prop=function(e,t,r){if(";"==e)return c(r);if("{"==e&&A)return s(r,t,"propBlock");if("}"==e||"{"==e)return d(e,t,r);if("("==e)return s(r,t,"parens");if("hash"!=e||/^#([0-9a-fA-f]{3,4}|[0-9a-fA-f]{6}|[0-9a-fA-f]{8})$/.test(t.current())){if("word"==e)f(t);else if("interpolation"==e)return s(r,t,"interpolation")}else m+=" error";return"prop"},N.propBlock=function(e,t,r){return"}"==e?c(r):"word"==e?(m="property","maybeprop"):r.context.type},N.parens=function(e,t,r){return"{"==e||"}"==e?d(e,t,r):")"==e?c(r):"("==e?s(r,t,"parens"):"interpolation"==e?s(r,t,"interpolation"):("word"==e&&f(t),"parens")},N.pseudo=function(e,t,r){return"meta"==e?"pseudo":"word"==e?(m="variable-3",r.context.type):u(e,t,r)},N.documentTypes=function(e,t,r){return"word"==e&&y.hasOwnProperty(t.current())?(m="tag",r.context.type):N.atBlock(e,t,r)},N.atBlock=function(e,t,r){if("("==e)return s(r,t,"atBlock_parens");if("}"==e||";"==e)return d(e,t,r);if("{"==e)return c(r)&&s(r,t,A?"block":"top");if("interpolation"==e)return s(r,t,"interpolation");if("word"==e){var n=t.current().toLowerCase();m="only"==n||"not"==n||"and"==n||"or"==n?"keyword":b.hasOwnProperty(n)?"attribute":w.hasOwnProperty(n)?"property":x.hasOwnProperty(n)?"keyword":k.hasOwnProperty(n)?"property":C.hasOwnProperty(n)?"string-2":M.hasOwnProperty(n)?"atom":L.hasOwnProperty(n)?"keyword":"error"}return r.context.type},N.atComponentBlock=function(e,t,r){return"}"==e?d(e,t,r):"{"==e?c(r)&&s(r,t,A?"block":"top",!1):("word"==e&&(m="error"),r.context.type)},N.atBlock_parens=function(e,t,r){return")"==e?c(r):"{"==e||"}"==e?d(e,t,r,2):N.atBlock(e,t,r)},N.restricted_atBlock_before=function(e,t,r){return"{"==e?s(r,t,"restricted_atBlock"):"word"==e&&"@counter-style"==r.stateArg?(m="variable","restricted_atBlock_before"):u(e,t,r)},N.restricted_atBlock=function(e,t,r){return"}"==e?(r.stateArg=null,c(r)):"word"==e?(m="@font-face"==r.stateArg&&!S.hasOwnProperty(t.current().toLowerCase())||"@counter-style"==r.stateArg&&!T.hasOwnProperty(t.current().toLowerCase())?"error":"property","maybeprop"):"restricted_atBlock"},N.keyframes=function(e,t,r){return"word"==e?(m="variable","keyframes"):"{"==e?s(r,t,"top"):u(e,t,r)},N.at=function(e,t,r){return";"==e?c(r):"{"==e||"}"==e?d(e,t,r):("word"==e?m="tag":"hash"==e&&(m="builtin"),"at")},N.interpolation=function(e,t,r){return"}"==e?c(r):"{"==e||";"==e?d(e,t,r):("word"==e?m="variable":"variable"!=e&&"("!=e&&")"!=e&&(m="error"),"interpolation")},{startState:function(e){return{tokenize:null,state:h?"block":"top",stateArg:null,context:new l(h?"block":"top",e||0,null)}},token:function(e,t){if(!t.tokenize&&e.eatSpace())return null;var r=(t.tokenize||i)(e,t);return r&&"object"==typeof r&&(p=r[1],r=r[0]),m=r,t.state=N[t.state](p,e,t),m},indent:function(e,t){var r=e.context,n=t&&t.charAt(0),i=r.indent;return"prop"!=r.type||"}"!=n&&")"!=n||(r=r.prev),r.prev&&("}"!=n||"block"!=r.type&&"top"!=r.type&&"interpolation"!=r.type&&"restricted_atBlock"!=r.type?(")"!=n||"parens"!=r.type&&"atBlock_parens"!=r.type)&&("{"!=n||"at"!=r.type&&"atBlock"!=r.type)||(i=Math.max(0,r.indent-g),r=r.prev):(r=r.prev,i=r.indent)),i},electricChars:"}",
7
- blockCommentStart:"/*",blockCommentEnd:"*/",lineComment:_,fold:"brace"}});var n=["domain","regexp","url","url-prefix"],i=t(n),o=["all","aural","braille","handheld","print","projection","screen","tty","tv","embossed"],a=t(o),l=["width","min-width","max-width","height","min-height","max-height","device-width","min-device-width","max-device-width","device-height","min-device-height","max-device-height","aspect-ratio","min-aspect-ratio","max-aspect-ratio","device-aspect-ratio","min-device-aspect-ratio","max-device-aspect-ratio","color","min-color","max-color","color-index","min-color-index","max-color-index","monochrome","min-monochrome","max-monochrome","resolution","min-resolution","max-resolution","scan","grid","orientation","device-pixel-ratio","min-device-pixel-ratio","max-device-pixel-ratio","pointer","any-pointer","hover","any-hover"],s=t(l),c=["landscape","portrait","none","coarse","fine","on-demand","hover","interlace","progressive"],u=t(c),d=["align-content","align-items","align-self","alignment-adjust","alignment-baseline","anchor-point","animation","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-timing-function","appearance","azimuth","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-repeat","background-size","baseline-shift","binding","bleed","bookmark-label","bookmark-level","bookmark-state","bookmark-target","border","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-decoration-break","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","clear","clip","color","color-profile","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","content","counter-increment","counter-reset","crop","cue","cue-after","cue-before","cursor","direction","display","dominant-baseline","drop-initial-after-adjust","drop-initial-after-align","drop-initial-before-adjust","drop-initial-before-align","drop-initial-size","drop-initial-value","elevation","empty-cells","fit","fit-position","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","float-offset","flow-from","flow-into","font","font-feature-settings","font-family","font-kerning","font-language-override","font-size","font-size-adjust","font-stretch","font-style","font-synthesis","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-ligatures","font-variant-numeric","font-variant-position","font-weight","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-gap","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-gap","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphens","icon","image-orientation","image-rendering","image-resolution","inline-box-align","justify-content","left","letter-spacing","line-break","line-height","line-stacking","line-stacking-ruby","line-stacking-shift","line-stacking-strategy","list-style","list-style-image","list-style-position","list-style-type","margin","margin-bottom","margin-left","margin-right","margin-top","marks","marquee-direction","marquee-loop","marquee-play-count","marquee-speed","marquee-style","max-height","max-width","min-height","min-width","move-to","nav-down","nav-index","nav-left","nav-right","nav-up","object-fit","object-position","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-style","overflow-wrap","overflow-x","overflow-y","padding","padding-bottom","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","page-policy","pause","pause-after","pause-before","perspective","perspective-origin","pitch","pitch-range","play-during","position","presentation-level","punctuation-trim","quotes","region-break-after","region-break-before","region-break-inside","region-fragment","rendering-intent","resize","rest","rest-after","rest-before","richness","right","rotation","rotation-point","ruby-align","ruby-overhang","ruby-position","ruby-span","shape-image-threshold","shape-inside","shape-margin","shape-outside","size","speak","speak-as","speak-header","speak-numeral","speak-punctuation","speech-rate","stress","string-set","tab-size","table-layout","target","target-name","target-new","target-position","text-align","text-align-last","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-style","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-height","text-indent","text-justify","text-outline","text-overflow","text-shadow","text-size-adjust","text-space-collapse","text-transform","text-underline-position","text-wrap","top","transform","transform-origin","transform-style","transition","transition-delay","transition-duration","transition-property","transition-timing-function","unicode-bidi","user-select","vertical-align","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","volume","white-space","widows","width","will-change","word-break","word-spacing","word-wrap","z-index","clip-path","clip-rule","mask","enable-background","filter","flood-color","flood-opacity","lighting-color","stop-color","stop-opacity","pointer-events","color-interpolation","color-interpolation-filters","color-rendering","fill","fill-opacity","fill-rule","image-rendering","marker","marker-end","marker-mid","marker-start","shape-rendering","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","text-rendering","baseline-shift","dominant-baseline","glyph-orientation-horizontal","glyph-orientation-vertical","text-anchor","writing-mode"],f=t(d),h=["scrollbar-arrow-color","scrollbar-base-color","scrollbar-dark-shadow-color","scrollbar-face-color","scrollbar-highlight-color","scrollbar-shadow-color","scrollbar-3d-light-color","scrollbar-track-color","shape-inside","searchfield-cancel-button","searchfield-decoration","searchfield-results-button","searchfield-results-decoration","zoom"],p=t(h),m=["font-family","src","unicode-range","font-variant","font-feature-settings","font-stretch","font-weight","font-style"],g=t(m),v=["additive-symbols","fallback","negative","pad","prefix","range","speak-as","suffix","symbols","system"],y=t(v),b=["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","grey","green","greenyellow","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"],w=t(b),x=["above","absolute","activeborder","additive","activecaption","afar","after-white-space","ahead","alias","all","all-scroll","alphabetic","alternate","always","amharic","amharic-abegede","antialiased","appworkspace","arabic-indic","armenian","asterisks","attr","auto","auto-flow","avoid","avoid-column","avoid-page","avoid-region","background","backwards","baseline","below","bidi-override","binary","bengali","blink","block","block-axis","bold","bolder","border","border-box","both","bottom","break","break-all","break-word","bullets","button","button-bevel","buttonface","buttonhighlight","buttonshadow","buttontext","calc","cambodian","capitalize","caps-lock-indicator","caption","captiontext","caret","cell","center","checkbox","circle","cjk-decimal","cjk-earthly-branch","cjk-heavenly-stem","cjk-ideographic","clear","clip","close-quote","col-resize","collapse","color","color-burn","color-dodge","column","column-reverse","compact","condensed","contain","content","contents","content-box","context-menu","continuous","copy","counter","counters","cover","crop","cross","crosshair","currentcolor","cursive","cyclic","darken","dashed","decimal","decimal-leading-zero","default","default-button","dense","destination-atop","destination-in","destination-out","destination-over","devanagari","difference","disc","discard","disclosure-closed","disclosure-open","document","dot-dash","dot-dot-dash","dotted","double","down","e-resize","ease","ease-in","ease-in-out","ease-out","element","ellipse","ellipsis","embed","end","ethiopic","ethiopic-abegede","ethiopic-abegede-am-et","ethiopic-abegede-gez","ethiopic-abegede-ti-er","ethiopic-abegede-ti-et","ethiopic-halehame-aa-er","ethiopic-halehame-aa-et","ethiopic-halehame-am-et","ethiopic-halehame-gez","ethiopic-halehame-om-et","ethiopic-halehame-sid-et","ethiopic-halehame-so-et","ethiopic-halehame-ti-er","ethiopic-halehame-ti-et","ethiopic-halehame-tig","ethiopic-numeric","ew-resize","exclusion","expanded","extends","extra-condensed","extra-expanded","fantasy","fast","fill","fixed","flat","flex","flex-end","flex-start","footnotes","forwards","from","geometricPrecision","georgian","graytext","grid","groove","gujarati","gurmukhi","hand","hangul","hangul-consonant","hard-light","hebrew","help","hidden","hide","higher","highlight","highlighttext","hiragana","hiragana-iroha","horizontal","hsl","hsla","hue","icon","ignore","inactiveborder","inactivecaption","inactivecaptiontext","infinite","infobackground","infotext","inherit","initial","inline","inline-axis","inline-block","inline-flex","inline-grid","inline-table","inset","inside","intrinsic","invert","italic","japanese-formal","japanese-informal","justify","kannada","katakana","katakana-iroha","keep-all","khmer","korean-hangul-formal","korean-hanja-formal","korean-hanja-informal","landscape","lao","large","larger","left","level","lighter","lighten","line-through","linear","linear-gradient","lines","list-item","listbox","listitem","local","logical","loud","lower","lower-alpha","lower-armenian","lower-greek","lower-hexadecimal","lower-latin","lower-norwegian","lower-roman","lowercase","ltr","luminosity","malayalam","match","matrix","matrix3d","media-controls-background","media-current-time-display","media-fullscreen-button","media-mute-button","media-play-button","media-return-to-realtime-button","media-rewind-button","media-seek-back-button","media-seek-forward-button","media-slider","media-sliderthumb","media-time-remaining-display","media-volume-slider","media-volume-slider-container","media-volume-sliderthumb","medium","menu","menulist","menulist-button","menulist-text","menulist-textfield","menutext","message-box","middle","min-intrinsic","mix","mongolian","monospace","move","multiple","multiply","myanmar","n-resize","narrower","ne-resize","nesw-resize","no-close-quote","no-drop","no-open-quote","no-repeat","none","normal","not-allowed","nowrap","ns-resize","numbers","numeric","nw-resize","nwse-resize","oblique","octal","opacity","open-quote","optimizeLegibility","optimizeSpeed","oriya","oromo","outset","outside","outside-shape","overlay","overline","padding","padding-box","painted","page","paused","persian","perspective","plus-darker","plus-lighter","pointer","polygon","portrait","pre","pre-line","pre-wrap","preserve-3d","progress","push-button","radial-gradient","radio","read-only","read-write","read-write-plaintext-only","rectangle","region","relative","repeat","repeating-linear-gradient","repeating-radial-gradient","repeat-x","repeat-y","reset","reverse","rgb","rgba","ridge","right","rotate","rotate3d","rotateX","rotateY","rotateZ","round","row","row-resize","row-reverse","rtl","run-in","running","s-resize","sans-serif","saturation","scale","scale3d","scaleX","scaleY","scaleZ","screen","scroll","scrollbar","scroll-position","se-resize","searchfield","searchfield-cancel-button","searchfield-decoration","searchfield-results-button","searchfield-results-decoration","semi-condensed","semi-expanded","separate","serif","show","sidama","simp-chinese-formal","simp-chinese-informal","single","skew","skewX","skewY","skip-white-space","slide","slider-horizontal","slider-vertical","sliderthumb-horizontal","sliderthumb-vertical","slow","small","small-caps","small-caption","smaller","soft-light","solid","somali","source-atop","source-in","source-out","source-over","space","space-around","space-between","spell-out","square","square-button","start","static","status-bar","stretch","stroke","sub","subpixel-antialiased","super","sw-resize","symbolic","symbols","table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row","table-row-group","tamil","telugu","text","text-bottom","text-top","textarea","textfield","thai","thick","thin","threeddarkshadow","threedface","threedhighlight","threedlightshadow","threedshadow","tibetan","tigre","tigrinya-er","tigrinya-er-abegede","tigrinya-et","tigrinya-et-abegede","to","top","trad-chinese-formal","trad-chinese-informal","transform","translate","translate3d","translateX","translateY","translateZ","transparent","ultra-condensed","ultra-expanded","underline","unset","up","upper-alpha","upper-armenian","upper-greek","upper-hexadecimal","upper-latin","upper-norwegian","upper-roman","uppercase","urdu","url","var","vertical","vertical-text","visible","visibleFill","visiblePainted","visibleStroke","visual","w-resize","wait","wave","wider","window","windowframe","windowtext","words","wrap","wrap-reverse","x-large","x-small","xor","xx-large","xx-small"],k=t(x),C=n.concat(o).concat(l).concat(c).concat(d).concat(h).concat(b).concat(x);e.registerHelper("hintWords","css",C),e.defineMIME("text/css",{documentTypes:i,mediaTypes:a,mediaFeatures:s,mediaValueKeywords:u,propertyKeywords:f,nonStandardPropertyKeywords:p,fontProperties:g,counterDescriptors:y,colorKeywords:w,valueKeywords:k,tokenHooks:{"/":function(e,t){return!!e.eat("*")&&(t.tokenize=r,r(e,t))}},name:"css"}),e.defineMIME("text/x-scss",{mediaTypes:a,mediaFeatures:s,mediaValueKeywords:u,propertyKeywords:f,nonStandardPropertyKeywords:p,colorKeywords:w,valueKeywords:k,fontProperties:g,allowNested:!0,lineComment:"//",tokenHooks:{"/":function(e,t){return e.eat("/")?(e.skipToEnd(),["comment","comment"]):e.eat("*")?(t.tokenize=r,r(e,t)):["operator","operator"]},":":function(e){return!!e.match(/\s*\{/)&&[null,"{"]},$:function(e){return e.match(/^[\w-]+/),e.match(/^\s*:/,!1)?["variable-2","variable-definition"]:["variable-2","variable"]},"#":function(e){return!!e.eat("{")&&[null,"interpolation"]}},name:"css",helperType:"scss"}),e.defineMIME("text/x-less",{mediaTypes:a,mediaFeatures:s,mediaValueKeywords:u,propertyKeywords:f,nonStandardPropertyKeywords:p,colorKeywords:w,valueKeywords:k,fontProperties:g,allowNested:!0,lineComment:"//",tokenHooks:{"/":function(e,t){return e.eat("/")?(e.skipToEnd(),["comment","comment"]):e.eat("*")?(t.tokenize=r,r(e,t)):["operator","operator"]},"@":function(e){return e.eat("{")?[null,"interpolation"]:!e.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/,!1)&&(e.eatWhile(/[\w\\\-]/),e.match(/^\s*:/,!1)?["variable-2","variable-definition"]:["variable-2","variable"])},"&":function(){return["atom","atom"]}},name:"css",helperType:"less"}),e.defineMIME("text/x-gss",{documentTypes:i,mediaTypes:a,mediaFeatures:s,propertyKeywords:f,nonStandardPropertyKeywords:p,fontProperties:g,counterDescriptors:y,colorKeywords:w,valueKeywords:k,supportsAtComponent:!0,tokenHooks:{"/":function(e,t){return!!e.eat("*")&&(t.tokenize=r,r(e,t))}},name:"css",helperType:"gss"})})},{"../../lib/codemirror":15}],17:[function(e,r,n){!function(i){"object"==typeof n&&"object"==typeof r?i(e("../../lib/codemirror"),e("../xml/xml"),e("../javascript/javascript"),e("../css/css")):"function"==typeof t&&t.amd?t(["../../lib/codemirror","../xml/xml","../javascript/javascript","../css/css"],i):i(CodeMirror)}(function(e){"use strict";function t(e,t,r){var n=e.current(),i=n.search(t);return i>-1?e.backUp(n.length-i):n.match(/<\/?$/)&&(e.backUp(n.length),e.match(t,!1)||e.match(n)),r}function r(e){var t=s[e];return t?t:s[e]=new RegExp("\\s+"+e+"\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*")}function n(e,t){var n=e.match(r(t));return n?/^\s*(.*?)\s*$/.exec(n[2])[1]:""}function i(e,t){return new RegExp((t?"^":"")+"</s*"+e+"s*>","i")}function o(e,t){for(var r in e)for(var n=t[r]||(t[r]=[]),i=e[r],o=i.length-1;o>=0;o--)n.unshift(i[o])}function a(e,t){for(var r=0;r<e.length;r++){var i=e[r];if(!i[0]||i[1].test(n(t,i[0])))return i[2]}}var l={script:[["lang",/(javascript|babel)/i,"javascript"],["type",/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i,"javascript"],["type",/./,"text/plain"],[null,null,"javascript"]],style:[["lang",/^css$/i,"css"],["type",/^(text\/)?(x-)?(stylesheet|css)$/i,"css"],["type",/./,"text/plain"],[null,null,"css"]]},s={};e.defineMode("htmlmixed",function(r,n){function s(n,o){var l,d=c.token(n,o.htmlState),f=/\btag\b/.test(d);if(f&&!/[<>\s\/]/.test(n.current())&&(l=o.htmlState.tagName&&o.htmlState.tagName.toLowerCase())&&u.hasOwnProperty(l))o.inTag=l+" ";else if(o.inTag&&f&&/>$/.test(n.current())){var h=/^([\S]+) (.*)/.exec(o.inTag);o.inTag=null;var p=">"==n.current()&&a(u[h[1]],h[2]),m=e.getMode(r,p),g=i(h[1],!0),v=i(h[1],!1);o.token=function(e,r){return e.match(g,!1)?(r.token=s,r.localState=r.localMode=null,null):t(e,v,r.localMode.token(e,r.localState))},o.localMode=m,o.localState=e.startState(m,c.indent(o.htmlState,""))}else o.inTag&&(o.inTag+=n.current(),n.eol()&&(o.inTag+=" "));return d}var c=e.getMode(r,{name:"xml",htmlMode:!0,multilineTagIndentFactor:n.multilineTagIndentFactor,multilineTagIndentPastTag:n.multilineTagIndentPastTag}),u={},d=n&&n.tags,f=n&&n.scriptTypes;if(o(l,u),d&&o(d,u),f)for(var h=f.length-1;h>=0;h--)u.script.unshift(["type",f[h].matches,f[h].mode]);return{startState:function(){return{token:s,inTag:null,localMode:null,localState:null,htmlState:e.startState(c)}},copyState:function(t){var r;return t.localState&&(r=e.copyState(t.localMode,t.localState)),{token:t.token,inTag:t.inTag,localMode:t.localMode,localState:r,htmlState:e.copyState(c,t.htmlState)}},token:function(e,t){return t.token(e,t)},indent:function(t,r){return!t.localMode||/^\s*<\//.test(r)?c.indent(t.htmlState,r):t.localMode.indent?t.localMode.indent(t.localState,r):e.Pass},innerMode:function(e){return{state:e.localState||e.htmlState,mode:e.localMode||c}}}},"xml","javascript","css"),e.defineMIME("text/html","htmlmixed")})},{"../../lib/codemirror":15,"../css/css":16,"../javascript/javascript":18,"../xml/xml":19}],18:[function(e,r,n){!function(i){"object"==typeof n&&"object"==typeof r?i(e("../../lib/codemirror")):"function"==typeof t&&t.amd?t(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){"use strict";function t(e,t,r){return/^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.test(t.lastType)||"quasi"==t.lastType&&/\{\s*$/.test(e.string.slice(0,e.pos-(r||0)))}e.defineMode("javascript",function(r,n){function i(e){for(var t,r=!1,n=!1;null!=(t=e.next());){if(!r){if("/"==t&&!n)return;"["==t?n=!0:n&&"]"==t&&(n=!1)}r=!r&&"\\"==t}}function o(e,t,r){return Te=e,Le=r,t}function a(e,r){var n=e.next();if('"'==n||"'"==n)return r.tokenize=l(n),r.tokenize(e,r);if("."==n&&e.match(/^\d+(?:[eE][+\-]?\d+)?/))return o("number","number");if("."==n&&e.match(".."))return o("spread","meta");if(/[\[\]{}\(\),;\:\.]/.test(n))return o(n);if("="==n&&e.eat(">"))return o("=>","operator");if("0"==n&&e.eat(/x/i))return e.eatWhile(/[\da-f]/i),o("number","number");if("0"==n&&e.eat(/o/i))return e.eatWhile(/[0-7]/i),o("number","number");if("0"==n&&e.eat(/b/i))return e.eatWhile(/[01]/i),o("number","number");if(/\d/.test(n))return e.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/),o("number","number");if("/"==n)return e.eat("*")?(r.tokenize=s,s(e,r)):e.eat("/")?(e.skipToEnd(),o("comment","comment")):t(e,r,1)?(i(e),e.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/),o("regexp","string-2")):(e.eatWhile(ze),o("operator","operator",e.current()));if("`"==n)return r.tokenize=c,c(e,r);if("#"==n)return e.skipToEnd(),o("error","error");if(ze.test(n))return">"==n&&r.lexical&&">"==r.lexical.type||e.eatWhile(ze),o("operator","operator",e.current());if(We.test(n)){e.eatWhile(We);var a=e.current(),u=Ee.propertyIsEnumerable(a)&&Ee[a];return u&&"."!=r.lastType?o(u.type,u.style,a):o("variable","variable",a)}}function l(e){return function(t,r){var n,i=!1;if(_e&&"@"==t.peek()&&t.match(De))return r.tokenize=a,o("jsonld-keyword","meta");for(;null!=(n=t.next())&&(n!=e||i);)i=!i&&"\\"==n;return i||(r.tokenize=a),o("string","string")}}function s(e,t){for(var r,n=!1;r=e.next();){if("/"==r&&n){t.tokenize=a;break}n="*"==r}return o("comment","comment")}function c(e,t){for(var r,n=!1;null!=(r=e.next());){if(!n&&("`"==r||"$"==r&&e.eat("{"))){t.tokenize=a;break}n=!n&&"\\"==r}return o("quasi","string-2",e.current())}function u(e,t){t.fatArrowAt&&(t.fatArrowAt=null);var r=e.string.indexOf("=>",e.start);if(!(r<0)){if(Ne){var n=/:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(e.string.slice(e.start,r));n&&(r=n.index)}for(var i=0,o=!1,a=r-1;a>=0;--a){var l=e.string.charAt(a),s=Pe.indexOf(l);if(s>=0&&s<3){if(!i){++a;break}if(0==--i){"("==l&&(o=!0);break}}else if(s>=3&&s<6)++i;else if(We.test(l))o=!0;else{if(/["'\/]/.test(l))return;if(o&&!i){++a;break}}}o&&!i&&(t.fatArrowAt=a)}}function d(e,t,r,n,i,o){this.indented=e,this.column=t,this.type=r,this.prev=i,this.info=o,null!=n&&(this.align=n)}function f(e,t){for(var r=e.localVars;r;r=r.next)if(r.name==t)return!0;for(var n=e.context;n;n=n.prev)for(var r=n.vars;r;r=r.next)if(r.name==t)return!0}function h(e,t,r,n,i){var o=e.cc;for(Ie.state=e,Ie.stream=i,Ie.marked=null,Ie.cc=o,Ie.style=t,e.lexical.hasOwnProperty("align")||(e.lexical.align=!0);;){if((o.length?o.pop():Oe?C:k)(r,n)){for(;o.length&&o[o.length-1].lex;)o.pop()();return Ie.marked?Ie.marked:"variable"==r&&f(e,n)?"variable-2":t}}}function p(){for(var e=arguments.length-1;e>=0;e--)Ie.cc.push(arguments[e])}function m(){return p.apply(null,arguments),!0}function g(e){function t(t){for(var r=t;r;r=r.next)if(r.name==e)return!0;return!1}var r=Ie.state;if(Ie.marked="def",r.context){if(t(r.localVars))return;r.localVars={name:e,next:r.localVars}}else{if(t(r.globalVars))return;n.globalVars&&(r.globalVars={name:e,next:r.globalVars})}}function v(){Ie.state.context={prev:Ie.state.context,vars:Ie.state.localVars},Ie.state.localVars=Fe}function y(){Ie.state.localVars=Ie.state.context.vars,Ie.state.context=Ie.state.context.prev}function b(e,t){var r=function(){var r=Ie.state,n=r.indented;if("stat"==r.lexical.type)n=r.lexical.indented;else for(var i=r.lexical;i&&")"==i.type&&i.align;i=i.prev)n=i.indented;r.lexical=new d(n,Ie.stream.column(),e,null,r.lexical,t)};return r.lex=!0,r}function w(){var e=Ie.state;e.lexical.prev&&(")"==e.lexical.type&&(e.indented=e.lexical.indented),e.lexical=e.lexical.prev)}function x(e){function t(r){return r==e?m():";"==e?p():m(t)}return t}function k(e,t){return"var"==e?m(b("vardef",t.length),J,x(";"),w):"keyword a"==e?m(b("form"),T,k,w):"keyword b"==e?m(b("form"),k,w):"{"==e?m(b("}"),U,w):";"==e?m():"if"==e?("else"==Ie.state.lexical.info&&Ie.state.cc[Ie.state.cc.length-1]==w&&Ie.state.cc.pop()(),m(b("form"),T,k,w,ne)):"function"==e?m(ce):"for"==e?m(b("form"),ie,k,w):"variable"==e?m(b("stat"),I):"switch"==e?m(b("form"),T,b("}","switch"),x("{"),U,w,w):"case"==e?m(C,x(":")):"default"==e?m(x(":")):"catch"==e?m(b("form"),v,x("("),ue,x(")"),k,w,y):"class"==e?m(b("form"),fe,w):"export"==e?m(b("stat"),ge,w):"import"==e?m(b("stat"),ye,w):"module"==e?m(b("form"),Q,b("}"),x("{"),U,w,w):"type"==e?m(G,x("operator"),G,x(";")):"async"==e?m(k):p(b("stat"),C,x(";"),w)}function C(e){return L(e,!1)}function S(e){return L(e,!0)}function T(e){return"("!=e?p():m(b(")"),C,x(")"),w)}function L(e,t){if(Ie.state.fatArrowAt==Ie.stream.start){var r=t?z:E;if("("==e)return m(v,b(")"),q(Q,")"),w,x("=>"),r,y);if("variable"==e)return p(v,Q,x("=>"),r,y)}var n=t?O:_;return He.hasOwnProperty(e)?m(n):"function"==e?m(ce,n):"class"==e?m(b("form"),de,w):"keyword c"==e||"async"==e?m(t?A:M):"("==e?m(b(")"),M,x(")"),w,n):"operator"==e||"spread"==e?m(t?S:C):"["==e?m(b("]"),Ce,w,n):"{"==e?K(j,"}",null,n):"quasi"==e?p(N,n):"new"==e?m(D(t)):m()}function M(e){return e.match(/[;\}\)\],]/)?p():p(C)}function A(e){return e.match(/[;\}\)\],]/)?p():p(S)}function _(e,t){return","==e?m(C):O(e,t,!1)}function O(e,t,r){var n=0==r?_:O,i=0==r?C:S;return"=>"==e?m(v,r?z:E,y):"operator"==e?/\+\+|--/.test(t)?m(n):"?"==t?m(C,x(":"),i):m(i):"quasi"==e?p(N,n):";"!=e?"("==e?K(S,")","call",n):"."==e?m(F,n):"["==e?m(b("]"),M,x("]"),w,n):void 0:void 0}function N(e,t){return"quasi"!=e?p():"${"!=t.slice(t.length-2)?m(N):m(C,W)}function W(e){if("}"==e)return Ie.marked="string-2",Ie.state.tokenize=c,m(N)}function E(e){return u(Ie.stream,Ie.state),p("{"==e?k:C)}function z(e){return u(Ie.stream,Ie.state),p("{"==e?k:S)}function D(e){return function(t){return"."==t?m(e?H:P):p(e?S:C)}}function P(e,t){if("target"==t)return Ie.marked="keyword",m(_)}function H(e,t){if("target"==t)return Ie.marked="keyword",m(O)}function I(e){return":"==e?m(w,k):p(_,x(";"),w)}function F(e){if("variable"==e)return Ie.marked="property",m()}function j(e,t){return"async"==e?(Ie.marked="property",m(j)):"variable"==e||"keyword"==Ie.style?(Ie.marked="property",m("get"==t||"set"==t?R:B)):"number"==e||"string"==e?(Ie.marked=_e?"property":Ie.style+" property",m(B)):"jsonld-keyword"==e?m(B):"modifier"==e?m(j):"["==e?m(C,x("]"),B):"spread"==e?m(C):":"==e?p(B):void 0}function R(e){return"variable"!=e?p(B):(Ie.marked="property",m(ce))}function B(e){return":"==e?m(S):"("==e?p(ce):void 0}function q(e,t,r){function n(i,o){if(r?r.indexOf(i)>-1:","==i){var a=Ie.state.lexical;return"call"==a.info&&(a.pos=(a.pos||0)+1),m(function(r,n){return r==t||n==t?p():p(e)},n)}return i==t||o==t?m():m(x(t))}return function(r,i){return r==t||i==t?m():p(e,n)}}function K(e,t,r){for(var n=3;n<arguments.length;n++)Ie.cc.push(arguments[n]);return m(b(t,r),q(e,t),w)}function U(e){return"}"==e?m():p(k,U)}function V(e,t){if(Ne){if(":"==e)return m(G);if("?"==t)return m(V)}}function G(e){return"variable"==e?(Ie.marked="variable-3",m(Z)):"string"==e||"number"==e||"atom"==e?m(Z):"{"==e?m(b("}"),q(Y,"}",",;"),w):"("==e?m(q(X,")"),$):void 0}function $(e){if("=>"==e)return m(G)}function Y(e,t){return"variable"==e||"keyword"==Ie.style?(Ie.marked="property",m(Y)):"?"==t?m(Y):":"==e?m(G):void 0}function X(e){return"variable"==e?m(X):":"==e?m(G):void 0}function Z(e,t){return"<"==t?m(b(">"),q(G,">"),w,Z):"|"==t||"."==e?m(G):"["==e?m(x("]"),Z):void 0}function J(){return p(Q,V,te,re)}function Q(e,t){return"modifier"==e?m(Q):"variable"==e?(g(t),m()):"spread"==e?m(Q):"["==e?K(Q,"]"):"{"==e?K(ee,"}"):void 0}function ee(e,t){return"variable"!=e||Ie.stream.match(/^\s*:/,!1)?("variable"==e&&(Ie.marked="property"),"spread"==e?m(Q):"}"==e?p():m(x(":"),Q,te)):(g(t),m(te))}function te(e,t){if("="==t)return m(S)}function re(e){if(","==e)return m(J)}function ne(e,t){if("keyword b"==e&&"else"==t)return m(b("form","else"),k,w)}function ie(e){if("("==e)return m(b(")"),oe,x(")"),w)}function oe(e){return"var"==e?m(J,x(";"),le):";"==e?m(le):"variable"==e?m(ae):p(C,x(";"),le)}function ae(e,t){return"in"==t||"of"==t?(Ie.marked="keyword",m(C)):m(_,le)}function le(e,t){return";"==e?m(se):"in"==t||"of"==t?(Ie.marked="keyword",m(C)):p(C,x(";"),se)}function se(e){")"!=e&&m(C)}function ce(e,t){return"*"==t?(Ie.marked="keyword",m(ce)):"variable"==e?(g(t),m(ce)):"("==e?m(v,b(")"),q(ue,")"),w,V,k,y):void 0}function ue(e){return"spread"==e?m(ue):p(Q,V,te)}function de(e,t){return"variable"==e?fe(e,t):he(e,t)}function fe(e,t){if("variable"==e)return g(t),m(he)}function he(e,t){return"extends"==t||"implements"==t||Ne&&","==e?m(Ne?G:C,he):"{"==e?m(b("}"),pe,w):void 0}function pe(e,t){return"variable"==e||"keyword"==Ie.style?("async"==t||"static"==t||"get"==t||"set"==t||Ne&&("public"==t||"private"==t||"protected"==t||"readonly"==t||"abstract"==t))&&Ie.stream.match(/^\s+[\w$\xa1-\uffff]/,!1)?(Ie.marked="keyword",m(pe)):(Ie.marked="property",m(Ne?me:ce,pe)):"["==e?m(C,x("]"),Ne?me:ce,pe):"*"==t?(Ie.marked="keyword",m(pe)):";"==e?m(pe):"}"==e?m():void 0}function me(e,t){return"?"==t?m(me):":"==e?m(G,te):p(ce)}function ge(e,t){return"*"==t?(Ie.marked="keyword",m(ke,x(";"))):"default"==t?(Ie.marked="keyword",m(C,x(";"))):"{"==e?m(q(ve,"}"),ke,x(";")):p(k)}function ve(e,t){return"as"==t?(Ie.marked="keyword",m(x("variable"))):"variable"==e?p(S,ve):void 0}function ye(e){return"string"==e?m():p(be,we,ke)}function be(e,t){return"{"==e?K(be,"}"):("variable"==e&&g(t),"*"==t&&(Ie.marked="keyword"),m(xe))}function we(e){if(","==e)return m(be,we)}function xe(e,t){if("as"==t)return Ie.marked="keyword",m(be)}function ke(e,t){if("from"==t)return Ie.marked="keyword",m(C)}function Ce(e){return"]"==e?m():p(q(S,"]"))}function Se(e,t){return"operator"==e.lastType||","==e.lastType||ze.test(t.charAt(0))||/[,.]/.test(t.charAt(0))}var Te,Le,Me=r.indentUnit,Ae=n.statementIndent,_e=n.jsonld,Oe=n.json||_e,Ne=n.typescript,We=n.wordCharacters||/[\w$\xa1-\uffff]/,Ee=function(){function e(e){return{type:e,style:"keyword"}}var t=e("keyword a"),r=e("keyword b"),n=e("keyword c"),i=e("operator"),o={type:"atom",style:"atom"},a={if:e("if"),while:t,with:t,else:r,do:r,try:r,finally:r,return:n,break:n,continue:n,new:e("new"),delete:n,throw:n,debugger:n,var:e("var"),const:e("var"),let:e("var"),function:e("function"),catch:e("catch"),for:e("for"),switch:e("switch"),case:e("case"),default:e("default"),in:i,typeof:i,instanceof:i,true:o,false:o,null:o,undefined:o,NaN:o,Infinity:o,this:e("this"),class:e("class"),super:e("atom"),yield:n,export:e("export"),import:e("import"),extends:n,await:n,async:e("async")};if(Ne){var l={type:"variable",style:"variable-3"},s={interface:e("class"),implements:n,namespace:n,module:e("module"),enum:e("module"),type:e("type"),public:e("modifier"),private:e("modifier"),protected:e("modifier"),
8
- abstract:e("modifier"),as:i,string:l,number:l,boolean:l,any:l};for(var c in s)a[c]=s[c]}return a}(),ze=/[+\-*&%=<>!?|~^]/,De=/^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/,Pe="([{}])",He={atom:!0,number:!0,variable:!0,string:!0,regexp:!0,this:!0,"jsonld-keyword":!0},Ie={state:null,column:null,marked:null,cc:null},Fe={name:"this",next:{name:"arguments"}};return w.lex=!0,{startState:function(e){var t={tokenize:a,lastType:"sof",cc:[],lexical:new d((e||0)-Me,0,"block",!1),localVars:n.localVars,context:n.localVars&&{vars:n.localVars},indented:e||0};return n.globalVars&&"object"==typeof n.globalVars&&(t.globalVars=n.globalVars),t},token:function(e,t){if(e.sol()&&(t.lexical.hasOwnProperty("align")||(t.lexical.align=!1),t.indented=e.indentation(),u(e,t)),t.tokenize!=s&&e.eatSpace())return null;var r=t.tokenize(e,t);return"comment"==Te?r:(t.lastType="operator"!=Te||"++"!=Le&&"--"!=Le?Te:"incdec",h(t,r,Te,Le,e))},indent:function(t,r){if(t.tokenize==s)return e.Pass;if(t.tokenize!=a)return 0;var i,o=r&&r.charAt(0),l=t.lexical;if(!/^\s*else\b/.test(r))for(var c=t.cc.length-1;c>=0;--c){var u=t.cc[c];if(u==w)l=l.prev;else if(u!=ne)break}for(;("stat"==l.type||"form"==l.type)&&("}"==o||(i=t.cc[t.cc.length-1])&&(i==_||i==O)&&!/^[,\.=+\-*:?[\(]/.test(r));)l=l.prev;Ae&&")"==l.type&&"stat"==l.prev.type&&(l=l.prev);var d=l.type,f=o==d;return"vardef"==d?l.indented+("operator"==t.lastType||","==t.lastType?l.info+1:0):"form"==d&&"{"==o?l.indented:"form"==d?l.indented+Me:"stat"==d?l.indented+(Se(t,r)?Ae||Me:0):"switch"!=l.info||f||0==n.doubleIndentSwitch?l.align?l.column+(f?0:1):l.indented+(f?0:Me):l.indented+(/^(?:case|default)\b/.test(r)?Me:2*Me)},electricInput:/^\s*(?:case .*?:|default:|\{|\})$/,blockCommentStart:Oe?null:"/*",blockCommentEnd:Oe?null:"*/",lineComment:Oe?null:"//",fold:"brace",closeBrackets:"()[]{}''\"\"``",helperType:Oe?"json":"javascript",jsonldMode:_e,jsonMode:Oe,expressionAllowed:t,skipExpression:function(e){var t=e.cc[e.cc.length-1];t!=C&&t!=S||e.cc.pop()}}}),e.registerHelper("wordChars","javascript",/[\w$]/),e.defineMIME("text/javascript","javascript"),e.defineMIME("text/ecmascript","javascript"),e.defineMIME("application/javascript","javascript"),e.defineMIME("application/x-javascript","javascript"),e.defineMIME("application/ecmascript","javascript"),e.defineMIME("application/json",{name:"javascript",json:!0}),e.defineMIME("application/x-json",{name:"javascript",json:!0}),e.defineMIME("application/ld+json",{name:"javascript",jsonld:!0}),e.defineMIME("text/typescript",{name:"javascript",typescript:!0}),e.defineMIME("application/typescript",{name:"javascript",typescript:!0})})},{"../../lib/codemirror":15}],19:[function(e,r,n){!function(i){"object"==typeof n&&"object"==typeof r?i(e("../../lib/codemirror")):"function"==typeof t&&t.amd?t(["../../lib/codemirror"],i):i(CodeMirror)}(function(e){"use strict";var t={autoSelfClosers:{area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0},implicitlyClosed:{dd:!0,li:!0,optgroup:!0,option:!0,p:!0,rp:!0,rt:!0,tbody:!0,td:!0,tfoot:!0,th:!0,tr:!0},contextGrabbers:{dd:{dd:!0,dt:!0},dt:{dd:!0,dt:!0},li:{li:!0},option:{option:!0,optgroup:!0},optgroup:{optgroup:!0},p:{address:!0,article:!0,aside:!0,blockquote:!0,dir:!0,div:!0,dl:!0,fieldset:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,menu:!0,nav:!0,ol:!0,p:!0,pre:!0,section:!0,table:!0,ul:!0},rp:{rp:!0,rt:!0},rt:{rp:!0,rt:!0},tbody:{tbody:!0,tfoot:!0},td:{td:!0,th:!0},tfoot:{tbody:!0},th:{td:!0,th:!0},thead:{tbody:!0,tfoot:!0},tr:{tr:!0}},doNotIndent:{pre:!0},allowUnquoted:!0,allowMissing:!0,caseFold:!0},r={autoSelfClosers:{},implicitlyClosed:{},contextGrabbers:{},doNotIndent:{},allowUnquoted:!1,allowMissing:!1,caseFold:!1};e.defineMode("xml",function(n,i){function o(e,t){function r(r){return t.tokenize=r,r(e,t)}var n=e.next();if("<"==n)return e.eat("!")?e.eat("[")?e.match("CDATA[")?r(s("atom","]]>")):null:e.match("--")?r(s("comment","-->")):e.match("DOCTYPE",!0,!0)?(e.eatWhile(/[\w\._\-]/),r(c(1))):null:e.eat("?")?(e.eatWhile(/[\w\._\-]/),t.tokenize=s("meta","?>"),"meta"):(L=e.eat("/")?"closeTag":"openTag",t.tokenize=a,"tag bracket");if("&"==n){var i;return i=e.eat("#")?e.eat("x")?e.eatWhile(/[a-fA-F\d]/)&&e.eat(";"):e.eatWhile(/[\d]/)&&e.eat(";"):e.eatWhile(/[\w\.\-:]/)&&e.eat(";"),i?"atom":"error"}return e.eatWhile(/[^&<]/),null}function a(e,t){var r=e.next();if(">"==r||"/"==r&&e.eat(">"))return t.tokenize=o,L=">"==r?"endTag":"selfcloseTag","tag bracket";if("="==r)return L="equals",null;if("<"==r){t.tokenize=o,t.state=h,t.tagName=t.tagStart=null;var n=t.tokenize(e,t);return n?n+" tag error":"tag error"}return/[\'\"]/.test(r)?(t.tokenize=l(r),t.stringStartCol=e.column(),t.tokenize(e,t)):(e.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/),"word")}function l(e){var t=function(t,r){for(;!t.eol();)if(t.next()==e){r.tokenize=a;break}return"string"};return t.isInAttribute=!0,t}function s(e,t){return function(r,n){for(;!r.eol();){if(r.match(t)){n.tokenize=o;break}r.next()}return e}}function c(e){return function(t,r){for(var n;null!=(n=t.next());){if("<"==n)return r.tokenize=c(e+1),r.tokenize(t,r);if(">"==n){if(1==e){r.tokenize=o;break}return r.tokenize=c(e-1),r.tokenize(t,r)}}return"meta"}}function u(e,t,r){this.prev=e.context,this.tagName=t,this.indent=e.indented,this.startOfLine=r,(C.doNotIndent.hasOwnProperty(t)||e.context&&e.context.noIndent)&&(this.noIndent=!0)}function d(e){e.context&&(e.context=e.context.prev)}function f(e,t){for(var r;;){if(!e.context)return;if(r=e.context.tagName,!C.contextGrabbers.hasOwnProperty(r)||!C.contextGrabbers[r].hasOwnProperty(t))return;d(e)}}function h(e,t,r){return"openTag"==e?(r.tagStart=t.column(),p):"closeTag"==e?m:h}function p(e,t,r){return"word"==e?(r.tagName=t.current(),M="tag",y):(M="error",p)}function m(e,t,r){if("word"==e){var n=t.current();return r.context&&r.context.tagName!=n&&C.implicitlyClosed.hasOwnProperty(r.context.tagName)&&d(r),r.context&&r.context.tagName==n||C.matchClosing===!1?(M="tag",g):(M="tag error",v)}return M="error",v}function g(e,t,r){return"endTag"!=e?(M="error",g):(d(r),h)}function v(e,t,r){return M="error",g(e,t,r)}function y(e,t,r){if("word"==e)return M="attribute",b;if("endTag"==e||"selfcloseTag"==e){var n=r.tagName,i=r.tagStart;return r.tagName=r.tagStart=null,"selfcloseTag"==e||C.autoSelfClosers.hasOwnProperty(n)?f(r,n):(f(r,n),r.context=new u(r,n,i==r.indented)),h}return M="error",y}function b(e,t,r){return"equals"==e?w:(C.allowMissing||(M="error"),y(e,t,r))}function w(e,t,r){return"string"==e?x:"word"==e&&C.allowUnquoted?(M="string",y):(M="error",y(e,t,r))}function x(e,t,r){return"string"==e?x:y(e,t,r)}var k=n.indentUnit,C={},S=i.htmlMode?t:r;for(var T in S)C[T]=S[T];for(var T in i)C[T]=i[T];var L,M;return o.isInText=!0,{startState:function(e){var t={tokenize:o,state:h,indented:e||0,tagName:null,tagStart:null,context:null};return null!=e&&(t.baseIndent=e),t},token:function(e,t){if(!t.tagName&&e.sol()&&(t.indented=e.indentation()),e.eatSpace())return null;L=null;var r=t.tokenize(e,t);return(r||L)&&"comment"!=r&&(M=null,t.state=t.state(L||r,e,t),M&&(r="error"==M?r+" error":M)),r},indent:function(t,r,n){var i=t.context;if(t.tokenize.isInAttribute)return t.tagStart==t.indented?t.stringStartCol+1:t.indented+k;if(i&&i.noIndent)return e.Pass;if(t.tokenize!=a&&t.tokenize!=o)return n?n.match(/^(\s*)/)[0].length:0;if(t.tagName)return C.multilineTagIndentPastTag!==!1?t.tagStart+t.tagName.length+2:t.tagStart+k*(C.multilineTagIndentFactor||1);if(C.alignCDATA&&/<!\[CDATA\[/.test(r))return 0;var l=r&&/^<(\/)?([\w_:\.-]*)/.exec(r);if(l&&l[1])for(;i;){if(i.tagName==l[2]){i=i.prev;break}if(!C.implicitlyClosed.hasOwnProperty(i.tagName))break;i=i.prev}else if(l)for(;i;){var s=C.contextGrabbers[i.tagName];if(!s||!s.hasOwnProperty(l[2]))break;i=i.prev}for(;i&&i.prev&&!i.startOfLine;)i=i.prev;return i?i.indent+k:t.baseIndent||0},electricInput:/<\/[\s\w:]+>$/,blockCommentStart:"<!--",blockCommentEnd:"-->",configuration:C.htmlMode?"html":"xml",helperType:C.htmlMode?"html":"xml",skipAttribute:function(e){e.state==w&&(e.state=y)}}}),e.defineMIME("text/xml","xml"),e.defineMIME("application/xml","xml"),e.mimeModes.hasOwnProperty("text/html")||e.defineMIME("text/html",{name:"xml",htmlMode:!0})})},{"../../lib/codemirror":15}],20:[function(e,t,r){function n(e,t){function r(){return this.pos=0,this.token="",this.current_mode="CONTENT",this.tags={parent:"parent1",parentcount:1,parent1:""},this.tag_type="",this.token_text=this.last_token=this.last_text=this.token_type="",this.Utils={whitespace:"\n\r\t ".split(""),single_token:"br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed,?php,?,?=".split(","),extra_liners:"head,body,/html".split(","),in_array:function(e,t){for(var r=0;r<t.length;r++)if(e===t[r])return!0;return!1}},this.get_content=function(){for(var e="",t=[],r=!1;"<"!==this.input.charAt(this.pos);){if(this.pos>=this.input.length)return t.length?t.join(""):["","TK_EOF"];if(e=this.input.charAt(this.pos),this.pos++,this.line_char_count++,this.Utils.in_array(e,this.Utils.whitespace))t.length&&(r=!0),this.line_char_count--;else{if(r){if(this.line_char_count>=this.max_char){t.push("\n");for(var n=0;n<this.indent_level;n++)t.push(this.indent_string);this.line_char_count=0}else t.push(" "),this.line_char_count++;r=!1}t.push(e)}}return t.length?t.join(""):""},this.get_contents_to=function(e){if(this.pos==this.input.length)return["","TK_EOF"];var t="",r=new RegExp("</"+e+"\\s*>","igm");r.lastIndex=this.pos;var n=r.exec(this.input),i=n?n.index:this.input.length;return this.pos<i&&(t=this.input.substring(this.pos,i),this.pos=i),t},this.record_tag=function(e){this.tags[e+"count"]?(this.tags[e+"count"]++,this.tags[e+this.tags[e+"count"]]=this.indent_level):(this.tags[e+"count"]=1,this.tags[e+this.tags[e+"count"]]=this.indent_level),this.tags[e+this.tags[e+"count"]+"parent"]=this.tags.parent,this.tags.parent=e+this.tags[e+"count"]},this.retrieve_tag=function(e){if(this.tags[e+"count"]){for(var t=this.tags.parent;t&&e+this.tags[e+"count"]!==t;)t=this.tags[t+"parent"];t&&(this.indent_level=this.tags[e+this.tags[e+"count"]],this.tags.parent=this.tags[t+"parent"]),delete this.tags[e+this.tags[e+"count"]+"parent"],delete this.tags[e+this.tags[e+"count"]],1==this.tags[e+"count"]?delete this.tags[e+"count"]:this.tags[e+"count"]--}},this.get_tag=function(){var e,t,r="",n=[],i=!1;do{if(this.pos>=this.input.length)return n.length?n.join(""):["","TK_EOF"];r=this.input.charAt(this.pos),this.pos++,this.line_char_count++,this.Utils.in_array(r,this.Utils.whitespace)?(i=!0,this.line_char_count--):("'"!==r&&'"'!==r||n[1]&&"!"===n[1]||(r+=this.get_unformatted(r),i=!0),"="===r&&(i=!1),n.length&&"="!==n[n.length-1]&&">"!==r&&i&&(this.line_char_count>=this.max_char?(this.print_newline(!1,n),this.line_char_count=0):(n.push(" "),this.line_char_count++),i=!1),"<"===r&&(e=this.pos-1),n.push(r))}while(">"!==r);var o,a=n.join("");o=a.indexOf(" ")!=-1?a.indexOf(" "):a.indexOf(">");var l=a.substring(1,o).toLowerCase();if("/"===a.charAt(a.length-2)||this.Utils.in_array(l,this.Utils.single_token))this.tag_type="SINGLE";else if("script"===l)this.record_tag(l),this.tag_type="SCRIPT";else if("style"===l)this.record_tag(l),this.tag_type="STYLE";else if(this.Utils.in_array(l,s)){var c=this.get_unformatted("</"+l+">",a);n.push(c),e>0&&this.Utils.in_array(this.input.charAt(e-1),this.Utils.whitespace)&&n.splice(0,0,this.input.charAt(e-1)),t=this.pos-1,this.Utils.in_array(this.input.charAt(t+1),this.Utils.whitespace)&&n.push(this.input.charAt(t+1)),this.tag_type="SINGLE"}else if("!"===l.charAt(0))if(l.indexOf("[if")!=-1){if(a.indexOf("!IE")!=-1){var c=this.get_unformatted("-->",a);n.push(c)}this.tag_type="START"}else if(l.indexOf("[endif")!=-1)this.tag_type="END",this.unindent();else if(l.indexOf("[cdata[")!=-1){var c=this.get_unformatted("]]>",a);n.push(c),this.tag_type="SINGLE"}else{var c=this.get_unformatted("-->",a);n.push(c),this.tag_type="SINGLE"}else"/"===l.charAt(0)?(this.retrieve_tag(l.substring(1)),this.tag_type="END"):(this.record_tag(l),this.tag_type="START"),this.Utils.in_array(l,this.Utils.extra_liners)&&this.print_newline(!0,this.output);return n.join("")},this.get_unformatted=function(e,t){if(t&&t.toLowerCase().indexOf(e)!=-1)return"";var r="",n="",i=!0;do{if(this.pos>=this.input.length)return n;if(r=this.input.charAt(this.pos),this.pos++,this.Utils.in_array(r,this.Utils.whitespace)){if(!i){this.line_char_count--;continue}if("\n"===r||"\r"===r){n+="\n",this.line_char_count=0;continue}}n+=r,this.line_char_count++,i=!0}while(n.toLowerCase().indexOf(e)==-1);return n},this.get_token=function(){var e;if("TK_TAG_SCRIPT"===this.last_token||"TK_TAG_STYLE"===this.last_token){var t=this.last_token.substr(7);return e=this.get_contents_to(t),"string"!=typeof e?e:[e,"TK_"+t]}if("CONTENT"===this.current_mode)return e=this.get_content(),"string"!=typeof e?e:[e,"TK_CONTENT"];if("TAG"===this.current_mode){if("string"!=typeof(e=this.get_tag()))return e;return[e,"TK_TAG_"+this.tag_type]}},this.get_full_indent=function(e){return e=this.indent_level+e||0,e<1?"":Array(e+1).join(this.indent_string)},this.printer=function(e,t,r,n,i){this.input=e||"",this.output=[],this.indent_character=t,this.indent_string="",this.indent_size=r,this.brace_style=i,this.indent_level=0,this.max_char=n,this.line_char_count=0;for(var o=0;o<this.indent_size;o++)this.indent_string+=this.indent_character;this.print_newline=function(e,t){if(this.line_char_count=0,t&&t.length){if(!e)for(;this.Utils.in_array(t[t.length-1],this.Utils.whitespace);)t.pop();t.push("\n");for(var r=0;r<this.indent_level;r++)t.pu