\";\n return div.innerHTML.indexOf('
') > 0;\n} // #3663: IE encodes newlines inside attribute values while other browsers don't\n\n\nvar shouldDecodeNewlines = inBrowser ? getShouldDecode(false) : false; // #6828: chrome encodes content in a[href]\n\nvar shouldDecodeNewlinesForHref = inBrowser ? getShouldDecode(true) : false;\n/* */\n\nvar idToTemplate = cached(function (id) {\n var el = query(id);\n return el && el.innerHTML;\n});\nvar mount = Vue.prototype.$mount;\n\nVue.prototype.$mount = function (el, hydrating) {\n el = el && query(el);\n /* istanbul ignore if */\n\n if (el === document.body || el === document.documentElement) {\n process.env.NODE_ENV !== 'production' && warn(\"Do not mount Vue to or - mount to normal elements instead.\");\n return this;\n }\n\n var options = this.$options; // resolve template/el and convert to render function\n\n if (!options.render) {\n var template = options.template;\n\n if (template) {\n if (typeof template === 'string') {\n if (template.charAt(0) === '#') {\n template = idToTemplate(template);\n /* istanbul ignore if */\n\n if (process.env.NODE_ENV !== 'production' && !template) {\n warn(\"Template element not found or is empty: \" + options.template, this);\n }\n }\n } else if (template.nodeType) {\n template = template.innerHTML;\n } else {\n if (process.env.NODE_ENV !== 'production') {\n warn('invalid template option:' + template, this);\n }\n\n return this;\n }\n } else if (el) {\n template = getOuterHTML(el);\n }\n\n if (template) {\n /* istanbul ignore if */\n if (process.env.NODE_ENV !== 'production' && config.performance && mark) {\n mark('compile');\n }\n\n var ref = compileToFunctions(template, {\n outputSourceRange: process.env.NODE_ENV !== 'production',\n shouldDecodeNewlines: shouldDecodeNewlines,\n shouldDecodeNewlinesForHref: shouldDecodeNewlinesForHref,\n delimiters: options.delimiters,\n comments: options.comments\n }, this);\n var render = ref.render;\n var staticRenderFns = ref.staticRenderFns;\n options.render = render;\n options.staticRenderFns = staticRenderFns;\n /* istanbul ignore if */\n\n if (process.env.NODE_ENV !== 'production' && config.performance && mark) {\n mark('compile end');\n measure(\"vue \" + this._name + \" compile\", 'compile', 'compile end');\n }\n }\n }\n\n return mount.call(this, el, hydrating);\n};\n/**\n * Get outerHTML of elements, taking care\n * of SVG elements in IE as well.\n */\n\n\nfunction getOuterHTML(el) {\n if (el.outerHTML) {\n return el.outerHTML;\n } else {\n var container = document.createElement('div');\n container.appendChild(el.cloneNode(true));\n return container.innerHTML;\n }\n}\n\nVue.compile = compileToFunctions;\nexport default Vue;","export default {\n data: function data() {\n return {\n inputClasses: 'appearance-none inline-flex bg-gray-200 disabled:bg-gray-400 disabled:cursor-not-allowed focus:bg-white text-gray-700 disabled:text-gray-600 rounded-md py-3 px-3 leading-tight border border-gray-300 outline-none focus:border-gray-400 outline'\n };\n }\n};","import isNull from 'lodash/isNull';\nimport isUndefined from 'lodash/isUndefined';\nexport default {\n data: function data() {\n return {\n value: ''\n };\n },\n props: {\n field: {},\n resourceName: {},\n resourceId: {},\n index: {\n type: Number\n },\n errors: {\n type: Object,\n \"default\": function _default() {\n return {};\n }\n },\n displayedIn: {\n \"default\": function _default() {\n return 'form';\n }\n }\n },\n computed: {\n disabled: function disabled() {\n return this.field.readonly;\n },\n fieldError: function fieldError() {\n if (!this.hasErrors) return '';\n return \"\".concat(this.field.id, \" \").concat(this.errors[this.field.id].join(', '));\n },\n hasErrors: function hasErrors() {\n if (isUndefined(this.errors) || isNull(this.errors) || Object.keys(this.errors).length === 0) return false;\n return !isUndefined(this.errors[this.field.id]);\n }\n },\n methods: {\n setInitialConfig: function setInitialConfig() {},\n setInitialValue: function setInitialValue() {\n this.value = this.field.value;\n },\n getValue: function getValue() {\n return this.value;\n },\n getId: function getId() {\n return this.field.id;\n },\n focus: function focus() {\n if (this.$refs['field-input']) this.$refs['field-input'].focus();\n }\n },\n created: function created() {\n this.setInitialConfig();\n },\n mounted: function mounted() {\n this.setInitialValue();\n this.field.getId = this.getId;\n this.field.getValue = this.getValue;\n\n if (this.index === 0) {\n this.focus();\n }\n }\n};","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: https://codemirror.net/LICENSE\n// This is CodeMirror (https://codemirror.net), a code editor\n// implemented in JavaScript on top of the browser's DOM.\n//\n// You can find some technical background for some of the code below\n// at http://marijnhaverbeke.nl/blog/#cm-internals .\n(function (global, factory) {\n (typeof exports === \"undefined\" ? \"undefined\" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.CodeMirror = factory());\n})(this, function () {\n 'use strict'; // Kludges for bugs and behavior differences that can't be feature\n // detected are enabled based on userAgent etc sniffing.\n\n var userAgent = navigator.userAgent;\n var platform = navigator.platform;\n var gecko = /gecko\\/\\d/i.test(userAgent);\n var ie_upto10 = /MSIE \\d/.test(userAgent);\n var ie_11up = /Trident\\/(?:[7-9]|\\d{2,})\\..*rv:(\\d+)/.exec(userAgent);\n var edge = /Edge\\/(\\d+)/.exec(userAgent);\n var ie = ie_upto10 || ie_11up || edge;\n var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);\n var webkit = !edge && /WebKit\\//.test(userAgent);\n var qtwebkit = webkit && /Qt\\/\\d+\\.\\d+/.test(userAgent);\n var chrome = !edge && /Chrome\\//.test(userAgent);\n var presto = /Opera\\//.test(userAgent);\n var safari = /Apple Computer/.test(navigator.vendor);\n var mac_geMountainLion = /Mac OS X 1\\d\\D([8-9]|\\d\\d)\\D/.test(userAgent);\n var phantom = /PhantomJS/.test(userAgent);\n var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\\/\\w+/.test(userAgent);\n var android = /Android/.test(userAgent); // This is woefully incomplete. Suggestions for alternative methods welcome.\n\n var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);\n var mac = ios || /Mac/.test(platform);\n var chromeOS = /\\bCrOS\\b/.test(userAgent);\n var windows = /win/i.test(platform);\n var presto_version = presto && userAgent.match(/Version\\/(\\d*\\.\\d*)/);\n\n if (presto_version) {\n presto_version = Number(presto_version[1]);\n }\n\n if (presto_version && presto_version >= 15) {\n presto = false;\n webkit = true;\n } // Some browsers use the wrong event properties to signal cmd/ctrl on OS X\n\n\n var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));\n var captureRightClick = gecko || ie && ie_version >= 9;\n\n function classTest(cls) {\n return new RegExp(\"(^|\\\\s)\" + cls + \"(?:$|\\\\s)\\\\s*\");\n }\n\n var rmClass = function rmClass(node, cls) {\n var current = node.className;\n var match = classTest(cls).exec(current);\n\n if (match) {\n var after = current.slice(match.index + match[0].length);\n node.className = current.slice(0, match.index) + (after ? match[1] + after : \"\");\n }\n };\n\n function removeChildren(e) {\n for (var count = e.childNodes.length; count > 0; --count) {\n e.removeChild(e.firstChild);\n }\n\n return e;\n }\n\n function removeChildrenAndAdd(parent, e) {\n return removeChildren(parent).appendChild(e);\n }\n\n function elt(tag, content, className, style) {\n var e = document.createElement(tag);\n\n if (className) {\n e.className = className;\n }\n\n if (style) {\n e.style.cssText = style;\n }\n\n if (typeof content == \"string\") {\n e.appendChild(document.createTextNode(content));\n } else if (content) {\n for (var i = 0; i < content.length; ++i) {\n e.appendChild(content[i]);\n }\n }\n\n return e;\n } // wrapper for elt, which removes the elt from the accessibility tree\n\n\n function eltP(tag, content, className, style) {\n var e = elt(tag, content, className, style);\n e.setAttribute(\"role\", \"presentation\");\n return e;\n }\n\n var range;\n\n if (document.createRange) {\n range = function range(node, start, end, endNode) {\n var r = document.createRange();\n r.setEnd(endNode || node, end);\n r.setStart(node, start);\n return r;\n };\n } else {\n range = function range(node, start, end) {\n var r = document.body.createTextRange();\n\n try {\n r.moveToElementText(node.parentNode);\n } catch (e) {\n return r;\n }\n\n r.collapse(true);\n r.moveEnd(\"character\", end);\n r.moveStart(\"character\", start);\n return r;\n };\n }\n\n function contains(parent, child) {\n if (child.nodeType == 3) // Android browser always returns false when child is a textnode\n {\n child = child.parentNode;\n }\n\n if (parent.contains) {\n return parent.contains(child);\n }\n\n do {\n if (child.nodeType == 11) {\n child = child.host;\n }\n\n if (child == parent) {\n return true;\n }\n } while (child = child.parentNode);\n }\n\n function activeElt() {\n // IE and Edge may throw an \"Unspecified Error\" when accessing document.activeElement.\n // IE < 10 will throw when accessed while the page is loading or in an iframe.\n // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.\n var activeElement;\n\n try {\n activeElement = document.activeElement;\n } catch (e) {\n activeElement = document.body || null;\n }\n\n while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) {\n activeElement = activeElement.shadowRoot.activeElement;\n }\n\n return activeElement;\n }\n\n function addClass(node, cls) {\n var current = node.className;\n\n if (!classTest(cls).test(current)) {\n node.className += (current ? \" \" : \"\") + cls;\n }\n }\n\n function joinClasses(a, b) {\n var as = a.split(\" \");\n\n for (var i = 0; i < as.length; i++) {\n if (as[i] && !classTest(as[i]).test(b)) {\n b += \" \" + as[i];\n }\n }\n\n return b;\n }\n\n var selectInput = function selectInput(node) {\n node.select();\n };\n\n if (ios) // Mobile Safari apparently has a bug where select() is broken.\n {\n selectInput = function selectInput(node) {\n node.selectionStart = 0;\n node.selectionEnd = node.value.length;\n };\n } else if (ie) // Suppress mysterious IE10 errors\n {\n selectInput = function selectInput(node) {\n try {\n node.select();\n } catch (_e) {}\n };\n }\n\n function bind(f) {\n var args = Array.prototype.slice.call(arguments, 1);\n return function () {\n return f.apply(null, args);\n };\n }\n\n function copyObj(obj, target, overwrite) {\n if (!target) {\n target = {};\n }\n\n for (var prop in obj) {\n if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop))) {\n target[prop] = obj[prop];\n }\n }\n\n return target;\n } // Counts the column offset in a string, taking tabs into account.\n // Used mostly to find indentation.\n\n\n function countColumn(string, end, tabSize, startIndex, startValue) {\n if (end == null) {\n end = string.search(/[^\\s\\u00a0]/);\n\n if (end == -1) {\n end = string.length;\n }\n }\n\n for (var i = startIndex || 0, n = startValue || 0;;) {\n var nextTab = string.indexOf(\"\\t\", i);\n\n if (nextTab < 0 || nextTab >= end) {\n return n + (end - i);\n }\n\n n += nextTab - i;\n n += tabSize - n % tabSize;\n i = nextTab + 1;\n }\n }\n\n var Delayed = function Delayed() {\n this.id = null;\n this.f = null;\n this.time = 0;\n this.handler = bind(this.onTimeout, this);\n };\n\n Delayed.prototype.onTimeout = function (self) {\n self.id = 0;\n\n if (self.time <= +new Date()) {\n self.f();\n } else {\n setTimeout(self.handler, self.time - +new Date());\n }\n };\n\n Delayed.prototype.set = function (ms, f) {\n this.f = f;\n var time = +new Date() + ms;\n\n if (!this.id || time < this.time) {\n clearTimeout(this.id);\n this.id = setTimeout(this.handler, ms);\n this.time = time;\n }\n };\n\n function indexOf(array, elt) {\n for (var i = 0; i < array.length; ++i) {\n if (array[i] == elt) {\n return i;\n }\n }\n\n return -1;\n } // Number of pixels added to scroller and sizer to hide scrollbar\n\n\n var scrollerGap = 50; // Returned or thrown by various protocols to signal 'I'm not\n // handling this'.\n\n var Pass = {\n toString: function toString() {\n return \"CodeMirror.Pass\";\n }\n }; // Reused option objects for setSelection & friends\n\n var sel_dontScroll = {\n scroll: false\n },\n sel_mouse = {\n origin: \"*mouse\"\n },\n sel_move = {\n origin: \"+move\"\n }; // The inverse of countColumn -- find the offset that corresponds to\n // a particular column.\n\n function findColumn(string, goal, tabSize) {\n for (var pos = 0, col = 0;;) {\n var nextTab = string.indexOf(\"\\t\", pos);\n\n if (nextTab == -1) {\n nextTab = string.length;\n }\n\n var skipped = nextTab - pos;\n\n if (nextTab == string.length || col + skipped >= goal) {\n return pos + Math.min(skipped, goal - col);\n }\n\n col += nextTab - pos;\n col += tabSize - col % tabSize;\n pos = nextTab + 1;\n\n if (col >= goal) {\n return pos;\n }\n }\n }\n\n var spaceStrs = [\"\"];\n\n function spaceStr(n) {\n while (spaceStrs.length <= n) {\n spaceStrs.push(lst(spaceStrs) + \" \");\n }\n\n return spaceStrs[n];\n }\n\n function lst(arr) {\n return arr[arr.length - 1];\n }\n\n function map(array, f) {\n var out = [];\n\n for (var i = 0; i < array.length; i++) {\n out[i] = f(array[i], i);\n }\n\n return out;\n }\n\n function insertSorted(array, value, score) {\n var pos = 0,\n priority = score(value);\n\n while (pos < array.length && score(array[pos]) <= priority) {\n pos++;\n }\n\n array.splice(pos, 0, value);\n }\n\n function nothing() {}\n\n function createObj(base, props) {\n var inst;\n\n if (Object.create) {\n inst = Object.create(base);\n } else {\n nothing.prototype = base;\n inst = new nothing();\n }\n\n if (props) {\n copyObj(props, inst);\n }\n\n return inst;\n }\n\n var nonASCIISingleCaseWordChar = /[\\u00df\\u0587\\u0590-\\u05f4\\u0600-\\u06ff\\u3040-\\u309f\\u30a0-\\u30ff\\u3400-\\u4db5\\u4e00-\\u9fcc\\uac00-\\ud7af]/;\n\n function isWordCharBasic(ch) {\n return /\\w/.test(ch) || ch > \"\\x80\" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));\n }\n\n function isWordChar(ch, helper) {\n if (!helper) {\n return isWordCharBasic(ch);\n }\n\n if (helper.source.indexOf(\"\\\\w\") > -1 && isWordCharBasic(ch)) {\n return true;\n }\n\n return helper.test(ch);\n }\n\n function isEmpty(obj) {\n for (var n in obj) {\n if (obj.hasOwnProperty(n) && obj[n]) {\n return false;\n }\n }\n\n return true;\n } // Extending unicode characters. A series of a non-extending char +\n // any number of extending chars is treated as a single unit as far\n // as editing and measuring is concerned. This is not fully correct,\n // since some scripts/fonts/browsers also treat other configurations\n // of code points as a group.\n\n\n 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]/;\n\n function isExtendingChar(ch) {\n return ch.charCodeAt(0) >= 768 && extendingChars.test(ch);\n } // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.\n\n\n function skipExtendingChars(str, pos, dir) {\n while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) {\n pos += dir;\n }\n\n return pos;\n } // Returns the value from the range [`from`; `to`] that satisfies\n // `pred` and is closest to `from`. Assumes that at least `to`\n // satisfies `pred`. Supports `from` being greater than `to`.\n\n\n function findFirst(pred, from, to) {\n // At any point we are certain `to` satisfies `pred`, don't know\n // whether `from` does.\n var dir = from > to ? -1 : 1;\n\n for (;;) {\n if (from == to) {\n return from;\n }\n\n var midF = (from + to) / 2,\n mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);\n\n if (mid == from) {\n return pred(mid) ? from : to;\n }\n\n if (pred(mid)) {\n to = mid;\n } else {\n from = mid + dir;\n }\n }\n } // BIDI HELPERS\n\n\n function iterateBidiSections(order, from, to, f) {\n if (!order) {\n return f(from, to, \"ltr\", 0);\n }\n\n var found = false;\n\n for (var i = 0; i < order.length; ++i) {\n var part = order[i];\n\n if (part.from < to && part.to > from || from == to && part.to == from) {\n f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? \"rtl\" : \"ltr\", i);\n found = true;\n }\n }\n\n if (!found) {\n f(from, to, \"ltr\");\n }\n }\n\n var bidiOther = null;\n\n function getBidiPartAt(order, ch, sticky) {\n var found;\n bidiOther = null;\n\n for (var i = 0; i < order.length; ++i) {\n var cur = order[i];\n\n if (cur.from < ch && cur.to > ch) {\n return i;\n }\n\n if (cur.to == ch) {\n if (cur.from != cur.to && sticky == \"before\") {\n found = i;\n } else {\n bidiOther = i;\n }\n }\n\n if (cur.from == ch) {\n if (cur.from != cur.to && sticky != \"before\") {\n found = i;\n } else {\n bidiOther = i;\n }\n }\n }\n\n return found != null ? found : bidiOther;\n } // Bidirectional ordering algorithm\n // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm\n // that this (partially) implements.\n // One-char codes used for character types:\n // L (L): Left-to-Right\n // R (R): Right-to-Left\n // r (AL): Right-to-Left Arabic\n // 1 (EN): European Number\n // + (ES): European Number Separator\n // % (ET): European Number Terminator\n // n (AN): Arabic Number\n // , (CS): Common Number Separator\n // m (NSM): Non-Spacing Mark\n // b (BN): Boundary Neutral\n // s (B): Paragraph Separator\n // t (S): Segment Separator\n // w (WS): Whitespace\n // N (ON): Other Neutrals\n // Returns null if characters are ordered as they appear\n // (left-to-right), or an array of sections ({from, to, level}\n // objects) in the order in which they occur visually.\n\n\n var bidiOrdering = function () {\n // Character types for codepoints 0 to 0xff\n var lowTypes = \"bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN\"; // Character types for codepoints 0x600 to 0x6f9\n\n var arabicTypes = \"nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111\";\n\n function charType(code) {\n if (code <= 0xf7) {\n return lowTypes.charAt(code);\n } else if (0x590 <= code && code <= 0x5f4) {\n return \"R\";\n } else if (0x600 <= code && code <= 0x6f9) {\n return arabicTypes.charAt(code - 0x600);\n } else if (0x6ee <= code && code <= 0x8ac) {\n return \"r\";\n } else if (0x2000 <= code && code <= 0x200b) {\n return \"w\";\n } else if (code == 0x200c) {\n return \"b\";\n } else {\n return \"L\";\n }\n }\n\n var bidiRE = /[\\u0590-\\u05f4\\u0600-\\u06ff\\u0700-\\u08ac]/;\n var isNeutral = /[stwN]/,\n isStrong = /[LRr]/,\n countsAsLeft = /[Lb1n]/,\n countsAsNum = /[1n]/;\n\n function BidiSpan(level, from, to) {\n this.level = level;\n this.from = from;\n this.to = to;\n }\n\n return function (str, direction) {\n var outerType = direction == \"ltr\" ? \"L\" : \"R\";\n\n if (str.length == 0 || direction == \"ltr\" && !bidiRE.test(str)) {\n return false;\n }\n\n var len = str.length,\n types = [];\n\n for (var i = 0; i < len; ++i) {\n types.push(charType(str.charCodeAt(i)));\n } // W1. Examine each non-spacing mark (NSM) in the level run, and\n // change the type of the NSM to the type of the previous\n // character. If the NSM is at the start of the level run, it will\n // get the type of sor.\n\n\n for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {\n var type = types[i$1];\n\n if (type == \"m\") {\n types[i$1] = prev;\n } else {\n prev = type;\n }\n } // W2. Search backwards from each instance of a European number\n // until the first strong type (R, L, AL, or sor) is found. If an\n // AL is found, change the type of the European number to Arabic\n // number.\n // W3. Change all ALs to R.\n\n\n for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {\n var type$1 = types[i$2];\n\n if (type$1 == \"1\" && cur == \"r\") {\n types[i$2] = \"n\";\n } else if (isStrong.test(type$1)) {\n cur = type$1;\n\n if (type$1 == \"r\") {\n types[i$2] = \"R\";\n }\n }\n } // W4. A single European separator between two European numbers\n // changes to a European number. A single common separator between\n // two numbers of the same type changes to that type.\n\n\n for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {\n var type$2 = types[i$3];\n\n if (type$2 == \"+\" && prev$1 == \"1\" && types[i$3 + 1] == \"1\") {\n types[i$3] = \"1\";\n } else if (type$2 == \",\" && prev$1 == types[i$3 + 1] && (prev$1 == \"1\" || prev$1 == \"n\")) {\n types[i$3] = prev$1;\n }\n\n prev$1 = type$2;\n } // W5. A sequence of European terminators adjacent to European\n // numbers changes to all European numbers.\n // W6. Otherwise, separators and terminators change to Other\n // Neutral.\n\n\n for (var i$4 = 0; i$4 < len; ++i$4) {\n var type$3 = types[i$4];\n\n if (type$3 == \",\") {\n types[i$4] = \"N\";\n } else if (type$3 == \"%\") {\n var end = void 0;\n\n for (end = i$4 + 1; end < len && types[end] == \"%\"; ++end) {}\n\n var replace = i$4 && types[i$4 - 1] == \"!\" || end < len && types[end] == \"1\" ? \"1\" : \"N\";\n\n for (var j = i$4; j < end; ++j) {\n types[j] = replace;\n }\n\n i$4 = end - 1;\n }\n } // W7. Search backwards from each instance of a European number\n // until the first strong type (R, L, or sor) is found. If an L is\n // found, then change the type of the European number to L.\n\n\n for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {\n var type$4 = types[i$5];\n\n if (cur$1 == \"L\" && type$4 == \"1\") {\n types[i$5] = \"L\";\n } else if (isStrong.test(type$4)) {\n cur$1 = type$4;\n }\n } // N1. A sequence of neutrals takes the direction of the\n // surrounding strong text if the text on both sides has the same\n // direction. European and Arabic numbers act as if they were R in\n // terms of their influence on neutrals. Start-of-level-run (sor)\n // and end-of-level-run (eor) are used at level run boundaries.\n // N2. Any remaining neutrals take the embedding direction.\n\n\n for (var i$6 = 0; i$6 < len; ++i$6) {\n if (isNeutral.test(types[i$6])) {\n var end$1 = void 0;\n\n for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}\n\n var before = (i$6 ? types[i$6 - 1] : outerType) == \"L\";\n var after = (end$1 < len ? types[end$1] : outerType) == \"L\";\n var replace$1 = before == after ? before ? \"L\" : \"R\" : outerType;\n\n for (var j$1 = i$6; j$1 < end$1; ++j$1) {\n types[j$1] = replace$1;\n }\n\n i$6 = end$1 - 1;\n }\n } // Here we depart from the documented algorithm, in order to avoid\n // building up an actual levels array. Since there are only three\n // levels (0, 1, 2) in an implementation that doesn't take\n // explicit embedding into account, we can build up the order on\n // the fly, without following the level-based algorithm.\n\n\n var order = [],\n m;\n\n for (var i$7 = 0; i$7 < len;) {\n if (countsAsLeft.test(types[i$7])) {\n var start = i$7;\n\n for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}\n\n order.push(new BidiSpan(0, start, i$7));\n } else {\n var pos = i$7,\n at = order.length,\n isRTL = direction == \"rtl\" ? 1 : 0;\n\n for (++i$7; i$7 < len && types[i$7] != \"L\"; ++i$7) {}\n\n for (var j$2 = pos; j$2 < i$7;) {\n if (countsAsNum.test(types[j$2])) {\n if (pos < j$2) {\n order.splice(at, 0, new BidiSpan(1, pos, j$2));\n at += isRTL;\n }\n\n var nstart = j$2;\n\n for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}\n\n order.splice(at, 0, new BidiSpan(2, nstart, j$2));\n at += isRTL;\n pos = j$2;\n } else {\n ++j$2;\n }\n }\n\n if (pos < i$7) {\n order.splice(at, 0, new BidiSpan(1, pos, i$7));\n }\n }\n }\n\n if (direction == \"ltr\") {\n if (order[0].level == 1 && (m = str.match(/^\\s+/))) {\n order[0].from = m[0].length;\n order.unshift(new BidiSpan(0, 0, m[0].length));\n }\n\n if (lst(order).level == 1 && (m = str.match(/\\s+$/))) {\n lst(order).to -= m[0].length;\n order.push(new BidiSpan(0, len - m[0].length, len));\n }\n }\n\n return direction == \"rtl\" ? order.reverse() : order;\n };\n }(); // Get the bidi ordering for the given line (and cache it). Returns\n // false for lines that are fully left-to-right, and an array of\n // BidiSpan objects otherwise.\n\n\n function getOrder(line, direction) {\n var order = line.order;\n\n if (order == null) {\n order = line.order = bidiOrdering(line.text, direction);\n }\n\n return order;\n } // EVENT HANDLING\n // Lightweight event framework. on/off also work on DOM nodes,\n // registering native DOM handlers.\n\n\n var noHandlers = [];\n\n var on = function on(emitter, type, f) {\n if (emitter.addEventListener) {\n emitter.addEventListener(type, f, false);\n } else if (emitter.attachEvent) {\n emitter.attachEvent(\"on\" + type, f);\n } else {\n var map = emitter._handlers || (emitter._handlers = {});\n map[type] = (map[type] || noHandlers).concat(f);\n }\n };\n\n function getHandlers(emitter, type) {\n return emitter._handlers && emitter._handlers[type] || noHandlers;\n }\n\n function off(emitter, type, f) {\n if (emitter.removeEventListener) {\n emitter.removeEventListener(type, f, false);\n } else if (emitter.detachEvent) {\n emitter.detachEvent(\"on\" + type, f);\n } else {\n var map = emitter._handlers,\n arr = map && map[type];\n\n if (arr) {\n var index = indexOf(arr, f);\n\n if (index > -1) {\n map[type] = arr.slice(0, index).concat(arr.slice(index + 1));\n }\n }\n }\n }\n\n function signal(emitter, type\n /*, values...*/\n ) {\n var handlers = getHandlers(emitter, type);\n\n if (!handlers.length) {\n return;\n }\n\n var args = Array.prototype.slice.call(arguments, 2);\n\n for (var i = 0; i < handlers.length; ++i) {\n handlers[i].apply(null, args);\n }\n } // The DOM events that CodeMirror handles can be overridden by\n // registering a (non-DOM) handler on the editor for the event name,\n // and preventDefault-ing the event in that handler.\n\n\n function signalDOMEvent(cm, e, override) {\n if (typeof e == \"string\") {\n e = {\n type: e,\n preventDefault: function preventDefault() {\n this.defaultPrevented = true;\n }\n };\n }\n\n signal(cm, override || e.type, cm, e);\n return e_defaultPrevented(e) || e.codemirrorIgnore;\n }\n\n function signalCursorActivity(cm) {\n var arr = cm._handlers && cm._handlers.cursorActivity;\n\n if (!arr) {\n return;\n }\n\n var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);\n\n for (var i = 0; i < arr.length; ++i) {\n if (indexOf(set, arr[i]) == -1) {\n set.push(arr[i]);\n }\n }\n }\n\n function hasHandler(emitter, type) {\n return getHandlers(emitter, type).length > 0;\n } // Add on and off methods to a constructor's prototype, to make\n // registering events on such objects more convenient.\n\n\n function eventMixin(ctor) {\n ctor.prototype.on = function (type, f) {\n on(this, type, f);\n };\n\n ctor.prototype.off = function (type, f) {\n off(this, type, f);\n };\n } // Due to the fact that we still support jurassic IE versions, some\n // compatibility wrappers are needed.\n\n\n function e_preventDefault(e) {\n if (e.preventDefault) {\n e.preventDefault();\n } else {\n e.returnValue = false;\n }\n }\n\n function e_stopPropagation(e) {\n if (e.stopPropagation) {\n e.stopPropagation();\n } else {\n e.cancelBubble = true;\n }\n }\n\n function e_defaultPrevented(e) {\n return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;\n }\n\n function e_stop(e) {\n e_preventDefault(e);\n e_stopPropagation(e);\n }\n\n function e_target(e) {\n return e.target || e.srcElement;\n }\n\n function e_button(e) {\n var b = e.which;\n\n if (b == null) {\n if (e.button & 1) {\n b = 1;\n } else if (e.button & 2) {\n b = 3;\n } else if (e.button & 4) {\n b = 2;\n }\n }\n\n if (mac && e.ctrlKey && b == 1) {\n b = 3;\n }\n\n return b;\n } // Detect drag-and-drop\n\n\n var dragAndDrop = function () {\n // There is *some* kind of drag-and-drop support in IE6-8, but I\n // couldn't get it to work yet.\n if (ie && ie_version < 9) {\n return false;\n }\n\n var div = elt('div');\n return \"draggable\" in div || \"dragDrop\" in div;\n }();\n\n var zwspSupported;\n\n function zeroWidthElement(measure) {\n if (zwspSupported == null) {\n var test = elt(\"span\", \"\\u200B\");\n removeChildrenAndAdd(measure, elt(\"span\", [test, document.createTextNode(\"x\")]));\n\n if (measure.firstChild.offsetHeight != 0) {\n zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);\n }\n }\n\n var node = zwspSupported ? elt(\"span\", \"\\u200B\") : elt(\"span\", \"\\xA0\", null, \"display: inline-block; width: 1px; margin-right: -1px\");\n node.setAttribute(\"cm-text\", \"\");\n return node;\n } // Feature-detect IE's crummy client rect reporting for bidi text\n\n\n var badBidiRects;\n\n function hasBadBidiRects(measure) {\n if (badBidiRects != null) {\n return badBidiRects;\n }\n\n var txt = removeChildrenAndAdd(measure, document.createTextNode(\"A\\u062EA\"));\n var r0 = range(txt, 0, 1).getBoundingClientRect();\n var r1 = range(txt, 1, 2).getBoundingClientRect();\n removeChildren(measure);\n\n if (!r0 || r0.left == r0.right) {\n return false;\n } // Safari returns null in some cases (#2780)\n\n\n return badBidiRects = r1.right - r0.right < 3;\n } // See if \"\".split is the broken IE version, if so, provide an\n // alternative way to split lines.\n\n\n var splitLinesAuto = \"\\n\\nb\".split(/\\n/).length != 3 ? function (string) {\n var pos = 0,\n result = [],\n l = string.length;\n\n while (pos <= l) {\n var nl = string.indexOf(\"\\n\", pos);\n\n if (nl == -1) {\n nl = string.length;\n }\n\n var line = string.slice(pos, string.charAt(nl - 1) == \"\\r\" ? nl - 1 : nl);\n var rt = line.indexOf(\"\\r\");\n\n if (rt != -1) {\n result.push(line.slice(0, rt));\n pos += rt + 1;\n } else {\n result.push(line);\n pos = nl + 1;\n }\n }\n\n return result;\n } : function (string) {\n return string.split(/\\r\\n?|\\n/);\n };\n var hasSelection = window.getSelection ? function (te) {\n try {\n return te.selectionStart != te.selectionEnd;\n } catch (e) {\n return false;\n }\n } : function (te) {\n var range;\n\n try {\n range = te.ownerDocument.selection.createRange();\n } catch (e) {}\n\n if (!range || range.parentElement() != te) {\n return false;\n }\n\n return range.compareEndPoints(\"StartToEnd\", range) != 0;\n };\n\n var hasCopyEvent = function () {\n var e = elt(\"div\");\n\n if (\"oncopy\" in e) {\n return true;\n }\n\n e.setAttribute(\"oncopy\", \"return;\");\n return typeof e.oncopy == \"function\";\n }();\n\n var badZoomedRects = null;\n\n function hasBadZoomedRects(measure) {\n if (badZoomedRects != null) {\n return badZoomedRects;\n }\n\n var node = removeChildrenAndAdd(measure, elt(\"span\", \"x\"));\n var normal = node.getBoundingClientRect();\n var fromRange = range(node, 0, 1).getBoundingClientRect();\n return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;\n } // Known modes, by name and by MIME\n\n\n var modes = {},\n mimeModes = {}; // Extra arguments are stored as the mode's dependencies, which is\n // used by (legacy) mechanisms like loadmode.js to automatically\n // load a mode. (Preferred mechanism is the require/define calls.)\n\n function defineMode(name, mode) {\n if (arguments.length > 2) {\n mode.dependencies = Array.prototype.slice.call(arguments, 2);\n }\n\n modes[name] = mode;\n }\n\n function defineMIME(mime, spec) {\n mimeModes[mime] = spec;\n } // Given a MIME type, a {name, ...options} config object, or a name\n // string, return a mode config object.\n\n\n function resolveMode(spec) {\n if (typeof spec == \"string\" && mimeModes.hasOwnProperty(spec)) {\n spec = mimeModes[spec];\n } else if (spec && typeof spec.name == \"string\" && mimeModes.hasOwnProperty(spec.name)) {\n var found = mimeModes[spec.name];\n\n if (typeof found == \"string\") {\n found = {\n name: found\n };\n }\n\n spec = createObj(found, spec);\n spec.name = found.name;\n } else if (typeof spec == \"string\" && /^[\\w\\-]+\\/[\\w\\-]+\\+xml$/.test(spec)) {\n return resolveMode(\"application/xml\");\n } else if (typeof spec == \"string\" && /^[\\w\\-]+\\/[\\w\\-]+\\+json$/.test(spec)) {\n return resolveMode(\"application/json\");\n }\n\n if (typeof spec == \"string\") {\n return {\n name: spec\n };\n } else {\n return spec || {\n name: \"null\"\n };\n }\n } // Given a mode spec (anything that resolveMode accepts), find and\n // initialize an actual mode object.\n\n\n function getMode(options, spec) {\n spec = resolveMode(spec);\n var mfactory = modes[spec.name];\n\n if (!mfactory) {\n return getMode(options, \"text/plain\");\n }\n\n var modeObj = mfactory(options, spec);\n\n if (modeExtensions.hasOwnProperty(spec.name)) {\n var exts = modeExtensions[spec.name];\n\n for (var prop in exts) {\n if (!exts.hasOwnProperty(prop)) {\n continue;\n }\n\n if (modeObj.hasOwnProperty(prop)) {\n modeObj[\"_\" + prop] = modeObj[prop];\n }\n\n modeObj[prop] = exts[prop];\n }\n }\n\n modeObj.name = spec.name;\n\n if (spec.helperType) {\n modeObj.helperType = spec.helperType;\n }\n\n if (spec.modeProps) {\n for (var prop$1 in spec.modeProps) {\n modeObj[prop$1] = spec.modeProps[prop$1];\n }\n }\n\n return modeObj;\n } // This can be used to attach properties to mode objects from\n // outside the actual mode definition.\n\n\n var modeExtensions = {};\n\n function extendMode(mode, properties) {\n var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : modeExtensions[mode] = {};\n copyObj(properties, exts);\n }\n\n function copyState(mode, state) {\n if (state === true) {\n return state;\n }\n\n if (mode.copyState) {\n return mode.copyState(state);\n }\n\n var nstate = {};\n\n for (var n in state) {\n var val = state[n];\n\n if (val instanceof Array) {\n val = val.concat([]);\n }\n\n nstate[n] = val;\n }\n\n return nstate;\n } // Given a mode and a state (for that mode), find the inner mode and\n // state at the position that the state refers to.\n\n\n function innerMode(mode, state) {\n var info;\n\n while (mode.innerMode) {\n info = mode.innerMode(state);\n\n if (!info || info.mode == mode) {\n break;\n }\n\n state = info.state;\n mode = info.mode;\n }\n\n return info || {\n mode: mode,\n state: state\n };\n }\n\n function startState(mode, a1, a2) {\n return mode.startState ? mode.startState(a1, a2) : true;\n } // STRING STREAM\n // Fed to the mode parsers, provides helper functions to make\n // parsers more succinct.\n\n\n var StringStream = function StringStream(string, tabSize, lineOracle) {\n this.pos = this.start = 0;\n this.string = string;\n this.tabSize = tabSize || 8;\n this.lastColumnPos = this.lastColumnValue = 0;\n this.lineStart = 0;\n this.lineOracle = lineOracle;\n };\n\n StringStream.prototype.eol = function () {\n return this.pos >= this.string.length;\n };\n\n StringStream.prototype.sol = function () {\n return this.pos == this.lineStart;\n };\n\n StringStream.prototype.peek = function () {\n return this.string.charAt(this.pos) || undefined;\n };\n\n StringStream.prototype.next = function () {\n if (this.pos < this.string.length) {\n return this.string.charAt(this.pos++);\n }\n };\n\n StringStream.prototype.eat = function (match) {\n var ch = this.string.charAt(this.pos);\n var ok;\n\n if (typeof match == \"string\") {\n ok = ch == match;\n } else {\n ok = ch && (match.test ? match.test(ch) : match(ch));\n }\n\n if (ok) {\n ++this.pos;\n return ch;\n }\n };\n\n StringStream.prototype.eatWhile = function (match) {\n var start = this.pos;\n\n while (this.eat(match)) {}\n\n return this.pos > start;\n };\n\n StringStream.prototype.eatSpace = function () {\n var start = this.pos;\n\n while (/[\\s\\u00a0]/.test(this.string.charAt(this.pos))) {\n ++this.pos;\n }\n\n return this.pos > start;\n };\n\n StringStream.prototype.skipToEnd = function () {\n this.pos = this.string.length;\n };\n\n StringStream.prototype.skipTo = function (ch) {\n var found = this.string.indexOf(ch, this.pos);\n\n if (found > -1) {\n this.pos = found;\n return true;\n }\n };\n\n StringStream.prototype.backUp = function (n) {\n this.pos -= n;\n };\n\n StringStream.prototype.column = function () {\n if (this.lastColumnPos < this.start) {\n this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);\n this.lastColumnPos = this.start;\n }\n\n return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);\n };\n\n StringStream.prototype.indentation = function () {\n return countColumn(this.string, null, this.tabSize) - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);\n };\n\n StringStream.prototype.match = function (pattern, consume, caseInsensitive) {\n if (typeof pattern == \"string\") {\n var cased = function cased(str) {\n return caseInsensitive ? str.toLowerCase() : str;\n };\n\n var substr = this.string.substr(this.pos, pattern.length);\n\n if (cased(substr) == cased(pattern)) {\n if (consume !== false) {\n this.pos += pattern.length;\n }\n\n return true;\n }\n } else {\n var match = this.string.slice(this.pos).match(pattern);\n\n if (match && match.index > 0) {\n return null;\n }\n\n if (match && consume !== false) {\n this.pos += match[0].length;\n }\n\n return match;\n }\n };\n\n StringStream.prototype.current = function () {\n return this.string.slice(this.start, this.pos);\n };\n\n StringStream.prototype.hideFirstChars = function (n, inner) {\n this.lineStart += n;\n\n try {\n return inner();\n } finally {\n this.lineStart -= n;\n }\n };\n\n StringStream.prototype.lookAhead = function (n) {\n var oracle = this.lineOracle;\n return oracle && oracle.lookAhead(n);\n };\n\n StringStream.prototype.baseToken = function () {\n var oracle = this.lineOracle;\n return oracle && oracle.baseToken(this.pos);\n }; // Find the line object corresponding to the given line number.\n\n\n function getLine(doc, n) {\n n -= doc.first;\n\n if (n < 0 || n >= doc.size) {\n throw new Error(\"There is no line \" + (n + doc.first) + \" in the document.\");\n }\n\n var chunk = doc;\n\n while (!chunk.lines) {\n for (var i = 0;; ++i) {\n var child = chunk.children[i],\n sz = child.chunkSize();\n\n if (n < sz) {\n chunk = child;\n break;\n }\n\n n -= sz;\n }\n }\n\n return chunk.lines[n];\n } // Get the part of a document between two positions, as an array of\n // strings.\n\n\n function getBetween(doc, start, end) {\n var out = [],\n n = start.line;\n doc.iter(start.line, end.line + 1, function (line) {\n var text = line.text;\n\n if (n == end.line) {\n text = text.slice(0, end.ch);\n }\n\n if (n == start.line) {\n text = text.slice(start.ch);\n }\n\n out.push(text);\n ++n;\n });\n return out;\n } // Get the lines between from and to, as array of strings.\n\n\n function getLines(doc, from, to) {\n var out = [];\n doc.iter(from, to, function (line) {\n out.push(line.text);\n }); // iter aborts when callback returns truthy value\n\n return out;\n } // Update the height of a line, propagating the height change\n // upwards to parent nodes.\n\n\n function updateLineHeight(line, height) {\n var diff = height - line.height;\n\n if (diff) {\n for (var n = line; n; n = n.parent) {\n n.height += diff;\n }\n }\n } // Given a line object, find its line number by walking up through\n // its parent links.\n\n\n function lineNo(line) {\n if (line.parent == null) {\n return null;\n }\n\n var cur = line.parent,\n no = indexOf(cur.lines, line);\n\n for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {\n for (var i = 0;; ++i) {\n if (chunk.children[i] == cur) {\n break;\n }\n\n no += chunk.children[i].chunkSize();\n }\n }\n\n return no + cur.first;\n } // Find the line at the given vertical position, using the height\n // information in the document tree.\n\n\n function _lineAtHeight(chunk, h) {\n var n = chunk.first;\n\n outer: do {\n for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {\n var child = chunk.children[i$1],\n ch = child.height;\n\n if (h < ch) {\n chunk = child;\n continue outer;\n }\n\n h -= ch;\n n += child.chunkSize();\n }\n\n return n;\n } while (!chunk.lines);\n\n var i = 0;\n\n for (; i < chunk.lines.length; ++i) {\n var line = chunk.lines[i],\n lh = line.height;\n\n if (h < lh) {\n break;\n }\n\n h -= lh;\n }\n\n return n + i;\n }\n\n function isLine(doc, l) {\n return l >= doc.first && l < doc.first + doc.size;\n }\n\n function lineNumberFor(options, i) {\n return String(options.lineNumberFormatter(i + options.firstLineNumber));\n } // A Pos instance represents a position within the text.\n\n\n function Pos(line, ch, sticky) {\n if (sticky === void 0) sticky = null;\n\n if (!(this instanceof Pos)) {\n return new Pos(line, ch, sticky);\n }\n\n this.line = line;\n this.ch = ch;\n this.sticky = sticky;\n } // Compare two positions, return 0 if they are the same, a negative\n // number when a is less, and a positive number otherwise.\n\n\n function cmp(a, b) {\n return a.line - b.line || a.ch - b.ch;\n }\n\n function equalCursorPos(a, b) {\n return a.sticky == b.sticky && cmp(a, b) == 0;\n }\n\n function copyPos(x) {\n return Pos(x.line, x.ch);\n }\n\n function maxPos(a, b) {\n return cmp(a, b) < 0 ? b : a;\n }\n\n function minPos(a, b) {\n return cmp(a, b) < 0 ? a : b;\n } // Most of the external API clips given positions to make sure they\n // actually exist within the document.\n\n\n function clipLine(doc, n) {\n return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));\n }\n\n function _clipPos(doc, pos) {\n if (pos.line < doc.first) {\n return Pos(doc.first, 0);\n }\n\n var last = doc.first + doc.size - 1;\n\n if (pos.line > last) {\n return Pos(last, getLine(doc, last).text.length);\n }\n\n return clipToLen(pos, getLine(doc, pos.line).text.length);\n }\n\n function clipToLen(pos, linelen) {\n var ch = pos.ch;\n\n if (ch == null || ch > linelen) {\n return Pos(pos.line, linelen);\n } else if (ch < 0) {\n return Pos(pos.line, 0);\n } else {\n return pos;\n }\n }\n\n function clipPosArray(doc, array) {\n var out = [];\n\n for (var i = 0; i < array.length; i++) {\n out[i] = _clipPos(doc, array[i]);\n }\n\n return out;\n }\n\n var SavedContext = function SavedContext(state, lookAhead) {\n this.state = state;\n this.lookAhead = lookAhead;\n };\n\n var Context = function Context(doc, state, line, lookAhead) {\n this.state = state;\n this.doc = doc;\n this.line = line;\n this.maxLookAhead = lookAhead || 0;\n this.baseTokens = null;\n this.baseTokenPos = 1;\n };\n\n Context.prototype.lookAhead = function (n) {\n var line = this.doc.getLine(this.line + n);\n\n if (line != null && n > this.maxLookAhead) {\n this.maxLookAhead = n;\n }\n\n return line;\n };\n\n Context.prototype.baseToken = function (n) {\n if (!this.baseTokens) {\n return null;\n }\n\n while (this.baseTokens[this.baseTokenPos] <= n) {\n this.baseTokenPos += 2;\n }\n\n var type = this.baseTokens[this.baseTokenPos + 1];\n return {\n type: type && type.replace(/( |^)overlay .*/, \"\"),\n size: this.baseTokens[this.baseTokenPos] - n\n };\n };\n\n Context.prototype.nextLine = function () {\n this.line++;\n\n if (this.maxLookAhead > 0) {\n this.maxLookAhead--;\n }\n };\n\n Context.fromSaved = function (doc, saved, line) {\n if (saved instanceof SavedContext) {\n return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead);\n } else {\n return new Context(doc, copyState(doc.mode, saved), line);\n }\n };\n\n Context.prototype.save = function (copy) {\n var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;\n return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state;\n }; // Compute a style array (an array starting with a mode generation\n // -- for invalidation -- followed by pairs of end positions and\n // style strings), which is used to highlight the tokens on the\n // line.\n\n\n function highlightLine(cm, line, context, forceToEnd) {\n // A styles array always starts with a number identifying the\n // mode/overlays that it is based on (for easy invalidation).\n var st = [cm.state.modeGen],\n lineClasses = {}; // Compute the base array of styles\n\n runMode(cm, line.text, cm.doc.mode, context, function (end, style) {\n return st.push(end, style);\n }, lineClasses, forceToEnd);\n var state = context.state; // Run overlays, adjust style array.\n\n var loop = function loop(o) {\n context.baseTokens = st;\n var overlay = cm.state.overlays[o],\n i = 1,\n at = 0;\n context.state = true;\n runMode(cm, line.text, overlay.mode, context, function (end, style) {\n var start = i; // Ensure there's a token end at the current position, and that i points at it\n\n while (at < end) {\n var i_end = st[i];\n\n if (i_end > end) {\n st.splice(i, 1, end, st[i + 1], i_end);\n }\n\n i += 2;\n at = Math.min(end, i_end);\n }\n\n if (!style) {\n return;\n }\n\n if (overlay.opaque) {\n st.splice(start, i - start, end, \"overlay \" + style);\n i = start + 2;\n } else {\n for (; start < i; start += 2) {\n var cur = st[start + 1];\n st[start + 1] = (cur ? cur + \" \" : \"\") + \"overlay \" + style;\n }\n }\n }, lineClasses);\n context.state = state;\n context.baseTokens = null;\n context.baseTokenPos = 1;\n };\n\n for (var o = 0; o < cm.state.overlays.length; ++o) {\n loop(o);\n }\n\n return {\n styles: st,\n classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null\n };\n }\n\n function getLineStyles(cm, line, updateFrontier) {\n if (!line.styles || line.styles[0] != cm.state.modeGen) {\n var context = getContextBefore(cm, lineNo(line));\n var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);\n var result = highlightLine(cm, line, context);\n\n if (resetState) {\n context.state = resetState;\n }\n\n line.stateAfter = context.save(!resetState);\n line.styles = result.styles;\n\n if (result.classes) {\n line.styleClasses = result.classes;\n } else if (line.styleClasses) {\n line.styleClasses = null;\n }\n\n if (updateFrontier === cm.doc.highlightFrontier) {\n cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier);\n }\n }\n\n return line.styles;\n }\n\n function getContextBefore(cm, n, precise) {\n var doc = cm.doc,\n display = cm.display;\n\n if (!doc.mode.startState) {\n return new Context(doc, true, n);\n }\n\n var start = findStartLine(cm, n, precise);\n var saved = start > doc.first && getLine(doc, start - 1).stateAfter;\n var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start);\n doc.iter(start, n, function (line) {\n processLine(cm, line.text, context);\n var pos = context.line;\n line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;\n context.nextLine();\n });\n\n if (precise) {\n doc.modeFrontier = context.line;\n }\n\n return context;\n } // Lightweight form of highlight -- proceed over this line and\n // update state, but don't save a style array. Used for lines that\n // aren't currently visible.\n\n\n function processLine(cm, text, context, startAt) {\n var mode = cm.doc.mode;\n var stream = new StringStream(text, cm.options.tabSize, context);\n stream.start = stream.pos = startAt || 0;\n\n if (text == \"\") {\n callBlankLine(mode, context.state);\n }\n\n while (!stream.eol()) {\n readToken(mode, stream, context.state);\n stream.start = stream.pos;\n }\n }\n\n function callBlankLine(mode, state) {\n if (mode.blankLine) {\n return mode.blankLine(state);\n }\n\n if (!mode.innerMode) {\n return;\n }\n\n var inner = innerMode(mode, state);\n\n if (inner.mode.blankLine) {\n return inner.mode.blankLine(inner.state);\n }\n }\n\n function readToken(mode, stream, state, inner) {\n for (var i = 0; i < 10; i++) {\n if (inner) {\n inner[0] = innerMode(mode, state).mode;\n }\n\n var style = mode.token(stream, state);\n\n if (stream.pos > stream.start) {\n return style;\n }\n }\n\n throw new Error(\"Mode \" + mode.name + \" failed to advance stream.\");\n }\n\n var Token = function Token(stream, type, state) {\n this.start = stream.start;\n this.end = stream.pos;\n this.string = stream.current();\n this.type = type || null;\n this.state = state;\n }; // Utility for getTokenAt and getLineTokens\n\n\n function takeToken(cm, pos, precise, asArray) {\n var doc = cm.doc,\n mode = doc.mode,\n style;\n pos = _clipPos(doc, pos);\n var line = getLine(doc, pos.line),\n context = getContextBefore(cm, pos.line, precise);\n var stream = new StringStream(line.text, cm.options.tabSize, context),\n tokens;\n\n if (asArray) {\n tokens = [];\n }\n\n while ((asArray || stream.pos < pos.ch) && !stream.eol()) {\n stream.start = stream.pos;\n style = readToken(mode, stream, context.state);\n\n if (asArray) {\n tokens.push(new Token(stream, style, copyState(doc.mode, context.state)));\n }\n }\n\n return asArray ? tokens : new Token(stream, style, context.state);\n }\n\n function extractLineClasses(type, output) {\n if (type) {\n for (;;) {\n var lineClass = type.match(/(?:^|\\s+)line-(background-)?(\\S+)/);\n\n if (!lineClass) {\n break;\n }\n\n type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);\n var prop = lineClass[1] ? \"bgClass\" : \"textClass\";\n\n if (output[prop] == null) {\n output[prop] = lineClass[2];\n } else if (!new RegExp(\"(?:^|\\\\s)\" + lineClass[2] + \"(?:$|\\\\s)\").test(output[prop])) {\n output[prop] += \" \" + lineClass[2];\n }\n }\n }\n\n return type;\n } // Run the given mode's parser over a line, calling f for each token.\n\n\n function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {\n var flattenSpans = mode.flattenSpans;\n\n if (flattenSpans == null) {\n flattenSpans = cm.options.flattenSpans;\n }\n\n var curStart = 0,\n curStyle = null;\n var stream = new StringStream(text, cm.options.tabSize, context),\n style;\n var inner = cm.options.addModeClass && [null];\n\n if (text == \"\") {\n extractLineClasses(callBlankLine(mode, context.state), lineClasses);\n }\n\n while (!stream.eol()) {\n if (stream.pos > cm.options.maxHighlightLength) {\n flattenSpans = false;\n\n if (forceToEnd) {\n processLine(cm, text, context, stream.pos);\n }\n\n stream.pos = text.length;\n style = null;\n } else {\n style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);\n }\n\n if (inner) {\n var mName = inner[0].name;\n\n if (mName) {\n style = \"m-\" + (style ? mName + \" \" + style : mName);\n }\n }\n\n if (!flattenSpans || curStyle != style) {\n while (curStart < stream.start) {\n curStart = Math.min(stream.start, curStart + 5000);\n f(curStart, curStyle);\n }\n\n curStyle = style;\n }\n\n stream.start = stream.pos;\n }\n\n while (curStart < stream.pos) {\n // Webkit seems to refuse to render text nodes longer than 57444\n // characters, and returns inaccurate measurements in nodes\n // starting around 5000 chars.\n var pos = Math.min(stream.pos, curStart + 5000);\n f(pos, curStyle);\n curStart = pos;\n }\n } // Finds the line to start with when starting a parse. Tries to\n // find a line with a stateAfter, so that it can start with a\n // valid state. If that fails, it returns the line with the\n // smallest indentation, which tends to need the least context to\n // parse correctly.\n\n\n function findStartLine(cm, n, precise) {\n var minindent,\n minline,\n doc = cm.doc;\n var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);\n\n for (var search = n; search > lim; --search) {\n if (search <= doc.first) {\n return doc.first;\n }\n\n var line = getLine(doc, search - 1),\n after = line.stateAfter;\n\n if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier)) {\n return search;\n }\n\n var indented = countColumn(line.text, null, cm.options.tabSize);\n\n if (minline == null || minindent > indented) {\n minline = search - 1;\n minindent = indented;\n }\n }\n\n return minline;\n }\n\n function retreatFrontier(doc, n) {\n doc.modeFrontier = Math.min(doc.modeFrontier, n);\n\n if (doc.highlightFrontier < n - 10) {\n return;\n }\n\n var start = doc.first;\n\n for (var line = n - 1; line > start; line--) {\n var saved = getLine(doc, line).stateAfter; // change is on 3\n // state on line 1 looked ahead 2 -- so saw 3\n // test 1 + 2 < 3 should cover this\n\n if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {\n start = line + 1;\n break;\n }\n }\n\n doc.highlightFrontier = Math.min(doc.highlightFrontier, start);\n } // Optimize some code when these features are not used.\n\n\n var sawReadOnlySpans = false,\n sawCollapsedSpans = false;\n\n function seeReadOnlySpans() {\n sawReadOnlySpans = true;\n }\n\n function seeCollapsedSpans() {\n sawCollapsedSpans = true;\n } // TEXTMARKER SPANS\n\n\n function MarkedSpan(marker, from, to) {\n this.marker = marker;\n this.from = from;\n this.to = to;\n } // Search an array of spans for a span matching the given marker.\n\n\n function getMarkedSpanFor(spans, marker) {\n if (spans) {\n for (var i = 0; i < spans.length; ++i) {\n var span = spans[i];\n\n if (span.marker == marker) {\n return span;\n }\n }\n }\n } // Remove a span from an array, returning undefined if no spans are\n // left (we don't store arrays for lines without spans).\n\n\n function removeMarkedSpan(spans, span) {\n var r;\n\n for (var i = 0; i < spans.length; ++i) {\n if (spans[i] != span) {\n (r || (r = [])).push(spans[i]);\n }\n }\n\n return r;\n } // Add a span to a line.\n\n\n function addMarkedSpan(line, span) {\n line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];\n span.marker.attachLine(line);\n } // Used for the algorithm that adjusts markers for a change in the\n // document. These functions cut an array of spans at a given\n // character position, returning an array of remaining chunks (or\n // undefined if nothing remains).\n\n\n function markedSpansBefore(old, startCh, isInsert) {\n var nw;\n\n if (old) {\n for (var i = 0; i < old.length; ++i) {\n var span = old[i],\n marker = span.marker;\n var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);\n\n if (startsBefore || span.from == startCh && marker.type == \"bookmark\" && (!isInsert || !span.marker.insertLeft)) {\n var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);\n (nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));\n }\n }\n }\n\n return nw;\n }\n\n function markedSpansAfter(old, endCh, isInsert) {\n var nw;\n\n if (old) {\n for (var i = 0; i < old.length; ++i) {\n var span = old[i],\n marker = span.marker;\n var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);\n\n if (endsAfter || span.from == endCh && marker.type == \"bookmark\" && (!isInsert || span.marker.insertLeft)) {\n var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);\n (nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh, span.to == null ? null : span.to - endCh));\n }\n }\n }\n\n return nw;\n } // Given a change object, compute the new set of marker spans that\n // cover the line in which the change took place. Removes spans\n // entirely within the change, reconnects spans belonging to the\n // same marker that appear on both sides of the change, and cuts off\n // spans partially within the change. Returns an array of span\n // arrays with one element for each line in (after) the change.\n\n\n function stretchSpansOverChange(doc, change) {\n if (change.full) {\n return null;\n }\n\n var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;\n var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;\n\n if (!oldFirst && !oldLast) {\n return null;\n }\n\n var startCh = change.from.ch,\n endCh = change.to.ch,\n isInsert = cmp(change.from, change.to) == 0; // Get the spans that 'stick out' on both sides\n\n var first = markedSpansBefore(oldFirst, startCh, isInsert);\n var last = markedSpansAfter(oldLast, endCh, isInsert); // Next, merge those two ends\n\n var sameLine = change.text.length == 1,\n offset = lst(change.text).length + (sameLine ? startCh : 0);\n\n if (first) {\n // Fix up .to properties of first\n for (var i = 0; i < first.length; ++i) {\n var span = first[i];\n\n if (span.to == null) {\n var found = getMarkedSpanFor(last, span.marker);\n\n if (!found) {\n span.to = startCh;\n } else if (sameLine) {\n span.to = found.to == null ? null : found.to + offset;\n }\n }\n }\n }\n\n if (last) {\n // Fix up .from in last (or move them into first in case of sameLine)\n for (var i$1 = 0; i$1 < last.length; ++i$1) {\n var span$1 = last[i$1];\n\n if (span$1.to != null) {\n span$1.to += offset;\n }\n\n if (span$1.from == null) {\n var found$1 = getMarkedSpanFor(first, span$1.marker);\n\n if (!found$1) {\n span$1.from = offset;\n\n if (sameLine) {\n (first || (first = [])).push(span$1);\n }\n }\n } else {\n span$1.from += offset;\n\n if (sameLine) {\n (first || (first = [])).push(span$1);\n }\n }\n }\n } // Make sure we didn't create any zero-length spans\n\n\n if (first) {\n first = clearEmptySpans(first);\n }\n\n if (last && last != first) {\n last = clearEmptySpans(last);\n }\n\n var newMarkers = [first];\n\n if (!sameLine) {\n // Fill gap with whole-line-spans\n var gap = change.text.length - 2,\n gapMarkers;\n\n if (gap > 0 && first) {\n for (var i$2 = 0; i$2 < first.length; ++i$2) {\n if (first[i$2].to == null) {\n (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null));\n }\n }\n }\n\n for (var i$3 = 0; i$3 < gap; ++i$3) {\n newMarkers.push(gapMarkers);\n }\n\n newMarkers.push(last);\n }\n\n return newMarkers;\n } // Remove spans that are empty and don't have a clearWhenEmpty\n // option of false.\n\n\n function clearEmptySpans(spans) {\n for (var i = 0; i < spans.length; ++i) {\n var span = spans[i];\n\n if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false) {\n spans.splice(i--, 1);\n }\n }\n\n if (!spans.length) {\n return null;\n }\n\n return spans;\n } // Used to 'clip' out readOnly ranges when making a change.\n\n\n function removeReadOnlyRanges(doc, from, to) {\n var markers = null;\n doc.iter(from.line, to.line + 1, function (line) {\n if (line.markedSpans) {\n for (var i = 0; i < line.markedSpans.length; ++i) {\n var mark = line.markedSpans[i].marker;\n\n if (mark.readOnly && (!markers || indexOf(markers, mark) == -1)) {\n (markers || (markers = [])).push(mark);\n }\n }\n }\n });\n\n if (!markers) {\n return null;\n }\n\n var parts = [{\n from: from,\n to: to\n }];\n\n for (var i = 0; i < markers.length; ++i) {\n var mk = markers[i],\n m = mk.find(0);\n\n for (var j = 0; j < parts.length; ++j) {\n var p = parts[j];\n\n if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) {\n continue;\n }\n\n var newParts = [j, 1],\n dfrom = cmp(p.from, m.from),\n dto = cmp(p.to, m.to);\n\n if (dfrom < 0 || !mk.inclusiveLeft && !dfrom) {\n newParts.push({\n from: p.from,\n to: m.from\n });\n }\n\n if (dto > 0 || !mk.inclusiveRight && !dto) {\n newParts.push({\n from: m.to,\n to: p.to\n });\n }\n\n parts.splice.apply(parts, newParts);\n j += newParts.length - 3;\n }\n }\n\n return parts;\n } // Connect or disconnect spans from a line.\n\n\n function detachMarkedSpans(line) {\n var spans = line.markedSpans;\n\n if (!spans) {\n return;\n }\n\n for (var i = 0; i < spans.length; ++i) {\n spans[i].marker.detachLine(line);\n }\n\n line.markedSpans = null;\n }\n\n function attachMarkedSpans(line, spans) {\n if (!spans) {\n return;\n }\n\n for (var i = 0; i < spans.length; ++i) {\n spans[i].marker.attachLine(line);\n }\n\n line.markedSpans = spans;\n } // Helpers used when computing which overlapping collapsed span\n // counts as the larger one.\n\n\n function extraLeft(marker) {\n return marker.inclusiveLeft ? -1 : 0;\n }\n\n function extraRight(marker) {\n return marker.inclusiveRight ? 1 : 0;\n } // Returns a number indicating which of two overlapping collapsed\n // spans is larger (and thus includes the other). Falls back to\n // comparing ids when the spans cover exactly the same range.\n\n\n function compareCollapsedMarkers(a, b) {\n var lenDiff = a.lines.length - b.lines.length;\n\n if (lenDiff != 0) {\n return lenDiff;\n }\n\n var aPos = a.find(),\n bPos = b.find();\n var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);\n\n if (fromCmp) {\n return -fromCmp;\n }\n\n var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);\n\n if (toCmp) {\n return toCmp;\n }\n\n return b.id - a.id;\n } // Find out whether a line ends or starts in a collapsed span. If\n // so, return the marker for that span.\n\n\n function collapsedSpanAtSide(line, start) {\n var sps = sawCollapsedSpans && line.markedSpans,\n found;\n\n if (sps) {\n for (var sp = void 0, i = 0; i < sps.length; ++i) {\n sp = sps[i];\n\n if (sp.marker.collapsed && (start ? sp.from : sp.to) == null && (!found || compareCollapsedMarkers(found, sp.marker) < 0)) {\n found = sp.marker;\n }\n }\n }\n\n return found;\n }\n\n function collapsedSpanAtStart(line) {\n return collapsedSpanAtSide(line, true);\n }\n\n function collapsedSpanAtEnd(line) {\n return collapsedSpanAtSide(line, false);\n }\n\n function collapsedSpanAround(line, ch) {\n var sps = sawCollapsedSpans && line.markedSpans,\n found;\n\n if (sps) {\n for (var i = 0; i < sps.length; ++i) {\n var sp = sps[i];\n\n if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) && (!found || compareCollapsedMarkers(found, sp.marker) < 0)) {\n found = sp.marker;\n }\n }\n }\n\n return found;\n } // Test whether there exists a collapsed span that partially\n // overlaps (covers the start or end, but not both) of a new span.\n // Such overlap is not allowed.\n\n\n function conflictingCollapsedRange(doc, lineNo, from, to, marker) {\n var line = getLine(doc, lineNo);\n var sps = sawCollapsedSpans && line.markedSpans;\n\n if (sps) {\n for (var i = 0; i < sps.length; ++i) {\n var sp = sps[i];\n\n if (!sp.marker.collapsed) {\n continue;\n }\n\n var found = sp.marker.find(0);\n var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);\n var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);\n\n if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) {\n continue;\n }\n\n if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) || fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0)) {\n return true;\n }\n }\n }\n } // A visual line is a line as drawn on the screen. Folding, for\n // example, can cause multiple logical lines to appear on the same\n // visual line. This finds the start of the visual line that the\n // given line is part of (usually that is the line itself).\n\n\n function visualLine(line) {\n var merged;\n\n while (merged = collapsedSpanAtStart(line)) {\n line = merged.find(-1, true).line;\n }\n\n return line;\n }\n\n function visualLineEnd(line) {\n var merged;\n\n while (merged = collapsedSpanAtEnd(line)) {\n line = merged.find(1, true).line;\n }\n\n return line;\n } // Returns an array of logical lines that continue the visual line\n // started by the argument, or undefined if there are no such lines.\n\n\n function visualLineContinued(line) {\n var merged, lines;\n\n while (merged = collapsedSpanAtEnd(line)) {\n line = merged.find(1, true).line;\n (lines || (lines = [])).push(line);\n }\n\n return lines;\n } // Get the line number of the start of the visual line that the\n // given line number is part of.\n\n\n function visualLineNo(doc, lineN) {\n var line = getLine(doc, lineN),\n vis = visualLine(line);\n\n if (line == vis) {\n return lineN;\n }\n\n return lineNo(vis);\n } // Get the line number of the start of the next visual line after\n // the given line.\n\n\n function visualLineEndNo(doc, lineN) {\n if (lineN > doc.lastLine()) {\n return lineN;\n }\n\n var line = getLine(doc, lineN),\n merged;\n\n if (!lineIsHidden(doc, line)) {\n return lineN;\n }\n\n while (merged = collapsedSpanAtEnd(line)) {\n line = merged.find(1, true).line;\n }\n\n return lineNo(line) + 1;\n } // Compute whether a line is hidden. Lines count as hidden when they\n // are part of a visual line that starts with another line, or when\n // they are entirely covered by collapsed, non-widget span.\n\n\n function lineIsHidden(doc, line) {\n var sps = sawCollapsedSpans && line.markedSpans;\n\n if (sps) {\n for (var sp = void 0, i = 0; i < sps.length; ++i) {\n sp = sps[i];\n\n if (!sp.marker.collapsed) {\n continue;\n }\n\n if (sp.from == null) {\n return true;\n }\n\n if (sp.marker.widgetNode) {\n continue;\n }\n\n if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp)) {\n return true;\n }\n }\n }\n }\n\n function lineIsHiddenInner(doc, line, span) {\n if (span.to == null) {\n var end = span.marker.find(1, true);\n return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));\n }\n\n if (span.marker.inclusiveRight && span.to == line.text.length) {\n return true;\n }\n\n for (var sp = void 0, i = 0; i < line.markedSpans.length; ++i) {\n sp = line.markedSpans[i];\n\n if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to && (sp.to == null || sp.to != span.from) && (sp.marker.inclusiveLeft || span.marker.inclusiveRight) && lineIsHiddenInner(doc, line, sp)) {\n return true;\n }\n }\n } // Find the height above the given line.\n\n\n function _heightAtLine(lineObj) {\n lineObj = visualLine(lineObj);\n var h = 0,\n chunk = lineObj.parent;\n\n for (var i = 0; i < chunk.lines.length; ++i) {\n var line = chunk.lines[i];\n\n if (line == lineObj) {\n break;\n } else {\n h += line.height;\n }\n }\n\n for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {\n for (var i$1 = 0; i$1 < p.children.length; ++i$1) {\n var cur = p.children[i$1];\n\n if (cur == chunk) {\n break;\n } else {\n h += cur.height;\n }\n }\n }\n\n return h;\n } // Compute the character length of a line, taking into account\n // collapsed ranges (see markText) that might hide parts, and join\n // other lines onto it.\n\n\n function lineLength(line) {\n if (line.height == 0) {\n return 0;\n }\n\n var len = line.text.length,\n merged,\n cur = line;\n\n while (merged = collapsedSpanAtStart(cur)) {\n var found = merged.find(0, true);\n cur = found.from.line;\n len += found.from.ch - found.to.ch;\n }\n\n cur = line;\n\n while (merged = collapsedSpanAtEnd(cur)) {\n var found$1 = merged.find(0, true);\n len -= cur.text.length - found$1.from.ch;\n cur = found$1.to.line;\n len += cur.text.length - found$1.to.ch;\n }\n\n return len;\n } // Find the longest line in the document.\n\n\n function findMaxLine(cm) {\n var d = cm.display,\n doc = cm.doc;\n d.maxLine = getLine(doc, doc.first);\n d.maxLineLength = lineLength(d.maxLine);\n d.maxLineChanged = true;\n doc.iter(function (line) {\n var len = lineLength(line);\n\n if (len > d.maxLineLength) {\n d.maxLineLength = len;\n d.maxLine = line;\n }\n });\n } // LINE DATA STRUCTURE\n // Line objects. These hold state related to a line, including\n // highlighting info (the styles array).\n\n\n var Line = function Line(text, markedSpans, estimateHeight) {\n this.text = text;\n attachMarkedSpans(this, markedSpans);\n this.height = estimateHeight ? estimateHeight(this) : 1;\n };\n\n Line.prototype.lineNo = function () {\n return lineNo(this);\n };\n\n eventMixin(Line); // Change the content (text, markers) of a line. Automatically\n // invalidates cached information and tries to re-estimate the\n // line's height.\n\n function updateLine(line, text, markedSpans, estimateHeight) {\n line.text = text;\n\n if (line.stateAfter) {\n line.stateAfter = null;\n }\n\n if (line.styles) {\n line.styles = null;\n }\n\n if (line.order != null) {\n line.order = null;\n }\n\n detachMarkedSpans(line);\n attachMarkedSpans(line, markedSpans);\n var estHeight = estimateHeight ? estimateHeight(line) : 1;\n\n if (estHeight != line.height) {\n updateLineHeight(line, estHeight);\n }\n } // Detach a line from the document tree and its markers.\n\n\n function cleanUpLine(line) {\n line.parent = null;\n detachMarkedSpans(line);\n } // Convert a style as returned by a mode (either null, or a string\n // containing one or more styles) to a CSS style. This is cached,\n // and also looks for line-wide styles.\n\n\n var styleToClassCache = {},\n styleToClassCacheWithMode = {};\n\n function interpretTokenStyle(style, options) {\n if (!style || /^\\s*$/.test(style)) {\n return null;\n }\n\n var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;\n return cache[style] || (cache[style] = style.replace(/\\S+/g, \"cm-$&\"));\n } // Render the DOM representation of the text of a line. Also builds\n // up a 'line map', which points at the DOM nodes that represent\n // specific stretches of text, and is used by the measuring code.\n // The returned object contains the DOM node, this map, and\n // information about line-wide styles that were set by the mode.\n\n\n function buildLineContent(cm, lineView) {\n // The padding-right forces the element to have a 'border', which\n // is needed on Webkit to be able to get line-level bounding\n // rectangles for it (in measureChar).\n var content = eltP(\"span\", null, null, webkit ? \"padding-right: .1px\" : null);\n var builder = {\n pre: eltP(\"pre\", [content], \"CodeMirror-line\"),\n content: content,\n col: 0,\n pos: 0,\n cm: cm,\n trailingSpace: false,\n splitSpaces: cm.getOption(\"lineWrapping\")\n };\n lineView.measure = {}; // Iterate over the logical lines that make up this visual line.\n\n for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {\n var line = i ? lineView.rest[i - 1] : lineView.line,\n order = void 0;\n builder.pos = 0;\n builder.addToken = buildToken; // Optionally wire in some hacks into the token-rendering\n // algorithm, to deal with browser quirks.\n\n if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) {\n builder.addToken = buildTokenBadBidi(builder.addToken, order);\n }\n\n builder.map = [];\n var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);\n insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));\n\n if (line.styleClasses) {\n if (line.styleClasses.bgClass) {\n builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || \"\");\n }\n\n if (line.styleClasses.textClass) {\n builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || \"\");\n }\n } // Ensure at least a single node is present, for measuring.\n\n\n if (builder.map.length == 0) {\n builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));\n } // Store the map and a cache object for the current logical line\n\n\n if (i == 0) {\n lineView.measure.map = builder.map;\n lineView.measure.cache = {};\n } else {\n (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);\n (lineView.measure.caches || (lineView.measure.caches = [])).push({});\n }\n } // See issue #2901\n\n\n if (webkit) {\n var last = builder.content.lastChild;\n\n if (/\\bcm-tab\\b/.test(last.className) || last.querySelector && last.querySelector(\".cm-tab\")) {\n builder.content.className = \"cm-tab-wrap-hack\";\n }\n }\n\n signal(cm, \"renderLine\", cm, lineView.line, builder.pre);\n\n if (builder.pre.className) {\n builder.textClass = joinClasses(builder.pre.className, builder.textClass || \"\");\n }\n\n return builder;\n }\n\n function defaultSpecialCharPlaceholder(ch) {\n var token = elt(\"span\", \"\\u2022\", \"cm-invalidchar\");\n token.title = \"\\\\u\" + ch.charCodeAt(0).toString(16);\n token.setAttribute(\"aria-label\", token.title);\n return token;\n } // Build up the DOM representation for a single token, and add it to\n // the line map. Takes care to render special characters separately.\n\n\n function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {\n if (!text) {\n return;\n }\n\n var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;\n var special = builder.cm.state.specialChars,\n mustWrap = false;\n var content;\n\n if (!special.test(text)) {\n builder.col += text.length;\n content = document.createTextNode(displayText);\n builder.map.push(builder.pos, builder.pos + text.length, content);\n\n if (ie && ie_version < 9) {\n mustWrap = true;\n }\n\n builder.pos += text.length;\n } else {\n content = document.createDocumentFragment();\n var pos = 0;\n\n while (true) {\n special.lastIndex = pos;\n var m = special.exec(text);\n var skipped = m ? m.index - pos : text.length - pos;\n\n if (skipped) {\n var txt = document.createTextNode(displayText.slice(pos, pos + skipped));\n\n if (ie && ie_version < 9) {\n content.appendChild(elt(\"span\", [txt]));\n } else {\n content.appendChild(txt);\n }\n\n builder.map.push(builder.pos, builder.pos + skipped, txt);\n builder.col += skipped;\n builder.pos += skipped;\n }\n\n if (!m) {\n break;\n }\n\n pos += skipped + 1;\n var txt$1 = void 0;\n\n if (m[0] == \"\\t\") {\n var tabSize = builder.cm.options.tabSize,\n tabWidth = tabSize - builder.col % tabSize;\n txt$1 = content.appendChild(elt(\"span\", spaceStr(tabWidth), \"cm-tab\"));\n txt$1.setAttribute(\"role\", \"presentation\");\n txt$1.setAttribute(\"cm-text\", \"\\t\");\n builder.col += tabWidth;\n } else if (m[0] == \"\\r\" || m[0] == \"\\n\") {\n txt$1 = content.appendChild(elt(\"span\", m[0] == \"\\r\" ? \"\\u240D\" : \"\\u2424\", \"cm-invalidchar\"));\n txt$1.setAttribute(\"cm-text\", m[0]);\n builder.col += 1;\n } else {\n txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);\n txt$1.setAttribute(\"cm-text\", m[0]);\n\n if (ie && ie_version < 9) {\n content.appendChild(elt(\"span\", [txt$1]));\n } else {\n content.appendChild(txt$1);\n }\n\n builder.col += 1;\n }\n\n builder.map.push(builder.pos, builder.pos + 1, txt$1);\n builder.pos++;\n }\n }\n\n builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;\n\n if (style || startStyle || endStyle || mustWrap || css || attributes) {\n var fullStyle = style || \"\";\n\n if (startStyle) {\n fullStyle += startStyle;\n }\n\n if (endStyle) {\n fullStyle += endStyle;\n }\n\n var token = elt(\"span\", [content], fullStyle, css);\n\n if (attributes) {\n for (var attr in attributes) {\n if (attributes.hasOwnProperty(attr) && attr != \"style\" && attr != \"class\") {\n token.setAttribute(attr, attributes[attr]);\n }\n }\n }\n\n return builder.content.appendChild(token);\n }\n\n builder.content.appendChild(content);\n } // Change some spaces to NBSP to prevent the browser from collapsing\n // trailing spaces at the end of a line when rendering text (issue #1362).\n\n\n function splitSpaces(text, trailingBefore) {\n if (text.length > 1 && !/ /.test(text)) {\n return text;\n }\n\n var spaceBefore = trailingBefore,\n result = \"\";\n\n for (var i = 0; i < text.length; i++) {\n var ch = text.charAt(i);\n\n if (ch == \" \" && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) {\n ch = \"\\xA0\";\n }\n\n result += ch;\n spaceBefore = ch == \" \";\n }\n\n return result;\n } // Work around nonsense dimensions being reported for stretches of\n // right-to-left text.\n\n\n function buildTokenBadBidi(inner, order) {\n return function (builder, text, style, startStyle, endStyle, css, attributes) {\n style = style ? style + \" cm-force-border\" : \"cm-force-border\";\n var start = builder.pos,\n end = start + text.length;\n\n for (;;) {\n // Find the part that overlaps with the start of this text\n var part = void 0;\n\n for (var i = 0; i < order.length; i++) {\n part = order[i];\n\n if (part.to > start && part.from <= start) {\n break;\n }\n }\n\n if (part.to >= end) {\n return inner(builder, text, style, startStyle, endStyle, css, attributes);\n }\n\n inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes);\n startStyle = null;\n text = text.slice(part.to - start);\n start = part.to;\n }\n };\n }\n\n function buildCollapsedSpan(builder, size, marker, ignoreWidget) {\n var widget = !ignoreWidget && marker.widgetNode;\n\n if (widget) {\n builder.map.push(builder.pos, builder.pos + size, widget);\n }\n\n if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {\n if (!widget) {\n widget = builder.content.appendChild(document.createElement(\"span\"));\n }\n\n widget.setAttribute(\"cm-marker\", marker.id);\n }\n\n if (widget) {\n builder.cm.display.input.setUneditable(widget);\n builder.content.appendChild(widget);\n }\n\n builder.pos += size;\n builder.trailingSpace = false;\n } // Outputs a number of spans to make up a line, taking highlighting\n // and marked text into account.\n\n\n function insertLineContent(line, builder, styles) {\n var spans = line.markedSpans,\n allText = line.text,\n at = 0;\n\n if (!spans) {\n for (var i$1 = 1; i$1 < styles.length; i$1 += 2) {\n builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1 + 1], builder.cm.options));\n }\n\n return;\n }\n\n var len = allText.length,\n pos = 0,\n i = 1,\n text = \"\",\n style,\n css;\n var nextChange = 0,\n spanStyle,\n spanEndStyle,\n spanStartStyle,\n collapsed,\n attributes;\n\n for (;;) {\n if (nextChange == pos) {\n // Update current marker set\n spanStyle = spanEndStyle = spanStartStyle = css = \"\";\n attributes = null;\n collapsed = null;\n nextChange = Infinity;\n var foundBookmarks = [],\n endStyles = void 0;\n\n for (var j = 0; j < spans.length; ++j) {\n var sp = spans[j],\n m = sp.marker;\n\n if (m.type == \"bookmark\" && sp.from == pos && m.widgetNode) {\n foundBookmarks.push(m);\n } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {\n if (sp.to != null && sp.to != pos && nextChange > sp.to) {\n nextChange = sp.to;\n spanEndStyle = \"\";\n }\n\n if (m.className) {\n spanStyle += \" \" + m.className;\n }\n\n if (m.css) {\n css = (css ? css + \";\" : \"\") + m.css;\n }\n\n if (m.startStyle && sp.from == pos) {\n spanStartStyle += \" \" + m.startStyle;\n }\n\n if (m.endStyle && sp.to == nextChange) {\n (endStyles || (endStyles = [])).push(m.endStyle, sp.to);\n } // support for the old title property\n // https://github.com/codemirror/CodeMirror/pull/5673\n\n\n if (m.title) {\n (attributes || (attributes = {})).title = m.title;\n }\n\n if (m.attributes) {\n for (var attr in m.attributes) {\n (attributes || (attributes = {}))[attr] = m.attributes[attr];\n }\n }\n\n if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) {\n collapsed = sp;\n }\n } else if (sp.from > pos && nextChange > sp.from) {\n nextChange = sp.from;\n }\n }\n\n if (endStyles) {\n for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2) {\n if (endStyles[j$1 + 1] == nextChange) {\n spanEndStyle += \" \" + endStyles[j$1];\n }\n }\n }\n\n if (!collapsed || collapsed.from == pos) {\n for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2) {\n buildCollapsedSpan(builder, 0, foundBookmarks[j$2]);\n }\n }\n\n if (collapsed && (collapsed.from || 0) == pos) {\n buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, collapsed.marker, collapsed.from == null);\n\n if (collapsed.to == null) {\n return;\n }\n\n if (collapsed.to == pos) {\n collapsed = false;\n }\n }\n }\n\n if (pos >= len) {\n break;\n }\n\n var upto = Math.min(len, nextChange);\n\n while (true) {\n if (text) {\n var end = pos + text.length;\n\n if (!collapsed) {\n var tokenText = end > upto ? text.slice(0, upto - pos) : text;\n builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle, spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : \"\", css, attributes);\n }\n\n if (end >= upto) {\n text = text.slice(upto - pos);\n pos = upto;\n break;\n }\n\n pos = end;\n spanStartStyle = \"\";\n }\n\n text = allText.slice(at, at = styles[i++]);\n style = interpretTokenStyle(styles[i++], builder.cm.options);\n }\n }\n } // These objects are used to represent the visible (currently drawn)\n // part of the document. A LineView may correspond to multiple\n // logical lines, if those are connected by collapsed ranges.\n\n\n function LineView(doc, line, lineN) {\n // The starting line\n this.line = line; // Continuing lines, if any\n\n this.rest = visualLineContinued(line); // Number of logical lines in this visual line\n\n this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;\n this.node = this.text = null;\n this.hidden = lineIsHidden(doc, line);\n } // Create a range of LineView objects for the given lines.\n\n\n function buildViewArray(cm, from, to) {\n var array = [],\n nextPos;\n\n for (var pos = from; pos < to; pos = nextPos) {\n var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);\n nextPos = pos + view.size;\n array.push(view);\n }\n\n return array;\n }\n\n var operationGroup = null;\n\n function pushOperation(op) {\n if (operationGroup) {\n operationGroup.ops.push(op);\n } else {\n op.ownsGroup = operationGroup = {\n ops: [op],\n delayedCallbacks: []\n };\n }\n }\n\n function fireCallbacksForOps(group) {\n // Calls delayed callbacks and cursorActivity handlers until no\n // new ones appear\n var callbacks = group.delayedCallbacks,\n i = 0;\n\n do {\n for (; i < callbacks.length; i++) {\n callbacks[i].call(null);\n }\n\n for (var j = 0; j < group.ops.length; j++) {\n var op = group.ops[j];\n\n if (op.cursorActivityHandlers) {\n while (op.cursorActivityCalled < op.cursorActivityHandlers.length) {\n op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm);\n }\n }\n }\n } while (i < callbacks.length);\n }\n\n function finishOperation(op, endCb) {\n var group = op.ownsGroup;\n\n if (!group) {\n return;\n }\n\n try {\n fireCallbacksForOps(group);\n } finally {\n operationGroup = null;\n endCb(group);\n }\n }\n\n var orphanDelayedCallbacks = null; // Often, we want to signal events at a point where we are in the\n // middle of some work, but don't want the handler to start calling\n // other methods on the editor, which might be in an inconsistent\n // state or simply not expect any other events to happen.\n // signalLater looks whether there are any handlers, and schedules\n // them to be executed when the last operation ends, or, if no\n // operation is active, when a timeout fires.\n\n function signalLater(emitter, type\n /*, values...*/\n ) {\n var arr = getHandlers(emitter, type);\n\n if (!arr.length) {\n return;\n }\n\n var args = Array.prototype.slice.call(arguments, 2),\n list;\n\n if (operationGroup) {\n list = operationGroup.delayedCallbacks;\n } else if (orphanDelayedCallbacks) {\n list = orphanDelayedCallbacks;\n } else {\n list = orphanDelayedCallbacks = [];\n setTimeout(fireOrphanDelayed, 0);\n }\n\n var loop = function loop(i) {\n list.push(function () {\n return arr[i].apply(null, args);\n });\n };\n\n for (var i = 0; i < arr.length; ++i) {\n loop(i);\n }\n }\n\n function fireOrphanDelayed() {\n var delayed = orphanDelayedCallbacks;\n orphanDelayedCallbacks = null;\n\n for (var i = 0; i < delayed.length; ++i) {\n delayed[i]();\n }\n } // When an aspect of a line changes, a string is added to\n // lineView.changes. This updates the relevant part of the line's\n // DOM structure.\n\n\n function updateLineForChanges(cm, lineView, lineN, dims) {\n for (var j = 0; j < lineView.changes.length; j++) {\n var type = lineView.changes[j];\n\n if (type == \"text\") {\n updateLineText(cm, lineView);\n } else if (type == \"gutter\") {\n updateLineGutter(cm, lineView, lineN, dims);\n } else if (type == \"class\") {\n updateLineClasses(cm, lineView);\n } else if (type == \"widget\") {\n updateLineWidgets(cm, lineView, dims);\n }\n }\n\n lineView.changes = null;\n } // Lines with gutter elements, widgets or a background class need to\n // be wrapped, and have the extra elements added to the wrapper div\n\n\n function ensureLineWrapped(lineView) {\n if (lineView.node == lineView.text) {\n lineView.node = elt(\"div\", null, null, \"position: relative\");\n\n if (lineView.text.parentNode) {\n lineView.text.parentNode.replaceChild(lineView.node, lineView.text);\n }\n\n lineView.node.appendChild(lineView.text);\n\n if (ie && ie_version < 8) {\n lineView.node.style.zIndex = 2;\n }\n }\n\n return lineView.node;\n }\n\n function updateLineBackground(cm, lineView) {\n var cls = lineView.bgClass ? lineView.bgClass + \" \" + (lineView.line.bgClass || \"\") : lineView.line.bgClass;\n\n if (cls) {\n cls += \" CodeMirror-linebackground\";\n }\n\n if (lineView.background) {\n if (cls) {\n lineView.background.className = cls;\n } else {\n lineView.background.parentNode.removeChild(lineView.background);\n lineView.background = null;\n }\n } else if (cls) {\n var wrap = ensureLineWrapped(lineView);\n lineView.background = wrap.insertBefore(elt(\"div\", null, cls), wrap.firstChild);\n cm.display.input.setUneditable(lineView.background);\n }\n } // Wrapper around buildLineContent which will reuse the structure\n // in display.externalMeasured when possible.\n\n\n function getLineContent(cm, lineView) {\n var ext = cm.display.externalMeasured;\n\n if (ext && ext.line == lineView.line) {\n cm.display.externalMeasured = null;\n lineView.measure = ext.measure;\n return ext.built;\n }\n\n return buildLineContent(cm, lineView);\n } // Redraw the line's text. Interacts with the background and text\n // classes because the mode may output tokens that influence these\n // classes.\n\n\n function updateLineText(cm, lineView) {\n var cls = lineView.text.className;\n var built = getLineContent(cm, lineView);\n\n if (lineView.text == lineView.node) {\n lineView.node = built.pre;\n }\n\n lineView.text.parentNode.replaceChild(built.pre, lineView.text);\n lineView.text = built.pre;\n\n if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {\n lineView.bgClass = built.bgClass;\n lineView.textClass = built.textClass;\n updateLineClasses(cm, lineView);\n } else if (cls) {\n lineView.text.className = cls;\n }\n }\n\n function updateLineClasses(cm, lineView) {\n updateLineBackground(cm, lineView);\n\n if (lineView.line.wrapClass) {\n ensureLineWrapped(lineView).className = lineView.line.wrapClass;\n } else if (lineView.node != lineView.text) {\n lineView.node.className = \"\";\n }\n\n var textClass = lineView.textClass ? lineView.textClass + \" \" + (lineView.line.textClass || \"\") : lineView.line.textClass;\n lineView.text.className = textClass || \"\";\n }\n\n function updateLineGutter(cm, lineView, lineN, dims) {\n if (lineView.gutter) {\n lineView.node.removeChild(lineView.gutter);\n lineView.gutter = null;\n }\n\n if (lineView.gutterBackground) {\n lineView.node.removeChild(lineView.gutterBackground);\n lineView.gutterBackground = null;\n }\n\n if (lineView.line.gutterClass) {\n var wrap = ensureLineWrapped(lineView);\n lineView.gutterBackground = elt(\"div\", null, \"CodeMirror-gutter-background \" + lineView.line.gutterClass, \"left: \" + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + \"px; width: \" + dims.gutterTotalWidth + \"px\");\n cm.display.input.setUneditable(lineView.gutterBackground);\n wrap.insertBefore(lineView.gutterBackground, lineView.text);\n }\n\n var markers = lineView.line.gutterMarkers;\n\n if (cm.options.lineNumbers || markers) {\n var wrap$1 = ensureLineWrapped(lineView);\n var gutterWrap = lineView.gutter = elt(\"div\", null, \"CodeMirror-gutter-wrapper\", \"left: \" + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + \"px\");\n cm.display.input.setUneditable(gutterWrap);\n wrap$1.insertBefore(gutterWrap, lineView.text);\n\n if (lineView.line.gutterClass) {\n gutterWrap.className += \" \" + lineView.line.gutterClass;\n }\n\n if (cm.options.lineNumbers && (!markers || !markers[\"CodeMirror-linenumbers\"])) {\n lineView.lineNumber = gutterWrap.appendChild(elt(\"div\", lineNumberFor(cm.options, lineN), \"CodeMirror-linenumber CodeMirror-gutter-elt\", \"left: \" + dims.gutterLeft[\"CodeMirror-linenumbers\"] + \"px; width: \" + cm.display.lineNumInnerWidth + \"px\"));\n }\n\n if (markers) {\n for (var k = 0; k < cm.display.gutterSpecs.length; ++k) {\n var id = cm.display.gutterSpecs[k].className,\n found = markers.hasOwnProperty(id) && markers[id];\n\n if (found) {\n gutterWrap.appendChild(elt(\"div\", [found], \"CodeMirror-gutter-elt\", \"left: \" + dims.gutterLeft[id] + \"px; width: \" + dims.gutterWidth[id] + \"px\"));\n }\n }\n }\n }\n }\n\n function updateLineWidgets(cm, lineView, dims) {\n if (lineView.alignable) {\n lineView.alignable = null;\n }\n\n var isWidget = classTest(\"CodeMirror-linewidget\");\n\n for (var node = lineView.node.firstChild, next = void 0; node; node = next) {\n next = node.nextSibling;\n\n if (isWidget.test(node.className)) {\n lineView.node.removeChild(node);\n }\n }\n\n insertLineWidgets(cm, lineView, dims);\n } // Build a line's DOM representation from scratch\n\n\n function buildLineElement(cm, lineView, lineN, dims) {\n var built = getLineContent(cm, lineView);\n lineView.text = lineView.node = built.pre;\n\n if (built.bgClass) {\n lineView.bgClass = built.bgClass;\n }\n\n if (built.textClass) {\n lineView.textClass = built.textClass;\n }\n\n updateLineClasses(cm, lineView);\n updateLineGutter(cm, lineView, lineN, dims);\n insertLineWidgets(cm, lineView, dims);\n return lineView.node;\n } // A lineView may contain multiple logical lines (when merged by\n // collapsed spans). The widgets for all of them need to be drawn.\n\n\n function insertLineWidgets(cm, lineView, dims) {\n insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);\n\n if (lineView.rest) {\n for (var i = 0; i < lineView.rest.length; i++) {\n insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false);\n }\n }\n }\n\n function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {\n if (!line.widgets) {\n return;\n }\n\n var wrap = ensureLineWrapped(lineView);\n\n for (var i = 0, ws = line.widgets; i < ws.length; ++i) {\n var widget = ws[i],\n node = elt(\"div\", [widget.node], \"CodeMirror-linewidget\" + (widget.className ? \" \" + widget.className : \"\"));\n\n if (!widget.handleMouseEvents) {\n node.setAttribute(\"cm-ignore-events\", \"true\");\n }\n\n positionLineWidget(widget, node, lineView, dims);\n cm.display.input.setUneditable(node);\n\n if (allowAbove && widget.above) {\n wrap.insertBefore(node, lineView.gutter || lineView.text);\n } else {\n wrap.appendChild(node);\n }\n\n signalLater(widget, \"redraw\");\n }\n }\n\n function positionLineWidget(widget, node, lineView, dims) {\n if (widget.noHScroll) {\n (lineView.alignable || (lineView.alignable = [])).push(node);\n var width = dims.wrapperWidth;\n node.style.left = dims.fixedPos + \"px\";\n\n if (!widget.coverGutter) {\n width -= dims.gutterTotalWidth;\n node.style.paddingLeft = dims.gutterTotalWidth + \"px\";\n }\n\n node.style.width = width + \"px\";\n }\n\n if (widget.coverGutter) {\n node.style.zIndex = 5;\n node.style.position = \"relative\";\n\n if (!widget.noHScroll) {\n node.style.marginLeft = -dims.gutterTotalWidth + \"px\";\n }\n }\n }\n\n function widgetHeight(widget) {\n if (widget.height != null) {\n return widget.height;\n }\n\n var cm = widget.doc.cm;\n\n if (!cm) {\n return 0;\n }\n\n if (!contains(document.body, widget.node)) {\n var parentStyle = \"position: relative;\";\n\n if (widget.coverGutter) {\n parentStyle += \"margin-left: -\" + cm.display.gutters.offsetWidth + \"px;\";\n }\n\n if (widget.noHScroll) {\n parentStyle += \"width: \" + cm.display.wrapper.clientWidth + \"px;\";\n }\n\n removeChildrenAndAdd(cm.display.measure, elt(\"div\", [widget.node], null, parentStyle));\n }\n\n return widget.height = widget.node.parentNode.offsetHeight;\n } // Return true when the given mouse event happened in a widget\n\n\n function eventInWidget(display, e) {\n for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {\n if (!n || n.nodeType == 1 && n.getAttribute(\"cm-ignore-events\") == \"true\" || n.parentNode == display.sizer && n != display.mover) {\n return true;\n }\n }\n } // POSITION MEASUREMENT\n\n\n function paddingTop(display) {\n return display.lineSpace.offsetTop;\n }\n\n function paddingVert(display) {\n return display.mover.offsetHeight - display.lineSpace.offsetHeight;\n }\n\n function paddingH(display) {\n if (display.cachedPaddingH) {\n return display.cachedPaddingH;\n }\n\n var e = removeChildrenAndAdd(display.measure, elt(\"pre\", \"x\", \"CodeMirror-line-like\"));\n var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;\n var data = {\n left: parseInt(style.paddingLeft),\n right: parseInt(style.paddingRight)\n };\n\n if (!isNaN(data.left) && !isNaN(data.right)) {\n display.cachedPaddingH = data;\n }\n\n return data;\n }\n\n function scrollGap(cm) {\n return scrollerGap - cm.display.nativeBarWidth;\n }\n\n function displayWidth(cm) {\n return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;\n }\n\n function displayHeight(cm) {\n return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;\n } // Ensure the lineView.wrapping.heights array is populated. This is\n // an array of bottom offsets for the lines that make up a drawn\n // line. When lineWrapping is on, there might be more than one\n // height.\n\n\n function ensureLineHeights(cm, lineView, rect) {\n var wrapping = cm.options.lineWrapping;\n var curWidth = wrapping && displayWidth(cm);\n\n if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {\n var heights = lineView.measure.heights = [];\n\n if (wrapping) {\n lineView.measure.width = curWidth;\n var rects = lineView.text.firstChild.getClientRects();\n\n for (var i = 0; i < rects.length - 1; i++) {\n var cur = rects[i],\n next = rects[i + 1];\n\n if (Math.abs(cur.bottom - next.bottom) > 2) {\n heights.push((cur.bottom + next.top) / 2 - rect.top);\n }\n }\n }\n\n heights.push(rect.bottom - rect.top);\n }\n } // Find a line map (mapping character offsets to text nodes) and a\n // measurement cache for the given line number. (A line view might\n // contain multiple lines when collapsed ranges are present.)\n\n\n function mapFromLineView(lineView, line, lineN) {\n if (lineView.line == line) {\n return {\n map: lineView.measure.map,\n cache: lineView.measure.cache\n };\n }\n\n for (var i = 0; i < lineView.rest.length; i++) {\n if (lineView.rest[i] == line) {\n return {\n map: lineView.measure.maps[i],\n cache: lineView.measure.caches[i]\n };\n }\n }\n\n for (var i$1 = 0; i$1 < lineView.rest.length; i$1++) {\n if (lineNo(lineView.rest[i$1]) > lineN) {\n return {\n map: lineView.measure.maps[i$1],\n cache: lineView.measure.caches[i$1],\n before: true\n };\n }\n }\n } // Render a line into the hidden node display.externalMeasured. Used\n // when measurement is needed for a line that's not in the viewport.\n\n\n function updateExternalMeasurement(cm, line) {\n line = visualLine(line);\n var lineN = lineNo(line);\n var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);\n view.lineN = lineN;\n var built = view.built = buildLineContent(cm, view);\n view.text = built.pre;\n removeChildrenAndAdd(cm.display.lineMeasure, built.pre);\n return view;\n } // Get a {top, bottom, left, right} box (in line-local coordinates)\n // for a given character.\n\n\n function measureChar(cm, line, ch, bias) {\n return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);\n } // Find a line view that corresponds to the given line number.\n\n\n function findViewForLine(cm, lineN) {\n if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo) {\n return cm.display.view[findViewIndex(cm, lineN)];\n }\n\n var ext = cm.display.externalMeasured;\n\n if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size) {\n return ext;\n }\n } // Measurement can be split in two steps, the set-up work that\n // applies to the whole line, and the measurement of the actual\n // character. Functions like coordsChar, that need to do a lot of\n // measurements in a row, can thus ensure that the set-up work is\n // only done once.\n\n\n function prepareMeasureForLine(cm, line) {\n var lineN = lineNo(line);\n var view = findViewForLine(cm, lineN);\n\n if (view && !view.text) {\n view = null;\n } else if (view && view.changes) {\n updateLineForChanges(cm, view, lineN, getDimensions(cm));\n cm.curOp.forceUpdate = true;\n }\n\n if (!view) {\n view = updateExternalMeasurement(cm, line);\n }\n\n var info = mapFromLineView(view, line, lineN);\n return {\n line: line,\n view: view,\n rect: null,\n map: info.map,\n cache: info.cache,\n before: info.before,\n hasHeights: false\n };\n } // Given a prepared measurement object, measures the position of an\n // actual character (or fetches it from the cache).\n\n\n function measureCharPrepared(cm, prepared, ch, bias, varHeight) {\n if (prepared.before) {\n ch = -1;\n }\n\n var key = ch + (bias || \"\"),\n found;\n\n if (prepared.cache.hasOwnProperty(key)) {\n found = prepared.cache[key];\n } else {\n if (!prepared.rect) {\n prepared.rect = prepared.view.text.getBoundingClientRect();\n }\n\n if (!prepared.hasHeights) {\n ensureLineHeights(cm, prepared.view, prepared.rect);\n prepared.hasHeights = true;\n }\n\n found = measureCharInner(cm, prepared, ch, bias);\n\n if (!found.bogus) {\n prepared.cache[key] = found;\n }\n }\n\n return {\n left: found.left,\n right: found.right,\n top: varHeight ? found.rtop : found.top,\n bottom: varHeight ? found.rbottom : found.bottom\n };\n }\n\n var nullRect = {\n left: 0,\n right: 0,\n top: 0,\n bottom: 0\n };\n\n function nodeAndOffsetInLineMap(map, ch, bias) {\n var node, start, end, collapse, mStart, mEnd; // First, search the line map for the text node corresponding to,\n // or closest to, the target character.\n\n for (var i = 0; i < map.length; i += 3) {\n mStart = map[i];\n mEnd = map[i + 1];\n\n if (ch < mStart) {\n start = 0;\n end = 1;\n collapse = \"left\";\n } else if (ch < mEnd) {\n start = ch - mStart;\n end = start + 1;\n } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {\n end = mEnd - mStart;\n start = end - 1;\n\n if (ch >= mEnd) {\n collapse = \"right\";\n }\n }\n\n if (start != null) {\n node = map[i + 2];\n\n if (mStart == mEnd && bias == (node.insertLeft ? \"left\" : \"right\")) {\n collapse = bias;\n }\n\n if (bias == \"left\" && start == 0) {\n while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {\n node = map[(i -= 3) + 2];\n collapse = \"left\";\n }\n }\n\n if (bias == \"right\" && start == mEnd - mStart) {\n while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {\n node = map[(i += 3) + 2];\n collapse = \"right\";\n }\n }\n\n break;\n }\n }\n\n return {\n node: node,\n start: start,\n end: end,\n collapse: collapse,\n coverStart: mStart,\n coverEnd: mEnd\n };\n }\n\n function getUsefulRect(rects, bias) {\n var rect = nullRect;\n\n if (bias == \"left\") {\n for (var i = 0; i < rects.length; i++) {\n if ((rect = rects[i]).left != rect.right) {\n break;\n }\n }\n } else {\n for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {\n if ((rect = rects[i$1]).left != rect.right) {\n break;\n }\n }\n }\n\n return rect;\n }\n\n function measureCharInner(cm, prepared, ch, bias) {\n var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);\n var node = place.node,\n start = place.start,\n end = place.end,\n collapse = place.collapse;\n var rect;\n\n if (node.nodeType == 3) {\n // If it is a text node, use a range to retrieve the coordinates.\n for (var i$1 = 0; i$1 < 4; i$1++) {\n // Retry a maximum of 4 times when nonsense rectangles are returned\n while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) {\n --start;\n }\n\n while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) {\n ++end;\n }\n\n if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) {\n rect = node.parentNode.getBoundingClientRect();\n } else {\n rect = getUsefulRect(range(node, start, end).getClientRects(), bias);\n }\n\n if (rect.left || rect.right || start == 0) {\n break;\n }\n\n end = start;\n start = start - 1;\n collapse = \"right\";\n }\n\n if (ie && ie_version < 11) {\n rect = maybeUpdateRectForZooming(cm.display.measure, rect);\n }\n } else {\n // If it is a widget, simply get the box for the whole widget.\n if (start > 0) {\n collapse = bias = \"right\";\n }\n\n var rects;\n\n if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1) {\n rect = rects[bias == \"right\" ? rects.length - 1 : 0];\n } else {\n rect = node.getBoundingClientRect();\n }\n }\n\n if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {\n var rSpan = node.parentNode.getClientRects()[0];\n\n if (rSpan) {\n rect = {\n left: rSpan.left,\n right: rSpan.left + charWidth(cm.display),\n top: rSpan.top,\n bottom: rSpan.bottom\n };\n } else {\n rect = nullRect;\n }\n }\n\n var rtop = rect.top - prepared.rect.top,\n rbot = rect.bottom - prepared.rect.top;\n var mid = (rtop + rbot) / 2;\n var heights = prepared.view.measure.heights;\n var i = 0;\n\n for (; i < heights.length - 1; i++) {\n if (mid < heights[i]) {\n break;\n }\n }\n\n var top = i ? heights[i - 1] : 0,\n bot = heights[i];\n var result = {\n left: (collapse == \"right\" ? rect.right : rect.left) - prepared.rect.left,\n right: (collapse == \"left\" ? rect.left : rect.right) - prepared.rect.left,\n top: top,\n bottom: bot\n };\n\n if (!rect.left && !rect.right) {\n result.bogus = true;\n }\n\n if (!cm.options.singleCursorHeightPerLine) {\n result.rtop = rtop;\n result.rbottom = rbot;\n }\n\n return result;\n } // Work around problem with bounding client rects on ranges being\n // returned incorrectly when zoomed on IE10 and below.\n\n\n function maybeUpdateRectForZooming(measure, rect) {\n if (!window.screen || screen.logicalXDPI == null || screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure)) {\n return rect;\n }\n\n var scaleX = screen.logicalXDPI / screen.deviceXDPI;\n var scaleY = screen.logicalYDPI / screen.deviceYDPI;\n return {\n left: rect.left * scaleX,\n right: rect.right * scaleX,\n top: rect.top * scaleY,\n bottom: rect.bottom * scaleY\n };\n }\n\n function clearLineMeasurementCacheFor(lineView) {\n if (lineView.measure) {\n lineView.measure.cache = {};\n lineView.measure.heights = null;\n\n if (lineView.rest) {\n for (var i = 0; i < lineView.rest.length; i++) {\n lineView.measure.caches[i] = {};\n }\n }\n }\n }\n\n function clearLineMeasurementCache(cm) {\n cm.display.externalMeasure = null;\n removeChildren(cm.display.lineMeasure);\n\n for (var i = 0; i < cm.display.view.length; i++) {\n clearLineMeasurementCacheFor(cm.display.view[i]);\n }\n }\n\n function clearCaches(cm) {\n clearLineMeasurementCache(cm);\n cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;\n\n if (!cm.options.lineWrapping) {\n cm.display.maxLineChanged = true;\n }\n\n cm.display.lineNumChars = null;\n }\n\n function pageScrollX() {\n // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206\n // which causes page_Offset and bounding client rects to use\n // different reference viewports and invalidate our calculations.\n if (chrome && android) {\n return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft));\n }\n\n return window.pageXOffset || (document.documentElement || document.body).scrollLeft;\n }\n\n function pageScrollY() {\n if (chrome && android) {\n return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop));\n }\n\n return window.pageYOffset || (document.documentElement || document.body).scrollTop;\n }\n\n function widgetTopHeight(lineObj) {\n var height = 0;\n\n if (lineObj.widgets) {\n for (var i = 0; i < lineObj.widgets.length; ++i) {\n if (lineObj.widgets[i].above) {\n height += widgetHeight(lineObj.widgets[i]);\n }\n }\n }\n\n return height;\n } // Converts a {top, bottom, left, right} box from line-local\n // coordinates into another coordinate system. Context may be one of\n // \"line\", \"div\" (display.lineDiv), \"local\"./null (editor), \"window\",\n // or \"page\".\n\n\n function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {\n if (!includeWidgets) {\n var height = widgetTopHeight(lineObj);\n rect.top += height;\n rect.bottom += height;\n }\n\n if (context == \"line\") {\n return rect;\n }\n\n if (!context) {\n context = \"local\";\n }\n\n var yOff = _heightAtLine(lineObj);\n\n if (context == \"local\") {\n yOff += paddingTop(cm.display);\n } else {\n yOff -= cm.display.viewOffset;\n }\n\n if (context == \"page\" || context == \"window\") {\n var lOff = cm.display.lineSpace.getBoundingClientRect();\n yOff += lOff.top + (context == \"window\" ? 0 : pageScrollY());\n var xOff = lOff.left + (context == \"window\" ? 0 : pageScrollX());\n rect.left += xOff;\n rect.right += xOff;\n }\n\n rect.top += yOff;\n rect.bottom += yOff;\n return rect;\n } // Coverts a box from \"div\" coords to another coordinate system.\n // Context may be \"window\", \"page\", \"div\", or \"local\"./null.\n\n\n function fromCoordSystem(cm, coords, context) {\n if (context == \"div\") {\n return coords;\n }\n\n var left = coords.left,\n top = coords.top; // First move into \"page\" coordinate system\n\n if (context == \"page\") {\n left -= pageScrollX();\n top -= pageScrollY();\n } else if (context == \"local\" || !context) {\n var localBox = cm.display.sizer.getBoundingClientRect();\n left += localBox.left;\n top += localBox.top;\n }\n\n var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();\n return {\n left: left - lineSpaceBox.left,\n top: top - lineSpaceBox.top\n };\n }\n\n function _charCoords(cm, pos, context, lineObj, bias) {\n if (!lineObj) {\n lineObj = getLine(cm.doc, pos.line);\n }\n\n return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);\n } // Returns a box for a given cursor position, which may have an\n // 'other' property containing the position of the secondary cursor\n // on a bidi boundary.\n // A cursor Pos(line, char, \"before\") is on the same visual line as `char - 1`\n // and after `char - 1` in writing order of `char - 1`\n // A cursor Pos(line, char, \"after\") is on the same visual line as `char`\n // and before `char` in writing order of `char`\n // Examples (upper-case letters are RTL, lower-case are LTR):\n // Pos(0, 1, ...)\n // before after\n // ab a|b a|b\n // aB a|B aB|\n // Ab |Ab A|b\n // AB B|A B|A\n // Every position after the last character on a line is considered to stick\n // to the last character on the line.\n\n\n function _cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {\n lineObj = lineObj || getLine(cm.doc, pos.line);\n\n if (!preparedMeasure) {\n preparedMeasure = prepareMeasureForLine(cm, lineObj);\n }\n\n function get(ch, right) {\n var m = measureCharPrepared(cm, preparedMeasure, ch, right ? \"right\" : \"left\", varHeight);\n\n if (right) {\n m.left = m.right;\n } else {\n m.right = m.left;\n }\n\n return intoCoordSystem(cm, lineObj, m, context);\n }\n\n var order = getOrder(lineObj, cm.doc.direction),\n ch = pos.ch,\n sticky = pos.sticky;\n\n if (ch >= lineObj.text.length) {\n ch = lineObj.text.length;\n sticky = \"before\";\n } else if (ch <= 0) {\n ch = 0;\n sticky = \"after\";\n }\n\n if (!order) {\n return get(sticky == \"before\" ? ch - 1 : ch, sticky == \"before\");\n }\n\n function getBidi(ch, partPos, invert) {\n var part = order[partPos],\n right = part.level == 1;\n return get(invert ? ch - 1 : ch, right != invert);\n }\n\n var partPos = getBidiPartAt(order, ch, sticky);\n var other = bidiOther;\n var val = getBidi(ch, partPos, sticky == \"before\");\n\n if (other != null) {\n val.other = getBidi(ch, other, sticky != \"before\");\n }\n\n return val;\n } // Used to cheaply estimate the coordinates for a position. Used for\n // intermediate scroll updates.\n\n\n function estimateCoords(cm, pos) {\n var left = 0;\n pos = _clipPos(cm.doc, pos);\n\n if (!cm.options.lineWrapping) {\n left = charWidth(cm.display) * pos.ch;\n }\n\n var lineObj = getLine(cm.doc, pos.line);\n var top = _heightAtLine(lineObj) + paddingTop(cm.display);\n return {\n left: left,\n right: left,\n top: top,\n bottom: top + lineObj.height\n };\n } // Positions returned by coordsChar contain some extra information.\n // xRel is the relative x position of the input coordinates compared\n // to the found position (so xRel > 0 means the coordinates are to\n // the right of the character position, for example). When outside\n // is true, that means the coordinates lie outside the line's\n // vertical range.\n\n\n function PosWithInfo(line, ch, sticky, outside, xRel) {\n var pos = Pos(line, ch, sticky);\n pos.xRel = xRel;\n\n if (outside) {\n pos.outside = outside;\n }\n\n return pos;\n } // Compute the character position closest to the given coordinates.\n // Input must be lineSpace-local (\"div\" coordinate system).\n\n\n function _coordsChar(cm, x, y) {\n var doc = cm.doc;\n y += cm.display.viewOffset;\n\n if (y < 0) {\n return PosWithInfo(doc.first, 0, null, -1, -1);\n }\n\n var lineN = _lineAtHeight(doc, y),\n last = doc.first + doc.size - 1;\n\n if (lineN > last) {\n return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, 1, 1);\n }\n\n if (x < 0) {\n x = 0;\n }\n\n var lineObj = getLine(doc, lineN);\n\n for (;;) {\n var found = coordsCharInner(cm, lineObj, lineN, x, y);\n var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0));\n\n if (!collapsed) {\n return found;\n }\n\n var rangeEnd = collapsed.find(1);\n\n if (rangeEnd.line == lineN) {\n return rangeEnd;\n }\n\n lineObj = getLine(doc, lineN = rangeEnd.line);\n }\n }\n\n function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {\n y -= widgetTopHeight(lineObj);\n var end = lineObj.text.length;\n var begin = findFirst(function (ch) {\n return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y;\n }, end, 0);\n end = findFirst(function (ch) {\n return measureCharPrepared(cm, preparedMeasure, ch).top > y;\n }, begin, end);\n return {\n begin: begin,\n end: end\n };\n }\n\n function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {\n if (!preparedMeasure) {\n preparedMeasure = prepareMeasureForLine(cm, lineObj);\n }\n\n var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), \"line\").top;\n return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop);\n } // Returns true if the given side of a box is after the given\n // coordinates, in top-to-bottom, left-to-right order.\n\n\n function boxIsAfter(box, x, y, left) {\n return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x;\n }\n\n function coordsCharInner(cm, lineObj, lineNo, x, y) {\n // Move y into line-local coordinate space\n y -= _heightAtLine(lineObj);\n var preparedMeasure = prepareMeasureForLine(cm, lineObj); // When directly calling `measureCharPrepared`, we have to adjust\n // for the widgets at this line.\n\n var widgetHeight = widgetTopHeight(lineObj);\n var begin = 0,\n end = lineObj.text.length,\n ltr = true;\n var order = getOrder(lineObj, cm.doc.direction); // If the line isn't plain left-to-right text, first figure out\n // which bidi section the coordinates fall into.\n\n if (order) {\n var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)(cm, lineObj, lineNo, preparedMeasure, order, x, y);\n ltr = part.level != 1; // The awkward -1 offsets are needed because findFirst (called\n // on these below) will treat its first bound as inclusive,\n // second as exclusive, but we want to actually address the\n // characters in the part's range\n\n begin = ltr ? part.from : part.to - 1;\n end = ltr ? part.to : part.from - 1;\n } // A binary search to find the first character whose bounding box\n // starts after the coordinates. If we run across any whose box wrap\n // the coordinates, store that.\n\n\n var chAround = null,\n boxAround = null;\n var ch = findFirst(function (ch) {\n var box = measureCharPrepared(cm, preparedMeasure, ch);\n box.top += widgetHeight;\n box.bottom += widgetHeight;\n\n if (!boxIsAfter(box, x, y, false)) {\n return false;\n }\n\n if (box.top <= y && box.left <= x) {\n chAround = ch;\n boxAround = box;\n }\n\n return true;\n }, begin, end);\n var baseX,\n sticky,\n outside = false; // If a box around the coordinates was found, use that\n\n if (boxAround) {\n // Distinguish coordinates nearer to the left or right side of the box\n var atLeft = x - boxAround.left < boxAround.right - x,\n atStart = atLeft == ltr;\n ch = chAround + (atStart ? 0 : 1);\n sticky = atStart ? \"after\" : \"before\";\n baseX = atLeft ? boxAround.left : boxAround.right;\n } else {\n // (Adjust for extended bound, if necessary.)\n if (!ltr && (ch == end || ch == begin)) {\n ch++;\n } // To determine which side to associate with, get the box to the\n // left of the character and compare it's vertical position to the\n // coordinates\n\n\n sticky = ch == 0 ? \"after\" : ch == lineObj.text.length ? \"before\" : measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y == ltr ? \"after\" : \"before\"; // Now get accurate coordinates for this place, in order to get a\n // base X position\n\n var coords = _cursorCoords(cm, Pos(lineNo, ch, sticky), \"line\", lineObj, preparedMeasure);\n\n baseX = coords.left;\n outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0;\n }\n\n ch = skipExtendingChars(lineObj.text, ch, 1);\n return PosWithInfo(lineNo, ch, sticky, outside, x - baseX);\n }\n\n function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) {\n // Bidi parts are sorted left-to-right, and in a non-line-wrapping\n // situation, we can take this ordering to correspond to the visual\n // ordering. This finds the first part whose end is after the given\n // coordinates.\n var index = findFirst(function (i) {\n var part = order[i],\n ltr = part.level != 1;\n return boxIsAfter(_cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? \"before\" : \"after\"), \"line\", lineObj, preparedMeasure), x, y, true);\n }, 0, order.length - 1);\n var part = order[index]; // If this isn't the first part, the part's start is also after\n // the coordinates, and the coordinates aren't on the same line as\n // that start, move one part back.\n\n if (index > 0) {\n var ltr = part.level != 1;\n\n var start = _cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? \"after\" : \"before\"), \"line\", lineObj, preparedMeasure);\n\n if (boxIsAfter(start, x, y, true) && start.top > y) {\n part = order[index - 1];\n }\n }\n\n return part;\n }\n\n function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {\n // In a wrapped line, rtl text on wrapping boundaries can do things\n // that don't correspond to the ordering in our `order` array at\n // all, so a binary search doesn't work, and we want to return a\n // part that only spans one line so that the binary search in\n // coordsCharInner is safe. As such, we first find the extent of the\n // wrapped line, and then do a flat search in which we discard any\n // spans that aren't on the line.\n var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);\n var begin = ref.begin;\n var end = ref.end;\n\n if (/\\s/.test(lineObj.text.charAt(end - 1))) {\n end--;\n }\n\n var part = null,\n closestDist = null;\n\n for (var i = 0; i < order.length; i++) {\n var p = order[i];\n\n if (p.from >= end || p.to <= begin) {\n continue;\n }\n\n var ltr = p.level != 1;\n var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right; // Weigh against spans ending before this, so that they are only\n // picked if nothing ends after\n\n var dist = endX < x ? x - endX + 1e9 : endX - x;\n\n if (!part || closestDist > dist) {\n part = p;\n closestDist = dist;\n }\n }\n\n if (!part) {\n part = order[order.length - 1];\n } // Clip the part to the wrapped line.\n\n\n if (part.from < begin) {\n part = {\n from: begin,\n to: part.to,\n level: part.level\n };\n }\n\n if (part.to > end) {\n part = {\n from: part.from,\n to: end,\n level: part.level\n };\n }\n\n return part;\n }\n\n var measureText; // Compute the default text height.\n\n function textHeight(display) {\n if (display.cachedTextHeight != null) {\n return display.cachedTextHeight;\n }\n\n if (measureText == null) {\n measureText = elt(\"pre\", null, \"CodeMirror-line-like\"); // Measure a bunch of lines, for browsers that compute\n // fractional heights.\n\n for (var i = 0; i < 49; ++i) {\n measureText.appendChild(document.createTextNode(\"x\"));\n measureText.appendChild(elt(\"br\"));\n }\n\n measureText.appendChild(document.createTextNode(\"x\"));\n }\n\n removeChildrenAndAdd(display.measure, measureText);\n var height = measureText.offsetHeight / 50;\n\n if (height > 3) {\n display.cachedTextHeight = height;\n }\n\n removeChildren(display.measure);\n return height || 1;\n } // Compute the default character width.\n\n\n function charWidth(display) {\n if (display.cachedCharWidth != null) {\n return display.cachedCharWidth;\n }\n\n var anchor = elt(\"span\", \"xxxxxxxxxx\");\n var pre = elt(\"pre\", [anchor], \"CodeMirror-line-like\");\n removeChildrenAndAdd(display.measure, pre);\n var rect = anchor.getBoundingClientRect(),\n width = (rect.right - rect.left) / 10;\n\n if (width > 2) {\n display.cachedCharWidth = width;\n }\n\n return width || 10;\n } // Do a bulk-read of the DOM positions and sizes needed to draw the\n // view, so that we don't interleave reading and writing to the DOM.\n\n\n function getDimensions(cm) {\n var d = cm.display,\n left = {},\n width = {};\n var gutterLeft = d.gutters.clientLeft;\n\n for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {\n var id = cm.display.gutterSpecs[i].className;\n left[id] = n.offsetLeft + n.clientLeft + gutterLeft;\n width[id] = n.clientWidth;\n }\n\n return {\n fixedPos: compensateForHScroll(d),\n gutterTotalWidth: d.gutters.offsetWidth,\n gutterLeft: left,\n gutterWidth: width,\n wrapperWidth: d.wrapper.clientWidth\n };\n } // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,\n // but using getBoundingClientRect to get a sub-pixel-accurate\n // result.\n\n\n function compensateForHScroll(display) {\n return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;\n } // Returns a function that estimates the height of a line, to use as\n // first approximation until the line becomes visible (and is thus\n // properly measurable).\n\n\n function estimateHeight(cm) {\n var th = textHeight(cm.display),\n wrapping = cm.options.lineWrapping;\n var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);\n return function (line) {\n if (lineIsHidden(cm.doc, line)) {\n return 0;\n }\n\n var widgetsHeight = 0;\n\n if (line.widgets) {\n for (var i = 0; i < line.widgets.length; i++) {\n if (line.widgets[i].height) {\n widgetsHeight += line.widgets[i].height;\n }\n }\n }\n\n if (wrapping) {\n return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;\n } else {\n return widgetsHeight + th;\n }\n };\n }\n\n function estimateLineHeights(cm) {\n var doc = cm.doc,\n est = estimateHeight(cm);\n doc.iter(function (line) {\n var estHeight = est(line);\n\n if (estHeight != line.height) {\n updateLineHeight(line, estHeight);\n }\n });\n } // Given a mouse event, find the corresponding position. If liberal\n // is false, it checks whether a gutter or scrollbar was clicked,\n // and returns null if it was. forRect is used by rectangular\n // selections, and tries to estimate a character position even for\n // coordinates beyond the right of the text.\n\n\n function posFromMouse(cm, e, liberal, forRect) {\n var display = cm.display;\n\n if (!liberal && e_target(e).getAttribute(\"cm-not-content\") == \"true\") {\n return null;\n }\n\n var x,\n y,\n space = display.lineSpace.getBoundingClientRect(); // Fails unpredictably on IE[67] when mouse is dragged around quickly.\n\n try {\n x = e.clientX - space.left;\n y = e.clientY - space.top;\n } catch (e$1) {\n return null;\n }\n\n var coords = _coordsChar(cm, x, y),\n line;\n\n if (forRect && coords.xRel > 0 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {\n var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;\n coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));\n }\n\n return coords;\n } // Find the view element corresponding to a given line. Return null\n // when the line isn't visible.\n\n\n function findViewIndex(cm, n) {\n if (n >= cm.display.viewTo) {\n return null;\n }\n\n n -= cm.display.viewFrom;\n\n if (n < 0) {\n return null;\n }\n\n var view = cm.display.view;\n\n for (var i = 0; i < view.length; i++) {\n n -= view[i].size;\n\n if (n < 0) {\n return i;\n }\n }\n } // Updates the display.view data structure for a given change to the\n // document. From and to are in pre-change coordinates. Lendiff is\n // the amount of lines added or subtracted by the change. This is\n // used for changes that span multiple lines, or change the way\n // lines are divided into visual lines. regLineChange (below)\n // registers single-line changes.\n\n\n function regChange(cm, from, to, lendiff) {\n if (from == null) {\n from = cm.doc.first;\n }\n\n if (to == null) {\n to = cm.doc.first + cm.doc.size;\n }\n\n if (!lendiff) {\n lendiff = 0;\n }\n\n var display = cm.display;\n\n if (lendiff && to < display.viewTo && (display.updateLineNumbers == null || display.updateLineNumbers > from)) {\n display.updateLineNumbers = from;\n }\n\n cm.curOp.viewChanged = true;\n\n if (from >= display.viewTo) {\n // Change after\n if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo) {\n resetView(cm);\n }\n } else if (to <= display.viewFrom) {\n // Change before\n if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {\n resetView(cm);\n } else {\n display.viewFrom += lendiff;\n display.viewTo += lendiff;\n }\n } else if (from <= display.viewFrom && to >= display.viewTo) {\n // Full overlap\n resetView(cm);\n } else if (from <= display.viewFrom) {\n // Top overlap\n var cut = viewCuttingPoint(cm, to, to + lendiff, 1);\n\n if (cut) {\n display.view = display.view.slice(cut.index);\n display.viewFrom = cut.lineN;\n display.viewTo += lendiff;\n } else {\n resetView(cm);\n }\n } else if (to >= display.viewTo) {\n // Bottom overlap\n var cut$1 = viewCuttingPoint(cm, from, from, -1);\n\n if (cut$1) {\n display.view = display.view.slice(0, cut$1.index);\n display.viewTo = cut$1.lineN;\n } else {\n resetView(cm);\n }\n } else {\n // Gap in the middle\n var cutTop = viewCuttingPoint(cm, from, from, -1);\n var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);\n\n if (cutTop && cutBot) {\n display.view = display.view.slice(0, cutTop.index).concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN)).concat(display.view.slice(cutBot.index));\n display.viewTo += lendiff;\n } else {\n resetView(cm);\n }\n }\n\n var ext = display.externalMeasured;\n\n if (ext) {\n if (to < ext.lineN) {\n ext.lineN += lendiff;\n } else if (from < ext.lineN + ext.size) {\n display.externalMeasured = null;\n }\n }\n } // Register a change to a single line. Type must be one of \"text\",\n // \"gutter\", \"class\", \"widget\"\n\n\n function regLineChange(cm, line, type) {\n cm.curOp.viewChanged = true;\n var display = cm.display,\n ext = cm.display.externalMeasured;\n\n if (ext && line >= ext.lineN && line < ext.lineN + ext.size) {\n display.externalMeasured = null;\n }\n\n if (line < display.viewFrom || line >= display.viewTo) {\n return;\n }\n\n var lineView = display.view[findViewIndex(cm, line)];\n\n if (lineView.node == null) {\n return;\n }\n\n var arr = lineView.changes || (lineView.changes = []);\n\n if (indexOf(arr, type) == -1) {\n arr.push(type);\n }\n } // Clear the view.\n\n\n function resetView(cm) {\n cm.display.viewFrom = cm.display.viewTo = cm.doc.first;\n cm.display.view = [];\n cm.display.viewOffset = 0;\n }\n\n function viewCuttingPoint(cm, oldN, newN, dir) {\n var index = findViewIndex(cm, oldN),\n diff,\n view = cm.display.view;\n\n if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size) {\n return {\n index: index,\n lineN: newN\n };\n }\n\n var n = cm.display.viewFrom;\n\n for (var i = 0; i < index; i++) {\n n += view[i].size;\n }\n\n if (n != oldN) {\n if (dir > 0) {\n if (index == view.length - 1) {\n return null;\n }\n\n diff = n + view[index].size - oldN;\n index++;\n } else {\n diff = n - oldN;\n }\n\n oldN += diff;\n newN += diff;\n }\n\n while (visualLineNo(cm.doc, newN) != newN) {\n if (index == (dir < 0 ? 0 : view.length - 1)) {\n return null;\n }\n\n newN += dir * view[index - (dir < 0 ? 1 : 0)].size;\n index += dir;\n }\n\n return {\n index: index,\n lineN: newN\n };\n } // Force the view to cover a given range, adding empty view element\n // or clipping off existing ones as needed.\n\n\n function adjustView(cm, from, to) {\n var display = cm.display,\n view = display.view;\n\n if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {\n display.view = buildViewArray(cm, from, to);\n display.viewFrom = from;\n } else {\n if (display.viewFrom > from) {\n display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);\n } else if (display.viewFrom < from) {\n display.view = display.view.slice(findViewIndex(cm, from));\n }\n\n display.viewFrom = from;\n\n if (display.viewTo < to) {\n display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));\n } else if (display.viewTo > to) {\n display.view = display.view.slice(0, findViewIndex(cm, to));\n }\n }\n\n display.viewTo = to;\n } // Count the number of lines in the view whose DOM representation is\n // out of date (or nonexistent).\n\n\n function countDirtyView(cm) {\n var view = cm.display.view,\n dirty = 0;\n\n for (var i = 0; i < view.length; i++) {\n var lineView = view[i];\n\n if (!lineView.hidden && (!lineView.node || lineView.changes)) {\n ++dirty;\n }\n }\n\n return dirty;\n }\n\n function updateSelection(cm) {\n cm.display.input.showSelection(cm.display.input.prepareSelection());\n }\n\n function prepareSelection(cm, primary) {\n if (primary === void 0) primary = true;\n var doc = cm.doc,\n result = {};\n var curFragment = result.cursors = document.createDocumentFragment();\n var selFragment = result.selection = document.createDocumentFragment();\n\n for (var i = 0; i < doc.sel.ranges.length; i++) {\n if (!primary && i == doc.sel.primIndex) {\n continue;\n }\n\n var range = doc.sel.ranges[i];\n\n if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) {\n continue;\n }\n\n var collapsed = range.empty();\n\n if (collapsed || cm.options.showCursorWhenSelecting) {\n drawSelectionCursor(cm, range.head, curFragment);\n }\n\n if (!collapsed) {\n drawSelectionRange(cm, range, selFragment);\n }\n }\n\n return result;\n } // Draws a cursor for the given range\n\n\n function drawSelectionCursor(cm, head, output) {\n var pos = _cursorCoords(cm, head, \"div\", null, null, !cm.options.singleCursorHeightPerLine);\n\n var cursor = output.appendChild(elt(\"div\", \"\\xA0\", \"CodeMirror-cursor\"));\n cursor.style.left = pos.left + \"px\";\n cursor.style.top = pos.top + \"px\";\n cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + \"px\";\n\n if (pos.other) {\n // Secondary cursor, shown when on a 'jump' in bi-directional text\n var otherCursor = output.appendChild(elt(\"div\", \"\\xA0\", \"CodeMirror-cursor CodeMirror-secondarycursor\"));\n otherCursor.style.display = \"\";\n otherCursor.style.left = pos.other.left + \"px\";\n otherCursor.style.top = pos.other.top + \"px\";\n otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + \"px\";\n }\n }\n\n function cmpCoords(a, b) {\n return a.top - b.top || a.left - b.left;\n } // Draws the given range as a highlighted selection\n\n\n function drawSelectionRange(cm, range, output) {\n var display = cm.display,\n doc = cm.doc;\n var fragment = document.createDocumentFragment();\n var padding = paddingH(cm.display),\n leftSide = padding.left;\n var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;\n var docLTR = doc.direction == \"ltr\";\n\n function add(left, top, width, bottom) {\n if (top < 0) {\n top = 0;\n }\n\n top = Math.round(top);\n bottom = Math.round(bottom);\n 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\"));\n }\n\n function drawForLine(line, fromArg, toArg) {\n var lineObj = getLine(doc, line);\n var lineLen = lineObj.text.length;\n var start, end;\n\n function coords(ch, bias) {\n return _charCoords(cm, Pos(line, ch), \"div\", lineObj, bias);\n }\n\n function wrapX(pos, dir, side) {\n var extent = wrappedLineExtentChar(cm, lineObj, null, pos);\n var prop = dir == \"ltr\" == (side == \"after\") ? \"left\" : \"right\";\n var ch = side == \"after\" ? extent.begin : extent.end - (/\\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);\n return coords(ch, prop)[prop];\n }\n\n var order = getOrder(lineObj, doc.direction);\n iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {\n var ltr = dir == \"ltr\";\n var fromPos = coords(from, ltr ? \"left\" : \"right\");\n var toPos = coords(to - 1, ltr ? \"right\" : \"left\");\n var openStart = fromArg == null && from == 0,\n openEnd = toArg == null && to == lineLen;\n var first = i == 0,\n last = !order || i == order.length - 1;\n\n if (toPos.top - fromPos.top <= 3) {\n // Single line\n var openLeft = (docLTR ? openStart : openEnd) && first;\n var openRight = (docLTR ? openEnd : openStart) && last;\n var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;\n var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;\n add(left, fromPos.top, right - left, fromPos.bottom);\n } else {\n // Multiple lines\n var topLeft, topRight, botLeft, botRight;\n\n if (ltr) {\n topLeft = docLTR && openStart && first ? leftSide : fromPos.left;\n topRight = docLTR ? rightSide : wrapX(from, dir, \"before\");\n botLeft = docLTR ? leftSide : wrapX(to, dir, \"after\");\n botRight = docLTR && openEnd && last ? rightSide : toPos.right;\n } else {\n topLeft = !docLTR ? leftSide : wrapX(from, dir, \"before\");\n topRight = !docLTR && openStart && first ? rightSide : fromPos.right;\n botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;\n botRight = !docLTR ? rightSide : wrapX(to, dir, \"after\");\n }\n\n add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);\n\n if (fromPos.bottom < toPos.top) {\n add(leftSide, fromPos.bottom, null, toPos.top);\n }\n\n add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);\n }\n\n if (!start || cmpCoords(fromPos, start) < 0) {\n start = fromPos;\n }\n\n if (cmpCoords(toPos, start) < 0) {\n start = toPos;\n }\n\n if (!end || cmpCoords(fromPos, end) < 0) {\n end = fromPos;\n }\n\n if (cmpCoords(toPos, end) < 0) {\n end = toPos;\n }\n });\n return {\n start: start,\n end: end\n };\n }\n\n var sFrom = range.from(),\n sTo = range.to();\n\n if (sFrom.line == sTo.line) {\n drawForLine(sFrom.line, sFrom.ch, sTo.ch);\n } else {\n var fromLine = getLine(doc, sFrom.line),\n toLine = getLine(doc, sTo.line);\n var singleVLine = visualLine(fromLine) == visualLine(toLine);\n var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;\n var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;\n\n if (singleVLine) {\n if (leftEnd.top < rightStart.top - 2) {\n add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);\n add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);\n } else {\n add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);\n }\n }\n\n if (leftEnd.bottom < rightStart.top) {\n add(leftSide, leftEnd.bottom, null, rightStart.top);\n }\n }\n\n output.appendChild(fragment);\n } // Cursor-blinking\n\n\n function restartBlink(cm) {\n if (!cm.state.focused) {\n return;\n }\n\n var display = cm.display;\n clearInterval(display.blinker);\n var on = true;\n display.cursorDiv.style.visibility = \"\";\n\n if (cm.options.cursorBlinkRate > 0) {\n display.blinker = setInterval(function () {\n if (!cm.hasFocus()) {\n onBlur(cm);\n }\n\n display.cursorDiv.style.visibility = (on = !on) ? \"\" : \"hidden\";\n }, cm.options.cursorBlinkRate);\n } else if (cm.options.cursorBlinkRate < 0) {\n display.cursorDiv.style.visibility = \"hidden\";\n }\n }\n\n function ensureFocus(cm) {\n if (!cm.state.focused) {\n cm.display.input.focus();\n onFocus(cm);\n }\n }\n\n function delayBlurEvent(cm) {\n cm.state.delayingBlurEvent = true;\n setTimeout(function () {\n if (cm.state.delayingBlurEvent) {\n cm.state.delayingBlurEvent = false;\n onBlur(cm);\n }\n }, 100);\n }\n\n function onFocus(cm, e) {\n if (cm.state.delayingBlurEvent) {\n cm.state.delayingBlurEvent = false;\n }\n\n if (cm.options.readOnly == \"nocursor\") {\n return;\n }\n\n if (!cm.state.focused) {\n signal(cm, \"focus\", cm, e);\n cm.state.focused = true;\n addClass(cm.display.wrapper, \"CodeMirror-focused\"); // This test prevents this from firing when a context\n // menu is closed (since the input reset would kill the\n // select-all detection hack)\n\n if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {\n cm.display.input.reset();\n\n if (webkit) {\n setTimeout(function () {\n return cm.display.input.reset(true);\n }, 20);\n } // Issue #1730\n\n }\n\n cm.display.input.receivedFocus();\n }\n\n restartBlink(cm);\n }\n\n function onBlur(cm, e) {\n if (cm.state.delayingBlurEvent) {\n return;\n }\n\n if (cm.state.focused) {\n signal(cm, \"blur\", cm, e);\n cm.state.focused = false;\n rmClass(cm.display.wrapper, \"CodeMirror-focused\");\n }\n\n clearInterval(cm.display.blinker);\n setTimeout(function () {\n if (!cm.state.focused) {\n cm.display.shift = false;\n }\n }, 150);\n } // Read the actual heights of the rendered lines, and update their\n // stored heights to match.\n\n\n function updateHeightsInViewport(cm) {\n var display = cm.display;\n var prevBottom = display.lineDiv.offsetTop;\n\n for (var i = 0; i < display.view.length; i++) {\n var cur = display.view[i],\n wrapping = cm.options.lineWrapping;\n var height = void 0,\n width = 0;\n\n if (cur.hidden) {\n continue;\n }\n\n if (ie && ie_version < 8) {\n var bot = cur.node.offsetTop + cur.node.offsetHeight;\n height = bot - prevBottom;\n prevBottom = bot;\n } else {\n var box = cur.node.getBoundingClientRect();\n height = box.bottom - box.top; // Check that lines don't extend past the right of the current\n // editor width\n\n if (!wrapping && cur.text.firstChild) {\n width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1;\n }\n }\n\n var diff = cur.line.height - height;\n\n if (diff > .005 || diff < -.005) {\n updateLineHeight(cur.line, height);\n updateWidgetHeight(cur.line);\n\n if (cur.rest) {\n for (var j = 0; j < cur.rest.length; j++) {\n updateWidgetHeight(cur.rest[j]);\n }\n }\n }\n\n if (width > cm.display.sizerWidth) {\n var chWidth = Math.ceil(width / charWidth(cm.display));\n\n if (chWidth > cm.display.maxLineLength) {\n cm.display.maxLineLength = chWidth;\n cm.display.maxLine = cur.line;\n cm.display.maxLineChanged = true;\n }\n }\n }\n } // Read and store the height of line widgets associated with the\n // given line.\n\n\n function updateWidgetHeight(line) {\n if (line.widgets) {\n for (var i = 0; i < line.widgets.length; ++i) {\n var w = line.widgets[i],\n parent = w.node.parentNode;\n\n if (parent) {\n w.height = parent.offsetHeight;\n }\n }\n }\n } // Compute the lines that are visible in a given viewport (defaults\n // the the current scroll position). viewport may contain top,\n // height, and ensure (see op.scrollToPos) properties.\n\n\n function visibleLines(display, doc, viewport) {\n var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;\n top = Math.floor(top - paddingTop(display));\n var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;\n\n var from = _lineAtHeight(doc, top),\n to = _lineAtHeight(doc, bottom); // Ensure is a {from: {line, ch}, to: {line, ch}} object, and\n // forces those lines into the viewport (if possible).\n\n\n if (viewport && viewport.ensure) {\n var ensureFrom = viewport.ensure.from.line,\n ensureTo = viewport.ensure.to.line;\n\n if (ensureFrom < from) {\n from = ensureFrom;\n to = _lineAtHeight(doc, _heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);\n } else if (Math.min(ensureTo, doc.lastLine()) >= to) {\n from = _lineAtHeight(doc, _heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);\n to = ensureTo;\n }\n }\n\n return {\n from: from,\n to: Math.max(to, from + 1)\n };\n } // SCROLLING THINGS INTO VIEW\n // If an editor sits on the top or bottom of the window, partially\n // scrolled out of view, this ensures that the cursor is visible.\n\n\n function maybeScrollWindow(cm, rect) {\n if (signalDOMEvent(cm, \"scrollCursorIntoView\")) {\n return;\n }\n\n var display = cm.display,\n box = display.sizer.getBoundingClientRect(),\n doScroll = null;\n\n if (rect.top + box.top < 0) {\n doScroll = true;\n } else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) {\n doScroll = false;\n }\n\n if (doScroll != null && !phantom) {\n 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;\");\n cm.display.lineSpace.appendChild(scrollNode);\n scrollNode.scrollIntoView(doScroll);\n cm.display.lineSpace.removeChild(scrollNode);\n }\n } // Scroll a given position into view (immediately), verifying that\n // it actually became visible (as line heights are accurately\n // measured, the position of something may 'drift' during drawing).\n\n\n function scrollPosIntoView(cm, pos, end, margin) {\n if (margin == null) {\n margin = 0;\n }\n\n var rect;\n\n if (!cm.options.lineWrapping && pos == end) {\n // Set pos and end to the cursor positions around the character pos sticks to\n // If pos.sticky == \"before\", that is around pos.ch - 1, otherwise around pos.ch\n // If pos == Pos(_, 0, \"before\"), pos and end are unchanged\n pos = pos.ch ? Pos(pos.line, pos.sticky == \"before\" ? pos.ch - 1 : pos.ch, \"after\") : pos;\n end = pos.sticky == \"before\" ? Pos(pos.line, pos.ch + 1, \"before\") : pos;\n }\n\n for (var limit = 0; limit < 5; limit++) {\n var changed = false;\n\n var coords = _cursorCoords(cm, pos);\n\n var endCoords = !end || end == pos ? coords : _cursorCoords(cm, end);\n rect = {\n left: Math.min(coords.left, endCoords.left),\n top: Math.min(coords.top, endCoords.top) - margin,\n right: Math.max(coords.left, endCoords.left),\n bottom: Math.max(coords.bottom, endCoords.bottom) + margin\n };\n var scrollPos = calculateScrollPos(cm, rect);\n var startTop = cm.doc.scrollTop,\n startLeft = cm.doc.scrollLeft;\n\n if (scrollPos.scrollTop != null) {\n updateScrollTop(cm, scrollPos.scrollTop);\n\n if (Math.abs(cm.doc.scrollTop - startTop) > 1) {\n changed = true;\n }\n }\n\n if (scrollPos.scrollLeft != null) {\n setScrollLeft(cm, scrollPos.scrollLeft);\n\n if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) {\n changed = true;\n }\n }\n\n if (!changed) {\n break;\n }\n }\n\n return rect;\n } // Scroll a given set of coordinates into view (immediately).\n\n\n function scrollIntoView(cm, rect) {\n var scrollPos = calculateScrollPos(cm, rect);\n\n if (scrollPos.scrollTop != null) {\n updateScrollTop(cm, scrollPos.scrollTop);\n }\n\n if (scrollPos.scrollLeft != null) {\n setScrollLeft(cm, scrollPos.scrollLeft);\n }\n } // Calculate a new scroll position needed to scroll the given\n // rectangle into view. Returns an object with scrollTop and\n // scrollLeft properties. When these are undefined, the\n // vertical/horizontal position does not need to be adjusted.\n\n\n function calculateScrollPos(cm, rect) {\n var display = cm.display,\n snapMargin = textHeight(cm.display);\n\n if (rect.top < 0) {\n rect.top = 0;\n }\n\n var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;\n var screen = displayHeight(cm),\n result = {};\n\n if (rect.bottom - rect.top > screen) {\n rect.bottom = rect.top + screen;\n }\n\n var docBottom = cm.doc.height + paddingVert(display);\n var atTop = rect.top < snapMargin,\n atBottom = rect.bottom > docBottom - snapMargin;\n\n if (rect.top < screentop) {\n result.scrollTop = atTop ? 0 : rect.top;\n } else if (rect.bottom > screentop + screen) {\n var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);\n\n if (newTop != screentop) {\n result.scrollTop = newTop;\n }\n }\n\n var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;\n var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);\n var tooWide = rect.right - rect.left > screenw;\n\n if (tooWide) {\n rect.right = rect.left + screenw;\n }\n\n if (rect.left < 10) {\n result.scrollLeft = 0;\n } else if (rect.left < screenleft) {\n result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10));\n } else if (rect.right > screenw + screenleft - 3) {\n result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw;\n }\n\n return result;\n } // Store a relative adjustment to the scroll position in the current\n // operation (to be applied when the operation finishes).\n\n\n function addToScrollTop(cm, top) {\n if (top == null) {\n return;\n }\n\n resolveScrollToPos(cm);\n cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;\n } // Make sure that at the end of the operation the current cursor is\n // shown.\n\n\n function ensureCursorVisible(cm) {\n resolveScrollToPos(cm);\n var cur = cm.getCursor();\n cm.curOp.scrollToPos = {\n from: cur,\n to: cur,\n margin: cm.options.cursorScrollMargin\n };\n }\n\n function scrollToCoords(cm, x, y) {\n if (x != null || y != null) {\n resolveScrollToPos(cm);\n }\n\n if (x != null) {\n cm.curOp.scrollLeft = x;\n }\n\n if (y != null) {\n cm.curOp.scrollTop = y;\n }\n }\n\n function scrollToRange(cm, range) {\n resolveScrollToPos(cm);\n cm.curOp.scrollToPos = range;\n } // When an operation has its scrollToPos property set, and another\n // scroll action is applied before the end of the operation, this\n // 'simulates' scrolling that position into view in a cheap way, so\n // that the effect of intermediate scroll commands is not ignored.\n\n\n function resolveScrollToPos(cm) {\n var range = cm.curOp.scrollToPos;\n\n if (range) {\n cm.curOp.scrollToPos = null;\n var from = estimateCoords(cm, range.from),\n to = estimateCoords(cm, range.to);\n scrollToCoordsRange(cm, from, to, range.margin);\n }\n }\n\n function scrollToCoordsRange(cm, from, to, margin) {\n var sPos = calculateScrollPos(cm, {\n left: Math.min(from.left, to.left),\n top: Math.min(from.top, to.top) - margin,\n right: Math.max(from.right, to.right),\n bottom: Math.max(from.bottom, to.bottom) + margin\n });\n scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);\n } // Sync the scrollable area and scrollbars, ensure the viewport\n // covers the visible area.\n\n\n function updateScrollTop(cm, val) {\n if (Math.abs(cm.doc.scrollTop - val) < 2) {\n return;\n }\n\n if (!gecko) {\n updateDisplaySimple(cm, {\n top: val\n });\n }\n\n setScrollTop(cm, val, true);\n\n if (gecko) {\n updateDisplaySimple(cm);\n }\n\n startWorker(cm, 100);\n }\n\n function setScrollTop(cm, val, forceScroll) {\n val = Math.max(0, Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val));\n\n if (cm.display.scroller.scrollTop == val && !forceScroll) {\n return;\n }\n\n cm.doc.scrollTop = val;\n cm.display.scrollbars.setScrollTop(val);\n\n if (cm.display.scroller.scrollTop != val) {\n cm.display.scroller.scrollTop = val;\n }\n } // Sync scroller and scrollbar, ensure the gutter elements are\n // aligned.\n\n\n function setScrollLeft(cm, val, isScroller, forceScroll) {\n val = Math.max(0, Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth));\n\n if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) {\n return;\n }\n\n cm.doc.scrollLeft = val;\n alignHorizontally(cm);\n\n if (cm.display.scroller.scrollLeft != val) {\n cm.display.scroller.scrollLeft = val;\n }\n\n cm.display.scrollbars.setScrollLeft(val);\n } // SCROLLBARS\n // Prepare DOM reads needed to update the scrollbars. Done in one\n // shot to minimize update/measure roundtrips.\n\n\n function measureForScrollbars(cm) {\n var d = cm.display,\n gutterW = d.gutters.offsetWidth;\n var docH = Math.round(cm.doc.height + paddingVert(cm.display));\n return {\n clientHeight: d.scroller.clientHeight,\n viewHeight: d.wrapper.clientHeight,\n scrollWidth: d.scroller.scrollWidth,\n clientWidth: d.scroller.clientWidth,\n viewWidth: d.wrapper.clientWidth,\n barLeft: cm.options.fixedGutter ? gutterW : 0,\n docHeight: docH,\n scrollHeight: docH + scrollGap(cm) + d.barHeight,\n nativeBarWidth: d.nativeBarWidth,\n gutterWidth: gutterW\n };\n }\n\n var NativeScrollbars = function NativeScrollbars(place, scroll, cm) {\n this.cm = cm;\n var vert = this.vert = elt(\"div\", [elt(\"div\", null, null, \"min-width: 1px\")], \"CodeMirror-vscrollbar\");\n var horiz = this.horiz = elt(\"div\", [elt(\"div\", null, null, \"height: 100%; min-height: 1px\")], \"CodeMirror-hscrollbar\");\n vert.tabIndex = horiz.tabIndex = -1;\n place(vert);\n place(horiz);\n on(vert, \"scroll\", function () {\n if (vert.clientHeight) {\n scroll(vert.scrollTop, \"vertical\");\n }\n });\n on(horiz, \"scroll\", function () {\n if (horiz.clientWidth) {\n scroll(horiz.scrollLeft, \"horizontal\");\n }\n });\n this.checkedZeroWidth = false; // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).\n\n if (ie && ie_version < 8) {\n this.horiz.style.minHeight = this.vert.style.minWidth = \"18px\";\n }\n };\n\n NativeScrollbars.prototype.update = function (measure) {\n var needsH = measure.scrollWidth > measure.clientWidth + 1;\n var needsV = measure.scrollHeight > measure.clientHeight + 1;\n var sWidth = measure.nativeBarWidth;\n\n if (needsV) {\n this.vert.style.display = \"block\";\n this.vert.style.bottom = needsH ? sWidth + \"px\" : \"0\";\n var totalHeight = measure.viewHeight - (needsH ? sWidth : 0); // A bug in IE8 can cause this value to be negative, so guard it.\n\n this.vert.firstChild.style.height = Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + \"px\";\n } else {\n this.vert.style.display = \"\";\n this.vert.firstChild.style.height = \"0\";\n }\n\n if (needsH) {\n this.horiz.style.display = \"block\";\n this.horiz.style.right = needsV ? sWidth + \"px\" : \"0\";\n this.horiz.style.left = measure.barLeft + \"px\";\n var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);\n this.horiz.firstChild.style.width = Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + \"px\";\n } else {\n this.horiz.style.display = \"\";\n this.horiz.firstChild.style.width = \"0\";\n }\n\n if (!this.checkedZeroWidth && measure.clientHeight > 0) {\n if (sWidth == 0) {\n this.zeroWidthHack();\n }\n\n this.checkedZeroWidth = true;\n }\n\n return {\n right: needsV ? sWidth : 0,\n bottom: needsH ? sWidth : 0\n };\n };\n\n NativeScrollbars.prototype.setScrollLeft = function (pos) {\n if (this.horiz.scrollLeft != pos) {\n this.horiz.scrollLeft = pos;\n }\n\n if (this.disableHoriz) {\n this.enableZeroWidthBar(this.horiz, this.disableHoriz, \"horiz\");\n }\n };\n\n NativeScrollbars.prototype.setScrollTop = function (pos) {\n if (this.vert.scrollTop != pos) {\n this.vert.scrollTop = pos;\n }\n\n if (this.disableVert) {\n this.enableZeroWidthBar(this.vert, this.disableVert, \"vert\");\n }\n };\n\n NativeScrollbars.prototype.zeroWidthHack = function () {\n var w = mac && !mac_geMountainLion ? \"12px\" : \"18px\";\n this.horiz.style.height = this.vert.style.width = w;\n this.horiz.style.pointerEvents = this.vert.style.pointerEvents = \"none\";\n this.disableHoriz = new Delayed();\n this.disableVert = new Delayed();\n };\n\n NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {\n bar.style.pointerEvents = \"auto\";\n\n function maybeDisable() {\n // To find out whether the scrollbar is still visible, we\n // check whether the element under the pixel in the bottom\n // right corner of the scrollbar box is the scrollbar box\n // itself (when the bar is still visible) or its filler child\n // (when the bar is hidden). If it is still visible, we keep\n // it enabled, if it's hidden, we disable pointer events.\n var box = bar.getBoundingClientRect();\n var elt = type == \"vert\" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2) : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);\n\n if (elt != bar) {\n bar.style.pointerEvents = \"none\";\n } else {\n delay.set(1000, maybeDisable);\n }\n }\n\n delay.set(1000, maybeDisable);\n };\n\n NativeScrollbars.prototype.clear = function () {\n var parent = this.horiz.parentNode;\n parent.removeChild(this.horiz);\n parent.removeChild(this.vert);\n };\n\n var NullScrollbars = function NullScrollbars() {};\n\n NullScrollbars.prototype.update = function () {\n return {\n bottom: 0,\n right: 0\n };\n };\n\n NullScrollbars.prototype.setScrollLeft = function () {};\n\n NullScrollbars.prototype.setScrollTop = function () {};\n\n NullScrollbars.prototype.clear = function () {};\n\n function updateScrollbars(cm, measure) {\n if (!measure) {\n measure = measureForScrollbars(cm);\n }\n\n var startWidth = cm.display.barWidth,\n startHeight = cm.display.barHeight;\n updateScrollbarsInner(cm, measure);\n\n for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {\n if (startWidth != cm.display.barWidth && cm.options.lineWrapping) {\n updateHeightsInViewport(cm);\n }\n\n updateScrollbarsInner(cm, measureForScrollbars(cm));\n startWidth = cm.display.barWidth;\n startHeight = cm.display.barHeight;\n }\n } // Re-synchronize the fake scrollbars with the actual size of the\n // content.\n\n\n function updateScrollbarsInner(cm, measure) {\n var d = cm.display;\n var sizes = d.scrollbars.update(measure);\n d.sizer.style.paddingRight = (d.barWidth = sizes.right) + \"px\";\n d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + \"px\";\n d.heightForcer.style.borderBottom = sizes.bottom + \"px solid transparent\";\n\n if (sizes.right && sizes.bottom) {\n d.scrollbarFiller.style.display = \"block\";\n d.scrollbarFiller.style.height = sizes.bottom + \"px\";\n d.scrollbarFiller.style.width = sizes.right + \"px\";\n } else {\n d.scrollbarFiller.style.display = \"\";\n }\n\n if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {\n d.gutterFiller.style.display = \"block\";\n d.gutterFiller.style.height = sizes.bottom + \"px\";\n d.gutterFiller.style.width = measure.gutterWidth + \"px\";\n } else {\n d.gutterFiller.style.display = \"\";\n }\n }\n\n var scrollbarModel = {\n \"native\": NativeScrollbars,\n \"null\": NullScrollbars\n };\n\n function initScrollbars(cm) {\n if (cm.display.scrollbars) {\n cm.display.scrollbars.clear();\n\n if (cm.display.scrollbars.addClass) {\n rmClass(cm.display.wrapper, cm.display.scrollbars.addClass);\n }\n }\n\n cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {\n cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller); // Prevent clicks in the scrollbars from killing focus\n\n on(node, \"mousedown\", function () {\n if (cm.state.focused) {\n setTimeout(function () {\n return cm.display.input.focus();\n }, 0);\n }\n });\n node.setAttribute(\"cm-not-content\", \"true\");\n }, function (pos, axis) {\n if (axis == \"horizontal\") {\n setScrollLeft(cm, pos);\n } else {\n updateScrollTop(cm, pos);\n }\n }, cm);\n\n if (cm.display.scrollbars.addClass) {\n addClass(cm.display.wrapper, cm.display.scrollbars.addClass);\n }\n } // Operations are used to wrap a series of changes to the editor\n // state in such a way that each change won't have to update the\n // cursor and display (which would be awkward, slow, and\n // error-prone). Instead, display updates are batched and then all\n // combined and executed at once.\n\n\n var nextOpId = 0; // Start a new operation.\n\n function _startOperation(cm) {\n cm.curOp = {\n cm: cm,\n viewChanged: false,\n // Flag that indicates that lines might need to be redrawn\n startHeight: cm.doc.height,\n // Used to detect need to update scrollbar\n forceUpdate: false,\n // Used to force a redraw\n updateInput: 0,\n // Whether to reset the input textarea\n typing: false,\n // Whether this reset should be careful to leave existing text (for compositing)\n changeObjs: null,\n // Accumulated changes, for firing change events\n cursorActivityHandlers: null,\n // Set of handlers to fire cursorActivity on\n cursorActivityCalled: 0,\n // Tracks which cursorActivity handlers have been called already\n selectionChanged: false,\n // Whether the selection needs to be redrawn\n updateMaxLine: false,\n // Set when the widest line needs to be determined anew\n scrollLeft: null,\n scrollTop: null,\n // Intermediate scroll position, not pushed to DOM yet\n scrollToPos: null,\n // Used to scroll to a specific position\n focus: false,\n id: ++nextOpId // Unique ID\n\n };\n pushOperation(cm.curOp);\n } // Finish an operation, updating the display and signalling delayed events\n\n\n function _endOperation(cm) {\n var op = cm.curOp;\n\n if (op) {\n finishOperation(op, function (group) {\n for (var i = 0; i < group.ops.length; i++) {\n group.ops[i].cm.curOp = null;\n }\n\n endOperations(group);\n });\n }\n } // The DOM updates done when an operation finishes are batched so\n // that the minimum number of relayouts are required.\n\n\n function endOperations(group) {\n var ops = group.ops;\n\n for (var i = 0; i < ops.length; i++) // Read DOM\n {\n endOperation_R1(ops[i]);\n }\n\n for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)\n {\n endOperation_W1(ops[i$1]);\n }\n\n for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM\n {\n endOperation_R2(ops[i$2]);\n }\n\n for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)\n {\n endOperation_W2(ops[i$3]);\n }\n\n for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM\n {\n endOperation_finish(ops[i$4]);\n }\n }\n\n function endOperation_R1(op) {\n var cm = op.cm,\n display = cm.display;\n maybeClipScrollbars(cm);\n\n if (op.updateMaxLine) {\n findMaxLine(cm);\n }\n\n op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null || op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom || op.scrollToPos.to.line >= display.viewTo) || display.maxLineChanged && cm.options.lineWrapping;\n op.update = op.mustUpdate && new DisplayUpdate(cm, op.mustUpdate && {\n top: op.scrollTop,\n ensure: op.scrollToPos\n }, op.forceUpdate);\n }\n\n function endOperation_W1(op) {\n op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);\n }\n\n function endOperation_R2(op) {\n var cm = op.cm,\n display = cm.display;\n\n if (op.updatedDisplay) {\n updateHeightsInViewport(cm);\n }\n\n op.barMeasure = measureForScrollbars(cm); // If the max line changed since it was last measured, measure it,\n // and ensure the document's width matches it.\n // updateDisplay_W2 will use these properties to do the actual resizing\n\n if (display.maxLineChanged && !cm.options.lineWrapping) {\n op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;\n cm.display.sizerWidth = op.adjustWidthTo;\n op.barMeasure.scrollWidth = Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);\n op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));\n }\n\n if (op.updatedDisplay || op.selectionChanged) {\n op.preparedSelection = display.input.prepareSelection();\n }\n }\n\n function endOperation_W2(op) {\n var cm = op.cm;\n\n if (op.adjustWidthTo != null) {\n cm.display.sizer.style.minWidth = op.adjustWidthTo + \"px\";\n\n if (op.maxScrollLeft < cm.doc.scrollLeft) {\n setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);\n }\n\n cm.display.maxLineChanged = false;\n }\n\n var takeFocus = op.focus && op.focus == activeElt();\n\n if (op.preparedSelection) {\n cm.display.input.showSelection(op.preparedSelection, takeFocus);\n }\n\n if (op.updatedDisplay || op.startHeight != cm.doc.height) {\n updateScrollbars(cm, op.barMeasure);\n }\n\n if (op.updatedDisplay) {\n setDocumentHeight(cm, op.barMeasure);\n }\n\n if (op.selectionChanged) {\n restartBlink(cm);\n }\n\n if (cm.state.focused && op.updateInput) {\n cm.display.input.reset(op.typing);\n }\n\n if (takeFocus) {\n ensureFocus(op.cm);\n }\n }\n\n function endOperation_finish(op) {\n var cm = op.cm,\n display = cm.display,\n doc = cm.doc;\n\n if (op.updatedDisplay) {\n postUpdateDisplay(cm, op.update);\n } // Abort mouse wheel delta measurement, when scrolling explicitly\n\n\n if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos)) {\n display.wheelStartX = display.wheelStartY = null;\n } // Propagate the scroll position to the actual DOM scroller\n\n\n if (op.scrollTop != null) {\n setScrollTop(cm, op.scrollTop, op.forceScroll);\n }\n\n if (op.scrollLeft != null) {\n setScrollLeft(cm, op.scrollLeft, true, true);\n } // If we need to scroll a specific position into view, do so.\n\n\n if (op.scrollToPos) {\n var rect = scrollPosIntoView(cm, _clipPos(doc, op.scrollToPos.from), _clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);\n maybeScrollWindow(cm, rect);\n } // Fire events for markers that are hidden/unidden by editing or\n // undoing\n\n\n var hidden = op.maybeHiddenMarkers,\n unhidden = op.maybeUnhiddenMarkers;\n\n if (hidden) {\n for (var i = 0; i < hidden.length; ++i) {\n if (!hidden[i].lines.length) {\n signal(hidden[i], \"hide\");\n }\n }\n }\n\n if (unhidden) {\n for (var i$1 = 0; i$1 < unhidden.length; ++i$1) {\n if (unhidden[i$1].lines.length) {\n signal(unhidden[i$1], \"unhide\");\n }\n }\n }\n\n if (display.wrapper.offsetHeight) {\n doc.scrollTop = cm.display.scroller.scrollTop;\n } // Fire change events, and delayed event handlers\n\n\n if (op.changeObjs) {\n signal(cm, \"changes\", cm, op.changeObjs);\n }\n\n if (op.update) {\n op.update.finish();\n }\n } // Run the given function in an operation\n\n\n function runInOp(cm, f) {\n if (cm.curOp) {\n return f();\n }\n\n _startOperation(cm);\n\n try {\n return f();\n } finally {\n _endOperation(cm);\n }\n } // Wraps a function in an operation. Returns the wrapped function.\n\n\n function operation(cm, f) {\n return function () {\n if (cm.curOp) {\n return f.apply(cm, arguments);\n }\n\n _startOperation(cm);\n\n try {\n return f.apply(cm, arguments);\n } finally {\n _endOperation(cm);\n }\n };\n } // Used to add methods to editor and doc instances, wrapping them in\n // operations.\n\n\n function methodOp(f) {\n return function () {\n if (this.curOp) {\n return f.apply(this, arguments);\n }\n\n _startOperation(this);\n\n try {\n return f.apply(this, arguments);\n } finally {\n _endOperation(this);\n }\n };\n }\n\n function docMethodOp(f) {\n return function () {\n var cm = this.cm;\n\n if (!cm || cm.curOp) {\n return f.apply(this, arguments);\n }\n\n _startOperation(cm);\n\n try {\n return f.apply(this, arguments);\n } finally {\n _endOperation(cm);\n }\n };\n } // HIGHLIGHT WORKER\n\n\n function startWorker(cm, time) {\n if (cm.doc.highlightFrontier < cm.display.viewTo) {\n cm.state.highlight.set(time, bind(highlightWorker, cm));\n }\n }\n\n function highlightWorker(cm) {\n var doc = cm.doc;\n\n if (doc.highlightFrontier >= cm.display.viewTo) {\n return;\n }\n\n var end = +new Date() + cm.options.workTime;\n var context = getContextBefore(cm, doc.highlightFrontier);\n var changedLines = [];\n doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {\n if (context.line >= cm.display.viewFrom) {\n // Visible\n var oldStyles = line.styles;\n var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null;\n var highlighted = highlightLine(cm, line, context, true);\n\n if (resetState) {\n context.state = resetState;\n }\n\n line.styles = highlighted.styles;\n var oldCls = line.styleClasses,\n newCls = highlighted.classes;\n\n if (newCls) {\n line.styleClasses = newCls;\n } else if (oldCls) {\n line.styleClasses = null;\n }\n\n var ischange = !oldStyles || oldStyles.length != line.styles.length || oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);\n\n for (var i = 0; !ischange && i < oldStyles.length; ++i) {\n ischange = oldStyles[i] != line.styles[i];\n }\n\n if (ischange) {\n changedLines.push(context.line);\n }\n\n line.stateAfter = context.save();\n context.nextLine();\n } else {\n if (line.text.length <= cm.options.maxHighlightLength) {\n processLine(cm, line.text, context);\n }\n\n line.stateAfter = context.line % 5 == 0 ? context.save() : null;\n context.nextLine();\n }\n\n if (+new Date() > end) {\n startWorker(cm, cm.options.workDelay);\n return true;\n }\n });\n doc.highlightFrontier = context.line;\n doc.modeFrontier = Math.max(doc.modeFrontier, context.line);\n\n if (changedLines.length) {\n runInOp(cm, function () {\n for (var i = 0; i < changedLines.length; i++) {\n regLineChange(cm, changedLines[i], \"text\");\n }\n });\n }\n } // DISPLAY DRAWING\n\n\n var DisplayUpdate = function DisplayUpdate(cm, viewport, force) {\n var display = cm.display;\n this.viewport = viewport; // Store some values that we'll need later (but don't want to force a relayout for)\n\n this.visible = visibleLines(display, cm.doc, viewport);\n this.editorIsHidden = !display.wrapper.offsetWidth;\n this.wrapperHeight = display.wrapper.clientHeight;\n this.wrapperWidth = display.wrapper.clientWidth;\n this.oldDisplayWidth = displayWidth(cm);\n this.force = force;\n this.dims = getDimensions(cm);\n this.events = [];\n };\n\n DisplayUpdate.prototype.signal = function (emitter, type) {\n if (hasHandler(emitter, type)) {\n this.events.push(arguments);\n }\n };\n\n DisplayUpdate.prototype.finish = function () {\n for (var i = 0; i < this.events.length; i++) {\n signal.apply(null, this.events[i]);\n }\n };\n\n function maybeClipScrollbars(cm) {\n var display = cm.display;\n\n if (!display.scrollbarsClipped && display.scroller.offsetWidth) {\n display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;\n display.heightForcer.style.height = scrollGap(cm) + \"px\";\n display.sizer.style.marginBottom = -display.nativeBarWidth + \"px\";\n display.sizer.style.borderRightWidth = scrollGap(cm) + \"px\";\n display.scrollbarsClipped = true;\n }\n }\n\n function selectionSnapshot(cm) {\n if (cm.hasFocus()) {\n return null;\n }\n\n var active = activeElt();\n\n if (!active || !contains(cm.display.lineDiv, active)) {\n return null;\n }\n\n var result = {\n activeElt: active\n };\n\n if (window.getSelection) {\n var sel = window.getSelection();\n\n if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {\n result.anchorNode = sel.anchorNode;\n result.anchorOffset = sel.anchorOffset;\n result.focusNode = sel.focusNode;\n result.focusOffset = sel.focusOffset;\n }\n }\n\n return result;\n }\n\n function restoreSelection(snapshot) {\n if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) {\n return;\n }\n\n snapshot.activeElt.focus();\n\n if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) && snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {\n var sel = window.getSelection(),\n range = document.createRange();\n range.setEnd(snapshot.anchorNode, snapshot.anchorOffset);\n range.collapse(false);\n sel.removeAllRanges();\n sel.addRange(range);\n sel.extend(snapshot.focusNode, snapshot.focusOffset);\n }\n } // Does the actual updating of the line display. Bails out\n // (returning false) when there is nothing to be done and forced is\n // false.\n\n\n function updateDisplayIfNeeded(cm, update) {\n var display = cm.display,\n doc = cm.doc;\n\n if (update.editorIsHidden) {\n resetView(cm);\n return false;\n } // Bail out if the visible area is already rendered and nothing changed.\n\n\n if (!update.force && update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && display.renderedView == display.view && countDirtyView(cm) == 0) {\n return false;\n }\n\n if (maybeUpdateLineNumberWidth(cm)) {\n resetView(cm);\n update.dims = getDimensions(cm);\n } // Compute a suitable new viewport (from & to)\n\n\n var end = doc.first + doc.size;\n var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);\n var to = Math.min(end, update.visible.to + cm.options.viewportMargin);\n\n if (display.viewFrom < from && from - display.viewFrom < 20) {\n from = Math.max(doc.first, display.viewFrom);\n }\n\n if (display.viewTo > to && display.viewTo - to < 20) {\n to = Math.min(end, display.viewTo);\n }\n\n if (sawCollapsedSpans) {\n from = visualLineNo(cm.doc, from);\n to = visualLineEndNo(cm.doc, to);\n }\n\n var different = from != display.viewFrom || to != display.viewTo || display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;\n adjustView(cm, from, to);\n display.viewOffset = _heightAtLine(getLine(cm.doc, display.viewFrom)); // Position the mover div to align with the current scroll position\n\n cm.display.mover.style.top = display.viewOffset + \"px\";\n var toUpdate = countDirtyView(cm);\n\n if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) {\n return false;\n } // For big changes, we hide the enclosing element during the\n // update, since that speeds up the operations on most browsers.\n\n\n var selSnapshot = selectionSnapshot(cm);\n\n if (toUpdate > 4) {\n display.lineDiv.style.display = \"none\";\n }\n\n patchDisplay(cm, display.updateLineNumbers, update.dims);\n\n if (toUpdate > 4) {\n display.lineDiv.style.display = \"\";\n }\n\n display.renderedView = display.view; // There might have been a widget with a focused element that got\n // hidden or updated, if so re-focus it.\n\n restoreSelection(selSnapshot); // Prevent selection and cursors from interfering with the scroll\n // width and height.\n\n removeChildren(display.cursorDiv);\n removeChildren(display.selectionDiv);\n display.gutters.style.height = display.sizer.style.minHeight = 0;\n\n if (different) {\n display.lastWrapHeight = update.wrapperHeight;\n display.lastWrapWidth = update.wrapperWidth;\n startWorker(cm, 400);\n }\n\n display.updateLineNumbers = null;\n return true;\n }\n\n function postUpdateDisplay(cm, update) {\n var viewport = update.viewport;\n\n for (var first = true;; first = false) {\n if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {\n // Clip forced viewport to actual scrollable area.\n if (viewport && viewport.top != null) {\n viewport = {\n top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)\n };\n } // Updated line heights might result in the drawn area not\n // actually covering the viewport. Keep looping until it does.\n\n\n update.visible = visibleLines(cm.display, cm.doc, viewport);\n\n if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo) {\n break;\n }\n } else if (first) {\n update.visible = visibleLines(cm.display, cm.doc, viewport);\n }\n\n if (!updateDisplayIfNeeded(cm, update)) {\n break;\n }\n\n updateHeightsInViewport(cm);\n var barMeasure = measureForScrollbars(cm);\n updateSelection(cm);\n updateScrollbars(cm, barMeasure);\n setDocumentHeight(cm, barMeasure);\n update.force = false;\n }\n\n update.signal(cm, \"update\", cm);\n\n if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {\n update.signal(cm, \"viewportChange\", cm, cm.display.viewFrom, cm.display.viewTo);\n cm.display.reportedViewFrom = cm.display.viewFrom;\n cm.display.reportedViewTo = cm.display.viewTo;\n }\n }\n\n function updateDisplaySimple(cm, viewport) {\n var update = new DisplayUpdate(cm, viewport);\n\n if (updateDisplayIfNeeded(cm, update)) {\n updateHeightsInViewport(cm);\n postUpdateDisplay(cm, update);\n var barMeasure = measureForScrollbars(cm);\n updateSelection(cm);\n updateScrollbars(cm, barMeasure);\n setDocumentHeight(cm, barMeasure);\n update.finish();\n }\n } // Sync the actual display DOM structure with display.view, removing\n // nodes for lines that are no longer in view, and creating the ones\n // that are not there yet, and updating the ones that are out of\n // date.\n\n\n function patchDisplay(cm, updateNumbersFrom, dims) {\n var display = cm.display,\n lineNumbers = cm.options.lineNumbers;\n var container = display.lineDiv,\n cur = container.firstChild;\n\n function rm(node) {\n var next = node.nextSibling; // Works around a throw-scroll bug in OS X Webkit\n\n if (webkit && mac && cm.display.currentWheelTarget == node) {\n node.style.display = \"none\";\n } else {\n node.parentNode.removeChild(node);\n }\n\n return next;\n }\n\n var view = display.view,\n lineN = display.viewFrom; // Loop over the elements in the view, syncing cur (the DOM nodes\n // in display.lineDiv) with the view as we go.\n\n for (var i = 0; i < view.length; i++) {\n var lineView = view[i];\n if (lineView.hidden) ;else if (!lineView.node || lineView.node.parentNode != container) {\n // Not drawn yet\n var node = buildLineElement(cm, lineView, lineN, dims);\n container.insertBefore(node, cur);\n } else {\n // Already drawn\n while (cur != lineView.node) {\n cur = rm(cur);\n }\n\n var updateNumber = lineNumbers && updateNumbersFrom != null && updateNumbersFrom <= lineN && lineView.lineNumber;\n\n if (lineView.changes) {\n if (indexOf(lineView.changes, \"gutter\") > -1) {\n updateNumber = false;\n }\n\n updateLineForChanges(cm, lineView, lineN, dims);\n }\n\n if (updateNumber) {\n removeChildren(lineView.lineNumber);\n lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));\n }\n\n cur = lineView.node.nextSibling;\n }\n lineN += lineView.size;\n }\n\n while (cur) {\n cur = rm(cur);\n }\n }\n\n function updateGutterSpace(display) {\n var width = display.gutters.offsetWidth;\n display.sizer.style.marginLeft = width + \"px\";\n }\n\n function setDocumentHeight(cm, measure) {\n cm.display.sizer.style.minHeight = measure.docHeight + \"px\";\n cm.display.heightForcer.style.top = measure.docHeight + \"px\";\n cm.display.gutters.style.height = measure.docHeight + cm.display.barHeight + scrollGap(cm) + \"px\";\n } // Re-align line numbers and gutter marks to compensate for\n // horizontal scrolling.\n\n\n function alignHorizontally(cm) {\n var display = cm.display,\n view = display.view;\n\n if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) {\n return;\n }\n\n var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;\n var gutterW = display.gutters.offsetWidth,\n left = comp + \"px\";\n\n for (var i = 0; i < view.length; i++) {\n if (!view[i].hidden) {\n if (cm.options.fixedGutter) {\n if (view[i].gutter) {\n view[i].gutter.style.left = left;\n }\n\n if (view[i].gutterBackground) {\n view[i].gutterBackground.style.left = left;\n }\n }\n\n var align = view[i].alignable;\n\n if (align) {\n for (var j = 0; j < align.length; j++) {\n align[j].style.left = left;\n }\n }\n }\n }\n\n if (cm.options.fixedGutter) {\n display.gutters.style.left = comp + gutterW + \"px\";\n }\n } // Used to ensure that the line number gutter is still the right\n // size for the current document size. Returns true when an update\n // is needed.\n\n\n function maybeUpdateLineNumberWidth(cm) {\n if (!cm.options.lineNumbers) {\n return false;\n }\n\n var doc = cm.doc,\n last = lineNumberFor(cm.options, doc.first + doc.size - 1),\n display = cm.display;\n\n if (last.length != display.lineNumChars) {\n var test = display.measure.appendChild(elt(\"div\", [elt(\"div\", last)], \"CodeMirror-linenumber CodeMirror-gutter-elt\"));\n var innerW = test.firstChild.offsetWidth,\n padding = test.offsetWidth - innerW;\n display.lineGutter.style.width = \"\";\n display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;\n display.lineNumWidth = display.lineNumInnerWidth + padding;\n display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;\n display.lineGutter.style.width = display.lineNumWidth + \"px\";\n updateGutterSpace(cm.display);\n return true;\n }\n\n return false;\n }\n\n function getGutters(gutters, lineNumbers) {\n var result = [],\n sawLineNumbers = false;\n\n for (var i = 0; i < gutters.length; i++) {\n var name = gutters[i],\n style = null;\n\n if (typeof name != \"string\") {\n style = name.style;\n name = name.className;\n }\n\n if (name == \"CodeMirror-linenumbers\") {\n if (!lineNumbers) {\n continue;\n } else {\n sawLineNumbers = true;\n }\n }\n\n result.push({\n className: name,\n style: style\n });\n }\n\n if (lineNumbers && !sawLineNumbers) {\n result.push({\n className: \"CodeMirror-linenumbers\",\n style: null\n });\n }\n\n return result;\n } // Rebuild the gutter elements, ensure the margin to the left of the\n // code matches their width.\n\n\n function renderGutters(display) {\n var gutters = display.gutters,\n specs = display.gutterSpecs;\n removeChildren(gutters);\n display.lineGutter = null;\n\n for (var i = 0; i < specs.length; ++i) {\n var ref = specs[i];\n var className = ref.className;\n var style = ref.style;\n var gElt = gutters.appendChild(elt(\"div\", null, \"CodeMirror-gutter \" + className));\n\n if (style) {\n gElt.style.cssText = style;\n }\n\n if (className == \"CodeMirror-linenumbers\") {\n display.lineGutter = gElt;\n gElt.style.width = (display.lineNumWidth || 1) + \"px\";\n }\n }\n\n gutters.style.display = specs.length ? \"\" : \"none\";\n updateGutterSpace(display);\n }\n\n function updateGutters(cm) {\n renderGutters(cm.display);\n regChange(cm);\n alignHorizontally(cm);\n } // The display handles the DOM integration, both for input reading\n // and content drawing. It holds references to DOM nodes and\n // display-related state.\n\n\n function Display(place, doc, input, options) {\n var d = this;\n this.input = input; // Covers bottom-right square when both scrollbars are present.\n\n d.scrollbarFiller = elt(\"div\", null, \"CodeMirror-scrollbar-filler\");\n d.scrollbarFiller.setAttribute(\"cm-not-content\", \"true\"); // Covers bottom of gutter when coverGutterNextToScrollbar is on\n // and h scrollbar is present.\n\n d.gutterFiller = elt(\"div\", null, \"CodeMirror-gutter-filler\");\n d.gutterFiller.setAttribute(\"cm-not-content\", \"true\"); // Will contain the actual code, positioned to cover the viewport.\n\n d.lineDiv = eltP(\"div\", null, \"CodeMirror-code\"); // Elements are added to these to represent selection and cursors.\n\n d.selectionDiv = elt(\"div\", null, null, \"position: relative; z-index: 1\");\n d.cursorDiv = elt(\"div\", null, \"CodeMirror-cursors\"); // A visibility: hidden element used to find the size of things.\n\n d.measure = elt(\"div\", null, \"CodeMirror-measure\"); // When lines outside of the viewport are measured, they are drawn in this.\n\n d.lineMeasure = elt(\"div\", null, \"CodeMirror-measure\"); // Wraps everything that needs to exist inside the vertically-padded coordinate system\n\n d.lineSpace = eltP(\"div\", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv], null, \"position: relative; outline: none\");\n var lines = eltP(\"div\", [d.lineSpace], \"CodeMirror-lines\"); // Moved around its parent to cover visible view.\n\n d.mover = elt(\"div\", [lines], null, \"position: relative\"); // Set to the height of the document, allowing scrolling.\n\n d.sizer = elt(\"div\", [d.mover], \"CodeMirror-sizer\");\n d.sizerWidth = null; // Behavior of elts with overflow: auto and padding is\n // inconsistent across browsers. This is used to ensure the\n // scrollable area is big enough.\n\n d.heightForcer = elt(\"div\", null, null, \"position: absolute; height: \" + scrollerGap + \"px; width: 1px;\"); // Will contain the gutters, if any.\n\n d.gutters = elt(\"div\", null, \"CodeMirror-gutters\");\n d.lineGutter = null; // Actual scrollable element.\n\n d.scroller = elt(\"div\", [d.sizer, d.heightForcer, d.gutters], \"CodeMirror-scroll\");\n d.scroller.setAttribute(\"tabIndex\", \"-1\"); // The element in which the editor lives.\n\n d.wrapper = elt(\"div\", [d.scrollbarFiller, d.gutterFiller, d.scroller], \"CodeMirror\"); // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)\n\n if (ie && ie_version < 8) {\n d.gutters.style.zIndex = -1;\n d.scroller.style.paddingRight = 0;\n }\n\n if (!webkit && !(gecko && mobile)) {\n d.scroller.draggable = true;\n }\n\n if (place) {\n if (place.appendChild) {\n place.appendChild(d.wrapper);\n } else {\n place(d.wrapper);\n }\n } // Current rendered range (may be bigger than the view window).\n\n\n d.viewFrom = d.viewTo = doc.first;\n d.reportedViewFrom = d.reportedViewTo = doc.first; // Information about the rendered lines.\n\n d.view = [];\n d.renderedView = null; // Holds info about a single rendered line when it was rendered\n // for measurement, while not in view.\n\n d.externalMeasured = null; // Empty space (in pixels) above the view\n\n d.viewOffset = 0;\n d.lastWrapHeight = d.lastWrapWidth = 0;\n d.updateLineNumbers = null;\n d.nativeBarWidth = d.barHeight = d.barWidth = 0;\n d.scrollbarsClipped = false; // Used to only resize the line number gutter when necessary (when\n // the amount of lines crosses a boundary that makes its width change)\n\n d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null; // Set to true when a non-horizontal-scrolling line widget is\n // added. As an optimization, line widget aligning is skipped when\n // this is false.\n\n d.alignWidgets = false;\n d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null; // Tracks the maximum line length so that the horizontal scrollbar\n // can be kept static when scrolling.\n\n d.maxLine = null;\n d.maxLineLength = 0;\n d.maxLineChanged = false; // Used for measuring wheel scrolling granularity\n\n d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null; // True when shift is held down.\n\n d.shift = false; // Used to track whether anything happened since the context menu\n // was opened.\n\n d.selForContextMenu = null;\n d.activeTouch = null;\n d.gutterSpecs = getGutters(options.gutters, options.lineNumbers);\n renderGutters(d);\n input.init(d);\n } // Since the delta values reported on mouse wheel events are\n // unstandardized between browsers and even browser versions, and\n // generally horribly unpredictable, this code starts by measuring\n // the scroll effect that the first few mouse wheel events have,\n // and, from that, detects the way it can convert deltas to pixel\n // offsets afterwards.\n //\n // The reason we want to know the amount a wheel event will scroll\n // is that it gives us a chance to update the display before the\n // actual scrolling happens, reducing flickering.\n\n\n var wheelSamples = 0,\n wheelPixelsPerUnit = null; // Fill in a browser-detected starting value on browsers where we\n // know one. These don't have to be accurate -- the result of them\n // being wrong would just be a slight flicker on the first wheel\n // scroll (if it is large enough).\n\n if (ie) {\n wheelPixelsPerUnit = -.53;\n } else if (gecko) {\n wheelPixelsPerUnit = 15;\n } else if (chrome) {\n wheelPixelsPerUnit = -.7;\n } else if (safari) {\n wheelPixelsPerUnit = -1 / 3;\n }\n\n function wheelEventDelta(e) {\n var dx = e.wheelDeltaX,\n dy = e.wheelDeltaY;\n\n if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) {\n dx = e.detail;\n }\n\n if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) {\n dy = e.detail;\n } else if (dy == null) {\n dy = e.wheelDelta;\n }\n\n return {\n x: dx,\n y: dy\n };\n }\n\n function wheelEventPixels(e) {\n var delta = wheelEventDelta(e);\n delta.x *= wheelPixelsPerUnit;\n delta.y *= wheelPixelsPerUnit;\n return delta;\n }\n\n function onScrollWheel(cm, e) {\n var delta = wheelEventDelta(e),\n dx = delta.x,\n dy = delta.y;\n var display = cm.display,\n scroll = display.scroller; // Quit if there's nothing to scroll here\n\n var canScrollX = scroll.scrollWidth > scroll.clientWidth;\n var canScrollY = scroll.scrollHeight > scroll.clientHeight;\n\n if (!(dx && canScrollX || dy && canScrollY)) {\n return;\n } // Webkit browsers on OS X abort momentum scrolls when the target\n // of the scroll event is removed from the scrollable element.\n // This hack (see related code in patchDisplay) makes sure the\n // element is kept around.\n\n\n if (dy && mac && webkit) {\n outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {\n for (var i = 0; i < view.length; i++) {\n if (view[i].node == cur) {\n cm.display.currentWheelTarget = cur;\n break outer;\n }\n }\n }\n } // On some browsers, horizontal scrolling will cause redraws to\n // happen before the gutter has been realigned, causing it to\n // wriggle around in a most unseemly way. When we have an\n // estimated pixels/delta value, we just handle horizontal\n // scrolling entirely here. It'll be slightly off from native, but\n // better than glitching out.\n\n\n if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {\n if (dy && canScrollY) {\n updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit));\n }\n\n setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit)); // Only prevent default scrolling if vertical scrolling is\n // actually possible. Otherwise, it causes vertical scroll\n // jitter on OSX trackpads when deltaX is small and deltaY\n // is large (issue #3579)\n\n if (!dy || dy && canScrollY) {\n e_preventDefault(e);\n }\n\n display.wheelStartX = null; // Abort measurement, if in progress\n\n return;\n } // 'Project' the visible viewport to cover the area that is being\n // scrolled into view (if we know enough to estimate it).\n\n\n if (dy && wheelPixelsPerUnit != null) {\n var pixels = dy * wheelPixelsPerUnit;\n var top = cm.doc.scrollTop,\n bot = top + display.wrapper.clientHeight;\n\n if (pixels < 0) {\n top = Math.max(0, top + pixels - 50);\n } else {\n bot = Math.min(cm.doc.height, bot + pixels + 50);\n }\n\n updateDisplaySimple(cm, {\n top: top,\n bottom: bot\n });\n }\n\n if (wheelSamples < 20) {\n if (display.wheelStartX == null) {\n display.wheelStartX = scroll.scrollLeft;\n display.wheelStartY = scroll.scrollTop;\n display.wheelDX = dx;\n display.wheelDY = dy;\n setTimeout(function () {\n if (display.wheelStartX == null) {\n return;\n }\n\n var movedX = scroll.scrollLeft - display.wheelStartX;\n var movedY = scroll.scrollTop - display.wheelStartY;\n var sample = movedY && display.wheelDY && movedY / display.wheelDY || movedX && display.wheelDX && movedX / display.wheelDX;\n display.wheelStartX = display.wheelStartY = null;\n\n if (!sample) {\n return;\n }\n\n wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);\n ++wheelSamples;\n }, 200);\n } else {\n display.wheelDX += dx;\n display.wheelDY += dy;\n }\n }\n } // Selection objects are immutable. A new one is created every time\n // the selection changes. A selection is one or more non-overlapping\n // (and non-touching) ranges, sorted, and an integer that indicates\n // which one is the primary selection (the one that's scrolled into\n // view, that getCursor returns, etc).\n\n\n var Selection = function Selection(ranges, primIndex) {\n this.ranges = ranges;\n this.primIndex = primIndex;\n };\n\n Selection.prototype.primary = function () {\n return this.ranges[this.primIndex];\n };\n\n Selection.prototype.equals = function (other) {\n if (other == this) {\n return true;\n }\n\n if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) {\n return false;\n }\n\n for (var i = 0; i < this.ranges.length; i++) {\n var here = this.ranges[i],\n there = other.ranges[i];\n\n if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) {\n return false;\n }\n }\n\n return true;\n };\n\n Selection.prototype.deepCopy = function () {\n var out = [];\n\n for (var i = 0; i < this.ranges.length; i++) {\n out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head));\n }\n\n return new Selection(out, this.primIndex);\n };\n\n Selection.prototype.somethingSelected = function () {\n for (var i = 0; i < this.ranges.length; i++) {\n if (!this.ranges[i].empty()) {\n return true;\n }\n }\n\n return false;\n };\n\n Selection.prototype.contains = function (pos, end) {\n if (!end) {\n end = pos;\n }\n\n for (var i = 0; i < this.ranges.length; i++) {\n var range = this.ranges[i];\n\n if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0) {\n return i;\n }\n }\n\n return -1;\n };\n\n var Range = function Range(anchor, head) {\n this.anchor = anchor;\n this.head = head;\n };\n\n Range.prototype.from = function () {\n return minPos(this.anchor, this.head);\n };\n\n Range.prototype.to = function () {\n return maxPos(this.anchor, this.head);\n };\n\n Range.prototype.empty = function () {\n return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;\n }; // Take an unsorted, potentially overlapping set of ranges, and\n // build a selection out of it. 'Consumes' ranges array (modifying\n // it).\n\n\n function normalizeSelection(cm, ranges, primIndex) {\n var mayTouch = cm && cm.options.selectionsMayTouch;\n var prim = ranges[primIndex];\n ranges.sort(function (a, b) {\n return cmp(a.from(), b.from());\n });\n primIndex = indexOf(ranges, prim);\n\n for (var i = 1; i < ranges.length; i++) {\n var cur = ranges[i],\n prev = ranges[i - 1];\n var diff = cmp(prev.to(), cur.from());\n\n if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {\n var from = minPos(prev.from(), cur.from()),\n to = maxPos(prev.to(), cur.to());\n var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;\n\n if (i <= primIndex) {\n --primIndex;\n }\n\n ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));\n }\n }\n\n return new Selection(ranges, primIndex);\n }\n\n function simpleSelection(anchor, head) {\n return new Selection([new Range(anchor, head || anchor)], 0);\n } // Compute the position of the end of a change (its 'to' property\n // refers to the pre-change end).\n\n\n function changeEnd(change) {\n if (!change.text) {\n return change.to;\n }\n\n return Pos(change.from.line + change.text.length - 1, lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));\n } // Adjust a position to refer to the post-change position of the\n // same text, or the end of the change if the change covers it.\n\n\n function adjustForChange(pos, change) {\n if (cmp(pos, change.from) < 0) {\n return pos;\n }\n\n if (cmp(pos, change.to) <= 0) {\n return changeEnd(change);\n }\n\n var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1,\n ch = pos.ch;\n\n if (pos.line == change.to.line) {\n ch += changeEnd(change).ch - change.to.ch;\n }\n\n return Pos(line, ch);\n }\n\n function computeSelAfterChange(doc, change) {\n var out = [];\n\n for (var i = 0; i < doc.sel.ranges.length; i++) {\n var range = doc.sel.ranges[i];\n out.push(new Range(adjustForChange(range.anchor, change), adjustForChange(range.head, change)));\n }\n\n return normalizeSelection(doc.cm, out, doc.sel.primIndex);\n }\n\n function offsetPos(pos, old, nw) {\n if (pos.line == old.line) {\n return Pos(nw.line, pos.ch - old.ch + nw.ch);\n } else {\n return Pos(nw.line + (pos.line - old.line), pos.ch);\n }\n } // Used by replaceSelections to allow moving the selection to the\n // start or around the replaced test. Hint may be \"start\" or \"around\".\n\n\n function computeReplacedSel(doc, changes, hint) {\n var out = [];\n var oldPrev = Pos(doc.first, 0),\n newPrev = oldPrev;\n\n for (var i = 0; i < changes.length; i++) {\n var change = changes[i];\n var from = offsetPos(change.from, oldPrev, newPrev);\n var to = offsetPos(changeEnd(change), oldPrev, newPrev);\n oldPrev = change.to;\n newPrev = to;\n\n if (hint == \"around\") {\n var range = doc.sel.ranges[i],\n inv = cmp(range.head, range.anchor) < 0;\n out[i] = new Range(inv ? to : from, inv ? from : to);\n } else {\n out[i] = new Range(from, from);\n }\n }\n\n return new Selection(out, doc.sel.primIndex);\n } // Used to get the editor into a consistent state again when options change.\n\n\n function loadMode(cm) {\n cm.doc.mode = getMode(cm.options, cm.doc.modeOption);\n resetModeState(cm);\n }\n\n function resetModeState(cm) {\n cm.doc.iter(function (line) {\n if (line.stateAfter) {\n line.stateAfter = null;\n }\n\n if (line.styles) {\n line.styles = null;\n }\n });\n cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;\n startWorker(cm, 100);\n cm.state.modeGen++;\n\n if (cm.curOp) {\n regChange(cm);\n }\n } // DOCUMENT DATA STRUCTURE\n // By default, updates that start and end at the beginning of a line\n // are treated specially, in order to make the association of line\n // widgets and marker elements with the text behave more intuitive.\n\n\n function isWholeLineUpdate(doc, change) {\n return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == \"\" && (!doc.cm || doc.cm.options.wholeLineUpdateBefore);\n } // Perform a change on the document data structure.\n\n\n function updateDoc(doc, change, markedSpans, estimateHeight) {\n function spansFor(n) {\n return markedSpans ? markedSpans[n] : null;\n }\n\n function update(line, text, spans) {\n updateLine(line, text, spans, estimateHeight);\n signalLater(line, \"change\", line, change);\n }\n\n function linesFor(start, end) {\n var result = [];\n\n for (var i = start; i < end; ++i) {\n result.push(new Line(text[i], spansFor(i), estimateHeight));\n }\n\n return result;\n }\n\n var from = change.from,\n to = change.to,\n text = change.text;\n var firstLine = getLine(doc, from.line),\n lastLine = getLine(doc, to.line);\n var lastText = lst(text),\n lastSpans = spansFor(text.length - 1),\n nlines = to.line - from.line; // Adjust the line structure\n\n if (change.full) {\n doc.insert(0, linesFor(0, text.length));\n doc.remove(text.length, doc.size - text.length);\n } else if (isWholeLineUpdate(doc, change)) {\n // This is a whole-line replace. Treated specially to make\n // sure line objects move the way they are supposed to.\n var added = linesFor(0, text.length - 1);\n update(lastLine, lastLine.text, lastSpans);\n\n if (nlines) {\n doc.remove(from.line, nlines);\n }\n\n if (added.length) {\n doc.insert(from.line, added);\n }\n } else if (firstLine == lastLine) {\n if (text.length == 1) {\n update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);\n } else {\n var added$1 = linesFor(1, text.length - 1);\n added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));\n update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));\n doc.insert(from.line + 1, added$1);\n }\n } else if (text.length == 1) {\n update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));\n doc.remove(from.line + 1, nlines);\n } else {\n update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));\n update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);\n var added$2 = linesFor(1, text.length - 1);\n\n if (nlines > 1) {\n doc.remove(from.line + 1, nlines - 1);\n }\n\n doc.insert(from.line + 1, added$2);\n }\n\n signalLater(doc, \"change\", doc, change);\n } // Call f for all linked documents.\n\n\n function linkedDocs(doc, f, sharedHistOnly) {\n function propagate(doc, skip, sharedHist) {\n if (doc.linked) {\n for (var i = 0; i < doc.linked.length; ++i) {\n var rel = doc.linked[i];\n\n if (rel.doc == skip) {\n continue;\n }\n\n var shared = sharedHist && rel.sharedHist;\n\n if (sharedHistOnly && !shared) {\n continue;\n }\n\n f(rel.doc, shared);\n propagate(rel.doc, doc, shared);\n }\n }\n }\n\n propagate(doc, null, true);\n } // Attach a document to an editor.\n\n\n function attachDoc(cm, doc) {\n if (doc.cm) {\n throw new Error(\"This document is already in use.\");\n }\n\n cm.doc = doc;\n doc.cm = cm;\n estimateLineHeights(cm);\n loadMode(cm);\n setDirectionClass(cm);\n\n if (!cm.options.lineWrapping) {\n findMaxLine(cm);\n }\n\n cm.options.mode = doc.modeOption;\n regChange(cm);\n }\n\n function setDirectionClass(cm) {\n (cm.doc.direction == \"rtl\" ? addClass : rmClass)(cm.display.lineDiv, \"CodeMirror-rtl\");\n }\n\n function directionChanged(cm) {\n runInOp(cm, function () {\n setDirectionClass(cm);\n regChange(cm);\n });\n }\n\n function History(startGen) {\n // Arrays of change events and selections. Doing something adds an\n // event to done and clears undo. Undoing moves events from done\n // to undone, redoing moves them in the other direction.\n this.done = [];\n this.undone = [];\n this.undoDepth = Infinity; // Used to track when changes can be merged into a single undo\n // event\n\n this.lastModTime = this.lastSelTime = 0;\n this.lastOp = this.lastSelOp = null;\n this.lastOrigin = this.lastSelOrigin = null; // Used by the isClean() method\n\n this.generation = this.maxGeneration = startGen || 1;\n } // Create a history change event from an updateDoc-style change\n // object.\n\n\n function historyChangeFromChange(doc, change) {\n var histChange = {\n from: copyPos(change.from),\n to: changeEnd(change),\n text: getBetween(doc, change.from, change.to)\n };\n attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);\n linkedDocs(doc, function (doc) {\n return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);\n }, true);\n return histChange;\n } // Pop all selection events off the end of a history array. Stop at\n // a change event.\n\n\n function clearSelectionEvents(array) {\n while (array.length) {\n var last = lst(array);\n\n if (last.ranges) {\n array.pop();\n } else {\n break;\n }\n }\n } // Find the top change event in the history. Pop off selection\n // events that are in the way.\n\n\n function lastChangeEvent(hist, force) {\n if (force) {\n clearSelectionEvents(hist.done);\n return lst(hist.done);\n } else if (hist.done.length && !lst(hist.done).ranges) {\n return lst(hist.done);\n } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {\n hist.done.pop();\n return lst(hist.done);\n }\n } // Register a change in the history. Merges changes that are within\n // a single operation, or are close together with an origin that\n // allows merging (starting with \"+\") into a single event.\n\n\n function addChangeToHistory(doc, change, selAfter, opId) {\n var hist = doc.history;\n hist.undone.length = 0;\n var time = +new Date(),\n cur;\n var last;\n\n if ((hist.lastOp == opId || hist.lastOrigin == change.origin && change.origin && (change.origin.charAt(0) == \"+\" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500) || change.origin.charAt(0) == \"*\")) && (cur = lastChangeEvent(hist, hist.lastOp == opId))) {\n // Merge this change into the last event\n last = lst(cur.changes);\n\n if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {\n // Optimized case for simple insertion -- don't want to add\n // new changesets for every character typed\n last.to = changeEnd(change);\n } else {\n // Add new sub-event\n cur.changes.push(historyChangeFromChange(doc, change));\n }\n } else {\n // Can not be merged, start a new event.\n var before = lst(hist.done);\n\n if (!before || !before.ranges) {\n pushSelectionToHistory(doc.sel, hist.done);\n }\n\n cur = {\n changes: [historyChangeFromChange(doc, change)],\n generation: hist.generation\n };\n hist.done.push(cur);\n\n while (hist.done.length > hist.undoDepth) {\n hist.done.shift();\n\n if (!hist.done[0].ranges) {\n hist.done.shift();\n }\n }\n }\n\n hist.done.push(selAfter);\n hist.generation = ++hist.maxGeneration;\n hist.lastModTime = hist.lastSelTime = time;\n hist.lastOp = hist.lastSelOp = opId;\n hist.lastOrigin = hist.lastSelOrigin = change.origin;\n\n if (!last) {\n signal(doc, \"historyAdded\");\n }\n }\n\n function selectionEventCanBeMerged(doc, origin, prev, sel) {\n var ch = origin.charAt(0);\n return ch == \"*\" || ch == \"+\" && prev.ranges.length == sel.ranges.length && prev.somethingSelected() == sel.somethingSelected() && new Date() - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500);\n } // Called whenever the selection changes, sets the new selection as\n // the pending selection in the history, and pushes the old pending\n // selection into the 'done' array when it was significantly\n // different (in number of selected ranges, emptiness, or time).\n\n\n function addSelectionToHistory(doc, sel, opId, options) {\n var hist = doc.history,\n origin = options && options.origin; // A new event is started when the previous origin does not match\n // the current, or the origins don't allow matching. Origins\n // starting with * are always merged, those starting with + are\n // merged when similar and close together in time.\n\n if (opId == hist.lastSelOp || origin && hist.lastSelOrigin == origin && (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin || selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))) {\n hist.done[hist.done.length - 1] = sel;\n } else {\n pushSelectionToHistory(sel, hist.done);\n }\n\n hist.lastSelTime = +new Date();\n hist.lastSelOrigin = origin;\n hist.lastSelOp = opId;\n\n if (options && options.clearRedo !== false) {\n clearSelectionEvents(hist.undone);\n }\n }\n\n function pushSelectionToHistory(sel, dest) {\n var top = lst(dest);\n\n if (!(top && top.ranges && top.equals(sel))) {\n dest.push(sel);\n }\n } // Used to store marked span information in the history.\n\n\n function attachLocalSpans(doc, change, from, to) {\n var existing = change[\"spans_\" + doc.id],\n n = 0;\n doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {\n if (line.markedSpans) {\n (existing || (existing = change[\"spans_\" + doc.id] = {}))[n] = line.markedSpans;\n }\n\n ++n;\n });\n } // When un/re-doing restores text containing marked spans, those\n // that have been explicitly cleared should not be restored.\n\n\n function removeClearedSpans(spans) {\n if (!spans) {\n return null;\n }\n\n var out;\n\n for (var i = 0; i < spans.length; ++i) {\n if (spans[i].marker.explicitlyCleared) {\n if (!out) {\n out = spans.slice(0, i);\n }\n } else if (out) {\n out.push(spans[i]);\n }\n }\n\n return !out ? spans : out.length ? out : null;\n } // Retrieve and filter the old marked spans stored in a change event.\n\n\n function getOldSpans(doc, change) {\n var found = change[\"spans_\" + doc.id];\n\n if (!found) {\n return null;\n }\n\n var nw = [];\n\n for (var i = 0; i < change.text.length; ++i) {\n nw.push(removeClearedSpans(found[i]));\n }\n\n return nw;\n } // Used for un/re-doing changes from the history. Combines the\n // result of computing the existing spans with the set of spans that\n // existed in the history (so that deleting around a span and then\n // undoing brings back the span).\n\n\n function mergeOldSpans(doc, change) {\n var old = getOldSpans(doc, change);\n var stretched = stretchSpansOverChange(doc, change);\n\n if (!old) {\n return stretched;\n }\n\n if (!stretched) {\n return old;\n }\n\n for (var i = 0; i < old.length; ++i) {\n var oldCur = old[i],\n stretchCur = stretched[i];\n\n if (oldCur && stretchCur) {\n spans: for (var j = 0; j < stretchCur.length; ++j) {\n var span = stretchCur[j];\n\n for (var k = 0; k < oldCur.length; ++k) {\n if (oldCur[k].marker == span.marker) {\n continue spans;\n }\n }\n\n oldCur.push(span);\n }\n } else if (stretchCur) {\n old[i] = stretchCur;\n }\n }\n\n return old;\n } // Used both to provide a JSON-safe object in .getHistory, and, when\n // detaching a document, to split the history in two\n\n\n function copyHistoryArray(events, newGroup, instantiateSel) {\n var copy = [];\n\n for (var i = 0; i < events.length; ++i) {\n var event = events[i];\n\n if (event.ranges) {\n copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);\n continue;\n }\n\n var changes = event.changes,\n newChanges = [];\n copy.push({\n changes: newChanges\n });\n\n for (var j = 0; j < changes.length; ++j) {\n var change = changes[j],\n m = void 0;\n newChanges.push({\n from: change.from,\n to: change.to,\n text: change.text\n });\n\n if (newGroup) {\n for (var prop in change) {\n if (m = prop.match(/^spans_(\\d+)$/)) {\n if (indexOf(newGroup, Number(m[1])) > -1) {\n lst(newChanges)[prop] = change[prop];\n delete change[prop];\n }\n }\n }\n }\n }\n }\n\n return copy;\n } // The 'scroll' parameter given to many of these indicated whether\n // the new cursor position should be scrolled into view after\n // modifying the selection.\n // If shift is held or the extend flag is set, extends a range to\n // include a given position (and optionally a second position).\n // Otherwise, simply returns the range between the given positions.\n // Used for cursor motion and such.\n\n\n function extendRange(range, head, other, extend) {\n if (extend) {\n var anchor = range.anchor;\n\n if (other) {\n var posBefore = cmp(head, anchor) < 0;\n\n if (posBefore != cmp(other, anchor) < 0) {\n anchor = head;\n head = other;\n } else if (posBefore != cmp(head, other) < 0) {\n head = other;\n }\n }\n\n return new Range(anchor, head);\n } else {\n return new Range(other || head, head);\n }\n } // Extend the primary selection range, discard the rest.\n\n\n function extendSelection(doc, head, other, options, extend) {\n if (extend == null) {\n extend = doc.cm && (doc.cm.display.shift || doc.extend);\n }\n\n setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options);\n } // Extend all selections (pos is an array of selections with length\n // equal the number of selections)\n\n\n function extendSelections(doc, heads, options) {\n var out = [];\n var extend = doc.cm && (doc.cm.display.shift || doc.extend);\n\n for (var i = 0; i < doc.sel.ranges.length; i++) {\n out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend);\n }\n\n var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex);\n setSelection(doc, newSel, options);\n } // Updates a single range in the selection.\n\n\n function replaceOneSelection(doc, i, range, options) {\n var ranges = doc.sel.ranges.slice(0);\n ranges[i] = range;\n setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options);\n } // Reset the selection to a single range.\n\n\n function setSimpleSelection(doc, anchor, head, options) {\n setSelection(doc, simpleSelection(anchor, head), options);\n } // Give beforeSelectionChange handlers a change to influence a\n // selection update.\n\n\n function filterSelectionChange(doc, sel, options) {\n var obj = {\n ranges: sel.ranges,\n update: function update(ranges) {\n this.ranges = [];\n\n for (var i = 0; i < ranges.length; i++) {\n this.ranges[i] = new Range(_clipPos(doc, ranges[i].anchor), _clipPos(doc, ranges[i].head));\n }\n },\n origin: options && options.origin\n };\n signal(doc, \"beforeSelectionChange\", doc, obj);\n\n if (doc.cm) {\n signal(doc.cm, \"beforeSelectionChange\", doc.cm, obj);\n }\n\n if (obj.ranges != sel.ranges) {\n return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1);\n } else {\n return sel;\n }\n }\n\n function setSelectionReplaceHistory(doc, sel, options) {\n var done = doc.history.done,\n last = lst(done);\n\n if (last && last.ranges) {\n done[done.length - 1] = sel;\n setSelectionNoUndo(doc, sel, options);\n } else {\n setSelection(doc, sel, options);\n }\n } // Set a new selection.\n\n\n function setSelection(doc, sel, options) {\n setSelectionNoUndo(doc, sel, options);\n addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);\n }\n\n function setSelectionNoUndo(doc, sel, options) {\n if (hasHandler(doc, \"beforeSelectionChange\") || doc.cm && hasHandler(doc.cm, \"beforeSelectionChange\")) {\n sel = filterSelectionChange(doc, sel, options);\n }\n\n var bias = options && options.bias || (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);\n setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));\n\n if (!(options && options.scroll === false) && doc.cm) {\n ensureCursorVisible(doc.cm);\n }\n }\n\n function setSelectionInner(doc, sel) {\n if (sel.equals(doc.sel)) {\n return;\n }\n\n doc.sel = sel;\n\n if (doc.cm) {\n doc.cm.curOp.updateInput = 1;\n doc.cm.curOp.selectionChanged = true;\n signalCursorActivity(doc.cm);\n }\n\n signalLater(doc, \"cursorActivity\", doc);\n } // Verify that the selection does not partially select any atomic\n // marked ranges.\n\n\n function reCheckSelection(doc) {\n setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false));\n } // Return a selection that does not partially select any atomic\n // ranges.\n\n\n function skipAtomicInSelection(doc, sel, bias, mayClear) {\n var out;\n\n for (var i = 0; i < sel.ranges.length; i++) {\n var range = sel.ranges[i];\n var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];\n var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);\n var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);\n\n if (out || newAnchor != range.anchor || newHead != range.head) {\n if (!out) {\n out = sel.ranges.slice(0, i);\n }\n\n out[i] = new Range(newAnchor, newHead);\n }\n }\n\n return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel;\n }\n\n function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {\n var line = getLine(doc, pos.line);\n\n if (line.markedSpans) {\n for (var i = 0; i < line.markedSpans.length; ++i) {\n var sp = line.markedSpans[i],\n m = sp.marker; // Determine if we should prevent the cursor being placed to the left/right of an atomic marker\n // Historically this was determined using the inclusiveLeft/Right option, but the new way to control it\n // is with selectLeft/Right\n\n var preventCursorLeft = \"selectLeft\" in m ? !m.selectLeft : m.inclusiveLeft;\n var preventCursorRight = \"selectRight\" in m ? !m.selectRight : m.inclusiveRight;\n\n if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) && (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {\n if (mayClear) {\n signal(m, \"beforeCursorEnter\");\n\n if (m.explicitlyCleared) {\n if (!line.markedSpans) {\n break;\n } else {\n --i;\n continue;\n }\n }\n }\n\n if (!m.atomic) {\n continue;\n }\n\n if (oldPos) {\n var near = m.find(dir < 0 ? 1 : -1),\n diff = void 0;\n\n if (dir < 0 ? preventCursorRight : preventCursorLeft) {\n near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null);\n }\n\n if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0)) {\n return skipAtomicInner(doc, near, pos, dir, mayClear);\n }\n }\n\n var far = m.find(dir < 0 ? -1 : 1);\n\n if (dir < 0 ? preventCursorLeft : preventCursorRight) {\n far = movePos(doc, far, dir, far.line == pos.line ? line : null);\n }\n\n return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null;\n }\n }\n }\n\n return pos;\n } // Ensure a given position is not inside an atomic range.\n\n\n function skipAtomic(doc, pos, oldPos, bias, mayClear) {\n var dir = bias || 1;\n var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) || !mayClear && skipAtomicInner(doc, pos, oldPos, dir, true) || skipAtomicInner(doc, pos, oldPos, -dir, mayClear) || !mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true);\n\n if (!found) {\n doc.cantEdit = true;\n return Pos(doc.first, 0);\n }\n\n return found;\n }\n\n function movePos(doc, pos, dir, line) {\n if (dir < 0 && pos.ch == 0) {\n if (pos.line > doc.first) {\n return _clipPos(doc, Pos(pos.line - 1));\n } else {\n return null;\n }\n } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {\n if (pos.line < doc.first + doc.size - 1) {\n return Pos(pos.line + 1, 0);\n } else {\n return null;\n }\n } else {\n return new Pos(pos.line, pos.ch + dir);\n }\n }\n\n function selectAll(cm) {\n cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);\n } // UPDATING\n // Allow \"beforeChange\" event handlers to influence a change\n\n\n function filterChange(doc, change, update) {\n var obj = {\n canceled: false,\n from: change.from,\n to: change.to,\n text: change.text,\n origin: change.origin,\n cancel: function cancel() {\n return obj.canceled = true;\n }\n };\n\n if (update) {\n obj.update = function (from, to, text, origin) {\n if (from) {\n obj.from = _clipPos(doc, from);\n }\n\n if (to) {\n obj.to = _clipPos(doc, to);\n }\n\n if (text) {\n obj.text = text;\n }\n\n if (origin !== undefined) {\n obj.origin = origin;\n }\n };\n }\n\n signal(doc, \"beforeChange\", doc, obj);\n\n if (doc.cm) {\n signal(doc.cm, \"beforeChange\", doc.cm, obj);\n }\n\n if (obj.canceled) {\n if (doc.cm) {\n doc.cm.curOp.updateInput = 2;\n }\n\n return null;\n }\n\n return {\n from: obj.from,\n to: obj.to,\n text: obj.text,\n origin: obj.origin\n };\n } // Apply a change to a document, and add it to the document's\n // history, and propagating it to all linked documents.\n\n\n function makeChange(doc, change, ignoreReadOnly) {\n if (doc.cm) {\n if (!doc.cm.curOp) {\n return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);\n }\n\n if (doc.cm.state.suppressEdits) {\n return;\n }\n }\n\n if (hasHandler(doc, \"beforeChange\") || doc.cm && hasHandler(doc.cm, \"beforeChange\")) {\n change = filterChange(doc, change, true);\n\n if (!change) {\n return;\n }\n } // Possibly split or suppress the update based on the presence\n // of read-only spans in its range.\n\n\n var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);\n\n if (split) {\n for (var i = split.length - 1; i >= 0; --i) {\n makeChangeInner(doc, {\n from: split[i].from,\n to: split[i].to,\n text: i ? [\"\"] : change.text,\n origin: change.origin\n });\n }\n } else {\n makeChangeInner(doc, change);\n }\n }\n\n function makeChangeInner(doc, change) {\n if (change.text.length == 1 && change.text[0] == \"\" && cmp(change.from, change.to) == 0) {\n return;\n }\n\n var selAfter = computeSelAfterChange(doc, change);\n addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);\n makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));\n var rebased = [];\n linkedDocs(doc, function (doc, sharedHist) {\n if (!sharedHist && indexOf(rebased, doc.history) == -1) {\n rebaseHist(doc.history, change);\n rebased.push(doc.history);\n }\n\n makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));\n });\n } // Revert a change stored in a document's history.\n\n\n function makeChangeFromHistory(doc, type, allowSelectionOnly) {\n var suppress = doc.cm && doc.cm.state.suppressEdits;\n\n if (suppress && !allowSelectionOnly) {\n return;\n }\n\n var hist = doc.history,\n event,\n selAfter = doc.sel;\n var source = type == \"undo\" ? hist.done : hist.undone,\n dest = type == \"undo\" ? hist.undone : hist.done; // Verify that there is a useable event (so that ctrl-z won't\n // needlessly clear selection events)\n\n var i = 0;\n\n for (; i < source.length; i++) {\n event = source[i];\n\n if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges) {\n break;\n }\n }\n\n if (i == source.length) {\n return;\n }\n\n hist.lastOrigin = hist.lastSelOrigin = null;\n\n for (;;) {\n event = source.pop();\n\n if (event.ranges) {\n pushSelectionToHistory(event, dest);\n\n if (allowSelectionOnly && !event.equals(doc.sel)) {\n setSelection(doc, event, {\n clearRedo: false\n });\n return;\n }\n\n selAfter = event;\n } else if (suppress) {\n source.push(event);\n return;\n } else {\n break;\n }\n } // Build up a reverse change object to add to the opposite history\n // stack (redo when undoing, and vice versa).\n\n\n var antiChanges = [];\n pushSelectionToHistory(selAfter, dest);\n dest.push({\n changes: antiChanges,\n generation: hist.generation\n });\n hist.generation = event.generation || ++hist.maxGeneration;\n var filter = hasHandler(doc, \"beforeChange\") || doc.cm && hasHandler(doc.cm, \"beforeChange\");\n\n var loop = function loop(i) {\n var change = event.changes[i];\n change.origin = type;\n\n if (filter && !filterChange(doc, change, false)) {\n source.length = 0;\n return {};\n }\n\n antiChanges.push(historyChangeFromChange(doc, change));\n var after = i ? computeSelAfterChange(doc, change) : lst(source);\n makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));\n\n if (!i && doc.cm) {\n doc.cm.scrollIntoView({\n from: change.from,\n to: changeEnd(change)\n });\n }\n\n var rebased = []; // Propagate to the linked documents\n\n linkedDocs(doc, function (doc, sharedHist) {\n if (!sharedHist && indexOf(rebased, doc.history) == -1) {\n rebaseHist(doc.history, change);\n rebased.push(doc.history);\n }\n\n makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));\n });\n };\n\n for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {\n var returned = loop(i$1);\n if (returned) return returned.v;\n }\n } // Sub-views need their line numbers shifted when text is added\n // above or below them in the parent document.\n\n\n function shiftDoc(doc, distance) {\n if (distance == 0) {\n return;\n }\n\n doc.first += distance;\n doc.sel = new Selection(map(doc.sel.ranges, function (range) {\n return new Range(Pos(range.anchor.line + distance, range.anchor.ch), Pos(range.head.line + distance, range.head.ch));\n }), doc.sel.primIndex);\n\n if (doc.cm) {\n regChange(doc.cm, doc.first, doc.first - distance, distance);\n\n for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++) {\n regLineChange(doc.cm, l, \"gutter\");\n }\n }\n } // More lower-level change function, handling only a single document\n // (not linked ones).\n\n\n function makeChangeSingleDoc(doc, change, selAfter, spans) {\n if (doc.cm && !doc.cm.curOp) {\n return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);\n }\n\n if (change.to.line < doc.first) {\n shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));\n return;\n }\n\n if (change.from.line > doc.lastLine()) {\n return;\n } // Clip the change to the size of this doc\n\n\n if (change.from.line < doc.first) {\n var shift = change.text.length - 1 - (doc.first - change.from.line);\n shiftDoc(doc, shift);\n change = {\n from: Pos(doc.first, 0),\n to: Pos(change.to.line + shift, change.to.ch),\n text: [lst(change.text)],\n origin: change.origin\n };\n }\n\n var last = doc.lastLine();\n\n if (change.to.line > last) {\n change = {\n from: change.from,\n to: Pos(last, getLine(doc, last).text.length),\n text: [change.text[0]],\n origin: change.origin\n };\n }\n\n change.removed = getBetween(doc, change.from, change.to);\n\n if (!selAfter) {\n selAfter = computeSelAfterChange(doc, change);\n }\n\n if (doc.cm) {\n makeChangeSingleDocInEditor(doc.cm, change, spans);\n } else {\n updateDoc(doc, change, spans);\n }\n\n setSelectionNoUndo(doc, selAfter, sel_dontScroll);\n\n if (doc.cantEdit && skipAtomic(doc, Pos(doc.firstLine(), 0))) {\n doc.cantEdit = false;\n }\n } // Handle the interaction of a change to a document with the editor\n // that this document is part of.\n\n\n function makeChangeSingleDocInEditor(cm, change, spans) {\n var doc = cm.doc,\n display = cm.display,\n from = change.from,\n to = change.to;\n var recomputeMaxLength = false,\n checkWidthStart = from.line;\n\n if (!cm.options.lineWrapping) {\n checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));\n doc.iter(checkWidthStart, to.line + 1, function (line) {\n if (line == display.maxLine) {\n recomputeMaxLength = true;\n return true;\n }\n });\n }\n\n if (doc.sel.contains(change.from, change.to) > -1) {\n signalCursorActivity(cm);\n }\n\n updateDoc(doc, change, spans, estimateHeight(cm));\n\n if (!cm.options.lineWrapping) {\n doc.iter(checkWidthStart, from.line + change.text.length, function (line) {\n var len = lineLength(line);\n\n if (len > display.maxLineLength) {\n display.maxLine = line;\n display.maxLineLength = len;\n display.maxLineChanged = true;\n recomputeMaxLength = false;\n }\n });\n\n if (recomputeMaxLength) {\n cm.curOp.updateMaxLine = true;\n }\n }\n\n retreatFrontier(doc, from.line);\n startWorker(cm, 400);\n var lendiff = change.text.length - (to.line - from.line) - 1; // Remember that these lines changed, for updating the display\n\n if (change.full) {\n regChange(cm);\n } else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) {\n regLineChange(cm, from.line, \"text\");\n } else {\n regChange(cm, from.line, to.line + 1, lendiff);\n }\n\n var changesHandler = hasHandler(cm, \"changes\"),\n changeHandler = hasHandler(cm, \"change\");\n\n if (changeHandler || changesHandler) {\n var obj = {\n from: from,\n to: to,\n text: change.text,\n removed: change.removed,\n origin: change.origin\n };\n\n if (changeHandler) {\n signalLater(cm, \"change\", cm, obj);\n }\n\n if (changesHandler) {\n (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);\n }\n }\n\n cm.display.selForContextMenu = null;\n }\n\n function _replaceRange(doc, code, from, to, origin) {\n var assign;\n\n if (!to) {\n to = from;\n }\n\n if (cmp(to, from) < 0) {\n assign = [to, from], from = assign[0], to = assign[1];\n }\n\n if (typeof code == \"string\") {\n code = doc.splitLines(code);\n }\n\n makeChange(doc, {\n from: from,\n to: to,\n text: code,\n origin: origin\n });\n } // Rebasing/resetting history to deal with externally-sourced changes\n\n\n function rebaseHistSelSingle(pos, from, to, diff) {\n if (to < pos.line) {\n pos.line += diff;\n } else if (from < pos.line) {\n pos.line = from;\n pos.ch = 0;\n }\n } // Tries to rebase an array of history events given a change in the\n // document. If the change touches the same lines as the event, the\n // event, and everything 'behind' it, is discarded. If the change is\n // before the event, the event's positions are updated. Uses a\n // copy-on-write scheme for the positions, to avoid having to\n // reallocate them all on every rebase, but also avoid problems with\n // shared position objects being unsafely updated.\n\n\n function rebaseHistArray(array, from, to, diff) {\n for (var i = 0; i < array.length; ++i) {\n var sub = array[i],\n ok = true;\n\n if (sub.ranges) {\n if (!sub.copied) {\n sub = array[i] = sub.deepCopy();\n sub.copied = true;\n }\n\n for (var j = 0; j < sub.ranges.length; j++) {\n rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);\n rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);\n }\n\n continue;\n }\n\n for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {\n var cur = sub.changes[j$1];\n\n if (to < cur.from.line) {\n cur.from = Pos(cur.from.line + diff, cur.from.ch);\n cur.to = Pos(cur.to.line + diff, cur.to.ch);\n } else if (from <= cur.to.line) {\n ok = false;\n break;\n }\n }\n\n if (!ok) {\n array.splice(0, i + 1);\n i = 0;\n }\n }\n }\n\n function rebaseHist(hist, change) {\n var from = change.from.line,\n to = change.to.line,\n diff = change.text.length - (to - from) - 1;\n rebaseHistArray(hist.done, from, to, diff);\n rebaseHistArray(hist.undone, from, to, diff);\n } // Utility for applying a change to a line by handle or number,\n // returning the number and optionally registering the line as\n // changed.\n\n\n function changeLine(doc, handle, changeType, op) {\n var no = handle,\n line = handle;\n\n if (typeof handle == \"number\") {\n line = getLine(doc, clipLine(doc, handle));\n } else {\n no = lineNo(handle);\n }\n\n if (no == null) {\n return null;\n }\n\n if (op(line, no) && doc.cm) {\n regLineChange(doc.cm, no, changeType);\n }\n\n return line;\n } // The document is represented as a BTree consisting of leaves, with\n // chunk of lines in them, and branches, with up to ten leaves or\n // other branch nodes below them. The top node is always a branch\n // node, and is the document object itself (meaning it has\n // additional methods and properties).\n //\n // All nodes have parent links. The tree is used both to go from\n // line numbers to line objects, and to go from objects to numbers.\n // It also indexes by height, and is used to convert between height\n // and line object, and to find the total height of the document.\n //\n // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html\n\n\n function LeafChunk(lines) {\n this.lines = lines;\n this.parent = null;\n var height = 0;\n\n for (var i = 0; i < lines.length; ++i) {\n lines[i].parent = this;\n height += lines[i].height;\n }\n\n this.height = height;\n }\n\n LeafChunk.prototype = {\n chunkSize: function chunkSize() {\n return this.lines.length;\n },\n // Remove the n lines at offset 'at'.\n removeInner: function removeInner(at, n) {\n for (var i = at, e = at + n; i < e; ++i) {\n var line = this.lines[i];\n this.height -= line.height;\n cleanUpLine(line);\n signalLater(line, \"delete\");\n }\n\n this.lines.splice(at, n);\n },\n // Helper used to collapse a small branch into a single leaf.\n collapse: function collapse(lines) {\n lines.push.apply(lines, this.lines);\n },\n // Insert the given array of lines at offset 'at', count them as\n // having the given height.\n insertInner: function insertInner(at, lines, height) {\n this.height += height;\n this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));\n\n for (var i = 0; i < lines.length; ++i) {\n lines[i].parent = this;\n }\n },\n // Used to iterate over a part of the tree.\n iterN: function iterN(at, n, op) {\n for (var e = at + n; at < e; ++at) {\n if (op(this.lines[at])) {\n return true;\n }\n }\n }\n };\n\n function BranchChunk(children) {\n this.children = children;\n var size = 0,\n height = 0;\n\n for (var i = 0; i < children.length; ++i) {\n var ch = children[i];\n size += ch.chunkSize();\n height += ch.height;\n ch.parent = this;\n }\n\n this.size = size;\n this.height = height;\n this.parent = null;\n }\n\n BranchChunk.prototype = {\n chunkSize: function chunkSize() {\n return this.size;\n },\n removeInner: function removeInner(at, n) {\n this.size -= n;\n\n for (var i = 0; i < this.children.length; ++i) {\n var child = this.children[i],\n sz = child.chunkSize();\n\n if (at < sz) {\n var rm = Math.min(n, sz - at),\n oldHeight = child.height;\n child.removeInner(at, rm);\n this.height -= oldHeight - child.height;\n\n if (sz == rm) {\n this.children.splice(i--, 1);\n child.parent = null;\n }\n\n if ((n -= rm) == 0) {\n break;\n }\n\n at = 0;\n } else {\n at -= sz;\n }\n } // If the result is smaller than 25 lines, ensure that it is a\n // single leaf node.\n\n\n if (this.size - n < 25 && (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {\n var lines = [];\n this.collapse(lines);\n this.children = [new LeafChunk(lines)];\n this.children[0].parent = this;\n }\n },\n collapse: function collapse(lines) {\n for (var i = 0; i < this.children.length; ++i) {\n this.children[i].collapse(lines);\n }\n },\n insertInner: function insertInner(at, lines, height) {\n this.size += lines.length;\n this.height += height;\n\n for (var i = 0; i < this.children.length; ++i) {\n var child = this.children[i],\n sz = child.chunkSize();\n\n if (at <= sz) {\n child.insertInner(at, lines, height);\n\n if (child.lines && child.lines.length > 50) {\n // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.\n // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.\n var remaining = child.lines.length % 25 + 25;\n\n for (var pos = remaining; pos < child.lines.length;) {\n var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));\n child.height -= leaf.height;\n this.children.splice(++i, 0, leaf);\n leaf.parent = this;\n }\n\n child.lines = child.lines.slice(0, remaining);\n this.maybeSpill();\n }\n\n break;\n }\n\n at -= sz;\n }\n },\n // When a node has grown, check whether it should be split.\n maybeSpill: function maybeSpill() {\n if (this.children.length <= 10) {\n return;\n }\n\n var me = this;\n\n do {\n var spilled = me.children.splice(me.children.length - 5, 5);\n var sibling = new BranchChunk(spilled);\n\n if (!me.parent) {\n // Become the parent node\n var copy = new BranchChunk(me.children);\n copy.parent = me;\n me.children = [copy, sibling];\n me = copy;\n } else {\n me.size -= sibling.size;\n me.height -= sibling.height;\n var myIndex = indexOf(me.parent.children, me);\n me.parent.children.splice(myIndex + 1, 0, sibling);\n }\n\n sibling.parent = me.parent;\n } while (me.children.length > 10);\n\n me.parent.maybeSpill();\n },\n iterN: function iterN(at, n, op) {\n for (var i = 0; i < this.children.length; ++i) {\n var child = this.children[i],\n sz = child.chunkSize();\n\n if (at < sz) {\n var used = Math.min(n, sz - at);\n\n if (child.iterN(at, used, op)) {\n return true;\n }\n\n if ((n -= used) == 0) {\n break;\n }\n\n at = 0;\n } else {\n at -= sz;\n }\n }\n }\n }; // Line widgets are block elements displayed above or below a line.\n\n var LineWidget = function LineWidget(doc, node, options) {\n if (options) {\n for (var opt in options) {\n if (options.hasOwnProperty(opt)) {\n this[opt] = options[opt];\n }\n }\n }\n\n this.doc = doc;\n this.node = node;\n };\n\n LineWidget.prototype.clear = function () {\n var cm = this.doc.cm,\n ws = this.line.widgets,\n line = this.line,\n no = lineNo(line);\n\n if (no == null || !ws) {\n return;\n }\n\n for (var i = 0; i < ws.length; ++i) {\n if (ws[i] == this) {\n ws.splice(i--, 1);\n }\n }\n\n if (!ws.length) {\n line.widgets = null;\n }\n\n var height = widgetHeight(this);\n updateLineHeight(line, Math.max(0, line.height - height));\n\n if (cm) {\n runInOp(cm, function () {\n adjustScrollWhenAboveVisible(cm, line, -height);\n regLineChange(cm, no, \"widget\");\n });\n signalLater(cm, \"lineWidgetCleared\", cm, this, no);\n }\n };\n\n LineWidget.prototype.changed = function () {\n var this$1 = this;\n var oldH = this.height,\n cm = this.doc.cm,\n line = this.line;\n this.height = null;\n var diff = widgetHeight(this) - oldH;\n\n if (!diff) {\n return;\n }\n\n if (!lineIsHidden(this.doc, line)) {\n updateLineHeight(line, line.height + diff);\n }\n\n if (cm) {\n runInOp(cm, function () {\n cm.curOp.forceUpdate = true;\n adjustScrollWhenAboveVisible(cm, line, diff);\n signalLater(cm, \"lineWidgetChanged\", cm, this$1, lineNo(line));\n });\n }\n };\n\n eventMixin(LineWidget);\n\n function adjustScrollWhenAboveVisible(cm, line, diff) {\n if (_heightAtLine(line) < (cm.curOp && cm.curOp.scrollTop || cm.doc.scrollTop)) {\n addToScrollTop(cm, diff);\n }\n }\n\n function addLineWidget(doc, handle, node, options) {\n var widget = new LineWidget(doc, node, options);\n var cm = doc.cm;\n\n if (cm && widget.noHScroll) {\n cm.display.alignWidgets = true;\n }\n\n changeLine(doc, handle, \"widget\", function (line) {\n var widgets = line.widgets || (line.widgets = []);\n\n if (widget.insertAt == null) {\n widgets.push(widget);\n } else {\n widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);\n }\n\n widget.line = line;\n\n if (cm && !lineIsHidden(doc, line)) {\n var aboveVisible = _heightAtLine(line) < doc.scrollTop;\n updateLineHeight(line, line.height + widgetHeight(widget));\n\n if (aboveVisible) {\n addToScrollTop(cm, widget.height);\n }\n\n cm.curOp.forceUpdate = true;\n }\n\n return true;\n });\n\n if (cm) {\n signalLater(cm, \"lineWidgetAdded\", cm, widget, typeof handle == \"number\" ? handle : lineNo(handle));\n }\n\n return widget;\n } // TEXTMARKERS\n // Created with markText and setBookmark methods. A TextMarker is a\n // handle that can be used to clear or find a marked position in the\n // document. Line objects hold arrays (markedSpans) containing\n // {from, to, marker} object pointing to such marker objects, and\n // indicating that such a marker is present on that line. Multiple\n // lines may point to the same marker when it spans across lines.\n // The spans will have null for their from/to properties when the\n // marker continues beyond the start/end of the line. Markers have\n // links back to the lines they currently touch.\n // Collapsed markers have unique ids, in order to be able to order\n // them, which is needed for uniquely determining an outer marker\n // when they overlap (they may nest, but not partially overlap).\n\n\n var nextMarkerId = 0;\n\n var TextMarker = function TextMarker(doc, type) {\n this.lines = [];\n this.type = type;\n this.doc = doc;\n this.id = ++nextMarkerId;\n }; // Clear the marker.\n\n\n TextMarker.prototype.clear = function () {\n if (this.explicitlyCleared) {\n return;\n }\n\n var cm = this.doc.cm,\n withOp = cm && !cm.curOp;\n\n if (withOp) {\n _startOperation(cm);\n }\n\n if (hasHandler(this, \"clear\")) {\n var found = this.find();\n\n if (found) {\n signalLater(this, \"clear\", found.from, found.to);\n }\n }\n\n var min = null,\n max = null;\n\n for (var i = 0; i < this.lines.length; ++i) {\n var line = this.lines[i];\n var span = getMarkedSpanFor(line.markedSpans, this);\n\n if (cm && !this.collapsed) {\n regLineChange(cm, lineNo(line), \"text\");\n } else if (cm) {\n if (span.to != null) {\n max = lineNo(line);\n }\n\n if (span.from != null) {\n min = lineNo(line);\n }\n }\n\n line.markedSpans = removeMarkedSpan(line.markedSpans, span);\n\n if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm) {\n updateLineHeight(line, textHeight(cm.display));\n }\n }\n\n if (cm && this.collapsed && !cm.options.lineWrapping) {\n for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {\n var visual = visualLine(this.lines[i$1]),\n len = lineLength(visual);\n\n if (len > cm.display.maxLineLength) {\n cm.display.maxLine = visual;\n cm.display.maxLineLength = len;\n cm.display.maxLineChanged = true;\n }\n }\n }\n\n if (min != null && cm && this.collapsed) {\n regChange(cm, min, max + 1);\n }\n\n this.lines.length = 0;\n this.explicitlyCleared = true;\n\n if (this.atomic && this.doc.cantEdit) {\n this.doc.cantEdit = false;\n\n if (cm) {\n reCheckSelection(cm.doc);\n }\n }\n\n if (cm) {\n signalLater(cm, \"markerCleared\", cm, this, min, max);\n }\n\n if (withOp) {\n _endOperation(cm);\n }\n\n if (this.parent) {\n this.parent.clear();\n }\n }; // Find the position of the marker in the document. Returns a {from,\n // to} object by default. Side can be passed to get a specific side\n // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the\n // Pos objects returned contain a line object, rather than a line\n // number (used to prevent looking up the same line twice).\n\n\n TextMarker.prototype.find = function (side, lineObj) {\n if (side == null && this.type == \"bookmark\") {\n side = 1;\n }\n\n var from, to;\n\n for (var i = 0; i < this.lines.length; ++i) {\n var line = this.lines[i];\n var span = getMarkedSpanFor(line.markedSpans, this);\n\n if (span.from != null) {\n from = Pos(lineObj ? line : lineNo(line), span.from);\n\n if (side == -1) {\n return from;\n }\n }\n\n if (span.to != null) {\n to = Pos(lineObj ? line : lineNo(line), span.to);\n\n if (side == 1) {\n return to;\n }\n }\n }\n\n return from && {\n from: from,\n to: to\n };\n }; // Signals that the marker's widget changed, and surrounding layout\n // should be recomputed.\n\n\n TextMarker.prototype.changed = function () {\n var this$1 = this;\n var pos = this.find(-1, true),\n widget = this,\n cm = this.doc.cm;\n\n if (!pos || !cm) {\n return;\n }\n\n runInOp(cm, function () {\n var line = pos.line,\n lineN = lineNo(pos.line);\n var view = findViewForLine(cm, lineN);\n\n if (view) {\n clearLineMeasurementCacheFor(view);\n cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;\n }\n\n cm.curOp.updateMaxLine = true;\n\n if (!lineIsHidden(widget.doc, line) && widget.height != null) {\n var oldHeight = widget.height;\n widget.height = null;\n var dHeight = widgetHeight(widget) - oldHeight;\n\n if (dHeight) {\n updateLineHeight(line, line.height + dHeight);\n }\n }\n\n signalLater(cm, \"markerChanged\", cm, this$1);\n });\n };\n\n TextMarker.prototype.attachLine = function (line) {\n if (!this.lines.length && this.doc.cm) {\n var op = this.doc.cm.curOp;\n\n if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1) {\n (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);\n }\n }\n\n this.lines.push(line);\n };\n\n TextMarker.prototype.detachLine = function (line) {\n this.lines.splice(indexOf(this.lines, line), 1);\n\n if (!this.lines.length && this.doc.cm) {\n var op = this.doc.cm.curOp;\n (op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);\n }\n };\n\n eventMixin(TextMarker); // Create a marker, wire it up to the right lines, and\n\n function _markText(doc, from, to, options, type) {\n // Shared markers (across linked documents) are handled separately\n // (markTextShared will call out to this again, once per\n // document).\n if (options && options.shared) {\n return markTextShared(doc, from, to, options, type);\n } // Ensure we are in an operation.\n\n\n if (doc.cm && !doc.cm.curOp) {\n return operation(doc.cm, _markText)(doc, from, to, options, type);\n }\n\n var marker = new TextMarker(doc, type),\n diff = cmp(from, to);\n\n if (options) {\n copyObj(options, marker, false);\n } // Don't connect empty markers unless clearWhenEmpty is false\n\n\n if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false) {\n return marker;\n }\n\n if (marker.replacedWith) {\n // Showing up as a widget implies collapsed (widget replaces text)\n marker.collapsed = true;\n marker.widgetNode = eltP(\"span\", [marker.replacedWith], \"CodeMirror-widget\");\n\n if (!options.handleMouseEvents) {\n marker.widgetNode.setAttribute(\"cm-ignore-events\", \"true\");\n }\n\n if (options.insertLeft) {\n marker.widgetNode.insertLeft = true;\n }\n }\n\n if (marker.collapsed) {\n if (conflictingCollapsedRange(doc, from.line, from, to, marker) || from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker)) {\n throw new Error(\"Inserting collapsed marker partially overlapping an existing one\");\n }\n\n seeCollapsedSpans();\n }\n\n if (marker.addToHistory) {\n addChangeToHistory(doc, {\n from: from,\n to: to,\n origin: \"markText\"\n }, doc.sel, NaN);\n }\n\n var curLine = from.line,\n cm = doc.cm,\n updateMaxLine;\n doc.iter(curLine, to.line + 1, function (line) {\n if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) {\n updateMaxLine = true;\n }\n\n if (marker.collapsed && curLine != from.line) {\n updateLineHeight(line, 0);\n }\n\n addMarkedSpan(line, new MarkedSpan(marker, curLine == from.line ? from.ch : null, curLine == to.line ? to.ch : null));\n ++curLine;\n }); // lineIsHidden depends on the presence of the spans, so needs a second pass\n\n if (marker.collapsed) {\n doc.iter(from.line, to.line + 1, function (line) {\n if (lineIsHidden(doc, line)) {\n updateLineHeight(line, 0);\n }\n });\n }\n\n if (marker.clearOnEnter) {\n on(marker, \"beforeCursorEnter\", function () {\n return marker.clear();\n });\n }\n\n if (marker.readOnly) {\n seeReadOnlySpans();\n\n if (doc.history.done.length || doc.history.undone.length) {\n doc.clearHistory();\n }\n }\n\n if (marker.collapsed) {\n marker.id = ++nextMarkerId;\n marker.atomic = true;\n }\n\n if (cm) {\n // Sync editor state\n if (updateMaxLine) {\n cm.curOp.updateMaxLine = true;\n }\n\n if (marker.collapsed) {\n regChange(cm, from.line, to.line + 1);\n } else if (marker.className || marker.startStyle || marker.endStyle || marker.css || marker.attributes || marker.title) {\n for (var i = from.line; i <= to.line; i++) {\n regLineChange(cm, i, \"text\");\n }\n }\n\n if (marker.atomic) {\n reCheckSelection(cm.doc);\n }\n\n signalLater(cm, \"markerAdded\", cm, marker);\n }\n\n return marker;\n } // SHARED TEXTMARKERS\n // A shared marker spans multiple linked documents. It is\n // implemented as a meta-marker-object controlling multiple normal\n // markers.\n\n\n var SharedTextMarker = function SharedTextMarker(markers, primary) {\n this.markers = markers;\n this.primary = primary;\n\n for (var i = 0; i < markers.length; ++i) {\n markers[i].parent = this;\n }\n };\n\n SharedTextMarker.prototype.clear = function () {\n if (this.explicitlyCleared) {\n return;\n }\n\n this.explicitlyCleared = true;\n\n for (var i = 0; i < this.markers.length; ++i) {\n this.markers[i].clear();\n }\n\n signalLater(this, \"clear\");\n };\n\n SharedTextMarker.prototype.find = function (side, lineObj) {\n return this.primary.find(side, lineObj);\n };\n\n eventMixin(SharedTextMarker);\n\n function markTextShared(doc, from, to, options, type) {\n options = copyObj(options);\n options.shared = false;\n var markers = [_markText(doc, from, to, options, type)],\n primary = markers[0];\n var widget = options.widgetNode;\n linkedDocs(doc, function (doc) {\n if (widget) {\n options.widgetNode = widget.cloneNode(true);\n }\n\n markers.push(_markText(doc, _clipPos(doc, from), _clipPos(doc, to), options, type));\n\n for (var i = 0; i < doc.linked.length; ++i) {\n if (doc.linked[i].isParent) {\n return;\n }\n }\n\n primary = lst(markers);\n });\n return new SharedTextMarker(markers, primary);\n }\n\n function findSharedMarkers(doc) {\n return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) {\n return m.parent;\n });\n }\n\n function copySharedMarkers(doc, markers) {\n for (var i = 0; i < markers.length; i++) {\n var marker = markers[i],\n pos = marker.find();\n var mFrom = doc.clipPos(pos.from),\n mTo = doc.clipPos(pos.to);\n\n if (cmp(mFrom, mTo)) {\n var subMark = _markText(doc, mFrom, mTo, marker.primary, marker.primary.type);\n\n marker.markers.push(subMark);\n subMark.parent = marker;\n }\n }\n }\n\n function detachSharedMarkers(markers) {\n var loop = function loop(i) {\n var marker = markers[i],\n linked = [marker.primary.doc];\n linkedDocs(marker.primary.doc, function (d) {\n return linked.push(d);\n });\n\n for (var j = 0; j < marker.markers.length; j++) {\n var subMarker = marker.markers[j];\n\n if (indexOf(linked, subMarker.doc) == -1) {\n subMarker.parent = null;\n marker.markers.splice(j--, 1);\n }\n }\n };\n\n for (var i = 0; i < markers.length; i++) {\n loop(i);\n }\n }\n\n var nextDocId = 0;\n\n var Doc = function Doc(text, mode, firstLine, lineSep, direction) {\n if (!(this instanceof Doc)) {\n return new Doc(text, mode, firstLine, lineSep, direction);\n }\n\n if (firstLine == null) {\n firstLine = 0;\n }\n\n BranchChunk.call(this, [new LeafChunk([new Line(\"\", null)])]);\n this.first = firstLine;\n this.scrollTop = this.scrollLeft = 0;\n this.cantEdit = false;\n this.cleanGeneration = 1;\n this.modeFrontier = this.highlightFrontier = firstLine;\n var start = Pos(firstLine, 0);\n this.sel = simpleSelection(start);\n this.history = new History(null);\n this.id = ++nextDocId;\n this.modeOption = mode;\n this.lineSep = lineSep;\n this.direction = direction == \"rtl\" ? \"rtl\" : \"ltr\";\n this.extend = false;\n\n if (typeof text == \"string\") {\n text = this.splitLines(text);\n }\n\n updateDoc(this, {\n from: start,\n to: start,\n text: text\n });\n setSelection(this, simpleSelection(start), sel_dontScroll);\n };\n\n Doc.prototype = createObj(BranchChunk.prototype, {\n constructor: Doc,\n // Iterate over the document. Supports two forms -- with only one\n // argument, it calls that for each line in the document. With\n // three, it iterates over the range given by the first two (with\n // the second being non-inclusive).\n iter: function iter(from, to, op) {\n if (op) {\n this.iterN(from - this.first, to - from, op);\n } else {\n this.iterN(this.first, this.first + this.size, from);\n }\n },\n // Non-public interface for adding and removing lines.\n insert: function insert(at, lines) {\n var height = 0;\n\n for (var i = 0; i < lines.length; ++i) {\n height += lines[i].height;\n }\n\n this.insertInner(at - this.first, lines, height);\n },\n remove: function remove(at, n) {\n this.removeInner(at - this.first, n);\n },\n // From here, the methods are part of the public interface. Most\n // are also available from CodeMirror (editor) instances.\n getValue: function getValue(lineSep) {\n var lines = getLines(this, this.first, this.first + this.size);\n\n if (lineSep === false) {\n return lines;\n }\n\n return lines.join(lineSep || this.lineSeparator());\n },\n setValue: docMethodOp(function (code) {\n var top = Pos(this.first, 0),\n last = this.first + this.size - 1;\n makeChange(this, {\n from: top,\n to: Pos(last, getLine(this, last).text.length),\n text: this.splitLines(code),\n origin: \"setValue\",\n full: true\n }, true);\n\n if (this.cm) {\n scrollToCoords(this.cm, 0, 0);\n }\n\n setSelection(this, simpleSelection(top), sel_dontScroll);\n }),\n replaceRange: function replaceRange(code, from, to, origin) {\n from = _clipPos(this, from);\n to = to ? _clipPos(this, to) : from;\n\n _replaceRange(this, code, from, to, origin);\n },\n getRange: function getRange(from, to, lineSep) {\n var lines = getBetween(this, _clipPos(this, from), _clipPos(this, to));\n\n if (lineSep === false) {\n return lines;\n }\n\n return lines.join(lineSep || this.lineSeparator());\n },\n getLine: function getLine(line) {\n var l = this.getLineHandle(line);\n return l && l.text;\n },\n getLineHandle: function getLineHandle(line) {\n if (isLine(this, line)) {\n return getLine(this, line);\n }\n },\n getLineNumber: function getLineNumber(line) {\n return lineNo(line);\n },\n getLineHandleVisualStart: function getLineHandleVisualStart(line) {\n if (typeof line == \"number\") {\n line = getLine(this, line);\n }\n\n return visualLine(line);\n },\n lineCount: function lineCount() {\n return this.size;\n },\n firstLine: function firstLine() {\n return this.first;\n },\n lastLine: function lastLine() {\n return this.first + this.size - 1;\n },\n clipPos: function clipPos(pos) {\n return _clipPos(this, pos);\n },\n getCursor: function getCursor(start) {\n var range = this.sel.primary(),\n pos;\n\n if (start == null || start == \"head\") {\n pos = range.head;\n } else if (start == \"anchor\") {\n pos = range.anchor;\n } else if (start == \"end\" || start == \"to\" || start === false) {\n pos = range.to();\n } else {\n pos = range.from();\n }\n\n return pos;\n },\n listSelections: function listSelections() {\n return this.sel.ranges;\n },\n somethingSelected: function somethingSelected() {\n return this.sel.somethingSelected();\n },\n setCursor: docMethodOp(function (line, ch, options) {\n setSimpleSelection(this, _clipPos(this, typeof line == \"number\" ? Pos(line, ch || 0) : line), null, options);\n }),\n setSelection: docMethodOp(function (anchor, head, options) {\n setSimpleSelection(this, _clipPos(this, anchor), _clipPos(this, head || anchor), options);\n }),\n extendSelection: docMethodOp(function (head, other, options) {\n extendSelection(this, _clipPos(this, head), other && _clipPos(this, other), options);\n }),\n extendSelections: docMethodOp(function (heads, options) {\n extendSelections(this, clipPosArray(this, heads), options);\n }),\n extendSelectionsBy: docMethodOp(function (f, options) {\n var heads = map(this.sel.ranges, f);\n extendSelections(this, clipPosArray(this, heads), options);\n }),\n setSelections: docMethodOp(function (ranges, primary, options) {\n if (!ranges.length) {\n return;\n }\n\n var out = [];\n\n for (var i = 0; i < ranges.length; i++) {\n out[i] = new Range(_clipPos(this, ranges[i].anchor), _clipPos(this, ranges[i].head));\n }\n\n if (primary == null) {\n primary = Math.min(ranges.length - 1, this.sel.primIndex);\n }\n\n setSelection(this, normalizeSelection(this.cm, out, primary), options);\n }),\n addSelection: docMethodOp(function (anchor, head, options) {\n var ranges = this.sel.ranges.slice(0);\n ranges.push(new Range(_clipPos(this, anchor), _clipPos(this, head || anchor)));\n setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options);\n }),\n getSelection: function getSelection(lineSep) {\n var ranges = this.sel.ranges,\n lines;\n\n for (var i = 0; i < ranges.length; i++) {\n var sel = getBetween(this, ranges[i].from(), ranges[i].to());\n lines = lines ? lines.concat(sel) : sel;\n }\n\n if (lineSep === false) {\n return lines;\n } else {\n return lines.join(lineSep || this.lineSeparator());\n }\n },\n getSelections: function getSelections(lineSep) {\n var parts = [],\n ranges = this.sel.ranges;\n\n for (var i = 0; i < ranges.length; i++) {\n var sel = getBetween(this, ranges[i].from(), ranges[i].to());\n\n if (lineSep !== false) {\n sel = sel.join(lineSep || this.lineSeparator());\n }\n\n parts[i] = sel;\n }\n\n return parts;\n },\n replaceSelection: function replaceSelection(code, collapse, origin) {\n var dup = [];\n\n for (var i = 0; i < this.sel.ranges.length; i++) {\n dup[i] = code;\n }\n\n this.replaceSelections(dup, collapse, origin || \"+input\");\n },\n replaceSelections: docMethodOp(function (code, collapse, origin) {\n var changes = [],\n sel = this.sel;\n\n for (var i = 0; i < sel.ranges.length; i++) {\n var range = sel.ranges[i];\n changes[i] = {\n from: range.from(),\n to: range.to(),\n text: this.splitLines(code[i]),\n origin: origin\n };\n }\n\n var newSel = collapse && collapse != \"end\" && computeReplacedSel(this, changes, collapse);\n\n for (var i$1 = changes.length - 1; i$1 >= 0; i$1--) {\n makeChange(this, changes[i$1]);\n }\n\n if (newSel) {\n setSelectionReplaceHistory(this, newSel);\n } else if (this.cm) {\n ensureCursorVisible(this.cm);\n }\n }),\n undo: docMethodOp(function () {\n makeChangeFromHistory(this, \"undo\");\n }),\n redo: docMethodOp(function () {\n makeChangeFromHistory(this, \"redo\");\n }),\n undoSelection: docMethodOp(function () {\n makeChangeFromHistory(this, \"undo\", true);\n }),\n redoSelection: docMethodOp(function () {\n makeChangeFromHistory(this, \"redo\", true);\n }),\n setExtending: function setExtending(val) {\n this.extend = val;\n },\n getExtending: function getExtending() {\n return this.extend;\n },\n historySize: function historySize() {\n var hist = this.history,\n done = 0,\n undone = 0;\n\n for (var i = 0; i < hist.done.length; i++) {\n if (!hist.done[i].ranges) {\n ++done;\n }\n }\n\n for (var i$1 = 0; i$1 < hist.undone.length; i$1++) {\n if (!hist.undone[i$1].ranges) {\n ++undone;\n }\n }\n\n return {\n undo: done,\n redo: undone\n };\n },\n clearHistory: function clearHistory() {\n var this$1 = this;\n this.history = new History(this.history.maxGeneration);\n linkedDocs(this, function (doc) {\n return doc.history = this$1.history;\n }, true);\n },\n markClean: function markClean() {\n this.cleanGeneration = this.changeGeneration(true);\n },\n changeGeneration: function changeGeneration(forceSplit) {\n if (forceSplit) {\n this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;\n }\n\n return this.history.generation;\n },\n isClean: function isClean(gen) {\n return this.history.generation == (gen || this.cleanGeneration);\n },\n getHistory: function getHistory() {\n return {\n done: copyHistoryArray(this.history.done),\n undone: copyHistoryArray(this.history.undone)\n };\n },\n setHistory: function setHistory(histData) {\n var hist = this.history = new History(this.history.maxGeneration);\n hist.done = copyHistoryArray(histData.done.slice(0), null, true);\n hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);\n },\n setGutterMarker: docMethodOp(function (line, gutterID, value) {\n return changeLine(this, line, \"gutter\", function (line) {\n var markers = line.gutterMarkers || (line.gutterMarkers = {});\n markers[gutterID] = value;\n\n if (!value && isEmpty(markers)) {\n line.gutterMarkers = null;\n }\n\n return true;\n });\n }),\n clearGutter: docMethodOp(function (gutterID) {\n var this$1 = this;\n this.iter(function (line) {\n if (line.gutterMarkers && line.gutterMarkers[gutterID]) {\n changeLine(this$1, line, \"gutter\", function () {\n line.gutterMarkers[gutterID] = null;\n\n if (isEmpty(line.gutterMarkers)) {\n line.gutterMarkers = null;\n }\n\n return true;\n });\n }\n });\n }),\n lineInfo: function lineInfo(line) {\n var n;\n\n if (typeof line == \"number\") {\n if (!isLine(this, line)) {\n return null;\n }\n\n n = line;\n line = getLine(this, line);\n\n if (!line) {\n return null;\n }\n } else {\n n = lineNo(line);\n\n if (n == null) {\n return null;\n }\n }\n\n return {\n line: n,\n handle: line,\n text: line.text,\n gutterMarkers: line.gutterMarkers,\n textClass: line.textClass,\n bgClass: line.bgClass,\n wrapClass: line.wrapClass,\n widgets: line.widgets\n };\n },\n addLineClass: docMethodOp(function (handle, where, cls) {\n return changeLine(this, handle, where == \"gutter\" ? \"gutter\" : \"class\", function (line) {\n var prop = where == \"text\" ? \"textClass\" : where == \"background\" ? \"bgClass\" : where == \"gutter\" ? \"gutterClass\" : \"wrapClass\";\n\n if (!line[prop]) {\n line[prop] = cls;\n } else if (classTest(cls).test(line[prop])) {\n return false;\n } else {\n line[prop] += \" \" + cls;\n }\n\n return true;\n });\n }),\n removeLineClass: docMethodOp(function (handle, where, cls) {\n return changeLine(this, handle, where == \"gutter\" ? \"gutter\" : \"class\", function (line) {\n var prop = where == \"text\" ? \"textClass\" : where == \"background\" ? \"bgClass\" : where == \"gutter\" ? \"gutterClass\" : \"wrapClass\";\n var cur = line[prop];\n\n if (!cur) {\n return false;\n } else if (cls == null) {\n line[prop] = null;\n } else {\n var found = cur.match(classTest(cls));\n\n if (!found) {\n return false;\n }\n\n var end = found.index + found[0].length;\n line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? \"\" : \" \") + cur.slice(end) || null;\n }\n\n return true;\n });\n }),\n addLineWidget: docMethodOp(function (handle, node, options) {\n return addLineWidget(this, handle, node, options);\n }),\n removeLineWidget: function removeLineWidget(widget) {\n widget.clear();\n },\n markText: function markText(from, to, options) {\n return _markText(this, _clipPos(this, from), _clipPos(this, to), options, options && options.type || \"range\");\n },\n setBookmark: function setBookmark(pos, options) {\n var realOpts = {\n replacedWith: options && (options.nodeType == null ? options.widget : options),\n insertLeft: options && options.insertLeft,\n clearWhenEmpty: false,\n shared: options && options.shared,\n handleMouseEvents: options && options.handleMouseEvents\n };\n pos = _clipPos(this, pos);\n return _markText(this, pos, pos, realOpts, \"bookmark\");\n },\n findMarksAt: function findMarksAt(pos) {\n pos = _clipPos(this, pos);\n var markers = [],\n spans = getLine(this, pos.line).markedSpans;\n\n if (spans) {\n for (var i = 0; i < spans.length; ++i) {\n var span = spans[i];\n\n if ((span.from == null || span.from <= pos.ch) && (span.to == null || span.to >= pos.ch)) {\n markers.push(span.marker.parent || span.marker);\n }\n }\n }\n\n return markers;\n },\n findMarks: function findMarks(from, to, filter) {\n from = _clipPos(this, from);\n to = _clipPos(this, to);\n var found = [],\n lineNo = from.line;\n this.iter(from.line, to.line + 1, function (line) {\n var spans = line.markedSpans;\n\n if (spans) {\n for (var i = 0; i < spans.length; i++) {\n var span = spans[i];\n\n if (!(span.to != null && lineNo == from.line && from.ch >= span.to || span.from == null && lineNo != from.line || span.from != null && lineNo == to.line && span.from >= to.ch) && (!filter || filter(span.marker))) {\n found.push(span.marker.parent || span.marker);\n }\n }\n }\n\n ++lineNo;\n });\n return found;\n },\n getAllMarks: function getAllMarks() {\n var markers = [];\n this.iter(function (line) {\n var sps = line.markedSpans;\n\n if (sps) {\n for (var i = 0; i < sps.length; ++i) {\n if (sps[i].from != null) {\n markers.push(sps[i].marker);\n }\n }\n }\n });\n return markers;\n },\n posFromIndex: function posFromIndex(off) {\n var ch,\n lineNo = this.first,\n sepSize = this.lineSeparator().length;\n this.iter(function (line) {\n var sz = line.text.length + sepSize;\n\n if (sz > off) {\n ch = off;\n return true;\n }\n\n off -= sz;\n ++lineNo;\n });\n return _clipPos(this, Pos(lineNo, ch));\n },\n indexFromPos: function indexFromPos(coords) {\n coords = _clipPos(this, coords);\n var index = coords.ch;\n\n if (coords.line < this.first || coords.ch < 0) {\n return 0;\n }\n\n var sepSize = this.lineSeparator().length;\n this.iter(this.first, coords.line, function (line) {\n // iter aborts when callback returns a truthy value\n index += line.text.length + sepSize;\n });\n return index;\n },\n copy: function copy(copyHistory) {\n var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first, this.lineSep, this.direction);\n doc.scrollTop = this.scrollTop;\n doc.scrollLeft = this.scrollLeft;\n doc.sel = this.sel;\n doc.extend = false;\n\n if (copyHistory) {\n doc.history.undoDepth = this.history.undoDepth;\n doc.setHistory(this.getHistory());\n }\n\n return doc;\n },\n linkedDoc: function linkedDoc(options) {\n if (!options) {\n options = {};\n }\n\n var from = this.first,\n to = this.first + this.size;\n\n if (options.from != null && options.from > from) {\n from = options.from;\n }\n\n if (options.to != null && options.to < to) {\n to = options.to;\n }\n\n var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);\n\n if (options.sharedHist) {\n copy.history = this.history;\n }\n\n (this.linked || (this.linked = [])).push({\n doc: copy,\n sharedHist: options.sharedHist\n });\n copy.linked = [{\n doc: this,\n isParent: true,\n sharedHist: options.sharedHist\n }];\n copySharedMarkers(copy, findSharedMarkers(this));\n return copy;\n },\n unlinkDoc: function unlinkDoc(other) {\n if (other instanceof CodeMirror) {\n other = other.doc;\n }\n\n if (this.linked) {\n for (var i = 0; i < this.linked.length; ++i) {\n var link = this.linked[i];\n\n if (link.doc != other) {\n continue;\n }\n\n this.linked.splice(i, 1);\n other.unlinkDoc(this);\n detachSharedMarkers(findSharedMarkers(this));\n break;\n }\n } // If the histories were shared, split them again\n\n\n if (other.history == this.history) {\n var splitIds = [other.id];\n linkedDocs(other, function (doc) {\n return splitIds.push(doc.id);\n }, true);\n other.history = new History(null);\n other.history.done = copyHistoryArray(this.history.done, splitIds);\n other.history.undone = copyHistoryArray(this.history.undone, splitIds);\n }\n },\n iterLinkedDocs: function iterLinkedDocs(f) {\n linkedDocs(this, f);\n },\n getMode: function getMode() {\n return this.mode;\n },\n getEditor: function getEditor() {\n return this.cm;\n },\n splitLines: function splitLines(str) {\n if (this.lineSep) {\n return str.split(this.lineSep);\n }\n\n return splitLinesAuto(str);\n },\n lineSeparator: function lineSeparator() {\n return this.lineSep || \"\\n\";\n },\n setDirection: docMethodOp(function (dir) {\n if (dir != \"rtl\") {\n dir = \"ltr\";\n }\n\n if (dir == this.direction) {\n return;\n }\n\n this.direction = dir;\n this.iter(function (line) {\n return line.order = null;\n });\n\n if (this.cm) {\n directionChanged(this.cm);\n }\n })\n }); // Public alias.\n\n Doc.prototype.eachLine = Doc.prototype.iter; // Kludge to work around strange IE behavior where it'll sometimes\n // re-fire a series of drag-related events right after the drop (#1551)\n\n var lastDrop = 0;\n\n function onDrop(e) {\n var cm = this;\n clearDragCursor(cm);\n\n if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) {\n return;\n }\n\n e_preventDefault(e);\n\n if (ie) {\n lastDrop = +new Date();\n }\n\n var pos = posFromMouse(cm, e, true),\n files = e.dataTransfer.files;\n\n if (!pos || cm.isReadOnly()) {\n return;\n } // Might be a file drop, in which case we simply extract the text\n // and insert it.\n\n\n if (files && files.length && window.FileReader && window.File) {\n var n = files.length,\n text = Array(n),\n read = 0;\n\n var markAsReadAndPasteIfAllFilesAreRead = function markAsReadAndPasteIfAllFilesAreRead() {\n if (++read == n) {\n operation(cm, function () {\n pos = _clipPos(cm.doc, pos);\n var change = {\n from: pos,\n to: pos,\n text: cm.doc.splitLines(text.filter(function (t) {\n return t != null;\n }).join(cm.doc.lineSeparator())),\n origin: \"paste\"\n };\n makeChange(cm.doc, change);\n setSelectionReplaceHistory(cm.doc, simpleSelection(_clipPos(cm.doc, pos), _clipPos(cm.doc, changeEnd(change))));\n })();\n }\n };\n\n var readTextFromFile = function readTextFromFile(file, i) {\n if (cm.options.allowDropFileTypes && indexOf(cm.options.allowDropFileTypes, file.type) == -1) {\n markAsReadAndPasteIfAllFilesAreRead();\n return;\n }\n\n var reader = new FileReader();\n\n reader.onerror = function () {\n return markAsReadAndPasteIfAllFilesAreRead();\n };\n\n reader.onload = function () {\n var content = reader.result;\n\n if (/[\\x00-\\x08\\x0e-\\x1f]{2}/.test(content)) {\n markAsReadAndPasteIfAllFilesAreRead();\n return;\n }\n\n text[i] = content;\n markAsReadAndPasteIfAllFilesAreRead();\n };\n\n reader.readAsText(file);\n };\n\n for (var i = 0; i < files.length; i++) {\n readTextFromFile(files[i], i);\n }\n } else {\n // Normal drop\n // Don't do a replace if the drop happened inside of the selected text.\n if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {\n cm.state.draggingText(e); // Ensure the editor is re-focused\n\n setTimeout(function () {\n return cm.display.input.focus();\n }, 20);\n return;\n }\n\n try {\n var text$1 = e.dataTransfer.getData(\"Text\");\n\n if (text$1) {\n var selected;\n\n if (cm.state.draggingText && !cm.state.draggingText.copy) {\n selected = cm.listSelections();\n }\n\n setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));\n\n if (selected) {\n for (var i$1 = 0; i$1 < selected.length; ++i$1) {\n _replaceRange(cm.doc, \"\", selected[i$1].anchor, selected[i$1].head, \"drag\");\n }\n }\n\n cm.replaceSelection(text$1, \"around\", \"paste\");\n cm.display.input.focus();\n }\n } catch (e$1) {}\n }\n }\n\n function onDragStart(cm, e) {\n if (ie && (!cm.state.draggingText || +new Date() - lastDrop < 100)) {\n e_stop(e);\n return;\n }\n\n if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) {\n return;\n }\n\n e.dataTransfer.setData(\"Text\", cm.getSelection());\n e.dataTransfer.effectAllowed = \"copyMove\"; // Use dummy image instead of default browsers image.\n // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.\n\n if (e.dataTransfer.setDragImage && !safari) {\n var img = elt(\"img\", null, null, \"position: fixed; left: 0; top: 0;\");\n img.src = \"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\";\n\n if (presto) {\n img.width = img.height = 1;\n cm.display.wrapper.appendChild(img); // Force a relayout, or Opera won't use our image for some obscure reason\n\n img._top = img.offsetTop;\n }\n\n e.dataTransfer.setDragImage(img, 0, 0);\n\n if (presto) {\n img.parentNode.removeChild(img);\n }\n }\n }\n\n function onDragOver(cm, e) {\n var pos = posFromMouse(cm, e);\n\n if (!pos) {\n return;\n }\n\n var frag = document.createDocumentFragment();\n drawSelectionCursor(cm, pos, frag);\n\n if (!cm.display.dragCursor) {\n cm.display.dragCursor = elt(\"div\", null, \"CodeMirror-cursors CodeMirror-dragcursors\");\n cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);\n }\n\n removeChildrenAndAdd(cm.display.dragCursor, frag);\n }\n\n function clearDragCursor(cm) {\n if (cm.display.dragCursor) {\n cm.display.lineSpace.removeChild(cm.display.dragCursor);\n cm.display.dragCursor = null;\n }\n } // These must be handled carefully, because naively registering a\n // handler for each editor will cause the editors to never be\n // garbage collected.\n\n\n function forEachCodeMirror(f) {\n if (!document.getElementsByClassName) {\n return;\n }\n\n var byClass = document.getElementsByClassName(\"CodeMirror\"),\n editors = [];\n\n for (var i = 0; i < byClass.length; i++) {\n var cm = byClass[i].CodeMirror;\n\n if (cm) {\n editors.push(cm);\n }\n }\n\n if (editors.length) {\n editors[0].operation(function () {\n for (var i = 0; i < editors.length; i++) {\n f(editors[i]);\n }\n });\n }\n }\n\n var globalsRegistered = false;\n\n function ensureGlobalHandlers() {\n if (globalsRegistered) {\n return;\n }\n\n registerGlobalHandlers();\n globalsRegistered = true;\n }\n\n function registerGlobalHandlers() {\n // When the window resizes, we need to refresh active editors.\n var resizeTimer;\n on(window, \"resize\", function () {\n if (resizeTimer == null) {\n resizeTimer = setTimeout(function () {\n resizeTimer = null;\n forEachCodeMirror(onResize);\n }, 100);\n }\n }); // When the window loses focus, we want to show the editor as blurred\n\n on(window, \"blur\", function () {\n return forEachCodeMirror(onBlur);\n });\n } // Called when the window resizes\n\n\n function onResize(cm) {\n var d = cm.display; // Might be a text scaling operation, clear size caches.\n\n d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;\n d.scrollbarsClipped = false;\n cm.setSize();\n }\n\n var keyNames = {\n 3: \"Pause\",\n 8: \"Backspace\",\n 9: \"Tab\",\n 13: \"Enter\",\n 16: \"Shift\",\n 17: \"Ctrl\",\n 18: \"Alt\",\n 19: \"Pause\",\n 20: \"CapsLock\",\n 27: \"Esc\",\n 32: \"Space\",\n 33: \"PageUp\",\n 34: \"PageDown\",\n 35: \"End\",\n 36: \"Home\",\n 37: \"Left\",\n 38: \"Up\",\n 39: \"Right\",\n 40: \"Down\",\n 44: \"PrintScrn\",\n 45: \"Insert\",\n 46: \"Delete\",\n 59: \";\",\n 61: \"=\",\n 91: \"Mod\",\n 92: \"Mod\",\n 93: \"Mod\",\n 106: \"*\",\n 107: \"=\",\n 109: \"-\",\n 110: \".\",\n 111: \"/\",\n 145: \"ScrollLock\",\n 173: \"-\",\n 186: \";\",\n 187: \"=\",\n 188: \",\",\n 189: \"-\",\n 190: \".\",\n 191: \"/\",\n 192: \"`\",\n 219: \"[\",\n 220: \"\\\\\",\n 221: \"]\",\n 222: \"'\",\n 224: \"Mod\",\n 63232: \"Up\",\n 63233: \"Down\",\n 63234: \"Left\",\n 63235: \"Right\",\n 63272: \"Delete\",\n 63273: \"Home\",\n 63275: \"End\",\n 63276: \"PageUp\",\n 63277: \"PageDown\",\n 63302: \"Insert\"\n }; // Number keys\n\n for (var i = 0; i < 10; i++) {\n keyNames[i + 48] = keyNames[i + 96] = String(i);\n } // Alphabetic keys\n\n\n for (var i$1 = 65; i$1 <= 90; i$1++) {\n keyNames[i$1] = String.fromCharCode(i$1);\n } // Function keys\n\n\n for (var i$2 = 1; i$2 <= 12; i$2++) {\n keyNames[i$2 + 111] = keyNames[i$2 + 63235] = \"F\" + i$2;\n }\n\n var keyMap = {};\n keyMap.basic = {\n \"Left\": \"goCharLeft\",\n \"Right\": \"goCharRight\",\n \"Up\": \"goLineUp\",\n \"Down\": \"goLineDown\",\n \"End\": \"goLineEnd\",\n \"Home\": \"goLineStartSmart\",\n \"PageUp\": \"goPageUp\",\n \"PageDown\": \"goPageDown\",\n \"Delete\": \"delCharAfter\",\n \"Backspace\": \"delCharBefore\",\n \"Shift-Backspace\": \"delCharBefore\",\n \"Tab\": \"defaultTab\",\n \"Shift-Tab\": \"indentAuto\",\n \"Enter\": \"newlineAndIndent\",\n \"Insert\": \"toggleOverwrite\",\n \"Esc\": \"singleSelection\"\n }; // Note that the save and find-related commands aren't defined by\n // default. User code or addons can define them. Unknown commands\n // are simply ignored.\n\n keyMap.pcDefault = {\n \"Ctrl-A\": \"selectAll\",\n \"Ctrl-D\": \"deleteLine\",\n \"Ctrl-Z\": \"undo\",\n \"Shift-Ctrl-Z\": \"redo\",\n \"Ctrl-Y\": \"redo\",\n \"Ctrl-Home\": \"goDocStart\",\n \"Ctrl-End\": \"goDocEnd\",\n \"Ctrl-Up\": \"goLineUp\",\n \"Ctrl-Down\": \"goLineDown\",\n \"Ctrl-Left\": \"goGroupLeft\",\n \"Ctrl-Right\": \"goGroupRight\",\n \"Alt-Left\": \"goLineStart\",\n \"Alt-Right\": \"goLineEnd\",\n \"Ctrl-Backspace\": \"delGroupBefore\",\n \"Ctrl-Delete\": \"delGroupAfter\",\n \"Ctrl-S\": \"save\",\n \"Ctrl-F\": \"find\",\n \"Ctrl-G\": \"findNext\",\n \"Shift-Ctrl-G\": \"findPrev\",\n \"Shift-Ctrl-F\": \"replace\",\n \"Shift-Ctrl-R\": \"replaceAll\",\n \"Ctrl-[\": \"indentLess\",\n \"Ctrl-]\": \"indentMore\",\n \"Ctrl-U\": \"undoSelection\",\n \"Shift-Ctrl-U\": \"redoSelection\",\n \"Alt-U\": \"redoSelection\",\n \"fallthrough\": \"basic\"\n }; // Very basic readline/emacs-style bindings, which are standard on Mac.\n\n keyMap.emacsy = {\n \"Ctrl-F\": \"goCharRight\",\n \"Ctrl-B\": \"goCharLeft\",\n \"Ctrl-P\": \"goLineUp\",\n \"Ctrl-N\": \"goLineDown\",\n \"Alt-F\": \"goWordRight\",\n \"Alt-B\": \"goWordLeft\",\n \"Ctrl-A\": \"goLineStart\",\n \"Ctrl-E\": \"goLineEnd\",\n \"Ctrl-V\": \"goPageDown\",\n \"Shift-Ctrl-V\": \"goPageUp\",\n \"Ctrl-D\": \"delCharAfter\",\n \"Ctrl-H\": \"delCharBefore\",\n \"Alt-D\": \"delWordAfter\",\n \"Alt-Backspace\": \"delWordBefore\",\n \"Ctrl-K\": \"killLine\",\n \"Ctrl-T\": \"transposeChars\",\n \"Ctrl-O\": \"openLine\"\n };\n keyMap.macDefault = {\n \"Cmd-A\": \"selectAll\",\n \"Cmd-D\": \"deleteLine\",\n \"Cmd-Z\": \"undo\",\n \"Shift-Cmd-Z\": \"redo\",\n \"Cmd-Y\": \"redo\",\n \"Cmd-Home\": \"goDocStart\",\n \"Cmd-Up\": \"goDocStart\",\n \"Cmd-End\": \"goDocEnd\",\n \"Cmd-Down\": \"goDocEnd\",\n \"Alt-Left\": \"goGroupLeft\",\n \"Alt-Right\": \"goGroupRight\",\n \"Cmd-Left\": \"goLineLeft\",\n \"Cmd-Right\": \"goLineRight\",\n \"Alt-Backspace\": \"delGroupBefore\",\n \"Ctrl-Alt-Backspace\": \"delGroupAfter\",\n \"Alt-Delete\": \"delGroupAfter\",\n \"Cmd-S\": \"save\",\n \"Cmd-F\": \"find\",\n \"Cmd-G\": \"findNext\",\n \"Shift-Cmd-G\": \"findPrev\",\n \"Cmd-Alt-F\": \"replace\",\n \"Shift-Cmd-Alt-F\": \"replaceAll\",\n \"Cmd-[\": \"indentLess\",\n \"Cmd-]\": \"indentMore\",\n \"Cmd-Backspace\": \"delWrappedLineLeft\",\n \"Cmd-Delete\": \"delWrappedLineRight\",\n \"Cmd-U\": \"undoSelection\",\n \"Shift-Cmd-U\": \"redoSelection\",\n \"Ctrl-Up\": \"goDocStart\",\n \"Ctrl-Down\": \"goDocEnd\",\n \"fallthrough\": [\"basic\", \"emacsy\"]\n };\n keyMap[\"default\"] = mac ? keyMap.macDefault : keyMap.pcDefault; // KEYMAP DISPATCH\n\n function normalizeKeyName(name) {\n var parts = name.split(/-(?!$)/);\n name = parts[parts.length - 1];\n var alt, ctrl, shift, cmd;\n\n for (var i = 0; i < parts.length - 1; i++) {\n var mod = parts[i];\n\n if (/^(cmd|meta|m)$/i.test(mod)) {\n cmd = true;\n } else if (/^a(lt)?$/i.test(mod)) {\n alt = true;\n } else if (/^(c|ctrl|control)$/i.test(mod)) {\n ctrl = true;\n } else if (/^s(hift)?$/i.test(mod)) {\n shift = true;\n } else {\n throw new Error(\"Unrecognized modifier name: \" + mod);\n }\n }\n\n if (alt) {\n name = \"Alt-\" + name;\n }\n\n if (ctrl) {\n name = \"Ctrl-\" + name;\n }\n\n if (cmd) {\n name = \"Cmd-\" + name;\n }\n\n if (shift) {\n name = \"Shift-\" + name;\n }\n\n return name;\n } // This is a kludge to keep keymaps mostly working as raw objects\n // (backwards compatibility) while at the same time support features\n // like normalization and multi-stroke key bindings. It compiles a\n // new normalized keymap, and then updates the old object to reflect\n // this.\n\n\n function normalizeKeyMap(keymap) {\n var copy = {};\n\n for (var keyname in keymap) {\n if (keymap.hasOwnProperty(keyname)) {\n var value = keymap[keyname];\n\n if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) {\n continue;\n }\n\n if (value == \"...\") {\n delete keymap[keyname];\n continue;\n }\n\n var keys = map(keyname.split(\" \"), normalizeKeyName);\n\n for (var i = 0; i < keys.length; i++) {\n var val = void 0,\n name = void 0;\n\n if (i == keys.length - 1) {\n name = keys.join(\" \");\n val = value;\n } else {\n name = keys.slice(0, i + 1).join(\" \");\n val = \"...\";\n }\n\n var prev = copy[name];\n\n if (!prev) {\n copy[name] = val;\n } else if (prev != val) {\n throw new Error(\"Inconsistent bindings for \" + name);\n }\n }\n\n delete keymap[keyname];\n }\n }\n\n for (var prop in copy) {\n keymap[prop] = copy[prop];\n }\n\n return keymap;\n }\n\n function lookupKey(key, map, handle, context) {\n map = getKeyMap(map);\n var found = map.call ? map.call(key, context) : map[key];\n\n if (found === false) {\n return \"nothing\";\n }\n\n if (found === \"...\") {\n return \"multi\";\n }\n\n if (found != null && handle(found)) {\n return \"handled\";\n }\n\n if (map.fallthrough) {\n if (Object.prototype.toString.call(map.fallthrough) != \"[object Array]\") {\n return lookupKey(key, map.fallthrough, handle, context);\n }\n\n for (var i = 0; i < map.fallthrough.length; i++) {\n var result = lookupKey(key, map.fallthrough[i], handle, context);\n\n if (result) {\n return result;\n }\n }\n }\n } // Modifier key presses don't count as 'real' key presses for the\n // purpose of keymap fallthrough.\n\n\n function isModifierKey(value) {\n var name = typeof value == \"string\" ? value : keyNames[value.keyCode];\n return name == \"Ctrl\" || name == \"Alt\" || name == \"Shift\" || name == \"Mod\";\n }\n\n function addModifierNames(name, event, noShift) {\n var base = name;\n\n if (event.altKey && base != \"Alt\") {\n name = \"Alt-\" + name;\n }\n\n if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != \"Ctrl\") {\n name = \"Ctrl-\" + name;\n }\n\n if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != \"Mod\") {\n name = \"Cmd-\" + name;\n }\n\n if (!noShift && event.shiftKey && base != \"Shift\") {\n name = \"Shift-\" + name;\n }\n\n return name;\n } // Look up the name of a key as indicated by an event object.\n\n\n function keyName(event, noShift) {\n if (presto && event.keyCode == 34 && event[\"char\"]) {\n return false;\n }\n\n var name = keyNames[event.keyCode];\n\n if (name == null || event.altGraphKey) {\n return false;\n } // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,\n // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)\n\n\n if (event.keyCode == 3 && event.code) {\n name = event.code;\n }\n\n return addModifierNames(name, event, noShift);\n }\n\n function getKeyMap(val) {\n return typeof val == \"string\" ? keyMap[val] : val;\n } // Helper for deleting text near the selection(s), used to implement\n // backspace, delete, and similar functionality.\n\n\n function deleteNearSelection(cm, compute) {\n var ranges = cm.doc.sel.ranges,\n kill = []; // Build up a set of ranges to kill first, merging overlapping\n // ranges.\n\n for (var i = 0; i < ranges.length; i++) {\n var toKill = compute(ranges[i]);\n\n while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {\n var replaced = kill.pop();\n\n if (cmp(replaced.from, toKill.from) < 0) {\n toKill.from = replaced.from;\n break;\n }\n }\n\n kill.push(toKill);\n } // Next, remove those actual ranges.\n\n\n runInOp(cm, function () {\n for (var i = kill.length - 1; i >= 0; i--) {\n _replaceRange(cm.doc, \"\", kill[i].from, kill[i].to, \"+delete\");\n }\n\n ensureCursorVisible(cm);\n });\n }\n\n function moveCharLogically(line, ch, dir) {\n var target = skipExtendingChars(line.text, ch + dir, dir);\n return target < 0 || target > line.text.length ? null : target;\n }\n\n function moveLogically(line, start, dir) {\n var ch = moveCharLogically(line, start.ch, dir);\n return ch == null ? null : new Pos(start.line, ch, dir < 0 ? \"after\" : \"before\");\n }\n\n function endOfLine(visually, cm, lineObj, lineNo, dir) {\n if (visually) {\n if (cm.doc.direction == \"rtl\") {\n dir = -dir;\n }\n\n var order = getOrder(lineObj, cm.doc.direction);\n\n if (order) {\n var part = dir < 0 ? lst(order) : order[0];\n var moveInStorageOrder = dir < 0 == (part.level == 1);\n var sticky = moveInStorageOrder ? \"after\" : \"before\";\n var ch; // With a wrapped rtl chunk (possibly spanning multiple bidi parts),\n // it could be that the last bidi part is not on the last visual line,\n // since visual lines contain content order-consecutive chunks.\n // Thus, in rtl, we are looking for the first (content-order) character\n // in the rtl chunk that is on the last line (that is, the same line\n // as the last (content-order) character).\n\n if (part.level > 0 || cm.doc.direction == \"rtl\") {\n var prep = prepareMeasureForLine(cm, lineObj);\n ch = dir < 0 ? lineObj.text.length - 1 : 0;\n var targetTop = measureCharPrepared(cm, prep, ch).top;\n ch = findFirst(function (ch) {\n return measureCharPrepared(cm, prep, ch).top == targetTop;\n }, dir < 0 == (part.level == 1) ? part.from : part.to - 1, ch);\n\n if (sticky == \"before\") {\n ch = moveCharLogically(lineObj, ch, 1);\n }\n } else {\n ch = dir < 0 ? part.to : part.from;\n }\n\n return new Pos(lineNo, ch, sticky);\n }\n }\n\n return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? \"before\" : \"after\");\n }\n\n function moveVisually(cm, line, start, dir) {\n var bidi = getOrder(line, cm.doc.direction);\n\n if (!bidi) {\n return moveLogically(line, start, dir);\n }\n\n if (start.ch >= line.text.length) {\n start.ch = line.text.length;\n start.sticky = \"before\";\n } else if (start.ch <= 0) {\n start.ch = 0;\n start.sticky = \"after\";\n }\n\n var partPos = getBidiPartAt(bidi, start.ch, start.sticky),\n part = bidi[partPos];\n\n if (cm.doc.direction == \"ltr\" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {\n // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,\n // nothing interesting happens.\n return moveLogically(line, start, dir);\n }\n\n var mv = function mv(pos, dir) {\n return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir);\n };\n\n var prep;\n\n var getWrappedLineExtent = function getWrappedLineExtent(ch) {\n if (!cm.options.lineWrapping) {\n return {\n begin: 0,\n end: line.text.length\n };\n }\n\n prep = prep || prepareMeasureForLine(cm, line);\n return wrappedLineExtentChar(cm, line, prep, ch);\n };\n\n var wrappedLineExtent = getWrappedLineExtent(start.sticky == \"before\" ? mv(start, -1) : start.ch);\n\n if (cm.doc.direction == \"rtl\" || part.level == 1) {\n var moveInStorageOrder = part.level == 1 == dir < 0;\n var ch = mv(start, moveInStorageOrder ? 1 : -1);\n\n if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {\n // Case 2: We move within an rtl part or in an rtl editor on the same visual line\n var sticky = moveInStorageOrder ? \"before\" : \"after\";\n return new Pos(start.line, ch, sticky);\n }\n } // Case 3: Could not move within this bidi part in this visual line, so leave\n // the current bidi part\n\n\n var searchInVisualLine = function searchInVisualLine(partPos, dir, wrappedLineExtent) {\n var getRes = function getRes(ch, moveInStorageOrder) {\n return moveInStorageOrder ? new Pos(start.line, mv(ch, 1), \"before\") : new Pos(start.line, ch, \"after\");\n };\n\n for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {\n var part = bidi[partPos];\n var moveInStorageOrder = dir > 0 == (part.level != 1);\n var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);\n\n if (part.from <= ch && ch < part.to) {\n return getRes(ch, moveInStorageOrder);\n }\n\n ch = moveInStorageOrder ? part.from : mv(part.to, -1);\n\n if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) {\n return getRes(ch, moveInStorageOrder);\n }\n }\n }; // Case 3a: Look for other bidi parts on the same visual line\n\n\n var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);\n\n if (res) {\n return res;\n } // Case 3b: Look for other bidi parts on the next visual line\n\n\n var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);\n\n if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {\n res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));\n\n if (res) {\n return res;\n }\n } // Case 4: Nowhere to move\n\n\n return null;\n } // Commands are parameter-less actions that can be performed on an\n // editor, mostly used for keybindings.\n\n\n var commands = {\n selectAll: selectAll,\n singleSelection: function singleSelection(cm) {\n return cm.setSelection(cm.getCursor(\"anchor\"), cm.getCursor(\"head\"), sel_dontScroll);\n },\n killLine: function killLine(cm) {\n return deleteNearSelection(cm, function (range) {\n if (range.empty()) {\n var len = getLine(cm.doc, range.head.line).text.length;\n\n if (range.head.ch == len && range.head.line < cm.lastLine()) {\n return {\n from: range.head,\n to: Pos(range.head.line + 1, 0)\n };\n } else {\n return {\n from: range.head,\n to: Pos(range.head.line, len)\n };\n }\n } else {\n return {\n from: range.from(),\n to: range.to()\n };\n }\n });\n },\n deleteLine: function deleteLine(cm) {\n return deleteNearSelection(cm, function (range) {\n return {\n from: Pos(range.from().line, 0),\n to: _clipPos(cm.doc, Pos(range.to().line + 1, 0))\n };\n });\n },\n delLineLeft: function delLineLeft(cm) {\n return deleteNearSelection(cm, function (range) {\n return {\n from: Pos(range.from().line, 0),\n to: range.from()\n };\n });\n },\n delWrappedLineLeft: function delWrappedLineLeft(cm) {\n return deleteNearSelection(cm, function (range) {\n var top = cm.charCoords(range.head, \"div\").top + 5;\n var leftPos = cm.coordsChar({\n left: 0,\n top: top\n }, \"div\");\n return {\n from: leftPos,\n to: range.from()\n };\n });\n },\n delWrappedLineRight: function delWrappedLineRight(cm) {\n return deleteNearSelection(cm, function (range) {\n var top = cm.charCoords(range.head, \"div\").top + 5;\n var rightPos = cm.coordsChar({\n left: cm.display.lineDiv.offsetWidth + 100,\n top: top\n }, \"div\");\n return {\n from: range.from(),\n to: rightPos\n };\n });\n },\n undo: function undo(cm) {\n return cm.undo();\n },\n redo: function redo(cm) {\n return cm.redo();\n },\n undoSelection: function undoSelection(cm) {\n return cm.undoSelection();\n },\n redoSelection: function redoSelection(cm) {\n return cm.redoSelection();\n },\n goDocStart: function goDocStart(cm) {\n return cm.extendSelection(Pos(cm.firstLine(), 0));\n },\n goDocEnd: function goDocEnd(cm) {\n return cm.extendSelection(Pos(cm.lastLine()));\n },\n goLineStart: function goLineStart(cm) {\n return cm.extendSelectionsBy(function (range) {\n return lineStart(cm, range.head.line);\n }, {\n origin: \"+move\",\n bias: 1\n });\n },\n goLineStartSmart: function goLineStartSmart(cm) {\n return cm.extendSelectionsBy(function (range) {\n return lineStartSmart(cm, range.head);\n }, {\n origin: \"+move\",\n bias: 1\n });\n },\n goLineEnd: function goLineEnd(cm) {\n return cm.extendSelectionsBy(function (range) {\n return lineEnd(cm, range.head.line);\n }, {\n origin: \"+move\",\n bias: -1\n });\n },\n goLineRight: function goLineRight(cm) {\n return cm.extendSelectionsBy(function (range) {\n var top = cm.cursorCoords(range.head, \"div\").top + 5;\n return cm.coordsChar({\n left: cm.display.lineDiv.offsetWidth + 100,\n top: top\n }, \"div\");\n }, sel_move);\n },\n goLineLeft: function goLineLeft(cm) {\n return cm.extendSelectionsBy(function (range) {\n var top = cm.cursorCoords(range.head, \"div\").top + 5;\n return cm.coordsChar({\n left: 0,\n top: top\n }, \"div\");\n }, sel_move);\n },\n goLineLeftSmart: function goLineLeftSmart(cm) {\n return cm.extendSelectionsBy(function (range) {\n var top = cm.cursorCoords(range.head, \"div\").top + 5;\n var pos = cm.coordsChar({\n left: 0,\n top: top\n }, \"div\");\n\n if (pos.ch < cm.getLine(pos.line).search(/\\S/)) {\n return lineStartSmart(cm, range.head);\n }\n\n return pos;\n }, sel_move);\n },\n goLineUp: function goLineUp(cm) {\n return cm.moveV(-1, \"line\");\n },\n goLineDown: function goLineDown(cm) {\n return cm.moveV(1, \"line\");\n },\n goPageUp: function goPageUp(cm) {\n return cm.moveV(-1, \"page\");\n },\n goPageDown: function goPageDown(cm) {\n return cm.moveV(1, \"page\");\n },\n goCharLeft: function goCharLeft(cm) {\n return cm.moveH(-1, \"char\");\n },\n goCharRight: function goCharRight(cm) {\n return cm.moveH(1, \"char\");\n },\n goColumnLeft: function goColumnLeft(cm) {\n return cm.moveH(-1, \"column\");\n },\n goColumnRight: function goColumnRight(cm) {\n return cm.moveH(1, \"column\");\n },\n goWordLeft: function goWordLeft(cm) {\n return cm.moveH(-1, \"word\");\n },\n goGroupRight: function goGroupRight(cm) {\n return cm.moveH(1, \"group\");\n },\n goGroupLeft: function goGroupLeft(cm) {\n return cm.moveH(-1, \"group\");\n },\n goWordRight: function goWordRight(cm) {\n return cm.moveH(1, \"word\");\n },\n delCharBefore: function delCharBefore(cm) {\n return cm.deleteH(-1, \"codepoint\");\n },\n delCharAfter: function delCharAfter(cm) {\n return cm.deleteH(1, \"char\");\n },\n delWordBefore: function delWordBefore(cm) {\n return cm.deleteH(-1, \"word\");\n },\n delWordAfter: function delWordAfter(cm) {\n return cm.deleteH(1, \"word\");\n },\n delGroupBefore: function delGroupBefore(cm) {\n return cm.deleteH(-1, \"group\");\n },\n delGroupAfter: function delGroupAfter(cm) {\n return cm.deleteH(1, \"group\");\n },\n indentAuto: function indentAuto(cm) {\n return cm.indentSelection(\"smart\");\n },\n indentMore: function indentMore(cm) {\n return cm.indentSelection(\"add\");\n },\n indentLess: function indentLess(cm) {\n return cm.indentSelection(\"subtract\");\n },\n insertTab: function insertTab(cm) {\n return cm.replaceSelection(\"\\t\");\n },\n insertSoftTab: function insertSoftTab(cm) {\n var spaces = [],\n ranges = cm.listSelections(),\n tabSize = cm.options.tabSize;\n\n for (var i = 0; i < ranges.length; i++) {\n var pos = ranges[i].from();\n var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);\n spaces.push(spaceStr(tabSize - col % tabSize));\n }\n\n cm.replaceSelections(spaces);\n },\n defaultTab: function defaultTab(cm) {\n if (cm.somethingSelected()) {\n cm.indentSelection(\"add\");\n } else {\n cm.execCommand(\"insertTab\");\n }\n },\n // Swap the two chars left and right of each selection's head.\n // Move cursor behind the two swapped characters afterwards.\n //\n // Doesn't consider line feeds a character.\n // Doesn't scan more than one line above to find a character.\n // Doesn't do anything on an empty line.\n // Doesn't do anything with non-empty selections.\n transposeChars: function transposeChars(cm) {\n return runInOp(cm, function () {\n var ranges = cm.listSelections(),\n newSel = [];\n\n for (var i = 0; i < ranges.length; i++) {\n if (!ranges[i].empty()) {\n continue;\n }\n\n var cur = ranges[i].head,\n line = getLine(cm.doc, cur.line).text;\n\n if (line) {\n if (cur.ch == line.length) {\n cur = new Pos(cur.line, cur.ch - 1);\n }\n\n if (cur.ch > 0) {\n cur = new Pos(cur.line, cur.ch + 1);\n cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2), Pos(cur.line, cur.ch - 2), cur, \"+transpose\");\n } else if (cur.line > cm.doc.first) {\n var prev = getLine(cm.doc, cur.line - 1).text;\n\n if (prev) {\n cur = new Pos(cur.line, 1);\n cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() + prev.charAt(prev.length - 1), Pos(cur.line - 1, prev.length - 1), cur, \"+transpose\");\n }\n }\n }\n\n newSel.push(new Range(cur, cur));\n }\n\n cm.setSelections(newSel);\n });\n },\n newlineAndIndent: function newlineAndIndent(cm) {\n return runInOp(cm, function () {\n var sels = cm.listSelections();\n\n for (var i = sels.length - 1; i >= 0; i--) {\n cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, \"+input\");\n }\n\n sels = cm.listSelections();\n\n for (var i$1 = 0; i$1 < sels.length; i$1++) {\n cm.indentLine(sels[i$1].from().line, null, true);\n }\n\n ensureCursorVisible(cm);\n });\n },\n openLine: function openLine(cm) {\n return cm.replaceSelection(\"\\n\", \"start\");\n },\n toggleOverwrite: function toggleOverwrite(cm) {\n return cm.toggleOverwrite();\n }\n };\n\n function lineStart(cm, lineN) {\n var line = getLine(cm.doc, lineN);\n var visual = visualLine(line);\n\n if (visual != line) {\n lineN = lineNo(visual);\n }\n\n return endOfLine(true, cm, visual, lineN, 1);\n }\n\n function lineEnd(cm, lineN) {\n var line = getLine(cm.doc, lineN);\n var visual = visualLineEnd(line);\n\n if (visual != line) {\n lineN = lineNo(visual);\n }\n\n return endOfLine(true, cm, line, lineN, -1);\n }\n\n function lineStartSmart(cm, pos) {\n var start = lineStart(cm, pos.line);\n var line = getLine(cm.doc, start.line);\n var order = getOrder(line, cm.doc.direction);\n\n if (!order || order[0].level == 0) {\n var firstNonWS = Math.max(start.ch, line.text.search(/\\S/));\n var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;\n return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky);\n }\n\n return start;\n } // Run a handler that was bound to a key.\n\n\n function doHandleBinding(cm, bound, dropShift) {\n if (typeof bound == \"string\") {\n bound = commands[bound];\n\n if (!bound) {\n return false;\n }\n } // Ensure previous input has been read, so that the handler sees a\n // consistent view of the document\n\n\n cm.display.input.ensurePolled();\n var prevShift = cm.display.shift,\n done = false;\n\n try {\n if (cm.isReadOnly()) {\n cm.state.suppressEdits = true;\n }\n\n if (dropShift) {\n cm.display.shift = false;\n }\n\n done = bound(cm) != Pass;\n } finally {\n cm.display.shift = prevShift;\n cm.state.suppressEdits = false;\n }\n\n return done;\n }\n\n function lookupKeyForEditor(cm, name, handle) {\n for (var i = 0; i < cm.state.keyMaps.length; i++) {\n var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);\n\n if (result) {\n return result;\n }\n }\n\n return cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm) || lookupKey(name, cm.options.keyMap, handle, cm);\n } // Note that, despite the name, this function is also used to check\n // for bound mouse clicks.\n\n\n var stopSeq = new Delayed();\n\n function dispatchKey(cm, name, e, handle) {\n var seq = cm.state.keySeq;\n\n if (seq) {\n if (isModifierKey(name)) {\n return \"handled\";\n }\n\n if (/\\'$/.test(name)) {\n cm.state.keySeq = null;\n } else {\n stopSeq.set(50, function () {\n if (cm.state.keySeq == seq) {\n cm.state.keySeq = null;\n cm.display.input.reset();\n }\n });\n }\n\n if (dispatchKeyInner(cm, seq + \" \" + name, e, handle)) {\n return true;\n }\n }\n\n return dispatchKeyInner(cm, name, e, handle);\n }\n\n function dispatchKeyInner(cm, name, e, handle) {\n var result = lookupKeyForEditor(cm, name, handle);\n\n if (result == \"multi\") {\n cm.state.keySeq = name;\n }\n\n if (result == \"handled\") {\n signalLater(cm, \"keyHandled\", cm, name, e);\n }\n\n if (result == \"handled\" || result == \"multi\") {\n e_preventDefault(e);\n restartBlink(cm);\n }\n\n return !!result;\n } // Handle a key from the keydown event.\n\n\n function handleKeyBinding(cm, e) {\n var name = keyName(e, true);\n\n if (!name) {\n return false;\n }\n\n if (e.shiftKey && !cm.state.keySeq) {\n // First try to resolve full name (including 'Shift-'). Failing\n // that, see if there is a cursor-motion command (starting with\n // 'go') bound to the keyname without 'Shift-'.\n return dispatchKey(cm, \"Shift-\" + name, e, function (b) {\n return doHandleBinding(cm, b, true);\n }) || dispatchKey(cm, name, e, function (b) {\n if (typeof b == \"string\" ? /^go[A-Z]/.test(b) : b.motion) {\n return doHandleBinding(cm, b);\n }\n });\n } else {\n return dispatchKey(cm, name, e, function (b) {\n return doHandleBinding(cm, b);\n });\n }\n } // Handle a key from the keypress event\n\n\n function handleCharBinding(cm, e, ch) {\n return dispatchKey(cm, \"'\" + ch + \"'\", e, function (b) {\n return doHandleBinding(cm, b, true);\n });\n }\n\n var lastStoppedKey = null;\n\n function onKeyDown(e) {\n var cm = this;\n\n if (e.target && e.target != cm.display.input.getField()) {\n return;\n }\n\n cm.curOp.focus = activeElt();\n\n if (signalDOMEvent(cm, e)) {\n return;\n } // IE does strange things with escape.\n\n\n if (ie && ie_version < 11 && e.keyCode == 27) {\n e.returnValue = false;\n }\n\n var code = e.keyCode;\n cm.display.shift = code == 16 || e.shiftKey;\n var handled = handleKeyBinding(cm, e);\n\n if (presto) {\n lastStoppedKey = handled ? code : null; // Opera has no cut event... we try to at least catch the key combo\n\n if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey)) {\n cm.replaceSelection(\"\", null, \"cut\");\n }\n }\n\n if (gecko && !mac && !handled && code == 46 && e.shiftKey && !e.ctrlKey && document.execCommand) {\n document.execCommand(\"cut\");\n } // Turn mouse into crosshair when Alt is held on Mac.\n\n\n if (code == 18 && !/\\bCodeMirror-crosshair\\b/.test(cm.display.lineDiv.className)) {\n showCrossHair(cm);\n }\n }\n\n function showCrossHair(cm) {\n var lineDiv = cm.display.lineDiv;\n addClass(lineDiv, \"CodeMirror-crosshair\");\n\n function up(e) {\n if (e.keyCode == 18 || !e.altKey) {\n rmClass(lineDiv, \"CodeMirror-crosshair\");\n off(document, \"keyup\", up);\n off(document, \"mouseover\", up);\n }\n }\n\n on(document, \"keyup\", up);\n on(document, \"mouseover\", up);\n }\n\n function onKeyUp(e) {\n if (e.keyCode == 16) {\n this.doc.sel.shift = false;\n }\n\n signalDOMEvent(this, e);\n }\n\n function onKeyPress(e) {\n var cm = this;\n\n if (e.target && e.target != cm.display.input.getField()) {\n return;\n }\n\n if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) {\n return;\n }\n\n var keyCode = e.keyCode,\n charCode = e.charCode;\n\n if (presto && keyCode == lastStoppedKey) {\n lastStoppedKey = null;\n e_preventDefault(e);\n return;\n }\n\n if (presto && (!e.which || e.which < 10) && handleKeyBinding(cm, e)) {\n return;\n }\n\n var ch = String.fromCharCode(charCode == null ? keyCode : charCode); // Some browsers fire keypress events for backspace\n\n if (ch == \"\\x08\") {\n return;\n }\n\n if (handleCharBinding(cm, e, ch)) {\n return;\n }\n\n cm.display.input.onKeyPress(e);\n }\n\n var DOUBLECLICK_DELAY = 400;\n\n var PastClick = function PastClick(time, pos, button) {\n this.time = time;\n this.pos = pos;\n this.button = button;\n };\n\n PastClick.prototype.compare = function (time, pos, button) {\n return this.time + DOUBLECLICK_DELAY > time && cmp(pos, this.pos) == 0 && button == this.button;\n };\n\n var lastClick, lastDoubleClick;\n\n function clickRepeat(pos, button) {\n var now = +new Date();\n\n if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {\n lastClick = lastDoubleClick = null;\n return \"triple\";\n } else if (lastClick && lastClick.compare(now, pos, button)) {\n lastDoubleClick = new PastClick(now, pos, button);\n lastClick = null;\n return \"double\";\n } else {\n lastClick = new PastClick(now, pos, button);\n lastDoubleClick = null;\n return \"single\";\n }\n } // A mouse down can be a single click, double click, triple click,\n // start of selection drag, start of text drag, new cursor\n // (ctrl-click), rectangle drag (alt-drag), or xwin\n // middle-click-paste. Or it might be a click on something we should\n // not interfere with, such as a scrollbar or widget.\n\n\n function onMouseDown(e) {\n var cm = this,\n display = cm.display;\n\n if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) {\n return;\n }\n\n display.input.ensurePolled();\n display.shift = e.shiftKey;\n\n if (eventInWidget(display, e)) {\n if (!webkit) {\n // Briefly turn off draggability, to allow widgets to do\n // normal dragging things.\n display.scroller.draggable = false;\n setTimeout(function () {\n return display.scroller.draggable = true;\n }, 100);\n }\n\n return;\n }\n\n if (clickInGutter(cm, e)) {\n return;\n }\n\n var pos = posFromMouse(cm, e),\n button = e_button(e),\n repeat = pos ? clickRepeat(pos, button) : \"single\";\n window.focus(); // #3261: make sure, that we're not starting a second selection\n\n if (button == 1 && cm.state.selectingText) {\n cm.state.selectingText(e);\n }\n\n if (pos && handleMappedButton(cm, button, pos, repeat, e)) {\n return;\n }\n\n if (button == 1) {\n if (pos) {\n leftButtonDown(cm, pos, repeat, e);\n } else if (e_target(e) == display.scroller) {\n e_preventDefault(e);\n }\n } else if (button == 2) {\n if (pos) {\n extendSelection(cm.doc, pos);\n }\n\n setTimeout(function () {\n return display.input.focus();\n }, 20);\n } else if (button == 3) {\n if (captureRightClick) {\n cm.display.input.onContextMenu(e);\n } else {\n delayBlurEvent(cm);\n }\n }\n }\n\n function handleMappedButton(cm, button, pos, repeat, event) {\n var name = \"Click\";\n\n if (repeat == \"double\") {\n name = \"Double\" + name;\n } else if (repeat == \"triple\") {\n name = \"Triple\" + name;\n }\n\n name = (button == 1 ? \"Left\" : button == 2 ? \"Middle\" : \"Right\") + name;\n return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {\n if (typeof bound == \"string\") {\n bound = commands[bound];\n }\n\n if (!bound) {\n return false;\n }\n\n var done = false;\n\n try {\n if (cm.isReadOnly()) {\n cm.state.suppressEdits = true;\n }\n\n done = bound(cm, pos) != Pass;\n } finally {\n cm.state.suppressEdits = false;\n }\n\n return done;\n });\n }\n\n function configureMouse(cm, repeat, event) {\n var option = cm.getOption(\"configureMouse\");\n var value = option ? option(cm, repeat, event) : {};\n\n if (value.unit == null) {\n var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;\n value.unit = rect ? \"rectangle\" : repeat == \"single\" ? \"char\" : repeat == \"double\" ? \"word\" : \"line\";\n }\n\n if (value.extend == null || cm.doc.extend) {\n value.extend = cm.doc.extend || event.shiftKey;\n }\n\n if (value.addNew == null) {\n value.addNew = mac ? event.metaKey : event.ctrlKey;\n }\n\n if (value.moveOnDrag == null) {\n value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey);\n }\n\n return value;\n }\n\n function leftButtonDown(cm, pos, repeat, event) {\n if (ie) {\n setTimeout(bind(ensureFocus, cm), 0);\n } else {\n cm.curOp.focus = activeElt();\n }\n\n var behavior = configureMouse(cm, repeat, event);\n var sel = cm.doc.sel,\n contained;\n\n if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() && repeat == \"single\" && (contained = sel.contains(pos)) > -1 && (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) && (cmp(contained.to(), pos) > 0 || pos.xRel < 0)) {\n leftButtonStartDrag(cm, event, pos, behavior);\n } else {\n leftButtonSelect(cm, event, pos, behavior);\n }\n } // Start a text drag. When it ends, see if any dragging actually\n // happen, and treat as a click if it didn't.\n\n\n function leftButtonStartDrag(cm, event, pos, behavior) {\n var display = cm.display,\n moved = false;\n var dragEnd = operation(cm, function (e) {\n if (webkit) {\n display.scroller.draggable = false;\n }\n\n cm.state.draggingText = false;\n off(display.wrapper.ownerDocument, \"mouseup\", dragEnd);\n off(display.wrapper.ownerDocument, \"mousemove\", mouseMove);\n off(display.scroller, \"dragstart\", dragStart);\n off(display.scroller, \"drop\", dragEnd);\n\n if (!moved) {\n e_preventDefault(e);\n\n if (!behavior.addNew) {\n extendSelection(cm.doc, pos, null, null, behavior.extend);\n } // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)\n\n\n if (webkit && !safari || ie && ie_version == 9) {\n setTimeout(function () {\n display.wrapper.ownerDocument.body.focus({\n preventScroll: true\n });\n display.input.focus();\n }, 20);\n } else {\n display.input.focus();\n }\n }\n });\n\n var mouseMove = function mouseMove(e2) {\n moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;\n };\n\n var dragStart = function dragStart() {\n return moved = true;\n }; // Let the drag handler handle this.\n\n\n if (webkit) {\n display.scroller.draggable = true;\n }\n\n cm.state.draggingText = dragEnd;\n dragEnd.copy = !behavior.moveOnDrag; // IE's approach to draggable\n\n if (display.scroller.dragDrop) {\n display.scroller.dragDrop();\n }\n\n on(display.wrapper.ownerDocument, \"mouseup\", dragEnd);\n on(display.wrapper.ownerDocument, \"mousemove\", mouseMove);\n on(display.scroller, \"dragstart\", dragStart);\n on(display.scroller, \"drop\", dragEnd);\n delayBlurEvent(cm);\n setTimeout(function () {\n return display.input.focus();\n }, 20);\n }\n\n function rangeForUnit(cm, pos, unit) {\n if (unit == \"char\") {\n return new Range(pos, pos);\n }\n\n if (unit == \"word\") {\n return cm.findWordAt(pos);\n }\n\n if (unit == \"line\") {\n return new Range(Pos(pos.line, 0), _clipPos(cm.doc, Pos(pos.line + 1, 0)));\n }\n\n var result = unit(cm, pos);\n return new Range(result.from, result.to);\n } // Normal selection, as opposed to text dragging.\n\n\n function leftButtonSelect(cm, event, start, behavior) {\n var display = cm.display,\n doc = cm.doc;\n e_preventDefault(event);\n var ourRange,\n ourIndex,\n startSel = doc.sel,\n ranges = startSel.ranges;\n\n if (behavior.addNew && !behavior.extend) {\n ourIndex = doc.sel.contains(start);\n\n if (ourIndex > -1) {\n ourRange = ranges[ourIndex];\n } else {\n ourRange = new Range(start, start);\n }\n } else {\n ourRange = doc.sel.primary();\n ourIndex = doc.sel.primIndex;\n }\n\n if (behavior.unit == \"rectangle\") {\n if (!behavior.addNew) {\n ourRange = new Range(start, start);\n }\n\n start = posFromMouse(cm, event, true, true);\n ourIndex = -1;\n } else {\n var range = rangeForUnit(cm, start, behavior.unit);\n\n if (behavior.extend) {\n ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend);\n } else {\n ourRange = range;\n }\n }\n\n if (!behavior.addNew) {\n ourIndex = 0;\n setSelection(doc, new Selection([ourRange], 0), sel_mouse);\n startSel = doc.sel;\n } else if (ourIndex == -1) {\n ourIndex = ranges.length;\n setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex), {\n scroll: false,\n origin: \"*mouse\"\n });\n } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == \"char\" && !behavior.extend) {\n setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), {\n scroll: false,\n origin: \"*mouse\"\n });\n startSel = doc.sel;\n } else {\n replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);\n }\n\n var lastPos = start;\n\n function extendTo(pos) {\n if (cmp(lastPos, pos) == 0) {\n return;\n }\n\n lastPos = pos;\n\n if (behavior.unit == \"rectangle\") {\n var ranges = [],\n tabSize = cm.options.tabSize;\n var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);\n var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);\n var left = Math.min(startCol, posCol),\n right = Math.max(startCol, posCol);\n\n for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); line <= end; line++) {\n var text = getLine(doc, line).text,\n leftPos = findColumn(text, left, tabSize);\n\n if (left == right) {\n ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));\n } else if (text.length > leftPos) {\n ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));\n }\n }\n\n if (!ranges.length) {\n ranges.push(new Range(start, start));\n }\n\n setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), {\n origin: \"*mouse\",\n scroll: false\n });\n cm.scrollIntoView(pos);\n } else {\n var oldRange = ourRange;\n var range = rangeForUnit(cm, pos, behavior.unit);\n var anchor = oldRange.anchor,\n head;\n\n if (cmp(range.anchor, anchor) > 0) {\n head = range.head;\n anchor = minPos(oldRange.from(), range.anchor);\n } else {\n head = range.anchor;\n anchor = maxPos(oldRange.to(), range.head);\n }\n\n var ranges$1 = startSel.ranges.slice(0);\n ranges$1[ourIndex] = bidiSimplify(cm, new Range(_clipPos(doc, anchor), head));\n setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);\n }\n }\n\n var editorSize = display.wrapper.getBoundingClientRect(); // Used to ensure timeout re-tries don't fire when another extend\n // happened in the meantime (clearTimeout isn't reliable -- at\n // least on Chrome, the timeouts still happen even when cleared,\n // if the clear happens after their scheduled firing time).\n\n var counter = 0;\n\n function extend(e) {\n var curCount = ++counter;\n var cur = posFromMouse(cm, e, true, behavior.unit == \"rectangle\");\n\n if (!cur) {\n return;\n }\n\n if (cmp(cur, lastPos) != 0) {\n cm.curOp.focus = activeElt();\n extendTo(cur);\n var visible = visibleLines(display, doc);\n\n if (cur.line >= visible.to || cur.line < visible.from) {\n setTimeout(operation(cm, function () {\n if (counter == curCount) {\n extend(e);\n }\n }), 150);\n }\n } else {\n var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;\n\n if (outside) {\n setTimeout(operation(cm, function () {\n if (counter != curCount) {\n return;\n }\n\n display.scroller.scrollTop += outside;\n extend(e);\n }), 50);\n }\n }\n }\n\n function done(e) {\n cm.state.selectingText = false;\n counter = Infinity; // If e is null or undefined we interpret this as someone trying\n // to explicitly cancel the selection rather than the user\n // letting go of the mouse button.\n\n if (e) {\n e_preventDefault(e);\n display.input.focus();\n }\n\n off(display.wrapper.ownerDocument, \"mousemove\", move);\n off(display.wrapper.ownerDocument, \"mouseup\", up);\n doc.history.lastSelOrigin = null;\n }\n\n var move = operation(cm, function (e) {\n if (e.buttons === 0 || !e_button(e)) {\n done(e);\n } else {\n extend(e);\n }\n });\n var up = operation(cm, done);\n cm.state.selectingText = up;\n on(display.wrapper.ownerDocument, \"mousemove\", move);\n on(display.wrapper.ownerDocument, \"mouseup\", up);\n } // Used when mouse-selecting to adjust the anchor to the proper side\n // of a bidi jump depending on the visual position of the head.\n\n\n function bidiSimplify(cm, range) {\n var anchor = range.anchor;\n var head = range.head;\n var anchorLine = getLine(cm.doc, anchor.line);\n\n if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) {\n return range;\n }\n\n var order = getOrder(anchorLine);\n\n if (!order) {\n return range;\n }\n\n var index = getBidiPartAt(order, anchor.ch, anchor.sticky),\n part = order[index];\n\n if (part.from != anchor.ch && part.to != anchor.ch) {\n return range;\n }\n\n var boundary = index + (part.from == anchor.ch == (part.level != 1) ? 0 : 1);\n\n if (boundary == 0 || boundary == order.length) {\n return range;\n } // Compute the relative visual position of the head compared to the\n // anchor (<0 is to the left, >0 to the right)\n\n\n var leftSide;\n\n if (head.line != anchor.line) {\n leftSide = (head.line - anchor.line) * (cm.doc.direction == \"ltr\" ? 1 : -1) > 0;\n } else {\n var headIndex = getBidiPartAt(order, head.ch, head.sticky);\n var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);\n\n if (headIndex == boundary - 1 || headIndex == boundary) {\n leftSide = dir < 0;\n } else {\n leftSide = dir > 0;\n }\n }\n\n var usePart = order[boundary + (leftSide ? -1 : 0)];\n var from = leftSide == (usePart.level == 1);\n var ch = from ? usePart.from : usePart.to,\n sticky = from ? \"after\" : \"before\";\n return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head);\n } // Determines whether an event happened in the gutter, and fires the\n // handlers for the corresponding event.\n\n\n function gutterEvent(cm, e, type, prevent) {\n var mX, mY;\n\n if (e.touches) {\n mX = e.touches[0].clientX;\n mY = e.touches[0].clientY;\n } else {\n try {\n mX = e.clientX;\n mY = e.clientY;\n } catch (e$1) {\n return false;\n }\n }\n\n if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) {\n return false;\n }\n\n if (prevent) {\n e_preventDefault(e);\n }\n\n var display = cm.display;\n var lineBox = display.lineDiv.getBoundingClientRect();\n\n if (mY > lineBox.bottom || !hasHandler(cm, type)) {\n return e_defaultPrevented(e);\n }\n\n mY -= lineBox.top - display.viewOffset;\n\n for (var i = 0; i < cm.display.gutterSpecs.length; ++i) {\n var g = display.gutters.childNodes[i];\n\n if (g && g.getBoundingClientRect().right >= mX) {\n var line = _lineAtHeight(cm.doc, mY);\n\n var gutter = cm.display.gutterSpecs[i];\n signal(cm, type, cm, line, gutter.className, e);\n return e_defaultPrevented(e);\n }\n }\n }\n\n function clickInGutter(cm, e) {\n return gutterEvent(cm, e, \"gutterClick\", true);\n } // CONTEXT MENU HANDLING\n // To make the context menu work, we need to briefly unhide the\n // textarea (making it as unobtrusive as possible) to let the\n // right-click take effect on it.\n\n\n function onContextMenu(cm, e) {\n if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) {\n return;\n }\n\n if (signalDOMEvent(cm, e, \"contextmenu\")) {\n return;\n }\n\n if (!captureRightClick) {\n cm.display.input.onContextMenu(e);\n }\n }\n\n function contextMenuInGutter(cm, e) {\n if (!hasHandler(cm, \"gutterContextMenu\")) {\n return false;\n }\n\n return gutterEvent(cm, e, \"gutterContextMenu\", false);\n }\n\n function themeChanged(cm) {\n cm.display.wrapper.className = cm.display.wrapper.className.replace(/\\s*cm-s-\\S+/g, \"\") + cm.options.theme.replace(/(^|\\s)\\s*/g, \" cm-s-\");\n clearCaches(cm);\n }\n\n var Init = {\n toString: function toString() {\n return \"CodeMirror.Init\";\n }\n };\n var defaults = {};\n var optionHandlers = {};\n\n function defineOptions(CodeMirror) {\n var optionHandlers = CodeMirror.optionHandlers;\n\n function option(name, deflt, handle, notOnInit) {\n CodeMirror.defaults[name] = deflt;\n\n if (handle) {\n optionHandlers[name] = notOnInit ? function (cm, val, old) {\n if (old != Init) {\n handle(cm, val, old);\n }\n } : handle;\n }\n }\n\n CodeMirror.defineOption = option; // Passed to option handlers when there is no old value.\n\n CodeMirror.Init = Init; // These two are, on init, called from the constructor because they\n // have to be initialized before the editor can start at all.\n\n option(\"value\", \"\", function (cm, val) {\n return cm.setValue(val);\n }, true);\n option(\"mode\", null, function (cm, val) {\n cm.doc.modeOption = val;\n loadMode(cm);\n }, true);\n option(\"indentUnit\", 2, loadMode, true);\n option(\"indentWithTabs\", false);\n option(\"smartIndent\", true);\n option(\"tabSize\", 4, function (cm) {\n resetModeState(cm);\n clearCaches(cm);\n regChange(cm);\n }, true);\n option(\"lineSeparator\", null, function (cm, val) {\n cm.doc.lineSep = val;\n\n if (!val) {\n return;\n }\n\n var newBreaks = [],\n lineNo = cm.doc.first;\n cm.doc.iter(function (line) {\n for (var pos = 0;;) {\n var found = line.text.indexOf(val, pos);\n\n if (found == -1) {\n break;\n }\n\n pos = found + val.length;\n newBreaks.push(Pos(lineNo, found));\n }\n\n lineNo++;\n });\n\n for (var i = newBreaks.length - 1; i >= 0; i--) {\n _replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length));\n }\n });\n option(\"specialChars\", /[\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u061c\\u200b-\\u200c\\u200e\\u200f\\u2028\\u2029\\ufeff\\ufff9-\\ufffc]/g, function (cm, val, old) {\n cm.state.specialChars = new RegExp(val.source + (val.test(\"\\t\") ? \"\" : \"|\\t\"), \"g\");\n\n if (old != Init) {\n cm.refresh();\n }\n });\n option(\"specialCharPlaceholder\", defaultSpecialCharPlaceholder, function (cm) {\n return cm.refresh();\n }, true);\n option(\"electricChars\", true);\n option(\"inputStyle\", mobile ? \"contenteditable\" : \"textarea\", function () {\n throw new Error(\"inputStyle can not (yet) be changed in a running editor\"); // FIXME\n }, true);\n option(\"spellcheck\", false, function (cm, val) {\n return cm.getInputField().spellcheck = val;\n }, true);\n option(\"autocorrect\", false, function (cm, val) {\n return cm.getInputField().autocorrect = val;\n }, true);\n option(\"autocapitalize\", false, function (cm, val) {\n return cm.getInputField().autocapitalize = val;\n }, true);\n option(\"rtlMoveVisually\", !windows);\n option(\"wholeLineUpdateBefore\", true);\n option(\"theme\", \"default\", function (cm) {\n themeChanged(cm);\n updateGutters(cm);\n }, true);\n option(\"keyMap\", \"default\", function (cm, val, old) {\n var next = getKeyMap(val);\n var prev = old != Init && getKeyMap(old);\n\n if (prev && prev.detach) {\n prev.detach(cm, next);\n }\n\n if (next.attach) {\n next.attach(cm, prev || null);\n }\n });\n option(\"extraKeys\", null);\n option(\"configureMouse\", null);\n option(\"lineWrapping\", false, wrappingChanged, true);\n option(\"gutters\", [], function (cm, val) {\n cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers);\n updateGutters(cm);\n }, true);\n option(\"fixedGutter\", true, function (cm, val) {\n cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + \"px\" : \"0\";\n cm.refresh();\n }, true);\n option(\"coverGutterNextToScrollbar\", false, function (cm) {\n return updateScrollbars(cm);\n }, true);\n option(\"scrollbarStyle\", \"native\", function (cm) {\n initScrollbars(cm);\n updateScrollbars(cm);\n cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);\n cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);\n }, true);\n option(\"lineNumbers\", false, function (cm, val) {\n cm.display.gutterSpecs = getGutters(cm.options.gutters, val);\n updateGutters(cm);\n }, true);\n option(\"firstLineNumber\", 1, updateGutters, true);\n option(\"lineNumberFormatter\", function (integer) {\n return integer;\n }, updateGutters, true);\n option(\"showCursorWhenSelecting\", false, updateSelection, true);\n option(\"resetSelectionOnContextMenu\", true);\n option(\"lineWiseCopyCut\", true);\n option(\"pasteLinesPerSelection\", true);\n option(\"selectionsMayTouch\", false);\n option(\"readOnly\", false, function (cm, val) {\n if (val == \"nocursor\") {\n onBlur(cm);\n cm.display.input.blur();\n }\n\n cm.display.input.readOnlyChanged(val);\n });\n option(\"screenReaderLabel\", null, function (cm, val) {\n val = val === '' ? null : val;\n cm.display.input.screenReaderLabelChanged(val);\n });\n option(\"disableInput\", false, function (cm, val) {\n if (!val) {\n cm.display.input.reset();\n }\n }, true);\n option(\"dragDrop\", true, dragDropChanged);\n option(\"allowDropFileTypes\", null);\n option(\"cursorBlinkRate\", 530);\n option(\"cursorScrollMargin\", 0);\n option(\"cursorHeight\", 1, updateSelection, true);\n option(\"singleCursorHeightPerLine\", true, updateSelection, true);\n option(\"workTime\", 100);\n option(\"workDelay\", 100);\n option(\"flattenSpans\", true, resetModeState, true);\n option(\"addModeClass\", false, resetModeState, true);\n option(\"pollInterval\", 100);\n option(\"undoDepth\", 200, function (cm, val) {\n return cm.doc.history.undoDepth = val;\n });\n option(\"historyEventDelay\", 1250);\n option(\"viewportMargin\", 10, function (cm) {\n return cm.refresh();\n }, true);\n option(\"maxHighlightLength\", 10000, resetModeState, true);\n option(\"moveInputWithCursor\", true, function (cm, val) {\n if (!val) {\n cm.display.input.resetPosition();\n }\n });\n option(\"tabindex\", null, function (cm, val) {\n return cm.display.input.getField().tabIndex = val || \"\";\n });\n option(\"autofocus\", null);\n option(\"direction\", \"ltr\", function (cm, val) {\n return cm.doc.setDirection(val);\n }, true);\n option(\"phrases\", null);\n }\n\n function dragDropChanged(cm, value, old) {\n var wasOn = old && old != Init;\n\n if (!value != !wasOn) {\n var funcs = cm.display.dragFunctions;\n var toggle = value ? on : off;\n toggle(cm.display.scroller, \"dragstart\", funcs.start);\n toggle(cm.display.scroller, \"dragenter\", funcs.enter);\n toggle(cm.display.scroller, \"dragover\", funcs.over);\n toggle(cm.display.scroller, \"dragleave\", funcs.leave);\n toggle(cm.display.scroller, \"drop\", funcs.drop);\n }\n }\n\n function wrappingChanged(cm) {\n if (cm.options.lineWrapping) {\n addClass(cm.display.wrapper, \"CodeMirror-wrap\");\n cm.display.sizer.style.minWidth = \"\";\n cm.display.sizerWidth = null;\n } else {\n rmClass(cm.display.wrapper, \"CodeMirror-wrap\");\n findMaxLine(cm);\n }\n\n estimateLineHeights(cm);\n regChange(cm);\n clearCaches(cm);\n setTimeout(function () {\n return updateScrollbars(cm);\n }, 100);\n } // A CodeMirror instance represents an editor. This is the object\n // that user code is usually dealing with.\n\n\n function CodeMirror(place, options) {\n var this$1 = this;\n\n if (!(this instanceof CodeMirror)) {\n return new CodeMirror(place, options);\n }\n\n this.options = options = options ? copyObj(options) : {}; // Determine effective options based on given values and defaults.\n\n copyObj(defaults, options, false);\n var doc = options.value;\n\n if (typeof doc == \"string\") {\n doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction);\n } else if (options.mode) {\n doc.modeOption = options.mode;\n }\n\n this.doc = doc;\n var input = new CodeMirror.inputStyles[options.inputStyle](this);\n var display = this.display = new Display(place, doc, input, options);\n display.wrapper.CodeMirror = this;\n themeChanged(this);\n\n if (options.lineWrapping) {\n this.display.wrapper.className += \" CodeMirror-wrap\";\n }\n\n initScrollbars(this);\n this.state = {\n keyMaps: [],\n // stores maps added by addKeyMap\n overlays: [],\n // highlighting overlays, as added by addOverlay\n modeGen: 0,\n // bumped when mode/overlay changes, used to invalidate highlighting info\n overwrite: false,\n delayingBlurEvent: false,\n focused: false,\n suppressEdits: false,\n // used to disable editing during key handlers when in readOnly mode\n pasteIncoming: -1,\n cutIncoming: -1,\n // help recognize paste/cut edits in input.poll\n selectingText: false,\n draggingText: false,\n highlight: new Delayed(),\n // stores highlight worker timeout\n keySeq: null,\n // Unfinished key sequence\n specialChars: null\n };\n\n if (options.autofocus && !mobile) {\n display.input.focus();\n } // Override magic textarea content restore that IE sometimes does\n // on our hidden textarea on reload\n\n\n if (ie && ie_version < 11) {\n setTimeout(function () {\n return this$1.display.input.reset(true);\n }, 20);\n }\n\n registerEventHandlers(this);\n ensureGlobalHandlers();\n\n _startOperation(this);\n\n this.curOp.forceUpdate = true;\n attachDoc(this, doc);\n\n if (options.autofocus && !mobile || this.hasFocus()) {\n setTimeout(function () {\n if (this$1.hasFocus() && !this$1.state.focused) {\n onFocus(this$1);\n }\n }, 20);\n } else {\n onBlur(this);\n }\n\n for (var opt in optionHandlers) {\n if (optionHandlers.hasOwnProperty(opt)) {\n optionHandlers[opt](this, options[opt], Init);\n }\n }\n\n maybeUpdateLineNumberWidth(this);\n\n if (options.finishInit) {\n options.finishInit(this);\n }\n\n for (var i = 0; i < initHooks.length; ++i) {\n initHooks[i](this);\n }\n\n _endOperation(this); // Suppress optimizelegibility in Webkit, since it breaks text\n // measuring on line wrapping boundaries.\n\n\n if (webkit && options.lineWrapping && getComputedStyle(display.lineDiv).textRendering == \"optimizelegibility\") {\n display.lineDiv.style.textRendering = \"auto\";\n }\n } // The default configuration options.\n\n\n CodeMirror.defaults = defaults; // Functions to run when options are changed.\n\n CodeMirror.optionHandlers = optionHandlers; // Attach the necessary event handlers when initializing the editor\n\n function registerEventHandlers(cm) {\n var d = cm.display;\n on(d.scroller, \"mousedown\", operation(cm, onMouseDown)); // Older IE's will not fire a second mousedown for a double click\n\n if (ie && ie_version < 11) {\n on(d.scroller, \"dblclick\", operation(cm, function (e) {\n if (signalDOMEvent(cm, e)) {\n return;\n }\n\n var pos = posFromMouse(cm, e);\n\n if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) {\n return;\n }\n\n e_preventDefault(e);\n var word = cm.findWordAt(pos);\n extendSelection(cm.doc, word.anchor, word.head);\n }));\n } else {\n on(d.scroller, \"dblclick\", function (e) {\n return signalDOMEvent(cm, e) || e_preventDefault(e);\n });\n } // Some browsers fire contextmenu *after* opening the menu, at\n // which point we can't mess with it anymore. Context menu is\n // handled in onMouseDown for these browsers.\n\n\n on(d.scroller, \"contextmenu\", function (e) {\n return onContextMenu(cm, e);\n });\n on(d.input.getField(), \"contextmenu\", function (e) {\n if (!d.scroller.contains(e.target)) {\n onContextMenu(cm, e);\n }\n }); // Used to suppress mouse event handling when a touch happens\n\n var touchFinished,\n prevTouch = {\n end: 0\n };\n\n function finishTouch() {\n if (d.activeTouch) {\n touchFinished = setTimeout(function () {\n return d.activeTouch = null;\n }, 1000);\n prevTouch = d.activeTouch;\n prevTouch.end = +new Date();\n }\n }\n\n function isMouseLikeTouchEvent(e) {\n if (e.touches.length != 1) {\n return false;\n }\n\n var touch = e.touches[0];\n return touch.radiusX <= 1 && touch.radiusY <= 1;\n }\n\n function farAway(touch, other) {\n if (other.left == null) {\n return true;\n }\n\n var dx = other.left - touch.left,\n dy = other.top - touch.top;\n return dx * dx + dy * dy > 20 * 20;\n }\n\n on(d.scroller, \"touchstart\", function (e) {\n if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {\n d.input.ensurePolled();\n clearTimeout(touchFinished);\n var now = +new Date();\n d.activeTouch = {\n start: now,\n moved: false,\n prev: now - prevTouch.end <= 300 ? prevTouch : null\n };\n\n if (e.touches.length == 1) {\n d.activeTouch.left = e.touches[0].pageX;\n d.activeTouch.top = e.touches[0].pageY;\n }\n }\n });\n on(d.scroller, \"touchmove\", function () {\n if (d.activeTouch) {\n d.activeTouch.moved = true;\n }\n });\n on(d.scroller, \"touchend\", function (e) {\n var touch = d.activeTouch;\n\n if (touch && !eventInWidget(d, e) && touch.left != null && !touch.moved && new Date() - touch.start < 300) {\n var pos = cm.coordsChar(d.activeTouch, \"page\"),\n range;\n\n if (!touch.prev || farAway(touch, touch.prev)) // Single tap\n {\n range = new Range(pos, pos);\n } else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap\n {\n range = cm.findWordAt(pos);\n } else // Triple tap\n {\n range = new Range(Pos(pos.line, 0), _clipPos(cm.doc, Pos(pos.line + 1, 0)));\n }\n\n cm.setSelection(range.anchor, range.head);\n cm.focus();\n e_preventDefault(e);\n }\n\n finishTouch();\n });\n on(d.scroller, \"touchcancel\", finishTouch); // Sync scrolling between fake scrollbars and real scrollable\n // area, ensure viewport is updated when scrolling.\n\n on(d.scroller, \"scroll\", function () {\n if (d.scroller.clientHeight) {\n updateScrollTop(cm, d.scroller.scrollTop);\n setScrollLeft(cm, d.scroller.scrollLeft, true);\n signal(cm, \"scroll\", cm);\n }\n }); // Listen to wheel events in order to try and update the viewport on time.\n\n on(d.scroller, \"mousewheel\", function (e) {\n return onScrollWheel(cm, e);\n });\n on(d.scroller, \"DOMMouseScroll\", function (e) {\n return onScrollWheel(cm, e);\n }); // Prevent wrapper from ever scrolling\n\n on(d.wrapper, \"scroll\", function () {\n return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0;\n });\n d.dragFunctions = {\n enter: function enter(e) {\n if (!signalDOMEvent(cm, e)) {\n e_stop(e);\n }\n },\n over: function over(e) {\n if (!signalDOMEvent(cm, e)) {\n onDragOver(cm, e);\n e_stop(e);\n }\n },\n start: function start(e) {\n return onDragStart(cm, e);\n },\n drop: operation(cm, onDrop),\n leave: function leave(e) {\n if (!signalDOMEvent(cm, e)) {\n clearDragCursor(cm);\n }\n }\n };\n var inp = d.input.getField();\n on(inp, \"keyup\", function (e) {\n return onKeyUp.call(cm, e);\n });\n on(inp, \"keydown\", operation(cm, onKeyDown));\n on(inp, \"keypress\", operation(cm, onKeyPress));\n on(inp, \"focus\", function (e) {\n return onFocus(cm, e);\n });\n on(inp, \"blur\", function (e) {\n return onBlur(cm, e);\n });\n }\n\n var initHooks = [];\n\n CodeMirror.defineInitHook = function (f) {\n return initHooks.push(f);\n }; // Indent the given line. The how parameter can be \"smart\",\n // \"add\"/null, \"subtract\", or \"prev\". When aggressive is false\n // (typically set to true for forced single-line indents), empty\n // lines are not indented, and places where the mode returns Pass\n // are left alone.\n\n\n function indentLine(cm, n, how, aggressive) {\n var doc = cm.doc,\n state;\n\n if (how == null) {\n how = \"add\";\n }\n\n if (how == \"smart\") {\n // Fall back to \"prev\" when the mode doesn't have an indentation\n // method.\n if (!doc.mode.indent) {\n how = \"prev\";\n } else {\n state = getContextBefore(cm, n).state;\n }\n }\n\n var tabSize = cm.options.tabSize;\n var line = getLine(doc, n),\n curSpace = countColumn(line.text, null, tabSize);\n\n if (line.stateAfter) {\n line.stateAfter = null;\n }\n\n var curSpaceString = line.text.match(/^\\s*/)[0],\n indentation;\n\n if (!aggressive && !/\\S/.test(line.text)) {\n indentation = 0;\n how = \"not\";\n } else if (how == \"smart\") {\n indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);\n\n if (indentation == Pass || indentation > 150) {\n if (!aggressive) {\n return;\n }\n\n how = \"prev\";\n }\n }\n\n if (how == \"prev\") {\n if (n > doc.first) {\n indentation = countColumn(getLine(doc, n - 1).text, null, tabSize);\n } else {\n indentation = 0;\n }\n } else if (how == \"add\") {\n indentation = curSpace + cm.options.indentUnit;\n } else if (how == \"subtract\") {\n indentation = curSpace - cm.options.indentUnit;\n } else if (typeof how == \"number\") {\n indentation = curSpace + how;\n }\n\n indentation = Math.max(0, indentation);\n var indentString = \"\",\n pos = 0;\n\n if (cm.options.indentWithTabs) {\n for (var i = Math.floor(indentation / tabSize); i; --i) {\n pos += tabSize;\n indentString += \"\\t\";\n }\n }\n\n if (pos < indentation) {\n indentString += spaceStr(indentation - pos);\n }\n\n if (indentString != curSpaceString) {\n _replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), \"+input\");\n\n line.stateAfter = null;\n return true;\n } else {\n // Ensure that, if the cursor was in the whitespace at the start\n // of the line, it is moved to the end of that space.\n for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {\n var range = doc.sel.ranges[i$1];\n\n if (range.head.line == n && range.head.ch < curSpaceString.length) {\n var pos$1 = Pos(n, curSpaceString.length);\n replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));\n break;\n }\n }\n }\n } // This will be set to a {lineWise: bool, text: [string]} object, so\n // that, when pasting, we know what kind of selections the copied\n // text was made out of.\n\n\n var lastCopied = null;\n\n function setLastCopied(newLastCopied) {\n lastCopied = newLastCopied;\n }\n\n function applyTextInput(cm, inserted, deleted, sel, origin) {\n var doc = cm.doc;\n cm.display.shift = false;\n\n if (!sel) {\n sel = doc.sel;\n }\n\n var recent = +new Date() - 200;\n var paste = origin == \"paste\" || cm.state.pasteIncoming > recent;\n var textLines = splitLinesAuto(inserted),\n multiPaste = null; // When pasting N lines into N selections, insert one line per selection\n\n if (paste && sel.ranges.length > 1) {\n if (lastCopied && lastCopied.text.join(\"\\n\") == inserted) {\n if (sel.ranges.length % lastCopied.text.length == 0) {\n multiPaste = [];\n\n for (var i = 0; i < lastCopied.text.length; i++) {\n multiPaste.push(doc.splitLines(lastCopied.text[i]));\n }\n }\n } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {\n multiPaste = map(textLines, function (l) {\n return [l];\n });\n }\n }\n\n var updateInput = cm.curOp.updateInput; // Normal behavior is to insert the new text into every selection\n\n for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {\n var range = sel.ranges[i$1];\n var from = range.from(),\n to = range.to();\n\n if (range.empty()) {\n if (deleted && deleted > 0) // Handle deletion\n {\n from = Pos(from.line, from.ch - deleted);\n } else if (cm.state.overwrite && !paste) // Handle overwrite\n {\n to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));\n } else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join(\"\\n\") == textLines.join(\"\\n\")) {\n from = to = Pos(from.line, 0);\n }\n }\n\n var changeEvent = {\n from: from,\n to: to,\n text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,\n origin: origin || (paste ? \"paste\" : cm.state.cutIncoming > recent ? \"cut\" : \"+input\")\n };\n makeChange(cm.doc, changeEvent);\n signalLater(cm, \"inputRead\", cm, changeEvent);\n }\n\n if (inserted && !paste) {\n triggerElectric(cm, inserted);\n }\n\n ensureCursorVisible(cm);\n\n if (cm.curOp.updateInput < 2) {\n cm.curOp.updateInput = updateInput;\n }\n\n cm.curOp.typing = true;\n cm.state.pasteIncoming = cm.state.cutIncoming = -1;\n }\n\n function handlePaste(e, cm) {\n var pasted = e.clipboardData && e.clipboardData.getData(\"Text\");\n\n if (pasted) {\n e.preventDefault();\n\n if (!cm.isReadOnly() && !cm.options.disableInput) {\n runInOp(cm, function () {\n return applyTextInput(cm, pasted, 0, null, \"paste\");\n });\n }\n\n return true;\n }\n }\n\n function triggerElectric(cm, inserted) {\n // When an 'electric' character is inserted, immediately trigger a reindent\n if (!cm.options.electricChars || !cm.options.smartIndent) {\n return;\n }\n\n var sel = cm.doc.sel;\n\n for (var i = sel.ranges.length - 1; i >= 0; i--) {\n var range = sel.ranges[i];\n\n if (range.head.ch > 100 || i && sel.ranges[i - 1].head.line == range.head.line) {\n continue;\n }\n\n var mode = cm.getModeAt(range.head);\n var indented = false;\n\n if (mode.electricChars) {\n for (var j = 0; j < mode.electricChars.length; j++) {\n if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {\n indented = indentLine(cm, range.head.line, \"smart\");\n break;\n }\n }\n } else if (mode.electricInput) {\n if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch))) {\n indented = indentLine(cm, range.head.line, \"smart\");\n }\n }\n\n if (indented) {\n signalLater(cm, \"electricInput\", cm, range.head.line);\n }\n }\n }\n\n function copyableRanges(cm) {\n var text = [],\n ranges = [];\n\n for (var i = 0; i < cm.doc.sel.ranges.length; i++) {\n var line = cm.doc.sel.ranges[i].head.line;\n var lineRange = {\n anchor: Pos(line, 0),\n head: Pos(line + 1, 0)\n };\n ranges.push(lineRange);\n text.push(cm.getRange(lineRange.anchor, lineRange.head));\n }\n\n return {\n text: text,\n ranges: ranges\n };\n }\n\n function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {\n field.setAttribute(\"autocorrect\", autocorrect ? \"\" : \"off\");\n field.setAttribute(\"autocapitalize\", autocapitalize ? \"\" : \"off\");\n field.setAttribute(\"spellcheck\", !!spellcheck);\n }\n\n function hiddenTextarea() {\n var te = elt(\"textarea\", null, null, \"position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none\");\n var div = elt(\"div\", [te], null, \"overflow: hidden; position: relative; width: 3px; height: 0px;\"); // The textarea is kept positioned near the cursor to prevent the\n // fact that it'll be scrolled into view on input from scrolling\n // our fake cursor out of view. On webkit, when wrap=off, paste is\n // very slow. So make the area wide instead.\n\n if (webkit) {\n te.style.width = \"1000px\";\n } else {\n te.setAttribute(\"wrap\", \"off\");\n } // If border: 0; -- iOS fails to open keyboard (issue #1287)\n\n\n if (ios) {\n te.style.border = \"1px solid black\";\n }\n\n disableBrowserMagic(te);\n return div;\n } // The publicly visible API. Note that methodOp(f) means\n // 'wrap f in an operation, performed on its `this` parameter'.\n // This is not the complete set of editor methods. Most of the\n // methods defined on the Doc type are also injected into\n // CodeMirror.prototype, for backwards compatibility and\n // convenience.\n\n\n function addEditorMethods(CodeMirror) {\n var optionHandlers = CodeMirror.optionHandlers;\n var helpers = CodeMirror.helpers = {};\n CodeMirror.prototype = {\n constructor: CodeMirror,\n focus: function focus() {\n window.focus();\n this.display.input.focus();\n },\n setOption: function setOption(option, value) {\n var options = this.options,\n old = options[option];\n\n if (options[option] == value && option != \"mode\") {\n return;\n }\n\n options[option] = value;\n\n if (optionHandlers.hasOwnProperty(option)) {\n operation(this, optionHandlers[option])(this, value, old);\n }\n\n signal(this, \"optionChange\", this, option);\n },\n getOption: function getOption(option) {\n return this.options[option];\n },\n getDoc: function getDoc() {\n return this.doc;\n },\n addKeyMap: function addKeyMap(map, bottom) {\n this.state.keyMaps[bottom ? \"push\" : \"unshift\"](getKeyMap(map));\n },\n removeKeyMap: function removeKeyMap(map) {\n var maps = this.state.keyMaps;\n\n for (var i = 0; i < maps.length; ++i) {\n if (maps[i] == map || maps[i].name == map) {\n maps.splice(i, 1);\n return true;\n }\n }\n },\n addOverlay: methodOp(function (spec, options) {\n var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);\n\n if (mode.startState) {\n throw new Error(\"Overlays may not be stateful.\");\n }\n\n insertSorted(this.state.overlays, {\n mode: mode,\n modeSpec: spec,\n opaque: options && options.opaque,\n priority: options && options.priority || 0\n }, function (overlay) {\n return overlay.priority;\n });\n this.state.modeGen++;\n regChange(this);\n }),\n removeOverlay: methodOp(function (spec) {\n var overlays = this.state.overlays;\n\n for (var i = 0; i < overlays.length; ++i) {\n var cur = overlays[i].modeSpec;\n\n if (cur == spec || typeof spec == \"string\" && cur.name == spec) {\n overlays.splice(i, 1);\n this.state.modeGen++;\n regChange(this);\n return;\n }\n }\n }),\n indentLine: methodOp(function (n, dir, aggressive) {\n if (typeof dir != \"string\" && typeof dir != \"number\") {\n if (dir == null) {\n dir = this.options.smartIndent ? \"smart\" : \"prev\";\n } else {\n dir = dir ? \"add\" : \"subtract\";\n }\n }\n\n if (isLine(this.doc, n)) {\n indentLine(this, n, dir, aggressive);\n }\n }),\n indentSelection: methodOp(function (how) {\n var ranges = this.doc.sel.ranges,\n end = -1;\n\n for (var i = 0; i < ranges.length; i++) {\n var range = ranges[i];\n\n if (!range.empty()) {\n var from = range.from(),\n to = range.to();\n var start = Math.max(end, from.line);\n end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;\n\n for (var j = start; j < end; ++j) {\n indentLine(this, j, how);\n }\n\n var newRanges = this.doc.sel.ranges;\n\n if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0) {\n replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll);\n }\n } else if (range.head.line > end) {\n indentLine(this, range.head.line, how, true);\n end = range.head.line;\n\n if (i == this.doc.sel.primIndex) {\n ensureCursorVisible(this);\n }\n }\n }\n }),\n // Fetch the parser token for a given character. Useful for hacks\n // that want to inspect the mode state (say, for completion).\n getTokenAt: function getTokenAt(pos, precise) {\n return takeToken(this, pos, precise);\n },\n getLineTokens: function getLineTokens(line, precise) {\n return takeToken(this, Pos(line), precise, true);\n },\n getTokenTypeAt: function getTokenTypeAt(pos) {\n pos = _clipPos(this.doc, pos);\n var styles = getLineStyles(this, getLine(this.doc, pos.line));\n var before = 0,\n after = (styles.length - 1) / 2,\n ch = pos.ch;\n var type;\n\n if (ch == 0) {\n type = styles[2];\n } else {\n for (;;) {\n var mid = before + after >> 1;\n\n if ((mid ? styles[mid * 2 - 1] : 0) >= ch) {\n after = mid;\n } else if (styles[mid * 2 + 1] < ch) {\n before = mid + 1;\n } else {\n type = styles[mid * 2 + 2];\n break;\n }\n }\n }\n\n var cut = type ? type.indexOf(\"overlay \") : -1;\n return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);\n },\n getModeAt: function getModeAt(pos) {\n var mode = this.doc.mode;\n\n if (!mode.innerMode) {\n return mode;\n }\n\n return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;\n },\n getHelper: function getHelper(pos, type) {\n return this.getHelpers(pos, type)[0];\n },\n getHelpers: function getHelpers(pos, type) {\n var found = [];\n\n if (!helpers.hasOwnProperty(type)) {\n return found;\n }\n\n var help = helpers[type],\n mode = this.getModeAt(pos);\n\n if (typeof mode[type] == \"string\") {\n if (help[mode[type]]) {\n found.push(help[mode[type]]);\n }\n } else if (mode[type]) {\n for (var i = 0; i < mode[type].length; i++) {\n var val = help[mode[type][i]];\n\n if (val) {\n found.push(val);\n }\n }\n } else if (mode.helperType && help[mode.helperType]) {\n found.push(help[mode.helperType]);\n } else if (help[mode.name]) {\n found.push(help[mode.name]);\n }\n\n for (var i$1 = 0; i$1 < help._global.length; i$1++) {\n var cur = help._global[i$1];\n\n if (cur.pred(mode, this) && indexOf(found, cur.val) == -1) {\n found.push(cur.val);\n }\n }\n\n return found;\n },\n getStateAfter: function getStateAfter(line, precise) {\n var doc = this.doc;\n line = clipLine(doc, line == null ? doc.first + doc.size - 1 : line);\n return getContextBefore(this, line + 1, precise).state;\n },\n cursorCoords: function cursorCoords(start, mode) {\n var pos,\n range = this.doc.sel.primary();\n\n if (start == null) {\n pos = range.head;\n } else if (_typeof(start) == \"object\") {\n pos = _clipPos(this.doc, start);\n } else {\n pos = start ? range.from() : range.to();\n }\n\n return _cursorCoords(this, pos, mode || \"page\");\n },\n charCoords: function charCoords(pos, mode) {\n return _charCoords(this, _clipPos(this.doc, pos), mode || \"page\");\n },\n coordsChar: function coordsChar(coords, mode) {\n coords = fromCoordSystem(this, coords, mode || \"page\");\n return _coordsChar(this, coords.left, coords.top);\n },\n lineAtHeight: function lineAtHeight(height, mode) {\n height = fromCoordSystem(this, {\n top: height,\n left: 0\n }, mode || \"page\").top;\n return _lineAtHeight(this.doc, height + this.display.viewOffset);\n },\n heightAtLine: function heightAtLine(line, mode, includeWidgets) {\n var end = false,\n lineObj;\n\n if (typeof line == \"number\") {\n var last = this.doc.first + this.doc.size - 1;\n\n if (line < this.doc.first) {\n line = this.doc.first;\n } else if (line > last) {\n line = last;\n end = true;\n }\n\n lineObj = getLine(this.doc, line);\n } else {\n lineObj = line;\n }\n\n return intoCoordSystem(this, lineObj, {\n top: 0,\n left: 0\n }, mode || \"page\", includeWidgets || end).top + (end ? this.doc.height - _heightAtLine(lineObj) : 0);\n },\n defaultTextHeight: function defaultTextHeight() {\n return textHeight(this.display);\n },\n defaultCharWidth: function defaultCharWidth() {\n return charWidth(this.display);\n },\n getViewport: function getViewport() {\n return {\n from: this.display.viewFrom,\n to: this.display.viewTo\n };\n },\n addWidget: function addWidget(pos, node, scroll, vert, horiz) {\n var display = this.display;\n pos = _cursorCoords(this, _clipPos(this.doc, pos));\n var top = pos.bottom,\n left = pos.left;\n node.style.position = \"absolute\";\n node.setAttribute(\"cm-ignore-events\", \"true\");\n this.display.input.setUneditable(node);\n display.sizer.appendChild(node);\n\n if (vert == \"over\") {\n top = pos.top;\n } else if (vert == \"above\" || vert == \"near\") {\n var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),\n hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth); // Default to positioning above (if specified and possible); otherwise default to positioning below\n\n if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight) {\n top = pos.top - node.offsetHeight;\n } else if (pos.bottom + node.offsetHeight <= vspace) {\n top = pos.bottom;\n }\n\n if (left + node.offsetWidth > hspace) {\n left = hspace - node.offsetWidth;\n }\n }\n\n node.style.top = top + \"px\";\n node.style.left = node.style.right = \"\";\n\n if (horiz == \"right\") {\n left = display.sizer.clientWidth - node.offsetWidth;\n node.style.right = \"0px\";\n } else {\n if (horiz == \"left\") {\n left = 0;\n } else if (horiz == \"middle\") {\n left = (display.sizer.clientWidth - node.offsetWidth) / 2;\n }\n\n node.style.left = left + \"px\";\n }\n\n if (scroll) {\n scrollIntoView(this, {\n left: left,\n top: top,\n right: left + node.offsetWidth,\n bottom: top + node.offsetHeight\n });\n }\n },\n triggerOnKeyDown: methodOp(onKeyDown),\n triggerOnKeyPress: methodOp(onKeyPress),\n triggerOnKeyUp: onKeyUp,\n triggerOnMouseDown: methodOp(onMouseDown),\n execCommand: function execCommand(cmd) {\n if (commands.hasOwnProperty(cmd)) {\n return commands[cmd].call(null, this);\n }\n },\n triggerElectric: methodOp(function (text) {\n triggerElectric(this, text);\n }),\n findPosH: function findPosH(from, amount, unit, visually) {\n var dir = 1;\n\n if (amount < 0) {\n dir = -1;\n amount = -amount;\n }\n\n var cur = _clipPos(this.doc, from);\n\n for (var i = 0; i < amount; ++i) {\n cur = _findPosH(this.doc, cur, dir, unit, visually);\n\n if (cur.hitSide) {\n break;\n }\n }\n\n return cur;\n },\n moveH: methodOp(function (dir, unit) {\n var this$1 = this;\n this.extendSelectionsBy(function (range) {\n if (this$1.display.shift || this$1.doc.extend || range.empty()) {\n return _findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually);\n } else {\n return dir < 0 ? range.from() : range.to();\n }\n }, sel_move);\n }),\n deleteH: methodOp(function (dir, unit) {\n var sel = this.doc.sel,\n doc = this.doc;\n\n if (sel.somethingSelected()) {\n doc.replaceSelection(\"\", null, \"+delete\");\n } else {\n deleteNearSelection(this, function (range) {\n var other = _findPosH(doc, range.head, dir, unit, false);\n\n return dir < 0 ? {\n from: other,\n to: range.head\n } : {\n from: range.head,\n to: other\n };\n });\n }\n }),\n findPosV: function findPosV(from, amount, unit, goalColumn) {\n var dir = 1,\n x = goalColumn;\n\n if (amount < 0) {\n dir = -1;\n amount = -amount;\n }\n\n var cur = _clipPos(this.doc, from);\n\n for (var i = 0; i < amount; ++i) {\n var coords = _cursorCoords(this, cur, \"div\");\n\n if (x == null) {\n x = coords.left;\n } else {\n coords.left = x;\n }\n\n cur = _findPosV(this, coords, dir, unit);\n\n if (cur.hitSide) {\n break;\n }\n }\n\n return cur;\n },\n moveV: methodOp(function (dir, unit) {\n var this$1 = this;\n var doc = this.doc,\n goals = [];\n var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();\n doc.extendSelectionsBy(function (range) {\n if (collapse) {\n return dir < 0 ? range.from() : range.to();\n }\n\n var headPos = _cursorCoords(this$1, range.head, \"div\");\n\n if (range.goalColumn != null) {\n headPos.left = range.goalColumn;\n }\n\n goals.push(headPos.left);\n\n var pos = _findPosV(this$1, headPos, dir, unit);\n\n if (unit == \"page\" && range == doc.sel.primary()) {\n addToScrollTop(this$1, _charCoords(this$1, pos, \"div\").top - headPos.top);\n }\n\n return pos;\n }, sel_move);\n\n if (goals.length) {\n for (var i = 0; i < doc.sel.ranges.length; i++) {\n doc.sel.ranges[i].goalColumn = goals[i];\n }\n }\n }),\n // Find the word at the given position (as returned by coordsChar).\n findWordAt: function findWordAt(pos) {\n var doc = this.doc,\n line = getLine(doc, pos.line).text;\n var start = pos.ch,\n end = pos.ch;\n\n if (line) {\n var helper = this.getHelper(pos, \"wordChars\");\n\n if ((pos.sticky == \"before\" || end == line.length) && start) {\n --start;\n } else {\n ++end;\n }\n\n var startChar = line.charAt(start);\n var check = isWordChar(startChar, helper) ? function (ch) {\n return isWordChar(ch, helper);\n } : /\\s/.test(startChar) ? function (ch) {\n return /\\s/.test(ch);\n } : function (ch) {\n return !/\\s/.test(ch) && !isWordChar(ch);\n };\n\n while (start > 0 && check(line.charAt(start - 1))) {\n --start;\n }\n\n while (end < line.length && check(line.charAt(end))) {\n ++end;\n }\n }\n\n return new Range(Pos(pos.line, start), Pos(pos.line, end));\n },\n toggleOverwrite: function toggleOverwrite(value) {\n if (value != null && value == this.state.overwrite) {\n return;\n }\n\n if (this.state.overwrite = !this.state.overwrite) {\n addClass(this.display.cursorDiv, \"CodeMirror-overwrite\");\n } else {\n rmClass(this.display.cursorDiv, \"CodeMirror-overwrite\");\n }\n\n signal(this, \"overwriteToggle\", this, this.state.overwrite);\n },\n hasFocus: function hasFocus() {\n return this.display.input.getField() == activeElt();\n },\n isReadOnly: function isReadOnly() {\n return !!(this.options.readOnly || this.doc.cantEdit);\n },\n scrollTo: methodOp(function (x, y) {\n scrollToCoords(this, x, y);\n }),\n getScrollInfo: function getScrollInfo() {\n var scroller = this.display.scroller;\n return {\n left: scroller.scrollLeft,\n top: scroller.scrollTop,\n height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,\n width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,\n clientHeight: displayHeight(this),\n clientWidth: displayWidth(this)\n };\n },\n scrollIntoView: methodOp(function (range, margin) {\n if (range == null) {\n range = {\n from: this.doc.sel.primary().head,\n to: null\n };\n\n if (margin == null) {\n margin = this.options.cursorScrollMargin;\n }\n } else if (typeof range == \"number\") {\n range = {\n from: Pos(range, 0),\n to: null\n };\n } else if (range.from == null) {\n range = {\n from: range,\n to: null\n };\n }\n\n if (!range.to) {\n range.to = range.from;\n }\n\n range.margin = margin || 0;\n\n if (range.from.line != null) {\n scrollToRange(this, range);\n } else {\n scrollToCoordsRange(this, range.from, range.to, range.margin);\n }\n }),\n setSize: methodOp(function (width, height) {\n var this$1 = this;\n\n var interpret = function interpret(val) {\n return typeof val == \"number\" || /^\\d+$/.test(String(val)) ? val + \"px\" : val;\n };\n\n if (width != null) {\n this.display.wrapper.style.width = interpret(width);\n }\n\n if (height != null) {\n this.display.wrapper.style.height = interpret(height);\n }\n\n if (this.options.lineWrapping) {\n clearLineMeasurementCache(this);\n }\n\n var lineNo = this.display.viewFrom;\n this.doc.iter(lineNo, this.display.viewTo, function (line) {\n if (line.widgets) {\n for (var i = 0; i < line.widgets.length; i++) {\n if (line.widgets[i].noHScroll) {\n regLineChange(this$1, lineNo, \"widget\");\n break;\n }\n }\n }\n\n ++lineNo;\n });\n this.curOp.forceUpdate = true;\n signal(this, \"refresh\", this);\n }),\n operation: function operation(f) {\n return runInOp(this, f);\n },\n startOperation: function startOperation() {\n return _startOperation(this);\n },\n endOperation: function endOperation() {\n return _endOperation(this);\n },\n refresh: methodOp(function () {\n var oldHeight = this.display.cachedTextHeight;\n regChange(this);\n this.curOp.forceUpdate = true;\n clearCaches(this);\n scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);\n updateGutterSpace(this.display);\n\n if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5 || this.options.lineWrapping) {\n estimateLineHeights(this);\n }\n\n signal(this, \"refresh\", this);\n }),\n swapDoc: methodOp(function (doc) {\n var old = this.doc;\n old.cm = null; // Cancel the current text selection if any (#5821)\n\n if (this.state.selectingText) {\n this.state.selectingText();\n }\n\n attachDoc(this, doc);\n clearCaches(this);\n this.display.input.reset();\n scrollToCoords(this, doc.scrollLeft, doc.scrollTop);\n this.curOp.forceScroll = true;\n signalLater(this, \"swapDoc\", this, old);\n return old;\n }),\n phrase: function phrase(phraseText) {\n var phrases = this.options.phrases;\n return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText;\n },\n getInputField: function getInputField() {\n return this.display.input.getField();\n },\n getWrapperElement: function getWrapperElement() {\n return this.display.wrapper;\n },\n getScrollerElement: function getScrollerElement() {\n return this.display.scroller;\n },\n getGutterElement: function getGutterElement() {\n return this.display.gutters;\n }\n };\n eventMixin(CodeMirror);\n\n CodeMirror.registerHelper = function (type, name, value) {\n if (!helpers.hasOwnProperty(type)) {\n helpers[type] = CodeMirror[type] = {\n _global: []\n };\n }\n\n helpers[type][name] = value;\n };\n\n CodeMirror.registerGlobalHelper = function (type, name, predicate, value) {\n CodeMirror.registerHelper(type, name, value);\n\n helpers[type]._global.push({\n pred: predicate,\n val: value\n });\n };\n } // Used for horizontal relative motion. Dir is -1 or 1 (left or\n // right), unit can be \"codepoint\", \"char\", \"column\" (like char, but\n // doesn't cross line boundaries), \"word\" (across next word), or\n // \"group\" (to the start of next group of word or\n // non-word-non-whitespace chars). The visually param controls\n // whether, in right-to-left text, direction 1 means to move towards\n // the next index in the string, or towards the character to the right\n // of the current position. The resulting position will have a\n // hitSide=true property if it reached the end of the document.\n\n\n function _findPosH(doc, pos, dir, unit, visually) {\n var oldPos = pos;\n var origDir = dir;\n var lineObj = getLine(doc, pos.line);\n var lineDir = visually && doc.direction == \"rtl\" ? -dir : dir;\n\n function findNextLine() {\n var l = pos.line + lineDir;\n\n if (l < doc.first || l >= doc.first + doc.size) {\n return false;\n }\n\n pos = new Pos(l, pos.ch, pos.sticky);\n return lineObj = getLine(doc, l);\n }\n\n function moveOnce(boundToLine) {\n var next;\n\n if (unit == \"codepoint\") {\n var ch = lineObj.text.charCodeAt(pos.ch + (unit > 0 ? 0 : -1));\n\n if (isNaN(ch)) {\n next = null;\n } else {\n next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (ch >= 0xD800 && ch < 0xDC00 ? 2 : 1))), -dir);\n }\n } else if (visually) {\n next = moveVisually(doc.cm, lineObj, pos, dir);\n } else {\n next = moveLogically(lineObj, pos, dir);\n }\n\n if (next == null) {\n if (!boundToLine && findNextLine()) {\n pos = endOfLine(visually, doc.cm, lineObj, pos.line, lineDir);\n } else {\n return false;\n }\n } else {\n pos = next;\n }\n\n return true;\n }\n\n if (unit == \"char\" || unit == \"codepoint\") {\n moveOnce();\n } else if (unit == \"column\") {\n moveOnce(true);\n } else if (unit == \"word\" || unit == \"group\") {\n var sawType = null,\n group = unit == \"group\";\n var helper = doc.cm && doc.cm.getHelper(pos, \"wordChars\");\n\n for (var first = true;; first = false) {\n if (dir < 0 && !moveOnce(!first)) {\n break;\n }\n\n var cur = lineObj.text.charAt(pos.ch) || \"\\n\";\n var type = isWordChar(cur, helper) ? \"w\" : group && cur == \"\\n\" ? \"n\" : !group || /\\s/.test(cur) ? null : \"p\";\n\n if (group && !first && !type) {\n type = \"s\";\n }\n\n if (sawType && sawType != type) {\n if (dir < 0) {\n dir = 1;\n moveOnce();\n pos.sticky = \"after\";\n }\n\n break;\n }\n\n if (type) {\n sawType = type;\n }\n\n if (dir > 0 && !moveOnce(!first)) {\n break;\n }\n }\n }\n\n var result = skipAtomic(doc, pos, oldPos, origDir, true);\n\n if (equalCursorPos(oldPos, result)) {\n result.hitSide = true;\n }\n\n return result;\n } // For relative vertical movement. Dir may be -1 or 1. Unit can be\n // \"page\" or \"line\". The resulting position will have a hitSide=true\n // property if it reached the end of the document.\n\n\n function _findPosV(cm, pos, dir, unit) {\n var doc = cm.doc,\n x = pos.left,\n y;\n\n if (unit == \"page\") {\n var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);\n var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);\n y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;\n } else if (unit == \"line\") {\n y = dir > 0 ? pos.bottom + 3 : pos.top - 3;\n }\n\n var target;\n\n for (;;) {\n target = _coordsChar(cm, x, y);\n\n if (!target.outside) {\n break;\n }\n\n if (dir < 0 ? y <= 0 : y >= doc.height) {\n target.hitSide = true;\n break;\n }\n\n y += dir * 5;\n }\n\n return target;\n } // CONTENTEDITABLE INPUT STYLE\n\n\n var ContentEditableInput = function ContentEditableInput(cm) {\n this.cm = cm;\n this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;\n this.polling = new Delayed();\n this.composing = null;\n this.gracePeriod = false;\n this.readDOMTimeout = null;\n };\n\n ContentEditableInput.prototype.init = function (display) {\n var this$1 = this;\n var input = this,\n cm = input.cm;\n var div = input.div = display.lineDiv;\n disableBrowserMagic(div, cm.options.spellcheck, cm.options.autocorrect, cm.options.autocapitalize);\n\n function belongsToInput(e) {\n for (var t = e.target; t; t = t.parentNode) {\n if (t == div) {\n return true;\n }\n\n if (/\\bCodeMirror-(?:line)?widget\\b/.test(t.className)) {\n break;\n }\n }\n\n return false;\n }\n\n on(div, \"paste\", function (e) {\n if (!belongsToInput(e) || signalDOMEvent(cm, e) || handlePaste(e, cm)) {\n return;\n } // IE doesn't fire input events, so we schedule a read for the pasted content in this way\n\n\n if (ie_version <= 11) {\n setTimeout(operation(cm, function () {\n return this$1.updateFromDOM();\n }), 20);\n }\n });\n on(div, \"compositionstart\", function (e) {\n this$1.composing = {\n data: e.data,\n done: false\n };\n });\n on(div, \"compositionupdate\", function (e) {\n if (!this$1.composing) {\n this$1.composing = {\n data: e.data,\n done: false\n };\n }\n });\n on(div, \"compositionend\", function (e) {\n if (this$1.composing) {\n if (e.data != this$1.composing.data) {\n this$1.readFromDOMSoon();\n }\n\n this$1.composing.done = true;\n }\n });\n on(div, \"touchstart\", function () {\n return input.forceCompositionEnd();\n });\n on(div, \"input\", function () {\n if (!this$1.composing) {\n this$1.readFromDOMSoon();\n }\n });\n\n function onCopyCut(e) {\n if (!belongsToInput(e) || signalDOMEvent(cm, e)) {\n return;\n }\n\n if (cm.somethingSelected()) {\n setLastCopied({\n lineWise: false,\n text: cm.getSelections()\n });\n\n if (e.type == \"cut\") {\n cm.replaceSelection(\"\", null, \"cut\");\n }\n } else if (!cm.options.lineWiseCopyCut) {\n return;\n } else {\n var ranges = copyableRanges(cm);\n setLastCopied({\n lineWise: true,\n text: ranges.text\n });\n\n if (e.type == \"cut\") {\n cm.operation(function () {\n cm.setSelections(ranges.ranges, 0, sel_dontScroll);\n cm.replaceSelection(\"\", null, \"cut\");\n });\n }\n }\n\n if (e.clipboardData) {\n e.clipboardData.clearData();\n var content = lastCopied.text.join(\"\\n\"); // iOS exposes the clipboard API, but seems to discard content inserted into it\n\n e.clipboardData.setData(\"Text\", content);\n\n if (e.clipboardData.getData(\"Text\") == content) {\n e.preventDefault();\n return;\n }\n } // Old-fashioned briefly-focus-a-textarea hack\n\n\n var kludge = hiddenTextarea(),\n te = kludge.firstChild;\n cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);\n te.value = lastCopied.text.join(\"\\n\");\n var hadFocus = document.activeElement;\n selectInput(te);\n setTimeout(function () {\n cm.display.lineSpace.removeChild(kludge);\n hadFocus.focus();\n\n if (hadFocus == div) {\n input.showPrimarySelection();\n }\n }, 50);\n }\n\n on(div, \"copy\", onCopyCut);\n on(div, \"cut\", onCopyCut);\n };\n\n ContentEditableInput.prototype.screenReaderLabelChanged = function (label) {\n // Label for screenreaders, accessibility\n if (label) {\n this.div.setAttribute('aria-label', label);\n } else {\n this.div.removeAttribute('aria-label');\n }\n };\n\n ContentEditableInput.prototype.prepareSelection = function () {\n var result = prepareSelection(this.cm, false);\n result.focus = document.activeElement == this.div;\n return result;\n };\n\n ContentEditableInput.prototype.showSelection = function (info, takeFocus) {\n if (!info || !this.cm.display.view.length) {\n return;\n }\n\n if (info.focus || takeFocus) {\n this.showPrimarySelection();\n }\n\n this.showMultipleSelections(info);\n };\n\n ContentEditableInput.prototype.getSelection = function () {\n return this.cm.display.wrapper.ownerDocument.getSelection();\n };\n\n ContentEditableInput.prototype.showPrimarySelection = function () {\n var sel = this.getSelection(),\n cm = this.cm,\n prim = cm.doc.sel.primary();\n var from = prim.from(),\n to = prim.to();\n\n if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {\n sel.removeAllRanges();\n return;\n }\n\n var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);\n var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);\n\n if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad && cmp(minPos(curAnchor, curFocus), from) == 0 && cmp(maxPos(curAnchor, curFocus), to) == 0) {\n return;\n }\n\n var view = cm.display.view;\n var start = from.line >= cm.display.viewFrom && posToDOM(cm, from) || {\n node: view[0].measure.map[2],\n offset: 0\n };\n var end = to.line < cm.display.viewTo && posToDOM(cm, to);\n\n if (!end) {\n var measure = view[view.length - 1].measure;\n var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;\n end = {\n node: map[map.length - 1],\n offset: map[map.length - 2] - map[map.length - 3]\n };\n }\n\n if (!start || !end) {\n sel.removeAllRanges();\n return;\n }\n\n var old = sel.rangeCount && sel.getRangeAt(0),\n rng;\n\n try {\n rng = range(start.node, start.offset, end.offset, end.node);\n } catch (e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible\n\n\n if (rng) {\n if (!gecko && cm.state.focused) {\n sel.collapse(start.node, start.offset);\n\n if (!rng.collapsed) {\n sel.removeAllRanges();\n sel.addRange(rng);\n }\n } else {\n sel.removeAllRanges();\n sel.addRange(rng);\n }\n\n if (old && sel.anchorNode == null) {\n sel.addRange(old);\n } else if (gecko) {\n this.startGracePeriod();\n }\n }\n\n this.rememberSelection();\n };\n\n ContentEditableInput.prototype.startGracePeriod = function () {\n var this$1 = this;\n clearTimeout(this.gracePeriod);\n this.gracePeriod = setTimeout(function () {\n this$1.gracePeriod = false;\n\n if (this$1.selectionChanged()) {\n this$1.cm.operation(function () {\n return this$1.cm.curOp.selectionChanged = true;\n });\n }\n }, 20);\n };\n\n ContentEditableInput.prototype.showMultipleSelections = function (info) {\n removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);\n removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);\n };\n\n ContentEditableInput.prototype.rememberSelection = function () {\n var sel = this.getSelection();\n this.lastAnchorNode = sel.anchorNode;\n this.lastAnchorOffset = sel.anchorOffset;\n this.lastFocusNode = sel.focusNode;\n this.lastFocusOffset = sel.focusOffset;\n };\n\n ContentEditableInput.prototype.selectionInEditor = function () {\n var sel = this.getSelection();\n\n if (!sel.rangeCount) {\n return false;\n }\n\n var node = sel.getRangeAt(0).commonAncestorContainer;\n return contains(this.div, node);\n };\n\n ContentEditableInput.prototype.focus = function () {\n if (this.cm.options.readOnly != \"nocursor\") {\n if (!this.selectionInEditor() || document.activeElement != this.div) {\n this.showSelection(this.prepareSelection(), true);\n }\n\n this.div.focus();\n }\n };\n\n ContentEditableInput.prototype.blur = function () {\n this.div.blur();\n };\n\n ContentEditableInput.prototype.getField = function () {\n return this.div;\n };\n\n ContentEditableInput.prototype.supportsTouch = function () {\n return true;\n };\n\n ContentEditableInput.prototype.receivedFocus = function () {\n var input = this;\n\n if (this.selectionInEditor()) {\n this.pollSelection();\n } else {\n runInOp(this.cm, function () {\n return input.cm.curOp.selectionChanged = true;\n });\n }\n\n function poll() {\n if (input.cm.state.focused) {\n input.pollSelection();\n input.polling.set(input.cm.options.pollInterval, poll);\n }\n }\n\n this.polling.set(this.cm.options.pollInterval, poll);\n };\n\n ContentEditableInput.prototype.selectionChanged = function () {\n var sel = this.getSelection();\n return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset || sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset;\n };\n\n ContentEditableInput.prototype.pollSelection = function () {\n if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) {\n return;\n }\n\n var sel = this.getSelection(),\n cm = this.cm; // On Android Chrome (version 56, at least), backspacing into an\n // uneditable block element will put the cursor in that element,\n // and then, because it's not editable, hide the virtual keyboard.\n // Because Android doesn't allow us to actually detect backspace\n // presses in a sane way, this code checks for when that happens\n // and simulates a backspace press in this case.\n\n if (android && chrome && this.cm.display.gutterSpecs.length && isInGutter(sel.anchorNode)) {\n this.cm.triggerOnKeyDown({\n type: \"keydown\",\n keyCode: 8,\n preventDefault: Math.abs\n });\n this.blur();\n this.focus();\n return;\n }\n\n if (this.composing) {\n return;\n }\n\n this.rememberSelection();\n var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);\n var head = domToPos(cm, sel.focusNode, sel.focusOffset);\n\n if (anchor && head) {\n runInOp(cm, function () {\n setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);\n\n if (anchor.bad || head.bad) {\n cm.curOp.selectionChanged = true;\n }\n });\n }\n };\n\n ContentEditableInput.prototype.pollContent = function () {\n if (this.readDOMTimeout != null) {\n clearTimeout(this.readDOMTimeout);\n this.readDOMTimeout = null;\n }\n\n var cm = this.cm,\n display = cm.display,\n sel = cm.doc.sel.primary();\n var from = sel.from(),\n to = sel.to();\n\n if (from.ch == 0 && from.line > cm.firstLine()) {\n from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length);\n }\n\n if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine()) {\n to = Pos(to.line + 1, 0);\n }\n\n if (from.line < display.viewFrom || to.line > display.viewTo - 1) {\n return false;\n }\n\n var fromIndex, fromLine, fromNode;\n\n if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {\n fromLine = lineNo(display.view[0].line);\n fromNode = display.view[0].node;\n } else {\n fromLine = lineNo(display.view[fromIndex].line);\n fromNode = display.view[fromIndex - 1].node.nextSibling;\n }\n\n var toIndex = findViewIndex(cm, to.line);\n var toLine, toNode;\n\n if (toIndex == display.view.length - 1) {\n toLine = display.viewTo - 1;\n toNode = display.lineDiv.lastChild;\n } else {\n toLine = lineNo(display.view[toIndex + 1].line) - 1;\n toNode = display.view[toIndex + 1].node.previousSibling;\n }\n\n if (!fromNode) {\n return false;\n }\n\n var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));\n var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));\n\n while (newText.length > 1 && oldText.length > 1) {\n if (lst(newText) == lst(oldText)) {\n newText.pop();\n oldText.pop();\n toLine--;\n } else if (newText[0] == oldText[0]) {\n newText.shift();\n oldText.shift();\n fromLine++;\n } else {\n break;\n }\n }\n\n var cutFront = 0,\n cutEnd = 0;\n var newTop = newText[0],\n oldTop = oldText[0],\n maxCutFront = Math.min(newTop.length, oldTop.length);\n\n while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront)) {\n ++cutFront;\n }\n\n var newBot = lst(newText),\n oldBot = lst(oldText);\n var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0), oldBot.length - (oldText.length == 1 ? cutFront : 0));\n\n while (cutEnd < maxCutEnd && newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {\n ++cutEnd;\n } // Try to move start of change to start of selection if ambiguous\n\n\n if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {\n while (cutFront && cutFront > from.ch && newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {\n cutFront--;\n cutEnd++;\n }\n }\n\n newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\\u200b+/, \"\");\n newText[0] = newText[0].slice(cutFront).replace(/\\u200b+$/, \"\");\n var chFrom = Pos(fromLine, cutFront);\n var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);\n\n if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {\n _replaceRange(cm.doc, newText, chFrom, chTo, \"+input\");\n\n return true;\n }\n };\n\n ContentEditableInput.prototype.ensurePolled = function () {\n this.forceCompositionEnd();\n };\n\n ContentEditableInput.prototype.reset = function () {\n this.forceCompositionEnd();\n };\n\n ContentEditableInput.prototype.forceCompositionEnd = function () {\n if (!this.composing) {\n return;\n }\n\n clearTimeout(this.readDOMTimeout);\n this.composing = null;\n this.updateFromDOM();\n this.div.blur();\n this.div.focus();\n };\n\n ContentEditableInput.prototype.readFromDOMSoon = function () {\n var this$1 = this;\n\n if (this.readDOMTimeout != null) {\n return;\n }\n\n this.readDOMTimeout = setTimeout(function () {\n this$1.readDOMTimeout = null;\n\n if (this$1.composing) {\n if (this$1.composing.done) {\n this$1.composing = null;\n } else {\n return;\n }\n }\n\n this$1.updateFromDOM();\n }, 80);\n };\n\n ContentEditableInput.prototype.updateFromDOM = function () {\n var this$1 = this;\n\n if (this.cm.isReadOnly() || !this.pollContent()) {\n runInOp(this.cm, function () {\n return regChange(this$1.cm);\n });\n }\n };\n\n ContentEditableInput.prototype.setUneditable = function (node) {\n node.contentEditable = \"false\";\n };\n\n ContentEditableInput.prototype.onKeyPress = function (e) {\n if (e.charCode == 0 || this.composing) {\n return;\n }\n\n e.preventDefault();\n\n if (!this.cm.isReadOnly()) {\n operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);\n }\n };\n\n ContentEditableInput.prototype.readOnlyChanged = function (val) {\n this.div.contentEditable = String(val != \"nocursor\");\n };\n\n ContentEditableInput.prototype.onContextMenu = function () {};\n\n ContentEditableInput.prototype.resetPosition = function () {};\n\n ContentEditableInput.prototype.needsContentAttribute = true;\n\n function posToDOM(cm, pos) {\n var view = findViewForLine(cm, pos.line);\n\n if (!view || view.hidden) {\n return null;\n }\n\n var line = getLine(cm.doc, pos.line);\n var info = mapFromLineView(view, line, pos.line);\n var order = getOrder(line, cm.doc.direction),\n side = \"left\";\n\n if (order) {\n var partPos = getBidiPartAt(order, pos.ch);\n side = partPos % 2 ? \"right\" : \"left\";\n }\n\n var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);\n result.offset = result.collapse == \"right\" ? result.end : result.start;\n return result;\n }\n\n function isInGutter(node) {\n for (var scan = node; scan; scan = scan.parentNode) {\n if (/CodeMirror-gutter-wrapper/.test(scan.className)) {\n return true;\n }\n }\n\n return false;\n }\n\n function badPos(pos, bad) {\n if (bad) {\n pos.bad = true;\n }\n\n return pos;\n }\n\n function domTextBetween(cm, from, to, fromLine, toLine) {\n var text = \"\",\n closing = false,\n lineSep = cm.doc.lineSeparator(),\n extraLinebreak = false;\n\n function recognizeMarker(id) {\n return function (marker) {\n return marker.id == id;\n };\n }\n\n function close() {\n if (closing) {\n text += lineSep;\n\n if (extraLinebreak) {\n text += lineSep;\n }\n\n closing = extraLinebreak = false;\n }\n }\n\n function addText(str) {\n if (str) {\n close();\n text += str;\n }\n }\n\n function walk(node) {\n if (node.nodeType == 1) {\n var cmText = node.getAttribute(\"cm-text\");\n\n if (cmText) {\n addText(cmText);\n return;\n }\n\n var markerID = node.getAttribute(\"cm-marker\"),\n range;\n\n if (markerID) {\n var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));\n\n if (found.length && (range = found[0].find(0))) {\n addText(getBetween(cm.doc, range.from, range.to).join(lineSep));\n }\n\n return;\n }\n\n if (node.getAttribute(\"contenteditable\") == \"false\") {\n return;\n }\n\n var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);\n\n if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) {\n return;\n }\n\n if (isBlock) {\n close();\n }\n\n for (var i = 0; i < node.childNodes.length; i++) {\n walk(node.childNodes[i]);\n }\n\n if (/^(pre|p)$/i.test(node.nodeName)) {\n extraLinebreak = true;\n }\n\n if (isBlock) {\n closing = true;\n }\n } else if (node.nodeType == 3) {\n addText(node.nodeValue.replace(/\\u200b/g, \"\").replace(/\\u00a0/g, \" \"));\n }\n }\n\n for (;;) {\n walk(from);\n\n if (from == to) {\n break;\n }\n\n from = from.nextSibling;\n extraLinebreak = false;\n }\n\n return text;\n }\n\n function domToPos(cm, node, offset) {\n var lineNode;\n\n if (node == cm.display.lineDiv) {\n lineNode = cm.display.lineDiv.childNodes[offset];\n\n if (!lineNode) {\n return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);\n }\n\n node = null;\n offset = 0;\n } else {\n for (lineNode = node;; lineNode = lineNode.parentNode) {\n if (!lineNode || lineNode == cm.display.lineDiv) {\n return null;\n }\n\n if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) {\n break;\n }\n }\n }\n\n for (var i = 0; i < cm.display.view.length; i++) {\n var lineView = cm.display.view[i];\n\n if (lineView.node == lineNode) {\n return locateNodeInLineView(lineView, node, offset);\n }\n }\n }\n\n function locateNodeInLineView(lineView, node, offset) {\n var wrapper = lineView.text.firstChild,\n bad = false;\n\n if (!node || !contains(wrapper, node)) {\n return badPos(Pos(lineNo(lineView.line), 0), true);\n }\n\n if (node == wrapper) {\n bad = true;\n node = wrapper.childNodes[offset];\n offset = 0;\n\n if (!node) {\n var line = lineView.rest ? lst(lineView.rest) : lineView.line;\n return badPos(Pos(lineNo(line), line.text.length), bad);\n }\n }\n\n var textNode = node.nodeType == 3 ? node : null,\n topNode = node;\n\n if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {\n textNode = node.firstChild;\n\n if (offset) {\n offset = textNode.nodeValue.length;\n }\n }\n\n while (topNode.parentNode != wrapper) {\n topNode = topNode.parentNode;\n }\n\n var measure = lineView.measure,\n maps = measure.maps;\n\n function find(textNode, topNode, offset) {\n for (var i = -1; i < (maps ? maps.length : 0); i++) {\n var map = i < 0 ? measure.map : maps[i];\n\n for (var j = 0; j < map.length; j += 3) {\n var curNode = map[j + 2];\n\n if (curNode == textNode || curNode == topNode) {\n var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);\n var ch = map[j] + offset;\n\n if (offset < 0 || curNode != textNode) {\n ch = map[j + (offset ? 1 : 0)];\n }\n\n return Pos(line, ch);\n }\n }\n }\n }\n\n var found = find(textNode, topNode, offset);\n\n if (found) {\n return badPos(found, bad);\n } // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems\n\n\n for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {\n found = find(after, after.firstChild, 0);\n\n if (found) {\n return badPos(Pos(found.line, found.ch - dist), bad);\n } else {\n dist += after.textContent.length;\n }\n }\n\n for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {\n found = find(before, before.firstChild, -1);\n\n if (found) {\n return badPos(Pos(found.line, found.ch + dist$1), bad);\n } else {\n dist$1 += before.textContent.length;\n }\n }\n } // TEXTAREA INPUT STYLE\n\n\n var TextareaInput = function TextareaInput(cm) {\n this.cm = cm; // See input.poll and input.reset\n\n this.prevInput = \"\"; // Flag that indicates whether we expect input to appear real soon\n // now (after some event like 'keypress' or 'input') and are\n // polling intensively.\n\n this.pollingFast = false; // Self-resetting timeout for the poller\n\n this.polling = new Delayed(); // Used to work around IE issue with selection being forgotten when focus moves away from textarea\n\n this.hasSelection = false;\n this.composing = null;\n };\n\n TextareaInput.prototype.init = function (display) {\n var this$1 = this;\n var input = this,\n cm = this.cm;\n this.createField(display);\n var te = this.textarea;\n display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild); // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)\n\n if (ios) {\n te.style.width = \"0px\";\n }\n\n on(te, \"input\", function () {\n if (ie && ie_version >= 9 && this$1.hasSelection) {\n this$1.hasSelection = null;\n }\n\n input.poll();\n });\n on(te, \"paste\", function (e) {\n if (signalDOMEvent(cm, e) || handlePaste(e, cm)) {\n return;\n }\n\n cm.state.pasteIncoming = +new Date();\n input.fastPoll();\n });\n\n function prepareCopyCut(e) {\n if (signalDOMEvent(cm, e)) {\n return;\n }\n\n if (cm.somethingSelected()) {\n setLastCopied({\n lineWise: false,\n text: cm.getSelections()\n });\n } else if (!cm.options.lineWiseCopyCut) {\n return;\n } else {\n var ranges = copyableRanges(cm);\n setLastCopied({\n lineWise: true,\n text: ranges.text\n });\n\n if (e.type == \"cut\") {\n cm.setSelections(ranges.ranges, null, sel_dontScroll);\n } else {\n input.prevInput = \"\";\n te.value = ranges.text.join(\"\\n\");\n selectInput(te);\n }\n }\n\n if (e.type == \"cut\") {\n cm.state.cutIncoming = +new Date();\n }\n }\n\n on(te, \"cut\", prepareCopyCut);\n on(te, \"copy\", prepareCopyCut);\n on(display.scroller, \"paste\", function (e) {\n if (eventInWidget(display, e) || signalDOMEvent(cm, e)) {\n return;\n }\n\n if (!te.dispatchEvent) {\n cm.state.pasteIncoming = +new Date();\n input.focus();\n return;\n } // Pass the `paste` event to the textarea so it's handled by its event listener.\n\n\n var event = new Event(\"paste\");\n event.clipboardData = e.clipboardData;\n te.dispatchEvent(event);\n }); // Prevent normal selection in the editor (we handle our own)\n\n on(display.lineSpace, \"selectstart\", function (e) {\n if (!eventInWidget(display, e)) {\n e_preventDefault(e);\n }\n });\n on(te, \"compositionstart\", function () {\n var start = cm.getCursor(\"from\");\n\n if (input.composing) {\n input.composing.range.clear();\n }\n\n input.composing = {\n start: start,\n range: cm.markText(start, cm.getCursor(\"to\"), {\n className: \"CodeMirror-composing\"\n })\n };\n });\n on(te, \"compositionend\", function () {\n if (input.composing) {\n input.poll();\n input.composing.range.clear();\n input.composing = null;\n }\n });\n };\n\n TextareaInput.prototype.createField = function (_display) {\n // Wraps and hides input textarea\n this.wrapper = hiddenTextarea(); // The semihidden textarea that is focused when the editor is\n // focused, and receives input.\n\n this.textarea = this.wrapper.firstChild;\n };\n\n TextareaInput.prototype.screenReaderLabelChanged = function (label) {\n // Label for screenreaders, accessibility\n if (label) {\n this.textarea.setAttribute('aria-label', label);\n } else {\n this.textarea.removeAttribute('aria-label');\n }\n };\n\n TextareaInput.prototype.prepareSelection = function () {\n // Redraw the selection and/or cursor\n var cm = this.cm,\n display = cm.display,\n doc = cm.doc;\n var result = prepareSelection(cm); // Move the hidden textarea near the cursor to prevent scrolling artifacts\n\n if (cm.options.moveInputWithCursor) {\n var headPos = _cursorCoords(cm, doc.sel.primary().head, \"div\");\n\n var wrapOff = display.wrapper.getBoundingClientRect(),\n lineOff = display.lineDiv.getBoundingClientRect();\n result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10, headPos.top + lineOff.top - wrapOff.top));\n result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10, headPos.left + lineOff.left - wrapOff.left));\n }\n\n return result;\n };\n\n TextareaInput.prototype.showSelection = function (drawn) {\n var cm = this.cm,\n display = cm.display;\n removeChildrenAndAdd(display.cursorDiv, drawn.cursors);\n removeChildrenAndAdd(display.selectionDiv, drawn.selection);\n\n if (drawn.teTop != null) {\n this.wrapper.style.top = drawn.teTop + \"px\";\n this.wrapper.style.left = drawn.teLeft + \"px\";\n }\n }; // Reset the input to correspond to the selection (or to be empty,\n // when not typing and nothing is selected)\n\n\n TextareaInput.prototype.reset = function (typing) {\n if (this.contextMenuPending || this.composing) {\n return;\n }\n\n var cm = this.cm;\n\n if (cm.somethingSelected()) {\n this.prevInput = \"\";\n var content = cm.getSelection();\n this.textarea.value = content;\n\n if (cm.state.focused) {\n selectInput(this.textarea);\n }\n\n if (ie && ie_version >= 9) {\n this.hasSelection = content;\n }\n } else if (!typing) {\n this.prevInput = this.textarea.value = \"\";\n\n if (ie && ie_version >= 9) {\n this.hasSelection = null;\n }\n }\n };\n\n TextareaInput.prototype.getField = function () {\n return this.textarea;\n };\n\n TextareaInput.prototype.supportsTouch = function () {\n return false;\n };\n\n TextareaInput.prototype.focus = function () {\n if (this.cm.options.readOnly != \"nocursor\" && (!mobile || activeElt() != this.textarea)) {\n try {\n this.textarea.focus();\n } catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM\n\n }\n };\n\n TextareaInput.prototype.blur = function () {\n this.textarea.blur();\n };\n\n TextareaInput.prototype.resetPosition = function () {\n this.wrapper.style.top = this.wrapper.style.left = 0;\n };\n\n TextareaInput.prototype.receivedFocus = function () {\n this.slowPoll();\n }; // Poll for input changes, using the normal rate of polling. This\n // runs as long as the editor is focused.\n\n\n TextareaInput.prototype.slowPoll = function () {\n var this$1 = this;\n\n if (this.pollingFast) {\n return;\n }\n\n this.polling.set(this.cm.options.pollInterval, function () {\n this$1.poll();\n\n if (this$1.cm.state.focused) {\n this$1.slowPoll();\n }\n });\n }; // When an event has just come in that is likely to add or change\n // something in the input textarea, we poll faster, to ensure that\n // the change appears on the screen quickly.\n\n\n TextareaInput.prototype.fastPoll = function () {\n var missed = false,\n input = this;\n input.pollingFast = true;\n\n function p() {\n var changed = input.poll();\n\n if (!changed && !missed) {\n missed = true;\n input.polling.set(60, p);\n } else {\n input.pollingFast = false;\n input.slowPoll();\n }\n }\n\n input.polling.set(20, p);\n }; // Read input from the textarea, and update the document to match.\n // When something is selected, it is present in the textarea, and\n // selected (unless it is huge, in which case a placeholder is\n // used). When nothing is selected, the cursor sits after previously\n // seen text (can be empty), which is stored in prevInput (we must\n // not reset the textarea when typing, because that breaks IME).\n\n\n TextareaInput.prototype.poll = function () {\n var this$1 = this;\n var cm = this.cm,\n input = this.textarea,\n prevInput = this.prevInput; // Since this is called a *lot*, try to bail out as cheaply as\n // possible when it is clear that nothing happened. hasSelection\n // will be the case when there is a lot of text in the textarea,\n // in which case reading its value would be expensive.\n\n if (this.contextMenuPending || !cm.state.focused || hasSelection(input) && !prevInput && !this.composing || cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq) {\n return false;\n }\n\n var text = input.value; // If nothing changed, bail.\n\n if (text == prevInput && !cm.somethingSelected()) {\n return false;\n } // Work around nonsensical selection resetting in IE9/10, and\n // inexplicable appearance of private area unicode characters on\n // some key combos in Mac (#2689).\n\n\n if (ie && ie_version >= 9 && this.hasSelection === text || mac && /[\\uf700-\\uf7ff]/.test(text)) {\n cm.display.input.reset();\n return false;\n }\n\n if (cm.doc.sel == cm.display.selForContextMenu) {\n var first = text.charCodeAt(0);\n\n if (first == 0x200b && !prevInput) {\n prevInput = \"\\u200B\";\n }\n\n if (first == 0x21da) {\n this.reset();\n return this.cm.execCommand(\"undo\");\n }\n } // Find the part of the input that is actually new\n\n\n var same = 0,\n l = Math.min(prevInput.length, text.length);\n\n while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) {\n ++same;\n }\n\n runInOp(cm, function () {\n applyTextInput(cm, text.slice(same), prevInput.length - same, null, this$1.composing ? \"*compose\" : null); // Don't leave long text in the textarea, since it makes further polling slow\n\n if (text.length > 1000 || text.indexOf(\"\\n\") > -1) {\n input.value = this$1.prevInput = \"\";\n } else {\n this$1.prevInput = text;\n }\n\n if (this$1.composing) {\n this$1.composing.range.clear();\n this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor(\"to\"), {\n className: \"CodeMirror-composing\"\n });\n }\n });\n return true;\n };\n\n TextareaInput.prototype.ensurePolled = function () {\n if (this.pollingFast && this.poll()) {\n this.pollingFast = false;\n }\n };\n\n TextareaInput.prototype.onKeyPress = function () {\n if (ie && ie_version >= 9) {\n this.hasSelection = null;\n }\n\n this.fastPoll();\n };\n\n TextareaInput.prototype.onContextMenu = function (e) {\n var input = this,\n cm = input.cm,\n display = cm.display,\n te = input.textarea;\n\n if (input.contextMenuPending) {\n input.contextMenuPending();\n }\n\n var pos = posFromMouse(cm, e),\n scrollPos = display.scroller.scrollTop;\n\n if (!pos || presto) {\n return;\n } // Opera is difficult.\n // Reset the current text selection only if the click is done outside of the selection\n // and 'resetSelectionOnContextMenu' option is true.\n\n\n var reset = cm.options.resetSelectionOnContextMenu;\n\n if (reset && cm.doc.sel.contains(pos) == -1) {\n operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);\n }\n\n var oldCSS = te.style.cssText,\n oldWrapperCSS = input.wrapper.style.cssText;\n var wrapperBox = input.wrapper.offsetParent.getBoundingClientRect();\n input.wrapper.style.cssText = \"position: static\";\n 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);\";\n var oldScrollY;\n\n if (webkit) {\n oldScrollY = window.scrollY;\n } // Work around Chrome issue (#2712)\n\n\n display.input.focus();\n\n if (webkit) {\n window.scrollTo(null, oldScrollY);\n }\n\n display.input.reset(); // Adds \"Select all\" to context menu in FF\n\n if (!cm.somethingSelected()) {\n te.value = input.prevInput = \" \";\n }\n\n input.contextMenuPending = rehide;\n display.selForContextMenu = cm.doc.sel;\n clearTimeout(display.detectingSelectAll); // Select-all will be greyed out if there's nothing to select, so\n // this adds a zero-width space so that we can later check whether\n // it got selected.\n\n function prepareSelectAllHack() {\n if (te.selectionStart != null) {\n var selected = cm.somethingSelected();\n var extval = \"\\u200B\" + (selected ? te.value : \"\");\n te.value = \"\\u21DA\"; // Used to catch context-menu undo\n\n te.value = extval;\n input.prevInput = selected ? \"\" : \"\\u200B\";\n te.selectionStart = 1;\n te.selectionEnd = extval.length; // Re-set this, in case some other handler touched the\n // selection in the meantime.\n\n display.selForContextMenu = cm.doc.sel;\n }\n }\n\n function rehide() {\n if (input.contextMenuPending != rehide) {\n return;\n }\n\n input.contextMenuPending = false;\n input.wrapper.style.cssText = oldWrapperCSS;\n te.style.cssText = oldCSS;\n\n if (ie && ie_version < 9) {\n display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos);\n } // Try to detect the user choosing select-all\n\n\n if (te.selectionStart != null) {\n if (!ie || ie && ie_version < 9) {\n prepareSelectAllHack();\n }\n\n var i = 0,\n poll = function poll() {\n if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 && te.selectionEnd > 0 && input.prevInput == \"\\u200B\") {\n operation(cm, selectAll)(cm);\n } else if (i++ < 10) {\n display.detectingSelectAll = setTimeout(poll, 500);\n } else {\n display.selForContextMenu = null;\n display.input.reset();\n }\n };\n\n display.detectingSelectAll = setTimeout(poll, 200);\n }\n }\n\n if (ie && ie_version >= 9) {\n prepareSelectAllHack();\n }\n\n if (captureRightClick) {\n e_stop(e);\n\n var mouseup = function mouseup() {\n off(window, \"mouseup\", mouseup);\n setTimeout(rehide, 20);\n };\n\n on(window, \"mouseup\", mouseup);\n } else {\n setTimeout(rehide, 50);\n }\n };\n\n TextareaInput.prototype.readOnlyChanged = function (val) {\n if (!val) {\n this.reset();\n }\n\n this.textarea.disabled = val == \"nocursor\";\n this.textarea.readOnly = !!val;\n };\n\n TextareaInput.prototype.setUneditable = function () {};\n\n TextareaInput.prototype.needsContentAttribute = false;\n\n function fromTextArea(textarea, options) {\n options = options ? copyObj(options) : {};\n options.value = textarea.value;\n\n if (!options.tabindex && textarea.tabIndex) {\n options.tabindex = textarea.tabIndex;\n }\n\n if (!options.placeholder && textarea.placeholder) {\n options.placeholder = textarea.placeholder;\n } // Set autofocus to true if this textarea is focused, or if it has\n // autofocus and no other element is focused.\n\n\n if (options.autofocus == null) {\n var hasFocus = activeElt();\n options.autofocus = hasFocus == textarea || textarea.getAttribute(\"autofocus\") != null && hasFocus == document.body;\n }\n\n function save() {\n textarea.value = cm.getValue();\n }\n\n var realSubmit;\n\n if (textarea.form) {\n on(textarea.form, \"submit\", save); // Deplorable hack to make the submit method do the right thing.\n\n if (!options.leaveSubmitMethodAlone) {\n var form = textarea.form;\n realSubmit = form.submit;\n\n try {\n var wrappedSubmit = form.submit = function () {\n save();\n form.submit = realSubmit;\n form.submit();\n form.submit = wrappedSubmit;\n };\n } catch (e) {}\n }\n }\n\n options.finishInit = function (cm) {\n cm.save = save;\n\n cm.getTextArea = function () {\n return textarea;\n };\n\n cm.toTextArea = function () {\n cm.toTextArea = isNaN; // Prevent this from being ran twice\n\n save();\n textarea.parentNode.removeChild(cm.getWrapperElement());\n textarea.style.display = \"\";\n\n if (textarea.form) {\n off(textarea.form, \"submit\", save);\n\n if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == \"function\") {\n textarea.form.submit = realSubmit;\n }\n }\n };\n };\n\n textarea.style.display = \"none\";\n var cm = CodeMirror(function (node) {\n return textarea.parentNode.insertBefore(node, textarea.nextSibling);\n }, options);\n return cm;\n }\n\n function addLegacyProps(CodeMirror) {\n CodeMirror.off = off;\n CodeMirror.on = on;\n CodeMirror.wheelEventPixels = wheelEventPixels;\n CodeMirror.Doc = Doc;\n CodeMirror.splitLines = splitLinesAuto;\n CodeMirror.countColumn = countColumn;\n CodeMirror.findColumn = findColumn;\n CodeMirror.isWordChar = isWordCharBasic;\n CodeMirror.Pass = Pass;\n CodeMirror.signal = signal;\n CodeMirror.Line = Line;\n CodeMirror.changeEnd = changeEnd;\n CodeMirror.scrollbarModel = scrollbarModel;\n CodeMirror.Pos = Pos;\n CodeMirror.cmpPos = cmp;\n CodeMirror.modes = modes;\n CodeMirror.mimeModes = mimeModes;\n CodeMirror.resolveMode = resolveMode;\n CodeMirror.getMode = getMode;\n CodeMirror.modeExtensions = modeExtensions;\n CodeMirror.extendMode = extendMode;\n CodeMirror.copyState = copyState;\n CodeMirror.startState = startState;\n CodeMirror.innerMode = innerMode;\n CodeMirror.commands = commands;\n CodeMirror.keyMap = keyMap;\n CodeMirror.keyName = keyName;\n CodeMirror.isModifierKey = isModifierKey;\n CodeMirror.lookupKey = lookupKey;\n CodeMirror.normalizeKeyMap = normalizeKeyMap;\n CodeMirror.StringStream = StringStream;\n CodeMirror.SharedTextMarker = SharedTextMarker;\n CodeMirror.TextMarker = TextMarker;\n CodeMirror.LineWidget = LineWidget;\n CodeMirror.e_preventDefault = e_preventDefault;\n CodeMirror.e_stopPropagation = e_stopPropagation;\n CodeMirror.e_stop = e_stop;\n CodeMirror.addClass = addClass;\n CodeMirror.contains = contains;\n CodeMirror.rmClass = rmClass;\n CodeMirror.keyNames = keyNames;\n } // EDITOR CONSTRUCTOR\n\n\n defineOptions(CodeMirror);\n addEditorMethods(CodeMirror); // Set up methods on CodeMirror's prototype to redirect to the editor's document.\n\n var dontDelegate = \"iter insert remove copy getEditor constructor\".split(\" \");\n\n for (var prop in Doc.prototype) {\n if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0) {\n CodeMirror.prototype[prop] = function (method) {\n return function () {\n return method.apply(this.doc, arguments);\n };\n }(Doc.prototype[prop]);\n }\n }\n\n eventMixin(Doc);\n CodeMirror.inputStyles = {\n \"textarea\": TextareaInput,\n \"contenteditable\": ContentEditableInput\n }; // Extra arguments are stored as the mode's dependencies, which is\n // used by (legacy) mechanisms like loadmode.js to automatically\n // load a mode. (Preferred mechanism is the require/define calls.)\n\n CodeMirror.defineMode = function (name\n /*, mode, …*/\n ) {\n if (!CodeMirror.defaults.mode && name != \"null\") {\n CodeMirror.defaults.mode = name;\n }\n\n defineMode.apply(this, arguments);\n };\n\n CodeMirror.defineMIME = defineMIME; // Minimal default mode.\n\n CodeMirror.defineMode(\"null\", function () {\n return {\n token: function token(stream) {\n return stream.skipToEnd();\n }\n };\n });\n CodeMirror.defineMIME(\"text/plain\", \"null\"); // EXTENSIONS\n\n CodeMirror.defineExtension = function (name, func) {\n CodeMirror.prototype[name] = func;\n };\n\n CodeMirror.defineDocExtension = function (name, func) {\n Doc.prototype[name] = func;\n };\n\n CodeMirror.fromTextArea = fromTextArea;\n addLegacyProps(CodeMirror);\n CodeMirror.version = \"5.58.1\";\n return CodeMirror;\n});","module.exports = function (module) {\n if (!module.webpackPolyfill) {\n module.deprecate = function () {};\n\n module.paths = []; // module.parent = undefined by default\n\n if (!module.children) module.children = [];\n Object.defineProperty(module, \"loaded\", {\n enumerable: true,\n get: function get() {\n return module.l;\n }\n });\n Object.defineProperty(module, \"id\", {\n enumerable: true,\n get: function get() {\n return module.i;\n }\n });\n module.webpackPolyfill = 1;\n }\n\n return module;\n};","import Paginate from 'vuejs-paginate'\nimport Vue from 'vue/dist/vue.esm'\nimport kebabCase from 'lodash/kebabCase'\n\nVue.component('paginate', Paginate)\n\n// Fields\nVue.component('index-field-wrapper', require('@/js/components/Index/FieldWrapper.vue').default)\nVue.component('index-id-field', require('@/js/components/Index/IdField.vue').default)\nVue.component('index-text-field', require('@/js/components/Index/TextField.vue').default)\nVue.component('index-textarea-field', require('@/js/components/Index/TextareaField.vue').default)\nVue.component('index-number-field', require('@/js/components/Index/NumberField.vue').default)\nVue.component('index-boolean-field', require('@/js/components/Index/BooleanField.vue').default)\nVue.component('index-select-field', require('@/js/components/Index/SelectField.vue').default)\nVue.component('index-datetime-field', require('@/js/components/Index/DatetimeField.vue').default)\nVue.component('index-file-field', require('@/js/components/Index/FileField.vue').default)\nVue.component('index-files-field', require('@/js/components/Index/FilesField.vue').default)\nVue.component('index-boolean-group-field', require('@/js/components/Index/BooleanGroupField.vue').default)\nVue.component('index-belongs-to-field', require('@/js/components/Index/BelongsTo.vue').default)\nVue.component('index-has-one-field', require('@/js/components/Index/HasOne.vue').default)\nVue.component('index-status-field', require('@/js/components/Index/StatusField.vue').default)\nVue.component('index-currency-field', require('@/js/components/Index/CurrencyField.vue').default)\nVue.component('index-gravatar-field', require('@/js/components/Index/GravatarField.vue').default)\nVue.component('index-country-field', require('@/js/components/Index/CountryField.vue').default)\nVue.component('index-badge-field', require('@/js/components/Index/BadgeField.vue').default)\n\nVue.component('show-field-wrapper', require('@/js/components/Show/FieldWrapper.vue').default)\nVue.component('show-id-field', require('@/js/components/Show/IdField.vue').default)\nVue.component('show-text-field', require('@/js/components/Show/TextField.vue').default)\nVue.component('show-textarea-field', require('@/js/components/Show/TextareaField.vue').default)\nVue.component('show-password-field', require('@/js/components/Show/PasswordField.vue').default)\nVue.component('show-number-field', require('@/js/components/Show/NumberField.vue').default)\nVue.component('show-boolean-field', require('@/js/components/Show/BooleanField.vue').default)\nVue.component('show-select-field', require('@/js/components/Show/SelectField.vue').default)\nVue.component('show-datetime-field', require('@/js/components/Show/DatetimeField.vue').default)\nVue.component('show-file-field', require('@/js/components/Show/FileField.vue').default)\nVue.component('show-files-field', require('@/js/components/Show/FilesField.vue').default)\nVue.component('show-key-value-field', require('@/js/components/Show/KeyValueField.vue').default)\nVue.component('show-boolean-group-field', require('@/js/components/Show/BooleanGroupField.vue').default)\nVue.component('show-belongs-to-field', require('@/js/components/Show/BelongsTo.vue').default)\nVue.component('show-has-one-field', require('@/js/components/Show/HasOne.vue').default)\nVue.component('show-has-many-field', require('@/js/components/Show/HasMany.vue').default)\nVue.component('show-status-field', require('@/js/components/Show/StatusField.vue').default)\nVue.component('show-currency-field', require('@/js/components/Show/CurrencyField.vue').default)\nVue.component('show-gravatar-field', require('@/js/components/Show/GravatarField.vue').default)\nVue.component('show-country-field', require('@/js/components/Show/CountryField.vue').default)\nVue.component('show-badge-field', require('@/js/components/Show/BadgeField.vue').default)\nVue.component('show-heading-field', require('@/js/components/Show/HeadingField.vue').default)\nVue.component('show-code-field', require('@/js/components/Show/CodeField.vue').default)\nVue.component('show-markdown-field', require('@/js/components/Show/MarkdownField.vue').default)\nVue.component('show-trix-field', require('@/js/components/Show/TrixField.vue').default)\n\nVue.component('edit-field-wrapper', require('@/js/components/Edit/FieldWrapper.vue').default)\nVue.component('edit-id-field', require('@/js/components/Edit/IdField.vue').default)\nVue.component('edit-text-field', require('@/js/components/Edit/TextField.vue').default)\nVue.component('edit-textarea-field', require('@/js/components/Edit/TextareaField.vue').default)\nVue.component('edit-password-field', require('@/js/components/Edit/PasswordField.vue').default)\nVue.component('edit-number-field', require('@/js/components/Edit/NumberField.vue').default)\nVue.component('edit-boolean-field', require('@/js/components/Edit/BooleanField.vue').default)\nVue.component('edit-select-field', require('@/js/components/Edit/SelectField.vue').default)\nVue.component('edit-datetime-field', require('@/js/components/Edit/DatetimeField.vue').default)\nVue.component('edit-file-field', require('@/js/components/Edit/FileField.vue').default)\nVue.component('edit-files-field', require('@/js/components/Edit/FilesField.vue').default)\nVue.component('edit-key-value-field', require('@/js/components/Edit/KeyValueField.vue').default)\nVue.component('edit-boolean-group-field', require('@/js/components/Edit/BooleanGroupField.vue').default)\nVue.component('edit-belongs-to-field', require('@/js/components/Edit/BelongsTo.vue').default)\nVue.component('edit-has-one-field', require('@/js/components/Edit/HasOne.vue').default)\nVue.component('edit-status-field', require('@/js/components/Edit/StatusField.vue').default)\nVue.component('edit-currency-field', require('@/js/components/Edit/CurrencyField.vue').default)\nVue.component('edit-country-field', require('@/js/components/Edit/CountryField.vue').default)\nVue.component('edit-heading-field', require('@/js/components/Show/HeadingField.vue').default)\nVue.component('edit-code-field', require('@/js/components/Edit/CodeField.vue').default)\nVue.component('edit-hidden-field', require('@/js/components/Edit/HiddenField.vue').default)\nVue.component('edit-markdown-field', require('@/js/components/Edit/MarkdownField.vue').default)\nVue.component('edit-trix-field', require('@/js/components/Edit/TrixField.vue').default)\n\n// Form Fields\nVue.component('input-component', require('@/js/components/InputComponent.vue').default)\n\n/* View Components */\n// Table\nVue.component('resource-table', require('@/js/components/Index/TableView/ResourceTable.vue').default)\nVue.component('table-row', require('@/js/components/Index/TableView/TableRow.vue').default)\nVue.component('table-header-cell', require('@/js/components/Index/TableView/TableHeaderCell.vue').default)\n\n// Grid\nVue.component('resource-grid', require('@/js/components/Index/GridView/ResourceGrid.vue').default)\nVue.component('grid-item', require('@/js/components/Index/GridView/GridItem.vue').default)\n\n// Common\nVue.component('item-controls', require('@/js/components/Index/ItemControls.vue').default)\n\n// Components\nVue.component('view-header', require('@/js/components/ViewHeader.vue').default)\nVue.component('view-footer', require('@/js/components/ViewFooter.vue').default)\nVue.component('panel', require('@/js/components/Panel.vue').default)\nVue.component('pane', require('@/js/components/Pane.vue').default)\nVue.component('resource-overview', require('@/js/components/ResourceOverview.vue').default)\nVue.component('heading', require('@/js/components/Heading.vue').default)\nVue.component('a-button', require('@/js/components/Button.vue').default)\nVue.component('resources-search', require('@/js/components/ResourcesSearch.vue').default)\nVue.component('loading-component', require('@/js/components/LoadingComponent.vue').default)\nVue.component('loading-overlay', require('@/js/components/LoadingOverlay.vue').default)\nVue.component('empty-dash', require('@/js/components/EmptyDash.vue').default)\nVue.component('empty-state', require('@/js/components/EmptyState.vue').default)\n\n// Filters\nVue.component('resource-filters', require('@/js/components/Index/ResourceFilters.vue').default)\nVue.component('resource-actions', require('@/js/components/ResourceActions.vue').default)\nVue.component('boolean-filter', require('@/js/components/Index/Filters/BooleanFilter.vue').default)\nVue.component('select-filter', require('@/js/components/Index/Filters/SelectFilter.vue').default)\nVue.component('filter-wrapper', require('@/js/components/Index/Filters/FilterWrapper.vue').default)\n\n// Sidebar\nVue.component('resources-navigation', require('@/js/components/ResourcesNavigation.vue').default)\nVue.component('sidebar-link', require('@/js/components/SidebarLink.vue').default)\nVue.component('application-sidebar', require('@/js/components/ApplicationSidebar.vue').default)\nVue.component('logo-component', require('@/js/components/LogoComponent.vue').default)\nVue.component('license-warnings', require('@/js/components/LicenseWarnings.vue').default)\nVue.component('license-warning', require('@/js/components/LicenseWarning.vue').default)\n\n// Views\nVue.component('resources-index', require('@/js/views/ResourceIndex.vue').default)\n\n// Layouts\nVue.component('app-layout', require('@/js/views/AppLayout.vue').default)\n\n// Icons are self imported as ICON_NAME-icon components\n// thumbs-up.svg ->
\nconst requireComponent = require.context('@/svgs/', false, /.*\\.svg$/im)\nrequireComponent.keys().forEach((fileName) => {\n // Get kebab-case name of component\n const iconName = kebabCase(\n // Gets the file name regardless of folder depth\n fileName\n .split('/')\n .pop()\n .replace(/\\.\\w+$/, ''),\n )\n const componentName = `${iconName}-icon`\n /* eslint-disable global-require */\n // eslint-disable-next-line import/no-dynamic-require\n const componentConfig = require(`@/svgs/${iconName}.svg?inline`)\n /* eslint-enable global-require */\n\n Vue.component(componentName, componentConfig)\n})\n","const initialState = {\n availableResources: [],\n}\n\nconst mutations = {\n setAvailableResources(state, availableResources) {\n state.availableResources = availableResources\n },\n}\n\nconst actions = {}\n\nconst store = {\n namespaced: true,\n state: initialState,\n mutations,\n actions,\n}\n\nexport default store\n","const initialState = {\n selectedResources: [],\n}\n\nconst mutations = {\n updateSelection(state, resource) {\n const currentIndex = state.selectedResources.indexOf(resource.id)\n const itemSelected = currentIndex !== -1\n\n if (itemSelected) {\n state.selectedResources.splice(currentIndex, 1)\n } else {\n state.selectedResources.push(resource.id)\n }\n },\n clearSelectedResources(state) {\n state.selectedResources = []\n },\n}\n\nconst actions = {}\n\nconst store = {\n namespaced: true,\n state: initialState,\n mutations,\n actions,\n}\n\nexport default store\n","import '@/js/components'\nimport Api from '@/js/Api'\nimport Bus from '@/js/Bus'\nimport I18n from 'i18n-js'\nimport PortalVue from 'portal-vue'\nimport Toasted from 'vue-toasted'\nimport VModal from 'vue-js-modal'\nimport VTooltip from 'v-tooltip'\nimport Vue from 'vue/dist/vue.esm'\nimport VueCurrencyInput from 'vue-currency-input'\nimport VueRouter from 'vue-router'\nimport Vuex, { mapMutations } from 'vuex'\n\nimport appStore from '@/js/stores/app-store'\nimport indexStore from '@/js/stores/index-store'\nimport router from '@/js/router'\n\nconst Avo = {\n Bus,\n Api,\n env: '',\n rootPath: window.rootPath || '/avo',\n\n init() {\n Avo.env = window.env || 'production'\n if (document.getElementById('app')) {\n Avo.initVue()\n }\n },\n\n reload() {\n this.vue.reload()\n },\n\n redirect(path) {\n this.vue.redirect(path)\n },\n\n alert(message, messageType) {\n this.vue.alert(message, messageType)\n },\n\n store() {\n return new Vuex.Store({\n modules: {\n index: indexStore,\n app: appStore,\n },\n })\n },\n\n initPlugins() {\n Vue.use(Toasted, {\n duration: 5000,\n keepOnHover: true,\n position: 'bottom-right',\n closeOnSwipe: true,\n })\n\n Vue.use(VTooltip)\n Vue.use(VueRouter)\n Vue.use(VueCurrencyInput)\n Vue.use(VModal, {\n dynamic: true,\n injectModalsContainer: false,\n dynamicDefaults: {\n adaptive: true,\n height: 'auto',\n minHeight: 250,\n width: 550,\n styles: 'border-radius: 1rem',\n },\n })\n Vue.use(PortalVue)\n Vue.use(Vuex)\n\n // Custom i18n plugin\n Vue.use({\n install(Vue) {\n Vue.prototype.$t = (key, options) => I18n.t(key, options)\n },\n })\n },\n\n initVue() {\n Avo.initPlugins()\n\n this.vue = new Vue({\n router,\n store: Avo.store(),\n el: '#app',\n computed: {\n routerKey() {\n return `${this.$route.name}-${this.$route.params.resourceName || ''}`\n },\n layout() {\n if (this.$route.name === '403') return 'blank'\n\n return 'application'\n },\n },\n methods: {\n ...mapMutations('app', [\n 'setAvailableResources',\n ]),\n reload() {\n this.$router.go()\n },\n redirect(url) {\n if (this.$route.path === url) return this.reload()\n\n return this.$router.push(url)\n },\n alert(message, type = 'success') {\n setTimeout(() => {\n this.$toasted.show(message, { type })\n }, 1)\n },\n },\n mounted() {\n this.setAvailableResources(window.avoResources)\n\n Bus.$on('reload', this.reload)\n Bus.$on('redirect', this.redirect)\n Bus.$on('message', (message) => this.alert(message, 'success'))\n Bus.$on('error', (error) => this.alert(error, 'error'))\n },\n destroyed() {\n Bus.$off('reload')\n Bus.$off('redirect')\n Bus.$off('message')\n Bus.$off('error')\n },\n })\n },\n}\n\nexport { Api, Bus }\nexport default Avo\n","import Vue from 'vue'\n\nexport default new Vue()\n","var createCaseFirst = require('./_createCaseFirst');\n/**\n * Converts the first character of `string` to upper case.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category String\n * @param {string} [string=''] The string to convert.\n * @returns {string} Returns the converted string.\n * @example\n *\n * _.upperFirst('fred');\n * // => 'Fred'\n *\n * _.upperFirst('FRED');\n * // => 'FRED'\n */\n\n\nvar upperFirst = createCaseFirst('toUpperCase');\nmodule.exports = upperFirst;","/**\n * Checks if `value` is `undefined`.\n *\n * @static\n * @since 0.1.0\n * @memberOf _\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.\n * @example\n *\n * _.isUndefined(void 0);\n * // => true\n *\n * _.isUndefined(null);\n * // => false\n */\nfunction isUndefined(value) {\n return value === undefined;\n}\n\nmodule.exports = isUndefined;","import Bus from '@/js/Bus'\nimport axios from 'axios'\nimport router from '@/js/router'\n\nfunction getCSRFToken() {\n const metaEl = document.querySelector('meta[name=\"csrf-token\"]')\n\n return metaEl ? metaEl.getAttribute('content') : null\n}\n\nconst appArgs = {\n baseURL: '',\n headers: {\n 'X-CSRF-TOKEN': getCSRFToken(),\n 'X-Requested-With': 'XMLHttpRequest',\n },\n}\n\nconst Api = axios.create(appArgs)\n\n// @todo: take redirects and reload into account before flashing toasts\nApi.interceptors.response.use(\n (response) => {\n const { data } = response\n\n if (data) {\n const {\n message, error, redirect_url, reload,\n } = data\n\n if (message) Bus.$emit('message', message)\n if (error) Bus.$emit('error', error)\n if (reload) Bus.$emit('reload')\n // eslint-disable-next-line camelcase\n if (redirect_url) Bus.$emit('redirect', redirect_url)\n }\n\n return response\n },\n (error) => {\n const { response } = error\n const { data } = response\n\n if (data && data.message) {\n Bus.$emit('error', data.message)\n } else if (data && data.exception) {\n Bus.$emit('error', /^#<(.*)>$/gm.exec(data.exception)[1])\n }\n\n if (response && response.status && response.status === 403) return router.push('/403')\n\n return Promise.reject(error)\n },\n)\n\nApi.interceptors.request.use((config) => {\n document.querySelector('body').classList.add('axios-loading')\n\n return config\n})\n\nApi.interceptors.response.use((response) => {\n document.querySelector('body').classList.remove('axios-loading')\n\n return response\n})\n\nexport default Api\n","import I18n from 'i18n-js'\nimport lowerCase from 'lodash/lowerCase'\nimport pluralize from 'pluralize'\nimport upperFirst from 'lodash/upperFirst'\n\nexport default {\n filters: {\n toLowerCase(value) {\n return value.toLowerCase()\n },\n },\n computed: {\n translationKey() {\n if (this.resourceTranslationKey) return this.resourceTranslationKey\n if (this.meta && this.meta.translation_key) return this.meta.translation_key\n if (this.resource && this.resource.translationKey) return this.resource.translationKey\n\n return null\n },\n resourceNameSingular() {\n if (this.translationKey) return upperFirst(lowerCase(I18n.t(this.translationKey, { count: 1 })))\n\n return pluralize(upperFirst(lowerCase(this.resourceName)), 1)\n },\n resourceNamePlural() {\n if (this.translationKey) return upperFirst(lowerCase(I18n.t(this.translationKey, { count: 2 })))\n\n return upperFirst(lowerCase(this.resourceName))\n },\n },\n}\n","'use strict';\n\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nvar bind = require('./helpers/bind');\n/*global toString:true*/\n// utils is a library of generic helper functions non-specific to axios\n\n\nvar toString = Object.prototype.toString;\n/**\n * Determine if a value is an Array\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an Array, otherwise false\n */\n\nfunction isArray(val) {\n return toString.call(val) === '[object Array]';\n}\n/**\n * Determine if a value is undefined\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if the value is undefined, otherwise false\n */\n\n\nfunction isUndefined(val) {\n return typeof val === 'undefined';\n}\n/**\n * Determine if a value is a Buffer\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Buffer, otherwise false\n */\n\n\nfunction isBuffer(val) {\n return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);\n}\n/**\n * Determine if a value is an ArrayBuffer\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an ArrayBuffer, otherwise false\n */\n\n\nfunction isArrayBuffer(val) {\n return toString.call(val) === '[object ArrayBuffer]';\n}\n/**\n * Determine if a value is a FormData\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an FormData, otherwise false\n */\n\n\nfunction isFormData(val) {\n return typeof FormData !== 'undefined' && val instanceof FormData;\n}\n/**\n * Determine if a value is a view on an ArrayBuffer\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false\n */\n\n\nfunction isArrayBufferView(val) {\n var result;\n\n if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) {\n result = ArrayBuffer.isView(val);\n } else {\n result = val && val.buffer && val.buffer instanceof ArrayBuffer;\n }\n\n return result;\n}\n/**\n * Determine if a value is a String\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a String, otherwise false\n */\n\n\nfunction isString(val) {\n return typeof val === 'string';\n}\n/**\n * Determine if a value is a Number\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Number, otherwise false\n */\n\n\nfunction isNumber(val) {\n return typeof val === 'number';\n}\n/**\n * Determine if a value is an Object\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is an Object, otherwise false\n */\n\n\nfunction isObject(val) {\n return val !== null && _typeof(val) === 'object';\n}\n/**\n * Determine if a value is a Date\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Date, otherwise false\n */\n\n\nfunction isDate(val) {\n return toString.call(val) === '[object Date]';\n}\n/**\n * Determine if a value is a File\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a File, otherwise false\n */\n\n\nfunction isFile(val) {\n return toString.call(val) === '[object File]';\n}\n/**\n * Determine if a value is a Blob\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Blob, otherwise false\n */\n\n\nfunction isBlob(val) {\n return toString.call(val) === '[object Blob]';\n}\n/**\n * Determine if a value is a Function\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Function, otherwise false\n */\n\n\nfunction isFunction(val) {\n return toString.call(val) === '[object Function]';\n}\n/**\n * Determine if a value is a Stream\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a Stream, otherwise false\n */\n\n\nfunction isStream(val) {\n return isObject(val) && isFunction(val.pipe);\n}\n/**\n * Determine if a value is a URLSearchParams object\n *\n * @param {Object} val The value to test\n * @returns {boolean} True if value is a URLSearchParams object, otherwise false\n */\n\n\nfunction isURLSearchParams(val) {\n return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;\n}\n/**\n * Trim excess whitespace off the beginning and end of a string\n *\n * @param {String} str The String to trim\n * @returns {String} The String freed of excess whitespace\n */\n\n\nfunction trim(str) {\n return str.replace(/^\\s*/, '').replace(/\\s*$/, '');\n}\n/**\n * Determine if we're running in a standard browser environment\n *\n * This allows axios to run in a web worker, and react-native.\n * Both environments support XMLHttpRequest, but not fully standard globals.\n *\n * web workers:\n * typeof window -> undefined\n * typeof document -> undefined\n *\n * react-native:\n * navigator.product -> 'ReactNative'\n * nativescript\n * navigator.product -> 'NativeScript' or 'NS'\n */\n\n\nfunction isStandardBrowserEnv() {\n if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' || navigator.product === 'NativeScript' || navigator.product === 'NS')) {\n return false;\n }\n\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n/**\n * Iterate over an Array or an Object invoking a function for each item.\n *\n * If `obj` is an Array callback will be called passing\n * the value, index, and complete array for each item.\n *\n * If 'obj' is an Object callback will be called passing\n * the value, key, and complete object for each property.\n *\n * @param {Object|Array} obj The object to iterate\n * @param {Function} fn The callback to invoke for each item\n */\n\n\nfunction forEach(obj, fn) {\n // Don't bother if no value provided\n if (obj === null || typeof obj === 'undefined') {\n return;\n } // Force an array if not already something iterable\n\n\n if (_typeof(obj) !== 'object') {\n /*eslint no-param-reassign:0*/\n obj = [obj];\n }\n\n if (isArray(obj)) {\n // Iterate over array values\n for (var i = 0, l = obj.length; i < l; i++) {\n fn.call(null, obj[i], i, obj);\n }\n } else {\n // Iterate over object keys\n for (var key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n fn.call(null, obj[key], key, obj);\n }\n }\n }\n}\n/**\n * Accepts varargs expecting each argument to be an object, then\n * immutably merges the properties of each object and returns result.\n *\n * When multiple objects contain the same key the later object in\n * the arguments list will take precedence.\n *\n * Example:\n *\n * ```js\n * var result = merge({foo: 123}, {foo: 456});\n * console.log(result.foo); // outputs 456\n * ```\n *\n * @param {Object} obj1 Object to merge\n * @returns {Object} Result of all merge properties\n */\n\n\nfunction merge()\n/* obj1, obj2, obj3, ... */\n{\n var result = {};\n\n function assignValue(val, key) {\n if (_typeof(result[key]) === 'object' && _typeof(val) === 'object') {\n result[key] = merge(result[key], val);\n } else {\n result[key] = val;\n }\n }\n\n for (var i = 0, l = arguments.length; i < l; i++) {\n forEach(arguments[i], assignValue);\n }\n\n return result;\n}\n/**\n * Function equal to merge with the difference being that no reference\n * to original objects is kept.\n *\n * @see merge\n * @param {Object} obj1 Object to merge\n * @returns {Object} Result of all merge properties\n */\n\n\nfunction deepMerge()\n/* obj1, obj2, obj3, ... */\n{\n var result = {};\n\n function assignValue(val, key) {\n if (_typeof(result[key]) === 'object' && _typeof(val) === 'object') {\n result[key] = deepMerge(result[key], val);\n } else if (_typeof(val) === 'object') {\n result[key] = deepMerge({}, val);\n } else {\n result[key] = val;\n }\n }\n\n for (var i = 0, l = arguments.length; i < l; i++) {\n forEach(arguments[i], assignValue);\n }\n\n return result;\n}\n/**\n * Extends object a by mutably adding to it the properties of object b.\n *\n * @param {Object} a The object to be extended\n * @param {Object} b The object to copy properties from\n * @param {Object} thisArg The object to bind function to\n * @return {Object} The resulting value of object a\n */\n\n\nfunction extend(a, b, thisArg) {\n forEach(b, function assignValue(val, key) {\n if (thisArg && typeof val === 'function') {\n a[key] = bind(val, thisArg);\n } else {\n a[key] = val;\n }\n });\n return a;\n}\n\nmodule.exports = {\n isArray: isArray,\n isArrayBuffer: isArrayBuffer,\n isBuffer: isBuffer,\n isFormData: isFormData,\n isArrayBufferView: isArrayBufferView,\n isString: isString,\n isNumber: isNumber,\n isObject: isObject,\n isUndefined: isUndefined,\n isDate: isDate,\n isFile: isFile,\n isBlob: isBlob,\n isFunction: isFunction,\n isStream: isStream,\n isURLSearchParams: isURLSearchParams,\n isStandardBrowserEnv: isStandardBrowserEnv,\n forEach: forEach,\n merge: merge,\n deepMerge: deepMerge,\n extend: extend,\n trim: trim\n};","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n/*!\n * URI.js - Mutating URLs\n *\n * Version: 1.19.2\n *\n * Author: Rodney Rehm\n * Web: http://medialize.github.io/URI.js/\n *\n * Licensed under\n * MIT License http://www.opensource.org/licenses/mit-license\n *\n */\n(function (root, factory) {\n 'use strict'; // https://github.com/umdjs/umd/blob/master/returnExports.js\n\n if ((typeof module === \"undefined\" ? \"undefined\" : _typeof(module)) === 'object' && module.exports) {\n // Node\n module.exports = factory(require('./punycode'), require('./IPv6'), require('./SecondLevelDomains'));\n } else if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(['./punycode', './IPv6', './SecondLevelDomains'], factory);\n } else {\n // Browser globals (root is window)\n root.URI = factory(root.punycode, root.IPv6, root.SecondLevelDomains, root);\n }\n})(this, function (punycode, IPv6, SLD, root) {\n 'use strict';\n /*global location, escape, unescape */\n // FIXME: v2.0.0 renamce non-camelCase properties to uppercase\n\n /*jshint camelcase: false */\n // save current URI variable, if any\n\n var _URI = root && root.URI;\n\n function URI(url, base) {\n var _urlSupplied = arguments.length >= 1;\n\n var _baseSupplied = arguments.length >= 2; // Allow instantiation without the 'new' keyword\n\n\n if (!(this instanceof URI)) {\n if (_urlSupplied) {\n if (_baseSupplied) {\n return new URI(url, base);\n }\n\n return new URI(url);\n }\n\n return new URI();\n }\n\n if (url === undefined) {\n if (_urlSupplied) {\n throw new TypeError('undefined is not a valid argument for URI');\n }\n\n if (typeof location !== 'undefined') {\n url = location.href + '';\n } else {\n url = '';\n }\n }\n\n if (url === null) {\n if (_urlSupplied) {\n throw new TypeError('null is not a valid argument for URI');\n }\n }\n\n this.href(url); // resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor\n\n if (base !== undefined) {\n return this.absoluteTo(base);\n }\n\n return this;\n }\n\n function isInteger(value) {\n return /^[0-9]+$/.test(value);\n }\n\n URI.version = '1.19.2';\n var p = URI.prototype;\n var hasOwn = Object.prototype.hasOwnProperty;\n\n function escapeRegEx(string) {\n // https://github.com/medialize/URI.js/commit/85ac21783c11f8ccab06106dba9735a31a86924d#commitcomment-821963\n return string.replace(/([.*+?^=!:${}()|[\\]\\/\\\\])/g, '\\\\$1');\n }\n\n function getType(value) {\n // IE8 doesn't return [Object Undefined] but [Object Object] for undefined value\n if (value === undefined) {\n return 'Undefined';\n }\n\n return String(Object.prototype.toString.call(value)).slice(8, -1);\n }\n\n function isArray(obj) {\n return getType(obj) === 'Array';\n }\n\n function filterArrayValues(data, value) {\n var lookup = {};\n var i, length;\n\n if (getType(value) === 'RegExp') {\n lookup = null;\n } else if (isArray(value)) {\n for (i = 0, length = value.length; i < length; i++) {\n lookup[value[i]] = true;\n }\n } else {\n lookup[value] = true;\n }\n\n for (i = 0, length = data.length; i < length; i++) {\n /*jshint laxbreak: true */\n var _match = lookup && lookup[data[i]] !== undefined || !lookup && value.test(data[i]);\n /*jshint laxbreak: false */\n\n\n if (_match) {\n data.splice(i, 1);\n length--;\n i--;\n }\n }\n\n return data;\n }\n\n function arrayContains(list, value) {\n var i, length; // value may be string, number, array, regexp\n\n if (isArray(value)) {\n // Note: this can be optimized to O(n) (instead of current O(m * n))\n for (i = 0, length = value.length; i < length; i++) {\n if (!arrayContains(list, value[i])) {\n return false;\n }\n }\n\n return true;\n }\n\n var _type = getType(value);\n\n for (i = 0, length = list.length; i < length; i++) {\n if (_type === 'RegExp') {\n if (typeof list[i] === 'string' && list[i].match(value)) {\n return true;\n }\n } else if (list[i] === value) {\n return true;\n }\n }\n\n return false;\n }\n\n function arraysEqual(one, two) {\n if (!isArray(one) || !isArray(two)) {\n return false;\n } // arrays can't be equal if they have different amount of content\n\n\n if (one.length !== two.length) {\n return false;\n }\n\n one.sort();\n two.sort();\n\n for (var i = 0, l = one.length; i < l; i++) {\n if (one[i] !== two[i]) {\n return false;\n }\n }\n\n return true;\n }\n\n function trimSlashes(text) {\n var trim_expression = /^\\/+|\\/+$/g;\n return text.replace(trim_expression, '');\n }\n\n URI._parts = function () {\n return {\n protocol: null,\n username: null,\n password: null,\n hostname: null,\n urn: null,\n port: null,\n path: null,\n query: null,\n fragment: null,\n // state\n preventInvalidHostname: URI.preventInvalidHostname,\n duplicateQueryParameters: URI.duplicateQueryParameters,\n escapeQuerySpace: URI.escapeQuerySpace\n };\n }; // state: throw on invalid hostname\n // see https://github.com/medialize/URI.js/pull/345\n // and https://github.com/medialize/URI.js/issues/354\n\n\n URI.preventInvalidHostname = false; // state: allow duplicate query parameters (a=1&a=1)\n\n URI.duplicateQueryParameters = false; // state: replaces + with %20 (space in query strings)\n\n URI.escapeQuerySpace = true; // static properties\n\n URI.protocol_expression = /^[a-z][a-z0-9.+-]*$/i;\n URI.idn_expression = /[^a-z0-9\\._-]/i;\n URI.punycode_expression = /(xn--)/i; // well, 333.444.555.666 matches, but it sure ain't no IPv4 - do we care?\n\n URI.ip4_expression = /^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/; // credits to Rich Brown\n // source: http://forums.intermapper.com/viewtopic.php?p=1096#1096\n // specification: http://www.ietf.org/rfc/rfc4291.txt\n\n URI.ip6_expression = /^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$/; // expression used is \"gruber revised\" (@gruber v2) determined to be the\n // best solution in a regex-golf we did a couple of ages ago at\n // * http://mathiasbynens.be/demo/url-regex\n // * http://rodneyrehm.de/t/url-regex.html\n\n URI.find_uri_expression = /\\b((?:[a-z][\\w-]+:(?:\\/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}\\/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))/ig;\n URI.findUri = {\n // valid \"scheme://\" or \"www.\"\n start: /\\b(?:([a-z][a-z0-9.+-]*:\\/\\/)|www\\.)/gi,\n // everything up to the next whitespace\n end: /[\\s\\r\\n]|$/,\n // trim trailing punctuation captured by end RegExp\n trim: /[`!()\\[\\]{};:'\".,<>?«»“”„‘’]+$/,\n // balanced parens inclusion (), [], {}, <>\n parens: /(\\([^\\)]*\\)|\\[[^\\]]*\\]|\\{[^}]*\\}|<[^>]*>)/g\n }; // http://www.iana.org/assignments/uri-schemes.html\n // http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports\n\n URI.defaultPorts = {\n http: '80',\n https: '443',\n ftp: '21',\n gopher: '70',\n ws: '80',\n wss: '443'\n }; // list of protocols which always require a hostname\n\n URI.hostProtocols = ['http', 'https']; // allowed hostname characters according to RFC 3986\n // ALPHA DIGIT \"-\" \".\" \"_\" \"~\" \"!\" \"$\" \"&\" \"'\" \"(\" \")\" \"*\" \"+\" \",\" \";\" \"=\" %encoded\n // I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . - _\n\n URI.invalid_hostname_characters = /[^a-zA-Z0-9\\.\\-:_]/; // map DOM Elements to their URI attribute\n\n URI.domAttributes = {\n 'a': 'href',\n 'blockquote': 'cite',\n 'link': 'href',\n 'base': 'href',\n 'script': 'src',\n 'form': 'action',\n 'img': 'src',\n 'area': 'href',\n 'iframe': 'src',\n 'embed': 'src',\n 'source': 'src',\n 'track': 'src',\n 'input': 'src',\n // but only if type=\"image\"\n 'audio': 'src',\n 'video': 'src'\n };\n\n URI.getDomAttribute = function (node) {\n if (!node || !node.nodeName) {\n return undefined;\n }\n\n var nodeName = node.nodeName.toLowerCase(); //
should only expose src for type=\"image\"\n\n if (nodeName === 'input' && node.type !== 'image') {\n return undefined;\n }\n\n return URI.domAttributes[nodeName];\n };\n\n function escapeForDumbFirefox36(value) {\n // https://github.com/medialize/URI.js/issues/91\n return escape(value);\n } // encoding / decoding according to RFC3986\n\n\n function strictEncodeURIComponent(string) {\n // see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent\n return encodeURIComponent(string).replace(/[!'()*]/g, escapeForDumbFirefox36).replace(/\\*/g, '%2A');\n }\n\n URI.encode = strictEncodeURIComponent;\n URI.decode = decodeURIComponent;\n\n URI.iso8859 = function () {\n URI.encode = escape;\n URI.decode = unescape;\n };\n\n URI.unicode = function () {\n URI.encode = strictEncodeURIComponent;\n URI.decode = decodeURIComponent;\n };\n\n URI.characters = {\n pathname: {\n encode: {\n // RFC3986 2.1: For consistency, URI producers and normalizers should\n // use uppercase hexadecimal digits for all percent-encodings.\n expression: /%(24|26|2B|2C|3B|3D|3A|40)/ig,\n map: {\n // -._~!'()*\n '%24': '$',\n '%26': '&',\n '%2B': '+',\n '%2C': ',',\n '%3B': ';',\n '%3D': '=',\n '%3A': ':',\n '%40': '@'\n }\n },\n decode: {\n expression: /[\\/\\?#]/g,\n map: {\n '/': '%2F',\n '?': '%3F',\n '#': '%23'\n }\n }\n },\n reserved: {\n encode: {\n // RFC3986 2.1: For consistency, URI producers and normalizers should\n // use uppercase hexadecimal digits for all percent-encodings.\n expression: /%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,\n map: {\n // gen-delims\n '%3A': ':',\n '%2F': '/',\n '%3F': '?',\n '%23': '#',\n '%5B': '[',\n '%5D': ']',\n '%40': '@',\n // sub-delims\n '%21': '!',\n '%24': '$',\n '%26': '&',\n '%27': '\\'',\n '%28': '(',\n '%29': ')',\n '%2A': '*',\n '%2B': '+',\n '%2C': ',',\n '%3B': ';',\n '%3D': '='\n }\n }\n },\n urnpath: {\n // The characters under `encode` are the characters called out by RFC 2141 as being acceptable\n // for usage in a URN. RFC2141 also calls out \"-\", \".\", and \"_\" as acceptable characters, but\n // these aren't encoded by encodeURIComponent, so we don't have to call them out here. Also\n // note that the colon character is not featured in the encoding map; this is because URI.js\n // gives the colons in URNs semantic meaning as the delimiters of path segements, and so it\n // should not appear unencoded in a segment itself.\n // See also the note above about RFC3986 and capitalalized hex digits.\n encode: {\n expression: /%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,\n map: {\n '%21': '!',\n '%24': '$',\n '%27': '\\'',\n '%28': '(',\n '%29': ')',\n '%2A': '*',\n '%2B': '+',\n '%2C': ',',\n '%3B': ';',\n '%3D': '=',\n '%40': '@'\n }\n },\n // These characters are the characters called out by RFC2141 as \"reserved\" characters that\n // should never appear in a URN, plus the colon character (see note above).\n decode: {\n expression: /[\\/\\?#:]/g,\n map: {\n '/': '%2F',\n '?': '%3F',\n '#': '%23',\n ':': '%3A'\n }\n }\n }\n };\n\n URI.encodeQuery = function (string, escapeQuerySpace) {\n var escaped = URI.encode(string + '');\n\n if (escapeQuerySpace === undefined) {\n escapeQuerySpace = URI.escapeQuerySpace;\n }\n\n return escapeQuerySpace ? escaped.replace(/%20/g, '+') : escaped;\n };\n\n URI.decodeQuery = function (string, escapeQuerySpace) {\n string += '';\n\n if (escapeQuerySpace === undefined) {\n escapeQuerySpace = URI.escapeQuerySpace;\n }\n\n try {\n return URI.decode(escapeQuerySpace ? string.replace(/\\+/g, '%20') : string);\n } catch (e) {\n // we're not going to mess with weird encodings,\n // give up and return the undecoded original string\n // see https://github.com/medialize/URI.js/issues/87\n // see https://github.com/medialize/URI.js/issues/92\n return string;\n }\n }; // generate encode/decode path functions\n\n\n var _parts = {\n 'encode': 'encode',\n 'decode': 'decode'\n };\n\n var _part;\n\n var generateAccessor = function generateAccessor(_group, _part) {\n return function (string) {\n try {\n return URI[_part](string + '').replace(URI.characters[_group][_part].expression, function (c) {\n return URI.characters[_group][_part].map[c];\n });\n } catch (e) {\n // we're not going to mess with weird encodings,\n // give up and return the undecoded original string\n // see https://github.com/medialize/URI.js/issues/87\n // see https://github.com/medialize/URI.js/issues/92\n return string;\n }\n };\n };\n\n for (_part in _parts) {\n URI[_part + 'PathSegment'] = generateAccessor('pathname', _parts[_part]);\n URI[_part + 'UrnPathSegment'] = generateAccessor('urnpath', _parts[_part]);\n }\n\n var generateSegmentedPathFunction = function generateSegmentedPathFunction(_sep, _codingFuncName, _innerCodingFuncName) {\n return function (string) {\n // Why pass in names of functions, rather than the function objects themselves? The\n // definitions of some functions (but in particular, URI.decode) will occasionally change due\n // to URI.js having ISO8859 and Unicode modes. Passing in the name and getting it will ensure\n // that the functions we use here are \"fresh\".\n var actualCodingFunc;\n\n if (!_innerCodingFuncName) {\n actualCodingFunc = URI[_codingFuncName];\n } else {\n actualCodingFunc = function actualCodingFunc(string) {\n return URI[_codingFuncName](URI[_innerCodingFuncName](string));\n };\n }\n\n var segments = (string + '').split(_sep);\n\n for (var i = 0, length = segments.length; i < length; i++) {\n segments[i] = actualCodingFunc(segments[i]);\n }\n\n return segments.join(_sep);\n };\n }; // This takes place outside the above loop because we don't want, e.g., encodeUrnPath functions.\n\n\n URI.decodePath = generateSegmentedPathFunction('/', 'decodePathSegment');\n URI.decodeUrnPath = generateSegmentedPathFunction(':', 'decodeUrnPathSegment');\n URI.recodePath = generateSegmentedPathFunction('/', 'encodePathSegment', 'decode');\n URI.recodeUrnPath = generateSegmentedPathFunction(':', 'encodeUrnPathSegment', 'decode');\n URI.encodeReserved = generateAccessor('reserved', 'encode');\n\n URI.parse = function (string, parts) {\n var pos;\n\n if (!parts) {\n parts = {\n preventInvalidHostname: URI.preventInvalidHostname\n };\n } // [protocol\"://\"[username[\":\"password]\"@\"]hostname[\":\"port]\"/\"?][path][\"?\"querystring][\"#\"fragment]\n // extract fragment\n\n\n pos = string.indexOf('#');\n\n if (pos > -1) {\n // escaping?\n parts.fragment = string.substring(pos + 1) || null;\n string = string.substring(0, pos);\n } // extract query\n\n\n pos = string.indexOf('?');\n\n if (pos > -1) {\n // escaping?\n parts.query = string.substring(pos + 1) || null;\n string = string.substring(0, pos);\n } // extract protocol\n\n\n if (string.substring(0, 2) === '//') {\n // relative-scheme\n parts.protocol = null;\n string = string.substring(2); // extract \"user:pass@host:port\"\n\n string = URI.parseAuthority(string, parts);\n } else {\n pos = string.indexOf(':');\n\n if (pos > -1) {\n parts.protocol = string.substring(0, pos) || null;\n\n if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {\n // : may be within the path\n parts.protocol = undefined;\n } else if (string.substring(pos + 1, pos + 3) === '//') {\n string = string.substring(pos + 3); // extract \"user:pass@host:port\"\n\n string = URI.parseAuthority(string, parts);\n } else {\n string = string.substring(pos + 1);\n parts.urn = true;\n }\n }\n } // what's left must be the path\n\n\n parts.path = string; // and we're done\n\n return parts;\n };\n\n URI.parseHost = function (string, parts) {\n if (!string) {\n string = '';\n } // Copy chrome, IE, opera backslash-handling behavior.\n // Back slashes before the query string get converted to forward slashes\n // See: https://github.com/joyent/node/blob/386fd24f49b0e9d1a8a076592a404168faeecc34/lib/url.js#L115-L124\n // See: https://code.google.com/p/chromium/issues/detail?id=25916\n // https://github.com/medialize/URI.js/pull/233\n\n\n string = string.replace(/\\\\/g, '/'); // extract host:port\n\n var pos = string.indexOf('/');\n var bracketPos;\n var t;\n\n if (pos === -1) {\n pos = string.length;\n }\n\n if (string.charAt(0) === '[') {\n // IPv6 host - http://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-04#section-6\n // I claim most client software breaks on IPv6 anyways. To simplify things, URI only accepts\n // IPv6+port in the format [2001:db8::1]:80 (for the time being)\n bracketPos = string.indexOf(']');\n parts.hostname = string.substring(1, bracketPos) || null;\n parts.port = string.substring(bracketPos + 2, pos) || null;\n\n if (parts.port === '/') {\n parts.port = null;\n }\n } else {\n var firstColon = string.indexOf(':');\n var firstSlash = string.indexOf('/');\n var nextColon = string.indexOf(':', firstColon + 1);\n\n if (nextColon !== -1 && (firstSlash === -1 || nextColon < firstSlash)) {\n // IPv6 host contains multiple colons - but no port\n // this notation is actually not allowed by RFC 3986, but we're a liberal parser\n parts.hostname = string.substring(0, pos) || null;\n parts.port = null;\n } else {\n t = string.substring(0, pos).split(':');\n parts.hostname = t[0] || null;\n parts.port = t[1] || null;\n }\n }\n\n if (parts.hostname && string.substring(pos).charAt(0) !== '/') {\n pos++;\n string = '/' + string;\n }\n\n if (parts.preventInvalidHostname) {\n URI.ensureValidHostname(parts.hostname, parts.protocol);\n }\n\n if (parts.port) {\n URI.ensureValidPort(parts.port);\n }\n\n return string.substring(pos) || '/';\n };\n\n URI.parseAuthority = function (string, parts) {\n string = URI.parseUserinfo(string, parts);\n return URI.parseHost(string, parts);\n };\n\n URI.parseUserinfo = function (string, parts) {\n // extract username:password\n var firstSlash = string.indexOf('/');\n var pos = string.lastIndexOf('@', firstSlash > -1 ? firstSlash : string.length - 1);\n var t; // authority@ must come before /path\n\n if (pos > -1 && (firstSlash === -1 || pos < firstSlash)) {\n t = string.substring(0, pos).split(':');\n parts.username = t[0] ? URI.decode(t[0]) : null;\n t.shift();\n parts.password = t[0] ? URI.decode(t.join(':')) : null;\n string = string.substring(pos + 1);\n } else {\n parts.username = null;\n parts.password = null;\n }\n\n return string;\n };\n\n URI.parseQuery = function (string, escapeQuerySpace) {\n if (!string) {\n return {};\n } // throw out the funky business - \"?\"[name\"=\"value\"&\"]+\n\n\n string = string.replace(/&+/g, '&').replace(/^\\?*&*|&+$/g, '');\n\n if (!string) {\n return {};\n }\n\n var items = {};\n var splits = string.split('&');\n var length = splits.length;\n var v, name, value;\n\n for (var i = 0; i < length; i++) {\n v = splits[i].split('=');\n name = URI.decodeQuery(v.shift(), escapeQuerySpace); // no \"=\" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters\n\n value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;\n\n if (hasOwn.call(items, name)) {\n if (typeof items[name] === 'string' || items[name] === null) {\n items[name] = [items[name]];\n }\n\n items[name].push(value);\n } else {\n items[name] = value;\n }\n }\n\n return items;\n };\n\n URI.build = function (parts) {\n var t = '';\n var requireAbsolutePath = false;\n\n if (parts.protocol) {\n t += parts.protocol + ':';\n }\n\n if (!parts.urn && (t || parts.hostname)) {\n t += '//';\n requireAbsolutePath = true;\n }\n\n t += URI.buildAuthority(parts) || '';\n\n if (typeof parts.path === 'string') {\n if (parts.path.charAt(0) !== '/' && requireAbsolutePath) {\n t += '/';\n }\n\n t += parts.path;\n }\n\n if (typeof parts.query === 'string' && parts.query) {\n t += '?' + parts.query;\n }\n\n if (typeof parts.fragment === 'string' && parts.fragment) {\n t += '#' + parts.fragment;\n }\n\n return t;\n };\n\n URI.buildHost = function (parts) {\n var t = '';\n\n if (!parts.hostname) {\n return '';\n } else if (URI.ip6_expression.test(parts.hostname)) {\n t += '[' + parts.hostname + ']';\n } else {\n t += parts.hostname;\n }\n\n if (parts.port) {\n t += ':' + parts.port;\n }\n\n return t;\n };\n\n URI.buildAuthority = function (parts) {\n return URI.buildUserinfo(parts) + URI.buildHost(parts);\n };\n\n URI.buildUserinfo = function (parts) {\n var t = '';\n\n if (parts.username) {\n t += URI.encode(parts.username);\n }\n\n if (parts.password) {\n t += ':' + URI.encode(parts.password);\n }\n\n if (t) {\n t += '@';\n }\n\n return t;\n };\n\n URI.buildQuery = function (data, duplicateQueryParameters, escapeQuerySpace) {\n // according to http://tools.ietf.org/html/rfc3986 or http://labs.apache.org/webarch/uri/rfc/rfc3986.html\n // being »-._~!$&'()*+,;=:@/?« %HEX and alnum are allowed\n // the RFC explicitly states ?/foo being a valid use case, no mention of parameter syntax!\n // URI.js treats the query string as being application/x-www-form-urlencoded\n // see http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type\n var t = '';\n var unique, key, i, length;\n\n for (key in data) {\n if (hasOwn.call(data, key)) {\n if (isArray(data[key])) {\n unique = {};\n\n for (i = 0, length = data[key].length; i < length; i++) {\n if (data[key][i] !== undefined && unique[data[key][i] + ''] === undefined) {\n t += '&' + URI.buildQueryParameter(key, data[key][i], escapeQuerySpace);\n\n if (duplicateQueryParameters !== true) {\n unique[data[key][i] + ''] = true;\n }\n }\n }\n } else if (data[key] !== undefined) {\n t += '&' + URI.buildQueryParameter(key, data[key], escapeQuerySpace);\n }\n }\n }\n\n return t.substring(1);\n };\n\n URI.buildQueryParameter = function (name, value, escapeQuerySpace) {\n // http://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type -- application/x-www-form-urlencoded\n // don't append \"=\" for null values, according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#url-parameter-serialization\n return URI.encodeQuery(name, escapeQuerySpace) + (value !== null ? '=' + URI.encodeQuery(value, escapeQuerySpace) : '');\n };\n\n URI.addQuery = function (data, name, value) {\n if (_typeof(name) === 'object') {\n for (var key in name) {\n if (hasOwn.call(name, key)) {\n URI.addQuery(data, key, name[key]);\n }\n }\n } else if (typeof name === 'string') {\n if (data[name] === undefined) {\n data[name] = value;\n return;\n } else if (typeof data[name] === 'string') {\n data[name] = [data[name]];\n }\n\n if (!isArray(value)) {\n value = [value];\n }\n\n data[name] = (data[name] || []).concat(value);\n } else {\n throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');\n }\n };\n\n URI.setQuery = function (data, name, value) {\n if (_typeof(name) === 'object') {\n for (var key in name) {\n if (hasOwn.call(name, key)) {\n URI.setQuery(data, key, name[key]);\n }\n }\n } else if (typeof name === 'string') {\n data[name] = value === undefined ? null : value;\n } else {\n throw new TypeError('URI.setQuery() accepts an object, string as the name parameter');\n }\n };\n\n URI.removeQuery = function (data, name, value) {\n var i, length, key;\n\n if (isArray(name)) {\n for (i = 0, length = name.length; i < length; i++) {\n data[name[i]] = undefined;\n }\n } else if (getType(name) === 'RegExp') {\n for (key in data) {\n if (name.test(key)) {\n data[key] = undefined;\n }\n }\n } else if (_typeof(name) === 'object') {\n for (key in name) {\n if (hasOwn.call(name, key)) {\n URI.removeQuery(data, key, name[key]);\n }\n }\n } else if (typeof name === 'string') {\n if (value !== undefined) {\n if (getType(value) === 'RegExp') {\n if (!isArray(data[name]) && value.test(data[name])) {\n data[name] = undefined;\n } else {\n data[name] = filterArrayValues(data[name], value);\n }\n } else if (data[name] === String(value) && (!isArray(value) || value.length === 1)) {\n data[name] = undefined;\n } else if (isArray(data[name])) {\n data[name] = filterArrayValues(data[name], value);\n }\n } else {\n data[name] = undefined;\n }\n } else {\n throw new TypeError('URI.removeQuery() accepts an object, string, RegExp as the first parameter');\n }\n };\n\n URI.hasQuery = function (data, name, value, withinArray) {\n switch (getType(name)) {\n case 'String':\n // Nothing to do here\n break;\n\n case 'RegExp':\n for (var key in data) {\n if (hasOwn.call(data, key)) {\n if (name.test(key) && (value === undefined || URI.hasQuery(data, key, value))) {\n return true;\n }\n }\n }\n\n return false;\n\n case 'Object':\n for (var _key in name) {\n if (hasOwn.call(name, _key)) {\n if (!URI.hasQuery(data, _key, name[_key])) {\n return false;\n }\n }\n }\n\n return true;\n\n default:\n throw new TypeError('URI.hasQuery() accepts a string, regular expression or object as the name parameter');\n }\n\n switch (getType(value)) {\n case 'Undefined':\n // true if exists (but may be empty)\n return name in data;\n // data[name] !== undefined;\n\n case 'Boolean':\n // true if exists and non-empty\n var _booly = Boolean(isArray(data[name]) ? data[name].length : data[name]);\n\n return value === _booly;\n\n case 'Function':\n // allow complex comparison\n return !!value(data[name], name, data);\n\n case 'Array':\n if (!isArray(data[name])) {\n return false;\n }\n\n var op = withinArray ? arrayContains : arraysEqual;\n return op(data[name], value);\n\n case 'RegExp':\n if (!isArray(data[name])) {\n return Boolean(data[name] && data[name].match(value));\n }\n\n if (!withinArray) {\n return false;\n }\n\n return arrayContains(data[name], value);\n\n case 'Number':\n value = String(value);\n\n /* falls through */\n\n case 'String':\n if (!isArray(data[name])) {\n return data[name] === value;\n }\n\n if (!withinArray) {\n return false;\n }\n\n return arrayContains(data[name], value);\n\n default:\n throw new TypeError('URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter');\n }\n };\n\n URI.joinPaths = function () {\n var input = [];\n var segments = [];\n var nonEmptySegments = 0;\n\n for (var i = 0; i < arguments.length; i++) {\n var url = new URI(arguments[i]);\n input.push(url);\n\n var _segments = url.segment();\n\n for (var s = 0; s < _segments.length; s++) {\n if (typeof _segments[s] === 'string') {\n segments.push(_segments[s]);\n }\n\n if (_segments[s]) {\n nonEmptySegments++;\n }\n }\n }\n\n if (!segments.length || !nonEmptySegments) {\n return new URI('');\n }\n\n var uri = new URI('').segment(segments);\n\n if (input[0].path() === '' || input[0].path().slice(0, 1) === '/') {\n uri.path('/' + uri.path());\n }\n\n return uri.normalize();\n };\n\n URI.commonPath = function (one, two) {\n var length = Math.min(one.length, two.length);\n var pos; // find first non-matching character\n\n for (pos = 0; pos < length; pos++) {\n if (one.charAt(pos) !== two.charAt(pos)) {\n pos--;\n break;\n }\n }\n\n if (pos < 1) {\n return one.charAt(0) === two.charAt(0) && one.charAt(0) === '/' ? '/' : '';\n } // revert to last /\n\n\n if (one.charAt(pos) !== '/' || two.charAt(pos) !== '/') {\n pos = one.substring(0, pos).lastIndexOf('/');\n }\n\n return one.substring(0, pos + 1);\n };\n\n URI.withinString = function (string, callback, options) {\n options || (options = {});\n\n var _start = options.start || URI.findUri.start;\n\n var _end = options.end || URI.findUri.end;\n\n var _trim = options.trim || URI.findUri.trim;\n\n var _parens = options.parens || URI.findUri.parens;\n\n var _attributeOpen = /[a-z0-9-]=[\"']?$/i;\n _start.lastIndex = 0;\n\n while (true) {\n var match = _start.exec(string);\n\n if (!match) {\n break;\n }\n\n var start = match.index;\n\n if (options.ignoreHtml) {\n // attribut(e=[\"']?$)\n var attributeOpen = string.slice(Math.max(start - 3, 0), start);\n\n if (attributeOpen && _attributeOpen.test(attributeOpen)) {\n continue;\n }\n }\n\n var end = start + string.slice(start).search(_end);\n var slice = string.slice(start, end); // make sure we include well balanced parens\n\n var parensEnd = -1;\n\n while (true) {\n var parensMatch = _parens.exec(slice);\n\n if (!parensMatch) {\n break;\n }\n\n var parensMatchEnd = parensMatch.index + parensMatch[0].length;\n parensEnd = Math.max(parensEnd, parensMatchEnd);\n }\n\n if (parensEnd > -1) {\n slice = slice.slice(0, parensEnd) + slice.slice(parensEnd).replace(_trim, '');\n } else {\n slice = slice.replace(_trim, '');\n }\n\n if (slice.length <= match[0].length) {\n // the extract only contains the starting marker of a URI,\n // e.g. \"www\" or \"http://\"\n continue;\n }\n\n if (options.ignore && options.ignore.test(slice)) {\n continue;\n }\n\n end = start + slice.length;\n var result = callback(slice, start, end, string);\n\n if (result === undefined) {\n _start.lastIndex = end;\n continue;\n }\n\n result = String(result);\n string = string.slice(0, start) + result + string.slice(end);\n _start.lastIndex = start + result.length;\n }\n\n _start.lastIndex = 0;\n return string;\n };\n\n URI.ensureValidHostname = function (v, protocol) {\n // Theoretically URIs allow percent-encoding in Hostnames (according to RFC 3986)\n // they are not part of DNS and therefore ignored by URI.js\n var hasHostname = !!v; // not null and not an empty string\n\n var hasProtocol = !!protocol;\n var rejectEmptyHostname = false;\n\n if (hasProtocol) {\n rejectEmptyHostname = arrayContains(URI.hostProtocols, protocol);\n }\n\n if (rejectEmptyHostname && !hasHostname) {\n throw new TypeError('Hostname cannot be empty, if protocol is ' + protocol);\n } else if (v && v.match(URI.invalid_hostname_characters)) {\n // test punycode\n if (!punycode) {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available');\n }\n\n if (punycode.toASCII(v).match(URI.invalid_hostname_characters)) {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-:_]');\n }\n }\n };\n\n URI.ensureValidPort = function (v) {\n if (!v) {\n return;\n }\n\n var port = Number(v);\n\n if (isInteger(port) && port > 0 && port < 65536) {\n return;\n }\n\n throw new TypeError('Port \"' + v + '\" is not a valid port');\n }; // noConflict\n\n\n URI.noConflict = function (removeAll) {\n if (removeAll) {\n var unconflicted = {\n URI: this.noConflict()\n };\n\n if (root.URITemplate && typeof root.URITemplate.noConflict === 'function') {\n unconflicted.URITemplate = root.URITemplate.noConflict();\n }\n\n if (root.IPv6 && typeof root.IPv6.noConflict === 'function') {\n unconflicted.IPv6 = root.IPv6.noConflict();\n }\n\n if (root.SecondLevelDomains && typeof root.SecondLevelDomains.noConflict === 'function') {\n unconflicted.SecondLevelDomains = root.SecondLevelDomains.noConflict();\n }\n\n return unconflicted;\n } else if (root.URI === this) {\n root.URI = _URI;\n }\n\n return this;\n };\n\n p.build = function (deferBuild) {\n if (deferBuild === true) {\n this._deferred_build = true;\n } else if (deferBuild === undefined || this._deferred_build) {\n this._string = URI.build(this._parts);\n this._deferred_build = false;\n }\n\n return this;\n };\n\n p.clone = function () {\n return new URI(this);\n };\n\n p.valueOf = p.toString = function () {\n return this.build(false)._string;\n };\n\n function generateSimpleAccessor(_part) {\n return function (v, build) {\n if (v === undefined) {\n return this._parts[_part] || '';\n } else {\n this._parts[_part] = v || null;\n this.build(!build);\n return this;\n }\n };\n }\n\n function generatePrefixAccessor(_part, _key) {\n return function (v, build) {\n if (v === undefined) {\n return this._parts[_part] || '';\n } else {\n if (v !== null) {\n v = v + '';\n\n if (v.charAt(0) === _key) {\n v = v.substring(1);\n }\n }\n\n this._parts[_part] = v;\n this.build(!build);\n return this;\n }\n };\n }\n\n p.protocol = generateSimpleAccessor('protocol');\n p.username = generateSimpleAccessor('username');\n p.password = generateSimpleAccessor('password');\n p.hostname = generateSimpleAccessor('hostname');\n p.port = generateSimpleAccessor('port');\n p.query = generatePrefixAccessor('query', '?');\n p.fragment = generatePrefixAccessor('fragment', '#');\n\n p.search = function (v, build) {\n var t = this.query(v, build);\n return typeof t === 'string' && t.length ? '?' + t : t;\n };\n\n p.hash = function (v, build) {\n var t = this.fragment(v, build);\n return typeof t === 'string' && t.length ? '#' + t : t;\n };\n\n p.pathname = function (v, build) {\n if (v === undefined || v === true) {\n var res = this._parts.path || (this._parts.hostname ? '/' : '');\n return v ? (this._parts.urn ? URI.decodeUrnPath : URI.decodePath)(res) : res;\n } else {\n if (this._parts.urn) {\n this._parts.path = v ? URI.recodeUrnPath(v) : '';\n } else {\n this._parts.path = v ? URI.recodePath(v) : '/';\n }\n\n this.build(!build);\n return this;\n }\n };\n\n p.path = p.pathname;\n\n p.href = function (href, build) {\n var key;\n\n if (href === undefined) {\n return this.toString();\n }\n\n this._string = '';\n this._parts = URI._parts();\n\n var _URI = href instanceof URI;\n\n var _object = _typeof(href) === 'object' && (href.hostname || href.path || href.pathname);\n\n if (href.nodeName) {\n var attribute = URI.getDomAttribute(href);\n href = href[attribute] || '';\n _object = false;\n } // window.location is reported to be an object, but it's not the sort\n // of object we're looking for:\n // * location.protocol ends with a colon\n // * location.query != object.search\n // * location.hash != object.fragment\n // simply serializing the unknown object should do the trick\n // (for location, not for everything...)\n\n\n if (!_URI && _object && href.pathname !== undefined) {\n href = href.toString();\n }\n\n if (typeof href === 'string' || href instanceof String) {\n this._parts = URI.parse(String(href), this._parts);\n } else if (_URI || _object) {\n var src = _URI ? href._parts : href;\n\n for (key in src) {\n if (key === 'query') {\n continue;\n }\n\n if (hasOwn.call(this._parts, key)) {\n this._parts[key] = src[key];\n }\n }\n\n if (src.query) {\n this.query(src.query, false);\n }\n } else {\n throw new TypeError('invalid input');\n }\n\n this.build(!build);\n return this;\n }; // identification accessors\n\n\n p.is = function (what) {\n var ip = false;\n var ip4 = false;\n var ip6 = false;\n var name = false;\n var sld = false;\n var idn = false;\n var punycode = false;\n var relative = !this._parts.urn;\n\n if (this._parts.hostname) {\n relative = false;\n ip4 = URI.ip4_expression.test(this._parts.hostname);\n ip6 = URI.ip6_expression.test(this._parts.hostname);\n ip = ip4 || ip6;\n name = !ip;\n sld = name && SLD && SLD.has(this._parts.hostname);\n idn = name && URI.idn_expression.test(this._parts.hostname);\n punycode = name && URI.punycode_expression.test(this._parts.hostname);\n }\n\n switch (what.toLowerCase()) {\n case 'relative':\n return relative;\n\n case 'absolute':\n return !relative;\n // hostname identification\n\n case 'domain':\n case 'name':\n return name;\n\n case 'sld':\n return sld;\n\n case 'ip':\n return ip;\n\n case 'ip4':\n case 'ipv4':\n case 'inet4':\n return ip4;\n\n case 'ip6':\n case 'ipv6':\n case 'inet6':\n return ip6;\n\n case 'idn':\n return idn;\n\n case 'url':\n return !this._parts.urn;\n\n case 'urn':\n return !!this._parts.urn;\n\n case 'punycode':\n return punycode;\n }\n\n return null;\n }; // component specific input validation\n\n\n var _protocol = p.protocol;\n var _port = p.port;\n var _hostname = p.hostname;\n\n p.protocol = function (v, build) {\n if (v) {\n // accept trailing ://\n v = v.replace(/:(\\/\\/)?$/, '');\n\n if (!v.match(URI.protocol_expression)) {\n throw new TypeError('Protocol \"' + v + '\" contains characters other than [A-Z0-9.+-] or doesn\\'t start with [A-Z]');\n }\n }\n\n return _protocol.call(this, v, build);\n };\n\n p.scheme = p.protocol;\n\n p.port = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v !== undefined) {\n if (v === 0) {\n v = null;\n }\n\n if (v) {\n v += '';\n\n if (v.charAt(0) === ':') {\n v = v.substring(1);\n }\n\n URI.ensureValidPort(v);\n }\n }\n\n return _port.call(this, v, build);\n };\n\n p.hostname = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v !== undefined) {\n var x = {\n preventInvalidHostname: this._parts.preventInvalidHostname\n };\n var res = URI.parseHost(v, x);\n\n if (res !== '/') {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-]');\n }\n\n v = x.hostname;\n\n if (this._parts.preventInvalidHostname) {\n URI.ensureValidHostname(v, this._parts.protocol);\n }\n }\n\n return _hostname.call(this, v, build);\n }; // compound accessors\n\n\n p.origin = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n var protocol = this.protocol();\n var authority = this.authority();\n\n if (!authority) {\n return '';\n }\n\n return (protocol ? protocol + '://' : '') + this.authority();\n } else {\n var origin = URI(v);\n this.protocol(origin.protocol()).authority(origin.authority()).build(!build);\n return this;\n }\n };\n\n p.host = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n return this._parts.hostname ? URI.buildHost(this._parts) : '';\n } else {\n var res = URI.parseHost(v, this._parts);\n\n if (res !== '/') {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-]');\n }\n\n this.build(!build);\n return this;\n }\n };\n\n p.authority = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n return this._parts.hostname ? URI.buildAuthority(this._parts) : '';\n } else {\n var res = URI.parseAuthority(v, this._parts);\n\n if (res !== '/') {\n throw new TypeError('Hostname \"' + v + '\" contains characters other than [A-Z0-9.-]');\n }\n\n this.build(!build);\n return this;\n }\n };\n\n p.userinfo = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined) {\n var t = URI.buildUserinfo(this._parts);\n return t ? t.substring(0, t.length - 1) : t;\n } else {\n if (v[v.length - 1] !== '@') {\n v += '@';\n }\n\n URI.parseUserinfo(v, this._parts);\n this.build(!build);\n return this;\n }\n };\n\n p.resource = function (v, build) {\n var parts;\n\n if (v === undefined) {\n return this.path() + this.search() + this.hash();\n }\n\n parts = URI.parse(v);\n this._parts.path = parts.path;\n this._parts.query = parts.query;\n this._parts.fragment = parts.fragment;\n this.build(!build);\n return this;\n }; // fraction accessors\n\n\n p.subdomain = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n } // convenience, return \"www\" from \"www.example.org\"\n\n\n if (v === undefined) {\n if (!this._parts.hostname || this.is('IP')) {\n return '';\n } // grab domain and add another segment\n\n\n var end = this._parts.hostname.length - this.domain().length - 1;\n return this._parts.hostname.substring(0, end) || '';\n } else {\n var e = this._parts.hostname.length - this.domain().length;\n\n var sub = this._parts.hostname.substring(0, e);\n\n var replace = new RegExp('^' + escapeRegEx(sub));\n\n if (v && v.charAt(v.length - 1) !== '.') {\n v += '.';\n }\n\n if (v.indexOf(':') !== -1) {\n throw new TypeError('Domains cannot contain colons');\n }\n\n if (v) {\n URI.ensureValidHostname(v, this._parts.protocol);\n }\n\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n this.build(!build);\n return this;\n }\n };\n\n p.domain = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (typeof v === 'boolean') {\n build = v;\n v = undefined;\n } // convenience, return \"example.org\" from \"www.example.org\"\n\n\n if (v === undefined) {\n if (!this._parts.hostname || this.is('IP')) {\n return '';\n } // if hostname consists of 1 or 2 segments, it must be the domain\n\n\n var t = this._parts.hostname.match(/\\./g);\n\n if (t && t.length < 2) {\n return this._parts.hostname;\n } // grab tld and add another segment\n\n\n var end = this._parts.hostname.length - this.tld(build).length - 1;\n end = this._parts.hostname.lastIndexOf('.', end - 1) + 1;\n return this._parts.hostname.substring(end) || '';\n } else {\n if (!v) {\n throw new TypeError('cannot set domain empty');\n }\n\n if (v.indexOf(':') !== -1) {\n throw new TypeError('Domains cannot contain colons');\n }\n\n URI.ensureValidHostname(v, this._parts.protocol);\n\n if (!this._parts.hostname || this.is('IP')) {\n this._parts.hostname = v;\n } else {\n var replace = new RegExp(escapeRegEx(this.domain()) + '$');\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n }\n\n this.build(!build);\n return this;\n }\n };\n\n p.tld = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (typeof v === 'boolean') {\n build = v;\n v = undefined;\n } // return \"org\" from \"www.example.org\"\n\n\n if (v === undefined) {\n if (!this._parts.hostname || this.is('IP')) {\n return '';\n }\n\n var pos = this._parts.hostname.lastIndexOf('.');\n\n var tld = this._parts.hostname.substring(pos + 1);\n\n if (build !== true && SLD && SLD.list[tld.toLowerCase()]) {\n return SLD.get(this._parts.hostname) || tld;\n }\n\n return tld;\n } else {\n var replace;\n\n if (!v) {\n throw new TypeError('cannot set TLD empty');\n } else if (v.match(/[^a-zA-Z0-9-]/)) {\n if (SLD && SLD.is(v)) {\n replace = new RegExp(escapeRegEx(this.tld()) + '$');\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n } else {\n throw new TypeError('TLD \"' + v + '\" contains characters other than [A-Z0-9]');\n }\n } else if (!this._parts.hostname || this.is('IP')) {\n throw new ReferenceError('cannot set TLD on non-domain host');\n } else {\n replace = new RegExp(escapeRegEx(this.tld()) + '$');\n this._parts.hostname = this._parts.hostname.replace(replace, v);\n }\n\n this.build(!build);\n return this;\n }\n };\n\n p.directory = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined || v === true) {\n if (!this._parts.path && !this._parts.hostname) {\n return '';\n }\n\n if (this._parts.path === '/') {\n return '/';\n }\n\n var end = this._parts.path.length - this.filename().length - 1;\n var res = this._parts.path.substring(0, end) || (this._parts.hostname ? '/' : '');\n return v ? URI.decodePath(res) : res;\n } else {\n var e = this._parts.path.length - this.filename().length;\n\n var directory = this._parts.path.substring(0, e);\n\n var replace = new RegExp('^' + escapeRegEx(directory)); // fully qualifier directories begin with a slash\n\n if (!this.is('relative')) {\n if (!v) {\n v = '/';\n }\n\n if (v.charAt(0) !== '/') {\n v = '/' + v;\n }\n } // directories always end with a slash\n\n\n if (v && v.charAt(v.length - 1) !== '/') {\n v += '/';\n }\n\n v = URI.recodePath(v);\n this._parts.path = this._parts.path.replace(replace, v);\n this.build(!build);\n return this;\n }\n };\n\n p.filename = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (typeof v !== 'string') {\n if (!this._parts.path || this._parts.path === '/') {\n return '';\n }\n\n var pos = this._parts.path.lastIndexOf('/');\n\n var res = this._parts.path.substring(pos + 1);\n\n return v ? URI.decodePathSegment(res) : res;\n } else {\n var mutatedDirectory = false;\n\n if (v.charAt(0) === '/') {\n v = v.substring(1);\n }\n\n if (v.match(/\\.?\\//)) {\n mutatedDirectory = true;\n }\n\n var replace = new RegExp(escapeRegEx(this.filename()) + '$');\n v = URI.recodePath(v);\n this._parts.path = this._parts.path.replace(replace, v);\n\n if (mutatedDirectory) {\n this.normalizePath(build);\n } else {\n this.build(!build);\n }\n\n return this;\n }\n };\n\n p.suffix = function (v, build) {\n if (this._parts.urn) {\n return v === undefined ? '' : this;\n }\n\n if (v === undefined || v === true) {\n if (!this._parts.path || this._parts.path === '/') {\n return '';\n }\n\n var filename = this.filename();\n var pos = filename.lastIndexOf('.');\n var s, res;\n\n if (pos === -1) {\n return '';\n } // suffix may only contain alnum characters (yup, I made this up.)\n\n\n s = filename.substring(pos + 1);\n res = /^[a-z0-9%]+$/i.test(s) ? s : '';\n return v ? URI.decodePathSegment(res) : res;\n } else {\n if (v.charAt(0) === '.') {\n v = v.substring(1);\n }\n\n var suffix = this.suffix();\n var replace;\n\n if (!suffix) {\n if (!v) {\n return this;\n }\n\n this._parts.path += '.' + URI.recodePath(v);\n } else if (!v) {\n replace = new RegExp(escapeRegEx('.' + suffix) + '$');\n } else {\n replace = new RegExp(escapeRegEx(suffix) + '$');\n }\n\n if (replace) {\n v = URI.recodePath(v);\n this._parts.path = this._parts.path.replace(replace, v);\n }\n\n this.build(!build);\n return this;\n }\n };\n\n p.segment = function (segment, v, build) {\n var separator = this._parts.urn ? ':' : '/';\n var path = this.path();\n var absolute = path.substring(0, 1) === '/';\n var segments = path.split(separator);\n\n if (segment !== undefined && typeof segment !== 'number') {\n build = v;\n v = segment;\n segment = undefined;\n }\n\n if (segment !== undefined && typeof segment !== 'number') {\n throw new Error('Bad segment \"' + segment + '\", must be 0-based integer');\n }\n\n if (absolute) {\n segments.shift();\n }\n\n if (segment < 0) {\n // allow negative indexes to address from the end\n segment = Math.max(segments.length + segment, 0);\n }\n\n if (v === undefined) {\n /*jshint laxbreak: true */\n return segment === undefined ? segments : segments[segment];\n /*jshint laxbreak: false */\n } else if (segment === null || segments[segment] === undefined) {\n if (isArray(v)) {\n segments = []; // collapse empty elements within array\n\n for (var i = 0, l = v.length; i < l; i++) {\n if (!v[i].length && (!segments.length || !segments[segments.length - 1].length)) {\n continue;\n }\n\n if (segments.length && !segments[segments.length - 1].length) {\n segments.pop();\n }\n\n segments.push(trimSlashes(v[i]));\n }\n } else if (v || typeof v === 'string') {\n v = trimSlashes(v);\n\n if (segments[segments.length - 1] === '') {\n // empty trailing elements have to be overwritten\n // to prevent results such as /foo//bar\n segments[segments.length - 1] = v;\n } else {\n segments.push(v);\n }\n }\n } else {\n if (v) {\n segments[segment] = trimSlashes(v);\n } else {\n segments.splice(segment, 1);\n }\n }\n\n if (absolute) {\n segments.unshift('');\n }\n\n return this.path(segments.join(separator), build);\n };\n\n p.segmentCoded = function (segment, v, build) {\n var segments, i, l;\n\n if (typeof segment !== 'number') {\n build = v;\n v = segment;\n segment = undefined;\n }\n\n if (v === undefined) {\n segments = this.segment(segment, v, build);\n\n if (!isArray(segments)) {\n segments = segments !== undefined ? URI.decode(segments) : undefined;\n } else {\n for (i = 0, l = segments.length; i < l; i++) {\n segments[i] = URI.decode(segments[i]);\n }\n }\n\n return segments;\n }\n\n if (!isArray(v)) {\n v = typeof v === 'string' || v instanceof String ? URI.encode(v) : v;\n } else {\n for (i = 0, l = v.length; i < l; i++) {\n v[i] = URI.encode(v[i]);\n }\n }\n\n return this.segment(segment, v, build);\n }; // mutating query string\n\n\n var q = p.query;\n\n p.query = function (v, build) {\n if (v === true) {\n return URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n } else if (typeof v === 'function') {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n var result = v.call(this, data);\n this._parts.query = URI.buildQuery(result || data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n this.build(!build);\n return this;\n } else if (v !== undefined && typeof v !== 'string') {\n this._parts.query = URI.buildQuery(v, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n this.build(!build);\n return this;\n } else {\n return q.call(this, v, build);\n }\n };\n\n p.setQuery = function (name, value, build) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n\n if (typeof name === 'string' || name instanceof String) {\n data[name] = value !== undefined ? value : null;\n } else if (_typeof(name) === 'object') {\n for (var key in name) {\n if (hasOwn.call(name, key)) {\n data[key] = name[key];\n }\n }\n } else {\n throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');\n }\n\n this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n\n if (typeof name !== 'string') {\n build = value;\n }\n\n this.build(!build);\n return this;\n };\n\n p.addQuery = function (name, value, build) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n URI.addQuery(data, name, value === undefined ? null : value);\n this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n\n if (typeof name !== 'string') {\n build = value;\n }\n\n this.build(!build);\n return this;\n };\n\n p.removeQuery = function (name, value, build) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n URI.removeQuery(data, name, value);\n this._parts.query = URI.buildQuery(data, this._parts.duplicateQueryParameters, this._parts.escapeQuerySpace);\n\n if (typeof name !== 'string') {\n build = value;\n }\n\n this.build(!build);\n return this;\n };\n\n p.hasQuery = function (name, value, withinArray) {\n var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);\n return URI.hasQuery(data, name, value, withinArray);\n };\n\n p.setSearch = p.setQuery;\n p.addSearch = p.addQuery;\n p.removeSearch = p.removeQuery;\n p.hasSearch = p.hasQuery; // sanitizing URLs\n\n p.normalize = function () {\n if (this._parts.urn) {\n return this.normalizeProtocol(false).normalizePath(false).normalizeQuery(false).normalizeFragment(false).build();\n }\n\n return this.normalizeProtocol(false).normalizeHostname(false).normalizePort(false).normalizePath(false).normalizeQuery(false).normalizeFragment(false).build();\n };\n\n p.normalizeProtocol = function (build) {\n if (typeof this._parts.protocol === 'string') {\n this._parts.protocol = this._parts.protocol.toLowerCase();\n this.build(!build);\n }\n\n return this;\n };\n\n p.normalizeHostname = function (build) {\n if (this._parts.hostname) {\n if (this.is('IDN') && punycode) {\n this._parts.hostname = punycode.toASCII(this._parts.hostname);\n } else if (this.is('IPv6') && IPv6) {\n this._parts.hostname = IPv6.best(this._parts.hostname);\n }\n\n this._parts.hostname = this._parts.hostname.toLowerCase();\n this.build(!build);\n }\n\n return this;\n };\n\n p.normalizePort = function (build) {\n // remove port of it's the protocol's default\n if (typeof this._parts.protocol === 'string' && this._parts.port === URI.defaultPorts[this._parts.protocol]) {\n this._parts.port = null;\n this.build(!build);\n }\n\n return this;\n };\n\n p.normalizePath = function (build) {\n var _path = this._parts.path;\n\n if (!_path) {\n return this;\n }\n\n if (this._parts.urn) {\n this._parts.path = URI.recodeUrnPath(this._parts.path);\n this.build(!build);\n return this;\n }\n\n if (this._parts.path === '/') {\n return this;\n }\n\n _path = URI.recodePath(_path);\n\n var _was_relative;\n\n var _leadingParents = '';\n\n var _parent, _pos; // handle relative paths\n\n\n if (_path.charAt(0) !== '/') {\n _was_relative = true;\n _path = '/' + _path;\n } // handle relative files (as opposed to directories)\n\n\n if (_path.slice(-3) === '/..' || _path.slice(-2) === '/.') {\n _path += '/';\n } // resolve simples\n\n\n _path = _path.replace(/(\\/(\\.\\/)+)|(\\/\\.$)/g, '/').replace(/\\/{2,}/g, '/'); // remember leading parents\n\n if (_was_relative) {\n _leadingParents = _path.substring(1).match(/^(\\.\\.\\/)+/) || '';\n\n if (_leadingParents) {\n _leadingParents = _leadingParents[0];\n }\n } // resolve parents\n\n\n while (true) {\n _parent = _path.search(/\\/\\.\\.(\\/|$)/);\n\n if (_parent === -1) {\n // no more ../ to resolve\n break;\n } else if (_parent === 0) {\n // top level cannot be relative, skip it\n _path = _path.substring(3);\n continue;\n }\n\n _pos = _path.substring(0, _parent).lastIndexOf('/');\n\n if (_pos === -1) {\n _pos = _parent;\n }\n\n _path = _path.substring(0, _pos) + _path.substring(_parent + 3);\n } // revert to relative\n\n\n if (_was_relative && this.is('relative')) {\n _path = _leadingParents + _path.substring(1);\n }\n\n this._parts.path = _path;\n this.build(!build);\n return this;\n };\n\n p.normalizePathname = p.normalizePath;\n\n p.normalizeQuery = function (build) {\n if (typeof this._parts.query === 'string') {\n if (!this._parts.query.length) {\n this._parts.query = null;\n } else {\n this.query(URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace));\n }\n\n this.build(!build);\n }\n\n return this;\n };\n\n p.normalizeFragment = function (build) {\n if (!this._parts.fragment) {\n this._parts.fragment = null;\n this.build(!build);\n }\n\n return this;\n };\n\n p.normalizeSearch = p.normalizeQuery;\n p.normalizeHash = p.normalizeFragment;\n\n p.iso8859 = function () {\n // expect unicode input, iso8859 output\n var e = URI.encode;\n var d = URI.decode;\n URI.encode = escape;\n URI.decode = decodeURIComponent;\n\n try {\n this.normalize();\n } finally {\n URI.encode = e;\n URI.decode = d;\n }\n\n return this;\n };\n\n p.unicode = function () {\n // expect iso8859 input, unicode output\n var e = URI.encode;\n var d = URI.decode;\n URI.encode = strictEncodeURIComponent;\n URI.decode = unescape;\n\n try {\n this.normalize();\n } finally {\n URI.encode = e;\n URI.decode = d;\n }\n\n return this;\n };\n\n p.readable = function () {\n var uri = this.clone(); // removing username, password, because they shouldn't be displayed according to RFC 3986\n\n uri.username('').password('').normalize();\n var t = '';\n\n if (uri._parts.protocol) {\n t += uri._parts.protocol + '://';\n }\n\n if (uri._parts.hostname) {\n if (uri.is('punycode') && punycode) {\n t += punycode.toUnicode(uri._parts.hostname);\n\n if (uri._parts.port) {\n t += ':' + uri._parts.port;\n }\n } else {\n t += uri.host();\n }\n }\n\n if (uri._parts.hostname && uri._parts.path && uri._parts.path.charAt(0) !== '/') {\n t += '/';\n }\n\n t += uri.path(true);\n\n if (uri._parts.query) {\n var q = '';\n\n for (var i = 0, qp = uri._parts.query.split('&'), l = qp.length; i < l; i++) {\n var kv = (qp[i] || '').split('=');\n q += '&' + URI.decodeQuery(kv[0], this._parts.escapeQuerySpace).replace(/&/g, '%26');\n\n if (kv[1] !== undefined) {\n q += '=' + URI.decodeQuery(kv[1], this._parts.escapeQuerySpace).replace(/&/g, '%26');\n }\n }\n\n t += '?' + q.substring(1);\n }\n\n t += URI.decodeQuery(uri.hash(), true);\n return t;\n }; // resolving relative and absolute URLs\n\n\n p.absoluteTo = function (base) {\n var resolved = this.clone();\n var properties = ['protocol', 'username', 'password', 'hostname', 'port'];\n var basedir, i, p;\n\n if (this._parts.urn) {\n throw new Error('URNs do not have any generally defined hierarchical components');\n }\n\n if (!(base instanceof URI)) {\n base = new URI(base);\n }\n\n if (resolved._parts.protocol) {\n // Directly returns even if this._parts.hostname is empty.\n return resolved;\n } else {\n resolved._parts.protocol = base._parts.protocol;\n }\n\n if (this._parts.hostname) {\n return resolved;\n }\n\n for (i = 0; p = properties[i]; i++) {\n resolved._parts[p] = base._parts[p];\n }\n\n if (!resolved._parts.path) {\n resolved._parts.path = base._parts.path;\n\n if (!resolved._parts.query) {\n resolved._parts.query = base._parts.query;\n }\n } else {\n if (resolved._parts.path.substring(-2) === '..') {\n resolved._parts.path += '/';\n }\n\n if (resolved.path().charAt(0) !== '/') {\n basedir = base.directory();\n basedir = basedir ? basedir : base.path().indexOf('/') === 0 ? '/' : '';\n resolved._parts.path = (basedir ? basedir + '/' : '') + resolved._parts.path;\n resolved.normalizePath();\n }\n }\n\n resolved.build();\n return resolved;\n };\n\n p.relativeTo = function (base) {\n var relative = this.clone().normalize();\n var relativeParts, baseParts, common, relativePath, basePath;\n\n if (relative._parts.urn) {\n throw new Error('URNs do not have any generally defined hierarchical components');\n }\n\n base = new URI(base).normalize();\n relativeParts = relative._parts;\n baseParts = base._parts;\n relativePath = relative.path();\n basePath = base.path();\n\n if (relativePath.charAt(0) !== '/') {\n throw new Error('URI is already relative');\n }\n\n if (basePath.charAt(0) !== '/') {\n throw new Error('Cannot calculate a URI relative to another relative URI');\n }\n\n if (relativeParts.protocol === baseParts.protocol) {\n relativeParts.protocol = null;\n }\n\n if (relativeParts.username !== baseParts.username || relativeParts.password !== baseParts.password) {\n return relative.build();\n }\n\n if (relativeParts.protocol !== null || relativeParts.username !== null || relativeParts.password !== null) {\n return relative.build();\n }\n\n if (relativeParts.hostname === baseParts.hostname && relativeParts.port === baseParts.port) {\n relativeParts.hostname = null;\n relativeParts.port = null;\n } else {\n return relative.build();\n }\n\n if (relativePath === basePath) {\n relativeParts.path = '';\n return relative.build();\n } // determine common sub path\n\n\n common = URI.commonPath(relativePath, basePath); // If the paths have nothing in common, return a relative URL with the absolute path.\n\n if (!common) {\n return relative.build();\n }\n\n var parents = baseParts.path.substring(common.length).replace(/[^\\/]*$/, '').replace(/.*?\\//g, '../');\n relativeParts.path = parents + relativeParts.path.substring(common.length) || './';\n return relative.build();\n }; // comparing URIs\n\n\n p.equals = function (uri) {\n var one = this.clone();\n var two = new URI(uri);\n var one_map = {};\n var two_map = {};\n var checked = {};\n var one_query, two_query, key;\n one.normalize();\n two.normalize(); // exact match\n\n if (one.toString() === two.toString()) {\n return true;\n } // extract query string\n\n\n one_query = one.query();\n two_query = two.query();\n one.query('');\n two.query(''); // definitely not equal if not even non-query parts match\n\n if (one.toString() !== two.toString()) {\n return false;\n } // query parameters have the same length, even if they're permuted\n\n\n if (one_query.length !== two_query.length) {\n return false;\n }\n\n one_map = URI.parseQuery(one_query, this._parts.escapeQuerySpace);\n two_map = URI.parseQuery(two_query, this._parts.escapeQuerySpace);\n\n for (key in one_map) {\n if (hasOwn.call(one_map, key)) {\n if (!isArray(one_map[key])) {\n if (one_map[key] !== two_map[key]) {\n return false;\n }\n } else if (!arraysEqual(one_map[key], two_map[key])) {\n return false;\n }\n\n checked[key] = true;\n }\n }\n\n for (key in two_map) {\n if (hasOwn.call(two_map, key)) {\n if (!checked[key]) {\n // two contains a parameter not present in one\n return false;\n }\n }\n }\n\n return true;\n }; // state\n\n\n p.preventInvalidHostname = function (v) {\n this._parts.preventInvalidHostname = !!v;\n return this;\n };\n\n p.duplicateQueryParameters = function (v) {\n this._parts.duplicateQueryParameters = !!v;\n return this;\n };\n\n p.escapeQuerySpace = function (v) {\n this._parts.escapeQuerySpace = !!v;\n return this;\n };\n\n return URI;\n});","export default {\n computed: {\n relationship() {\n if (this.field && this.field.relationship) return this.field.relationship\n\n return null\n },\n resourcePath() {\n if (this.resource && this.resource.path) {\n return this.resource.path\n }\n\n if (this.field && this.field.path) {\n return this.field.path\n }\n\n return this.resourceName.toLowerCase()\n },\n },\n}\n","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nvar freeGlobal = require('./_freeGlobal');\n/** Detect free variable `self`. */\n\n\nvar freeSelf = (typeof self === \"undefined\" ? \"undefined\" : _typeof(self)) == 'object' && self && self.Object === Object && self;\n/** Used as a reference to the global object. */\n\nvar root = freeGlobal || freeSelf || Function('return this')();\nmodule.exports = root;","/**\n * Checks if `value` is classified as an `Array` object.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an array, else `false`.\n * @example\n *\n * _.isArray([1, 2, 3]);\n * // => true\n *\n * _.isArray(document.body.children);\n * // => false\n *\n * _.isArray('abc');\n * // => false\n *\n * _.isArray(_.noop);\n * // => false\n */\nvar isArray = Array.isArray;\nmodule.exports = isArray;","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = _typeof(value);\n\n return value != null && (type == 'object' || type == 'function');\n}\n\nmodule.exports = isObject;","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n/*!\n * vuex v3.5.1\n * (c) 2020 Evan You\n * @license MIT\n */\nfunction applyMixin(Vue) {\n var version = Number(Vue.version.split('.')[0]);\n\n if (version >= 2) {\n Vue.mixin({\n beforeCreate: vuexInit\n });\n } else {\n // override init and inject vuex init procedure\n // for 1.x backwards compatibility.\n var _init = Vue.prototype._init;\n\n Vue.prototype._init = function (options) {\n if (options === void 0) options = {};\n options.init = options.init ? [vuexInit].concat(options.init) : vuexInit;\n\n _init.call(this, options);\n };\n }\n /**\n * Vuex init hook, injected into each instances init hooks list.\n */\n\n\n function vuexInit() {\n var options = this.$options; // store injection\n\n if (options.store) {\n this.$store = typeof options.store === 'function' ? options.store() : options.store;\n } else if (options.parent && options.parent.$store) {\n this.$store = options.parent.$store;\n }\n }\n}\n\nvar target = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};\nvar devtoolHook = target.__VUE_DEVTOOLS_GLOBAL_HOOK__;\n\nfunction devtoolPlugin(store) {\n if (!devtoolHook) {\n return;\n }\n\n store._devtoolHook = devtoolHook;\n devtoolHook.emit('vuex:init', store);\n devtoolHook.on('vuex:travel-to-state', function (targetState) {\n store.replaceState(targetState);\n });\n store.subscribe(function (mutation, state) {\n devtoolHook.emit('vuex:mutation', mutation, state);\n }, {\n prepend: true\n });\n store.subscribeAction(function (action, state) {\n devtoolHook.emit('vuex:action', action, state);\n }, {\n prepend: true\n });\n}\n/**\n * Get the first item that pass the test\n * by second argument function\n *\n * @param {Array} list\n * @param {Function} f\n * @return {*}\n */\n\n\nfunction find(list, f) {\n return list.filter(f)[0];\n}\n/**\n * Deep copy the given object considering circular structure.\n * This function caches all nested objects and its copies.\n * If it detects circular structure, use cached copy to avoid infinite loop.\n *\n * @param {*} obj\n * @param {Array