annotate plugins/managesieve/codemirror/lib/codemirror.js @ 41:d2414df68d78 default tip

Updated by Alex S Grebenschikov (www.poralix.com) to make it compatible with RoundCube 1.3.0
author Charlie Root
date Fri, 24 Jan 2025 14:20:15 -0500
parents 1e000243b222
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 // This is CodeMirror (http://codemirror.net), a code editor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 // implemented in JavaScript on top of the browser's DOM.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 //
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 // You can find some technical background for some of the code below
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 // at http://marijnhaverbeke.nl/blog/#cm-internals .
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 (function (global, factory) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 typeof define === 'function' && define.amd ? define(factory) :
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 (global.CodeMirror = factory());
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 }(this, (function () { 'use strict';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 // Kludges for bugs and behavior differences that can't be feature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 // detected are enabled based on userAgent etc sniffing.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 var userAgent = navigator.userAgent
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 var platform = navigator.platform
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 var gecko = /gecko\/\d/i.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 var ie_upto10 = /MSIE \d/.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 var ie = ie_upto10 || ie_11up
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 var webkit = /WebKit\//.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 var chrome = /Chrome\//.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 var presto = /Opera\//.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 var safari = /Apple Computer/.test(navigator.vendor)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 var phantom = /PhantomJS/.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 var ios = /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 // This is woefully incomplete. Suggestions for alternative methods welcome.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 var mac = ios || /Mac/.test(platform)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 var chromeOS = /\bCrOS\b/.test(userAgent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 var windows = /win/i.test(platform)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 if (presto_version) { presto_version = Number(presto_version[1]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 if (presto_version && presto_version >= 15) { presto = false; webkit = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 var captureRightClick = gecko || (ie && ie_version >= 9)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 var rmClass = function(node, cls) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 var current = node.className
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 var match = classTest(cls).exec(current)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 if (match) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 var after = current.slice(match.index + match[0].length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 node.className = current.slice(0, match.index) + (after ? match[1] + after : "")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 function removeChildren(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 for (var count = e.childNodes.length; count > 0; --count)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 { e.removeChild(e.firstChild) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 return e
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 function removeChildrenAndAdd(parent, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 return removeChildren(parent).appendChild(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 function elt(tag, content, className, style) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 var e = document.createElement(tag)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 if (className) { e.className = className }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 if (style) { e.style.cssText = style }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 if (typeof content == "string") { e.appendChild(document.createTextNode(content)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 return e
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 var range
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 if (document.createRange) { range = function(node, start, end, endNode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 var r = document.createRange()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 r.setEnd(endNode || node, end)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 r.setStart(node, start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 return r
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 else { range = function(node, start, end) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 var r = document.body.createTextRange()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 try { r.moveToElementText(node.parentNode) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 catch(e) { return r }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 r.collapse(true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 r.moveEnd("character", end)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 r.moveStart("character", start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 return r
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 function contains(parent, child) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 if (child.nodeType == 3) // Android browser always returns false when child is a textnode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 { child = child.parentNode }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 if (parent.contains)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 { return parent.contains(child) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 do {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 if (child.nodeType == 11) { child = child.host }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 if (child == parent) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 } while (child = child.parentNode)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 function activeElt() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107 // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 // IE < 10 will throw when accessed while the page is loading or in an iframe.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 var activeElement
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 try {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 activeElement = document.activeElement
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 } catch(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 activeElement = document.body || null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 while (activeElement && activeElement.root && activeElement.root.activeElement)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 { activeElement = activeElement.root.activeElement }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 return activeElement
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 function addClass(node, cls) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 var current = node.className
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 function joinClasses(a, b) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 var as = a.split(" ")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 for (var i = 0; i < as.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i] } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 return b
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 var selectInput = function(node) { node.select() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 if (ios) // Mobile Safari apparently has a bug where select() is broken.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 else if (ie) // Suppress mysterious IE10 errors
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 { selectInput = function(node) { try { node.select() } catch(_e) {} } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 function bind(f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 var args = Array.prototype.slice.call(arguments, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 return function(){return f.apply(null, args)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 function copyObj(obj, target, overwrite) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 if (!target) { target = {} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 for (var prop in obj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 { target[prop] = obj[prop] } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 return target
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 // Counts the column offset in a string, taking tabs into account.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 // Used mostly to find indentation.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 function countColumn(string, end, tabSize, startIndex, startValue) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 if (end == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 end = string.search(/[^\s\u00a0]/)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 if (end == -1) { end = string.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 for (var i = startIndex || 0, n = startValue || 0;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 var nextTab = string.indexOf("\t", i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 if (nextTab < 0 || nextTab >= end)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 { return n + (end - i) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 n += nextTab - i
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 n += tabSize - (n % tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 i = nextTab + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 function Delayed() {this.id = null}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 Delayed.prototype.set = function(ms, f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 clearTimeout(this.id)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 this.id = setTimeout(f, ms)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 function indexOf(array, elt) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175 for (var i = 0; i < array.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 { if (array[i] == elt) { return i } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 return -1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 // Number of pixels added to scroller and sizer to hide scrollbar
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 var scrollerGap = 30
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 // Returned or thrown by various protocols to signal 'I'm not
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 // handling this'.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 var Pass = {toString: function(){return "CodeMirror.Pass"}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 // Reused option objects for setSelection & friends
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 var sel_dontScroll = {scroll: false};
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 var sel_mouse = {origin: "*mouse"};
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 var sel_move = {origin: "+move"}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 // The inverse of countColumn -- find the offset that corresponds to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 // a particular column.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 function findColumn(string, goal, tabSize) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 for (var pos = 0, col = 0;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 var nextTab = string.indexOf("\t", pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 if (nextTab == -1) { nextTab = string.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 var skipped = nextTab - pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 if (nextTab == string.length || col + skipped >= goal)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 { return pos + Math.min(skipped, goal - col) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 col += nextTab - pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 col += tabSize - (col % tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 pos = nextTab + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 if (col >= goal) { return pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 var spaceStrs = [""]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 function spaceStr(n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 while (spaceStrs.length <= n)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 { spaceStrs.push(lst(spaceStrs) + " ") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 return spaceStrs[n]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 function lst(arr) { return arr[arr.length-1] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 function map(array, f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220 return out
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 function insertSorted(array, value, score) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 var pos = 0, priority = score(value)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 while (pos < array.length && score(array[pos]) <= priority) { pos++ }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 array.splice(pos, 0, value)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 function nothing() {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 function createObj(base, props) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 var inst
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 if (Object.create) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 inst = Object.create(base)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 nothing.prototype = base
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 inst = new nothing()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 if (props) { copyObj(props, inst) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 return inst
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 function isWordCharBasic(ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 return /\w/.test(ch) || ch > "\x80" &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 function isWordChar(ch, helper) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 if (!helper) { return isWordCharBasic(ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 return helper.test(ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 function isEmpty(obj) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 // Extending unicode characters. A series of a non-extending char +
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260 // any number of extending chars is treated as a single unit as far
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 // as editing and measuring is concerned. This is not fully correct,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 // since some scripts/fonts/browsers also treat other configurations
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 // of code points as a group.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 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]/
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 // The display handles the DOM integration, both for input reading
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268 // and content drawing. It holds references to DOM nodes and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 // display-related state.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 function Display(place, doc, input) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 var d = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 this.input = input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 // Covers bottom-right square when both scrollbars are present.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 d.scrollbarFiller.setAttribute("cm-not-content", "true")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 // Covers bottom of gutter when coverGutterNextToScrollbar is on
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 // and h scrollbar is present.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 d.gutterFiller.setAttribute("cm-not-content", "true")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 // Will contain the actual code, positioned to cover the viewport.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 d.lineDiv = elt("div", null, "CodeMirror-code")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 // Elements are added to these to represent selection and cursors.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 d.cursorDiv = elt("div", null, "CodeMirror-cursors")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 // A visibility: hidden element used to find the size of things.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 d.measure = elt("div", null, "CodeMirror-measure")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 // When lines outside of the viewport are measured, they are drawn in this.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 d.lineMeasure = elt("div", null, "CodeMirror-measure")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 // Wraps everything that needs to exist inside the vertically-padded coordinate system
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 null, "position: relative; outline: none")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 // Moved around its parent to cover visible view.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295 d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 // Set to the height of the document, allowing scrolling.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 d.sizerWidth = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 // Behavior of elts with overflow: auto and padding is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 // inconsistent across browsers. This is used to ensure the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 // scrollable area is big enough.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 // Will contain the gutters, if any.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 d.gutters = elt("div", null, "CodeMirror-gutters")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 d.lineGutter = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 // Actual scrollable element.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 d.scroller.setAttribute("tabIndex", "-1")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 // The element in which the editor lives.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 if (place) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 if (place.appendChild) { place.appendChild(d.wrapper) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 else { place(d.wrapper) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 // Current rendered range (may be bigger than the view window).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322 d.viewFrom = d.viewTo = doc.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323 d.reportedViewFrom = d.reportedViewTo = doc.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 // Information about the rendered lines.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 d.view = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 d.renderedView = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 // Holds info about a single rendered line when it was rendered
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 // for measurement, while not in view.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 d.externalMeasured = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 // Empty space (in pixels) above the view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331 d.viewOffset = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 d.lastWrapHeight = d.lastWrapWidth = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 d.updateLineNumbers = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 d.nativeBarWidth = d.barHeight = d.barWidth = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 d.scrollbarsClipped = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338 // Used to only resize the line number gutter when necessary (when
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 // the amount of lines crosses a boundary that makes its width change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 // Set to true when a non-horizontal-scrolling line widget is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 // added. As an optimization, line widget aligning is skipped when
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 // this is false.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 d.alignWidgets = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346 d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 // Tracks the maximum line length so that the horizontal scrollbar
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 // can be kept static when scrolling.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 d.maxLine = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 d.maxLineLength = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 d.maxLineChanged = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 // Used for measuring wheel scrolling granularity
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357 // True when shift is held down.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 d.shift = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 // Used to track whether anything happened since the context menu
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361 // was opened.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 d.selForContextMenu = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 d.activeTouch = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 input.init(d)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 // Find the line object corresponding to the given line number.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 function getLine(doc, n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371 n -= doc.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 var chunk = doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 while (!chunk.lines) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 for (var i = 0;; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 var child = chunk.children[i], sz = child.chunkSize()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 if (n < sz) { chunk = child; break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378 n -= sz
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381 return chunk.lines[n]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384 // Get the part of a document between two positions, as an array of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 // strings.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386 function getBetween(doc, start, end) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 var out = [], n = start.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388 doc.iter(start.line, end.line + 1, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 var text = line.text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390 if (n == end.line) { text = text.slice(0, end.ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 if (n == start.line) { text = text.slice(start.ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392 out.push(text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 ++n
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 return out
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 // Get the lines between from and to, as array of strings.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 function getLines(doc, from, to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 doc.iter(from, to, function (line) { out.push(line.text) }) // iter aborts when callback returns truthy value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 return out
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 // Update the height of a line, propagating the height change
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405 // upwards to parent nodes.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 function updateLineHeight(line, height) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 var diff = height - line.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408 if (diff) { for (var n = line; n; n = n.parent) { n.height += diff } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 // Given a line object, find its line number by walking up through
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 // its parent links.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 function lineNo(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 if (line.parent == null) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 var cur = line.parent, no = indexOf(cur.lines, line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 for (var i = 0;; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 if (chunk.children[i] == cur) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 no += chunk.children[i].chunkSize()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 return no + cur.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425 // Find the line at the given vertical position, using the height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 // information in the document tree.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 function lineAtHeight(chunk, h) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 var n = chunk.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 outer: do {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430 for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 var child = chunk.children[i$1], ch = child.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 if (h < ch) { chunk = child; continue outer }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433 h -= ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 n += child.chunkSize()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436 return n
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 } while (!chunk.lines)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438 var i = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 for (; i < chunk.lines.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 var line = chunk.lines[i], lh = line.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441 if (h < lh) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 h -= lh
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 return n + i
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447 function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449 function lineNumberFor(options, i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 return String(options.lineNumberFormatter(i + options.firstLineNumber))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 // A Pos instance represents a position within the text.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 function Pos (line, ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455 if (!(this instanceof Pos)) { return new Pos(line, ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 this.line = line; this.ch = ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459 // Compare two positions, return 0 if they are the same, a negative
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460 // number when a is less, and a positive number otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463 function copyPos(x) {return Pos(x.line, x.ch)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464 function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465 function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 // Most of the external API clips given positions to make sure they
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468 // actually exist within the document.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469 function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470 function clipPos(doc, pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471 if (pos.line < doc.first) { return Pos(doc.first, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472 var last = doc.first + doc.size - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473 if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474 return clipToLen(pos, getLine(doc, pos.line).text.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
475 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476 function clipToLen(pos, linelen) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 var ch = pos.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478 if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 else if (ch < 0) { return Pos(pos.line, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 else { return pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 function clipPosArray(doc, array) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485 return out
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 // Optimize some code when these features are not used.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489 var sawReadOnlySpans = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490 var sawCollapsedSpans = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 function seeReadOnlySpans() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493 sawReadOnlySpans = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496 function seeCollapsedSpans() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 sawCollapsedSpans = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 // TEXTMARKER SPANS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 function MarkedSpan(marker, from, to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503 this.marker = marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 this.from = from; this.to = to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507 // Search an array of spans for a span matching the given marker.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508 function getMarkedSpanFor(spans, marker) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509 if (spans) { for (var i = 0; i < spans.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510 var span = spans[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 if (span.marker == marker) { return span }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514 // Remove a span from an array, returning undefined if no spans are
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515 // left (we don't store arrays for lines without spans).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516 function removeMarkedSpan(spans, span) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517 var r
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 for (var i = 0; i < spans.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 { if (spans[i] != span) { (r || (r = [])).push(spans[i]) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520 return r
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 // Add a span to a line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523 function addMarkedSpan(line, span) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525 span.marker.attachLine(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 // Used for the algorithm that adjusts markers for a change in the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 // document. These functions cut an array of spans at a given
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530 // character position, returning an array of remaining chunks (or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 // undefined if nothing remains).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 function markedSpansBefore(old, startCh, isInsert) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 var nw
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 if (old) { for (var i = 0; i < old.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535 var span = old[i], marker = span.marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536 var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
538 var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
539 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
540 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541 return nw
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
543 function markedSpansAfter(old, endCh, isInsert) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544 var nw
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 if (old) { for (var i = 0; i < old.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 var span = old[i], marker = span.marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549 var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 span.to == null ? null : span.to - endCh))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553 return nw
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556 // Given a change object, compute the new set of marker spans that
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 // cover the line in which the change took place. Removes spans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 // entirely within the change, reconnects spans belonging to the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 // same marker that appear on both sides of the change, and cuts off
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560 // spans partially within the change. Returns an array of span
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 // arrays with one element for each line in (after) the change.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 function stretchSpansOverChange(doc, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563 if (change.full) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564 var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565 var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 if (!oldFirst && !oldLast) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568 var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 // Get the spans that 'stick out' on both sides
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570 var first = markedSpansBefore(oldFirst, startCh, isInsert)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 var last = markedSpansAfter(oldLast, endCh, isInsert)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 // Next, merge those two ends
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574 var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 if (first) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576 // Fix up .to properties of first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 for (var i = 0; i < first.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 var span = first[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579 if (span.to == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580 var found = getMarkedSpanFor(last, span.marker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581 if (!found) { span.to = startCh }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 else if (sameLine) { span.to = found.to == null ? null : found.to + offset }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 if (last) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587 // Fix up .from in last (or move them into first in case of sameLine)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588 for (var i$1 = 0; i$1 < last.length; ++i$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 var span$1 = last[i$1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590 if (span$1.to != null) { span$1.to += offset }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591 if (span$1.from == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592 var found$1 = getMarkedSpanFor(first, span$1.marker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
593 if (!found$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594 span$1.from = offset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 if (sameLine) { (first || (first = [])).push(span$1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
598 span$1.from += offset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
599 if (sameLine) { (first || (first = [])).push(span$1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
600 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 // Make sure we didn't create any zero-length spans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604 if (first) { first = clearEmptySpans(first) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605 if (last && last != first) { last = clearEmptySpans(last) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 var newMarkers = [first]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608 if (!sameLine) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609 // Fill gap with whole-line-spans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610 var gap = change.text.length - 2, gapMarkers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611 if (gap > 0 && first)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612 { for (var i$2 = 0; i$2 < first.length; ++i$2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613 { if (first[i$2].to == null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614 { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)) } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615 for (var i$3 = 0; i$3 < gap; ++i$3)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 { newMarkers.push(gapMarkers) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 newMarkers.push(last)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 return newMarkers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
621
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622 // Remove spans that are empty and don't have a clearWhenEmpty
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623 // option of false.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 function clearEmptySpans(spans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625 for (var i = 0; i < spans.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626 var span = spans[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628 { spans.splice(i--, 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630 if (!spans.length) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631 return spans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634 // Used to 'clip' out readOnly ranges when making a change.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635 function removeReadOnlyRanges(doc, from, to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636 var markers = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 doc.iter(from.line, to.line + 1, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638 if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 var mark = line.markedSpans[i].marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641 { (markers || (markers = [])).push(mark) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 if (!markers) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645 var parts = [{from: from, to: to}]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646 for (var i = 0; i < markers.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
647 var mk = markers[i], m = mk.find(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648 for (var j = 0; j < parts.length; ++j) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 var p = parts[j]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
650 if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651 var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653 { newParts.push({from: p.from, to: m.from}) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654 if (dto > 0 || !mk.inclusiveRight && !dto)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 { newParts.push({from: m.to, to: p.to}) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656 parts.splice.apply(parts, newParts)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 j += newParts.length - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 return parts
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663 // Connect or disconnect spans from a line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664 function detachMarkedSpans(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665 var spans = line.markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 if (!spans) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667 for (var i = 0; i < spans.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
668 { spans[i].marker.detachLine(line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
669 line.markedSpans = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
670 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
671 function attachMarkedSpans(line, spans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
672 if (!spans) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 for (var i = 0; i < spans.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
674 { spans[i].marker.attachLine(line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
675 line.markedSpans = spans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
676 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
678 // Helpers used when computing which overlapping collapsed span
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
679 // counts as the larger one.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
680 function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681 function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683 // Returns a number indicating which of two overlapping collapsed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 // spans is larger (and thus includes the other). Falls back to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
685 // comparing ids when the spans cover exactly the same range.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
686 function compareCollapsedMarkers(a, b) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
687 var lenDiff = a.lines.length - b.lines.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688 if (lenDiff != 0) { return lenDiff }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
689 var aPos = a.find(), bPos = b.find()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
690 var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
691 if (fromCmp) { return -fromCmp }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
693 if (toCmp) { return toCmp }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
694 return b.id - a.id
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
695 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
697 // Find out whether a line ends or starts in a collapsed span. If
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
698 // so, return the marker for that span.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
699 function collapsedSpanAtSide(line, start) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700 var sps = sawCollapsedSpans && line.markedSpans, found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 if (sps) { for (var sp = void 0, i = 0; i < sps.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702 sp = sps[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
704 (!found || compareCollapsedMarkers(found, sp.marker) < 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 { found = sp.marker }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
707 return found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
708 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
709 function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
710 function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
711
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
712 // Test whether there exists a collapsed span that partially
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 // overlaps (covers the start or end, but not both) of a new span.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714 // Such overlap is not allowed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715 function conflictingCollapsedRange(doc, lineNo$$1, from, to, marker) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716 var line = getLine(doc, lineNo$$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 var sps = sawCollapsedSpans && line.markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718 if (sps) { for (var i = 0; i < sps.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 var sp = sps[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720 if (!sp.marker.collapsed) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721 var found = sp.marker.find(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
723 var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
724 if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
725 if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
726 fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
727 { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
728 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
729 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
731 // A visual line is a line as drawn on the screen. Folding, for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
732 // example, can cause multiple logical lines to appear on the same
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733 // visual line. This finds the start of the visual line that the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
734 // given line is part of (usually that is the line itself).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735 function visualLine(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736 var merged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
737 while (merged = collapsedSpanAtStart(line))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
738 { line = merged.find(-1, true).line }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
739 return line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
740 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
741
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742 // Returns an array of logical lines that continue the visual line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
743 // started by the argument, or undefined if there are no such lines.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
744 function visualLineContinued(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
745 var merged, lines
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
746 while (merged = collapsedSpanAtEnd(line)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
747 line = merged.find(1, true).line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
748 ;(lines || (lines = [])).push(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
749 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
750 return lines
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753 // Get the line number of the start of the visual line that the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754 // given line number is part of.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755 function visualLineNo(doc, lineN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756 var line = getLine(doc, lineN), vis = visualLine(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757 if (line == vis) { return lineN }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758 return lineNo(vis)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 // Get the line number of the start of the next visual line after
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762 // the given line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763 function visualLineEndNo(doc, lineN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 if (lineN > doc.lastLine()) { return lineN }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 var line = getLine(doc, lineN), merged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766 if (!lineIsHidden(doc, line)) { return lineN }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 while (merged = collapsedSpanAtEnd(line))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 { line = merged.find(1, true).line }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769 return lineNo(line) + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 // Compute whether a line is hidden. Lines count as hidden when they
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773 // are part of a visual line that starts with another line, or when
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774 // they are entirely covered by collapsed, non-widget span.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775 function lineIsHidden(doc, line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776 var sps = sawCollapsedSpans && line.markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 if (sps) { for (var sp = void 0, i = 0; i < sps.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 sp = sps[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779 if (!sp.marker.collapsed) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 if (sp.from == null) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781 if (sp.marker.widgetNode) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782 if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783 { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 function lineIsHiddenInner(doc, line, span) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787 if (span.to == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788 var end = span.marker.find(1, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789 return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791 if (span.marker.inclusiveRight && span.to == line.text.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792 { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 for (var sp = void 0, i = 0; i < line.markedSpans.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 sp = line.markedSpans[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795 if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796 (sp.to == null || sp.to != span.from) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 lineIsHiddenInner(doc, line, sp)) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802 // Find the height above the given line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 function heightAtLine(lineObj) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804 lineObj = visualLine(lineObj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 var h = 0, chunk = lineObj.parent
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 for (var i = 0; i < chunk.lines.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808 var line = chunk.lines[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809 if (line == lineObj) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 else { h += line.height }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812 for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813 for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 var cur = p.children[i$1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815 if (cur == chunk) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 else { h += cur.height }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 return h
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822 // Compute the character length of a line, taking into account
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
823 // collapsed ranges (see markText) that might hide parts, and join
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824 // other lines onto it.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825 function lineLength(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826 if (line.height == 0) { return 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827 var len = line.text.length, merged, cur = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 while (merged = collapsedSpanAtStart(cur)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 var found = merged.find(0, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830 cur = found.from.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 len += found.from.ch - found.to.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 cur = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834 while (merged = collapsedSpanAtEnd(cur)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835 var found$1 = merged.find(0, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 len -= cur.text.length - found$1.from.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837 cur = found$1.to.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838 len += cur.text.length - found$1.to.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 return len
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 // Find the longest line in the document.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844 function findMaxLine(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845 var d = cm.display, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846 d.maxLine = getLine(doc, doc.first)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847 d.maxLineLength = lineLength(d.maxLine)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
848 d.maxLineChanged = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849 doc.iter(function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850 var len = lineLength(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851 if (len > d.maxLineLength) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 d.maxLineLength = len
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 d.maxLine = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858 // BIDI HELPERS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860 function iterateBidiSections(order, from, to, f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861 if (!order) { return f(from, to, "ltr") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862 var found = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863 for (var i = 0; i < order.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864 var part = order[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865 if (part.from < to && part.to > from || from == to && part.to == from) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866 f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 found = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 if (!found) { f(from, to, "ltr") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873 function bidiLeft(part) { return part.level % 2 ? part.to : part.from }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 function bidiRight(part) { return part.level % 2 ? part.from : part.to }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876 function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877 function lineRight(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878 var order = getOrder(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879 if (!order) { return line.text.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 return bidiRight(lst(order))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883 function compareBidiLevel(order, a, b) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 var linedir = order[0].level
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885 if (a == linedir) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 if (b == linedir) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887 return a < b
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890 var bidiOther = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891 function getBidiPartAt(order, pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892 var found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893 bidiOther = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
894 for (var i = 0; i < order.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 var cur = order[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896 if (cur.from < pos && cur.to > pos) { return i }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 if ((cur.from == pos || cur.to == pos)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 if (found == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899 found = i
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900 } else if (compareBidiLevel(order, cur.level, order[found].level)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901 if (cur.from != cur.to) { bidiOther = found }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902 return i
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904 if (cur.from != cur.to) { bidiOther = i }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905 return found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909 return found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912 function moveInLine(line, pos, dir, byUnit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913 if (!byUnit) { return pos + dir }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 do { pos += dir }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 while (pos > 0 && isExtendingChar(line.text.charAt(pos)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 return pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 // This is needed in order to move 'visually' through bi-directional
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920 // text -- i.e., pressing left should make the cursor go left, even
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921 // when in RTL text. The tricky part is the 'jumps', where RTL and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 // LTR text touch each other. This often requires the cursor offset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923 // to move more than one unit, in order to visually move one unit.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924 function moveVisually(line, start, dir, byUnit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925 var bidi = getOrder(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 if (!bidi) { return moveLogically(line, start, dir, byUnit) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927 var pos = getBidiPartAt(bidi, start), part = bidi[pos]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 if (target > part.from && target < part.to) { return target }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 if (target == part.from || target == part.to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933 if (getBidiPartAt(bidi, target) == pos) { return target }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
934 part = bidi[pos += dir]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 return (dir > 0) == part.level % 2 ? part.to : part.from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 part = bidi[pos += dir]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938 if (!part) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 if ((dir > 0) == part.level % 2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940 { target = moveInLine(line, part.to, -1, byUnit) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 { target = moveInLine(line, part.from, 1, byUnit) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 function moveLogically(line, start, dir, byUnit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948 var target = start + dir
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949 if (byUnit) { while (target > 0 && isExtendingChar(line.text.charAt(target))) { target += dir } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950 return target < 0 || target > line.text.length ? null : target
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 // Bidirectional ordering algorithm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954 // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 // that this (partially) implements.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957 // One-char codes used for character types:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958 // L (L): Left-to-Right
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 // R (R): Right-to-Left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960 // r (AL): Right-to-Left Arabic
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 // 1 (EN): European Number
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962 // + (ES): European Number Separator
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963 // % (ET): European Number Terminator
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 // n (AN): Arabic Number
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965 // , (CS): Common Number Separator
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 // m (NSM): Non-Spacing Mark
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 // b (BN): Boundary Neutral
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968 // s (B): Paragraph Separator
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 // t (S): Segment Separator
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970 // w (WS): Whitespace
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 // N (ON): Other Neutrals
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973 // Returns null if characters are ordered as they appear
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
974 // (left-to-right), or an array of sections ({from, to, level}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975 // objects) in the order in which they occur visually.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976 var bidiOrdering = (function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 // Character types for codepoints 0 to 0xff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978 var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979 // Character types for codepoints 0x600 to 0x6ff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980 var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981 function charType(code) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 if (code <= 0xf7) { return lowTypes.charAt(code) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983 else if (0x590 <= code && code <= 0x5f4) { return "R" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984 else if (0x600 <= code && code <= 0x6ed) { return arabicTypes.charAt(code - 0x600) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 else if (0x6ee <= code && code <= 0x8ac) { return "r" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 else if (0x2000 <= code && code <= 0x200b) { return "w" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987 else if (code == 0x200c) { return "b" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988 else { return "L" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992 var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993 // Browsers seem to always treat the boundaries of block elements as being L.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994 var outerType = "L"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 function BidiSpan(level, from, to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 this.level = level
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998 this.from = from; this.to = to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 return function(str) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 if (!bidiRE.test(str)) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003 var len = str.length, types = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1004 for (var i = 0; i < len; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005 { types.push(charType(str.charCodeAt(i))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1006
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1007 // W1. Examine each non-spacing mark (NSM) in the level run, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008 // change the type of the NSM to the type of the previous
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 // character. If the NSM is at the start of the level run, it will
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010 // get the type of sor.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012 var type = types[i$1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 if (type == "m") { types[i$1] = prev }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014 else { prev = type }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017 // W2. Search backwards from each instance of a European number
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018 // until the first strong type (R, L, AL, or sor) is found. If an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019 // AL is found, change the type of the European number to Arabic
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 // number.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 // W3. Change all ALs to R.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023 var type$1 = types[i$2]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024 if (type$1 == "1" && cur == "r") { types[i$2] = "n" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R" } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028 // W4. A single European separator between two European numbers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029 // changes to a European number. A single common separator between
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030 // two numbers of the same type changes to that type.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031 for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032 var type$2 = types[i$3]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 else if (type$2 == "," && prev$1 == types[i$3+1] &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035 (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036 prev$1 = type$2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 // W5. A sequence of European terminators adjacent to European
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040 // numbers changes to all European numbers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041 // W6. Otherwise, separators and terminators change to Other
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042 // Neutral.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043 for (var i$4 = 0; i$4 < len; ++i$4) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044 var type$3 = types[i$4]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045 if (type$3 == ",") { types[i$4] = "N" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 else if (type$3 == "%") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047 var end = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048 for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049 var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050 for (var j = i$4; j < end; ++j) { types[j] = replace }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051 i$4 = end - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 // W7. Search backwards from each instance of a European number
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056 // until the first strong type (R, L, or sor) is found. If an L is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057 // found, then change the type of the European number to L.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058 for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 var type$4 = types[i$5]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060 if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 else if (isStrong.test(type$4)) { cur$1 = type$4 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1063
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1064 // N1. A sequence of neutrals takes the direction of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1065 // surrounding strong text if the text on both sides has the same
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1066 // direction. European and Arabic numbers act as if they were R in
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1067 // terms of their influence on neutrals. Start-of-level-run (sor)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1068 // and end-of-level-run (eor) are used at level run boundaries.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069 // N2. Any remaining neutrals take the embedding direction.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 for (var i$6 = 0; i$6 < len; ++i$6) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071 if (isNeutral.test(types[i$6])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072 var end$1 = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073 for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 var before = (i$6 ? types[i$6-1] : outerType) == "L"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 var after = (end$1 < len ? types[end$1] : outerType) == "L"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076 var replace$1 = before || after ? "L" : "R"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077 for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078 i$6 = end$1 - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1079 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1081
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082 // Here we depart from the documented algorithm, in order to avoid
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1083 // building up an actual levels array. Since there are only three
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1084 // levels (0, 1, 2) in an implementation that doesn't take
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085 // explicit embedding into account, we can build up the order on
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086 // the fly, without following the level-based algorithm.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1087 var order = [], m
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1088 for (var i$7 = 0; i$7 < len;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1089 if (countsAsLeft.test(types[i$7])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1090 var start = i$7
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1091 for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1092 order.push(new BidiSpan(0, start, i$7))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1093 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1094 var pos = i$7, at = order.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1095 for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096 for (var j$2 = pos; j$2 < i$7;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 if (countsAsNum.test(types[j$2])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1098 if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 var nstart = j$2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100 for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101 order.splice(at, 0, new BidiSpan(2, nstart, j$2))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 pos = j$2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 } else { ++j$2 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105 if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 if (order[0].level == 1 && (m = str.match(/^\s+/))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109 order[0].from = m[0].length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110 order.unshift(new BidiSpan(0, 0, m[0].length))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112 if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 lst(order).to -= m[0].length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114 order.push(new BidiSpan(0, len - m[0].length, len))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116 if (order[0].level == 2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 { order.unshift(new BidiSpan(1, order[0].to, order[0].to)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118 if (order[0].level != lst(order).level)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 { order.push(new BidiSpan(order[0].level, len, len)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121 return order
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1122 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1123 })()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1124
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1125 // Get the bidi ordering for the given line (and cache it). Returns
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1126 // false for lines that are fully left-to-right, and an array of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1127 // BidiSpan objects otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1128 function getOrder(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1129 var order = line.order
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1130 if (order == null) { order = line.order = bidiOrdering(line.text) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1131 return order
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1132 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1133
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1134 // EVENT HANDLING
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1135
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1136 // Lightweight event framework. on/off also work on DOM nodes,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1137 // registering native DOM handlers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1138
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1139 var noHandlers = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1140
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1141 var on = function(emitter, type, f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1142 if (emitter.addEventListener) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1143 emitter.addEventListener(type, f, false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1144 } else if (emitter.attachEvent) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1145 emitter.attachEvent("on" + type, f)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1146 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1147 var map$$1 = emitter._handlers || (emitter._handlers = {})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1148 map$$1[type] = (map$$1[type] || noHandlers).concat(f)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1149 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1150 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1151
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1152 function getHandlers(emitter, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1153 return emitter._handlers && emitter._handlers[type] || noHandlers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1154 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1155
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1156 function off(emitter, type, f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1157 if (emitter.removeEventListener) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1158 emitter.removeEventListener(type, f, false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1159 } else if (emitter.detachEvent) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1160 emitter.detachEvent("on" + type, f)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1161 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1162 var map$$1 = emitter._handlers, arr = map$$1 && map$$1[type]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1163 if (arr) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1164 var index = indexOf(arr, f)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1165 if (index > -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1166 { map$$1[type] = arr.slice(0, index).concat(arr.slice(index + 1)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1167 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1168 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1169 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1170
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1171 function signal(emitter, type /*, values...*/) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1172 var handlers = getHandlers(emitter, type)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1173 if (!handlers.length) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1174 var args = Array.prototype.slice.call(arguments, 2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1175 for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1176 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1177
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1178 // The DOM events that CodeMirror handles can be overridden by
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1179 // registering a (non-DOM) handler on the editor for the event name,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1180 // and preventDefault-ing the event in that handler.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1181 function signalDOMEvent(cm, e, override) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1182 if (typeof e == "string")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1183 { e = {type: e, preventDefault: function() { this.defaultPrevented = true }} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1184 signal(cm, override || e.type, cm, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1185 return e_defaultPrevented(e) || e.codemirrorIgnore
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1186 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1187
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1188 function signalCursorActivity(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1189 var arr = cm._handlers && cm._handlers.cursorActivity
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1190 if (!arr) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1191 var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = [])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1192 for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1193 { set.push(arr[i]) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1194 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1195
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1196 function hasHandler(emitter, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1197 return getHandlers(emitter, type).length > 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1198 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1199
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1200 // Add on and off methods to a constructor's prototype, to make
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1201 // registering events on such objects more convenient.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1202 function eventMixin(ctor) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1203 ctor.prototype.on = function(type, f) {on(this, type, f)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1204 ctor.prototype.off = function(type, f) {off(this, type, f)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1205 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1206
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1207 // Due to the fact that we still support jurassic IE versions, some
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1208 // compatibility wrappers are needed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1209
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1210 function e_preventDefault(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1211 if (e.preventDefault) { e.preventDefault() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1212 else { e.returnValue = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1213 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1214 function e_stopPropagation(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1215 if (e.stopPropagation) { e.stopPropagation() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1216 else { e.cancelBubble = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1217 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1218 function e_defaultPrevented(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1219 return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1220 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1221 function e_stop(e) {e_preventDefault(e); e_stopPropagation(e)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1222
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1223 function e_target(e) {return e.target || e.srcElement}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1224 function e_button(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1225 var b = e.which
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1226 if (b == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1227 if (e.button & 1) { b = 1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1228 else if (e.button & 2) { b = 3 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1229 else if (e.button & 4) { b = 2 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1230 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1231 if (mac && e.ctrlKey && b == 1) { b = 3 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1232 return b
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1233 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1234
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1235 // Detect drag-and-drop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1236 var dragAndDrop = function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1237 // There is *some* kind of drag-and-drop support in IE6-8, but I
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1238 // couldn't get it to work yet.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1239 if (ie && ie_version < 9) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1240 var div = elt('div')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1241 return "draggable" in div || "dragDrop" in div
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1242 }()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1243
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1244 var zwspSupported
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1245 function zeroWidthElement(measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1246 if (zwspSupported == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1247 var test = elt("span", "\u200b")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1248 removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1249 if (measure.firstChild.offsetHeight != 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1250 { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1251 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1252 var node = zwspSupported ? elt("span", "\u200b") :
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1253 elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1254 node.setAttribute("cm-text", "")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1255 return node
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1256 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1257
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1258 // Feature-detect IE's crummy client rect reporting for bidi text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1259 var badBidiRects
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1260 function hasBadBidiRects(measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1261 if (badBidiRects != null) { return badBidiRects }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1262 var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1263 var r0 = range(txt, 0, 1).getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1264 var r1 = range(txt, 1, 2).getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1265 removeChildren(measure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1266 if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1267 return badBidiRects = (r1.right - r0.right < 3)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1268 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1269
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1270 // See if "".split is the broken IE version, if so, provide an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1271 // alternative way to split lines.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1272 var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1273 var pos = 0, result = [], l = string.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1274 while (pos <= l) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1275 var nl = string.indexOf("\n", pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1276 if (nl == -1) { nl = string.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1277 var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1278 var rt = line.indexOf("\r")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1279 if (rt != -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1280 result.push(line.slice(0, rt))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1281 pos += rt + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1282 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1283 result.push(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1284 pos = nl + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1285 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1286 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1287 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1288 } : function (string) { return string.split(/\r\n?|\n/); }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1289
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1290 var hasSelection = window.getSelection ? function (te) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1291 try { return te.selectionStart != te.selectionEnd }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1292 catch(e) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1293 } : function (te) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1294 var range$$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1295 try {range$$1 = te.ownerDocument.selection.createRange()}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1296 catch(e) {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1297 if (!range$$1 || range$$1.parentElement() != te) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1298 return range$$1.compareEndPoints("StartToEnd", range$$1) != 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1299 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1300
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1301 var hasCopyEvent = (function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1302 var e = elt("div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1303 if ("oncopy" in e) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1304 e.setAttribute("oncopy", "return;")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1305 return typeof e.oncopy == "function"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1306 })()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1307
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1308 var badZoomedRects = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1309 function hasBadZoomedRects(measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1310 if (badZoomedRects != null) { return badZoomedRects }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1311 var node = removeChildrenAndAdd(measure, elt("span", "x"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1312 var normal = node.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1313 var fromRange = range(node, 0, 1).getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1314 return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1315 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1316
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1317 // Known modes, by name and by MIME
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1318 var modes = {};
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1319 var mimeModes = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1320
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1321 // Extra arguments are stored as the mode's dependencies, which is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1322 // used by (legacy) mechanisms like loadmode.js to automatically
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1323 // load a mode. (Preferred mechanism is the require/define calls.)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1324 function defineMode(name, mode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1325 if (arguments.length > 2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1326 { mode.dependencies = Array.prototype.slice.call(arguments, 2) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1327 modes[name] = mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1328 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1329
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1330 function defineMIME(mime, spec) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1331 mimeModes[mime] = spec
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1332 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1333
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1334 // Given a MIME type, a {name, ...options} config object, or a name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1335 // string, return a mode config object.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1336 function resolveMode(spec) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1337 if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1338 spec = mimeModes[spec]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1339 } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1340 var found = mimeModes[spec.name]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1341 if (typeof found == "string") { found = {name: found} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1342 spec = createObj(found, spec)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1343 spec.name = found.name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1344 } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1345 return resolveMode("application/xml")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1346 } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1347 return resolveMode("application/json")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1348 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1349 if (typeof spec == "string") { return {name: spec} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1350 else { return spec || {name: "null"} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1351 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1352
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1353 // Given a mode spec (anything that resolveMode accepts), find and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1354 // initialize an actual mode object.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1355 function getMode(options, spec) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1356 spec = resolveMode(spec)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1357 var mfactory = modes[spec.name]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1358 if (!mfactory) { return getMode(options, "text/plain") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1359 var modeObj = mfactory(options, spec)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1360 if (modeExtensions.hasOwnProperty(spec.name)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1361 var exts = modeExtensions[spec.name]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1362 for (var prop in exts) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1363 if (!exts.hasOwnProperty(prop)) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1364 if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1365 modeObj[prop] = exts[prop]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1366 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1367 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1368 modeObj.name = spec.name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1369 if (spec.helperType) { modeObj.helperType = spec.helperType }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1370 if (spec.modeProps) { for (var prop$1 in spec.modeProps)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1371 { modeObj[prop$1] = spec.modeProps[prop$1] } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1372
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1373 return modeObj
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1374 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1375
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1376 // This can be used to attach properties to mode objects from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1377 // outside the actual mode definition.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1378 var modeExtensions = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1379 function extendMode(mode, properties) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1380 var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1381 copyObj(properties, exts)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1382 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1383
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1384 function copyState(mode, state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1385 if (state === true) { return state }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1386 if (mode.copyState) { return mode.copyState(state) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1387 var nstate = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1388 for (var n in state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1389 var val = state[n]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1390 if (val instanceof Array) { val = val.concat([]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1391 nstate[n] = val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1392 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1393 return nstate
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1394 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1395
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1396 // Given a mode and a state (for that mode), find the inner mode and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1397 // state at the position that the state refers to.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1398 function innerMode(mode, state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1399 var info
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1400 while (mode.innerMode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1401 info = mode.innerMode(state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1402 if (!info || info.mode == mode) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1403 state = info.state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1404 mode = info.mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1405 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1406 return info || {mode: mode, state: state}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1407 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1408
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1409 function startState(mode, a1, a2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1410 return mode.startState ? mode.startState(a1, a2) : true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1411 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1412
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1413 // STRING STREAM
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1414
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1415 // Fed to the mode parsers, provides helper functions to make
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1416 // parsers more succinct.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1417
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1418 var StringStream = function(string, tabSize) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1419 this.pos = this.start = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1420 this.string = string
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1421 this.tabSize = tabSize || 8
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1422 this.lastColumnPos = this.lastColumnValue = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1423 this.lineStart = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1424 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1425
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1426 StringStream.prototype = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1427 eol: function() {return this.pos >= this.string.length},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1428 sol: function() {return this.pos == this.lineStart},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1429 peek: function() {return this.string.charAt(this.pos) || undefined},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1430 next: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1431 if (this.pos < this.string.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1432 { return this.string.charAt(this.pos++) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1433 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1434 eat: function(match) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1435 var ch = this.string.charAt(this.pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1436 var ok
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1437 if (typeof match == "string") { ok = ch == match }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1438 else { ok = ch && (match.test ? match.test(ch) : match(ch)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1439 if (ok) {++this.pos; return ch}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1440 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1441 eatWhile: function(match) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1442 var start = this.pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1443 while (this.eat(match)){}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1444 return this.pos > start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1445 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1446 eatSpace: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1447 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1448
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1449 var start = this.pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1450 while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1451 return this.pos > start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1452 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1453 skipToEnd: function() {this.pos = this.string.length},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1454 skipTo: function(ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1455 var found = this.string.indexOf(ch, this.pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1456 if (found > -1) {this.pos = found; return true}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1457 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1458 backUp: function(n) {this.pos -= n},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1459 column: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1460 if (this.lastColumnPos < this.start) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1461 this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1462 this.lastColumnPos = this.start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1463 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1464 return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1465 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1466 indentation: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1467 return countColumn(this.string, null, this.tabSize) -
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1468 (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1469 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1470 match: function(pattern, consume, caseInsensitive) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1471 if (typeof pattern == "string") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1472 var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1473 var substr = this.string.substr(this.pos, pattern.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1474 if (cased(substr) == cased(pattern)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1475 if (consume !== false) { this.pos += pattern.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1476 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1477 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1478 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1479 var match = this.string.slice(this.pos).match(pattern)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1480 if (match && match.index > 0) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1481 if (match && consume !== false) { this.pos += match[0].length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1482 return match
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1483 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1484 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1485 current: function(){return this.string.slice(this.start, this.pos)},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1486 hideFirstChars: function(n, inner) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1487 this.lineStart += n
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1488 try { return inner() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1489 finally { this.lineStart -= n }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1490 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1491 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1492
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1493 // Compute a style array (an array starting with a mode generation
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1494 // -- for invalidation -- followed by pairs of end positions and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1495 // style strings), which is used to highlight the tokens on the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1496 // line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1497 function highlightLine(cm, line, state, forceToEnd) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1498 // A styles array always starts with a number identifying the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1499 // mode/overlays that it is based on (for easy invalidation).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1500 var st = [cm.state.modeGen], lineClasses = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1501 // Compute the base array of styles
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1502 runMode(cm, line.text, cm.doc.mode, state, function (end, style) { return st.push(end, style); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1503 lineClasses, forceToEnd)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1504
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1505 // Run overlays, adjust style array.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1506 var loop = function ( o ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1507 var overlay = cm.state.overlays[o], i = 1, at = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1508 runMode(cm, line.text, overlay.mode, true, function (end, style) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1509 var start = i
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1510 // Ensure there's a token end at the current position, and that i points at it
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1511 while (at < end) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1512 var i_end = st[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1513 if (i_end > end)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1514 { st.splice(i, 1, end, st[i+1], i_end) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1515 i += 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1516 at = Math.min(end, i_end)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1517 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1518 if (!style) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1519 if (overlay.opaque) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1520 st.splice(start, i - start, end, "overlay " + style)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1521 i = start + 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1522 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1523 for (; start < i; start += 2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1524 var cur = st[start+1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1525 st[start+1] = (cur ? cur + " " : "") + "overlay " + style
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1526 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1527 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1528 }, lineClasses)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1529 };
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1530
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1531 for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1532
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1533 return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1534 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1535
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1536 function getLineStyles(cm, line, updateFrontier) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1537 if (!line.styles || line.styles[0] != cm.state.modeGen) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1538 var state = getStateBefore(cm, lineNo(line))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1539 var result = highlightLine(cm, line, line.text.length > cm.options.maxHighlightLength ? copyState(cm.doc.mode, state) : state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1540 line.stateAfter = state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1541 line.styles = result.styles
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1542 if (result.classes) { line.styleClasses = result.classes }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1543 else if (line.styleClasses) { line.styleClasses = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1544 if (updateFrontier === cm.doc.frontier) { cm.doc.frontier++ }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1545 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1546 return line.styles
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1547 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1548
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1549 function getStateBefore(cm, n, precise) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1550 var doc = cm.doc, display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1551 if (!doc.mode.startState) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1552 var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1553 if (!state) { state = startState(doc.mode) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1554 else { state = copyState(doc.mode, state) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1555 doc.iter(pos, n, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1556 processLine(cm, line.text, state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1557 var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1558 line.stateAfter = save ? copyState(doc.mode, state) : null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1559 ++pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1560 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1561 if (precise) { doc.frontier = pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1562 return state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1563 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1564
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1565 // Lightweight form of highlight -- proceed over this line and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1566 // update state, but don't save a style array. Used for lines that
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1567 // aren't currently visible.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1568 function processLine(cm, text, state, startAt) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1569 var mode = cm.doc.mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1570 var stream = new StringStream(text, cm.options.tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1571 stream.start = stream.pos = startAt || 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1572 if (text == "") { callBlankLine(mode, state) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1573 while (!stream.eol()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1574 readToken(mode, stream, state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1575 stream.start = stream.pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1576 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1577 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1578
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1579 function callBlankLine(mode, state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1580 if (mode.blankLine) { return mode.blankLine(state) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1581 if (!mode.innerMode) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1582 var inner = innerMode(mode, state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1583 if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1584 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1585
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1586 function readToken(mode, stream, state, inner) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1587 for (var i = 0; i < 10; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1588 if (inner) { inner[0] = innerMode(mode, state).mode }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1589 var style = mode.token(stream, state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1590 if (stream.pos > stream.start) { return style }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1591 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1592 throw new Error("Mode " + mode.name + " failed to advance stream.")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1593 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1594
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1595 // Utility for getTokenAt and getLineTokens
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1596 function takeToken(cm, pos, precise, asArray) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1597 var getObj = function (copy) { return ({
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1598 start: stream.start, end: stream.pos,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1599 string: stream.current(),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1600 type: style || null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1601 state: copy ? copyState(doc.mode, state) : state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1602 }); }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1603
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1604 var doc = cm.doc, mode = doc.mode, style
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1605 pos = clipPos(doc, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1606 var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1607 var stream = new StringStream(line.text, cm.options.tabSize), tokens
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1608 if (asArray) { tokens = [] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1609 while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1610 stream.start = stream.pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1611 style = readToken(mode, stream, state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1612 if (asArray) { tokens.push(getObj(true)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1613 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1614 return asArray ? tokens : getObj()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1615 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1616
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1617 function extractLineClasses(type, output) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1618 if (type) { for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1619 var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1620 if (!lineClass) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1621 type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1622 var prop = lineClass[1] ? "bgClass" : "textClass"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1623 if (output[prop] == null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1624 { output[prop] = lineClass[2] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1625 else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1626 { output[prop] += " " + lineClass[2] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1627 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1628 return type
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1629 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1630
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1631 // Run the given mode's parser over a line, calling f for each token.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1632 function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1633 var flattenSpans = mode.flattenSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1634 if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1635 var curStart = 0, curStyle = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1636 var stream = new StringStream(text, cm.options.tabSize), style
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1637 var inner = cm.options.addModeClass && [null]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1638 if (text == "") { extractLineClasses(callBlankLine(mode, state), lineClasses) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1639 while (!stream.eol()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1640 if (stream.pos > cm.options.maxHighlightLength) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1641 flattenSpans = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1642 if (forceToEnd) { processLine(cm, text, state, stream.pos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1643 stream.pos = text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1644 style = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1645 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1646 style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1647 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1648 if (inner) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1649 var mName = inner[0].name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1650 if (mName) { style = "m-" + (style ? mName + " " + style : mName) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1651 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1652 if (!flattenSpans || curStyle != style) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1653 while (curStart < stream.start) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1654 curStart = Math.min(stream.start, curStart + 5000)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1655 f(curStart, curStyle)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1656 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1657 curStyle = style
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1658 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1659 stream.start = stream.pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1660 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1661 while (curStart < stream.pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1662 // Webkit seems to refuse to render text nodes longer than 57444
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1663 // characters, and returns inaccurate measurements in nodes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1664 // starting around 5000 chars.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1665 var pos = Math.min(stream.pos, curStart + 5000)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1666 f(pos, curStyle)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1667 curStart = pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1668 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1669 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1670
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1671 // Finds the line to start with when starting a parse. Tries to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1672 // find a line with a stateAfter, so that it can start with a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1673 // valid state. If that fails, it returns the line with the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1674 // smallest indentation, which tends to need the least context to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1675 // parse correctly.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1676 function findStartLine(cm, n, precise) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1677 var minindent, minline, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1678 var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1679 for (var search = n; search > lim; --search) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1680 if (search <= doc.first) { return doc.first }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1681 var line = getLine(doc, search - 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1682 if (line.stateAfter && (!precise || search <= doc.frontier)) { return search }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1683 var indented = countColumn(line.text, null, cm.options.tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1684 if (minline == null || minindent > indented) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1685 minline = search - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1686 minindent = indented
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1687 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1688 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1689 return minline
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1690 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1691
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1692 // LINE DATA STRUCTURE
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1693
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1694 // Line objects. These hold state related to a line, including
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1695 // highlighting info (the styles array).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1696 function Line(text, markedSpans, estimateHeight) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1697 this.text = text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1698 attachMarkedSpans(this, markedSpans)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1699 this.height = estimateHeight ? estimateHeight(this) : 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1700 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1701 eventMixin(Line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1702 Line.prototype.lineNo = function() { return lineNo(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1703
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1704 // Change the content (text, markers) of a line. Automatically
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1705 // invalidates cached information and tries to re-estimate the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1706 // line's height.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1707 function updateLine(line, text, markedSpans, estimateHeight) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1708 line.text = text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1709 if (line.stateAfter) { line.stateAfter = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1710 if (line.styles) { line.styles = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1711 if (line.order != null) { line.order = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1712 detachMarkedSpans(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1713 attachMarkedSpans(line, markedSpans)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1714 var estHeight = estimateHeight ? estimateHeight(line) : 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1715 if (estHeight != line.height) { updateLineHeight(line, estHeight) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1716 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1717
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1718 // Detach a line from the document tree and its markers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1719 function cleanUpLine(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1720 line.parent = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1721 detachMarkedSpans(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1722 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1723
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1724 // Convert a style as returned by a mode (either null, or a string
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1725 // containing one or more styles) to a CSS style. This is cached,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1726 // and also looks for line-wide styles.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1727 var styleToClassCache = {};
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1728 var styleToClassCacheWithMode = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1729 function interpretTokenStyle(style, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1730 if (!style || /^\s*$/.test(style)) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1731 var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1732 return cache[style] ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1733 (cache[style] = style.replace(/\S+/g, "cm-$&"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1734 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1735
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1736 // Render the DOM representation of the text of a line. Also builds
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1737 // up a 'line map', which points at the DOM nodes that represent
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1738 // specific stretches of text, and is used by the measuring code.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1739 // The returned object contains the DOM node, this map, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1740 // information about line-wide styles that were set by the mode.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1741 function buildLineContent(cm, lineView) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1742 // The padding-right forces the element to have a 'border', which
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1743 // is needed on Webkit to be able to get line-level bounding
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1744 // rectangles for it (in measureChar).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1745 var content = elt("span", null, null, webkit ? "padding-right: .1px" : null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1746 var builder = {pre: elt("pre", [content], "CodeMirror-line"), content: content,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1747 col: 0, pos: 0, cm: cm,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1748 trailingSpace: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1749 splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1750 lineView.measure = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1751
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1752 // Iterate over the logical lines that make up this visual line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1753 for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1754 var line = i ? lineView.rest[i - 1] : lineView.line, order = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1755 builder.pos = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1756 builder.addToken = buildToken
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1757 // Optionally wire in some hacks into the token-rendering
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1758 // algorithm, to deal with browser quirks.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1759 if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1760 { builder.addToken = buildTokenBadBidi(builder.addToken, order) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1761 builder.map = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1762 var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1763 insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1764 if (line.styleClasses) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1765 if (line.styleClasses.bgClass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1766 { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1767 if (line.styleClasses.textClass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1768 { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1769 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1770
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1771 // Ensure at least a single node is present, for measuring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1772 if (builder.map.length == 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1773 { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1774
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1775 // Store the map and a cache object for the current logical line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1776 if (i == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1777 lineView.measure.map = builder.map
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1778 lineView.measure.cache = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1779 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1780 (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1781 ;(lineView.measure.caches || (lineView.measure.caches = [])).push({})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1782 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1783 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1784
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1785 // See issue #2901
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1786 if (webkit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1787 var last = builder.content.lastChild
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1788 if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1789 { builder.content.className = "cm-tab-wrap-hack" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1790 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1791
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1792 signal(cm, "renderLine", cm, lineView.line, builder.pre)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1793 if (builder.pre.className)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1794 { builder.textClass = joinClasses(builder.pre.className, builder.textClass || "") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1795
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1796 return builder
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1797 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1798
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1799 function defaultSpecialCharPlaceholder(ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1800 var token = elt("span", "\u2022", "cm-invalidchar")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1801 token.title = "\\u" + ch.charCodeAt(0).toString(16)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1802 token.setAttribute("aria-label", token.title)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1803 return token
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1804 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1805
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1806 // Build up the DOM representation for a single token, and add it to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1807 // the line map. Takes care to render special characters separately.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1808 function buildToken(builder, text, style, startStyle, endStyle, title, css) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1809 if (!text) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1810 var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1811 var special = builder.cm.state.specialChars, mustWrap = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1812 var content
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1813 if (!special.test(text)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1814 builder.col += text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1815 content = document.createTextNode(displayText)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1816 builder.map.push(builder.pos, builder.pos + text.length, content)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1817 if (ie && ie_version < 9) { mustWrap = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1818 builder.pos += text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1819 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1820 content = document.createDocumentFragment()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1821 var pos = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1822 while (true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1823 special.lastIndex = pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1824 var m = special.exec(text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1825 var skipped = m ? m.index - pos : text.length - pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1826 if (skipped) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1827 var txt = document.createTextNode(displayText.slice(pos, pos + skipped))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1828 if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1829 else { content.appendChild(txt) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1830 builder.map.push(builder.pos, builder.pos + skipped, txt)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1831 builder.col += skipped
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1832 builder.pos += skipped
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1833 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1834 if (!m) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1835 pos += skipped + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1836 var txt$1 = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1837 if (m[0] == "\t") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1838 var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1839 txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1840 txt$1.setAttribute("role", "presentation")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1841 txt$1.setAttribute("cm-text", "\t")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1842 builder.col += tabWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1843 } else if (m[0] == "\r" || m[0] == "\n") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1844 txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1845 txt$1.setAttribute("cm-text", m[0])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1846 builder.col += 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1847 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1848 txt$1 = builder.cm.options.specialCharPlaceholder(m[0])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1849 txt$1.setAttribute("cm-text", m[0])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1850 if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1851 else { content.appendChild(txt$1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1852 builder.col += 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1853 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1854 builder.map.push(builder.pos, builder.pos + 1, txt$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1855 builder.pos++
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1856 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1857 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1858 builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1859 if (style || startStyle || endStyle || mustWrap || css) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1860 var fullStyle = style || ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1861 if (startStyle) { fullStyle += startStyle }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1862 if (endStyle) { fullStyle += endStyle }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1863 var token = elt("span", [content], fullStyle, css)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1864 if (title) { token.title = title }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1865 return builder.content.appendChild(token)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1866 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1867 builder.content.appendChild(content)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1868 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1869
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1870 function splitSpaces(text, trailingBefore) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1871 if (text.length > 1 && !/ /.test(text)) { return text }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1872 var spaceBefore = trailingBefore, result = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1873 for (var i = 0; i < text.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1874 var ch = text.charAt(i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1875 if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1876 { ch = "\u00a0" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1877 result += ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1878 spaceBefore = ch == " "
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1879 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1880 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1881 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1882
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1883 // Work around nonsense dimensions being reported for stretches of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1884 // right-to-left text.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1885 function buildTokenBadBidi(inner, order) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1886 return function (builder, text, style, startStyle, endStyle, title, css) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1887 style = style ? style + " cm-force-border" : "cm-force-border"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1888 var start = builder.pos, end = start + text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1889 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1890 // Find the part that overlaps with the start of this text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1891 var part = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1892 for (var i = 0; i < order.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1893 part = order[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1894 if (part.to > start && part.from <= start) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1895 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1896 if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, title, css) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1897 inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1898 startStyle = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1899 text = text.slice(part.to - start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1900 start = part.to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1901 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1902 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1903 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1904
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1905 function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1906 var widget = !ignoreWidget && marker.widgetNode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1907 if (widget) { builder.map.push(builder.pos, builder.pos + size, widget) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1908 if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1909 if (!widget)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1910 { widget = builder.content.appendChild(document.createElement("span")) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1911 widget.setAttribute("cm-marker", marker.id)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1912 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1913 if (widget) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1914 builder.cm.display.input.setUneditable(widget)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1915 builder.content.appendChild(widget)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1916 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1917 builder.pos += size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1918 builder.trailingSpace = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1919 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1920
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1921 // Outputs a number of spans to make up a line, taking highlighting
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1922 // and marked text into account.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1923 function insertLineContent(line, builder, styles) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1924 var spans = line.markedSpans, allText = line.text, at = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1925 if (!spans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1926 for (var i$1 = 1; i$1 < styles.length; i$1+=2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1927 { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1928 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1929 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1930
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1931 var len = allText.length, pos = 0, i = 1, text = "", style, css
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1932 var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1933 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1934 if (nextChange == pos) { // Update current marker set
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1935 spanStyle = spanEndStyle = spanStartStyle = title = css = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1936 collapsed = null; nextChange = Infinity
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1937 var foundBookmarks = [], endStyles = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1938 for (var j = 0; j < spans.length; ++j) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1939 var sp = spans[j], m = sp.marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1940 if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1941 foundBookmarks.push(m)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1942 } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1943 if (sp.to != null && sp.to != pos && nextChange > sp.to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1944 nextChange = sp.to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1945 spanEndStyle = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1946 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1947 if (m.className) { spanStyle += " " + m.className }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1948 if (m.css) { css = (css ? css + ";" : "") + m.css }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1949 if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1950 if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1951 if (m.title && !title) { title = m.title }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1952 if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1953 { collapsed = sp }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1954 } else if (sp.from > pos && nextChange > sp.from) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1955 nextChange = sp.from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1956 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1957 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1958 if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1959 { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1] } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1960
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1961 if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1962 { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1963 if (collapsed && (collapsed.from || 0) == pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1964 buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1965 collapsed.marker, collapsed.from == null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1966 if (collapsed.to == null) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1967 if (collapsed.to == pos) { collapsed = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1968 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1969 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1970 if (pos >= len) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1971
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1972 var upto = Math.min(len, nextChange)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1973 while (true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1974 if (text) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1975 var end = pos + text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1976 if (!collapsed) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1977 var tokenText = end > upto ? text.slice(0, upto - pos) : text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1978 builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1979 spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1980 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1981 if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1982 pos = end
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1983 spanStartStyle = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1984 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1985 text = allText.slice(at, at = styles[i++])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1986 style = interpretTokenStyle(styles[i++], builder.cm.options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1987 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1988 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1989 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1990
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1991
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1992 // These objects are used to represent the visible (currently drawn)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1993 // part of the document. A LineView may correspond to multiple
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1994 // logical lines, if those are connected by collapsed ranges.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1995 function LineView(doc, line, lineN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1996 // The starting line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1997 this.line = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1998 // Continuing lines, if any
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1999 this.rest = visualLineContinued(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2000 // Number of logical lines in this visual line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2001 this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2002 this.node = this.text = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2003 this.hidden = lineIsHidden(doc, line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2004 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2005
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2006 // Create a range of LineView objects for the given lines.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2007 function buildViewArray(cm, from, to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2008 var array = [], nextPos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2009 for (var pos = from; pos < to; pos = nextPos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2010 var view = new LineView(cm.doc, getLine(cm.doc, pos), pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2011 nextPos = pos + view.size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2012 array.push(view)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2013 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2014 return array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2015 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2016
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2017 var operationGroup = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2018
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2019 function pushOperation(op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2020 if (operationGroup) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2021 operationGroup.ops.push(op)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2022 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2023 op.ownsGroup = operationGroup = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2024 ops: [op],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2025 delayedCallbacks: []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2026 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2027 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2028 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2029
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2030 function fireCallbacksForOps(group) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2031 // Calls delayed callbacks and cursorActivity handlers until no
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2032 // new ones appear
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2033 var callbacks = group.delayedCallbacks, i = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2034 do {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2035 for (; i < callbacks.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2036 { callbacks[i].call(null) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2037 for (var j = 0; j < group.ops.length; j++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2038 var op = group.ops[j]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2039 if (op.cursorActivityHandlers)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2040 { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2041 { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2042 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2043 } while (i < callbacks.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2044 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2045
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2046 function finishOperation(op, endCb) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2047 var group = op.ownsGroup
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2048 if (!group) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2049
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2050 try { fireCallbacksForOps(group) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2051 finally {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2052 operationGroup = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2053 endCb(group)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2054 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2055 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2056
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2057 var orphanDelayedCallbacks = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2058
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2059 // Often, we want to signal events at a point where we are in the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2060 // middle of some work, but don't want the handler to start calling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2061 // other methods on the editor, which might be in an inconsistent
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2062 // state or simply not expect any other events to happen.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2063 // signalLater looks whether there are any handlers, and schedules
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2064 // them to be executed when the last operation ends, or, if no
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2065 // operation is active, when a timeout fires.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2066 function signalLater(emitter, type /*, values...*/) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2067 var arr = getHandlers(emitter, type)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2068 if (!arr.length) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2069 var args = Array.prototype.slice.call(arguments, 2), list
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2070 if (operationGroup) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2071 list = operationGroup.delayedCallbacks
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2072 } else if (orphanDelayedCallbacks) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2073 list = orphanDelayedCallbacks
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2074 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2075 list = orphanDelayedCallbacks = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2076 setTimeout(fireOrphanDelayed, 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2077 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2078 var loop = function ( i ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2079 list.push(function () { return arr[i].apply(null, args); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2080 };
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2081
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2082 for (var i = 0; i < arr.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2083 loop( i );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2084 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2085
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2086 function fireOrphanDelayed() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2087 var delayed = orphanDelayedCallbacks
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2088 orphanDelayedCallbacks = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2089 for (var i = 0; i < delayed.length; ++i) { delayed[i]() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2090 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2091
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2092 // When an aspect of a line changes, a string is added to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2093 // lineView.changes. This updates the relevant part of the line's
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2094 // DOM structure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2095 function updateLineForChanges(cm, lineView, lineN, dims) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2096 for (var j = 0; j < lineView.changes.length; j++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2097 var type = lineView.changes[j]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2098 if (type == "text") { updateLineText(cm, lineView) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2099 else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2100 else if (type == "class") { updateLineClasses(lineView) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2101 else if (type == "widget") { updateLineWidgets(cm, lineView, dims) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2102 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2103 lineView.changes = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2104 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2105
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2106 // Lines with gutter elements, widgets or a background class need to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2107 // be wrapped, and have the extra elements added to the wrapper div
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2108 function ensureLineWrapped(lineView) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2109 if (lineView.node == lineView.text) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2110 lineView.node = elt("div", null, null, "position: relative")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2111 if (lineView.text.parentNode)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2112 { lineView.text.parentNode.replaceChild(lineView.node, lineView.text) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2113 lineView.node.appendChild(lineView.text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2114 if (ie && ie_version < 8) { lineView.node.style.zIndex = 2 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2115 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2116 return lineView.node
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2117 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2118
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2119 function updateLineBackground(lineView) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2120 var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2121 if (cls) { cls += " CodeMirror-linebackground" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2122 if (lineView.background) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2123 if (cls) { lineView.background.className = cls }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2124 else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2125 } else if (cls) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2126 var wrap = ensureLineWrapped(lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2127 lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2128 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2129 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2130
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2131 // Wrapper around buildLineContent which will reuse the structure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2132 // in display.externalMeasured when possible.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2133 function getLineContent(cm, lineView) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2134 var ext = cm.display.externalMeasured
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2135 if (ext && ext.line == lineView.line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2136 cm.display.externalMeasured = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2137 lineView.measure = ext.measure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2138 return ext.built
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2139 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2140 return buildLineContent(cm, lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2141 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2142
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2143 // Redraw the line's text. Interacts with the background and text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2144 // classes because the mode may output tokens that influence these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2145 // classes.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2146 function updateLineText(cm, lineView) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2147 var cls = lineView.text.className
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2148 var built = getLineContent(cm, lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2149 if (lineView.text == lineView.node) { lineView.node = built.pre }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2150 lineView.text.parentNode.replaceChild(built.pre, lineView.text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2151 lineView.text = built.pre
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2152 if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2153 lineView.bgClass = built.bgClass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2154 lineView.textClass = built.textClass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2155 updateLineClasses(lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2156 } else if (cls) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2157 lineView.text.className = cls
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2158 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2159 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2160
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2161 function updateLineClasses(lineView) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2162 updateLineBackground(lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2163 if (lineView.line.wrapClass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2164 { ensureLineWrapped(lineView).className = lineView.line.wrapClass }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2165 else if (lineView.node != lineView.text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2166 { lineView.node.className = "" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2167 var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2168 lineView.text.className = textClass || ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2169 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2170
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2171 function updateLineGutter(cm, lineView, lineN, dims) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2172 if (lineView.gutter) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2173 lineView.node.removeChild(lineView.gutter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2174 lineView.gutter = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2175 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2176 if (lineView.gutterBackground) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2177 lineView.node.removeChild(lineView.gutterBackground)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2178 lineView.gutterBackground = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2179 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2180 if (lineView.line.gutterClass) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2181 var wrap = ensureLineWrapped(lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2182 lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2183 ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2184 wrap.insertBefore(lineView.gutterBackground, lineView.text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2185 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2186 var markers = lineView.line.gutterMarkers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2187 if (cm.options.lineNumbers || markers) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2188 var wrap$1 = ensureLineWrapped(lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2189 var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2190 cm.display.input.setUneditable(gutterWrap)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2191 wrap$1.insertBefore(gutterWrap, lineView.text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2192 if (lineView.line.gutterClass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2193 { gutterWrap.className += " " + lineView.line.gutterClass }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2194 if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2195 { lineView.lineNumber = gutterWrap.appendChild(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2196 elt("div", lineNumberFor(cm.options, lineN),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2197 "CodeMirror-linenumber CodeMirror-gutter-elt",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2198 ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2199 if (markers) { for (var k = 0; k < cm.options.gutters.length; ++k) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2200 var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2201 if (found)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2202 { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2203 ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2204 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2205 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2206 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2207
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2208 function updateLineWidgets(cm, lineView, dims) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2209 if (lineView.alignable) { lineView.alignable = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2210 for (var node = lineView.node.firstChild, next = void 0; node; node = next) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2211 next = node.nextSibling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2212 if (node.className == "CodeMirror-linewidget")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2213 { lineView.node.removeChild(node) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2214 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2215 insertLineWidgets(cm, lineView, dims)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2216 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2217
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2218 // Build a line's DOM representation from scratch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2219 function buildLineElement(cm, lineView, lineN, dims) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2220 var built = getLineContent(cm, lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2221 lineView.text = lineView.node = built.pre
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2222 if (built.bgClass) { lineView.bgClass = built.bgClass }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2223 if (built.textClass) { lineView.textClass = built.textClass }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2224
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2225 updateLineClasses(lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2226 updateLineGutter(cm, lineView, lineN, dims)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2227 insertLineWidgets(cm, lineView, dims)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2228 return lineView.node
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2229 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2230
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2231 // A lineView may contain multiple logical lines (when merged by
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2232 // collapsed spans). The widgets for all of them need to be drawn.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2233 function insertLineWidgets(cm, lineView, dims) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2234 insertLineWidgetsFor(cm, lineView.line, lineView, dims, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2235 if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2236 { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2237 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2238
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2239 function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2240 if (!line.widgets) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2241 var wrap = ensureLineWrapped(lineView)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2242 for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2243 var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2244 if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2245 positionLineWidget(widget, node, lineView, dims)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2246 cm.display.input.setUneditable(node)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2247 if (allowAbove && widget.above)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2248 { wrap.insertBefore(node, lineView.gutter || lineView.text) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2249 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2250 { wrap.appendChild(node) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2251 signalLater(widget, "redraw")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2252 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2253 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2254
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2255 function positionLineWidget(widget, node, lineView, dims) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2256 if (widget.noHScroll) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2257 (lineView.alignable || (lineView.alignable = [])).push(node)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2258 var width = dims.wrapperWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2259 node.style.left = dims.fixedPos + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2260 if (!widget.coverGutter) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2261 width -= dims.gutterTotalWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2262 node.style.paddingLeft = dims.gutterTotalWidth + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2263 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2264 node.style.width = width + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2265 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2266 if (widget.coverGutter) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2267 node.style.zIndex = 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2268 node.style.position = "relative"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2269 if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2270 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2271 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2272
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2273 function widgetHeight(widget) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2274 if (widget.height != null) { return widget.height }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2275 var cm = widget.doc.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2276 if (!cm) { return 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2277 if (!contains(document.body, widget.node)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2278 var parentStyle = "position: relative;"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2279 if (widget.coverGutter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2280 { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2281 if (widget.noHScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2282 { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2283 removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2284 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2285 return widget.height = widget.node.parentNode.offsetHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2286 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2287
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2288 // Return true when the given mouse event happened in a widget
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2289 function eventInWidget(display, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2290 for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2291 if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2292 (n.parentNode == display.sizer && n != display.mover))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2293 { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2294 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2295 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2296
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2297 // POSITION MEASUREMENT
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2298
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2299 function paddingTop(display) {return display.lineSpace.offsetTop}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2300 function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2301 function paddingH(display) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2302 if (display.cachedPaddingH) { return display.cachedPaddingH }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2303 var e = removeChildrenAndAdd(display.measure, elt("pre", "x"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2304 var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2305 var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2306 if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2307 return data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2308 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2309
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2310 function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2311 function displayWidth(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2312 return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2313 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2314 function displayHeight(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2315 return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2316 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2317
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2318 // Ensure the lineView.wrapping.heights array is populated. This is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2319 // an array of bottom offsets for the lines that make up a drawn
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2320 // line. When lineWrapping is on, there might be more than one
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2321 // height.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2322 function ensureLineHeights(cm, lineView, rect) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2323 var wrapping = cm.options.lineWrapping
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2324 var curWidth = wrapping && displayWidth(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2325 if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2326 var heights = lineView.measure.heights = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2327 if (wrapping) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2328 lineView.measure.width = curWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2329 var rects = lineView.text.firstChild.getClientRects()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2330 for (var i = 0; i < rects.length - 1; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2331 var cur = rects[i], next = rects[i + 1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2332 if (Math.abs(cur.bottom - next.bottom) > 2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2333 { heights.push((cur.bottom + next.top) / 2 - rect.top) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2334 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2335 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2336 heights.push(rect.bottom - rect.top)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2337 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2338 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2339
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2340 // Find a line map (mapping character offsets to text nodes) and a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2341 // measurement cache for the given line number. (A line view might
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2342 // contain multiple lines when collapsed ranges are present.)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2343 function mapFromLineView(lineView, line, lineN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2344 if (lineView.line == line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2345 { return {map: lineView.measure.map, cache: lineView.measure.cache} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2346 for (var i = 0; i < lineView.rest.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2347 { if (lineView.rest[i] == line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2348 { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2349 for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2350 { if (lineNo(lineView.rest[i$1]) > lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2351 { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2352 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2353
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2354 // Render a line into the hidden node display.externalMeasured. Used
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2355 // when measurement is needed for a line that's not in the viewport.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2356 function updateExternalMeasurement(cm, line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2357 line = visualLine(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2358 var lineN = lineNo(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2359 var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2360 view.lineN = lineN
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2361 var built = view.built = buildLineContent(cm, view)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2362 view.text = built.pre
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2363 removeChildrenAndAdd(cm.display.lineMeasure, built.pre)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2364 return view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2365 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2366
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2367 // Get a {top, bottom, left, right} box (in line-local coordinates)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2368 // for a given character.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2369 function measureChar(cm, line, ch, bias) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2370 return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2371 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2372
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2373 // Find a line view that corresponds to the given line number.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2374 function findViewForLine(cm, lineN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2375 if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2376 { return cm.display.view[findViewIndex(cm, lineN)] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2377 var ext = cm.display.externalMeasured
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2378 if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2379 { return ext }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2380 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2381
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2382 // Measurement can be split in two steps, the set-up work that
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2383 // applies to the whole line, and the measurement of the actual
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2384 // character. Functions like coordsChar, that need to do a lot of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2385 // measurements in a row, can thus ensure that the set-up work is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2386 // only done once.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2387 function prepareMeasureForLine(cm, line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2388 var lineN = lineNo(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2389 var view = findViewForLine(cm, lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2390 if (view && !view.text) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2391 view = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2392 } else if (view && view.changes) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2393 updateLineForChanges(cm, view, lineN, getDimensions(cm))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2394 cm.curOp.forceUpdate = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2395 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2396 if (!view)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2397 { view = updateExternalMeasurement(cm, line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2398
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2399 var info = mapFromLineView(view, line, lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2400 return {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2401 line: line, view: view, rect: null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2402 map: info.map, cache: info.cache, before: info.before,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2403 hasHeights: false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2404 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2405 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2406
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2407 // Given a prepared measurement object, measures the position of an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2408 // actual character (or fetches it from the cache).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2409 function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2410 if (prepared.before) { ch = -1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2411 var key = ch + (bias || ""), found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2412 if (prepared.cache.hasOwnProperty(key)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2413 found = prepared.cache[key]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2414 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2415 if (!prepared.rect)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2416 { prepared.rect = prepared.view.text.getBoundingClientRect() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2417 if (!prepared.hasHeights) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2418 ensureLineHeights(cm, prepared.view, prepared.rect)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2419 prepared.hasHeights = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2420 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2421 found = measureCharInner(cm, prepared, ch, bias)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2422 if (!found.bogus) { prepared.cache[key] = found }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2423 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2424 return {left: found.left, right: found.right,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2425 top: varHeight ? found.rtop : found.top,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2426 bottom: varHeight ? found.rbottom : found.bottom}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2427 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2428
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2429 var nullRect = {left: 0, right: 0, top: 0, bottom: 0}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2430
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2431 function nodeAndOffsetInLineMap(map$$1, ch, bias) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2432 var node, start, end, collapse, mStart, mEnd
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2433 // First, search the line map for the text node corresponding to,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2434 // or closest to, the target character.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2435 for (var i = 0; i < map$$1.length; i += 3) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2436 mStart = map$$1[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2437 mEnd = map$$1[i + 1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2438 if (ch < mStart) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2439 start = 0; end = 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2440 collapse = "left"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2441 } else if (ch < mEnd) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2442 start = ch - mStart
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2443 end = start + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2444 } else if (i == map$$1.length - 3 || ch == mEnd && map$$1[i + 3] > ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2445 end = mEnd - mStart
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2446 start = end - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2447 if (ch >= mEnd) { collapse = "right" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2448 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2449 if (start != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2450 node = map$$1[i + 2]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2451 if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2452 { collapse = bias }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2453 if (bias == "left" && start == 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2454 { while (i && map$$1[i - 2] == map$$1[i - 3] && map$$1[i - 1].insertLeft) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2455 node = map$$1[(i -= 3) + 2]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2456 collapse = "left"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2457 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2458 if (bias == "right" && start == mEnd - mStart)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2459 { while (i < map$$1.length - 3 && map$$1[i + 3] == map$$1[i + 4] && !map$$1[i + 5].insertLeft) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2460 node = map$$1[(i += 3) + 2]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2461 collapse = "right"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2462 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2463 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2464 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2465 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2466 return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2467 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2468
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2469 function getUsefulRect(rects, bias) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2470 var rect = nullRect
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2471 if (bias == "left") { for (var i = 0; i < rects.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2472 if ((rect = rects[i]).left != rect.right) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2473 } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2474 if ((rect = rects[i$1]).left != rect.right) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2475 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2476 return rect
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2477 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2478
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2479 function measureCharInner(cm, prepared, ch, bias) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2480 var place = nodeAndOffsetInLineMap(prepared.map, ch, bias)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2481 var node = place.node, start = place.start, end = place.end, collapse = place.collapse
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2482
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2483 var rect
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2484 if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2485 for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2486 while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2487 while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2488 if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2489 { rect = node.parentNode.getBoundingClientRect() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2490 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2491 { rect = getUsefulRect(range(node, start, end).getClientRects(), bias) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2492 if (rect.left || rect.right || start == 0) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2493 end = start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2494 start = start - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2495 collapse = "right"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2496 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2497 if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2498 } else { // If it is a widget, simply get the box for the whole widget.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2499 if (start > 0) { collapse = bias = "right" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2500 var rects
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2501 if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2502 { rect = rects[bias == "right" ? rects.length - 1 : 0] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2503 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2504 { rect = node.getBoundingClientRect() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2505 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2506 if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2507 var rSpan = node.parentNode.getClientRects()[0]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2508 if (rSpan)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2509 { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2510 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2511 { rect = nullRect }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2512 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2513
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2514 var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2515 var mid = (rtop + rbot) / 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2516 var heights = prepared.view.measure.heights
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2517 var i = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2518 for (; i < heights.length - 1; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2519 { if (mid < heights[i]) { break } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2520 var top = i ? heights[i - 1] : 0, bot = heights[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2521 var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2522 right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2523 top: top, bottom: bot}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2524 if (!rect.left && !rect.right) { result.bogus = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2525 if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2526
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2527 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2528 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2529
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2530 // Work around problem with bounding client rects on ranges being
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2531 // returned incorrectly when zoomed on IE10 and below.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2532 function maybeUpdateRectForZooming(measure, rect) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2533 if (!window.screen || screen.logicalXDPI == null ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2534 screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2535 { return rect }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2536 var scaleX = screen.logicalXDPI / screen.deviceXDPI
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2537 var scaleY = screen.logicalYDPI / screen.deviceYDPI
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2538 return {left: rect.left * scaleX, right: rect.right * scaleX,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2539 top: rect.top * scaleY, bottom: rect.bottom * scaleY}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2540 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2541
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2542 function clearLineMeasurementCacheFor(lineView) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2543 if (lineView.measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2544 lineView.measure.cache = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2545 lineView.measure.heights = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2546 if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2547 { lineView.measure.caches[i] = {} } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2548 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2549 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2550
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2551 function clearLineMeasurementCache(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2552 cm.display.externalMeasure = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2553 removeChildren(cm.display.lineMeasure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2554 for (var i = 0; i < cm.display.view.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2555 { clearLineMeasurementCacheFor(cm.display.view[i]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2556 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2557
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2558 function clearCaches(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2559 clearLineMeasurementCache(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2560 cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2561 if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2562 cm.display.lineNumChars = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2563 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2564
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2565 function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2566 function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2567
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2568 // Converts a {top, bottom, left, right} box from line-local
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2569 // coordinates into another coordinate system. Context may be one of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2570 // "line", "div" (display.lineDiv), "local"./null (editor), "window",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2571 // or "page".
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2572 function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2573 if (!includeWidgets && lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2574 var size = widgetHeight(lineObj.widgets[i])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2575 rect.top += size; rect.bottom += size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2576 } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2577 if (context == "line") { return rect }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2578 if (!context) { context = "local" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2579 var yOff = heightAtLine(lineObj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2580 if (context == "local") { yOff += paddingTop(cm.display) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2581 else { yOff -= cm.display.viewOffset }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2582 if (context == "page" || context == "window") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2583 var lOff = cm.display.lineSpace.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2584 yOff += lOff.top + (context == "window" ? 0 : pageScrollY())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2585 var xOff = lOff.left + (context == "window" ? 0 : pageScrollX())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2586 rect.left += xOff; rect.right += xOff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2587 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2588 rect.top += yOff; rect.bottom += yOff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2589 return rect
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2590 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2591
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2592 // Coverts a box from "div" coords to another coordinate system.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2593 // Context may be "window", "page", "div", or "local"./null.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2594 function fromCoordSystem(cm, coords, context) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2595 if (context == "div") { return coords }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2596 var left = coords.left, top = coords.top
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2597 // First move into "page" coordinate system
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2598 if (context == "page") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2599 left -= pageScrollX()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2600 top -= pageScrollY()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2601 } else if (context == "local" || !context) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2602 var localBox = cm.display.sizer.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2603 left += localBox.left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2604 top += localBox.top
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2605 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2606
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2607 var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2608 return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2609 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2610
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2611 function charCoords(cm, pos, context, lineObj, bias) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2612 if (!lineObj) { lineObj = getLine(cm.doc, pos.line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2613 return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2614 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2615
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2616 // Returns a box for a given cursor position, which may have an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2617 // 'other' property containing the position of the secondary cursor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2618 // on a bidi boundary.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2619 function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2620 lineObj = lineObj || getLine(cm.doc, pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2621 if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2622 function get(ch, right) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2623 var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2624 if (right) { m.left = m.right; } else { m.right = m.left }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2625 return intoCoordSystem(cm, lineObj, m, context)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2626 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2627 function getBidi(ch, partPos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2628 var part = order[partPos], right = part.level % 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2629 if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2630 part = order[--partPos]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2631 ch = bidiRight(part) - (part.level % 2 ? 0 : 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2632 right = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2633 } else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2634 part = order[++partPos]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2635 ch = bidiLeft(part) - part.level % 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2636 right = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2637 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2638 if (right && ch == part.to && ch > part.from) { return get(ch - 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2639 return get(ch, right)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2640 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2641 var order = getOrder(lineObj), ch = pos.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2642 if (!order) { return get(ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2643 var partPos = getBidiPartAt(order, ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2644 var val = getBidi(ch, partPos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2645 if (bidiOther != null) { val.other = getBidi(ch, bidiOther) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2646 return val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2647 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2648
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2649 // Used to cheaply estimate the coordinates for a position. Used for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2650 // intermediate scroll updates.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2651 function estimateCoords(cm, pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2652 var left = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2653 pos = clipPos(cm.doc, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2654 if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2655 var lineObj = getLine(cm.doc, pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2656 var top = heightAtLine(lineObj) + paddingTop(cm.display)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2657 return {left: left, right: left, top: top, bottom: top + lineObj.height}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2658 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2659
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2660 // Positions returned by coordsChar contain some extra information.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2661 // xRel is the relative x position of the input coordinates compared
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2662 // to the found position (so xRel > 0 means the coordinates are to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2663 // the right of the character position, for example). When outside
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2664 // is true, that means the coordinates lie outside the line's
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2665 // vertical range.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2666 function PosWithInfo(line, ch, outside, xRel) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2667 var pos = Pos(line, ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2668 pos.xRel = xRel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2669 if (outside) { pos.outside = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2670 return pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2671 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2672
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2673 // Compute the character position closest to the given coordinates.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2674 // Input must be lineSpace-local ("div" coordinate system).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2675 function coordsChar(cm, x, y) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2676 var doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2677 y += cm.display.viewOffset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2678 if (y < 0) { return PosWithInfo(doc.first, 0, true, -1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2679 var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2680 if (lineN > last)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2681 { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2682 if (x < 0) { x = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2683
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2684 var lineObj = getLine(doc, lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2685 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2686 var found = coordsCharInner(cm, lineObj, lineN, x, y)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2687 var merged = collapsedSpanAtEnd(lineObj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2688 var mergedPos = merged && merged.find(0, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2689 if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2690 { lineN = lineNo(lineObj = mergedPos.to.line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2691 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2692 { return found }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2693 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2694 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2695
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2696 function coordsCharInner(cm, lineObj, lineNo$$1, x, y) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2697 var innerOff = y - heightAtLine(lineObj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2698 var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2699 var preparedMeasure = prepareMeasureForLine(cm, lineObj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2700
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2701 function getX(ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2702 var sp = cursorCoords(cm, Pos(lineNo$$1, ch), "line", lineObj, preparedMeasure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2703 wrongLine = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2704 if (innerOff > sp.bottom) { return sp.left - adjust }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2705 else if (innerOff < sp.top) { return sp.left + adjust }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2706 else { wrongLine = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2707 return sp.left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2708 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2709
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2710 var bidi = getOrder(lineObj), dist = lineObj.text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2711 var from = lineLeft(lineObj), to = lineRight(lineObj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2712 var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2713
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2714 if (x > toX) { return PosWithInfo(lineNo$$1, to, toOutside, 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2715 // Do a binary search between these bounds.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2716 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2717 if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2718 var ch = x < fromX || x - fromX <= toX - x ? from : to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2719 var outside = ch == from ? fromOutside : toOutside
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2720 var xDiff = x - (ch == from ? fromX : toX)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2721 // This is a kludge to handle the case where the coordinates
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2722 // are after a line-wrapped line. We should replace it with a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2723 // more general handling of cursor positions around line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2724 // breaks. (Issue #4078)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2725 if (toOutside && !bidi && !/\s/.test(lineObj.text.charAt(ch)) && xDiff > 0 &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2726 ch < lineObj.text.length && preparedMeasure.view.measure.heights.length > 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2727 var charSize = measureCharPrepared(cm, preparedMeasure, ch, "right")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2728 if (innerOff <= charSize.bottom && innerOff >= charSize.top && Math.abs(x - charSize.right) < xDiff) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2729 outside = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2730 ch++
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2731 xDiff = x - charSize.right
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2732 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2733 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2734 while (isExtendingChar(lineObj.text.charAt(ch))) { ++ch }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2735 var pos = PosWithInfo(lineNo$$1, ch, outside, xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2736 return pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2737 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2738 var step = Math.ceil(dist / 2), middle = from + step
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2739 if (bidi) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2740 middle = from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2741 for (var i = 0; i < step; ++i) { middle = moveVisually(lineObj, middle, 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2742 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2743 var middleX = getX(middle)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2744 if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) { toX += 1000; } dist = step}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2745 else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2746 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2747 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2748
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2749 var measureText
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2750 // Compute the default text height.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2751 function textHeight(display) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2752 if (display.cachedTextHeight != null) { return display.cachedTextHeight }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2753 if (measureText == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2754 measureText = elt("pre")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2755 // Measure a bunch of lines, for browsers that compute
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2756 // fractional heights.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2757 for (var i = 0; i < 49; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2758 measureText.appendChild(document.createTextNode("x"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2759 measureText.appendChild(elt("br"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2760 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2761 measureText.appendChild(document.createTextNode("x"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2762 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2763 removeChildrenAndAdd(display.measure, measureText)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2764 var height = measureText.offsetHeight / 50
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2765 if (height > 3) { display.cachedTextHeight = height }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2766 removeChildren(display.measure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2767 return height || 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2768 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2769
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2770 // Compute the default character width.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2771 function charWidth(display) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2772 if (display.cachedCharWidth != null) { return display.cachedCharWidth }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2773 var anchor = elt("span", "xxxxxxxxxx")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2774 var pre = elt("pre", [anchor])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2775 removeChildrenAndAdd(display.measure, pre)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2776 var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2777 if (width > 2) { display.cachedCharWidth = width }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2778 return width || 10
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2779 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2780
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2781 // Do a bulk-read of the DOM positions and sizes needed to draw the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2782 // view, so that we don't interleave reading and writing to the DOM.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2783 function getDimensions(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2784 var d = cm.display, left = {}, width = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2785 var gutterLeft = d.gutters.clientLeft
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2786 for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2787 left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2788 width[cm.options.gutters[i]] = n.clientWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2789 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2790 return {fixedPos: compensateForHScroll(d),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2791 gutterTotalWidth: d.gutters.offsetWidth,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2792 gutterLeft: left,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2793 gutterWidth: width,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2794 wrapperWidth: d.wrapper.clientWidth}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2795 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2796
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2797 // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2798 // but using getBoundingClientRect to get a sub-pixel-accurate
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2799 // result.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2800 function compensateForHScroll(display) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2801 return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2802 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2803
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2804 // Returns a function that estimates the height of a line, to use as
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2805 // first approximation until the line becomes visible (and is thus
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2806 // properly measurable).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2807 function estimateHeight(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2808 var th = textHeight(cm.display), wrapping = cm.options.lineWrapping
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2809 var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2810 return function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2811 if (lineIsHidden(cm.doc, line)) { return 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2812
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2813 var widgetsHeight = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2814 if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2815 if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2816 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2817
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2818 if (wrapping)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2819 { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2820 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2821 { return widgetsHeight + th }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2822 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2823 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2824
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2825 function estimateLineHeights(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2826 var doc = cm.doc, est = estimateHeight(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2827 doc.iter(function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2828 var estHeight = est(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2829 if (estHeight != line.height) { updateLineHeight(line, estHeight) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2830 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2831 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2832
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2833 // Given a mouse event, find the corresponding position. If liberal
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2834 // is false, it checks whether a gutter or scrollbar was clicked,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2835 // and returns null if it was. forRect is used by rectangular
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2836 // selections, and tries to estimate a character position even for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2837 // coordinates beyond the right of the text.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2838 function posFromMouse(cm, e, liberal, forRect) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2839 var display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2840 if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2841
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2842 var x, y, space = display.lineSpace.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2843 // Fails unpredictably on IE[67] when mouse is dragged around quickly.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2844 try { x = e.clientX - space.left; y = e.clientY - space.top }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2845 catch (e) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2846 var coords = coordsChar(cm, x, y), line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2847 if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2848 var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2849 coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2850 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2851 return coords
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2852 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2853
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2854 // Find the view element corresponding to a given line. Return null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2855 // when the line isn't visible.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2856 function findViewIndex(cm, n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2857 if (n >= cm.display.viewTo) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2858 n -= cm.display.viewFrom
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2859 if (n < 0) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2860 var view = cm.display.view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2861 for (var i = 0; i < view.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2862 n -= view[i].size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2863 if (n < 0) { return i }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2864 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2865 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2866
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2867 function updateSelection(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2868 cm.display.input.showSelection(cm.display.input.prepareSelection())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2869 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2870
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2871 function prepareSelection(cm, primary) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2872 var doc = cm.doc, result = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2873 var curFragment = result.cursors = document.createDocumentFragment()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2874 var selFragment = result.selection = document.createDocumentFragment()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2875
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2876 for (var i = 0; i < doc.sel.ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2877 if (primary === false && i == doc.sel.primIndex) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2878 var range$$1 = doc.sel.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2879 if (range$$1.from().line >= cm.display.viewTo || range$$1.to().line < cm.display.viewFrom) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2880 var collapsed = range$$1.empty()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2881 if (collapsed || cm.options.showCursorWhenSelecting)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2882 { drawSelectionCursor(cm, range$$1.head, curFragment) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2883 if (!collapsed)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2884 { drawSelectionRange(cm, range$$1, selFragment) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2885 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2886 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2887 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2888
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2889 // Draws a cursor for the given range
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2890 function drawSelectionCursor(cm, head, output) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2891 var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2892
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2893 var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2894 cursor.style.left = pos.left + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2895 cursor.style.top = pos.top + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2896 cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2897
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2898 if (pos.other) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2899 // Secondary cursor, shown when on a 'jump' in bi-directional text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2900 var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2901 otherCursor.style.display = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2902 otherCursor.style.left = pos.other.left + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2903 otherCursor.style.top = pos.other.top + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2904 otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2905 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2906 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2907
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2908 // Draws the given range as a highlighted selection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2909 function drawSelectionRange(cm, range$$1, output) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2910 var display = cm.display, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2911 var fragment = document.createDocumentFragment()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2912 var padding = paddingH(cm.display), leftSide = padding.left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2913 var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2914
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2915 function add(left, top, width, bottom) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2916 if (top < 0) { top = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2917 top = Math.round(top)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2918 bottom = Math.round(bottom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2919 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")))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2920 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2921
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2922 function drawForLine(line, fromArg, toArg) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2923 var lineObj = getLine(doc, line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2924 var lineLen = lineObj.text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2925 var start, end
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2926 function coords(ch, bias) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2927 return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2928 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2929
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2930 iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2931 var leftPos = coords(from, "left"), rightPos, left, right
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2932 if (from == to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2933 rightPos = leftPos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2934 left = right = leftPos.left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2935 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2936 rightPos = coords(to - 1, "right")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2937 if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2938 left = leftPos.left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2939 right = rightPos.right
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2940 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2941 if (fromArg == null && from == 0) { left = leftSide }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2942 if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2943 add(left, leftPos.top, null, leftPos.bottom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2944 left = leftSide
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2945 if (leftPos.bottom < rightPos.top) { add(left, leftPos.bottom, null, rightPos.top) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2946 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2947 if (toArg == null && to == lineLen) { right = rightSide }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2948 if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2949 { start = leftPos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2950 if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2951 { end = rightPos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2952 if (left < leftSide + 1) { left = leftSide }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2953 add(left, rightPos.top, right - left, rightPos.bottom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2954 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2955 return {start: start, end: end}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2956 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2957
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2958 var sFrom = range$$1.from(), sTo = range$$1.to()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2959 if (sFrom.line == sTo.line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2960 drawForLine(sFrom.line, sFrom.ch, sTo.ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2961 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2962 var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2963 var singleVLine = visualLine(fromLine) == visualLine(toLine)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2964 var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2965 var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2966 if (singleVLine) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2967 if (leftEnd.top < rightStart.top - 2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2968 add(leftEnd.right, leftEnd.top, null, leftEnd.bottom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2969 add(leftSide, rightStart.top, rightStart.left, rightStart.bottom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2970 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2971 add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2972 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2973 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2974 if (leftEnd.bottom < rightStart.top)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2975 { add(leftSide, leftEnd.bottom, null, rightStart.top) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2976 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2977
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2978 output.appendChild(fragment)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2979 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2980
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2981 // Cursor-blinking
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2982 function restartBlink(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2983 if (!cm.state.focused) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2984 var display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2985 clearInterval(display.blinker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2986 var on = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2987 display.cursorDiv.style.visibility = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2988 if (cm.options.cursorBlinkRate > 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2989 { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2990 cm.options.cursorBlinkRate) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2991 else if (cm.options.cursorBlinkRate < 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2992 { display.cursorDiv.style.visibility = "hidden" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2993 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2994
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2995 function ensureFocus(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2996 if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2997 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2998
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2999 function delayBlurEvent(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3000 cm.state.delayingBlurEvent = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3001 setTimeout(function () { if (cm.state.delayingBlurEvent) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3002 cm.state.delayingBlurEvent = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3003 onBlur(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3004 } }, 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3005 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3006
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3007 function onFocus(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3008 if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3009
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3010 if (cm.options.readOnly == "nocursor") { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3011 if (!cm.state.focused) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3012 signal(cm, "focus", cm, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3013 cm.state.focused = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3014 addClass(cm.display.wrapper, "CodeMirror-focused")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3015 // This test prevents this from firing when a context
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3016 // menu is closed (since the input reset would kill the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3017 // select-all detection hack)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3018 if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3019 cm.display.input.reset()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3020 if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20) } // Issue #1730
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3021 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3022 cm.display.input.receivedFocus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3023 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3024 restartBlink(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3025 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3026 function onBlur(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3027 if (cm.state.delayingBlurEvent) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3028
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3029 if (cm.state.focused) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3030 signal(cm, "blur", cm, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3031 cm.state.focused = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3032 rmClass(cm.display.wrapper, "CodeMirror-focused")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3033 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3034 clearInterval(cm.display.blinker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3035 setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false } }, 150)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3036 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3037
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3038 // Re-align line numbers and gutter marks to compensate for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3039 // horizontal scrolling.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3040 function alignHorizontally(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3041 var display = cm.display, view = display.view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3042 if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3043 var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3044 var gutterW = display.gutters.offsetWidth, left = comp + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3045 for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3046 if (cm.options.fixedGutter) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3047 if (view[i].gutter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3048 { view[i].gutter.style.left = left }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3049 if (view[i].gutterBackground)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3050 { view[i].gutterBackground.style.left = left }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3051 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3052 var align = view[i].alignable
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3053 if (align) { for (var j = 0; j < align.length; j++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3054 { align[j].style.left = left } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3055 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3056 if (cm.options.fixedGutter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3057 { display.gutters.style.left = (comp + gutterW) + "px" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3058 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3059
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3060 // Used to ensure that the line number gutter is still the right
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3061 // size for the current document size. Returns true when an update
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3062 // is needed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3063 function maybeUpdateLineNumberWidth(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3064 if (!cm.options.lineNumbers) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3065 var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3066 if (last.length != display.lineNumChars) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3067 var test = display.measure.appendChild(elt("div", [elt("div", last)],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3068 "CodeMirror-linenumber CodeMirror-gutter-elt"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3069 var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3070 display.lineGutter.style.width = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3071 display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3072 display.lineNumWidth = display.lineNumInnerWidth + padding
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3073 display.lineNumChars = display.lineNumInnerWidth ? last.length : -1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3074 display.lineGutter.style.width = display.lineNumWidth + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3075 updateGutterSpace(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3076 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3077 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3078 return false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3079 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3080
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3081 // Read the actual heights of the rendered lines, and update their
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3082 // stored heights to match.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3083 function updateHeightsInViewport(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3084 var display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3085 var prevBottom = display.lineDiv.offsetTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3086 for (var i = 0; i < display.view.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3087 var cur = display.view[i], height = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3088 if (cur.hidden) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3089 if (ie && ie_version < 8) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3090 var bot = cur.node.offsetTop + cur.node.offsetHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3091 height = bot - prevBottom
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3092 prevBottom = bot
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3093 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3094 var box = cur.node.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3095 height = box.bottom - box.top
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3096 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3097 var diff = cur.line.height - height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3098 if (height < 2) { height = textHeight(display) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3099 if (diff > .001 || diff < -.001) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3100 updateLineHeight(cur.line, height)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3101 updateWidgetHeight(cur.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3102 if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3103 { updateWidgetHeight(cur.rest[j]) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3104 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3105 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3106 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3107
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3108 // Read and store the height of line widgets associated with the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3109 // given line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3110 function updateWidgetHeight(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3111 if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3112 { line.widgets[i].height = line.widgets[i].node.parentNode.offsetHeight } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3113 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3114
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3115 // Compute the lines that are visible in a given viewport (defaults
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3116 // the the current scroll position). viewport may contain top,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3117 // height, and ensure (see op.scrollToPos) properties.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3118 function visibleLines(display, doc, viewport) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3119 var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3120 top = Math.floor(top - paddingTop(display))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3121 var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3122
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3123 var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3124 // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3125 // forces those lines into the viewport (if possible).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3126 if (viewport && viewport.ensure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3127 var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3128 if (ensureFrom < from) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3129 from = ensureFrom
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3130 to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3131 } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3132 from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3133 to = ensureTo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3134 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3135 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3136 return {from: from, to: Math.max(to, from + 1)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3137 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3138
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3139 // Sync the scrollable area and scrollbars, ensure the viewport
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3140 // covers the visible area.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3141 function setScrollTop(cm, val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3142 if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3143 cm.doc.scrollTop = val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3144 if (!gecko) { updateDisplaySimple(cm, {top: val}) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3145 if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3146 cm.display.scrollbars.setScrollTop(val)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3147 if (gecko) { updateDisplaySimple(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3148 startWorker(cm, 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3149 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3150 // Sync scroller and scrollbar, ensure the gutter elements are
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3151 // aligned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3152 function setScrollLeft(cm, val, isScroller) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3153 if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3154 val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3155 cm.doc.scrollLeft = val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3156 alignHorizontally(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3157 if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3158 cm.display.scrollbars.setScrollLeft(val)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3159 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3160
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3161 // Since the delta values reported on mouse wheel events are
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3162 // unstandardized between browsers and even browser versions, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3163 // generally horribly unpredictable, this code starts by measuring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3164 // the scroll effect that the first few mouse wheel events have,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3165 // and, from that, detects the way it can convert deltas to pixel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3166 // offsets afterwards.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3167 //
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3168 // The reason we want to know the amount a wheel event will scroll
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3169 // is that it gives us a chance to update the display before the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3170 // actual scrolling happens, reducing flickering.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3171
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3172 var wheelSamples = 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3173 var wheelPixelsPerUnit = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3174 // Fill in a browser-detected starting value on browsers where we
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3175 // know one. These don't have to be accurate -- the result of them
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3176 // being wrong would just be a slight flicker on the first wheel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3177 // scroll (if it is large enough).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3178 if (ie) { wheelPixelsPerUnit = -.53 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3179 else if (gecko) { wheelPixelsPerUnit = 15 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3180 else if (chrome) { wheelPixelsPerUnit = -.7 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3181 else if (safari) { wheelPixelsPerUnit = -1/3 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3182
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3183 function wheelEventDelta(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3184 var dx = e.wheelDeltaX, dy = e.wheelDeltaY
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3185 if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3186 if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3187 else if (dy == null) { dy = e.wheelDelta }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3188 return {x: dx, y: dy}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3189 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3190 function wheelEventPixels(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3191 var delta = wheelEventDelta(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3192 delta.x *= wheelPixelsPerUnit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3193 delta.y *= wheelPixelsPerUnit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3194 return delta
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3195 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3196
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3197 function onScrollWheel(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3198 var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3199
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3200 var display = cm.display, scroll = display.scroller
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3201 // Quit if there's nothing to scroll here
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3202 var canScrollX = scroll.scrollWidth > scroll.clientWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3203 var canScrollY = scroll.scrollHeight > scroll.clientHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3204 if (!(dx && canScrollX || dy && canScrollY)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3205
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3206 // Webkit browsers on OS X abort momentum scrolls when the target
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3207 // of the scroll event is removed from the scrollable element.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3208 // This hack (see related code in patchDisplay) makes sure the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3209 // element is kept around.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3210 if (dy && mac && webkit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3211 outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3212 for (var i = 0; i < view.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3213 if (view[i].node == cur) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3214 cm.display.currentWheelTarget = cur
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3215 break outer
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3216 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3217 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3218 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3219 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3220
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3221 // On some browsers, horizontal scrolling will cause redraws to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3222 // happen before the gutter has been realigned, causing it to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3223 // wriggle around in a most unseemly way. When we have an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3224 // estimated pixels/delta value, we just handle horizontal
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3225 // scrolling entirely here. It'll be slightly off from native, but
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3226 // better than glitching out.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3227 if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3228 if (dy && canScrollY)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3229 { setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3230 setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3231 // Only prevent default scrolling if vertical scrolling is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3232 // actually possible. Otherwise, it causes vertical scroll
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3233 // jitter on OSX trackpads when deltaX is small and deltaY
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3234 // is large (issue #3579)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3235 if (!dy || (dy && canScrollY))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3236 { e_preventDefault(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3237 display.wheelStartX = null // Abort measurement, if in progress
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3238 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3239 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3240
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3241 // 'Project' the visible viewport to cover the area that is being
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3242 // scrolled into view (if we know enough to estimate it).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3243 if (dy && wheelPixelsPerUnit != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3244 var pixels = dy * wheelPixelsPerUnit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3245 var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3246 if (pixels < 0) { top = Math.max(0, top + pixels - 50) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3247 else { bot = Math.min(cm.doc.height, bot + pixels + 50) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3248 updateDisplaySimple(cm, {top: top, bottom: bot})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3249 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3250
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3251 if (wheelSamples < 20) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3252 if (display.wheelStartX == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3253 display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3254 display.wheelDX = dx; display.wheelDY = dy
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3255 setTimeout(function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3256 if (display.wheelStartX == null) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3257 var movedX = scroll.scrollLeft - display.wheelStartX
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3258 var movedY = scroll.scrollTop - display.wheelStartY
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3259 var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3260 (movedX && display.wheelDX && movedX / display.wheelDX)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3261 display.wheelStartX = display.wheelStartY = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3262 if (!sample) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3263 wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3264 ++wheelSamples
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3265 }, 200)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3266 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3267 display.wheelDX += dx; display.wheelDY += dy
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3268 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3269 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3270 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3271
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3272 // SCROLLBARS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3273
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3274 // Prepare DOM reads needed to update the scrollbars. Done in one
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3275 // shot to minimize update/measure roundtrips.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3276 function measureForScrollbars(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3277 var d = cm.display, gutterW = d.gutters.offsetWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3278 var docH = Math.round(cm.doc.height + paddingVert(cm.display))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3279 return {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3280 clientHeight: d.scroller.clientHeight,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3281 viewHeight: d.wrapper.clientHeight,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3282 scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3283 viewWidth: d.wrapper.clientWidth,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3284 barLeft: cm.options.fixedGutter ? gutterW : 0,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3285 docHeight: docH,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3286 scrollHeight: docH + scrollGap(cm) + d.barHeight,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3287 nativeBarWidth: d.nativeBarWidth,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3288 gutterWidth: gutterW
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3289 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3290 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3291
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3292 function NativeScrollbars(place, scroll, cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3293 this.cm = cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3294 var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3295 var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3296 place(vert); place(horiz)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3297
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3298 on(vert, "scroll", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3299 if (vert.clientHeight) { scroll(vert.scrollTop, "vertical") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3300 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3301 on(horiz, "scroll", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3302 if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3303 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3304
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3305 this.checkedZeroWidth = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3306 // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3307 if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3308 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3309
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3310 NativeScrollbars.prototype = copyObj({
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3311 update: function(measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3312 var needsH = measure.scrollWidth > measure.clientWidth + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3313 var needsV = measure.scrollHeight > measure.clientHeight + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3314 var sWidth = measure.nativeBarWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3315
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3316 if (needsV) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3317 this.vert.style.display = "block"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3318 this.vert.style.bottom = needsH ? sWidth + "px" : "0"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3319 var totalHeight = measure.viewHeight - (needsH ? sWidth : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3320 // A bug in IE8 can cause this value to be negative, so guard it.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3321 this.vert.firstChild.style.height =
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3322 Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3323 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3324 this.vert.style.display = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3325 this.vert.firstChild.style.height = "0"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3326 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3327
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3328 if (needsH) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3329 this.horiz.style.display = "block"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3330 this.horiz.style.right = needsV ? sWidth + "px" : "0"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3331 this.horiz.style.left = measure.barLeft + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3332 var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3333 this.horiz.firstChild.style.width =
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3334 (measure.scrollWidth - measure.clientWidth + totalWidth) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3335 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3336 this.horiz.style.display = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3337 this.horiz.firstChild.style.width = "0"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3338 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3339
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3340 if (!this.checkedZeroWidth && measure.clientHeight > 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3341 if (sWidth == 0) { this.zeroWidthHack() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3342 this.checkedZeroWidth = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3343 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3344
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3345 return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3346 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3347 setScrollLeft: function(pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3348 if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3349 if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3350 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3351 setScrollTop: function(pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3352 if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3353 if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3354 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3355 zeroWidthHack: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3356 var w = mac && !mac_geMountainLion ? "12px" : "18px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3357 this.horiz.style.height = this.vert.style.width = w
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3358 this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3359 this.disableHoriz = new Delayed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3360 this.disableVert = new Delayed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3361 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3362 enableZeroWidthBar: function(bar, delay) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3363 bar.style.pointerEvents = "auto"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3364 function maybeDisable() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3365 // To find out whether the scrollbar is still visible, we
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3366 // check whether the element under the pixel in the bottom
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3367 // left corner of the scrollbar box is the scrollbar box
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3368 // itself (when the bar is still visible) or its filler child
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3369 // (when the bar is hidden). If it is still visible, we keep
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3370 // it enabled, if it's hidden, we disable pointer events.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3371 var box = bar.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3372 var elt$$1 = document.elementFromPoint(box.left + 1, box.bottom - 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3373 if (elt$$1 != bar) { bar.style.pointerEvents = "none" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3374 else { delay.set(1000, maybeDisable) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3375 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3376 delay.set(1000, maybeDisable)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3377 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3378 clear: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3379 var parent = this.horiz.parentNode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3380 parent.removeChild(this.horiz)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3381 parent.removeChild(this.vert)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3382 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3383 }, NativeScrollbars.prototype)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3384
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3385 function NullScrollbars() {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3386
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3387 NullScrollbars.prototype = copyObj({
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3388 update: function() { return {bottom: 0, right: 0} },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3389 setScrollLeft: function() {},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3390 setScrollTop: function() {},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3391 clear: function() {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3392 }, NullScrollbars.prototype)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3393
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3394 function updateScrollbars(cm, measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3395 if (!measure) { measure = measureForScrollbars(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3396 var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3397 updateScrollbarsInner(cm, measure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3398 for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3399 if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3400 { updateHeightsInViewport(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3401 updateScrollbarsInner(cm, measureForScrollbars(cm))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3402 startWidth = cm.display.barWidth; startHeight = cm.display.barHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3403 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3404 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3405
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3406 // Re-synchronize the fake scrollbars with the actual size of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3407 // content.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3408 function updateScrollbarsInner(cm, measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3409 var d = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3410 var sizes = d.scrollbars.update(measure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3411
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3412 d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3413 d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3414 d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3415
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3416 if (sizes.right && sizes.bottom) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3417 d.scrollbarFiller.style.display = "block"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3418 d.scrollbarFiller.style.height = sizes.bottom + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3419 d.scrollbarFiller.style.width = sizes.right + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3420 } else { d.scrollbarFiller.style.display = "" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3421 if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3422 d.gutterFiller.style.display = "block"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3423 d.gutterFiller.style.height = sizes.bottom + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3424 d.gutterFiller.style.width = measure.gutterWidth + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3425 } else { d.gutterFiller.style.display = "" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3426 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3427
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3428 var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3429
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3430 function initScrollbars(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3431 if (cm.display.scrollbars) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3432 cm.display.scrollbars.clear()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3433 if (cm.display.scrollbars.addClass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3434 { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3435 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3436
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3437 cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3438 cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3439 // Prevent clicks in the scrollbars from killing focus
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3440 on(node, "mousedown", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3441 if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3442 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3443 node.setAttribute("cm-not-content", "true")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3444 }, function (pos, axis) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3445 if (axis == "horizontal") { setScrollLeft(cm, pos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3446 else { setScrollTop(cm, pos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3447 }, cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3448 if (cm.display.scrollbars.addClass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3449 { addClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3450 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3451
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3452 // SCROLLING THINGS INTO VIEW
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3453
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3454 // If an editor sits on the top or bottom of the window, partially
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3455 // scrolled out of view, this ensures that the cursor is visible.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3456 function maybeScrollWindow(cm, coords) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3457 if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3458
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3459 var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3460 if (coords.top + box.top < 0) { doScroll = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3461 else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3462 if (doScroll != null && !phantom) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3463 var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (coords.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (coords.left) + "px; width: 2px;"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3464 cm.display.lineSpace.appendChild(scrollNode)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3465 scrollNode.scrollIntoView(doScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3466 cm.display.lineSpace.removeChild(scrollNode)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3467 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3468 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3469
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3470 // Scroll a given position into view (immediately), verifying that
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3471 // it actually became visible (as line heights are accurately
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3472 // measured, the position of something may 'drift' during drawing).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3473 function scrollPosIntoView(cm, pos, end, margin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3474 if (margin == null) { margin = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3475 var coords
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3476 for (var limit = 0; limit < 5; limit++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3477 var changed = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3478 coords = cursorCoords(cm, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3479 var endCoords = !end || end == pos ? coords : cursorCoords(cm, end)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3480 var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3481 Math.min(coords.top, endCoords.top) - margin,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3482 Math.max(coords.left, endCoords.left),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3483 Math.max(coords.bottom, endCoords.bottom) + margin)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3484 var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3485 if (scrollPos.scrollTop != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3486 setScrollTop(cm, scrollPos.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3487 if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3488 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3489 if (scrollPos.scrollLeft != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3490 setScrollLeft(cm, scrollPos.scrollLeft)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3491 if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3492 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3493 if (!changed) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3494 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3495 return coords
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3496 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3497
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3498 // Scroll a given set of coordinates into view (immediately).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3499 function scrollIntoView(cm, x1, y1, x2, y2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3500 var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3501 if (scrollPos.scrollTop != null) { setScrollTop(cm, scrollPos.scrollTop) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3502 if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3503 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3504
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3505 // Calculate a new scroll position needed to scroll the given
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3506 // rectangle into view. Returns an object with scrollTop and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3507 // scrollLeft properties. When these are undefined, the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3508 // vertical/horizontal position does not need to be adjusted.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3509 function calculateScrollPos(cm, x1, y1, x2, y2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3510 var display = cm.display, snapMargin = textHeight(cm.display)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3511 if (y1 < 0) { y1 = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3512 var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3513 var screen = displayHeight(cm), result = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3514 if (y2 - y1 > screen) { y2 = y1 + screen }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3515 var docBottom = cm.doc.height + paddingVert(display)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3516 var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3517 if (y1 < screentop) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3518 result.scrollTop = atTop ? 0 : y1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3519 } else if (y2 > screentop + screen) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3520 var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3521 if (newTop != screentop) { result.scrollTop = newTop }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3522 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3523
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3524 var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3525 var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3526 var tooWide = x2 - x1 > screenw
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3527 if (tooWide) { x2 = x1 + screenw }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3528 if (x1 < 10)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3529 { result.scrollLeft = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3530 else if (x1 < screenleft)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3531 { result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3532 else if (x2 > screenw + screenleft - 3)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3533 { result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3534 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3535 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3536
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3537 // Store a relative adjustment to the scroll position in the current
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3538 // operation (to be applied when the operation finishes).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3539 function addToScrollPos(cm, left, top) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3540 if (left != null || top != null) { resolveScrollToPos(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3541 if (left != null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3542 { cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3543 if (top != null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3544 { cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3545 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3546
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3547 // Make sure that at the end of the operation the current cursor is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3548 // shown.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3549 function ensureCursorVisible(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3550 resolveScrollToPos(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3551 var cur = cm.getCursor(), from = cur, to = cur
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3552 if (!cm.options.lineWrapping) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3553 from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3554 to = Pos(cur.line, cur.ch + 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3555 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3556 cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3557 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3558
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3559 // When an operation has its scrollToPos property set, and another
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3560 // scroll action is applied before the end of the operation, this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3561 // 'simulates' scrolling that position into view in a cheap way, so
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3562 // that the effect of intermediate scroll commands is not ignored.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3563 function resolveScrollToPos(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3564 var range$$1 = cm.curOp.scrollToPos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3565 if (range$$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3566 cm.curOp.scrollToPos = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3567 var from = estimateCoords(cm, range$$1.from), to = estimateCoords(cm, range$$1.to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3568 var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3569 Math.min(from.top, to.top) - range$$1.margin,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3570 Math.max(from.right, to.right),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3571 Math.max(from.bottom, to.bottom) + range$$1.margin)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3572 cm.scrollTo(sPos.scrollLeft, sPos.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3573 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3574 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3575
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3576 // Operations are used to wrap a series of changes to the editor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3577 // state in such a way that each change won't have to update the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3578 // cursor and display (which would be awkward, slow, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3579 // error-prone). Instead, display updates are batched and then all
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3580 // combined and executed at once.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3581
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3582 var nextOpId = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3583 // Start a new operation.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3584 function startOperation(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3585 cm.curOp = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3586 cm: cm,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3587 viewChanged: false, // Flag that indicates that lines might need to be redrawn
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3588 startHeight: cm.doc.height, // Used to detect need to update scrollbar
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3589 forceUpdate: false, // Used to force a redraw
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3590 updateInput: null, // Whether to reset the input textarea
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3591 typing: false, // Whether this reset should be careful to leave existing text (for compositing)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3592 changeObjs: null, // Accumulated changes, for firing change events
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3593 cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3594 cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3595 selectionChanged: false, // Whether the selection needs to be redrawn
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3596 updateMaxLine: false, // Set when the widest line needs to be determined anew
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3597 scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3598 scrollToPos: null, // Used to scroll to a specific position
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3599 focus: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3600 id: ++nextOpId // Unique ID
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3601 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3602 pushOperation(cm.curOp)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3603 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3604
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3605 // Finish an operation, updating the display and signalling delayed events
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3606 function endOperation(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3607 var op = cm.curOp
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3608 finishOperation(op, function (group) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3609 for (var i = 0; i < group.ops.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3610 { group.ops[i].cm.curOp = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3611 endOperations(group)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3612 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3613 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3614
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3615 // The DOM updates done when an operation finishes are batched so
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3616 // that the minimum number of relayouts are required.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3617 function endOperations(group) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3618 var ops = group.ops
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3619 for (var i = 0; i < ops.length; i++) // Read DOM
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3620 { endOperation_R1(ops[i]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3621 for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3622 { endOperation_W1(ops[i$1]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3623 for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3624 { endOperation_R2(ops[i$2]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3625 for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3626 { endOperation_W2(ops[i$3]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3627 for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3628 { endOperation_finish(ops[i$4]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3629 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3630
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3631 function endOperation_R1(op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3632 var cm = op.cm, display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3633 maybeClipScrollbars(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3634 if (op.updateMaxLine) { findMaxLine(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3635
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3636 op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3637 op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3638 op.scrollToPos.to.line >= display.viewTo) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3639 display.maxLineChanged && cm.options.lineWrapping
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3640 op.update = op.mustUpdate &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3641 new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3642 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3643
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3644 function endOperation_W1(op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3645 op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3646 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3647
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3648 function endOperation_R2(op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3649 var cm = op.cm, display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3650 if (op.updatedDisplay) { updateHeightsInViewport(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3651
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3652 op.barMeasure = measureForScrollbars(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3653
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3654 // If the max line changed since it was last measured, measure it,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3655 // and ensure the document's width matches it.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3656 // updateDisplay_W2 will use these properties to do the actual resizing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3657 if (display.maxLineChanged && !cm.options.lineWrapping) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3658 op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3659 cm.display.sizerWidth = op.adjustWidthTo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3660 op.barMeasure.scrollWidth =
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3661 Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3662 op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3663 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3664
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3665 if (op.updatedDisplay || op.selectionChanged)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3666 { op.preparedSelection = display.input.prepareSelection(op.focus) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3667 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3668
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3669 function endOperation_W2(op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3670 var cm = op.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3671
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3672 if (op.adjustWidthTo != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3673 cm.display.sizer.style.minWidth = op.adjustWidthTo + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3674 if (op.maxScrollLeft < cm.doc.scrollLeft)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3675 { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3676 cm.display.maxLineChanged = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3677 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3678
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3679 var takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3680 if (op.preparedSelection)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3681 { cm.display.input.showSelection(op.preparedSelection, takeFocus) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3682 if (op.updatedDisplay || op.startHeight != cm.doc.height)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3683 { updateScrollbars(cm, op.barMeasure) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3684 if (op.updatedDisplay)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3685 { setDocumentHeight(cm, op.barMeasure) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3686
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3687 if (op.selectionChanged) { restartBlink(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3688
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3689 if (cm.state.focused && op.updateInput)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3690 { cm.display.input.reset(op.typing) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3691 if (takeFocus) { ensureFocus(op.cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3692 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3693
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3694 function endOperation_finish(op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3695 var cm = op.cm, display = cm.display, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3696
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3697 if (op.updatedDisplay) { postUpdateDisplay(cm, op.update) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3698
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3699 // Abort mouse wheel delta measurement, when scrolling explicitly
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3700 if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3701 { display.wheelStartX = display.wheelStartY = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3702
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3703 // Propagate the scroll position to the actual DOM scroller
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3704 if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3705 doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3706 display.scrollbars.setScrollTop(doc.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3707 display.scroller.scrollTop = doc.scrollTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3708 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3709 if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3710 doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3711 display.scrollbars.setScrollLeft(doc.scrollLeft)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3712 display.scroller.scrollLeft = doc.scrollLeft
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3713 alignHorizontally(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3714 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3715 // If we need to scroll a specific position into view, do so.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3716 if (op.scrollToPos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3717 var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3718 clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3719 if (op.scrollToPos.isCursor && cm.state.focused) { maybeScrollWindow(cm, coords) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3720 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3721
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3722 // Fire events for markers that are hidden/unidden by editing or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3723 // undoing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3724 var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3725 if (hidden) { for (var i = 0; i < hidden.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3726 { if (!hidden[i].lines.length) { signal(hidden[i], "hide") } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3727 if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3728 { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide") } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3729
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3730 if (display.wrapper.offsetHeight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3731 { doc.scrollTop = cm.display.scroller.scrollTop }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3732
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3733 // Fire change events, and delayed event handlers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3734 if (op.changeObjs)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3735 { signal(cm, "changes", cm, op.changeObjs) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3736 if (op.update)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3737 { op.update.finish() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3738 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3739
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3740 // Run the given function in an operation
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3741 function runInOp(cm, f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3742 if (cm.curOp) { return f() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3743 startOperation(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3744 try { return f() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3745 finally { endOperation(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3746 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3747 // Wraps a function in an operation. Returns the wrapped function.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3748 function operation(cm, f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3749 return function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3750 if (cm.curOp) { return f.apply(cm, arguments) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3751 startOperation(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3752 try { return f.apply(cm, arguments) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3753 finally { endOperation(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3754 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3755 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3756 // Used to add methods to editor and doc instances, wrapping them in
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3757 // operations.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3758 function methodOp(f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3759 return function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3760 if (this.curOp) { return f.apply(this, arguments) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3761 startOperation(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3762 try { return f.apply(this, arguments) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3763 finally { endOperation(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3764 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3765 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3766 function docMethodOp(f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3767 return function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3768 var cm = this.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3769 if (!cm || cm.curOp) { return f.apply(this, arguments) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3770 startOperation(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3771 try { return f.apply(this, arguments) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3772 finally { endOperation(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3773 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3774 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3775
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3776 // Updates the display.view data structure for a given change to the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3777 // document. From and to are in pre-change coordinates. Lendiff is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3778 // the amount of lines added or subtracted by the change. This is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3779 // used for changes that span multiple lines, or change the way
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3780 // lines are divided into visual lines. regLineChange (below)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3781 // registers single-line changes.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3782 function regChange(cm, from, to, lendiff) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3783 if (from == null) { from = cm.doc.first }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3784 if (to == null) { to = cm.doc.first + cm.doc.size }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3785 if (!lendiff) { lendiff = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3786
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3787 var display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3788 if (lendiff && to < display.viewTo &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3789 (display.updateLineNumbers == null || display.updateLineNumbers > from))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3790 { display.updateLineNumbers = from }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3791
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3792 cm.curOp.viewChanged = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3793
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3794 if (from >= display.viewTo) { // Change after
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3795 if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3796 { resetView(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3797 } else if (to <= display.viewFrom) { // Change before
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3798 if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3799 resetView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3800 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3801 display.viewFrom += lendiff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3802 display.viewTo += lendiff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3803 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3804 } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3805 resetView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3806 } else if (from <= display.viewFrom) { // Top overlap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3807 var cut = viewCuttingPoint(cm, to, to + lendiff, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3808 if (cut) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3809 display.view = display.view.slice(cut.index)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3810 display.viewFrom = cut.lineN
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3811 display.viewTo += lendiff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3812 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3813 resetView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3814 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3815 } else if (to >= display.viewTo) { // Bottom overlap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3816 var cut$1 = viewCuttingPoint(cm, from, from, -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3817 if (cut$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3818 display.view = display.view.slice(0, cut$1.index)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3819 display.viewTo = cut$1.lineN
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3820 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3821 resetView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3822 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3823 } else { // Gap in the middle
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3824 var cutTop = viewCuttingPoint(cm, from, from, -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3825 var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3826 if (cutTop && cutBot) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3827 display.view = display.view.slice(0, cutTop.index)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3828 .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3829 .concat(display.view.slice(cutBot.index))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3830 display.viewTo += lendiff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3831 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3832 resetView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3833 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3834 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3835
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3836 var ext = display.externalMeasured
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3837 if (ext) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3838 if (to < ext.lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3839 { ext.lineN += lendiff }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3840 else if (from < ext.lineN + ext.size)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3841 { display.externalMeasured = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3842 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3843 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3844
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3845 // Register a change to a single line. Type must be one of "text",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3846 // "gutter", "class", "widget"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3847 function regLineChange(cm, line, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3848 cm.curOp.viewChanged = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3849 var display = cm.display, ext = cm.display.externalMeasured
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3850 if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3851 { display.externalMeasured = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3852
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3853 if (line < display.viewFrom || line >= display.viewTo) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3854 var lineView = display.view[findViewIndex(cm, line)]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3855 if (lineView.node == null) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3856 var arr = lineView.changes || (lineView.changes = [])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3857 if (indexOf(arr, type) == -1) { arr.push(type) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3858 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3859
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3860 // Clear the view.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3861 function resetView(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3862 cm.display.viewFrom = cm.display.viewTo = cm.doc.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3863 cm.display.view = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3864 cm.display.viewOffset = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3865 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3866
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3867 function viewCuttingPoint(cm, oldN, newN, dir) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3868 var index = findViewIndex(cm, oldN), diff, view = cm.display.view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3869 if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3870 { return {index: index, lineN: newN} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3871 var n = cm.display.viewFrom
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3872 for (var i = 0; i < index; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3873 { n += view[i].size }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3874 if (n != oldN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3875 if (dir > 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3876 if (index == view.length - 1) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3877 diff = (n + view[index].size) - oldN
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3878 index++
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3879 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3880 diff = n - oldN
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3881 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3882 oldN += diff; newN += diff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3883 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3884 while (visualLineNo(cm.doc, newN) != newN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3885 if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3886 newN += dir * view[index - (dir < 0 ? 1 : 0)].size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3887 index += dir
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3888 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3889 return {index: index, lineN: newN}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3890 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3891
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3892 // Force the view to cover a given range, adding empty view element
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3893 // or clipping off existing ones as needed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3894 function adjustView(cm, from, to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3895 var display = cm.display, view = display.view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3896 if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3897 display.view = buildViewArray(cm, from, to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3898 display.viewFrom = from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3899 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3900 if (display.viewFrom > from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3901 { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3902 else if (display.viewFrom < from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3903 { display.view = display.view.slice(findViewIndex(cm, from)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3904 display.viewFrom = from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3905 if (display.viewTo < to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3906 { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3907 else if (display.viewTo > to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3908 { display.view = display.view.slice(0, findViewIndex(cm, to)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3909 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3910 display.viewTo = to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3911 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3912
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3913 // Count the number of lines in the view whose DOM representation is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3914 // out of date (or nonexistent).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3915 function countDirtyView(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3916 var view = cm.display.view, dirty = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3917 for (var i = 0; i < view.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3918 var lineView = view[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3919 if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3920 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3921 return dirty
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3922 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3923
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3924 // HIGHLIGHT WORKER
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3925
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3926 function startWorker(cm, time) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3927 if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3928 { cm.state.highlight.set(time, bind(highlightWorker, cm)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3929 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3930
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3931 function highlightWorker(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3932 var doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3933 if (doc.frontier < doc.first) { doc.frontier = doc.first }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3934 if (doc.frontier >= cm.display.viewTo) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3935 var end = +new Date + cm.options.workTime
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3936 var state = copyState(doc.mode, getStateBefore(cm, doc.frontier))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3937 var changedLines = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3938
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3939 doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3940 if (doc.frontier >= cm.display.viewFrom) { // Visible
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3941 var oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3942 var highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3943 line.styles = highlighted.styles
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3944 var oldCls = line.styleClasses, newCls = highlighted.classes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3945 if (newCls) { line.styleClasses = newCls }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3946 else if (oldCls) { line.styleClasses = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3947 var ischange = !oldStyles || oldStyles.length != line.styles.length ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3948 oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3949 for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3950 if (ischange) { changedLines.push(doc.frontier) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3951 line.stateAfter = tooLong ? state : copyState(doc.mode, state)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3952 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3953 if (line.text.length <= cm.options.maxHighlightLength)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3954 { processLine(cm, line.text, state) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3955 line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3956 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3957 ++doc.frontier
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3958 if (+new Date > end) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3959 startWorker(cm, cm.options.workDelay)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3960 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3961 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3962 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3963 if (changedLines.length) { runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3964 for (var i = 0; i < changedLines.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3965 { regLineChange(cm, changedLines[i], "text") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3966 }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3967 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3968
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3969 // DISPLAY DRAWING
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3970
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3971 function DisplayUpdate(cm, viewport, force) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3972 var display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3973
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3974 this.viewport = viewport
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3975 // Store some values that we'll need later (but don't want to force a relayout for)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3976 this.visible = visibleLines(display, cm.doc, viewport)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3977 this.editorIsHidden = !display.wrapper.offsetWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3978 this.wrapperHeight = display.wrapper.clientHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3979 this.wrapperWidth = display.wrapper.clientWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3980 this.oldDisplayWidth = displayWidth(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3981 this.force = force
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3982 this.dims = getDimensions(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3983 this.events = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3984 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3985
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3986 DisplayUpdate.prototype.signal = function(emitter, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3987 if (hasHandler(emitter, type))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3988 { this.events.push(arguments) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3989 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3990 DisplayUpdate.prototype.finish = function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3991 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3992
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3993 for (var i = 0; i < this.events.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3994 { signal.apply(null, this$1.events[i]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3995 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3996
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3997 function maybeClipScrollbars(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3998 var display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3999 if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4000 display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4001 display.heightForcer.style.height = scrollGap(cm) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4002 display.sizer.style.marginBottom = -display.nativeBarWidth + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4003 display.sizer.style.borderRightWidth = scrollGap(cm) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4004 display.scrollbarsClipped = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4005 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4006 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4007
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4008 // Does the actual updating of the line display. Bails out
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4009 // (returning false) when there is nothing to be done and forced is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4010 // false.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4011 function updateDisplayIfNeeded(cm, update) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4012 var display = cm.display, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4013
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4014 if (update.editorIsHidden) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4015 resetView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4016 return false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4017 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4018
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4019 // Bail out if the visible area is already rendered and nothing changed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4020 if (!update.force &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4021 update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4022 (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4023 display.renderedView == display.view && countDirtyView(cm) == 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4024 { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4025
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4026 if (maybeUpdateLineNumberWidth(cm)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4027 resetView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4028 update.dims = getDimensions(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4029 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4030
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4031 // Compute a suitable new viewport (from & to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4032 var end = doc.first + doc.size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4033 var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4034 var to = Math.min(end, update.visible.to + cm.options.viewportMargin)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4035 if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4036 if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4037 if (sawCollapsedSpans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4038 from = visualLineNo(cm.doc, from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4039 to = visualLineEndNo(cm.doc, to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4040 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4041
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4042 var different = from != display.viewFrom || to != display.viewTo ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4043 display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4044 adjustView(cm, from, to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4045
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4046 display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4047 // Position the mover div to align with the current scroll position
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4048 cm.display.mover.style.top = display.viewOffset + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4049
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4050 var toUpdate = countDirtyView(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4051 if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4052 (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4053 { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4054
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4055 // For big changes, we hide the enclosing element during the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4056 // update, since that speeds up the operations on most browsers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4057 var focused = activeElt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4058 if (toUpdate > 4) { display.lineDiv.style.display = "none" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4059 patchDisplay(cm, display.updateLineNumbers, update.dims)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4060 if (toUpdate > 4) { display.lineDiv.style.display = "" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4061 display.renderedView = display.view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4062 // There might have been a widget with a focused element that got
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4063 // hidden or updated, if so re-focus it.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4064 if (focused && activeElt() != focused && focused.offsetHeight) { focused.focus() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4065
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4066 // Prevent selection and cursors from interfering with the scroll
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4067 // width and height.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4068 removeChildren(display.cursorDiv)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4069 removeChildren(display.selectionDiv)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4070 display.gutters.style.height = display.sizer.style.minHeight = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4071
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4072 if (different) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4073 display.lastWrapHeight = update.wrapperHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4074 display.lastWrapWidth = update.wrapperWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4075 startWorker(cm, 400)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4076 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4077
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4078 display.updateLineNumbers = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4079
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4080 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4081 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4082
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4083 function postUpdateDisplay(cm, update) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4084 var viewport = update.viewport
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4085
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4086 for (var first = true;; first = false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4087 if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4088 // Clip forced viewport to actual scrollable area.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4089 if (viewport && viewport.top != null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4090 { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4091 // Updated line heights might result in the drawn area not
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4092 // actually covering the viewport. Keep looping until it does.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4093 update.visible = visibleLines(cm.display, cm.doc, viewport)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4094 if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4095 { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4096 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4097 if (!updateDisplayIfNeeded(cm, update)) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4098 updateHeightsInViewport(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4099 var barMeasure = measureForScrollbars(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4100 updateSelection(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4101 updateScrollbars(cm, barMeasure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4102 setDocumentHeight(cm, barMeasure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4103 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4104
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4105 update.signal(cm, "update", cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4106 if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4107 update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4108 cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4109 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4110 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4111
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4112 function updateDisplaySimple(cm, viewport) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4113 var update = new DisplayUpdate(cm, viewport)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4114 if (updateDisplayIfNeeded(cm, update)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4115 updateHeightsInViewport(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4116 postUpdateDisplay(cm, update)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4117 var barMeasure = measureForScrollbars(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4118 updateSelection(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4119 updateScrollbars(cm, barMeasure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4120 setDocumentHeight(cm, barMeasure)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4121 update.finish()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4122 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4123 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4124
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4125 // Sync the actual display DOM structure with display.view, removing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4126 // nodes for lines that are no longer in view, and creating the ones
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4127 // that are not there yet, and updating the ones that are out of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4128 // date.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4129 function patchDisplay(cm, updateNumbersFrom, dims) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4130 var display = cm.display, lineNumbers = cm.options.lineNumbers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4131 var container = display.lineDiv, cur = container.firstChild
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4132
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4133 function rm(node) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4134 var next = node.nextSibling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4135 // Works around a throw-scroll bug in OS X Webkit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4136 if (webkit && mac && cm.display.currentWheelTarget == node)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4137 { node.style.display = "none" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4138 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4139 { node.parentNode.removeChild(node) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4140 return next
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4141 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4142
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4143 var view = display.view, lineN = display.viewFrom
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4144 // Loop over the elements in the view, syncing cur (the DOM nodes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4145 // in display.lineDiv) with the view as we go.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4146 for (var i = 0; i < view.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4147 var lineView = view[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4148 if (lineView.hidden) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4149 } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4150 var node = buildLineElement(cm, lineView, lineN, dims)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4151 container.insertBefore(node, cur)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4152 } else { // Already drawn
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4153 while (cur != lineView.node) { cur = rm(cur) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4154 var updateNumber = lineNumbers && updateNumbersFrom != null &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4155 updateNumbersFrom <= lineN && lineView.lineNumber
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4156 if (lineView.changes) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4157 if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4158 updateLineForChanges(cm, lineView, lineN, dims)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4159 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4160 if (updateNumber) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4161 removeChildren(lineView.lineNumber)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4162 lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4163 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4164 cur = lineView.node.nextSibling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4165 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4166 lineN += lineView.size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4167 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4168 while (cur) { cur = rm(cur) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4169 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4170
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4171 function updateGutterSpace(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4172 var width = cm.display.gutters.offsetWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4173 cm.display.sizer.style.marginLeft = width + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4174 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4175
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4176 function setDocumentHeight(cm, measure) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4177 cm.display.sizer.style.minHeight = measure.docHeight + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4178 cm.display.heightForcer.style.top = measure.docHeight + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4179 cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4180 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4181
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4182 // Rebuild the gutter elements, ensure the margin to the left of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4183 // code matches their width.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4184 function updateGutters(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4185 var gutters = cm.display.gutters, specs = cm.options.gutters
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4186 removeChildren(gutters)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4187 var i = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4188 for (; i < specs.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4189 var gutterClass = specs[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4190 var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4191 if (gutterClass == "CodeMirror-linenumbers") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4192 cm.display.lineGutter = gElt
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4193 gElt.style.width = (cm.display.lineNumWidth || 1) + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4194 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4195 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4196 gutters.style.display = i ? "" : "none"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4197 updateGutterSpace(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4198 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4199
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4200 // Make sure the gutters options contains the element
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4201 // "CodeMirror-linenumbers" when the lineNumbers option is true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4202 function setGuttersForLineNumbers(options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4203 var found = indexOf(options.gutters, "CodeMirror-linenumbers")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4204 if (found == -1 && options.lineNumbers) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4205 options.gutters = options.gutters.concat(["CodeMirror-linenumbers"])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4206 } else if (found > -1 && !options.lineNumbers) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4207 options.gutters = options.gutters.slice(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4208 options.gutters.splice(found, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4209 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4210 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4211
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4212 // Selection objects are immutable. A new one is created every time
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4213 // the selection changes. A selection is one or more non-overlapping
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4214 // (and non-touching) ranges, sorted, and an integer that indicates
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4215 // which one is the primary selection (the one that's scrolled into
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4216 // view, that getCursor returns, etc).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4217 function Selection(ranges, primIndex) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4218 this.ranges = ranges
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4219 this.primIndex = primIndex
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4220 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4221
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4222 Selection.prototype = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4223 primary: function() { return this.ranges[this.primIndex] },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4224 equals: function(other) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4225 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4226
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4227 if (other == this) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4228 if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4229 for (var i = 0; i < this.ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4230 var here = this$1.ranges[i], there = other.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4231 if (cmp(here.anchor, there.anchor) != 0 || cmp(here.head, there.head) != 0) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4232 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4233 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4234 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4235 deepCopy: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4236 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4237
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4238 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4239 for (var i = 0; i < this.ranges.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4240 { out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4241 return new Selection(out, this.primIndex)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4242 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4243 somethingSelected: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4244 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4245
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4246 for (var i = 0; i < this.ranges.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4247 { if (!this$1.ranges[i].empty()) { return true } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4248 return false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4249 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4250 contains: function(pos, end) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4251 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4252
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4253 if (!end) { end = pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4254 for (var i = 0; i < this.ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4255 var range = this$1.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4256 if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4257 { return i }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4258 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4259 return -1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4260 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4261 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4262
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4263 function Range(anchor, head) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4264 this.anchor = anchor; this.head = head
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4265 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4266
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4267 Range.prototype = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4268 from: function() { return minPos(this.anchor, this.head) },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4269 to: function() { return maxPos(this.anchor, this.head) },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4270 empty: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4271 return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4272 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4273 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4274
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4275 // Take an unsorted, potentially overlapping set of ranges, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4276 // build a selection out of it. 'Consumes' ranges array (modifying
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4277 // it).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4278 function normalizeSelection(ranges, primIndex) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4279 var prim = ranges[primIndex]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4280 ranges.sort(function (a, b) { return cmp(a.from(), b.from()); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4281 primIndex = indexOf(ranges, prim)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4282 for (var i = 1; i < ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4283 var cur = ranges[i], prev = ranges[i - 1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4284 if (cmp(prev.to(), cur.from()) >= 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4285 var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4286 var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4287 if (i <= primIndex) { --primIndex }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4288 ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4289 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4290 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4291 return new Selection(ranges, primIndex)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4292 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4293
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4294 function simpleSelection(anchor, head) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4295 return new Selection([new Range(anchor, head || anchor)], 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4296 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4297
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4298 // Compute the position of the end of a change (its 'to' property
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4299 // refers to the pre-change end).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4300 function changeEnd(change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4301 if (!change.text) { return change.to }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4302 return Pos(change.from.line + change.text.length - 1,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4303 lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4304 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4305
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4306 // Adjust a position to refer to the post-change position of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4307 // same text, or the end of the change if the change covers it.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4308 function adjustForChange(pos, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4309 if (cmp(pos, change.from) < 0) { return pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4310 if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4311
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4312 var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4313 if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4314 return Pos(line, ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4315 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4316
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4317 function computeSelAfterChange(doc, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4318 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4319 for (var i = 0; i < doc.sel.ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4320 var range = doc.sel.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4321 out.push(new Range(adjustForChange(range.anchor, change),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4322 adjustForChange(range.head, change)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4323 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4324 return normalizeSelection(out, doc.sel.primIndex)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4325 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4326
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4327 function offsetPos(pos, old, nw) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4328 if (pos.line == old.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4329 { return Pos(nw.line, pos.ch - old.ch + nw.ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4330 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4331 { return Pos(nw.line + (pos.line - old.line), pos.ch) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4332 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4333
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4334 // Used by replaceSelections to allow moving the selection to the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4335 // start or around the replaced test. Hint may be "start" or "around".
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4336 function computeReplacedSel(doc, changes, hint) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4337 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4338 var oldPrev = Pos(doc.first, 0), newPrev = oldPrev
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4339 for (var i = 0; i < changes.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4340 var change = changes[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4341 var from = offsetPos(change.from, oldPrev, newPrev)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4342 var to = offsetPos(changeEnd(change), oldPrev, newPrev)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4343 oldPrev = change.to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4344 newPrev = to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4345 if (hint == "around") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4346 var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4347 out[i] = new Range(inv ? to : from, inv ? from : to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4348 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4349 out[i] = new Range(from, from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4350 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4351 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4352 return new Selection(out, doc.sel.primIndex)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4353 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4354
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4355 // Used to get the editor into a consistent state again when options change.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4356
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4357 function loadMode(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4358 cm.doc.mode = getMode(cm.options, cm.doc.modeOption)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4359 resetModeState(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4360 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4361
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4362 function resetModeState(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4363 cm.doc.iter(function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4364 if (line.stateAfter) { line.stateAfter = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4365 if (line.styles) { line.styles = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4366 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4367 cm.doc.frontier = cm.doc.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4368 startWorker(cm, 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4369 cm.state.modeGen++
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4370 if (cm.curOp) { regChange(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4371 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4372
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4373 // DOCUMENT DATA STRUCTURE
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4374
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4375 // By default, updates that start and end at the beginning of a line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4376 // are treated specially, in order to make the association of line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4377 // widgets and marker elements with the text behave more intuitive.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4378 function isWholeLineUpdate(doc, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4379 return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4380 (!doc.cm || doc.cm.options.wholeLineUpdateBefore)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4381 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4382
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4383 // Perform a change on the document data structure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4384 function updateDoc(doc, change, markedSpans, estimateHeight$$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4385 function spansFor(n) {return markedSpans ? markedSpans[n] : null}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4386 function update(line, text, spans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4387 updateLine(line, text, spans, estimateHeight$$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4388 signalLater(line, "change", line, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4389 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4390 function linesFor(start, end) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4391 var result = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4392 for (var i = start; i < end; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4393 { result.push(new Line(text[i], spansFor(i), estimateHeight$$1)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4394 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4395 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4396
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4397 var from = change.from, to = change.to, text = change.text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4398 var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4399 var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4400
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4401 // Adjust the line structure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4402 if (change.full) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4403 doc.insert(0, linesFor(0, text.length))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4404 doc.remove(text.length, doc.size - text.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4405 } else if (isWholeLineUpdate(doc, change)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4406 // This is a whole-line replace. Treated specially to make
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4407 // sure line objects move the way they are supposed to.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4408 var added = linesFor(0, text.length - 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4409 update(lastLine, lastLine.text, lastSpans)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4410 if (nlines) { doc.remove(from.line, nlines) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4411 if (added.length) { doc.insert(from.line, added) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4412 } else if (firstLine == lastLine) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4413 if (text.length == 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4414 update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4415 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4416 var added$1 = linesFor(1, text.length - 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4417 added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight$$1))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4418 update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4419 doc.insert(from.line + 1, added$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4420 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4421 } else if (text.length == 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4422 update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4423 doc.remove(from.line + 1, nlines)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4424 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4425 update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4426 update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4427 var added$2 = linesFor(1, text.length - 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4428 if (nlines > 1) { doc.remove(from.line + 1, nlines - 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4429 doc.insert(from.line + 1, added$2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4430 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4431
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4432 signalLater(doc, "change", doc, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4433 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4434
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4435 // Call f for all linked documents.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4436 function linkedDocs(doc, f, sharedHistOnly) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4437 function propagate(doc, skip, sharedHist) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4438 if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4439 var rel = doc.linked[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4440 if (rel.doc == skip) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4441 var shared = sharedHist && rel.sharedHist
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4442 if (sharedHistOnly && !shared) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4443 f(rel.doc, shared)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4444 propagate(rel.doc, doc, shared)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4445 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4446 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4447 propagate(doc, null, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4448 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4449
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4450 // Attach a document to an editor.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4451 function attachDoc(cm, doc) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4452 if (doc.cm) { throw new Error("This document is already in use.") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4453 cm.doc = doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4454 doc.cm = cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4455 estimateLineHeights(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4456 loadMode(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4457 if (!cm.options.lineWrapping) { findMaxLine(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4458 cm.options.mode = doc.modeOption
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4459 regChange(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4460 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4461
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4462 function History(startGen) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4463 // Arrays of change events and selections. Doing something adds an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4464 // event to done and clears undo. Undoing moves events from done
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4465 // to undone, redoing moves them in the other direction.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4466 this.done = []; this.undone = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4467 this.undoDepth = Infinity
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4468 // Used to track when changes can be merged into a single undo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4469 // event
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4470 this.lastModTime = this.lastSelTime = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4471 this.lastOp = this.lastSelOp = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4472 this.lastOrigin = this.lastSelOrigin = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4473 // Used by the isClean() method
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4474 this.generation = this.maxGeneration = startGen || 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4475 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4476
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4477 // Create a history change event from an updateDoc-style change
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4478 // object.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4479 function historyChangeFromChange(doc, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4480 var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4481 attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4482 linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4483 return histChange
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4484 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4485
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4486 // Pop all selection events off the end of a history array. Stop at
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4487 // a change event.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4488 function clearSelectionEvents(array) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4489 while (array.length) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4490 var last = lst(array)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4491 if (last.ranges) { array.pop() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4492 else { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4493 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4494 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4495
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4496 // Find the top change event in the history. Pop off selection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4497 // events that are in the way.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4498 function lastChangeEvent(hist, force) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4499 if (force) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4500 clearSelectionEvents(hist.done)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4501 return lst(hist.done)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4502 } else if (hist.done.length && !lst(hist.done).ranges) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4503 return lst(hist.done)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4504 } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4505 hist.done.pop()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4506 return lst(hist.done)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4507 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4508 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4509
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4510 // Register a change in the history. Merges changes that are within
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4511 // a single operation, or are close together with an origin that
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4512 // allows merging (starting with "+") into a single event.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4513 function addChangeToHistory(doc, change, selAfter, opId) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4514 var hist = doc.history
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4515 hist.undone.length = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4516 var time = +new Date, cur
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4517 var last
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4518
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4519 if ((hist.lastOp == opId ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4520 hist.lastOrigin == change.origin && change.origin &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4521 ((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4522 change.origin.charAt(0) == "*")) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4523 (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4524 // Merge this change into the last event
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4525 last = lst(cur.changes)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4526 if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4527 // Optimized case for simple insertion -- don't want to add
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4528 // new changesets for every character typed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4529 last.to = changeEnd(change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4530 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4531 // Add new sub-event
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4532 cur.changes.push(historyChangeFromChange(doc, change))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4533 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4534 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4535 // Can not be merged, start a new event.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4536 var before = lst(hist.done)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4537 if (!before || !before.ranges)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4538 { pushSelectionToHistory(doc.sel, hist.done) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4539 cur = {changes: [historyChangeFromChange(doc, change)],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4540 generation: hist.generation}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4541 hist.done.push(cur)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4542 while (hist.done.length > hist.undoDepth) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4543 hist.done.shift()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4544 if (!hist.done[0].ranges) { hist.done.shift() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4545 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4546 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4547 hist.done.push(selAfter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4548 hist.generation = ++hist.maxGeneration
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4549 hist.lastModTime = hist.lastSelTime = time
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4550 hist.lastOp = hist.lastSelOp = opId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4551 hist.lastOrigin = hist.lastSelOrigin = change.origin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4552
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4553 if (!last) { signal(doc, "historyAdded") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4554 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4555
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4556 function selectionEventCanBeMerged(doc, origin, prev, sel) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4557 var ch = origin.charAt(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4558 return ch == "*" ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4559 ch == "+" &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4560 prev.ranges.length == sel.ranges.length &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4561 prev.somethingSelected() == sel.somethingSelected() &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4562 new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4563 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4564
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4565 // Called whenever the selection changes, sets the new selection as
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4566 // the pending selection in the history, and pushes the old pending
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4567 // selection into the 'done' array when it was significantly
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4568 // different (in number of selected ranges, emptiness, or time).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4569 function addSelectionToHistory(doc, sel, opId, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4570 var hist = doc.history, origin = options && options.origin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4571
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4572 // A new event is started when the previous origin does not match
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4573 // the current, or the origins don't allow matching. Origins
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4574 // starting with * are always merged, those starting with + are
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4575 // merged when similar and close together in time.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4576 if (opId == hist.lastSelOp ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4577 (origin && hist.lastSelOrigin == origin &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4578 (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4579 selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4580 { hist.done[hist.done.length - 1] = sel }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4581 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4582 { pushSelectionToHistory(sel, hist.done) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4583
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4584 hist.lastSelTime = +new Date
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4585 hist.lastSelOrigin = origin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4586 hist.lastSelOp = opId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4587 if (options && options.clearRedo !== false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4588 { clearSelectionEvents(hist.undone) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4589 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4590
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4591 function pushSelectionToHistory(sel, dest) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4592 var top = lst(dest)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4593 if (!(top && top.ranges && top.equals(sel)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4594 { dest.push(sel) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4595 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4596
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4597 // Used to store marked span information in the history.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4598 function attachLocalSpans(doc, change, from, to) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4599 var existing = change["spans_" + doc.id], n = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4600 doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4601 if (line.markedSpans)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4602 { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4603 ++n
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4604 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4605 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4606
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4607 // When un/re-doing restores text containing marked spans, those
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4608 // that have been explicitly cleared should not be restored.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4609 function removeClearedSpans(spans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4610 if (!spans) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4611 var out
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4612 for (var i = 0; i < spans.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4613 if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4614 else if (out) { out.push(spans[i]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4615 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4616 return !out ? spans : out.length ? out : null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4617 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4618
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4619 // Retrieve and filter the old marked spans stored in a change event.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4620 function getOldSpans(doc, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4621 var found = change["spans_" + doc.id]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4622 if (!found) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4623 var nw = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4624 for (var i = 0; i < change.text.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4625 { nw.push(removeClearedSpans(found[i])) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4626 return nw
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4627 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4628
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4629 // Used for un/re-doing changes from the history. Combines the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4630 // result of computing the existing spans with the set of spans that
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4631 // existed in the history (so that deleting around a span and then
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4632 // undoing brings back the span).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4633 function mergeOldSpans(doc, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4634 var old = getOldSpans(doc, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4635 var stretched = stretchSpansOverChange(doc, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4636 if (!old) { return stretched }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4637 if (!stretched) { return old }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4638
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4639 for (var i = 0; i < old.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4640 var oldCur = old[i], stretchCur = stretched[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4641 if (oldCur && stretchCur) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4642 spans: for (var j = 0; j < stretchCur.length; ++j) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4643 var span = stretchCur[j]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4644 for (var k = 0; k < oldCur.length; ++k)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4645 { if (oldCur[k].marker == span.marker) { continue spans } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4646 oldCur.push(span)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4647 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4648 } else if (stretchCur) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4649 old[i] = stretchCur
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4650 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4651 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4652 return old
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4653 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4654
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4655 // Used both to provide a JSON-safe object in .getHistory, and, when
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4656 // detaching a document, to split the history in two
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4657 function copyHistoryArray(events, newGroup, instantiateSel) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4658 var copy = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4659 for (var i = 0; i < events.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4660 var event = events[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4661 if (event.ranges) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4662 copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4663 continue
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4664 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4665 var changes = event.changes, newChanges = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4666 copy.push({changes: newChanges})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4667 for (var j = 0; j < changes.length; ++j) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4668 var change = changes[j], m = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4669 newChanges.push({from: change.from, to: change.to, text: change.text})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4670 if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4671 if (indexOf(newGroup, Number(m[1])) > -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4672 lst(newChanges)[prop] = change[prop]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4673 delete change[prop]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4674 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4675 } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4676 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4677 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4678 return copy
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4679 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4680
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4681 // The 'scroll' parameter given to many of these indicated whether
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4682 // the new cursor position should be scrolled into view after
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4683 // modifying the selection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4684
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4685 // If shift is held or the extend flag is set, extends a range to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4686 // include a given position (and optionally a second position).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4687 // Otherwise, simply returns the range between the given positions.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4688 // Used for cursor motion and such.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4689 function extendRange(doc, range, head, other) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4690 if (doc.cm && doc.cm.display.shift || doc.extend) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4691 var anchor = range.anchor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4692 if (other) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4693 var posBefore = cmp(head, anchor) < 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4694 if (posBefore != (cmp(other, anchor) < 0)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4695 anchor = head
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4696 head = other
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4697 } else if (posBefore != (cmp(head, other) < 0)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4698 head = other
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4699 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4700 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4701 return new Range(anchor, head)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4702 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4703 return new Range(other || head, head)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4704 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4705 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4706
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4707 // Extend the primary selection range, discard the rest.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4708 function extendSelection(doc, head, other, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4709 setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4710 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4711
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4712 // Extend all selections (pos is an array of selections with length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4713 // equal the number of selections)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4714 function extendSelections(doc, heads, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4715 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4716 for (var i = 0; i < doc.sel.ranges.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4717 { out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4718 var newSel = normalizeSelection(out, doc.sel.primIndex)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4719 setSelection(doc, newSel, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4720 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4721
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4722 // Updates a single range in the selection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4723 function replaceOneSelection(doc, i, range, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4724 var ranges = doc.sel.ranges.slice(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4725 ranges[i] = range
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4726 setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4727 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4728
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4729 // Reset the selection to a single range.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4730 function setSimpleSelection(doc, anchor, head, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4731 setSelection(doc, simpleSelection(anchor, head), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4732 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4733
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4734 // Give beforeSelectionChange handlers a change to influence a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4735 // selection update.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4736 function filterSelectionChange(doc, sel, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4737 var obj = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4738 ranges: sel.ranges,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4739 update: function(ranges) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4740 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4741
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4742 this.ranges = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4743 for (var i = 0; i < ranges.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4744 { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4745 clipPos(doc, ranges[i].head)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4746 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4747 origin: options && options.origin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4748 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4749 signal(doc, "beforeSelectionChange", doc, obj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4750 if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4751 if (obj.ranges != sel.ranges) { return normalizeSelection(obj.ranges, obj.ranges.length - 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4752 else { return sel }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4753 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4754
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4755 function setSelectionReplaceHistory(doc, sel, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4756 var done = doc.history.done, last = lst(done)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4757 if (last && last.ranges) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4758 done[done.length - 1] = sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4759 setSelectionNoUndo(doc, sel, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4760 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4761 setSelection(doc, sel, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4762 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4763 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4764
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4765 // Set a new selection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4766 function setSelection(doc, sel, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4767 setSelectionNoUndo(doc, sel, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4768 addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4769 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4770
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4771 function setSelectionNoUndo(doc, sel, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4772 if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4773 { sel = filterSelectionChange(doc, sel, options) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4774
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4775 var bias = options && options.bias ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4776 (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4777 setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4778
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4779 if (!(options && options.scroll === false) && doc.cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4780 { ensureCursorVisible(doc.cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4781 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4782
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4783 function setSelectionInner(doc, sel) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4784 if (sel.equals(doc.sel)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4785
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4786 doc.sel = sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4787
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4788 if (doc.cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4789 doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4790 signalCursorActivity(doc.cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4791 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4792 signalLater(doc, "cursorActivity", doc)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4793 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4794
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4795 // Verify that the selection does not partially select any atomic
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4796 // marked ranges.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4797 function reCheckSelection(doc) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4798 setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4799 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4800
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4801 // Return a selection that does not partially select any atomic
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4802 // ranges.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4803 function skipAtomicInSelection(doc, sel, bias, mayClear) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4804 var out
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4805 for (var i = 0; i < sel.ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4806 var range = sel.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4807 var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4808 var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4809 var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4810 if (out || newAnchor != range.anchor || newHead != range.head) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4811 if (!out) { out = sel.ranges.slice(0, i) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4812 out[i] = new Range(newAnchor, newHead)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4813 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4814 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4815 return out ? normalizeSelection(out, sel.primIndex) : sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4816 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4817
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4818 function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4819 var line = getLine(doc, pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4820 if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4821 var sp = line.markedSpans[i], m = sp.marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4822 if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4823 (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4824 if (mayClear) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4825 signal(m, "beforeCursorEnter")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4826 if (m.explicitlyCleared) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4827 if (!line.markedSpans) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4828 else {--i; continue}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4829 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4830 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4831 if (!m.atomic) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4832
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4833 if (oldPos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4834 var near = m.find(dir < 0 ? 1 : -1), diff = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4835 if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4836 { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4837 if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4838 { return skipAtomicInner(doc, near, pos, dir, mayClear) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4839 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4840
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4841 var far = m.find(dir < 0 ? -1 : 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4842 if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4843 { far = movePos(doc, far, dir, far.line == pos.line ? line : null) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4844 return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4845 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4846 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4847 return pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4848 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4849
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4850 // Ensure a given position is not inside an atomic range.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4851 function skipAtomic(doc, pos, oldPos, bias, mayClear) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4852 var dir = bias || 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4853 var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4854 (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4855 skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4856 (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4857 if (!found) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4858 doc.cantEdit = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4859 return Pos(doc.first, 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4860 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4861 return found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4862 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4863
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4864 function movePos(doc, pos, dir, line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4865 if (dir < 0 && pos.ch == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4866 if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4867 else { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4868 } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4869 if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4870 else { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4871 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4872 return new Pos(pos.line, pos.ch + dir)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4873 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4874 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4875
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4876 function selectAll(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4877 cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4878 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4879
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4880 // UPDATING
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4881
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4882 // Allow "beforeChange" event handlers to influence a change
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4883 function filterChange(doc, change, update) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4884 var obj = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4885 canceled: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4886 from: change.from,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4887 to: change.to,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4888 text: change.text,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4889 origin: change.origin,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4890 cancel: function () { return obj.canceled = true; }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4891 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4892 if (update) { obj.update = function (from, to, text, origin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4893 if (from) { obj.from = clipPos(doc, from) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4894 if (to) { obj.to = clipPos(doc, to) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4895 if (text) { obj.text = text }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4896 if (origin !== undefined) { obj.origin = origin }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4897 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4898 signal(doc, "beforeChange", doc, obj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4899 if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4900
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4901 if (obj.canceled) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4902 return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4903 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4904
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4905 // Apply a change to a document, and add it to the document's
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4906 // history, and propagating it to all linked documents.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4907 function makeChange(doc, change, ignoreReadOnly) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4908 if (doc.cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4909 if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4910 if (doc.cm.state.suppressEdits) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4911 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4912
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4913 if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4914 change = filterChange(doc, change, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4915 if (!change) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4916 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4917
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4918 // Possibly split or suppress the update based on the presence
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4919 // of read-only spans in its range.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4920 var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4921 if (split) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4922 for (var i = split.length - 1; i >= 0; --i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4923 { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text}) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4924 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4925 makeChangeInner(doc, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4926 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4927 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4928
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4929 function makeChangeInner(doc, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4930 if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4931 var selAfter = computeSelAfterChange(doc, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4932 addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4933
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4934 makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4935 var rebased = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4936
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4937 linkedDocs(doc, function (doc, sharedHist) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4938 if (!sharedHist && indexOf(rebased, doc.history) == -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4939 rebaseHist(doc.history, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4940 rebased.push(doc.history)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4941 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4942 makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4943 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4944 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4945
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4946 // Revert a change stored in a document's history.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4947 function makeChangeFromHistory(doc, type, allowSelectionOnly) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4948 if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4949
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4950 var hist = doc.history, event, selAfter = doc.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4951 var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4952
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4953 // Verify that there is a useable event (so that ctrl-z won't
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4954 // needlessly clear selection events)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4955 var i = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4956 for (; i < source.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4957 event = source[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4958 if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4959 { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4960 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4961 if (i == source.length) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4962 hist.lastOrigin = hist.lastSelOrigin = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4963
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4964 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4965 event = source.pop()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4966 if (event.ranges) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4967 pushSelectionToHistory(event, dest)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4968 if (allowSelectionOnly && !event.equals(doc.sel)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4969 setSelection(doc, event, {clearRedo: false})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4970 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4971 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4972 selAfter = event
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4973 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4974 else { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4975 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4976
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4977 // Build up a reverse change object to add to the opposite history
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4978 // stack (redo when undoing, and vice versa).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4979 var antiChanges = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4980 pushSelectionToHistory(selAfter, dest)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4981 dest.push({changes: antiChanges, generation: hist.generation})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4982 hist.generation = event.generation || ++hist.maxGeneration
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4983
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4984 var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4985
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4986 var loop = function ( i ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4987 var change = event.changes[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4988 change.origin = type
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4989 if (filter && !filterChange(doc, change, false)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4990 source.length = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4991 return {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4992 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4993
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4994 antiChanges.push(historyChangeFromChange(doc, change))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4995
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4996 var after = i ? computeSelAfterChange(doc, change) : lst(source)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4997 makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4998 if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4999 var rebased = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5000
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5001 // Propagate to the linked documents
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5002 linkedDocs(doc, function (doc, sharedHist) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5003 if (!sharedHist && indexOf(rebased, doc.history) == -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5004 rebaseHist(doc.history, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5005 rebased.push(doc.history)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5006 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5007 makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5008 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5009 };
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5010
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5011 for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5012 var returned = loop( i$1 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5013
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5014 if ( returned ) return returned.v;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5015 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5016 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5017
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5018 // Sub-views need their line numbers shifted when text is added
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5019 // above or below them in the parent document.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5020 function shiftDoc(doc, distance) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5021 if (distance == 0) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5022 doc.first += distance
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5023 doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5024 Pos(range.anchor.line + distance, range.anchor.ch),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5025 Pos(range.head.line + distance, range.head.ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5026 ); }), doc.sel.primIndex)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5027 if (doc.cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5028 regChange(doc.cm, doc.first, doc.first - distance, distance)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5029 for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5030 { regLineChange(doc.cm, l, "gutter") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5031 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5032 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5033
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5034 // More lower-level change function, handling only a single document
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5035 // (not linked ones).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5036 function makeChangeSingleDoc(doc, change, selAfter, spans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5037 if (doc.cm && !doc.cm.curOp)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5038 { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5039
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5040 if (change.to.line < doc.first) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5041 shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5042 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5043 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5044 if (change.from.line > doc.lastLine()) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5045
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5046 // Clip the change to the size of this doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5047 if (change.from.line < doc.first) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5048 var shift = change.text.length - 1 - (doc.first - change.from.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5049 shiftDoc(doc, shift)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5050 change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5051 text: [lst(change.text)], origin: change.origin}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5052 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5053 var last = doc.lastLine()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5054 if (change.to.line > last) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5055 change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5056 text: [change.text[0]], origin: change.origin}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5057 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5058
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5059 change.removed = getBetween(doc, change.from, change.to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5060
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5061 if (!selAfter) { selAfter = computeSelAfterChange(doc, change) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5062 if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5063 else { updateDoc(doc, change, spans) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5064 setSelectionNoUndo(doc, selAfter, sel_dontScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5065 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5066
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5067 // Handle the interaction of a change to a document with the editor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5068 // that this document is part of.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5069 function makeChangeSingleDocInEditor(cm, change, spans) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5070 var doc = cm.doc, display = cm.display, from = change.from, to = change.to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5071
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5072 var recomputeMaxLength = false, checkWidthStart = from.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5073 if (!cm.options.lineWrapping) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5074 checkWidthStart = lineNo(visualLine(getLine(doc, from.line)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5075 doc.iter(checkWidthStart, to.line + 1, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5076 if (line == display.maxLine) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5077 recomputeMaxLength = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5078 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5079 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5080 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5081 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5082
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5083 if (doc.sel.contains(change.from, change.to) > -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5084 { signalCursorActivity(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5085
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5086 updateDoc(doc, change, spans, estimateHeight(cm))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5087
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5088 if (!cm.options.lineWrapping) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5089 doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5090 var len = lineLength(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5091 if (len > display.maxLineLength) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5092 display.maxLine = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5093 display.maxLineLength = len
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5094 display.maxLineChanged = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5095 recomputeMaxLength = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5096 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5097 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5098 if (recomputeMaxLength) { cm.curOp.updateMaxLine = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5099 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5100
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5101 // Adjust frontier, schedule worker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5102 doc.frontier = Math.min(doc.frontier, from.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5103 startWorker(cm, 400)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5104
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5105 var lendiff = change.text.length - (to.line - from.line) - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5106 // Remember that these lines changed, for updating the display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5107 if (change.full)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5108 { regChange(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5109 else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5110 { regLineChange(cm, from.line, "text") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5111 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5112 { regChange(cm, from.line, to.line + 1, lendiff) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5113
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5114 var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5115 if (changeHandler || changesHandler) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5116 var obj = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5117 from: from, to: to,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5118 text: change.text,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5119 removed: change.removed,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5120 origin: change.origin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5121 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5122 if (changeHandler) { signalLater(cm, "change", cm, obj) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5123 if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5124 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5125 cm.display.selForContextMenu = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5126 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5127
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5128 function replaceRange(doc, code, from, to, origin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5129 if (!to) { to = from }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5130 if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5131 if (typeof code == "string") { code = doc.splitLines(code) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5132 makeChange(doc, {from: from, to: to, text: code, origin: origin})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5133 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5134
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5135 // Rebasing/resetting history to deal with externally-sourced changes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5136
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5137 function rebaseHistSelSingle(pos, from, to, diff) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5138 if (to < pos.line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5139 pos.line += diff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5140 } else if (from < pos.line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5141 pos.line = from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5142 pos.ch = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5143 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5144 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5145
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5146 // Tries to rebase an array of history events given a change in the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5147 // document. If the change touches the same lines as the event, the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5148 // event, and everything 'behind' it, is discarded. If the change is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5149 // before the event, the event's positions are updated. Uses a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5150 // copy-on-write scheme for the positions, to avoid having to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5151 // reallocate them all on every rebase, but also avoid problems with
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5152 // shared position objects being unsafely updated.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5153 function rebaseHistArray(array, from, to, diff) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5154 for (var i = 0; i < array.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5155 var sub = array[i], ok = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5156 if (sub.ranges) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5157 if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5158 for (var j = 0; j < sub.ranges.length; j++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5159 rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5160 rebaseHistSelSingle(sub.ranges[j].head, from, to, diff)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5161 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5162 continue
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5163 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5164 for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5165 var cur = sub.changes[j$1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5166 if (to < cur.from.line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5167 cur.from = Pos(cur.from.line + diff, cur.from.ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5168 cur.to = Pos(cur.to.line + diff, cur.to.ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5169 } else if (from <= cur.to.line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5170 ok = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5171 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5172 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5173 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5174 if (!ok) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5175 array.splice(0, i + 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5176 i = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5177 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5178 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5179 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5180
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5181 function rebaseHist(hist, change) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5182 var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5183 rebaseHistArray(hist.done, from, to, diff)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5184 rebaseHistArray(hist.undone, from, to, diff)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5185 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5186
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5187 // Utility for applying a change to a line by handle or number,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5188 // returning the number and optionally registering the line as
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5189 // changed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5190 function changeLine(doc, handle, changeType, op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5191 var no = handle, line = handle
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5192 if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5193 else { no = lineNo(handle) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5194 if (no == null) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5195 if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5196 return line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5197 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5198
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5199 // The document is represented as a BTree consisting of leaves, with
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5200 // chunk of lines in them, and branches, with up to ten leaves or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5201 // other branch nodes below them. The top node is always a branch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5202 // node, and is the document object itself (meaning it has
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5203 // additional methods and properties).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5204 //
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5205 // All nodes have parent links. The tree is used both to go from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5206 // line numbers to line objects, and to go from objects to numbers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5207 // It also indexes by height, and is used to convert between height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5208 // and line object, and to find the total height of the document.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5209 //
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5210 // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5211
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5212 function LeafChunk(lines) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5213 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5214
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5215 this.lines = lines
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5216 this.parent = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5217 var height = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5218 for (var i = 0; i < lines.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5219 lines[i].parent = this$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5220 height += lines[i].height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5221 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5222 this.height = height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5223 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5224
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5225 LeafChunk.prototype = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5226 chunkSize: function() { return this.lines.length },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5227 // Remove the n lines at offset 'at'.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5228 removeInner: function(at, n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5229 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5230
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5231 for (var i = at, e = at + n; i < e; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5232 var line = this$1.lines[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5233 this$1.height -= line.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5234 cleanUpLine(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5235 signalLater(line, "delete")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5236 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5237 this.lines.splice(at, n)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5238 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5239 // Helper used to collapse a small branch into a single leaf.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5240 collapse: function(lines) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5241 lines.push.apply(lines, this.lines)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5242 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5243 // Insert the given array of lines at offset 'at', count them as
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5244 // having the given height.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5245 insertInner: function(at, lines, height) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5246 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5247
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5248 this.height += height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5249 this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5250 for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5251 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5252 // Used to iterate over a part of the tree.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5253 iterN: function(at, n, op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5254 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5255
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5256 for (var e = at + n; at < e; ++at)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5257 { if (op(this$1.lines[at])) { return true } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5258 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5259 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5260
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5261 function BranchChunk(children) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5262 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5263
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5264 this.children = children
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5265 var size = 0, height = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5266 for (var i = 0; i < children.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5267 var ch = children[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5268 size += ch.chunkSize(); height += ch.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5269 ch.parent = this$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5270 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5271 this.size = size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5272 this.height = height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5273 this.parent = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5274 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5275
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5276 BranchChunk.prototype = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5277 chunkSize: function() { return this.size },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5278 removeInner: function(at, n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5279 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5280
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5281 this.size -= n
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5282 for (var i = 0; i < this.children.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5283 var child = this$1.children[i], sz = child.chunkSize()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5284 if (at < sz) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5285 var rm = Math.min(n, sz - at), oldHeight = child.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5286 child.removeInner(at, rm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5287 this$1.height -= oldHeight - child.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5288 if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5289 if ((n -= rm) == 0) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5290 at = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5291 } else { at -= sz }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5292 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5293 // If the result is smaller than 25 lines, ensure that it is a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5294 // single leaf node.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5295 if (this.size - n < 25 &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5296 (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5297 var lines = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5298 this.collapse(lines)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5299 this.children = [new LeafChunk(lines)]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5300 this.children[0].parent = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5301 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5302 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5303 collapse: function(lines) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5304 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5305
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5306 for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5307 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5308 insertInner: function(at, lines, height) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5309 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5310
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5311 this.size += lines.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5312 this.height += height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5313 for (var i = 0; i < this.children.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5314 var child = this$1.children[i], sz = child.chunkSize()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5315 if (at <= sz) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5316 child.insertInner(at, lines, height)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5317 if (child.lines && child.lines.length > 50) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5318 // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5319 // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5320 var remaining = child.lines.length % 25 + 25
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5321 for (var pos = remaining; pos < child.lines.length;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5322 var leaf = new LeafChunk(child.lines.slice(pos, pos += 25))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5323 child.height -= leaf.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5324 this$1.children.splice(++i, 0, leaf)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5325 leaf.parent = this$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5326 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5327 child.lines = child.lines.slice(0, remaining)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5328 this$1.maybeSpill()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5329 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5330 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5331 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5332 at -= sz
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5333 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5334 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5335 // When a node has grown, check whether it should be split.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5336 maybeSpill: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5337 if (this.children.length <= 10) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5338 var me = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5339 do {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5340 var spilled = me.children.splice(me.children.length - 5, 5)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5341 var sibling = new BranchChunk(spilled)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5342 if (!me.parent) { // Become the parent node
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5343 var copy = new BranchChunk(me.children)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5344 copy.parent = me
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5345 me.children = [copy, sibling]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5346 me = copy
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5347 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5348 me.size -= sibling.size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5349 me.height -= sibling.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5350 var myIndex = indexOf(me.parent.children, me)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5351 me.parent.children.splice(myIndex + 1, 0, sibling)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5352 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5353 sibling.parent = me.parent
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5354 } while (me.children.length > 10)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5355 me.parent.maybeSpill()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5356 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5357 iterN: function(at, n, op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5358 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5359
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5360 for (var i = 0; i < this.children.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5361 var child = this$1.children[i], sz = child.chunkSize()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5362 if (at < sz) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5363 var used = Math.min(n, sz - at)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5364 if (child.iterN(at, used, op)) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5365 if ((n -= used) == 0) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5366 at = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5367 } else { at -= sz }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5368 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5369 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5370 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5371
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5372 // Line widgets are block elements displayed above or below a line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5373
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5374 function LineWidget(doc, node, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5375 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5376
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5377 if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5378 { this$1[opt] = options[opt] } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5379 this.doc = doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5380 this.node = node
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5381 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5382 eventMixin(LineWidget)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5383
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5384 function adjustScrollWhenAboveVisible(cm, line, diff) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5385 if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5386 { addToScrollPos(cm, null, diff) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5387 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5388
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5389 LineWidget.prototype.clear = function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5390 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5391
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5392 var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5393 if (no == null || !ws) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5394 for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5395 if (!ws.length) { line.widgets = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5396 var height = widgetHeight(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5397 updateLineHeight(line, Math.max(0, line.height - height))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5398 if (cm) { runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5399 adjustScrollWhenAboveVisible(cm, line, -height)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5400 regLineChange(cm, no, "widget")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5401 }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5402 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5403 LineWidget.prototype.changed = function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5404 var oldH = this.height, cm = this.doc.cm, line = this.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5405 this.height = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5406 var diff = widgetHeight(this) - oldH
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5407 if (!diff) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5408 updateLineHeight(line, line.height + diff)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5409 if (cm) { runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5410 cm.curOp.forceUpdate = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5411 adjustScrollWhenAboveVisible(cm, line, diff)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5412 }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5413 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5414
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5415 function addLineWidget(doc, handle, node, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5416 var widget = new LineWidget(doc, node, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5417 var cm = doc.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5418 if (cm && widget.noHScroll) { cm.display.alignWidgets = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5419 changeLine(doc, handle, "widget", function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5420 var widgets = line.widgets || (line.widgets = [])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5421 if (widget.insertAt == null) { widgets.push(widget) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5422 else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5423 widget.line = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5424 if (cm && !lineIsHidden(doc, line)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5425 var aboveVisible = heightAtLine(line) < doc.scrollTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5426 updateLineHeight(line, line.height + widgetHeight(widget))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5427 if (aboveVisible) { addToScrollPos(cm, null, widget.height) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5428 cm.curOp.forceUpdate = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5429 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5430 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5431 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5432 return widget
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5433 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5434
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5435 // TEXTMARKERS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5436
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5437 // Created with markText and setBookmark methods. A TextMarker is a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5438 // handle that can be used to clear or find a marked position in the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5439 // document. Line objects hold arrays (markedSpans) containing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5440 // {from, to, marker} object pointing to such marker objects, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5441 // indicating that such a marker is present on that line. Multiple
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5442 // lines may point to the same marker when it spans across lines.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5443 // The spans will have null for their from/to properties when the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5444 // marker continues beyond the start/end of the line. Markers have
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5445 // links back to the lines they currently touch.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5446
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5447 // Collapsed markers have unique ids, in order to be able to order
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5448 // them, which is needed for uniquely determining an outer marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5449 // when they overlap (they may nest, but not partially overlap).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5450 var nextMarkerId = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5451
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5452 function TextMarker(doc, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5453 this.lines = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5454 this.type = type
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5455 this.doc = doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5456 this.id = ++nextMarkerId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5457 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5458 eventMixin(TextMarker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5459
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5460 // Clear the marker.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5461 TextMarker.prototype.clear = function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5462 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5463
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5464 if (this.explicitlyCleared) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5465 var cm = this.doc.cm, withOp = cm && !cm.curOp
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5466 if (withOp) { startOperation(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5467 if (hasHandler(this, "clear")) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5468 var found = this.find()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5469 if (found) { signalLater(this, "clear", found.from, found.to) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5470 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5471 var min = null, max = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5472 for (var i = 0; i < this.lines.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5473 var line = this$1.lines[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5474 var span = getMarkedSpanFor(line.markedSpans, this$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5475 if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5476 else if (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5477 if (span.to != null) { max = lineNo(line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5478 if (span.from != null) { min = lineNo(line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5479 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5480 line.markedSpans = removeMarkedSpan(line.markedSpans, span)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5481 if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5482 { updateLineHeight(line, textHeight(cm.display)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5483 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5484 if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5485 var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5486 if (len > cm.display.maxLineLength) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5487 cm.display.maxLine = visual
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5488 cm.display.maxLineLength = len
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5489 cm.display.maxLineChanged = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5490 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5491 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5492
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5493 if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5494 this.lines.length = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5495 this.explicitlyCleared = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5496 if (this.atomic && this.doc.cantEdit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5497 this.doc.cantEdit = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5498 if (cm) { reCheckSelection(cm.doc) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5499 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5500 if (cm) { signalLater(cm, "markerCleared", cm, this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5501 if (withOp) { endOperation(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5502 if (this.parent) { this.parent.clear() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5503 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5504
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5505 // Find the position of the marker in the document. Returns a {from,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5506 // to} object by default. Side can be passed to get a specific side
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5507 // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5508 // Pos objects returned contain a line object, rather than a line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5509 // number (used to prevent looking up the same line twice).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5510 TextMarker.prototype.find = function(side, lineObj) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5511 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5512
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5513 if (side == null && this.type == "bookmark") { side = 1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5514 var from, to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5515 for (var i = 0; i < this.lines.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5516 var line = this$1.lines[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5517 var span = getMarkedSpanFor(line.markedSpans, this$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5518 if (span.from != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5519 from = Pos(lineObj ? line : lineNo(line), span.from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5520 if (side == -1) { return from }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5521 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5522 if (span.to != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5523 to = Pos(lineObj ? line : lineNo(line), span.to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5524 if (side == 1) { return to }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5525 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5526 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5527 return from && {from: from, to: to}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5528 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5529
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5530 // Signals that the marker's widget changed, and surrounding layout
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5531 // should be recomputed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5532 TextMarker.prototype.changed = function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5533 var pos = this.find(-1, true), widget = this, cm = this.doc.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5534 if (!pos || !cm) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5535 runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5536 var line = pos.line, lineN = lineNo(pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5537 var view = findViewForLine(cm, lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5538 if (view) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5539 clearLineMeasurementCacheFor(view)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5540 cm.curOp.selectionChanged = cm.curOp.forceUpdate = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5541 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5542 cm.curOp.updateMaxLine = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5543 if (!lineIsHidden(widget.doc, line) && widget.height != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5544 var oldHeight = widget.height
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5545 widget.height = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5546 var dHeight = widgetHeight(widget) - oldHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5547 if (dHeight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5548 { updateLineHeight(line, line.height + dHeight) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5549 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5550 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5551 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5552
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5553 TextMarker.prototype.attachLine = function(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5554 if (!this.lines.length && this.doc.cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5555 var op = this.doc.cm.curOp
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5556 if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5557 { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5558 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5559 this.lines.push(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5560 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5561 TextMarker.prototype.detachLine = function(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5562 this.lines.splice(indexOf(this.lines, line), 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5563 if (!this.lines.length && this.doc.cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5564 var op = this.doc.cm.curOp;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5565 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5566 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5567
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5568 // Create a marker, wire it up to the right lines, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5569 function markText(doc, from, to, options, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5570 // Shared markers (across linked documents) are handled separately
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5571 // (markTextShared will call out to this again, once per
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5572 // document).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5573 if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5574 // Ensure we are in an operation.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5575 if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5576
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5577 var marker = new TextMarker(doc, type), diff = cmp(from, to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5578 if (options) { copyObj(options, marker, false) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5579 // Don't connect empty markers unless clearWhenEmpty is false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5580 if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5581 { return marker }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5582 if (marker.replacedWith) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5583 // Showing up as a widget implies collapsed (widget replaces text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5584 marker.collapsed = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5585 marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5586 if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5587 if (options.insertLeft) { marker.widgetNode.insertLeft = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5588 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5589 if (marker.collapsed) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5590 if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5591 from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5592 { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5593 seeCollapsedSpans()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5594 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5595
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5596 if (marker.addToHistory)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5597 { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5598
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5599 var curLine = from.line, cm = doc.cm, updateMaxLine
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5600 doc.iter(curLine, to.line + 1, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5601 if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5602 { updateMaxLine = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5603 if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5604 addMarkedSpan(line, new MarkedSpan(marker,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5605 curLine == from.line ? from.ch : null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5606 curLine == to.line ? to.ch : null))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5607 ++curLine
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5608 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5609 // lineIsHidden depends on the presence of the spans, so needs a second pass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5610 if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5611 if (lineIsHidden(doc, line)) { updateLineHeight(line, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5612 }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5613
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5614 if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5615
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5616 if (marker.readOnly) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5617 seeReadOnlySpans()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5618 if (doc.history.done.length || doc.history.undone.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5619 { doc.clearHistory() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5620 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5621 if (marker.collapsed) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5622 marker.id = ++nextMarkerId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5623 marker.atomic = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5624 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5625 if (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5626 // Sync editor state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5627 if (updateMaxLine) { cm.curOp.updateMaxLine = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5628 if (marker.collapsed)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5629 { regChange(cm, from.line, to.line + 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5630 else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5631 { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text") } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5632 if (marker.atomic) { reCheckSelection(cm.doc) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5633 signalLater(cm, "markerAdded", cm, marker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5634 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5635 return marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5636 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5637
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5638 // SHARED TEXTMARKERS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5639
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5640 // A shared marker spans multiple linked documents. It is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5641 // implemented as a meta-marker-object controlling multiple normal
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5642 // markers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5643 function SharedTextMarker(markers, primary) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5644 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5645
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5646 this.markers = markers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5647 this.primary = primary
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5648 for (var i = 0; i < markers.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5649 { markers[i].parent = this$1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5650 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5651 eventMixin(SharedTextMarker)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5652
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5653 SharedTextMarker.prototype.clear = function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5654 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5655
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5656 if (this.explicitlyCleared) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5657 this.explicitlyCleared = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5658 for (var i = 0; i < this.markers.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5659 { this$1.markers[i].clear() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5660 signalLater(this, "clear")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5661 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5662 SharedTextMarker.prototype.find = function(side, lineObj) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5663 return this.primary.find(side, lineObj)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5664 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5665
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5666 function markTextShared(doc, from, to, options, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5667 options = copyObj(options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5668 options.shared = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5669 var markers = [markText(doc, from, to, options, type)], primary = markers[0]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5670 var widget = options.widgetNode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5671 linkedDocs(doc, function (doc) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5672 if (widget) { options.widgetNode = widget.cloneNode(true) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5673 markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5674 for (var i = 0; i < doc.linked.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5675 { if (doc.linked[i].isParent) { return } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5676 primary = lst(markers)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5677 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5678 return new SharedTextMarker(markers, primary)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5679 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5680
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5681 function findSharedMarkers(doc) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5682 return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5683 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5684
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5685 function copySharedMarkers(doc, markers) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5686 for (var i = 0; i < markers.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5687 var marker = markers[i], pos = marker.find()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5688 var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5689 if (cmp(mFrom, mTo)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5690 var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5691 marker.markers.push(subMark)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5692 subMark.parent = marker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5693 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5694 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5695 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5696
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5697 function detachSharedMarkers(markers) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5698 var loop = function ( i ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5699 var marker = markers[i], linked = [marker.primary.doc]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5700 linkedDocs(marker.primary.doc, function (d) { return linked.push(d); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5701 for (var j = 0; j < marker.markers.length; j++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5702 var subMarker = marker.markers[j]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5703 if (indexOf(linked, subMarker.doc) == -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5704 subMarker.parent = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5705 marker.markers.splice(j--, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5706 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5707 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5708 };
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5709
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5710 for (var i = 0; i < markers.length; i++) loop( i );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5711 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5712
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5713 var nextDocId = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5714 var Doc = function(text, mode, firstLine, lineSep) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5715 if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5716 if (firstLine == null) { firstLine = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5717
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5718 BranchChunk.call(this, [new LeafChunk([new Line("", null)])])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5719 this.first = firstLine
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5720 this.scrollTop = this.scrollLeft = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5721 this.cantEdit = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5722 this.cleanGeneration = 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5723 this.frontier = firstLine
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5724 var start = Pos(firstLine, 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5725 this.sel = simpleSelection(start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5726 this.history = new History(null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5727 this.id = ++nextDocId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5728 this.modeOption = mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5729 this.lineSep = lineSep
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5730 this.extend = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5731
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5732 if (typeof text == "string") { text = this.splitLines(text) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5733 updateDoc(this, {from: start, to: start, text: text})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5734 setSelection(this, simpleSelection(start), sel_dontScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5735 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5736
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5737 Doc.prototype = createObj(BranchChunk.prototype, {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5738 constructor: Doc,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5739 // Iterate over the document. Supports two forms -- with only one
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5740 // argument, it calls that for each line in the document. With
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5741 // three, it iterates over the range given by the first two (with
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5742 // the second being non-inclusive).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5743 iter: function(from, to, op) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5744 if (op) { this.iterN(from - this.first, to - from, op) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5745 else { this.iterN(this.first, this.first + this.size, from) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5746 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5747
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5748 // Non-public interface for adding and removing lines.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5749 insert: function(at, lines) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5750 var height = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5751 for (var i = 0; i < lines.length; ++i) { height += lines[i].height }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5752 this.insertInner(at - this.first, lines, height)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5753 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5754 remove: function(at, n) { this.removeInner(at - this.first, n) },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5755
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5756 // From here, the methods are part of the public interface. Most
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5757 // are also available from CodeMirror (editor) instances.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5758
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5759 getValue: function(lineSep) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5760 var lines = getLines(this, this.first, this.first + this.size)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5761 if (lineSep === false) { return lines }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5762 return lines.join(lineSep || this.lineSeparator())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5763 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5764 setValue: docMethodOp(function(code) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5765 var top = Pos(this.first, 0), last = this.first + this.size - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5766 makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5767 text: this.splitLines(code), origin: "setValue", full: true}, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5768 setSelection(this, simpleSelection(top))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5769 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5770 replaceRange: function(code, from, to, origin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5771 from = clipPos(this, from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5772 to = to ? clipPos(this, to) : from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5773 replaceRange(this, code, from, to, origin)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5774 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5775 getRange: function(from, to, lineSep) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5776 var lines = getBetween(this, clipPos(this, from), clipPos(this, to))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5777 if (lineSep === false) { return lines }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5778 return lines.join(lineSep || this.lineSeparator())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5779 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5780
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5781 getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5782
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5783 getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5784 getLineNumber: function(line) {return lineNo(line)},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5785
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5786 getLineHandleVisualStart: function(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5787 if (typeof line == "number") { line = getLine(this, line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5788 return visualLine(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5789 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5790
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5791 lineCount: function() {return this.size},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5792 firstLine: function() {return this.first},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5793 lastLine: function() {return this.first + this.size - 1},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5794
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5795 clipPos: function(pos) {return clipPos(this, pos)},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5796
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5797 getCursor: function(start) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5798 var range$$1 = this.sel.primary(), pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5799 if (start == null || start == "head") { pos = range$$1.head }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5800 else if (start == "anchor") { pos = range$$1.anchor }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5801 else if (start == "end" || start == "to" || start === false) { pos = range$$1.to() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5802 else { pos = range$$1.from() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5803 return pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5804 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5805 listSelections: function() { return this.sel.ranges },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5806 somethingSelected: function() {return this.sel.somethingSelected()},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5807
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5808 setCursor: docMethodOp(function(line, ch, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5809 setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5810 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5811 setSelection: docMethodOp(function(anchor, head, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5812 setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5813 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5814 extendSelection: docMethodOp(function(head, other, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5815 extendSelection(this, clipPos(this, head), other && clipPos(this, other), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5816 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5817 extendSelections: docMethodOp(function(heads, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5818 extendSelections(this, clipPosArray(this, heads), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5819 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5820 extendSelectionsBy: docMethodOp(function(f, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5821 var heads = map(this.sel.ranges, f)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5822 extendSelections(this, clipPosArray(this, heads), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5823 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5824 setSelections: docMethodOp(function(ranges, primary, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5825 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5826
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5827 if (!ranges.length) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5828 var out = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5829 for (var i = 0; i < ranges.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5830 { out[i] = new Range(clipPos(this$1, ranges[i].anchor),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5831 clipPos(this$1, ranges[i].head)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5832 if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5833 setSelection(this, normalizeSelection(out, primary), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5834 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5835 addSelection: docMethodOp(function(anchor, head, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5836 var ranges = this.sel.ranges.slice(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5837 ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5838 setSelection(this, normalizeSelection(ranges, ranges.length - 1), options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5839 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5840
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5841 getSelection: function(lineSep) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5842 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5843
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5844 var ranges = this.sel.ranges, lines
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5845 for (var i = 0; i < ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5846 var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5847 lines = lines ? lines.concat(sel) : sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5848 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5849 if (lineSep === false) { return lines }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5850 else { return lines.join(lineSep || this.lineSeparator()) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5851 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5852 getSelections: function(lineSep) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5853 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5854
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5855 var parts = [], ranges = this.sel.ranges
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5856 for (var i = 0; i < ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5857 var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5858 if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5859 parts[i] = sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5860 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5861 return parts
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5862 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5863 replaceSelection: function(code, collapse, origin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5864 var dup = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5865 for (var i = 0; i < this.sel.ranges.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5866 { dup[i] = code }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5867 this.replaceSelections(dup, collapse, origin || "+input")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5868 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5869 replaceSelections: docMethodOp(function(code, collapse, origin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5870 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5871
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5872 var changes = [], sel = this.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5873 for (var i = 0; i < sel.ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5874 var range$$1 = sel.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5875 changes[i] = {from: range$$1.from(), to: range$$1.to(), text: this$1.splitLines(code[i]), origin: origin}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5876 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5877 var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5878 for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5879 { makeChange(this$1, changes[i$1]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5880 if (newSel) { setSelectionReplaceHistory(this, newSel) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5881 else if (this.cm) { ensureCursorVisible(this.cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5882 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5883 undo: docMethodOp(function() {makeChangeFromHistory(this, "undo")}),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5884 redo: docMethodOp(function() {makeChangeFromHistory(this, "redo")}),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5885 undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true)}),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5886 redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true)}),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5887
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5888 setExtending: function(val) {this.extend = val},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5889 getExtending: function() {return this.extend},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5890
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5891 historySize: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5892 var hist = this.history, done = 0, undone = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5893 for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5894 for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5895 return {undo: done, redo: undone}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5896 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5897 clearHistory: function() {this.history = new History(this.history.maxGeneration)},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5898
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5899 markClean: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5900 this.cleanGeneration = this.changeGeneration(true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5901 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5902 changeGeneration: function(forceSplit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5903 if (forceSplit)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5904 { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5905 return this.history.generation
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5906 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5907 isClean: function (gen) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5908 return this.history.generation == (gen || this.cleanGeneration)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5909 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5910
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5911 getHistory: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5912 return {done: copyHistoryArray(this.history.done),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5913 undone: copyHistoryArray(this.history.undone)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5914 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5915 setHistory: function(histData) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5916 var hist = this.history = new History(this.history.maxGeneration)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5917 hist.done = copyHistoryArray(histData.done.slice(0), null, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5918 hist.undone = copyHistoryArray(histData.undone.slice(0), null, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5919 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5920
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5921 setGutterMarker: docMethodOp(function(line, gutterID, value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5922 return changeLine(this, line, "gutter", function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5923 var markers = line.gutterMarkers || (line.gutterMarkers = {})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5924 markers[gutterID] = value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5925 if (!value && isEmpty(markers)) { line.gutterMarkers = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5926 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5927 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5928 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5929
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5930 clearGutter: docMethodOp(function(gutterID) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5931 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5932
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5933 var i = this.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5934 this.iter(function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5935 if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5936 changeLine(this$1, line, "gutter", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5937 line.gutterMarkers[gutterID] = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5938 if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5939 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5940 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5941 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5942 ++i
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5943 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5944 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5945
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5946 lineInfo: function(line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5947 var n
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5948 if (typeof line == "number") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5949 if (!isLine(this, line)) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5950 n = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5951 line = getLine(this, line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5952 if (!line) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5953 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5954 n = lineNo(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5955 if (n == null) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5956 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5957 return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5958 textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5959 widgets: line.widgets}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5960 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5961
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5962 addLineClass: docMethodOp(function(handle, where, cls) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5963 return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5964 var prop = where == "text" ? "textClass"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5965 : where == "background" ? "bgClass"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5966 : where == "gutter" ? "gutterClass" : "wrapClass"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5967 if (!line[prop]) { line[prop] = cls }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5968 else if (classTest(cls).test(line[prop])) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5969 else { line[prop] += " " + cls }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5970 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5971 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5972 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5973 removeLineClass: docMethodOp(function(handle, where, cls) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5974 return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5975 var prop = where == "text" ? "textClass"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5976 : where == "background" ? "bgClass"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5977 : where == "gutter" ? "gutterClass" : "wrapClass"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5978 var cur = line[prop]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5979 if (!cur) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5980 else if (cls == null) { line[prop] = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5981 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5982 var found = cur.match(classTest(cls))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5983 if (!found) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5984 var end = found.index + found[0].length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5985 line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5986 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5987 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5988 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5989 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5990
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5991 addLineWidget: docMethodOp(function(handle, node, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5992 return addLineWidget(this, handle, node, options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5993 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5994 removeLineWidget: function(widget) { widget.clear() },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5995
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5996 markText: function(from, to, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5997 return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5998 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5999 setBookmark: function(pos, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6000 var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6001 insertLeft: options && options.insertLeft,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6002 clearWhenEmpty: false, shared: options && options.shared,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6003 handleMouseEvents: options && options.handleMouseEvents}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6004 pos = clipPos(this, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6005 return markText(this, pos, pos, realOpts, "bookmark")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6006 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6007 findMarksAt: function(pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6008 pos = clipPos(this, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6009 var markers = [], spans = getLine(this, pos.line).markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6010 if (spans) { for (var i = 0; i < spans.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6011 var span = spans[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6012 if ((span.from == null || span.from <= pos.ch) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6013 (span.to == null || span.to >= pos.ch))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6014 { markers.push(span.marker.parent || span.marker) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6015 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6016 return markers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6017 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6018 findMarks: function(from, to, filter) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6019 from = clipPos(this, from); to = clipPos(this, to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6020 var found = [], lineNo$$1 = from.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6021 this.iter(from.line, to.line + 1, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6022 var spans = line.markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6023 if (spans) { for (var i = 0; i < spans.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6024 var span = spans[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6025 if (!(span.to != null && lineNo$$1 == from.line && from.ch >= span.to ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6026 span.from == null && lineNo$$1 != from.line ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6027 span.from != null && lineNo$$1 == to.line && span.from >= to.ch) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6028 (!filter || filter(span.marker)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6029 { found.push(span.marker.parent || span.marker) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6030 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6031 ++lineNo$$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6032 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6033 return found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6034 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6035 getAllMarks: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6036 var markers = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6037 this.iter(function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6038 var sps = line.markedSpans
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6039 if (sps) { for (var i = 0; i < sps.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6040 { if (sps[i].from != null) { markers.push(sps[i].marker) } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6041 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6042 return markers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6043 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6044
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6045 posFromIndex: function(off) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6046 var ch, lineNo$$1 = this.first, sepSize = this.lineSeparator().length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6047 this.iter(function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6048 var sz = line.text.length + sepSize
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6049 if (sz > off) { ch = off; return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6050 off -= sz
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6051 ++lineNo$$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6052 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6053 return clipPos(this, Pos(lineNo$$1, ch))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6054 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6055 indexFromPos: function (coords) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6056 coords = clipPos(this, coords)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6057 var index = coords.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6058 if (coords.line < this.first || coords.ch < 0) { return 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6059 var sepSize = this.lineSeparator().length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6060 this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6061 index += line.text.length + sepSize
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6062 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6063 return index
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6064 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6065
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6066 copy: function(copyHistory) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6067 var doc = new Doc(getLines(this, this.first, this.first + this.size),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6068 this.modeOption, this.first, this.lineSep)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6069 doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6070 doc.sel = this.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6071 doc.extend = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6072 if (copyHistory) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6073 doc.history.undoDepth = this.history.undoDepth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6074 doc.setHistory(this.getHistory())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6075 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6076 return doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6077 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6078
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6079 linkedDoc: function(options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6080 if (!options) { options = {} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6081 var from = this.first, to = this.first + this.size
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6082 if (options.from != null && options.from > from) { from = options.from }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6083 if (options.to != null && options.to < to) { to = options.to }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6084 var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6085 if (options.sharedHist) { copy.history = this.history
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6086 ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6087 copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6088 copySharedMarkers(copy, findSharedMarkers(this))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6089 return copy
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6090 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6091 unlinkDoc: function(other) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6092 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6093
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6094 if (other instanceof CodeMirror$1) { other = other.doc }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6095 if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6096 var link = this$1.linked[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6097 if (link.doc != other) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6098 this$1.linked.splice(i, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6099 other.unlinkDoc(this$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6100 detachSharedMarkers(findSharedMarkers(this$1))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6101 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6102 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6103 // If the histories were shared, split them again
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6104 if (other.history == this.history) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6105 var splitIds = [other.id]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6106 linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6107 other.history = new History(null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6108 other.history.done = copyHistoryArray(this.history.done, splitIds)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6109 other.history.undone = copyHistoryArray(this.history.undone, splitIds)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6110 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6111 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6112 iterLinkedDocs: function(f) {linkedDocs(this, f)},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6113
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6114 getMode: function() {return this.mode},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6115 getEditor: function() {return this.cm},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6116
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6117 splitLines: function(str) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6118 if (this.lineSep) { return str.split(this.lineSep) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6119 return splitLinesAuto(str)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6120 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6121 lineSeparator: function() { return this.lineSep || "\n" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6122 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6123
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6124 // Public alias.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6125 Doc.prototype.eachLine = Doc.prototype.iter
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6126
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6127 // Kludge to work around strange IE behavior where it'll sometimes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6128 // re-fire a series of drag-related events right after the drop (#1551)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6129 var lastDrop = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6130
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6131 function onDrop(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6132 var cm = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6133 clearDragCursor(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6134 if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6135 { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6136 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6137 if (ie) { lastDrop = +new Date }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6138 var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6139 if (!pos || cm.isReadOnly()) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6140 // Might be a file drop, in which case we simply extract the text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6141 // and insert it.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6142 if (files && files.length && window.FileReader && window.File) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6143 var n = files.length, text = Array(n), read = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6144 var loadFile = function (file, i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6145 if (cm.options.allowDropFileTypes &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6146 indexOf(cm.options.allowDropFileTypes, file.type) == -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6147 { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6148
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6149 var reader = new FileReader
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6150 reader.onload = operation(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6151 var content = reader.result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6152 if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = "" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6153 text[i] = content
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6154 if (++read == n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6155 pos = clipPos(cm.doc, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6156 var change = {from: pos, to: pos,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6157 text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6158 origin: "paste"}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6159 makeChange(cm.doc, change)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6160 setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6161 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6162 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6163 reader.readAsText(file)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6164 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6165 for (var i = 0; i < n; ++i) { loadFile(files[i], i) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6166 } else { // Normal drop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6167 // Don't do a replace if the drop happened inside of the selected text.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6168 if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6169 cm.state.draggingText(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6170 // Ensure the editor is re-focused
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6171 setTimeout(function () { return cm.display.input.focus(); }, 20)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6172 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6173 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6174 try {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6175 var text$1 = e.dataTransfer.getData("Text")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6176 if (text$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6177 var selected
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6178 if (cm.state.draggingText && !cm.state.draggingText.copy)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6179 { selected = cm.listSelections() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6180 setSelectionNoUndo(cm.doc, simpleSelection(pos, pos))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6181 if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6182 { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag") } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6183 cm.replaceSelection(text$1, "around", "paste")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6184 cm.display.input.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6185 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6186 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6187 catch(e){}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6188 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6189 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6190
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6191 function onDragStart(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6192 if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6193 if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6194
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6195 e.dataTransfer.setData("Text", cm.getSelection())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6196 e.dataTransfer.effectAllowed = "copyMove"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6197
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6198 // Use dummy image instead of default browsers image.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6199 // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6200 if (e.dataTransfer.setDragImage && !safari) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6201 var img = elt("img", null, null, "position: fixed; left: 0; top: 0;")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6202 img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6203 if (presto) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6204 img.width = img.height = 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6205 cm.display.wrapper.appendChild(img)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6206 // Force a relayout, or Opera won't use our image for some obscure reason
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6207 img._top = img.offsetTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6208 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6209 e.dataTransfer.setDragImage(img, 0, 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6210 if (presto) { img.parentNode.removeChild(img) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6211 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6212 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6213
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6214 function onDragOver(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6215 var pos = posFromMouse(cm, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6216 if (!pos) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6217 var frag = document.createDocumentFragment()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6218 drawSelectionCursor(cm, pos, frag)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6219 if (!cm.display.dragCursor) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6220 cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6221 cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6222 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6223 removeChildrenAndAdd(cm.display.dragCursor, frag)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6224 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6225
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6226 function clearDragCursor(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6227 if (cm.display.dragCursor) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6228 cm.display.lineSpace.removeChild(cm.display.dragCursor)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6229 cm.display.dragCursor = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6230 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6231 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6232
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6233 // These must be handled carefully, because naively registering a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6234 // handler for each editor will cause the editors to never be
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6235 // garbage collected.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6236
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6237 function forEachCodeMirror(f) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6238 if (!document.body.getElementsByClassName) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6239 var byClass = document.body.getElementsByClassName("CodeMirror")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6240 for (var i = 0; i < byClass.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6241 var cm = byClass[i].CodeMirror
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6242 if (cm) { f(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6243 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6244 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6245
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6246 var globalsRegistered = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6247 function ensureGlobalHandlers() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6248 if (globalsRegistered) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6249 registerGlobalHandlers()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6250 globalsRegistered = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6251 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6252 function registerGlobalHandlers() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6253 // When the window resizes, we need to refresh active editors.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6254 var resizeTimer
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6255 on(window, "resize", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6256 if (resizeTimer == null) { resizeTimer = setTimeout(function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6257 resizeTimer = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6258 forEachCodeMirror(onResize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6259 }, 100) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6260 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6261 // When the window loses focus, we want to show the editor as blurred
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6262 on(window, "blur", function () { return forEachCodeMirror(onBlur); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6263 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6264 // Called when the window resizes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6265 function onResize(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6266 var d = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6267 if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6268 { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6269 // Might be a text scaling operation, clear size caches.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6270 d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6271 d.scrollbarsClipped = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6272 cm.setSize()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6273 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6274
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6275 var keyNames = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6276 3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6277 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6278 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6279 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6280 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6281 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6282 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6283 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6284 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6285
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6286 // Number keys
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6287 for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6288 // Alphabetic keys
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6289 for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6290 // Function keys
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6291 for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6292
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6293 var keyMap = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6294
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6295 keyMap.basic = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6296 "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6297 "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6298 "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6299 "Tab": "defaultTab", "Shift-Tab": "indentAuto",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6300 "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6301 "Esc": "singleSelection"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6302 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6303 // Note that the save and find-related commands aren't defined by
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6304 // default. User code or addons can define them. Unknown commands
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6305 // are simply ignored.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6306 keyMap.pcDefault = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6307 "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6308 "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6309 "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6310 "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6311 "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6312 "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6313 "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6314 fallthrough: "basic"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6315 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6316 // Very basic readline/emacs-style bindings, which are standard on Mac.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6317 keyMap.emacsy = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6318 "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6319 "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6320 "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6321 "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6322 "Ctrl-O": "openLine"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6323 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6324 keyMap.macDefault = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6325 "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6326 "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6327 "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6328 "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6329 "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6330 "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6331 "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6332 fallthrough: ["basic", "emacsy"]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6333 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6334 keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6335
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6336 // KEYMAP DISPATCH
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6337
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6338 function normalizeKeyName(name) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6339 var parts = name.split(/-(?!$)/)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6340 name = parts[parts.length - 1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6341 var alt, ctrl, shift, cmd
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6342 for (var i = 0; i < parts.length - 1; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6343 var mod = parts[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6344 if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6345 else if (/^a(lt)?$/i.test(mod)) { alt = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6346 else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6347 else if (/^s(hift)?$/i.test(mod)) { shift = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6348 else { throw new Error("Unrecognized modifier name: " + mod) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6349 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6350 if (alt) { name = "Alt-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6351 if (ctrl) { name = "Ctrl-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6352 if (cmd) { name = "Cmd-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6353 if (shift) { name = "Shift-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6354 return name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6355 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6356
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6357 // This is a kludge to keep keymaps mostly working as raw objects
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6358 // (backwards compatibility) while at the same time support features
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6359 // like normalization and multi-stroke key bindings. It compiles a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6360 // new normalized keymap, and then updates the old object to reflect
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6361 // this.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6362 function normalizeKeyMap(keymap) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6363 var copy = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6364 for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6365 var value = keymap[keyname]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6366 if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6367 if (value == "...") { delete keymap[keyname]; continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6368
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6369 var keys = map(keyname.split(" "), normalizeKeyName)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6370 for (var i = 0; i < keys.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6371 var val = void 0, name = void 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6372 if (i == keys.length - 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6373 name = keys.join(" ")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6374 val = value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6375 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6376 name = keys.slice(0, i + 1).join(" ")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6377 val = "..."
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6378 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6379 var prev = copy[name]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6380 if (!prev) { copy[name] = val }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6381 else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6382 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6383 delete keymap[keyname]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6384 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6385 for (var prop in copy) { keymap[prop] = copy[prop] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6386 return keymap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6387 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6388
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6389 function lookupKey(key, map$$1, handle, context) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6390 map$$1 = getKeyMap(map$$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6391 var found = map$$1.call ? map$$1.call(key, context) : map$$1[key]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6392 if (found === false) { return "nothing" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6393 if (found === "...") { return "multi" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6394 if (found != null && handle(found)) { return "handled" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6395
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6396 if (map$$1.fallthrough) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6397 if (Object.prototype.toString.call(map$$1.fallthrough) != "[object Array]")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6398 { return lookupKey(key, map$$1.fallthrough, handle, context) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6399 for (var i = 0; i < map$$1.fallthrough.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6400 var result = lookupKey(key, map$$1.fallthrough[i], handle, context)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6401 if (result) { return result }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6402 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6403 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6404 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6405
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6406 // Modifier key presses don't count as 'real' key presses for the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6407 // purpose of keymap fallthrough.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6408 function isModifierKey(value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6409 var name = typeof value == "string" ? value : keyNames[value.keyCode]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6410 return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6411 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6412
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6413 // Look up the name of a key as indicated by an event object.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6414 function keyName(event, noShift) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6415 if (presto && event.keyCode == 34 && event["char"]) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6416 var base = keyNames[event.keyCode], name = base
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6417 if (name == null || event.altGraphKey) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6418 if (event.altKey && base != "Alt") { name = "Alt-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6419 if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6420 if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6421 if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6422 return name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6423 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6424
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6425 function getKeyMap(val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6426 return typeof val == "string" ? keyMap[val] : val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6427 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6428
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6429 // Helper for deleting text near the selection(s), used to implement
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6430 // backspace, delete, and similar functionality.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6431 function deleteNearSelection(cm, compute) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6432 var ranges = cm.doc.sel.ranges, kill = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6433 // Build up a set of ranges to kill first, merging overlapping
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6434 // ranges.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6435 for (var i = 0; i < ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6436 var toKill = compute(ranges[i])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6437 while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6438 var replaced = kill.pop()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6439 if (cmp(replaced.from, toKill.from) < 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6440 toKill.from = replaced.from
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6441 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6442 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6443 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6444 kill.push(toKill)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6445 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6446 // Next, remove those actual ranges.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6447 runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6448 for (var i = kill.length - 1; i >= 0; i--)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6449 { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6450 ensureCursorVisible(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6451 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6452 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6453
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6454 // Commands are parameter-less actions that can be performed on an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6455 // editor, mostly used for keybindings.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6456 var commands = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6457 selectAll: selectAll,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6458 singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6459 killLine: function (cm) { return deleteNearSelection(cm, function (range) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6460 if (range.empty()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6461 var len = getLine(cm.doc, range.head.line).text.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6462 if (range.head.ch == len && range.head.line < cm.lastLine())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6463 { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6464 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6465 { return {from: range.head, to: Pos(range.head.line, len)} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6466 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6467 return {from: range.from(), to: range.to()}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6468 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6469 }); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6470 deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6471 from: Pos(range.from().line, 0),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6472 to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6473 }); }); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6474 delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6475 from: Pos(range.from().line, 0), to: range.from()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6476 }); }); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6477 delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6478 var top = cm.charCoords(range.head, "div").top + 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6479 var leftPos = cm.coordsChar({left: 0, top: top}, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6480 return {from: leftPos, to: range.from()}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6481 }); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6482 delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6483 var top = cm.charCoords(range.head, "div").top + 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6484 var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6485 return {from: range.from(), to: rightPos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6486 }); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6487 undo: function (cm) { return cm.undo(); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6488 redo: function (cm) { return cm.redo(); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6489 undoSelection: function (cm) { return cm.undoSelection(); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6490 redoSelection: function (cm) { return cm.redoSelection(); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6491 goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6492 goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6493 goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6494 {origin: "+move", bias: 1}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6495 ); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6496 goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6497 {origin: "+move", bias: 1}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6498 ); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6499 goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6500 {origin: "+move", bias: -1}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6501 ); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6502 goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6503 var top = cm.charCoords(range.head, "div").top + 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6504 return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6505 }, sel_move); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6506 goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6507 var top = cm.charCoords(range.head, "div").top + 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6508 return cm.coordsChar({left: 0, top: top}, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6509 }, sel_move); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6510 goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6511 var top = cm.charCoords(range.head, "div").top + 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6512 var pos = cm.coordsChar({left: 0, top: top}, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6513 if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6514 return pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6515 }, sel_move); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6516 goLineUp: function (cm) { return cm.moveV(-1, "line"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6517 goLineDown: function (cm) { return cm.moveV(1, "line"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6518 goPageUp: function (cm) { return cm.moveV(-1, "page"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6519 goPageDown: function (cm) { return cm.moveV(1, "page"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6520 goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6521 goCharRight: function (cm) { return cm.moveH(1, "char"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6522 goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6523 goColumnRight: function (cm) { return cm.moveH(1, "column"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6524 goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6525 goGroupRight: function (cm) { return cm.moveH(1, "group"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6526 goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6527 goWordRight: function (cm) { return cm.moveH(1, "word"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6528 delCharBefore: function (cm) { return cm.deleteH(-1, "char"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6529 delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6530 delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6531 delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6532 delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6533 delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6534 indentAuto: function (cm) { return cm.indentSelection("smart"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6535 indentMore: function (cm) { return cm.indentSelection("add"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6536 indentLess: function (cm) { return cm.indentSelection("subtract"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6537 insertTab: function (cm) { return cm.replaceSelection("\t"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6538 insertSoftTab: function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6539 var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6540 for (var i = 0; i < ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6541 var pos = ranges[i].from()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6542 var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6543 spaces.push(spaceStr(tabSize - col % tabSize))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6544 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6545 cm.replaceSelections(spaces)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6546 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6547 defaultTab: function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6548 if (cm.somethingSelected()) { cm.indentSelection("add") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6549 else { cm.execCommand("insertTab") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6550 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6551 // Swap the two chars left and right of each selection's head.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6552 // Move cursor behind the two swapped characters afterwards.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6553 //
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6554 // Doesn't consider line feeds a character.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6555 // Doesn't scan more than one line above to find a character.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6556 // Doesn't do anything on an empty line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6557 // Doesn't do anything with non-empty selections.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6558 transposeChars: function (cm) { return runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6559 var ranges = cm.listSelections(), newSel = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6560 for (var i = 0; i < ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6561 if (!ranges[i].empty()) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6562 var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6563 if (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6564 if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6565 if (cur.ch > 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6566 cur = new Pos(cur.line, cur.ch + 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6567 cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6568 Pos(cur.line, cur.ch - 2), cur, "+transpose")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6569 } else if (cur.line > cm.doc.first) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6570 var prev = getLine(cm.doc, cur.line - 1).text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6571 if (prev) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6572 cur = new Pos(cur.line, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6573 cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6574 prev.charAt(prev.length - 1),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6575 Pos(cur.line - 1, prev.length - 1), cur, "+transpose")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6576 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6577 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6578 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6579 newSel.push(new Range(cur, cur))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6580 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6581 cm.setSelections(newSel)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6582 }); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6583 newlineAndIndent: function (cm) { return runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6584 var sels = cm.listSelections()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6585 for (var i = sels.length - 1; i >= 0; i--)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6586 { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6587 sels = cm.listSelections()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6588 for (var i$1 = 0; i$1 < sels.length; i$1++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6589 { cm.indentLine(sels[i$1].from().line, null, true) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6590 ensureCursorVisible(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6591 }); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6592 openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6593 toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6594 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6595
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6596
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6597 function lineStart(cm, lineN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6598 var line = getLine(cm.doc, lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6599 var visual = visualLine(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6600 if (visual != line) { lineN = lineNo(visual) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6601 var order = getOrder(visual)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6602 var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6603 return Pos(lineN, ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6604 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6605 function lineEnd(cm, lineN) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6606 var merged, line = getLine(cm.doc, lineN)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6607 while (merged = collapsedSpanAtEnd(line)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6608 line = merged.find(1, true).line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6609 lineN = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6610 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6611 var order = getOrder(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6612 var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6613 return Pos(lineN == null ? lineNo(line) : lineN, ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6614 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6615 function lineStartSmart(cm, pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6616 var start = lineStart(cm, pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6617 var line = getLine(cm.doc, start.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6618 var order = getOrder(line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6619 if (!order || order[0].level == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6620 var firstNonWS = Math.max(0, line.text.search(/\S/))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6621 var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6622 return Pos(start.line, inWS ? 0 : firstNonWS)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6623 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6624 return start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6625 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6626
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6627 // Run a handler that was bound to a key.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6628 function doHandleBinding(cm, bound, dropShift) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6629 if (typeof bound == "string") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6630 bound = commands[bound]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6631 if (!bound) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6632 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6633 // Ensure previous input has been read, so that the handler sees a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6634 // consistent view of the document
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6635 cm.display.input.ensurePolled()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6636 var prevShift = cm.display.shift, done = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6637 try {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6638 if (cm.isReadOnly()) { cm.state.suppressEdits = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6639 if (dropShift) { cm.display.shift = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6640 done = bound(cm) != Pass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6641 } finally {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6642 cm.display.shift = prevShift
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6643 cm.state.suppressEdits = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6644 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6645 return done
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6646 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6647
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6648 function lookupKeyForEditor(cm, name, handle) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6649 for (var i = 0; i < cm.state.keyMaps.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6650 var result = lookupKey(name, cm.state.keyMaps[i], handle, cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6651 if (result) { return result }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6652 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6653 return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6654 || lookupKey(name, cm.options.keyMap, handle, cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6655 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6656
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6657 var stopSeq = new Delayed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6658 function dispatchKey(cm, name, e, handle) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6659 var seq = cm.state.keySeq
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6660 if (seq) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6661 if (isModifierKey(name)) { return "handled" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6662 stopSeq.set(50, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6663 if (cm.state.keySeq == seq) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6664 cm.state.keySeq = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6665 cm.display.input.reset()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6666 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6667 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6668 name = seq + " " + name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6669 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6670 var result = lookupKeyForEditor(cm, name, handle)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6671
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6672 if (result == "multi")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6673 { cm.state.keySeq = name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6674 if (result == "handled")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6675 { signalLater(cm, "keyHandled", cm, name, e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6676
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6677 if (result == "handled" || result == "multi") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6678 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6679 restartBlink(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6680 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6681
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6682 if (seq && !result && /\'$/.test(name)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6683 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6684 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6685 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6686 return !!result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6687 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6688
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6689 // Handle a key from the keydown event.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6690 function handleKeyBinding(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6691 var name = keyName(e, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6692 if (!name) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6693
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6694 if (e.shiftKey && !cm.state.keySeq) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6695 // First try to resolve full name (including 'Shift-'). Failing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6696 // that, see if there is a cursor-motion command (starting with
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6697 // 'go') bound to the keyname without 'Shift-'.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6698 return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6699 || dispatchKey(cm, name, e, function (b) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6700 if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6701 { return doHandleBinding(cm, b) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6702 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6703 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6704 return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6705 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6706 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6707
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6708 // Handle a key from the keypress event
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6709 function handleCharBinding(cm, e, ch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6710 return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6711 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6712
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6713 var lastStoppedKey = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6714 function onKeyDown(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6715 var cm = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6716 cm.curOp.focus = activeElt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6717 if (signalDOMEvent(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6718 // IE does strange things with escape.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6719 if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6720 var code = e.keyCode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6721 cm.display.shift = code == 16 || e.shiftKey
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6722 var handled = handleKeyBinding(cm, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6723 if (presto) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6724 lastStoppedKey = handled ? code : null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6725 // Opera has no cut event... we try to at least catch the key combo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6726 if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6727 { cm.replaceSelection("", null, "cut") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6728 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6729
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6730 // Turn mouse into crosshair when Alt is held on Mac.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6731 if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6732 { showCrossHair(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6733 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6734
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6735 function showCrossHair(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6736 var lineDiv = cm.display.lineDiv
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6737 addClass(lineDiv, "CodeMirror-crosshair")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6738
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6739 function up(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6740 if (e.keyCode == 18 || !e.altKey) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6741 rmClass(lineDiv, "CodeMirror-crosshair")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6742 off(document, "keyup", up)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6743 off(document, "mouseover", up)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6744 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6745 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6746 on(document, "keyup", up)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6747 on(document, "mouseover", up)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6748 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6749
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6750 function onKeyUp(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6751 if (e.keyCode == 16) { this.doc.sel.shift = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6752 signalDOMEvent(this, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6753 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6754
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6755 function onKeyPress(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6756 var cm = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6757 if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6758 var keyCode = e.keyCode, charCode = e.charCode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6759 if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6760 if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6761 var ch = String.fromCharCode(charCode == null ? keyCode : charCode)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6762 // Some browsers fire keypress events for backspace
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6763 if (ch == "\x08") { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6764 if (handleCharBinding(cm, e, ch)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6765 cm.display.input.onKeyPress(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6766 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6767
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6768 // A mouse down can be a single click, double click, triple click,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6769 // start of selection drag, start of text drag, new cursor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6770 // (ctrl-click), rectangle drag (alt-drag), or xwin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6771 // middle-click-paste. Or it might be a click on something we should
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6772 // not interfere with, such as a scrollbar or widget.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6773 function onMouseDown(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6774 var cm = this, display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6775 if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6776 display.input.ensurePolled()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6777 display.shift = e.shiftKey
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6778
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6779 if (eventInWidget(display, e)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6780 if (!webkit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6781 // Briefly turn off draggability, to allow widgets to do
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6782 // normal dragging things.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6783 display.scroller.draggable = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6784 setTimeout(function () { return display.scroller.draggable = true; }, 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6785 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6786 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6787 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6788 if (clickInGutter(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6789 var start = posFromMouse(cm, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6790 window.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6791
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6792 switch (e_button(e)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6793 case 1:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6794 // #3261: make sure, that we're not starting a second selection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6795 if (cm.state.selectingText)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6796 { cm.state.selectingText(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6797 else if (start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6798 { leftButtonDown(cm, e, start) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6799 else if (e_target(e) == display.scroller)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6800 { e_preventDefault(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6801 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6802 case 2:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6803 if (webkit) { cm.state.lastMiddleDown = +new Date }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6804 if (start) { extendSelection(cm.doc, start) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6805 setTimeout(function () { return display.input.focus(); }, 20)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6806 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6807 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6808 case 3:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6809 if (captureRightClick) { onContextMenu(cm, e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6810 else { delayBlurEvent(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6811 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6812 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6813 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6814
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6815 var lastClick;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6816 var lastDoubleClick
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6817 function leftButtonDown(cm, e, start) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6818 if (ie) { setTimeout(bind(ensureFocus, cm), 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6819 else { cm.curOp.focus = activeElt() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6820
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6821 var now = +new Date, type
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6822 if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6823 type = "triple"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6824 } else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6825 type = "double"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6826 lastDoubleClick = {time: now, pos: start}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6827 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6828 type = "single"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6829 lastClick = {time: now, pos: start}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6830 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6831
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6832 var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6833 if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6834 type == "single" && (contained = sel.contains(start)) > -1 &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6835 (cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6836 (cmp(contained.to(), start) > 0 || start.xRel < 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6837 { leftButtonStartDrag(cm, e, start, modifier) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6838 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6839 { leftButtonSelect(cm, e, start, type, modifier) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6840 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6841
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6842 // Start a text drag. When it ends, see if any dragging actually
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6843 // happen, and treat as a click if it didn't.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6844 function leftButtonStartDrag(cm, e, start, modifier) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6845 var display = cm.display, startTime = +new Date
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6846 var dragEnd = operation(cm, function (e2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6847 if (webkit) { display.scroller.draggable = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6848 cm.state.draggingText = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6849 off(document, "mouseup", dragEnd)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6850 off(display.scroller, "drop", dragEnd)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6851 if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6852 e_preventDefault(e2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6853 if (!modifier && +new Date - 200 < startTime)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6854 { extendSelection(cm.doc, start) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6855 // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6856 if (webkit || ie && ie_version == 9)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6857 { setTimeout(function () {document.body.focus(); display.input.focus()}, 20) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6858 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6859 { display.input.focus() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6860 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6861 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6862 // Let the drag handler handle this.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6863 if (webkit) { display.scroller.draggable = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6864 cm.state.draggingText = dragEnd
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6865 dragEnd.copy = mac ? e.altKey : e.ctrlKey
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6866 // IE's approach to draggable
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6867 if (display.scroller.dragDrop) { display.scroller.dragDrop() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6868 on(document, "mouseup", dragEnd)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6869 on(display.scroller, "drop", dragEnd)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6870 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6871
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6872 // Normal selection, as opposed to text dragging.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6873 function leftButtonSelect(cm, e, start, type, addNew) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6874 var display = cm.display, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6875 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6876
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6877 var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6878 if (addNew && !e.shiftKey) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6879 ourIndex = doc.sel.contains(start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6880 if (ourIndex > -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6881 { ourRange = ranges[ourIndex] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6882 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6883 { ourRange = new Range(start, start) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6884 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6885 ourRange = doc.sel.primary()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6886 ourIndex = doc.sel.primIndex
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6887 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6888
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6889 if (chromeOS ? e.shiftKey && e.metaKey : e.altKey) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6890 type = "rect"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6891 if (!addNew) { ourRange = new Range(start, start) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6892 start = posFromMouse(cm, e, true, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6893 ourIndex = -1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6894 } else if (type == "double") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6895 var word = cm.findWordAt(start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6896 if (cm.display.shift || doc.extend)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6897 { ourRange = extendRange(doc, ourRange, word.anchor, word.head) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6898 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6899 { ourRange = word }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6900 } else if (type == "triple") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6901 var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6902 if (cm.display.shift || doc.extend)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6903 { ourRange = extendRange(doc, ourRange, line.anchor, line.head) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6904 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6905 { ourRange = line }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6906 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6907 ourRange = extendRange(doc, ourRange, start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6908 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6909
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6910 if (!addNew) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6911 ourIndex = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6912 setSelection(doc, new Selection([ourRange], 0), sel_mouse)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6913 startSel = doc.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6914 } else if (ourIndex == -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6915 ourIndex = ranges.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6916 setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6917 {scroll: false, origin: "*mouse"})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6918 } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6919 setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6920 {scroll: false, origin: "*mouse"})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6921 startSel = doc.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6922 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6923 replaceOneSelection(doc, ourIndex, ourRange, sel_mouse)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6924 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6925
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6926 var lastPos = start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6927 function extendTo(pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6928 if (cmp(lastPos, pos) == 0) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6929 lastPos = pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6930
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6931 if (type == "rect") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6932 var ranges = [], tabSize = cm.options.tabSize
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6933 var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6934 var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6935 var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6936 for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6937 line <= end; line++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6938 var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6939 if (left == right)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6940 { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6941 else if (text.length > leftPos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6942 { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6943 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6944 if (!ranges.length) { ranges.push(new Range(start, start)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6945 setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6946 {origin: "*mouse", scroll: false})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6947 cm.scrollIntoView(pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6948 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6949 var oldRange = ourRange
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6950 var anchor = oldRange.anchor, head = pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6951 if (type != "single") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6952 var range$$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6953 if (type == "double")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6954 { range$$1 = cm.findWordAt(pos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6955 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6956 { range$$1 = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6957 if (cmp(range$$1.anchor, anchor) > 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6958 head = range$$1.head
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6959 anchor = minPos(oldRange.from(), range$$1.anchor)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6960 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6961 head = range$$1.anchor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6962 anchor = maxPos(oldRange.to(), range$$1.head)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6963 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6964 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6965 var ranges$1 = startSel.ranges.slice(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6966 ranges$1[ourIndex] = new Range(clipPos(doc, anchor), head)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6967 setSelection(doc, normalizeSelection(ranges$1, ourIndex), sel_mouse)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6968 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6969 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6970
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6971 var editorSize = display.wrapper.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6972 // Used to ensure timeout re-tries don't fire when another extend
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6973 // happened in the meantime (clearTimeout isn't reliable -- at
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6974 // least on Chrome, the timeouts still happen even when cleared,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6975 // if the clear happens after their scheduled firing time).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6976 var counter = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6977
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6978 function extend(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6979 var curCount = ++counter
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6980 var cur = posFromMouse(cm, e, true, type == "rect")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6981 if (!cur) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6982 if (cmp(cur, lastPos) != 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6983 cm.curOp.focus = activeElt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6984 extendTo(cur)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6985 var visible = visibleLines(display, doc)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6986 if (cur.line >= visible.to || cur.line < visible.from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6987 { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e) }}), 150) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6988 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6989 var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6990 if (outside) { setTimeout(operation(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6991 if (counter != curCount) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6992 display.scroller.scrollTop += outside
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6993 extend(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6994 }), 50) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6995 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6996 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6997
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6998 function done(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6999 cm.state.selectingText = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7000 counter = Infinity
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7001 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7002 display.input.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7003 off(document, "mousemove", move)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7004 off(document, "mouseup", up)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7005 doc.history.lastSelOrigin = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7006 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7007
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7008 var move = operation(cm, function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7009 if (!e_button(e)) { done(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7010 else { extend(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7011 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7012 var up = operation(cm, done)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7013 cm.state.selectingText = up
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7014 on(document, "mousemove", move)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7015 on(document, "mouseup", up)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7016 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7017
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7018
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7019 // Determines whether an event happened in the gutter, and fires the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7020 // handlers for the corresponding event.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7021 function gutterEvent(cm, e, type, prevent) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7022 var mX, mY
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7023 try { mX = e.clientX; mY = e.clientY }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7024 catch(e) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7025 if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7026 if (prevent) { e_preventDefault(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7027
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7028 var display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7029 var lineBox = display.lineDiv.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7030
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7031 if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7032 mY -= lineBox.top - display.viewOffset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7033
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7034 for (var i = 0; i < cm.options.gutters.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7035 var g = display.gutters.childNodes[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7036 if (g && g.getBoundingClientRect().right >= mX) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7037 var line = lineAtHeight(cm.doc, mY)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7038 var gutter = cm.options.gutters[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7039 signal(cm, type, cm, line, gutter, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7040 return e_defaultPrevented(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7041 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7042 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7043 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7044
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7045 function clickInGutter(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7046 return gutterEvent(cm, e, "gutterClick", true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7047 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7048
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7049 // CONTEXT MENU HANDLING
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7050
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7051 // To make the context menu work, we need to briefly unhide the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7052 // textarea (making it as unobtrusive as possible) to let the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7053 // right-click take effect on it.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7054 function onContextMenu(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7055 if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7056 if (signalDOMEvent(cm, e, "contextmenu")) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7057 cm.display.input.onContextMenu(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7058 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7059
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7060 function contextMenuInGutter(cm, e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7061 if (!hasHandler(cm, "gutterContextMenu")) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7062 return gutterEvent(cm, e, "gutterContextMenu", false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7063 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7064
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7065 function themeChanged(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7066 cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7067 cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7068 clearCaches(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7069 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7070
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7071 var Init = {toString: function(){return "CodeMirror.Init"}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7072
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7073 var defaults = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7074 var optionHandlers = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7075
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7076 function defineOptions(CodeMirror) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7077 var optionHandlers = CodeMirror.optionHandlers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7078
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7079 function option(name, deflt, handle, notOnInit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7080 CodeMirror.defaults[name] = deflt
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7081 if (handle) { optionHandlers[name] =
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7082 notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old) }} : handle }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7083 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7084
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7085 CodeMirror.defineOption = option
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7086
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7087 // Passed to option handlers when there is no old value.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7088 CodeMirror.Init = Init
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7089
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7090 // These two are, on init, called from the constructor because they
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7091 // have to be initialized before the editor can start at all.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7092 option("value", "", function (cm, val) { return cm.setValue(val); }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7093 option("mode", null, function (cm, val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7094 cm.doc.modeOption = val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7095 loadMode(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7096 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7097
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7098 option("indentUnit", 2, loadMode, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7099 option("indentWithTabs", false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7100 option("smartIndent", true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7101 option("tabSize", 4, function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7102 resetModeState(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7103 clearCaches(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7104 regChange(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7105 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7106 option("lineSeparator", null, function (cm, val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7107 cm.doc.lineSep = val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7108 if (!val) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7109 var newBreaks = [], lineNo = cm.doc.first
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7110 cm.doc.iter(function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7111 for (var pos = 0;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7112 var found = line.text.indexOf(val, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7113 if (found == -1) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7114 pos = found + val.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7115 newBreaks.push(Pos(lineNo, found))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7116 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7117 lineNo++
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7118 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7119 for (var i = newBreaks.length - 1; i >= 0; i--)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7120 { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7121 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7122 option("specialChars", /[\u0000-\u001f\u007f\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7123 cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7124 if (old != Init) { cm.refresh() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7125 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7126 option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7127 option("electricChars", true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7128 option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7129 throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7130 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7131 option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7132 option("rtlMoveVisually", !windows)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7133 option("wholeLineUpdateBefore", true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7134
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7135 option("theme", "default", function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7136 themeChanged(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7137 guttersChanged(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7138 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7139 option("keyMap", "default", function (cm, val, old) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7140 var next = getKeyMap(val)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7141 var prev = old != Init && getKeyMap(old)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7142 if (prev && prev.detach) { prev.detach(cm, next) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7143 if (next.attach) { next.attach(cm, prev || null) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7144 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7145 option("extraKeys", null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7146
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7147 option("lineWrapping", false, wrappingChanged, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7148 option("gutters", [], function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7149 setGuttersForLineNumbers(cm.options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7150 guttersChanged(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7151 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7152 option("fixedGutter", true, function (cm, val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7153 cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7154 cm.refresh()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7155 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7156 option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7157 option("scrollbarStyle", "native", function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7158 initScrollbars(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7159 updateScrollbars(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7160 cm.display.scrollbars.setScrollTop(cm.doc.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7161 cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7162 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7163 option("lineNumbers", false, function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7164 setGuttersForLineNumbers(cm.options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7165 guttersChanged(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7166 }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7167 option("firstLineNumber", 1, guttersChanged, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7168 option("lineNumberFormatter", function (integer) { return integer; }, guttersChanged, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7169 option("showCursorWhenSelecting", false, updateSelection, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7170
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7171 option("resetSelectionOnContextMenu", true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7172 option("lineWiseCopyCut", true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7173
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7174 option("readOnly", false, function (cm, val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7175 if (val == "nocursor") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7176 onBlur(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7177 cm.display.input.blur()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7178 cm.display.disabled = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7179 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7180 cm.display.disabled = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7181 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7182 cm.display.input.readOnlyChanged(val)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7183 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7184 option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset() }}, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7185 option("dragDrop", true, dragDropChanged)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7186 option("allowDropFileTypes", null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7187
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7188 option("cursorBlinkRate", 530)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7189 option("cursorScrollMargin", 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7190 option("cursorHeight", 1, updateSelection, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7191 option("singleCursorHeightPerLine", true, updateSelection, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7192 option("workTime", 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7193 option("workDelay", 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7194 option("flattenSpans", true, resetModeState, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7195 option("addModeClass", false, resetModeState, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7196 option("pollInterval", 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7197 option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7198 option("historyEventDelay", 1250)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7199 option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7200 option("maxHighlightLength", 10000, resetModeState, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7201 option("moveInputWithCursor", true, function (cm, val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7202 if (!val) { cm.display.input.resetPosition() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7203 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7204
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7205 option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7206 option("autofocus", null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7207 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7208
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7209 function guttersChanged(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7210 updateGutters(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7211 regChange(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7212 setTimeout(function () { return alignHorizontally(cm); }, 20)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7213 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7214
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7215 function dragDropChanged(cm, value, old) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7216 var wasOn = old && old != Init
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7217 if (!value != !wasOn) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7218 var funcs = cm.display.dragFunctions
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7219 var toggle = value ? on : off
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7220 toggle(cm.display.scroller, "dragstart", funcs.start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7221 toggle(cm.display.scroller, "dragenter", funcs.enter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7222 toggle(cm.display.scroller, "dragover", funcs.over)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7223 toggle(cm.display.scroller, "dragleave", funcs.leave)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7224 toggle(cm.display.scroller, "drop", funcs.drop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7225 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7226 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7227
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7228 function wrappingChanged(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7229 if (cm.options.lineWrapping) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7230 addClass(cm.display.wrapper, "CodeMirror-wrap")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7231 cm.display.sizer.style.minWidth = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7232 cm.display.sizerWidth = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7233 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7234 rmClass(cm.display.wrapper, "CodeMirror-wrap")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7235 findMaxLine(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7236 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7237 estimateLineHeights(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7238 regChange(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7239 clearCaches(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7240 setTimeout(function () { return updateScrollbars(cm); }, 100)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7241 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7242
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7243 // A CodeMirror instance represents an editor. This is the object
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7244 // that user code is usually dealing with.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7245
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7246 function CodeMirror$1(place, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7247 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7248
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7249 if (!(this instanceof CodeMirror$1)) { return new CodeMirror$1(place, options) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7250
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7251 this.options = options = options ? copyObj(options) : {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7252 // Determine effective options based on given values and defaults.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7253 copyObj(defaults, options, false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7254 setGuttersForLineNumbers(options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7255
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7256 var doc = options.value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7257 if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7258 this.doc = doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7259
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7260 var input = new CodeMirror$1.inputStyles[options.inputStyle](this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7261 var display = this.display = new Display(place, doc, input)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7262 display.wrapper.CodeMirror = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7263 updateGutters(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7264 themeChanged(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7265 if (options.lineWrapping)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7266 { this.display.wrapper.className += " CodeMirror-wrap" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7267 if (options.autofocus && !mobile) { display.input.focus() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7268 initScrollbars(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7269
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7270 this.state = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7271 keyMaps: [], // stores maps added by addKeyMap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7272 overlays: [], // highlighting overlays, as added by addOverlay
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7273 modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7274 overwrite: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7275 delayingBlurEvent: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7276 focused: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7277 suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7278 pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7279 selectingText: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7280 draggingText: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7281 highlight: new Delayed(), // stores highlight worker timeout
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7282 keySeq: null, // Unfinished key sequence
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7283 specialChars: null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7284 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7285
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7286 // Override magic textarea content restore that IE sometimes does
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7287 // on our hidden textarea on reload
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7288 if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7289
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7290 registerEventHandlers(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7291 ensureGlobalHandlers()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7292
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7293 startOperation(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7294 this.curOp.forceUpdate = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7295 attachDoc(this, doc)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7296
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7297 if ((options.autofocus && !mobile) || this.hasFocus())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7298 { setTimeout(bind(onFocus, this), 20) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7299 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7300 { onBlur(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7301
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7302 for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7303 { optionHandlers[opt](this$1, options[opt], Init) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7304 maybeUpdateLineNumberWidth(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7305 if (options.finishInit) { options.finishInit(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7306 for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7307 endOperation(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7308 // Suppress optimizelegibility in Webkit, since it breaks text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7309 // measuring on line wrapping boundaries.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7310 if (webkit && options.lineWrapping &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7311 getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7312 { display.lineDiv.style.textRendering = "auto" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7313 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7314
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7315 // The default configuration options.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7316 CodeMirror$1.defaults = defaults
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7317 // Functions to run when options are changed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7318 CodeMirror$1.optionHandlers = optionHandlers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7319
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7320 // Attach the necessary event handlers when initializing the editor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7321 function registerEventHandlers(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7322 var d = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7323 on(d.scroller, "mousedown", operation(cm, onMouseDown))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7324 // Older IE's will not fire a second mousedown for a double click
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7325 if (ie && ie_version < 11)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7326 { on(d.scroller, "dblclick", operation(cm, function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7327 if (signalDOMEvent(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7328 var pos = posFromMouse(cm, e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7329 if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7330 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7331 var word = cm.findWordAt(pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7332 extendSelection(cm.doc, word.anchor, word.head)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7333 })) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7334 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7335 { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7336 // Some browsers fire contextmenu *after* opening the menu, at
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7337 // which point we can't mess with it anymore. Context menu is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7338 // handled in onMouseDown for these browsers.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7339 if (!captureRightClick) { on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7340
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7341 // Used to suppress mouse event handling when a touch happens
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7342 var touchFinished, prevTouch = {end: 0}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7343 function finishTouch() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7344 if (d.activeTouch) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7345 touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7346 prevTouch = d.activeTouch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7347 prevTouch.end = +new Date
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7348 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7349 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7350 function isMouseLikeTouchEvent(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7351 if (e.touches.length != 1) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7352 var touch = e.touches[0]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7353 return touch.radiusX <= 1 && touch.radiusY <= 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7354 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7355 function farAway(touch, other) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7356 if (other.left == null) { return true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7357 var dx = other.left - touch.left, dy = other.top - touch.top
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7358 return dx * dx + dy * dy > 20 * 20
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7359 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7360 on(d.scroller, "touchstart", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7361 if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7362 d.input.ensurePolled()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7363 clearTimeout(touchFinished)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7364 var now = +new Date
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7365 d.activeTouch = {start: now, moved: false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7366 prev: now - prevTouch.end <= 300 ? prevTouch : null}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7367 if (e.touches.length == 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7368 d.activeTouch.left = e.touches[0].pageX
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7369 d.activeTouch.top = e.touches[0].pageY
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7370 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7371 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7372 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7373 on(d.scroller, "touchmove", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7374 if (d.activeTouch) { d.activeTouch.moved = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7375 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7376 on(d.scroller, "touchend", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7377 var touch = d.activeTouch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7378 if (touch && !eventInWidget(d, e) && touch.left != null &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7379 !touch.moved && new Date - touch.start < 300) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7380 var pos = cm.coordsChar(d.activeTouch, "page"), range
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7381 if (!touch.prev || farAway(touch, touch.prev)) // Single tap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7382 { range = new Range(pos, pos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7383 else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7384 { range = cm.findWordAt(pos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7385 else // Triple tap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7386 { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7387 cm.setSelection(range.anchor, range.head)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7388 cm.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7389 e_preventDefault(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7390 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7391 finishTouch()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7392 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7393 on(d.scroller, "touchcancel", finishTouch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7394
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7395 // Sync scrolling between fake scrollbars and real scrollable
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7396 // area, ensure viewport is updated when scrolling.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7397 on(d.scroller, "scroll", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7398 if (d.scroller.clientHeight) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7399 setScrollTop(cm, d.scroller.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7400 setScrollLeft(cm, d.scroller.scrollLeft, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7401 signal(cm, "scroll", cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7402 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7403 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7404
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7405 // Listen to wheel events in order to try and update the viewport on time.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7406 on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7407 on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7408
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7409 // Prevent wrapper from ever scrolling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7410 on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7411
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7412 d.dragFunctions = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7413 enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e) }},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7414 over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7415 start: function (e) { return onDragStart(cm, e); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7416 drop: operation(cm, onDrop),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7417 leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7418 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7419
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7420 var inp = d.input.getField()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7421 on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7422 on(inp, "keydown", operation(cm, onKeyDown))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7423 on(inp, "keypress", operation(cm, onKeyPress))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7424 on(inp, "focus", function (e) { return onFocus(cm, e); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7425 on(inp, "blur", function (e) { return onBlur(cm, e); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7426 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7427
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7428 var initHooks = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7429 CodeMirror$1.defineInitHook = function (f) { return initHooks.push(f); }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7430
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7431 // Indent the given line. The how parameter can be "smart",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7432 // "add"/null, "subtract", or "prev". When aggressive is false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7433 // (typically set to true for forced single-line indents), empty
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7434 // lines are not indented, and places where the mode returns Pass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7435 // are left alone.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7436 function indentLine(cm, n, how, aggressive) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7437 var doc = cm.doc, state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7438 if (how == null) { how = "add" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7439 if (how == "smart") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7440 // Fall back to "prev" when the mode doesn't have an indentation
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7441 // method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7442 if (!doc.mode.indent) { how = "prev" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7443 else { state = getStateBefore(cm, n) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7444 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7445
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7446 var tabSize = cm.options.tabSize
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7447 var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7448 if (line.stateAfter) { line.stateAfter = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7449 var curSpaceString = line.text.match(/^\s*/)[0], indentation
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7450 if (!aggressive && !/\S/.test(line.text)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7451 indentation = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7452 how = "not"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7453 } else if (how == "smart") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7454 indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7455 if (indentation == Pass || indentation > 150) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7456 if (!aggressive) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7457 how = "prev"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7458 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7459 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7460 if (how == "prev") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7461 if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7462 else { indentation = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7463 } else if (how == "add") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7464 indentation = curSpace + cm.options.indentUnit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7465 } else if (how == "subtract") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7466 indentation = curSpace - cm.options.indentUnit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7467 } else if (typeof how == "number") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7468 indentation = curSpace + how
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7469 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7470 indentation = Math.max(0, indentation)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7471
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7472 var indentString = "", pos = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7473 if (cm.options.indentWithTabs)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7474 { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t"} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7475 if (pos < indentation) { indentString += spaceStr(indentation - pos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7476
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7477 if (indentString != curSpaceString) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7478 replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7479 line.stateAfter = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7480 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7481 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7482 // Ensure that, if the cursor was in the whitespace at the start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7483 // of the line, it is moved to the end of that space.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7484 for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7485 var range = doc.sel.ranges[i$1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7486 if (range.head.line == n && range.head.ch < curSpaceString.length) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7487 var pos$1 = Pos(n, curSpaceString.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7488 replaceOneSelection(doc, i$1, new Range(pos$1, pos$1))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7489 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7490 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7491 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7492 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7493 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7494
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7495 // This will be set to a {lineWise: bool, text: [string]} object, so
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7496 // that, when pasting, we know what kind of selections the copied
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7497 // text was made out of.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7498 var lastCopied = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7499
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7500 function setLastCopied(newLastCopied) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7501 lastCopied = newLastCopied
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7502 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7503
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7504 function applyTextInput(cm, inserted, deleted, sel, origin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7505 var doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7506 cm.display.shift = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7507 if (!sel) { sel = doc.sel }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7508
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7509 var paste = cm.state.pasteIncoming || origin == "paste"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7510 var textLines = splitLinesAuto(inserted), multiPaste = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7511 // When pasing N lines into N selections, insert one line per selection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7512 if (paste && sel.ranges.length > 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7513 if (lastCopied && lastCopied.text.join("\n") == inserted) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7514 if (sel.ranges.length % lastCopied.text.length == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7515 multiPaste = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7516 for (var i = 0; i < lastCopied.text.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7517 { multiPaste.push(doc.splitLines(lastCopied.text[i])) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7518 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7519 } else if (textLines.length == sel.ranges.length) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7520 multiPaste = map(textLines, function (l) { return [l]; })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7521 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7522 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7523
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7524 var updateInput
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7525 // Normal behavior is to insert the new text into every selection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7526 for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7527 var range$$1 = sel.ranges[i$1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7528 var from = range$$1.from(), to = range$$1.to()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7529 if (range$$1.empty()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7530 if (deleted && deleted > 0) // Handle deletion
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7531 { from = Pos(from.line, from.ch - deleted) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7532 else if (cm.state.overwrite && !paste) // Handle overwrite
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7533 { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7534 else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7535 { from = to = Pos(from.line, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7536 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7537 updateInput = cm.curOp.updateInput
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7538 var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7539 origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7540 makeChange(cm.doc, changeEvent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7541 signalLater(cm, "inputRead", cm, changeEvent)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7542 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7543 if (inserted && !paste)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7544 { triggerElectric(cm, inserted) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7545
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7546 ensureCursorVisible(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7547 cm.curOp.updateInput = updateInput
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7548 cm.curOp.typing = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7549 cm.state.pasteIncoming = cm.state.cutIncoming = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7550 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7551
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7552 function handlePaste(e, cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7553 var pasted = e.clipboardData && e.clipboardData.getData("Text")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7554 if (pasted) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7555 e.preventDefault()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7556 if (!cm.isReadOnly() && !cm.options.disableInput)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7557 { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7558 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7559 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7560 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7561
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7562 function triggerElectric(cm, inserted) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7563 // When an 'electric' character is inserted, immediately trigger a reindent
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7564 if (!cm.options.electricChars || !cm.options.smartIndent) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7565 var sel = cm.doc.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7566
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7567 for (var i = sel.ranges.length - 1; i >= 0; i--) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7568 var range$$1 = sel.ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7569 if (range$$1.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range$$1.head.line)) { continue }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7570 var mode = cm.getModeAt(range$$1.head)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7571 var indented = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7572 if (mode.electricChars) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7573 for (var j = 0; j < mode.electricChars.length; j++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7574 { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7575 indented = indentLine(cm, range$$1.head.line, "smart")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7576 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7577 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7578 } else if (mode.electricInput) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7579 if (mode.electricInput.test(getLine(cm.doc, range$$1.head.line).text.slice(0, range$$1.head.ch)))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7580 { indented = indentLine(cm, range$$1.head.line, "smart") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7581 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7582 if (indented) { signalLater(cm, "electricInput", cm, range$$1.head.line) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7583 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7584 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7585
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7586 function copyableRanges(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7587 var text = [], ranges = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7588 for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7589 var line = cm.doc.sel.ranges[i].head.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7590 var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7591 ranges.push(lineRange)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7592 text.push(cm.getRange(lineRange.anchor, lineRange.head))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7593 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7594 return {text: text, ranges: ranges}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7595 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7596
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7597 function disableBrowserMagic(field, spellcheck) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7598 field.setAttribute("autocorrect", "off")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7599 field.setAttribute("autocapitalize", "off")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7600 field.setAttribute("spellcheck", !!spellcheck)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7601 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7602
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7603 function hiddenTextarea() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7604 var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7605 var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7606 // The textarea is kept positioned near the cursor to prevent the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7607 // fact that it'll be scrolled into view on input from scrolling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7608 // our fake cursor out of view. On webkit, when wrap=off, paste is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7609 // very slow. So make the area wide instead.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7610 if (webkit) { te.style.width = "1000px" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7611 else { te.setAttribute("wrap", "off") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7612 // If border: 0; -- iOS fails to open keyboard (issue #1287)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7613 if (ios) { te.style.border = "1px solid black" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7614 disableBrowserMagic(te)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7615 return div
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7616 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7617
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7618 // The publicly visible API. Note that methodOp(f) means
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7619 // 'wrap f in an operation, performed on its `this` parameter'.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7620
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7621 // This is not the complete set of editor methods. Most of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7622 // methods defined on the Doc type are also injected into
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7623 // CodeMirror.prototype, for backwards compatibility and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7624 // convenience.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7625
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7626 var addEditorMethods = function(CodeMirror) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7627 var optionHandlers = CodeMirror.optionHandlers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7628
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7629 var helpers = CodeMirror.helpers = {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7630
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7631 CodeMirror.prototype = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7632 constructor: CodeMirror,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7633 focus: function(){window.focus(); this.display.input.focus()},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7634
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7635 setOption: function(option, value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7636 var options = this.options, old = options[option]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7637 if (options[option] == value && option != "mode") { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7638 options[option] = value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7639 if (optionHandlers.hasOwnProperty(option))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7640 { operation(this, optionHandlers[option])(this, value, old) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7641 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7642
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7643 getOption: function(option) {return this.options[option]},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7644 getDoc: function() {return this.doc},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7645
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7646 addKeyMap: function(map$$1, bottom) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7647 this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map$$1))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7648 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7649 removeKeyMap: function(map$$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7650 var maps = this.state.keyMaps
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7651 for (var i = 0; i < maps.length; ++i)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7652 { if (maps[i] == map$$1 || maps[i].name == map$$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7653 maps.splice(i, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7654 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7655 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7656 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7657
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7658 addOverlay: methodOp(function(spec, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7659 var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7660 if (mode.startState) { throw new Error("Overlays may not be stateful.") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7661 insertSorted(this.state.overlays,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7662 {mode: mode, modeSpec: spec, opaque: options && options.opaque,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7663 priority: (options && options.priority) || 0},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7664 function (overlay) { return overlay.priority; })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7665 this.state.modeGen++
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7666 regChange(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7667 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7668 removeOverlay: methodOp(function(spec) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7669 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7670
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7671 var overlays = this.state.overlays
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7672 for (var i = 0; i < overlays.length; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7673 var cur = overlays[i].modeSpec
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7674 if (cur == spec || typeof spec == "string" && cur.name == spec) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7675 overlays.splice(i, 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7676 this$1.state.modeGen++
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7677 regChange(this$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7678 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7679 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7680 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7681 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7682
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7683 indentLine: methodOp(function(n, dir, aggressive) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7684 if (typeof dir != "string" && typeof dir != "number") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7685 if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7686 else { dir = dir ? "add" : "subtract" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7687 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7688 if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7689 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7690 indentSelection: methodOp(function(how) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7691 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7692
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7693 var ranges = this.doc.sel.ranges, end = -1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7694 for (var i = 0; i < ranges.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7695 var range$$1 = ranges[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7696 if (!range$$1.empty()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7697 var from = range$$1.from(), to = range$$1.to()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7698 var start = Math.max(end, from.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7699 end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7700 for (var j = start; j < end; ++j)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7701 { indentLine(this$1, j, how) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7702 var newRanges = this$1.doc.sel.ranges
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7703 if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7704 { replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7705 } else if (range$$1.head.line > end) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7706 indentLine(this$1, range$$1.head.line, how, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7707 end = range$$1.head.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7708 if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7709 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7710 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7711 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7712
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7713 // Fetch the parser token for a given character. Useful for hacks
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7714 // that want to inspect the mode state (say, for completion).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7715 getTokenAt: function(pos, precise) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7716 return takeToken(this, pos, precise)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7717 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7718
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7719 getLineTokens: function(line, precise) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7720 return takeToken(this, Pos(line), precise, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7721 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7722
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7723 getTokenTypeAt: function(pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7724 pos = clipPos(this.doc, pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7725 var styles = getLineStyles(this, getLine(this.doc, pos.line))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7726 var before = 0, after = (styles.length - 1) / 2, ch = pos.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7727 var type
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7728 if (ch == 0) { type = styles[2] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7729 else { for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7730 var mid = (before + after) >> 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7731 if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7732 else if (styles[mid * 2 + 1] < ch) { before = mid + 1 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7733 else { type = styles[mid * 2 + 2]; break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7734 } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7735 var cut = type ? type.indexOf("overlay ") : -1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7736 return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7737 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7738
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7739 getModeAt: function(pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7740 var mode = this.doc.mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7741 if (!mode.innerMode) { return mode }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7742 return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7743 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7744
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7745 getHelper: function(pos, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7746 return this.getHelpers(pos, type)[0]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7747 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7748
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7749 getHelpers: function(pos, type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7750 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7751
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7752 var found = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7753 if (!helpers.hasOwnProperty(type)) { return found }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7754 var help = helpers[type], mode = this.getModeAt(pos)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7755 if (typeof mode[type] == "string") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7756 if (help[mode[type]]) { found.push(help[mode[type]]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7757 } else if (mode[type]) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7758 for (var i = 0; i < mode[type].length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7759 var val = help[mode[type][i]]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7760 if (val) { found.push(val) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7761 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7762 } else if (mode.helperType && help[mode.helperType]) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7763 found.push(help[mode.helperType])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7764 } else if (help[mode.name]) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7765 found.push(help[mode.name])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7766 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7767 for (var i$1 = 0; i$1 < help._global.length; i$1++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7768 var cur = help._global[i$1]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7769 if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7770 { found.push(cur.val) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7771 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7772 return found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7773 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7774
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7775 getStateAfter: function(line, precise) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7776 var doc = this.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7777 line = clipLine(doc, line == null ? doc.first + doc.size - 1: line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7778 return getStateBefore(this, line + 1, precise)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7779 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7780
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7781 cursorCoords: function(start, mode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7782 var pos, range$$1 = this.doc.sel.primary()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7783 if (start == null) { pos = range$$1.head }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7784 else if (typeof start == "object") { pos = clipPos(this.doc, start) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7785 else { pos = start ? range$$1.from() : range$$1.to() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7786 return cursorCoords(this, pos, mode || "page")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7787 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7788
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7789 charCoords: function(pos, mode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7790 return charCoords(this, clipPos(this.doc, pos), mode || "page")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7791 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7792
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7793 coordsChar: function(coords, mode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7794 coords = fromCoordSystem(this, coords, mode || "page")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7795 return coordsChar(this, coords.left, coords.top)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7796 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7797
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7798 lineAtHeight: function(height, mode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7799 height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7800 return lineAtHeight(this.doc, height + this.display.viewOffset)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7801 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7802 heightAtLine: function(line, mode, includeWidgets) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7803 var end = false, lineObj
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7804 if (typeof line == "number") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7805 var last = this.doc.first + this.doc.size - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7806 if (line < this.doc.first) { line = this.doc.first }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7807 else if (line > last) { line = last; end = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7808 lineObj = getLine(this.doc, line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7809 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7810 lineObj = line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7811 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7812 return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets).top +
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7813 (end ? this.doc.height - heightAtLine(lineObj) : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7814 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7815
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7816 defaultTextHeight: function() { return textHeight(this.display) },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7817 defaultCharWidth: function() { return charWidth(this.display) },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7818
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7819 getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7820
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7821 addWidget: function(pos, node, scroll, vert, horiz) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7822 var display = this.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7823 pos = cursorCoords(this, clipPos(this.doc, pos))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7824 var top = pos.bottom, left = pos.left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7825 node.style.position = "absolute"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7826 node.setAttribute("cm-ignore-events", "true")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7827 this.display.input.setUneditable(node)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7828 display.sizer.appendChild(node)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7829 if (vert == "over") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7830 top = pos.top
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7831 } else if (vert == "above" || vert == "near") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7832 var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7833 hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7834 // Default to positioning above (if specified and possible); otherwise default to positioning below
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7835 if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7836 { top = pos.top - node.offsetHeight }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7837 else if (pos.bottom + node.offsetHeight <= vspace)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7838 { top = pos.bottom }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7839 if (left + node.offsetWidth > hspace)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7840 { left = hspace - node.offsetWidth }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7841 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7842 node.style.top = top + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7843 node.style.left = node.style.right = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7844 if (horiz == "right") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7845 left = display.sizer.clientWidth - node.offsetWidth
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7846 node.style.right = "0px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7847 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7848 if (horiz == "left") { left = 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7849 else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7850 node.style.left = left + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7851 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7852 if (scroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7853 { scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7854 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7855
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7856 triggerOnKeyDown: methodOp(onKeyDown),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7857 triggerOnKeyPress: methodOp(onKeyPress),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7858 triggerOnKeyUp: onKeyUp,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7859
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7860 execCommand: function(cmd) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7861 if (commands.hasOwnProperty(cmd))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7862 { return commands[cmd].call(null, this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7863 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7864
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7865 triggerElectric: methodOp(function(text) { triggerElectric(this, text) }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7866
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7867 findPosH: function(from, amount, unit, visually) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7868 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7869
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7870 var dir = 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7871 if (amount < 0) { dir = -1; amount = -amount }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7872 var cur = clipPos(this.doc, from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7873 for (var i = 0; i < amount; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7874 cur = findPosH(this$1.doc, cur, dir, unit, visually)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7875 if (cur.hitSide) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7876 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7877 return cur
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7878 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7879
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7880 moveH: methodOp(function(dir, unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7881 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7882
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7883 this.extendSelectionsBy(function (range$$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7884 if (this$1.display.shift || this$1.doc.extend || range$$1.empty())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7885 { return findPosH(this$1.doc, range$$1.head, dir, unit, this$1.options.rtlMoveVisually) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7886 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7887 { return dir < 0 ? range$$1.from() : range$$1.to() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7888 }, sel_move)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7889 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7890
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7891 deleteH: methodOp(function(dir, unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7892 var sel = this.doc.sel, doc = this.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7893 if (sel.somethingSelected())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7894 { doc.replaceSelection("", null, "+delete") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7895 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7896 { deleteNearSelection(this, function (range$$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7897 var other = findPosH(doc, range$$1.head, dir, unit, false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7898 return dir < 0 ? {from: other, to: range$$1.head} : {from: range$$1.head, to: other}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7899 }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7900 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7901
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7902 findPosV: function(from, amount, unit, goalColumn) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7903 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7904
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7905 var dir = 1, x = goalColumn
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7906 if (amount < 0) { dir = -1; amount = -amount }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7907 var cur = clipPos(this.doc, from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7908 for (var i = 0; i < amount; ++i) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7909 var coords = cursorCoords(this$1, cur, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7910 if (x == null) { x = coords.left }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7911 else { coords.left = x }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7912 cur = findPosV(this$1, coords, dir, unit)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7913 if (cur.hitSide) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7914 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7915 return cur
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7916 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7917
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7918 moveV: methodOp(function(dir, unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7919 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7920
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7921 var doc = this.doc, goals = []
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7922 var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7923 doc.extendSelectionsBy(function (range$$1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7924 if (collapse)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7925 { return dir < 0 ? range$$1.from() : range$$1.to() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7926 var headPos = cursorCoords(this$1, range$$1.head, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7927 if (range$$1.goalColumn != null) { headPos.left = range$$1.goalColumn }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7928 goals.push(headPos.left)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7929 var pos = findPosV(this$1, headPos, dir, unit)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7930 if (unit == "page" && range$$1 == doc.sel.primary())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7931 { addToScrollPos(this$1, null, charCoords(this$1, pos, "div").top - headPos.top) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7932 return pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7933 }, sel_move)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7934 if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7935 { doc.sel.ranges[i].goalColumn = goals[i] } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7936 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7937
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7938 // Find the word at the given position (as returned by coordsChar).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7939 findWordAt: function(pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7940 var doc = this.doc, line = getLine(doc, pos.line).text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7941 var start = pos.ch, end = pos.ch
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7942 if (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7943 var helper = this.getHelper(pos, "wordChars")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7944 if ((pos.xRel < 0 || end == line.length) && start) { --start; } else { ++end }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7945 var startChar = line.charAt(start)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7946 var check = isWordChar(startChar, helper)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7947 ? function (ch) { return isWordChar(ch, helper); }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7948 : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7949 : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7950 while (start > 0 && check(line.charAt(start - 1))) { --start }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7951 while (end < line.length && check(line.charAt(end))) { ++end }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7952 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7953 return new Range(Pos(pos.line, start), Pos(pos.line, end))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7954 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7955
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7956 toggleOverwrite: function(value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7957 if (value != null && value == this.state.overwrite) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7958 if (this.state.overwrite = !this.state.overwrite)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7959 { addClass(this.display.cursorDiv, "CodeMirror-overwrite") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7960 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7961 { rmClass(this.display.cursorDiv, "CodeMirror-overwrite") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7962
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7963 signal(this, "overwriteToggle", this, this.state.overwrite)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7964 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7965 hasFocus: function() { return this.display.input.getField() == activeElt() },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7966 isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7967
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7968 scrollTo: methodOp(function(x, y) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7969 if (x != null || y != null) { resolveScrollToPos(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7970 if (x != null) { this.curOp.scrollLeft = x }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7971 if (y != null) { this.curOp.scrollTop = y }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7972 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7973 getScrollInfo: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7974 var scroller = this.display.scroller
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7975 return {left: scroller.scrollLeft, top: scroller.scrollTop,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7976 height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7977 width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7978 clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7979 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7980
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7981 scrollIntoView: methodOp(function(range$$1, margin) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7982 if (range$$1 == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7983 range$$1 = {from: this.doc.sel.primary().head, to: null}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7984 if (margin == null) { margin = this.options.cursorScrollMargin }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7985 } else if (typeof range$$1 == "number") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7986 range$$1 = {from: Pos(range$$1, 0), to: null}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7987 } else if (range$$1.from == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7988 range$$1 = {from: range$$1, to: null}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7989 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7990 if (!range$$1.to) { range$$1.to = range$$1.from }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7991 range$$1.margin = margin || 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7992
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7993 if (range$$1.from.line != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7994 resolveScrollToPos(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7995 this.curOp.scrollToPos = range$$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7996 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7997 var sPos = calculateScrollPos(this, Math.min(range$$1.from.left, range$$1.to.left),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7998 Math.min(range$$1.from.top, range$$1.to.top) - range$$1.margin,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7999 Math.max(range$$1.from.right, range$$1.to.right),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8000 Math.max(range$$1.from.bottom, range$$1.to.bottom) + range$$1.margin)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8001 this.scrollTo(sPos.scrollLeft, sPos.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8002 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8003 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8004
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8005 setSize: methodOp(function(width, height) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8006 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8007
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8008 var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8009 if (width != null) { this.display.wrapper.style.width = interpret(width) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8010 if (height != null) { this.display.wrapper.style.height = interpret(height) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8011 if (this.options.lineWrapping) { clearLineMeasurementCache(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8012 var lineNo$$1 = this.display.viewFrom
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8013 this.doc.iter(lineNo$$1, this.display.viewTo, function (line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8014 if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8015 { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo$$1, "widget"); break } } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8016 ++lineNo$$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8017 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8018 this.curOp.forceUpdate = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8019 signal(this, "refresh", this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8020 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8021
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8022 operation: function(f){return runInOp(this, f)},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8023
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8024 refresh: methodOp(function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8025 var oldHeight = this.display.cachedTextHeight
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8026 regChange(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8027 this.curOp.forceUpdate = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8028 clearCaches(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8029 this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8030 updateGutterSpace(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8031 if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8032 { estimateLineHeights(this) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8033 signal(this, "refresh", this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8034 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8035
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8036 swapDoc: methodOp(function(doc) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8037 var old = this.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8038 old.cm = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8039 attachDoc(this, doc)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8040 clearCaches(this)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8041 this.display.input.reset()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8042 this.scrollTo(doc.scrollLeft, doc.scrollTop)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8043 this.curOp.forceScroll = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8044 signalLater(this, "swapDoc", this, old)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8045 return old
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8046 }),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8047
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8048 getInputField: function(){return this.display.input.getField()},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8049 getWrapperElement: function(){return this.display.wrapper},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8050 getScrollerElement: function(){return this.display.scroller},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8051 getGutterElement: function(){return this.display.gutters}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8052 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8053 eventMixin(CodeMirror)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8054
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8055 CodeMirror.registerHelper = function(type, name, value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8056 if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8057 helpers[type][name] = value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8058 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8059 CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8060 CodeMirror.registerHelper(type, name, value)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8061 helpers[type]._global.push({pred: predicate, val: value})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8062 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8063 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8064
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8065 // Used for horizontal relative motion. Dir is -1 or 1 (left or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8066 // right), unit can be "char", "column" (like char, but doesn't
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8067 // cross line boundaries), "word" (across next word), or "group" (to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8068 // the start of next group of word or non-word-non-whitespace
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8069 // chars). The visually param controls whether, in right-to-left
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8070 // text, direction 1 means to move towards the next index in the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8071 // string, or towards the character to the right of the current
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8072 // position. The resulting position will have a hitSide=true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8073 // property if it reached the end of the document.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8074 function findPosH(doc, pos, dir, unit, visually) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8075 var line = pos.line, ch = pos.ch, origDir = dir
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8076 var lineObj = getLine(doc, line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8077 function findNextLine() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8078 var l = line + dir
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8079 if (l < doc.first || l >= doc.first + doc.size) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8080 line = l
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8081 return lineObj = getLine(doc, l)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8082 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8083 function moveOnce(boundToLine) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8084 var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8085 if (next == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8086 if (!boundToLine && findNextLine()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8087 if (visually) { ch = (dir < 0 ? lineRight : lineLeft)(lineObj) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8088 else { ch = dir < 0 ? lineObj.text.length : 0 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8089 } else { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8090 } else { ch = next }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8091 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8092 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8093
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8094 if (unit == "char") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8095 moveOnce()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8096 } else if (unit == "column") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8097 moveOnce(true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8098 } else if (unit == "word" || unit == "group") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8099 var sawType = null, group = unit == "group"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8100 var helper = doc.cm && doc.cm.getHelper(pos, "wordChars")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8101 for (var first = true;; first = false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8102 if (dir < 0 && !moveOnce(!first)) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8103 var cur = lineObj.text.charAt(ch) || "\n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8104 var type = isWordChar(cur, helper) ? "w"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8105 : group && cur == "\n" ? "n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8106 : !group || /\s/.test(cur) ? null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8107 : "p"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8108 if (group && !first && !type) { type = "s" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8109 if (sawType && sawType != type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8110 if (dir < 0) {dir = 1; moveOnce()}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8111 break
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8112 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8113
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8114 if (type) { sawType = type }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8115 if (dir > 0 && !moveOnce(!first)) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8116 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8117 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8118 var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8119 if (!cmp(pos, result)) { result.hitSide = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8120 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8121 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8122
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8123 // For relative vertical movement. Dir may be -1 or 1. Unit can be
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8124 // "page" or "line". The resulting position will have a hitSide=true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8125 // property if it reached the end of the document.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8126 function findPosV(cm, pos, dir, unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8127 var doc = cm.doc, x = pos.left, y
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8128 if (unit == "page") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8129 var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8130 var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8131 y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8132
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8133 } else if (unit == "line") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8134 y = dir > 0 ? pos.bottom + 3 : pos.top - 3
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8135 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8136 var target
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8137 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8138 target = coordsChar(cm, x, y)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8139 if (!target.outside) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8140 if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8141 y += dir * 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8142 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8143 return target
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8144 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8145
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8146 // CONTENTEDITABLE INPUT STYLE
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8147
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8148 function ContentEditableInput(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8149 this.cm = cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8150 this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8151 this.polling = new Delayed()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8152 this.composing = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8153 this.gracePeriod = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8154 this.readDOMTimeout = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8155 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8156
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8157 ContentEditableInput.prototype = copyObj({
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8158 init: function(display) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8159 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8160
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8161 var input = this, cm = input.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8162 var div = input.div = display.lineDiv
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8163 disableBrowserMagic(div, cm.options.spellcheck)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8164
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8165 on(div, "paste", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8166 if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8167 // IE doesn't fire input events, so we schedule a read for the pasted content in this way
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8168 if (ie_version <= 11) { setTimeout(operation(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8169 if (!input.pollContent()) { regChange(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8170 }), 20) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8171 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8172
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8173 on(div, "compositionstart", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8174 this$1.composing = {data: e.data}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8175 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8176 on(div, "compositionupdate", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8177 if (!this$1.composing) { this$1.composing = {data: e.data} }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8178 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8179 on(div, "compositionend", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8180 if (this$1.composing) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8181 if (e.data != this$1.composing.data) { this$1.readFromDOMSoon() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8182 this$1.composing = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8183 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8184 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8185
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8186 on(div, "touchstart", function () { return input.forceCompositionEnd(); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8187
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8188 on(div, "input", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8189 if (!this$1.composing) { this$1.readFromDOMSoon() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8190 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8191
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8192 function onCopyCut(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8193 if (signalDOMEvent(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8194 if (cm.somethingSelected()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8195 setLastCopied({lineWise: false, text: cm.getSelections()})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8196 if (e.type == "cut") { cm.replaceSelection("", null, "cut") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8197 } else if (!cm.options.lineWiseCopyCut) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8198 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8199 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8200 var ranges = copyableRanges(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8201 setLastCopied({lineWise: true, text: ranges.text})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8202 if (e.type == "cut") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8203 cm.operation(function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8204 cm.setSelections(ranges.ranges, 0, sel_dontScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8205 cm.replaceSelection("", null, "cut")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8206 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8207 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8208 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8209 if (e.clipboardData) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8210 e.clipboardData.clearData()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8211 var content = lastCopied.text.join("\n")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8212 // iOS exposes the clipboard API, but seems to discard content inserted into it
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8213 e.clipboardData.setData("Text", content)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8214 if (e.clipboardData.getData("Text") == content) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8215 e.preventDefault()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8216 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8217 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8218 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8219 // Old-fashioned briefly-focus-a-textarea hack
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8220 var kludge = hiddenTextarea(), te = kludge.firstChild
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8221 cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8222 te.value = lastCopied.text.join("\n")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8223 var hadFocus = document.activeElement
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8224 selectInput(te)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8225 setTimeout(function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8226 cm.display.lineSpace.removeChild(kludge)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8227 hadFocus.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8228 if (hadFocus == div) { input.showPrimarySelection() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8229 }, 50)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8230 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8231 on(div, "copy", onCopyCut)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8232 on(div, "cut", onCopyCut)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8233 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8234
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8235 prepareSelection: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8236 var result = prepareSelection(this.cm, false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8237 result.focus = this.cm.state.focused
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8238 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8239 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8240
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8241 showSelection: function(info, takeFocus) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8242 if (!info || !this.cm.display.view.length) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8243 if (info.focus || takeFocus) { this.showPrimarySelection() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8244 this.showMultipleSelections(info)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8245 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8246
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8247 showPrimarySelection: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8248 var sel = window.getSelection(), prim = this.cm.doc.sel.primary()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8249 var curAnchor = domToPos(this.cm, sel.anchorNode, sel.anchorOffset)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8250 var curFocus = domToPos(this.cm, sel.focusNode, sel.focusOffset)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8251 if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8252 cmp(minPos(curAnchor, curFocus), prim.from()) == 0 &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8253 cmp(maxPos(curAnchor, curFocus), prim.to()) == 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8254 { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8255
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8256 var start = posToDOM(this.cm, prim.from())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8257 var end = posToDOM(this.cm, prim.to())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8258 if (!start && !end) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8259
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8260 var view = this.cm.display.view
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8261 var old = sel.rangeCount && sel.getRangeAt(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8262 if (!start) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8263 start = {node: view[0].measure.map[2], offset: 0}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8264 } else if (!end) { // FIXME dangerously hacky
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8265 var measure = view[view.length - 1].measure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8266 var map$$1 = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8267 end = {node: map$$1[map$$1.length - 1], offset: map$$1[map$$1.length - 2] - map$$1[map$$1.length - 3]}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8268 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8269
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8270 var rng
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8271 try { rng = range(start.node, start.offset, end.offset, end.node) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8272 catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8273 if (rng) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8274 if (!gecko && this.cm.state.focused) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8275 sel.collapse(start.node, start.offset)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8276 if (!rng.collapsed) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8277 sel.removeAllRanges()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8278 sel.addRange(rng)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8279 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8280 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8281 sel.removeAllRanges()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8282 sel.addRange(rng)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8283 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8284 if (old && sel.anchorNode == null) { sel.addRange(old) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8285 else if (gecko) { this.startGracePeriod() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8286 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8287 this.rememberSelection()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8288 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8289
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8290 startGracePeriod: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8291 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8292
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8293 clearTimeout(this.gracePeriod)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8294 this.gracePeriod = setTimeout(function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8295 this$1.gracePeriod = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8296 if (this$1.selectionChanged())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8297 { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8298 }, 20)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8299 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8300
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8301 showMultipleSelections: function(info) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8302 removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8303 removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8304 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8305
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8306 rememberSelection: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8307 var sel = window.getSelection()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8308 this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8309 this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8310 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8311
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8312 selectionInEditor: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8313 var sel = window.getSelection()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8314 if (!sel.rangeCount) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8315 var node = sel.getRangeAt(0).commonAncestorContainer
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8316 return contains(this.div, node)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8317 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8318
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8319 focus: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8320 if (this.cm.options.readOnly != "nocursor") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8321 if (!this.selectionInEditor())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8322 { this.showSelection(this.prepareSelection(), true) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8323 this.div.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8324 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8325 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8326 blur: function() { this.div.blur() },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8327 getField: function() { return this.div },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8328
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8329 supportsTouch: function() { return true },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8330
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8331 receivedFocus: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8332 var input = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8333 if (this.selectionInEditor())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8334 { this.pollSelection() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8335 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8336 { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8337
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8338 function poll() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8339 if (input.cm.state.focused) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8340 input.pollSelection()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8341 input.polling.set(input.cm.options.pollInterval, poll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8342 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8343 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8344 this.polling.set(this.cm.options.pollInterval, poll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8345 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8346
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8347 selectionChanged: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8348 var sel = window.getSelection()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8349 return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8350 sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8351 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8352
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8353 pollSelection: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8354 if (!this.composing && this.readDOMTimeout == null && !this.gracePeriod && this.selectionChanged()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8355 var sel = window.getSelection(), cm = this.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8356 this.rememberSelection()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8357 var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8358 var head = domToPos(cm, sel.focusNode, sel.focusOffset)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8359 if (anchor && head) { runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8360 setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8361 if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8362 }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8363 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8364 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8365
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8366 pollContent: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8367 if (this.readDOMTimeout != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8368 clearTimeout(this.readDOMTimeout)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8369 this.readDOMTimeout = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8370 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8371
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8372 var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8373 var from = sel.from(), to = sel.to()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8374 if (from.ch == 0 && from.line > cm.firstLine())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8375 { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8376 if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8377 { to = Pos(to.line + 1, 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8378 if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8379
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8380 var fromIndex, fromLine, fromNode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8381 if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8382 fromLine = lineNo(display.view[0].line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8383 fromNode = display.view[0].node
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8384 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8385 fromLine = lineNo(display.view[fromIndex].line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8386 fromNode = display.view[fromIndex - 1].node.nextSibling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8387 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8388 var toIndex = findViewIndex(cm, to.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8389 var toLine, toNode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8390 if (toIndex == display.view.length - 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8391 toLine = display.viewTo - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8392 toNode = display.lineDiv.lastChild
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8393 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8394 toLine = lineNo(display.view[toIndex + 1].line) - 1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8395 toNode = display.view[toIndex + 1].node.previousSibling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8396 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8397
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8398 if (!fromNode) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8399 var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8400 var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8401 while (newText.length > 1 && oldText.length > 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8402 if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine-- }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8403 else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++ }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8404 else { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8405 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8406
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8407 var cutFront = 0, cutEnd = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8408 var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8409 while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8410 { ++cutFront }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8411 var newBot = lst(newText), oldBot = lst(oldText)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8412 var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8413 oldBot.length - (oldText.length == 1 ? cutFront : 0))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8414 while (cutEnd < maxCutEnd &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8415 newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8416 { ++cutEnd }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8417
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8418 newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8419 newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8420
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8421 var chFrom = Pos(fromLine, cutFront)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8422 var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8423 if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8424 replaceRange(cm.doc, newText, chFrom, chTo, "+input")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8425 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8426 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8427 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8428
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8429 ensurePolled: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8430 this.forceCompositionEnd()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8431 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8432 reset: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8433 this.forceCompositionEnd()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8434 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8435 forceCompositionEnd: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8436 if (!this.composing) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8437 this.composing = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8438 if (!this.pollContent()) { regChange(this.cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8439 this.div.blur()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8440 this.div.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8441 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8442 readFromDOMSoon: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8443 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8444
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8445 if (this.readDOMTimeout != null) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8446 this.readDOMTimeout = setTimeout(function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8447 this$1.readDOMTimeout = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8448 if (this$1.composing) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8449 if (this$1.cm.isReadOnly() || !this$1.pollContent())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8450 { runInOp(this$1.cm, function () { return regChange(this$1.cm); }) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8451 }, 80)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8452 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8453
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8454 setUneditable: function(node) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8455 node.contentEditable = "false"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8456 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8457
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8458 onKeyPress: function(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8459 e.preventDefault()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8460 if (!this.cm.isReadOnly())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8461 { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8462 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8463
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8464 readOnlyChanged: function(val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8465 this.div.contentEditable = String(val != "nocursor")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8466 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8467
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8468 onContextMenu: nothing,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8469 resetPosition: nothing,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8470
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8471 needsContentAttribute: true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8472 }, ContentEditableInput.prototype)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8473
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8474 function posToDOM(cm, pos) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8475 var view = findViewForLine(cm, pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8476 if (!view || view.hidden) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8477 var line = getLine(cm.doc, pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8478 var info = mapFromLineView(view, line, pos.line)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8479
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8480 var order = getOrder(line), side = "left"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8481 if (order) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8482 var partPos = getBidiPartAt(order, pos.ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8483 side = partPos % 2 ? "right" : "left"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8484 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8485 var result = nodeAndOffsetInLineMap(info.map, pos.ch, side)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8486 result.offset = result.collapse == "right" ? result.end : result.start
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8487 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8488 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8489
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8490 function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8491
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8492 function domTextBetween(cm, from, to, fromLine, toLine) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8493 var text = "", closing = false, lineSep = cm.doc.lineSeparator()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8494 function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8495 function walk(node) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8496 if (node.nodeType == 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8497 var cmText = node.getAttribute("cm-text")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8498 if (cmText != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8499 if (cmText == "") { text += node.textContent.replace(/\u200b/g, "") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8500 else { text += cmText }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8501 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8502 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8503 var markerID = node.getAttribute("cm-marker"), range$$1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8504 if (markerID) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8505 var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8506 if (found.length && (range$$1 = found[0].find()))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8507 { text += getBetween(cm.doc, range$$1.from, range$$1.to).join(lineSep) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8508 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8509 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8510 if (node.getAttribute("contenteditable") == "false") { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8511 for (var i = 0; i < node.childNodes.length; i++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8512 { walk(node.childNodes[i]) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8513 if (/^(pre|div|p)$/i.test(node.nodeName))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8514 { closing = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8515 } else if (node.nodeType == 3) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8516 var val = node.nodeValue
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8517 if (!val) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8518 if (closing) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8519 text += lineSep
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8520 closing = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8521 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8522 text += val
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8523 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8524 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8525 for (;;) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8526 walk(from)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8527 if (from == to) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8528 from = from.nextSibling
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8529 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8530 return text
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8531 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8532
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8533 function domToPos(cm, node, offset) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8534 var lineNode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8535 if (node == cm.display.lineDiv) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8536 lineNode = cm.display.lineDiv.childNodes[offset]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8537 if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8538 node = null; offset = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8539 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8540 for (lineNode = node;; lineNode = lineNode.parentNode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8541 if (!lineNode || lineNode == cm.display.lineDiv) { return null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8542 if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8543 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8544 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8545 for (var i = 0; i < cm.display.view.length; i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8546 var lineView = cm.display.view[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8547 if (lineView.node == lineNode)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8548 { return locateNodeInLineView(lineView, node, offset) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8549 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8550 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8551
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8552 function locateNodeInLineView(lineView, node, offset) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8553 var wrapper = lineView.text.firstChild, bad = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8554 if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8555 if (node == wrapper) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8556 bad = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8557 node = wrapper.childNodes[offset]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8558 offset = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8559 if (!node) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8560 var line = lineView.rest ? lst(lineView.rest) : lineView.line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8561 return badPos(Pos(lineNo(line), line.text.length), bad)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8562 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8563 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8564
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8565 var textNode = node.nodeType == 3 ? node : null, topNode = node
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8566 if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8567 textNode = node.firstChild
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8568 if (offset) { offset = textNode.nodeValue.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8569 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8570 while (topNode.parentNode != wrapper) { topNode = topNode.parentNode }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8571 var measure = lineView.measure, maps = measure.maps
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8572
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8573 function find(textNode, topNode, offset) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8574 for (var i = -1; i < (maps ? maps.length : 0); i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8575 var map$$1 = i < 0 ? measure.map : maps[i]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8576 for (var j = 0; j < map$$1.length; j += 3) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8577 var curNode = map$$1[j + 2]
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8578 if (curNode == textNode || curNode == topNode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8579 var line = lineNo(i < 0 ? lineView.line : lineView.rest[i])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8580 var ch = map$$1[j] + offset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8581 if (offset < 0 || curNode != textNode) { ch = map$$1[j + (offset ? 1 : 0)] }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8582 return Pos(line, ch)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8583 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8584 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8585 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8586 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8587 var found = find(textNode, topNode, offset)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8588 if (found) { return badPos(found, bad) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8589
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8590 // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8591 for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8592 found = find(after, after.firstChild, 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8593 if (found)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8594 { return badPos(Pos(found.line, found.ch - dist), bad) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8595 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8596 { dist += after.textContent.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8597 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8598 for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8599 found = find(before, before.firstChild, -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8600 if (found)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8601 { return badPos(Pos(found.line, found.ch + dist$1), bad) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8602 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8603 { dist$1 += before.textContent.length }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8604 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8605 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8606
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8607 // TEXTAREA INPUT STYLE
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8608
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8609 function TextareaInput(cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8610 this.cm = cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8611 // See input.poll and input.reset
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8612 this.prevInput = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8613
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8614 // Flag that indicates whether we expect input to appear real soon
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8615 // now (after some event like 'keypress' or 'input') and are
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8616 // polling intensively.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8617 this.pollingFast = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8618 // Self-resetting timeout for the poller
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8619 this.polling = new Delayed()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8620 // Tracks when input.reset has punted to just putting a short
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8621 // string into the textarea instead of the full selection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8622 this.inaccurateSelection = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8623 // Used to work around IE issue with selection being forgotten when focus moves away from textarea
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8624 this.hasSelection = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8625 this.composing = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8626 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8627
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8628 TextareaInput.prototype = copyObj({
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8629 init: function(display) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8630 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8631
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8632 var input = this, cm = this.cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8633
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8634 // Wraps and hides input textarea
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8635 var div = this.wrapper = hiddenTextarea()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8636 // The semihidden textarea that is focused when the editor is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8637 // focused, and receives input.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8638 var te = this.textarea = div.firstChild
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8639 display.wrapper.insertBefore(div, display.wrapper.firstChild)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8640
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8641 // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8642 if (ios) { te.style.width = "0px" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8643
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8644 on(te, "input", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8645 if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8646 input.poll()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8647 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8648
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8649 on(te, "paste", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8650 if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8651
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8652 cm.state.pasteIncoming = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8653 input.fastPoll()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8654 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8655
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8656 function prepareCopyCut(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8657 if (signalDOMEvent(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8658 if (cm.somethingSelected()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8659 setLastCopied({lineWise: false, text: cm.getSelections()})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8660 if (input.inaccurateSelection) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8661 input.prevInput = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8662 input.inaccurateSelection = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8663 te.value = lastCopied.text.join("\n")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8664 selectInput(te)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8665 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8666 } else if (!cm.options.lineWiseCopyCut) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8667 return
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8668 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8669 var ranges = copyableRanges(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8670 setLastCopied({lineWise: true, text: ranges.text})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8671 if (e.type == "cut") {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8672 cm.setSelections(ranges.ranges, null, sel_dontScroll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8673 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8674 input.prevInput = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8675 te.value = ranges.text.join("\n")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8676 selectInput(te)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8677 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8678 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8679 if (e.type == "cut") { cm.state.cutIncoming = true }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8680 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8681 on(te, "cut", prepareCopyCut)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8682 on(te, "copy", prepareCopyCut)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8683
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8684 on(display.scroller, "paste", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8685 if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8686 cm.state.pasteIncoming = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8687 input.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8688 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8689
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8690 // Prevent normal selection in the editor (we handle our own)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8691 on(display.lineSpace, "selectstart", function (e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8692 if (!eventInWidget(display, e)) { e_preventDefault(e) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8693 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8694
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8695 on(te, "compositionstart", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8696 var start = cm.getCursor("from")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8697 if (input.composing) { input.composing.range.clear() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8698 input.composing = {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8699 start: start,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8700 range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8701 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8702 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8703 on(te, "compositionend", function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8704 if (input.composing) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8705 input.poll()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8706 input.composing.range.clear()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8707 input.composing = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8708 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8709 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8710 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8711
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8712 prepareSelection: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8713 // Redraw the selection and/or cursor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8714 var cm = this.cm, display = cm.display, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8715 var result = prepareSelection(cm)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8716
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8717 // Move the hidden textarea near the cursor to prevent scrolling artifacts
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8718 if (cm.options.moveInputWithCursor) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8719 var headPos = cursorCoords(cm, doc.sel.primary().head, "div")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8720 var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8721 result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8722 headPos.top + lineOff.top - wrapOff.top))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8723 result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8724 headPos.left + lineOff.left - wrapOff.left))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8725 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8726
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8727 return result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8728 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8729
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8730 showSelection: function(drawn) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8731 var cm = this.cm, display = cm.display
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8732 removeChildrenAndAdd(display.cursorDiv, drawn.cursors)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8733 removeChildrenAndAdd(display.selectionDiv, drawn.selection)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8734 if (drawn.teTop != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8735 this.wrapper.style.top = drawn.teTop + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8736 this.wrapper.style.left = drawn.teLeft + "px"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8737 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8738 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8739
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8740 // Reset the input to correspond to the selection (or to be empty,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8741 // when not typing and nothing is selected)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8742 reset: function(typing) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8743 if (this.contextMenuPending) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8744 var minimal, selected, cm = this.cm, doc = cm.doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8745 if (cm.somethingSelected()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8746 this.prevInput = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8747 var range$$1 = doc.sel.primary()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8748 minimal = hasCopyEvent &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8749 (range$$1.to().line - range$$1.from().line > 100 || (selected = cm.getSelection()).length > 1000)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8750 var content = minimal ? "-" : selected || cm.getSelection()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8751 this.textarea.value = content
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8752 if (cm.state.focused) { selectInput(this.textarea) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8753 if (ie && ie_version >= 9) { this.hasSelection = content }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8754 } else if (!typing) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8755 this.prevInput = this.textarea.value = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8756 if (ie && ie_version >= 9) { this.hasSelection = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8757 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8758 this.inaccurateSelection = minimal
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8759 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8760
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8761 getField: function() { return this.textarea },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8762
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8763 supportsTouch: function() { return false },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8764
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8765 focus: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8766 if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8767 try { this.textarea.focus() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8768 catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8769 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8770 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8771
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8772 blur: function() { this.textarea.blur() },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8773
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8774 resetPosition: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8775 this.wrapper.style.top = this.wrapper.style.left = 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8776 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8777
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8778 receivedFocus: function() { this.slowPoll() },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8779
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8780 // Poll for input changes, using the normal rate of polling. This
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8781 // runs as long as the editor is focused.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8782 slowPoll: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8783 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8784
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8785 if (this.pollingFast) { return }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8786 this.polling.set(this.cm.options.pollInterval, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8787 this$1.poll()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8788 if (this$1.cm.state.focused) { this$1.slowPoll() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8789 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8790 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8791
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8792 // When an event has just come in that is likely to add or change
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8793 // something in the input textarea, we poll faster, to ensure that
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8794 // the change appears on the screen quickly.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8795 fastPoll: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8796 var missed = false, input = this
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8797 input.pollingFast = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8798 function p() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8799 var changed = input.poll()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8800 if (!changed && !missed) {missed = true; input.polling.set(60, p)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8801 else {input.pollingFast = false; input.slowPoll()}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8802 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8803 input.polling.set(20, p)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8804 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8805
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8806 // Read input from the textarea, and update the document to match.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8807 // When something is selected, it is present in the textarea, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8808 // selected (unless it is huge, in which case a placeholder is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8809 // used). When nothing is selected, the cursor sits after previously
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8810 // seen text (can be empty), which is stored in prevInput (we must
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8811 // not reset the textarea when typing, because that breaks IME).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8812 poll: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8813 var this$1 = this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8814
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8815 var cm = this.cm, input = this.textarea, prevInput = this.prevInput
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8816 // Since this is called a *lot*, try to bail out as cheaply as
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8817 // possible when it is clear that nothing happened. hasSelection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8818 // will be the case when there is a lot of text in the textarea,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8819 // in which case reading its value would be expensive.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8820 if (this.contextMenuPending || !cm.state.focused ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8821 (hasSelection(input) && !prevInput && !this.composing) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8822 cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8823 { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8824
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8825 var text = input.value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8826 // If nothing changed, bail.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8827 if (text == prevInput && !cm.somethingSelected()) { return false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8828 // Work around nonsensical selection resetting in IE9/10, and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8829 // inexplicable appearance of private area unicode characters on
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8830 // some key combos in Mac (#2689).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8831 if (ie && ie_version >= 9 && this.hasSelection === text ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8832 mac && /[\uf700-\uf7ff]/.test(text)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8833 cm.display.input.reset()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8834 return false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8835 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8836
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8837 if (cm.doc.sel == cm.display.selForContextMenu) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8838 var first = text.charCodeAt(0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8839 if (first == 0x200b && !prevInput) { prevInput = "\u200b" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8840 if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8841 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8842 // Find the part of the input that is actually new
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8843 var same = 0, l = Math.min(prevInput.length, text.length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8844 while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8845
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8846 runInOp(cm, function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8847 applyTextInput(cm, text.slice(same), prevInput.length - same,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8848 null, this$1.composing ? "*compose" : null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8849
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8850 // Don't leave long text in the textarea, since it makes further polling slow
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8851 if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = "" }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8852 else { this$1.prevInput = text }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8853
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8854 if (this$1.composing) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8855 this$1.composing.range.clear()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8856 this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8857 {className: "CodeMirror-composing"})
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8858 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8859 })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8860 return true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8861 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8862
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8863 ensurePolled: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8864 if (this.pollingFast && this.poll()) { this.pollingFast = false }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8865 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8866
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8867 onKeyPress: function() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8868 if (ie && ie_version >= 9) { this.hasSelection = null }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8869 this.fastPoll()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8870 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8871
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8872 onContextMenu: function(e) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8873 var input = this, cm = input.cm, display = cm.display, te = input.textarea
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8874 var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8875 if (!pos || presto) { return } // Opera is difficult.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8876
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8877 // Reset the current text selection only if the click is done outside of the selection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8878 // and 'resetSelectionOnContextMenu' option is true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8879 var reset = cm.options.resetSelectionOnContextMenu
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8880 if (reset && cm.doc.sel.contains(pos) == -1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8881 { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8882
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8883 var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8884 input.wrapper.style.cssText = "position: absolute"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8885 var wrapperBox = input.wrapper.getBoundingClientRect()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8886 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);"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8887 var oldScrollY
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8888 if (webkit) { oldScrollY = window.scrollY } // Work around Chrome issue (#2712)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8889 display.input.focus()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8890 if (webkit) { window.scrollTo(null, oldScrollY) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8891 display.input.reset()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8892 // Adds "Select all" to context menu in FF
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8893 if (!cm.somethingSelected()) { te.value = input.prevInput = " " }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8894 input.contextMenuPending = true
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8895 display.selForContextMenu = cm.doc.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8896 clearTimeout(display.detectingSelectAll)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8897
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8898 // Select-all will be greyed out if there's nothing to select, so
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8899 // this adds a zero-width space so that we can later check whether
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8900 // it got selected.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8901 function prepareSelectAllHack() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8902 if (te.selectionStart != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8903 var selected = cm.somethingSelected()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8904 var extval = "\u200b" + (selected ? te.value : "")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8905 te.value = "\u21da" // Used to catch context-menu undo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8906 te.value = extval
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8907 input.prevInput = selected ? "" : "\u200b"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8908 te.selectionStart = 1; te.selectionEnd = extval.length
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8909 // Re-set this, in case some other handler touched the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8910 // selection in the meantime.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8911 display.selForContextMenu = cm.doc.sel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8912 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8913 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8914 function rehide() {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8915 input.contextMenuPending = false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8916 input.wrapper.style.cssText = oldWrapperCSS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8917 te.style.cssText = oldCSS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8918 if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8919
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8920 // Try to detect the user choosing select-all
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8921 if (te.selectionStart != null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8922 if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8923 var i = 0, poll = function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8924 if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8925 te.selectionEnd > 0 && input.prevInput == "\u200b")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8926 { operation(cm, selectAll)(cm) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8927 else if (i++ < 10) { display.detectingSelectAll = setTimeout(poll, 500) }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8928 else { display.input.reset() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8929 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8930 display.detectingSelectAll = setTimeout(poll, 200)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8931 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8932 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8933
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8934 if (ie && ie_version >= 9) { prepareSelectAllHack() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8935 if (captureRightClick) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8936 e_stop(e)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8937 var mouseup = function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8938 off(window, "mouseup", mouseup)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8939 setTimeout(rehide, 20)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8940 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8941 on(window, "mouseup", mouseup)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8942 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8943 setTimeout(rehide, 50)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8944 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8945 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8946
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8947 readOnlyChanged: function(val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8948 if (!val) { this.reset() }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8949 },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8950
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8951 setUneditable: nothing,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8952
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8953 needsContentAttribute: false
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8954 }, TextareaInput.prototype)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8955
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8956 function fromTextArea(textarea, options) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8957 options = options ? copyObj(options) : {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8958 options.value = textarea.value
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8959 if (!options.tabindex && textarea.tabIndex)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8960 { options.tabindex = textarea.tabIndex }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8961 if (!options.placeholder && textarea.placeholder)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8962 { options.placeholder = textarea.placeholder }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8963 // Set autofocus to true if this textarea is focused, or if it has
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8964 // autofocus and no other element is focused.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8965 if (options.autofocus == null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8966 var hasFocus = activeElt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8967 options.autofocus = hasFocus == textarea ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8968 textarea.getAttribute("autofocus") != null && hasFocus == document.body
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8969 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8970
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8971 function save() {textarea.value = cm.getValue()}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8972
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8973 var realSubmit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8974 if (textarea.form) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8975 on(textarea.form, "submit", save)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8976 // Deplorable hack to make the submit method do the right thing.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8977 if (!options.leaveSubmitMethodAlone) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8978 var form = textarea.form
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8979 realSubmit = form.submit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8980 try {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8981 var wrappedSubmit = form.submit = function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8982 save()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8983 form.submit = realSubmit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8984 form.submit()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8985 form.submit = wrappedSubmit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8986 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8987 } catch(e) {}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8988 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8989 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8990
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8991 options.finishInit = function (cm) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8992 cm.save = save
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8993 cm.getTextArea = function () { return textarea; }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8994 cm.toTextArea = function () {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8995 cm.toTextArea = isNaN // Prevent this from being ran twice
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8996 save()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8997 textarea.parentNode.removeChild(cm.getWrapperElement())
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8998 textarea.style.display = ""
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8999 if (textarea.form) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9000 off(textarea.form, "submit", save)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9001 if (typeof textarea.form.submit == "function")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9002 { textarea.form.submit = realSubmit }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9003 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9004 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9005 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9006
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9007 textarea.style.display = "none"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9008 var cm = CodeMirror$1(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9009 options)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9010 return cm
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9011 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9012
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9013 function addLegacyProps(CodeMirror) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9014 CodeMirror.off = off
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9015 CodeMirror.on = on
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9016 CodeMirror.wheelEventPixels = wheelEventPixels
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9017 CodeMirror.Doc = Doc
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9018 CodeMirror.splitLines = splitLinesAuto
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9019 CodeMirror.countColumn = countColumn
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9020 CodeMirror.findColumn = findColumn
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9021 CodeMirror.isWordChar = isWordCharBasic
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9022 CodeMirror.Pass = Pass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9023 CodeMirror.signal = signal
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9024 CodeMirror.Line = Line
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9025 CodeMirror.changeEnd = changeEnd
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9026 CodeMirror.scrollbarModel = scrollbarModel
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9027 CodeMirror.Pos = Pos
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9028 CodeMirror.cmpPos = cmp
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9029 CodeMirror.modes = modes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9030 CodeMirror.mimeModes = mimeModes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9031 CodeMirror.resolveMode = resolveMode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9032 CodeMirror.getMode = getMode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9033 CodeMirror.modeExtensions = modeExtensions
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9034 CodeMirror.extendMode = extendMode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9035 CodeMirror.copyState = copyState
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9036 CodeMirror.startState = startState
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9037 CodeMirror.innerMode = innerMode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9038 CodeMirror.commands = commands
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9039 CodeMirror.keyMap = keyMap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9040 CodeMirror.keyName = keyName
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9041 CodeMirror.isModifierKey = isModifierKey
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9042 CodeMirror.lookupKey = lookupKey
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9043 CodeMirror.normalizeKeyMap = normalizeKeyMap
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9044 CodeMirror.StringStream = StringStream
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9045 CodeMirror.SharedTextMarker = SharedTextMarker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9046 CodeMirror.TextMarker = TextMarker
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9047 CodeMirror.LineWidget = LineWidget
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9048 CodeMirror.e_preventDefault = e_preventDefault
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9049 CodeMirror.e_stopPropagation = e_stopPropagation
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9050 CodeMirror.e_stop = e_stop
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9051 CodeMirror.addClass = addClass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9052 CodeMirror.contains = contains
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9053 CodeMirror.rmClass = rmClass
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9054 CodeMirror.keyNames = keyNames
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9055 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9056
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9057 // EDITOR CONSTRUCTOR
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9058
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9059 defineOptions(CodeMirror$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9060
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9061 addEditorMethods(CodeMirror$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9062
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9063 // Set up methods on CodeMirror's prototype to redirect to the editor's document.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9064 var dontDelegate = "iter insert remove copy getEditor constructor".split(" ")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9065 for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9066 { CodeMirror$1.prototype[prop] = (function(method) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9067 return function() {return method.apply(this.doc, arguments)}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9068 })(Doc.prototype[prop]) } }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9069
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9070 eventMixin(Doc)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9071
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9072 // INPUT HANDLING
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9073
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9074 CodeMirror$1.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9075
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9076 // MODE DEFINITION AND QUERYING
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9077
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9078 // Extra arguments are stored as the mode's dependencies, which is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9079 // used by (legacy) mechanisms like loadmode.js to automatically
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9080 // load a mode. (Preferred mechanism is the require/define calls.)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9081 CodeMirror$1.defineMode = function(name/*, mode, …*/) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9082 if (!CodeMirror$1.defaults.mode && name != "null") { CodeMirror$1.defaults.mode = name }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9083 defineMode.apply(this, arguments)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9084 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9085
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9086 CodeMirror$1.defineMIME = defineMIME
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9087
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9088 // Minimal default mode.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9089 CodeMirror$1.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); })
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9090 CodeMirror$1.defineMIME("text/plain", "null")
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9091
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9092 // EXTENSIONS
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9093
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9094 CodeMirror$1.defineExtension = function (name, func) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9095 CodeMirror$1.prototype[name] = func
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9096 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9097 CodeMirror$1.defineDocExtension = function (name, func) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9098 Doc.prototype[name] = func
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9099 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9100
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9101 CodeMirror$1.fromTextArea = fromTextArea
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9102
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9103 addLegacyProps(CodeMirror$1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9104
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9105 CodeMirror$1.version = "5.21.0"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9106
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9107 return CodeMirror$1;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9108
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9109 })));