swagr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (359) hide show
  1. data/bin/swagr +15 -0
  2. data/examples/examples01/app.rb +6 -2
  3. data/examples/examples01/coffee/data_port.coffee +2 -0
  4. data/examples/examples01/static/css/codemirror.css +1247 -0
  5. data/examples/examples01/static/js/codemirror-compressed-3-0.js +5 -0
  6. data/examples/examples01/static/js/codemirror/keymap/emacs.js +30 -0
  7. data/examples/examples01/static/js/codemirror/keymap/vim.js +2298 -0
  8. data/examples/examples01/static/js/codemirror/lib/codemirror.css +239 -0
  9. data/examples/examples01/static/js/codemirror/lib/codemirror.js +4553 -0
  10. data/examples/examples01/static/js/codemirror/lib/util/closetag.js +85 -0
  11. data/examples/examples01/static/js/codemirror/lib/util/colorize.js +29 -0
  12. data/examples/examples01/static/js/codemirror/lib/util/continuecomment.js +36 -0
  13. data/examples/examples01/static/js/codemirror/lib/util/continuelist.js +28 -0
  14. data/examples/examples01/static/js/codemirror/lib/util/dialog.css +32 -0
  15. data/examples/examples01/static/js/codemirror/lib/util/dialog.js +75 -0
  16. data/examples/examples01/static/js/codemirror/lib/util/foldcode.js +182 -0
  17. data/examples/examples01/static/js/codemirror/lib/util/formatting.js +108 -0
  18. data/examples/examples01/static/js/codemirror/lib/util/javascript-hint.js +137 -0
  19. data/examples/examples01/static/js/codemirror/lib/util/loadmode.js +51 -0
  20. data/examples/examples01/static/js/codemirror/lib/util/match-highlighter.js +46 -0
  21. data/examples/examples01/static/js/codemirror/lib/util/matchbrackets.js +63 -0
  22. data/examples/examples01/static/js/codemirror/lib/util/multiplex.js +95 -0
  23. data/examples/examples01/static/js/codemirror/lib/util/overlay.js +59 -0
  24. data/examples/examples01/static/js/codemirror/lib/util/pig-hint.js +117 -0
  25. data/examples/examples01/static/js/codemirror/lib/util/runmode-standalone.js +90 -0
  26. data/examples/examples01/static/js/codemirror/lib/util/runmode.js +52 -0
  27. data/examples/examples01/static/js/codemirror/lib/util/search.js +119 -0
  28. data/examples/examples01/static/js/codemirror/lib/util/searchcursor.js +119 -0
  29. data/examples/examples01/static/js/codemirror/lib/util/simple-hint.css +16 -0
  30. data/examples/examples01/static/js/codemirror/lib/util/simple-hint.js +102 -0
  31. data/examples/examples01/static/js/codemirror/lib/util/xml-hint.js +131 -0
  32. data/examples/examples01/static/js/codemirror/mode/clike/clike.js +300 -0
  33. data/examples/examples01/static/js/codemirror/mode/clike/index.html +103 -0
  34. data/examples/examples01/static/js/codemirror/mode/clike/scala.html +767 -0
  35. data/examples/examples01/static/js/codemirror/mode/clojure/clojure.js +206 -0
  36. data/examples/examples01/static/js/codemirror/mode/clojure/index.html +67 -0
  37. data/examples/examples01/static/js/codemirror/mode/coffeescript/LICENSE +22 -0
  38. data/examples/examples01/static/js/codemirror/mode/coffeescript/coffeescript.js +346 -0
  39. data/examples/examples01/static/js/codemirror/mode/coffeescript/index.html +728 -0
  40. data/examples/examples01/static/js/codemirror/mode/commonlisp/commonlisp.js +101 -0
  41. data/examples/examples01/static/js/codemirror/mode/commonlisp/index.html +165 -0
  42. data/examples/examples01/static/js/codemirror/mode/css/css.js +465 -0
  43. data/examples/examples01/static/js/codemirror/mode/css/index.html +58 -0
  44. data/examples/examples01/static/js/codemirror/mode/css/test.js +501 -0
  45. data/examples/examples01/static/js/codemirror/mode/diff/diff.js +32 -0
  46. data/examples/examples01/static/js/codemirror/mode/diff/index.html +105 -0
  47. data/examples/examples01/static/js/codemirror/mode/ecl/ecl.js +192 -0
  48. data/examples/examples01/static/js/codemirror/mode/ecl/index.html +39 -0
  49. data/examples/examples01/static/js/codemirror/mode/erlang/erlang.js +463 -0
  50. data/examples/examples01/static/js/codemirror/mode/erlang/index.html +64 -0
  51. data/examples/examples01/static/js/codemirror/mode/gfm/gfm.js +94 -0
  52. data/examples/examples01/static/js/codemirror/mode/gfm/index.html +70 -0
  53. data/examples/examples01/static/js/codemirror/mode/gfm/test.js +225 -0
  54. data/examples/examples01/static/js/codemirror/mode/go/go.js +165 -0
  55. data/examples/examples01/static/js/codemirror/mode/go/index.html +74 -0
  56. data/examples/examples01/static/js/codemirror/mode/groovy/groovy.js +210 -0
  57. data/examples/examples01/static/js/codemirror/mode/groovy/index.html +73 -0
  58. data/examples/examples01/static/js/codemirror/mode/haskell/haskell.js +242 -0
  59. data/examples/examples01/static/js/codemirror/mode/haskell/index.html +62 -0
  60. data/examples/examples01/static/js/codemirror/mode/haxe/haxe.js +429 -0
  61. data/examples/examples01/static/js/codemirror/mode/haxe/index.html +90 -0
  62. data/examples/examples01/static/js/codemirror/mode/htmlembedded/htmlembedded.js +73 -0
  63. data/examples/examples01/static/js/codemirror/mode/htmlembedded/index.html +49 -0
  64. data/examples/examples01/static/js/codemirror/mode/htmlmixed/htmlmixed.js +84 -0
  65. data/examples/examples01/static/js/codemirror/mode/htmlmixed/index.html +52 -0
  66. data/examples/examples01/static/js/codemirror/mode/http/http.js +98 -0
  67. data/examples/examples01/static/js/codemirror/mode/http/index.html +32 -0
  68. data/examples/examples01/static/js/codemirror/mode/javascript/index.html +88 -0
  69. data/examples/examples01/static/js/codemirror/mode/javascript/javascript.js +411 -0
  70. data/examples/examples01/static/js/codemirror/mode/javascript/typescript.html +48 -0
  71. data/examples/examples01/static/js/codemirror/mode/jinja2/index.html +38 -0
  72. data/examples/examples01/static/js/codemirror/mode/jinja2/jinja2.js +42 -0
  73. data/examples/examples01/static/js/codemirror/mode/less/index.html +741 -0
  74. data/examples/examples01/static/js/codemirror/mode/less/less.js +266 -0
  75. data/examples/examples01/static/js/codemirror/mode/lua/index.html +74 -0
  76. data/examples/examples01/static/js/codemirror/mode/lua/lua.js +140 -0
  77. data/examples/examples01/static/js/codemirror/mode/markdown/index.html +344 -0
  78. data/examples/examples01/static/js/codemirror/mode/markdown/markdown.js +474 -0
  79. data/examples/examples01/static/js/codemirror/mode/markdown/test.js +1266 -0
  80. data/examples/examples01/static/js/codemirror/mode/mysql/index.html +41 -0
  81. data/examples/examples01/static/js/codemirror/mode/mysql/mysql.js +203 -0
  82. data/examples/examples01/static/js/codemirror/mode/ntriples/index.html +33 -0
  83. data/examples/examples01/static/js/codemirror/mode/ntriples/ntriples.js +170 -0
  84. data/examples/examples01/static/js/codemirror/mode/ocaml/index.html +131 -0
  85. data/examples/examples01/static/js/codemirror/mode/ocaml/ocaml.js +113 -0
  86. data/examples/examples01/static/js/codemirror/mode/pascal/LICENSE +7 -0
  87. data/examples/examples01/static/js/codemirror/mode/pascal/index.html +48 -0
  88. data/examples/examples01/static/js/codemirror/mode/pascal/pascal.js +94 -0
  89. data/examples/examples01/static/js/codemirror/mode/perl/LICENSE +19 -0
  90. data/examples/examples01/static/js/codemirror/mode/perl/index.html +62 -0
  91. data/examples/examples01/static/js/codemirror/mode/perl/perl.js +816 -0
  92. data/examples/examples01/static/js/codemirror/mode/php/index.html +51 -0
  93. data/examples/examples01/static/js/codemirror/mode/php/php.js +129 -0
  94. data/examples/examples01/static/js/codemirror/mode/pig/index.html +42 -0
  95. data/examples/examples01/static/js/codemirror/mode/pig/pig.js +171 -0
  96. data/examples/examples01/static/js/codemirror/mode/plsql/index.html +62 -0
  97. data/examples/examples01/static/js/codemirror/mode/plsql/plsql.js +216 -0
  98. data/examples/examples01/static/js/codemirror/mode/properties/index.html +41 -0
  99. data/examples/examples01/static/js/codemirror/mode/properties/properties.js +63 -0
  100. data/examples/examples01/static/js/codemirror/mode/python/LICENSE.txt +21 -0
  101. data/examples/examples01/static/js/codemirror/mode/python/index.html +124 -0
  102. data/examples/examples01/static/js/codemirror/mode/python/python.js +340 -0
  103. data/examples/examples01/static/js/codemirror/mode/r/LICENSE +24 -0
  104. data/examples/examples01/static/js/codemirror/mode/r/index.html +74 -0
  105. data/examples/examples01/static/js/codemirror/mode/r/r.js +141 -0
  106. data/examples/examples01/static/js/codemirror/mode/rpm/changes/changes.js +19 -0
  107. data/examples/examples01/static/js/codemirror/mode/rpm/changes/index.html +53 -0
  108. data/examples/examples01/static/js/codemirror/mode/rpm/spec/index.html +99 -0
  109. data/examples/examples01/static/js/codemirror/mode/rpm/spec/spec.css +5 -0
  110. data/examples/examples01/static/js/codemirror/mode/rpm/spec/spec.js +66 -0
  111. data/examples/examples01/static/js/codemirror/mode/rst/index.html +526 -0
  112. data/examples/examples01/static/js/codemirror/mode/rst/rst.js +314 -0
  113. data/examples/examples01/static/js/codemirror/mode/ruby/LICENSE +24 -0
  114. data/examples/examples01/static/js/codemirror/mode/ruby/index.html +173 -0
  115. data/examples/examples01/static/js/codemirror/mode/ruby/ruby.js +195 -0
  116. data/examples/examples01/static/js/codemirror/mode/rust/index.html +48 -0
  117. data/examples/examples01/static/js/codemirror/mode/rust/rust.js +432 -0
  118. data/examples/examples01/static/js/codemirror/mode/scheme/index.html +65 -0
  119. data/examples/examples01/static/js/codemirror/mode/scheme/scheme.js +230 -0
  120. data/examples/examples01/static/js/codemirror/mode/shell/index.html +51 -0
  121. data/examples/examples01/static/js/codemirror/mode/shell/shell.js +118 -0
  122. data/examples/examples01/static/js/codemirror/mode/sieve/LICENSE +23 -0
  123. data/examples/examples01/static/js/codemirror/mode/sieve/index.html +81 -0
  124. data/examples/examples01/static/js/codemirror/mode/sieve/sieve.js +156 -0
  125. data/examples/examples01/static/js/codemirror/mode/smalltalk/index.html +57 -0
  126. data/examples/examples01/static/js/codemirror/mode/smalltalk/smalltalk.js +139 -0
  127. data/examples/examples01/static/js/codemirror/mode/smarty/index.html +83 -0
  128. data/examples/examples01/static/js/codemirror/mode/smarty/smarty.js +148 -0
  129. data/examples/examples01/static/js/codemirror/mode/sparql/index.html +42 -0
  130. data/examples/examples01/static/js/codemirror/mode/sparql/sparql.js +143 -0
  131. data/examples/examples01/static/js/codemirror/mode/stex/index.html +98 -0
  132. data/examples/examples01/static/js/codemirror/mode/stex/stex.js +175 -0
  133. data/examples/examples01/static/js/codemirror/mode/stex/test.js +343 -0
  134. data/examples/examples01/static/js/codemirror/mode/tiddlywiki/index.html +142 -0
  135. data/examples/examples01/static/js/codemirror/mode/tiddlywiki/tiddlywiki.css +14 -0
  136. data/examples/examples01/static/js/codemirror/mode/tiddlywiki/tiddlywiki.js +353 -0
  137. data/examples/examples01/static/js/codemirror/mode/tiki/index.html +81 -0
  138. data/examples/examples01/static/js/codemirror/mode/tiki/tiki.css +26 -0
  139. data/examples/examples01/static/js/codemirror/mode/tiki/tiki.js +309 -0
  140. data/examples/examples01/static/js/codemirror/mode/vb/LICENSE.txt +21 -0
  141. data/examples/examples01/static/js/codemirror/mode/vb/index.html +88 -0
  142. data/examples/examples01/static/js/codemirror/mode/vb/vb.js +260 -0
  143. data/examples/examples01/static/js/codemirror/mode/vbscript/index.html +42 -0
  144. data/examples/examples01/static/js/codemirror/mode/vbscript/vbscript.js +26 -0
  145. data/examples/examples01/static/js/codemirror/mode/velocity/index.html +103 -0
  146. data/examples/examples01/static/js/codemirror/mode/velocity/velocity.js +144 -0
  147. data/examples/examples01/static/js/codemirror/mode/verilog/index.html +210 -0
  148. data/examples/examples01/static/js/codemirror/mode/verilog/verilog.js +182 -0
  149. data/examples/examples01/static/js/codemirror/mode/xml/index.html +45 -0
  150. data/examples/examples01/static/js/codemirror/mode/xml/xml.js +324 -0
  151. data/examples/examples01/static/js/codemirror/mode/xquery/LICENSE +20 -0
  152. data/examples/examples01/static/js/codemirror/mode/xquery/index.html +221 -0
  153. data/examples/examples01/static/js/codemirror/mode/xquery/test.js +77 -0
  154. data/examples/examples01/static/js/codemirror/mode/xquery/xquery.js +450 -0
  155. data/examples/examples01/static/js/codemirror/mode/yaml/index.html +68 -0
  156. data/examples/examples01/static/js/codemirror/mode/yaml/yaml.js +95 -0
  157. data/examples/examples01/static/js/codemirror/mode/z80/index.html +39 -0
  158. data/examples/examples01/static/js/codemirror/mode/z80/z80.js +113 -0
  159. data/examples/examples01/static/js/codemirror/theme/ambiance-mobile.css +6 -0
  160. data/examples/examples01/static/js/codemirror/theme/ambiance.css +76 -0
  161. data/examples/examples01/static/js/codemirror/theme/blackboard.css +25 -0
  162. data/examples/examples01/static/js/codemirror/theme/cobalt.css +18 -0
  163. data/examples/examples01/static/js/codemirror/theme/eclipse.css +25 -0
  164. data/examples/examples01/static/js/codemirror/theme/elegant.css +10 -0
  165. data/examples/examples01/static/js/codemirror/theme/erlang-dark.css +21 -0
  166. data/examples/examples01/static/js/codemirror/theme/lesser-dark.css +44 -0
  167. data/examples/examples01/static/js/codemirror/theme/monokai.css +28 -0
  168. data/examples/examples01/static/js/codemirror/theme/neat.css +9 -0
  169. data/examples/examples01/static/js/codemirror/theme/night.css +21 -0
  170. data/examples/examples01/static/js/codemirror/theme/rubyblue.css +21 -0
  171. data/examples/examples01/static/js/codemirror/theme/solarized.css +207 -0
  172. data/examples/examples01/static/js/codemirror/theme/twilight.css +26 -0
  173. data/examples/examples01/static/js/codemirror/theme/vibrant-ink.css +27 -0
  174. data/examples/examples01/static/js/codemirror/theme/xq-dark.css +46 -0
  175. data/examples/examples01/static/js/d3.v3.min.js +2 -2
  176. data/examples/examples01/static/test/cm.html +33 -0
  177. data/examples/examples01/views/about.slim +15 -0
  178. data/examples/examples01/views/index.slim +1 -1
  179. data/examples/examples01/views/layout.slim +1 -0
  180. data/examples/examples01/views/layout_cm.slim +17 -0
  181. data/examples/examples01/views/navbar.slim +4 -4
  182. data/lib/swagr/version.rb +1 -1
  183. data/templates/app.rb +4 -0
  184. data/templates/static/js/codemirror/keymap/emacs.js +30 -0
  185. data/templates/static/js/codemirror/keymap/vim.js +2298 -0
  186. data/templates/static/js/codemirror/lib/codemirror.css +239 -0
  187. data/templates/static/js/codemirror/lib/codemirror.js +4553 -0
  188. data/templates/static/js/codemirror/lib/util/closetag.js +85 -0
  189. data/templates/static/js/codemirror/lib/util/colorize.js +29 -0
  190. data/templates/static/js/codemirror/lib/util/continuecomment.js +36 -0
  191. data/templates/static/js/codemirror/lib/util/continuelist.js +28 -0
  192. data/templates/static/js/codemirror/lib/util/dialog.css +32 -0
  193. data/templates/static/js/codemirror/lib/util/dialog.js +75 -0
  194. data/templates/static/js/codemirror/lib/util/foldcode.js +182 -0
  195. data/templates/static/js/codemirror/lib/util/formatting.js +108 -0
  196. data/templates/static/js/codemirror/lib/util/javascript-hint.js +137 -0
  197. data/templates/static/js/codemirror/lib/util/loadmode.js +51 -0
  198. data/templates/static/js/codemirror/lib/util/match-highlighter.js +46 -0
  199. data/templates/static/js/codemirror/lib/util/matchbrackets.js +63 -0
  200. data/templates/static/js/codemirror/lib/util/multiplex.js +95 -0
  201. data/templates/static/js/codemirror/lib/util/overlay.js +59 -0
  202. data/templates/static/js/codemirror/lib/util/pig-hint.js +117 -0
  203. data/templates/static/js/codemirror/lib/util/runmode-standalone.js +90 -0
  204. data/templates/static/js/codemirror/lib/util/runmode.js +52 -0
  205. data/templates/static/js/codemirror/lib/util/search.js +119 -0
  206. data/templates/static/js/codemirror/lib/util/searchcursor.js +119 -0
  207. data/templates/static/js/codemirror/lib/util/simple-hint.css +16 -0
  208. data/templates/static/js/codemirror/lib/util/simple-hint.js +102 -0
  209. data/templates/static/js/codemirror/lib/util/xml-hint.js +131 -0
  210. data/templates/static/js/codemirror/mode/clike/clike.js +300 -0
  211. data/templates/static/js/codemirror/mode/clike/index.html +103 -0
  212. data/templates/static/js/codemirror/mode/clike/scala.html +767 -0
  213. data/templates/static/js/codemirror/mode/clojure/clojure.js +206 -0
  214. data/templates/static/js/codemirror/mode/clojure/index.html +67 -0
  215. data/templates/static/js/codemirror/mode/coffeescript/LICENSE +22 -0
  216. data/templates/static/js/codemirror/mode/coffeescript/coffeescript.js +346 -0
  217. data/templates/static/js/codemirror/mode/coffeescript/index.html +728 -0
  218. data/templates/static/js/codemirror/mode/commonlisp/commonlisp.js +101 -0
  219. data/templates/static/js/codemirror/mode/commonlisp/index.html +165 -0
  220. data/templates/static/js/codemirror/mode/css/css.js +465 -0
  221. data/templates/static/js/codemirror/mode/css/index.html +58 -0
  222. data/templates/static/js/codemirror/mode/css/test.js +501 -0
  223. data/templates/static/js/codemirror/mode/diff/diff.js +32 -0
  224. data/templates/static/js/codemirror/mode/diff/index.html +105 -0
  225. data/templates/static/js/codemirror/mode/ecl/ecl.js +192 -0
  226. data/templates/static/js/codemirror/mode/ecl/index.html +39 -0
  227. data/templates/static/js/codemirror/mode/erlang/erlang.js +463 -0
  228. data/templates/static/js/codemirror/mode/erlang/index.html +64 -0
  229. data/templates/static/js/codemirror/mode/gfm/gfm.js +94 -0
  230. data/templates/static/js/codemirror/mode/gfm/index.html +70 -0
  231. data/templates/static/js/codemirror/mode/gfm/test.js +225 -0
  232. data/templates/static/js/codemirror/mode/go/go.js +165 -0
  233. data/templates/static/js/codemirror/mode/go/index.html +74 -0
  234. data/templates/static/js/codemirror/mode/groovy/groovy.js +210 -0
  235. data/templates/static/js/codemirror/mode/groovy/index.html +73 -0
  236. data/templates/static/js/codemirror/mode/haskell/haskell.js +242 -0
  237. data/templates/static/js/codemirror/mode/haskell/index.html +62 -0
  238. data/templates/static/js/codemirror/mode/haxe/haxe.js +429 -0
  239. data/templates/static/js/codemirror/mode/haxe/index.html +90 -0
  240. data/templates/static/js/codemirror/mode/htmlembedded/htmlembedded.js +73 -0
  241. data/templates/static/js/codemirror/mode/htmlembedded/index.html +49 -0
  242. data/templates/static/js/codemirror/mode/htmlmixed/htmlmixed.js +84 -0
  243. data/templates/static/js/codemirror/mode/htmlmixed/index.html +52 -0
  244. data/templates/static/js/codemirror/mode/http/http.js +98 -0
  245. data/templates/static/js/codemirror/mode/http/index.html +32 -0
  246. data/templates/static/js/codemirror/mode/javascript/index.html +88 -0
  247. data/templates/static/js/codemirror/mode/javascript/javascript.js +411 -0
  248. data/templates/static/js/codemirror/mode/javascript/typescript.html +48 -0
  249. data/templates/static/js/codemirror/mode/jinja2/index.html +38 -0
  250. data/templates/static/js/codemirror/mode/jinja2/jinja2.js +42 -0
  251. data/templates/static/js/codemirror/mode/less/index.html +741 -0
  252. data/templates/static/js/codemirror/mode/less/less.js +266 -0
  253. data/templates/static/js/codemirror/mode/lua/index.html +74 -0
  254. data/templates/static/js/codemirror/mode/lua/lua.js +140 -0
  255. data/templates/static/js/codemirror/mode/markdown/index.html +344 -0
  256. data/templates/static/js/codemirror/mode/markdown/markdown.js +474 -0
  257. data/templates/static/js/codemirror/mode/markdown/test.js +1266 -0
  258. data/templates/static/js/codemirror/mode/mysql/index.html +41 -0
  259. data/templates/static/js/codemirror/mode/mysql/mysql.js +203 -0
  260. data/templates/static/js/codemirror/mode/ntriples/index.html +33 -0
  261. data/templates/static/js/codemirror/mode/ntriples/ntriples.js +170 -0
  262. data/templates/static/js/codemirror/mode/ocaml/index.html +131 -0
  263. data/templates/static/js/codemirror/mode/ocaml/ocaml.js +113 -0
  264. data/templates/static/js/codemirror/mode/pascal/LICENSE +7 -0
  265. data/templates/static/js/codemirror/mode/pascal/index.html +48 -0
  266. data/templates/static/js/codemirror/mode/pascal/pascal.js +94 -0
  267. data/templates/static/js/codemirror/mode/perl/LICENSE +19 -0
  268. data/templates/static/js/codemirror/mode/perl/index.html +62 -0
  269. data/templates/static/js/codemirror/mode/perl/perl.js +816 -0
  270. data/templates/static/js/codemirror/mode/php/index.html +51 -0
  271. data/templates/static/js/codemirror/mode/php/php.js +129 -0
  272. data/templates/static/js/codemirror/mode/pig/index.html +42 -0
  273. data/templates/static/js/codemirror/mode/pig/pig.js +171 -0
  274. data/templates/static/js/codemirror/mode/plsql/index.html +62 -0
  275. data/templates/static/js/codemirror/mode/plsql/plsql.js +216 -0
  276. data/templates/static/js/codemirror/mode/properties/index.html +41 -0
  277. data/templates/static/js/codemirror/mode/properties/properties.js +63 -0
  278. data/templates/static/js/codemirror/mode/python/LICENSE.txt +21 -0
  279. data/templates/static/js/codemirror/mode/python/index.html +124 -0
  280. data/templates/static/js/codemirror/mode/python/python.js +340 -0
  281. data/templates/static/js/codemirror/mode/r/LICENSE +24 -0
  282. data/templates/static/js/codemirror/mode/r/index.html +74 -0
  283. data/templates/static/js/codemirror/mode/r/r.js +141 -0
  284. data/templates/static/js/codemirror/mode/rpm/changes/changes.js +19 -0
  285. data/templates/static/js/codemirror/mode/rpm/changes/index.html +53 -0
  286. data/templates/static/js/codemirror/mode/rpm/spec/index.html +99 -0
  287. data/templates/static/js/codemirror/mode/rpm/spec/spec.css +5 -0
  288. data/templates/static/js/codemirror/mode/rpm/spec/spec.js +66 -0
  289. data/templates/static/js/codemirror/mode/rst/index.html +526 -0
  290. data/templates/static/js/codemirror/mode/rst/rst.js +314 -0
  291. data/templates/static/js/codemirror/mode/ruby/LICENSE +24 -0
  292. data/templates/static/js/codemirror/mode/ruby/index.html +173 -0
  293. data/templates/static/js/codemirror/mode/ruby/ruby.js +195 -0
  294. data/templates/static/js/codemirror/mode/rust/index.html +48 -0
  295. data/templates/static/js/codemirror/mode/rust/rust.js +432 -0
  296. data/templates/static/js/codemirror/mode/scheme/index.html +65 -0
  297. data/templates/static/js/codemirror/mode/scheme/scheme.js +230 -0
  298. data/templates/static/js/codemirror/mode/shell/index.html +51 -0
  299. data/templates/static/js/codemirror/mode/shell/shell.js +118 -0
  300. data/templates/static/js/codemirror/mode/sieve/LICENSE +23 -0
  301. data/templates/static/js/codemirror/mode/sieve/index.html +81 -0
  302. data/templates/static/js/codemirror/mode/sieve/sieve.js +156 -0
  303. data/templates/static/js/codemirror/mode/smalltalk/index.html +57 -0
  304. data/templates/static/js/codemirror/mode/smalltalk/smalltalk.js +139 -0
  305. data/templates/static/js/codemirror/mode/smarty/index.html +83 -0
  306. data/templates/static/js/codemirror/mode/smarty/smarty.js +148 -0
  307. data/templates/static/js/codemirror/mode/sparql/index.html +42 -0
  308. data/templates/static/js/codemirror/mode/sparql/sparql.js +143 -0
  309. data/templates/static/js/codemirror/mode/stex/index.html +98 -0
  310. data/templates/static/js/codemirror/mode/stex/stex.js +175 -0
  311. data/templates/static/js/codemirror/mode/stex/test.js +343 -0
  312. data/templates/static/js/codemirror/mode/tiddlywiki/index.html +142 -0
  313. data/templates/static/js/codemirror/mode/tiddlywiki/tiddlywiki.css +14 -0
  314. data/templates/static/js/codemirror/mode/tiddlywiki/tiddlywiki.js +353 -0
  315. data/templates/static/js/codemirror/mode/tiki/index.html +81 -0
  316. data/templates/static/js/codemirror/mode/tiki/tiki.css +26 -0
  317. data/templates/static/js/codemirror/mode/tiki/tiki.js +309 -0
  318. data/templates/static/js/codemirror/mode/vb/LICENSE.txt +21 -0
  319. data/templates/static/js/codemirror/mode/vb/index.html +88 -0
  320. data/templates/static/js/codemirror/mode/vb/vb.js +260 -0
  321. data/templates/static/js/codemirror/mode/vbscript/index.html +42 -0
  322. data/templates/static/js/codemirror/mode/vbscript/vbscript.js +26 -0
  323. data/templates/static/js/codemirror/mode/velocity/index.html +103 -0
  324. data/templates/static/js/codemirror/mode/velocity/velocity.js +144 -0
  325. data/templates/static/js/codemirror/mode/verilog/index.html +210 -0
  326. data/templates/static/js/codemirror/mode/verilog/verilog.js +182 -0
  327. data/templates/static/js/codemirror/mode/xml/index.html +45 -0
  328. data/templates/static/js/codemirror/mode/xml/xml.js +324 -0
  329. data/templates/static/js/codemirror/mode/xquery/LICENSE +20 -0
  330. data/templates/static/js/codemirror/mode/xquery/index.html +221 -0
  331. data/templates/static/js/codemirror/mode/xquery/test.js +77 -0
  332. data/templates/static/js/codemirror/mode/xquery/xquery.js +450 -0
  333. data/templates/static/js/codemirror/mode/yaml/index.html +68 -0
  334. data/templates/static/js/codemirror/mode/yaml/yaml.js +95 -0
  335. data/templates/static/js/codemirror/mode/z80/index.html +39 -0
  336. data/templates/static/js/codemirror/mode/z80/z80.js +113 -0
  337. data/templates/static/js/codemirror/theme/ambiance-mobile.css +6 -0
  338. data/templates/static/js/codemirror/theme/ambiance.css +76 -0
  339. data/templates/static/js/codemirror/theme/blackboard.css +25 -0
  340. data/templates/static/js/codemirror/theme/cobalt.css +18 -0
  341. data/templates/static/js/codemirror/theme/eclipse.css +25 -0
  342. data/templates/static/js/codemirror/theme/elegant.css +10 -0
  343. data/templates/static/js/codemirror/theme/erlang-dark.css +21 -0
  344. data/templates/static/js/codemirror/theme/lesser-dark.css +44 -0
  345. data/templates/static/js/codemirror/theme/monokai.css +28 -0
  346. data/templates/static/js/codemirror/theme/neat.css +9 -0
  347. data/templates/static/js/codemirror/theme/night.css +21 -0
  348. data/templates/static/js/codemirror/theme/rubyblue.css +21 -0
  349. data/templates/static/js/codemirror/theme/solarized.css +207 -0
  350. data/templates/static/js/codemirror/theme/twilight.css +26 -0
  351. data/templates/static/js/codemirror/theme/vibrant-ink.css +27 -0
  352. data/templates/static/js/codemirror/theme/xq-dark.css +46 -0
  353. data/templates/static/js/d3.v3.min.js +2 -2
  354. data/templates/static/test/cm.html +33 -0
  355. data/templates/views/about.slim +15 -0
  356. data/templates/views/index.slim +1 -1
  357. data/templates/views/layout.slim +1 -0
  358. data/templates/views/navbar.slim +4 -4
  359. metadata +347 -2
@@ -0,0 +1,5 @@
1
+ window.CodeMirror=function(){"use strict";function s(a,c){if(!(this instanceof s))return new s(a,c);this.options=c=c||{};for(var d in vc)!c.hasOwnProperty(d)&&vc.hasOwnProperty(d)&&(c[d]=vc[d]);D(c);var e=this.display=t(a);e.wrapper.CodeMirror=this,A(this),c.autofocus&&!o&&sb(this),this.view=u(new qd([new pd([cd("",null,ib(e))])])),this.nextOpId=0,v(this),y(this),c.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),this.setValue(c.value||""),b&&setTimeout(Wd(rb,this,!0),20),this.view.history=xd(),ub(this);var f;try{f=document.activeElement==e.input}catch(g){}f||c.autofocus&&!o?setTimeout(Wd(Ub,this),20):Vb(this),mb(this,function(){for(var a in uc)uc.propertyIsEnumerable(a)&&uc[a](this,c[a],xc);for(var b=0;Bc.length>b;++b)Bc[b](this)})()}function t(a){var b={},d=b.input=_d("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none;");d.setAttribute("wrap","off"),d.setAttribute("autocorrect","off"),d.setAttribute("autocapitalize","off"),b.inputDiv=_d("div",[d],null,"overflow: hidden; position: relative; width: 3px; height: 0px;"),b.scrollbarH=_d("div",[_d("div",null,null,"height: 1px")],"CodeMirror-hscrollbar"),b.scrollbarV=_d("div",[_d("div",null,null,"width: 1px")],"CodeMirror-vscrollbar"),b.scrollbarFiller=_d("div",null,"CodeMirror-scrollbar-filler"),b.lineDiv=_d("div"),b.selectionDiv=_d("div",null,null,"position: relative; z-index: 1"),b.cursor=_d("pre","\u00a0","CodeMirror-cursor"),b.otherCursor=_d("pre","\u00a0","CodeMirror-cursor CodeMirror-secondarycursor"),b.measure=_d("div",null,"CodeMirror-measure"),b.lineSpace=_d("div",[b.measure,b.selectionDiv,b.lineDiv,b.cursor,b.otherCursor],null,"position: relative; outline: none"),b.mover=_d("div",[_d("div",[b.lineSpace],"CodeMirror-lines")],null,"position: relative"),b.sizer=_d("div",[b.mover],"CodeMirror-sizer"),b.heightForcer=_d("div","\u00a0",null,"position: absolute; height: "+Md+"px"),b.gutters=_d("div",null,"CodeMirror-gutters"),b.lineGutter=null;var f=_d("div",[b.sizer,b.heightForcer,b.gutters],null,"position: relative; min-height: 100%");return b.scroller=_d("div",[f],"CodeMirror-scroll"),b.scroller.setAttribute("tabIndex","-1"),b.wrapper=_d("div",[b.inputDiv,b.scrollbarH,b.scrollbarV,b.scrollbarFiller,b.scroller],"CodeMirror"),c&&(b.gutters.style.zIndex=-1,b.scroller.style.paddingRight=0),a.appendChild?a.appendChild(b.wrapper):a(b.wrapper),n&&(d.style.width="0px"),e||(b.scroller.draggable=!0),j?(b.inputDiv.style.height="1px",b.inputDiv.style.position="absolute"):c&&(b.scrollbarH.style.minWidth=b.scrollbarV.style.minWidth="18px"),b.viewOffset=b.showingFrom=b.showingTo=b.lastSizeC=0,b.lineNumWidth=b.lineNumInnerWidth=b.lineNumChars=null,b.prevInput="",b.alignWidgets=!1,b.pollingFast=!1,b.poll=new Od,b.draggingText=!1,b.cachedCharWidth=b.cachedTextHeight=null,b.measureLineCache=[],b.measureLineCachePos=0,b.inaccurateSelection=!1,b.pasteIncoming=!1,b}function u(a){var b={line:0,ch:0};return{doc:a,frontier:0,highlight:new Od,sel:{from:b,to:b,head:b,anchor:b,shift:!1,extend:!1},scrollTop:0,scrollLeft:0,overwrite:!1,focused:!1,maxLine:rd(a,0),maxLineLength:0,maxLineChanged:!1,suppressEdits:!1,goalColumn:null,cantEdit:!1,keyMaps:[]}}function v(a){var b=a.view.doc;a.view.mode=s.getMode(a.options,a.options.mode),b.iter(0,b.size,function(a){a.stateAfter=null}),a.view.frontier=0,U(a,100)}function w(a){var b=a.view.doc,c=ib(a.display);if(a.options.lineWrapping){a.display.wrapper.className+=" CodeMirror-wrap";var d=a.display.scroller.clientWidth/jb(a.display)-3;b.iter(0,b.size,function(a){if(0!=a.height){var b=Math.ceil(a.text.length/d)||1;1!=b&&sd(a,b*c)}}),a.display.sizer.style.minWidth=""}else a.display.wrapper.className=a.display.wrapper.className.replace(" CodeMirror-wrap",""),C(a.view),b.iter(0,b.size,function(a){0!=a.height&&sd(a,c)});nb(a,0,b.size),bb(a),setTimeout(function(){E(a.display,a.view.doc.height)},100)}function x(a){var b=Fc[a.options.keyMap].style;a.display.wrapper.className=a.display.wrapper.className.replace(/\s*cm-keymap-\S+/g,"")+(b?" cm-keymap-"+b:"")}function y(a){a.display.wrapper.className=a.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+a.options.theme.replace(/(^|\s)\s*/g," cm-s-"),bb(a)}function z(a){A(a),K(a,!0)}function A(a){var b=a.display.gutters,c=a.options.gutters;ae(b);for(var d=0;c.length>d;++d){var e=c[d],f=b.appendChild(_d("div",null,"CodeMirror-gutter "+e));"CodeMirror-linenumbers"==e&&(a.display.lineGutter=f,f.style.width=(a.display.lineNumWidth||1)+"px")}b.style.display=d?"":"none"}function B(a,b){if(0==b.height)return 0;for(var d,c=b.text.length,e=b;d=Uc(e);){var f=d.find();e=rd(a,f.from.line),c+=f.from.ch-f.to.ch}for(e=b;d=Vc(e);){var f=d.find();c-=e.text.length-f.from.ch,e=rd(a,f.to.line),c+=e.text.length-f.to.ch}return c}function C(a){a.maxLine=rd(a.doc,0),a.maxLineLength=B(a.doc,a.maxLine),a.maxLineChanged=!0,a.doc.iter(1,a.doc.size,function(b){var c=B(a.doc,b);c>a.maxLineLength&&(a.maxLineLength=c,a.maxLine=b)})}function D(a){for(var b=!1,c=0;a.gutters.length>c;++c)"CodeMirror-linenumbers"==a.gutters[c]&&(a.lineNumbers?b=!0:a.gutters.splice(c--,1));!b&&a.lineNumbers&&a.gutters.push("CodeMirror-linenumbers")}function E(a,b){var c=b+2*Y(a);a.sizer.style.minHeight=a.heightForcer.style.top=c+"px";var d=Math.max(c,a.scroller.scrollHeight),e=a.scroller.scrollWidth>a.scroller.clientWidth,f=d>a.scroller.clientHeight;f?(a.scrollbarV.style.display="block",a.scrollbarV.style.bottom=e?ge(a.measure)+"px":"0",a.scrollbarV.firstChild.style.height=d-a.scroller.clientHeight+a.scrollbarV.clientHeight+"px"):a.scrollbarV.style.display="",e?(a.scrollbarH.style.display="block",a.scrollbarH.style.right=f?ge(a.measure)+"px":"0",a.scrollbarH.firstChild.style.width=a.scroller.scrollWidth-a.scroller.clientWidth+a.scrollbarH.clientWidth+"px"):a.scrollbarH.style.display="",e&&f?(a.scrollbarFiller.style.display="block",a.scrollbarFiller.style.height=a.scrollbarFiller.style.width=ge(a.measure)+"px"):a.scrollbarFiller.style.display="",k&&0===ge(a.measure)&&(a.scrollbarV.style.minWidth=a.scrollbarH.style.minHeight=l?"18px":"12px")}function F(a,b,c){var d=a.scroller.scrollTop,e=a.wrapper.clientHeight;"number"==typeof c?d=c:c&&(d=c.top,e=c.bottom-c.top),d=Math.floor(d-Y(a));var f=Math.ceil(d+e);return{from:ud(b,d),to:ud(b,f)}}function G(a){var b=a.display;if(b.alignWidgets||b.gutters.firstChild){for(var c=J(b)-b.scroller.scrollLeft+a.view.scrollLeft,d=b.gutters.offsetWidth,e=c+"px",f=b.lineDiv.firstChild;f;f=f.nextSibling)if(f.alignable)for(var g=0,h=f.alignable;h.length>g;++g)h[g].style.left=e;b.gutters.style.left=c+d+"px"}}function H(a){if(!a.options.lineNumbers)return!1;var b=a.view.doc,c=I(a.options,b.size-1),d=a.display;if(c.length!=d.lineNumChars){var e=d.measure.appendChild(_d("div",[_d("div",c)],"CodeMirror-linenumber CodeMirror-gutter-elt")),f=e.firstChild.offsetWidth,g=e.offsetWidth-f;return d.lineGutter.style.width="",d.lineNumInnerWidth=Math.max(f,d.lineGutter.offsetWidth-g),d.lineNumWidth=d.lineNumInnerWidth+g,d.lineNumChars=d.lineNumInnerWidth?c.length:-1,d.lineGutter.style.width=d.lineNumWidth+"px",!0}return!1}function I(a,b){return a.lineNumberFormatter(b+a.firstLineNumber)+""}function J(a){return a.scroller.getBoundingClientRect().left-a.sizer.getBoundingClientRect().left}function K(a,b,c){var d=a.display.showingFrom,e=a.display.showingTo,f=L(a,b,c);return f&&(Kd(a,a,"update",a),(a.display.showingFrom!=d||a.display.showingTo!=e)&&Kd(a,a,"viewportChange",a,a.display.showingFrom,a.display.showingTo)),Q(a),E(a.display,a.view.doc.height),f}function L(a,b,d){var e=a.display,f=a.view.doc;if(!e.wrapper.clientWidth)return e.showingFrom=e.showingTo=e.viewOffset=0,void 0;var g=F(e,f,d);if(!(b!==!0&&0==b.length&&g.from>e.showingFrom&&g.to<e.showingTo)){if(b&&H(a)&&(b=!0),e.sizer.style.marginLeft=e.scrollbarH.style.left=e.gutters.offsetWidth+"px",b!==!0&&r)for(var h=0;b.length>h;++h)for(var j,i=b[h];j=Uc(rd(f,i.from));){var k=j.find().from.line;i.diff&&(i.diff-=i.from-k),i.from=k}var l=b===!0?0:1/0;if(a.options.lineNumbers&&b&&b!==!0)for(var h=0;b.length>h;++h)if(b[h].diff){l=b[h].from;break}var k=Math.max(g.from-a.options.viewportMargin,0),m=Math.min(f.size,g.to+a.options.viewportMargin);if(k>e.showingFrom&&20>k-e.showingFrom&&(k=e.showingFrom),e.showingTo>m&&20>e.showingTo-m&&(m=Math.min(f.size,e.showingTo)),r)for(k=td(Wc(f,rd(f,k)));f.size>m&&Xc(rd(f,m));)++m;for(var n=b===!0?[]:M([{from:e.showingFrom,to:e.showingTo}],b),o=0,h=0;n.length>h;++h){var p=n[h];k>p.from&&(p.from=k),p.to>m&&(p.to=m),p.from>=p.to?n.splice(h--,1):o+=p.to-p.from}if(o!=m-k||k!=e.showingFrom||m!=e.showingTo){n.sort(function(a,b){return a.from-b.from}),.7*(m-k)>o&&(e.lineDiv.style.display="none"),O(a,k,m,n,l),e.lineDiv.style.display="";var q=k!=e.showingFrom||m!=e.showingTo||e.lastSizeC!=e.wrapper.clientHeight;q&&(e.lastSizeC=e.wrapper.clientHeight),e.showingFrom=k,e.showingTo=m,U(a,100);for(var u,s=e.lineDiv.offsetTop,t=e.lineDiv.firstChild;t;t=t.nextSibling)if(t.lineObj){if(c){var v=t.offsetTop+t.offsetHeight;u=v-s,s=v}else{var w=t.getBoundingClientRect();u=w.bottom-w.top}var x=t.lineObj.height-u;2>u&&(u=ib(e)),(x>.001||-.001>x)&&sd(t.lineObj,u)}return e.viewOffset=vd(a,rd(f,k)),e.mover.style.top=e.viewOffset+"px",!0}}}function M(a,b){for(var c=0,d=b.length||0;d>c;++c){for(var e=b[c],f=[],g=e.diff||0,h=0,i=a.length;i>h;++h){var j=a[h];e.to<=j.from&&e.diff?f.push({from:j.from+g,to:j.to+g}):e.to<=j.from||e.from>=j.to?f.push(j):(e.from>j.from&&f.push({from:j.from,to:e.from}),e.to<j.to&&f.push({from:e.to+g,to:j.to+g}))}a=f}return a}function N(a){for(var b=a.display,c={},d={},e=b.gutters.firstChild,f=0;e;e=e.nextSibling,++f)c[a.options.gutters[f]]=e.offsetLeft,d[a.options.gutters[f]]=e.offsetWidth;return{fixedPos:J(b),gutterTotalWidth:b.gutters.offsetWidth,gutterLeft:c,gutterWidth:d,wrapperWidth:b.wrapper.clientWidth}}function O(a,c,d,f,g){function m(b){var c=b.nextSibling;return e&&p&&a.display.currentWheelTarget==b?(b.style.display="none",b.lineObj=null):k.removeChild(b),c}var h=N(a),i=a.display,j=a.options.lineNumbers;f.length||b||e&&a.display.currentWheelTarget||ae(i.lineDiv);var k=i.lineDiv,l=k.firstChild,n=f.shift(),o=c;for(a.view.doc.iter(c,d,function(b){if(n&&n.to==o&&(n=f.shift()),Xc(b))0!=b.height&&sd(b,0);else if(n&&o>=n.from&&n.to>o){for(;l.lineObj!=b;)l=m(l);j&&o>=g&&l.lineNumber&&ce(l.lineNumber,I(a.options,o)),l=l.nextSibling}else{var c=P(a,b,o,h);k.insertBefore(c,l),c.lineObj=b}++o});l;)l=m(l)}function P(a,b,d,e){var f=jd(a,b),g=b.gutterMarkers,h=a.display;if(!(a.options.lineNumbers||g||b.bgClass||b.wrapClass||b.widgets&&b.widgets.length))return f;var i=_d("div",null,b.wrapClass,"position: relative");if(a.options.lineNumbers||g){var j=i.appendChild(_d("div",null,null,"position: absolute; left: "+e.fixedPos+"px"));if(i.alignable=[j],!a.options.lineNumbers||g&&g["CodeMirror-linenumbers"]||(i.lineNumber=j.appendChild(_d("div",I(a.options,d),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+e.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+h.lineNumInnerWidth+"px"))),g)for(var k=0;a.options.gutters.length>k;++k){var l=a.options.gutters[k],m=g.hasOwnProperty(l)&&g[l];m&&j.appendChild(_d("div",[m],"CodeMirror-gutter-elt","left: "+e.gutterLeft[l]+"px; width: "+e.gutterWidth[l]+"px"))}}if(b.bgClass&&i.appendChild(_d("div","\u00a0",b.bgClass+" CodeMirror-linebackground")),i.appendChild(f),b.widgets)for(var n=0,o=b.widgets;o.length>n;++n){var p=o[n],q=_d("div",[p.node],"CodeMirror-linewidget");if(q.widget=p,p.noHScroll){(i.alignable||(i.alignable=[])).push(q);var r=e.wrapperWidth;q.style.left=e.fixedPos+"px",p.coverGutter||(r-=e.gutterTotalWidth,q.style.paddingLeft=e.gutterTotalWidth+"px"),q.style.width=r+"px"}p.coverGutter&&(q.style.zIndex=5,q.style.position="relative",p.noHScroll||(q.style.marginLeft=-e.gutterTotalWidth+"px")),p.above?i.insertBefore(q,a.options.lineNumbers&&0!=b.height?j:f):i.appendChild(q)}return c&&(i.style.zIndex=2),i}function Q(a){var b=a.display,c=bc(a.view.sel.from,a.view.sel.to);c||a.options.showCursorWhenSelecting?R(a):b.cursor.style.display=b.otherCursor.style.display="none",c?b.selectionDiv.style.display="none":S(a);var d=eb(a,a.view.sel.head,"div"),e=b.wrapper.getBoundingClientRect(),f=b.lineDiv.getBoundingClientRect();b.inputDiv.style.top=Math.max(0,Math.min(b.wrapper.clientHeight-10,d.top+f.top-e.top))+"px",b.inputDiv.style.left=Math.max(0,Math.min(b.wrapper.clientWidth-10,d.left+f.left-e.left))+"px"}function R(a){var b=a.display,c=eb(a,a.view.sel.head,"div");b.cursor.style.left=c.left+"px",b.cursor.style.top=c.top+"px",b.cursor.style.height=Math.max(0,c.bottom-c.top)*a.options.cursorHeight+"px",b.cursor.style.display="",c.other?(b.otherCursor.style.display="",b.otherCursor.style.left=c.other.left+"px",b.otherCursor.style.top=c.other.top+"px",b.otherCursor.style.height=.85*(c.other.bottom-c.other.top)+"px"):b.otherCursor.style.display="none"}function S(a){function h(a,b,c,d){0>b&&(b=0),e.appendChild(_d("div",null,"CodeMirror-selected","position: absolute; left: "+a+"px; top: "+b+"px; width: "+(null==c?f-a:c)+"px; height: "+(d-b)+"px"))}function i(b,d,e,i){function m(c){return db(a,{line:b,ch:c},"div",j)}var j=rd(c,b),k=j.text.length,l=i?1/0:-1/0;return ne(wd(j),d||0,null==e?k:e,function(a,b,c){var j=m("rtl"==c?b-1:a),n=m("rtl"==c?a:b-1),o=j.left,p=n.right;n.top-j.top>3&&(h(o,j.top,null,j.bottom),o=g,j.bottom<n.top&&h(o,j.bottom,null,n.top)),null==e&&b==k&&(p=f),null==d&&0==a&&(o=g),l=i?Math.min(n.top,l):Math.max(n.bottom,l),g+1>o&&(o=g),h(o,n.top,p-o,n.bottom)}),l}var b=a.display,c=a.view.doc,d=a.view.sel,e=document.createDocumentFragment(),f=b.lineSpace.offsetWidth,g=Z(a.display);if(d.from.line==d.to.line)i(d.from.line,d.from.ch,d.to.ch);else{for(var l,n,j=rd(c,d.from.line),k=j,m=[d.from.line,d.from.ch];l=Vc(k);){var o=l.find();if(m.push(o.from.ch,o.to.line,o.to.ch),o.to.line==d.to.line){m.push(d.to.ch),n=!0;break}k=rd(c,o.to.line)}if(n)for(var p=0;m.length>p;p+=3)i(m[p],m[p+1],m[p+2]);else{var q,r,s=rd(c,d.to.line);q=d.from.ch?i(d.from.line,d.from.ch,null,!1):vd(a,j)-b.viewOffset,r=d.to.ch?i(d.to.line,Uc(s)?null:0,d.to.ch,!0):vd(a,s)-b.viewOffset,r>q&&h(g,q,null,r)}}be(b.selectionDiv,e),b.selectionDiv.style.display=""}function T(a){var b=a.display;clearInterval(b.blinker);var c=!0;b.cursor.style.visibility=b.otherCursor.style.visibility="",b.blinker=setInterval(function(){b.cursor.offsetHeight&&(b.cursor.style.visibility=b.otherCursor.style.visibility=(c=!c)?"":"hidden")},a.options.cursorBlinkRate)}function U(a,b){a.view.frontier<a.display.showingTo&&a.view.highlight.set(b,Wd(V,a))}function V(a){var b=a.view,c=b.doc;if(!(b.frontier>=a.display.showingTo)){var g,d=+new Date+a.options.workTime,e=Cc(b.mode,X(a,b.frontier)),f=[];c.iter(b.frontier,Math.min(c.size,a.display.showingTo+500),function(c){return b.frontier>=a.display.showingFrom?(fd(a,c,e)&&b.frontier>=a.display.showingFrom&&(g&&g.end==b.frontier?g.end++:f.push(g={start:b.frontier,end:b.frontier+1})),c.stateAfter=Cc(b.mode,e)):(gd(a,c,e),c.stateAfter=0==b.frontier%5?Cc(b.mode,e):null),++b.frontier,+new Date>d?(U(a,a.options.workDelay),!0):void 0}),f.length&&mb(a,function(){for(var a=0;f.length>a;++a)nb(this,f[a].start,f[a].end)})()}}function W(a,b){for(var c,d,e=a.view.doc,f=b,g=b-100;f>g;--f){if(0==f)return 0;var h=rd(e,f-1);if(h.stateAfter)return f;var i=Pd(h.text,null,a.options.tabSize);(null==d||c>i)&&(d=f-1,c=i)}return d}function X(a,b){var c=a.view,d=W(a,b),e=d&&rd(c.doc,d-1).stateAfter;return e=e?Cc(c.mode,e):Dc(c.mode),c.doc.iter(d,b,function(f){gd(a,f,e);var g=d==b-1||0==d%5||d>=c.showingFrom&&c.showingTo>d;f.stateAfter=g?Cc(c.mode,e):null,++d}),e}function Y(a){return a.lineSpace.offsetTop}function Z(a){var b=be(a.measure,_d("pre")).appendChild(_d("span","x"));return b.offsetLeft}function $(a,b,c,d){for(var d=d||_(a,b),e=-1,f=c;;f+=e){var g=d[f];if(g)break;0>e&&0==f&&(e=1)}return{left:c>f?g.right:g.left,right:f>c?g.left:g.right,top:g.top,bottom:g.bottom}}function _(a,b){for(var c=a.display,d=a.display.measureLineCache,e=0;d.length>e;++e){var f=d[e];if(f.text==b.text&&f.markedSpans==b.markedSpans&&c.scroller.clientWidth==f.width)return f.measure}var g=ab(a,b),f={text:b.text,width:c.scroller.clientWidth,markedSpans:b.markedSpans,measure:g};return 16==d.length?d[++c.measureLineCachePos%16]=f:d.push(f),g}function ab(a,d){var e=a.display,f=Vd(d.text.length),g=jd(a,d,f);if(b&&!c&&!a.options.lineWrapping&&g.childNodes.length>100){for(var h=document.createDocumentFragment(),i=10,j=g.childNodes.length,k=0,l=Math.ceil(j/i);l>k;++k){for(var m=_d("div",null,null,"display: inline-block"),n=0;i>n&&j;++n)m.appendChild(g.firstChild),--j;h.appendChild(m)}g.appendChild(h)}be(e.measure,g);for(var s,o=e.lineDiv.getBoundingClientRect(),p=[],q=Vd(d.text.length),r=g.offsetHeight,k=0;f.length>k;++k)if(s=f[k]){for(var t=s.getBoundingClientRect(),u=Math.max(0,t.top-o.top),v=Math.min(t.bottom-o.top,r),n=0;p.length>n;n+=2){var w=p[n],x=p[n+1];if(!(w>v||u>x)&&(u>=w&&x>=v||w>=u&&v>=x||Math.min(v,x)-Math.max(u,w)>=v-u>>1)){p[n]=Math.min(u,w),p[n+1]=Math.max(v,x);break}}n==p.length&&p.push(u,v),q[k]={left:t.left-o.left,right:t.right-o.left,top:n}}for(var s,k=0;q.length>k;++k)if(s=q[k]){var y=s.top;s.top=p[y],s.bottom=p[y+1]}return q}function bb(a){a.display.measureLineCache.length=a.display.measureLineCachePos=0,a.display.cachedCharWidth=a.display.cachedTextHeight=null,a.view.maxLineChanged=!0}function cb(a,b,c,d){if(b.widgets)for(var e=0;b.widgets.length>e;++e)if(b.widgets[e].above){var f=b.widgets[e].node.offsetHeight;c.top+=f,c.bottom+=f}if("line"==d)return c;d||(d="local");var g=vd(a,b);if("local"!=d&&(g-=a.display.viewOffset),"page"==d){var h=a.display.lineSpace.getBoundingClientRect();g+=h.top+(window.pageYOffset||(document.documentElement||document.body).scrollTop);var i=h.left+(window.pageXOffset||(document.documentElement||document.body).scrollLeft);c.left+=i,c.right+=i}return c.top+=g,c.bottom+=g,c}function db(a,b,c,d){return d||(d=rd(a.view.doc,b.line)),cb(a,d,$(a,d,b.ch),c)}function eb(a,b,c,d,e){function f(b,f){var g=$(a,d,b,e);return f?g.left=g.right:g.right=g.left,cb(a,d,g,c)}d=d||rd(a.view.doc,b.line),e||(e=_(a,d));var g=wd(d),h=b.ch;if(!g)return f(h);for(var i,j,k=g[0].level,l=0;g.length>l;++l){var o,p,m=g[l],n=m.level%2;if(h>m.from&&m.to>h)return f(h,n);var q=n?m.to:m.from,r=n?m.from:m.to;if(q==h)p=l&&m.level<(o=g[l-1]).level?f(o.level%2?o.from:o.to-1,!0):f(n&&m.from!=m.to?h-1:h),n==k?i=p:j=p;else if(r==h){var o=g.length-1>l&&g[l+1];if(!n&&o&&o.from==o.to)continue;p=o&&m.level<o.level?f(o.level%2?o.to-1:o.from):f(n?h:h-1,!0),n==k?i=p:j=p}}return k&&!h&&(j=f(g[0].to-1)),i?(j&&(i.other=j),i):j}function fb(a,b,c){var d=a.view.doc;if(c+=a.display.viewOffset,0>c)return{line:0,ch:0,outside:!0};var e=ud(d,c);if(e>=d.size)return{line:d.size-1,ch:rd(d,d.size-1).text.length};for(0>b&&(b=0);;){var f=rd(d,e),g=gb(a,f,e,b,c),h=Vc(f);if(!h||g.ch!=re(f))return g;e=h.find().to.line}}function gb(a,b,c,d,e){function j(d){var e=eb(a,{line:c,ch:d},"line",b,i);return g=!0,f>e.bottom?Math.max(0,e.left-h):e.top>f?e.left+h:(g=!1,e.left)}var f=e-vd(a,b),g=!1,h=a.display.wrapper.clientWidth,i=_(a,b),k=wd(b),l=b.text.length,m=qe(b),n=re(b),o=Z(a.display),p=j(n);if(d>p)return{line:c,ch:n,outside:g};for(;;){if(k?n==m||n==ue(b,m,1):1>=n-m){for(var q=p-d>d-o,r=q?m:n;$d.test(b.text.charAt(r));)++r;return{line:c,ch:r,after:q,outside:g}}var s=Math.ceil(l/2),t=m+s;if(k){t=m;for(var u=0;s>u;++u)t=ue(b,t,1)}var v=j(t);v>d?(n=t,p=v,g&&(p+=1e3),l-=s):(m=t,o=v,l=s)}}function ib(a){if(null!=a.cachedTextHeight)return a.cachedTextHeight;if(null==hb){hb=_d("pre");for(var b=0;49>b;++b)hb.appendChild(document.createTextNode("x")),hb.appendChild(_d("br"));hb.appendChild(document.createTextNode("x"))}be(a.measure,hb);var c=hb.offsetHeight/50;return c>3&&(a.cachedTextHeight=c),ae(a.measure),c||1}function jb(a){if(null!=a.cachedCharWidth)return a.cachedCharWidth;var b=_d("span","x"),c=_d("pre",[b]);be(a.measure,c);var d=b.offsetWidth;return d>2&&(a.cachedCharWidth=d),d||10}function kb(a){a.curOp?++a.curOp.depth:a.curOp={depth:1,changes:[],delayedCallbacks:[],updateInput:null,userSelChange:null,textChanged:null,selectionChanged:!1,updateMaxLine:!1,id:++a.nextOpId}}function lb(a){var b=a.curOp;if(!--b.depth){a.curOp=null;var c=a.view,d=a.display;if(b.updateMaxLine&&C(c),c.maxLineChanged&&!a.options.lineWrapping){var e=$(a,c.maxLine,c.maxLine.text.length).right;d.sizer.style.minWidth=e+3+Md+"px",c.maxLineChanged=!1}var f,g;if(b.selectionChanged){var h=eb(a,c.sel.head);f=oc(a,h.left,h.top,h.left,h.bottom)}(b.changes.length||f&&null!=f.scrollTop)&&(g=K(a,b.changes,f&&f.scrollTop)),!g&&b.selectionChanged&&Q(a),f&&lc(a),b.selectionChanged&&T(a),c.focused&&b.updateInput&&rb(a,b.userSelChange),b.textChanged&&Jd(a,"change",a,b.textChanged),b.selectionChanged&&Jd(a,"cursorActivity",a);for(var i=0;b.delayedCallbacks.length>i;++i)b.delayedCallbacks[i](a)}}function mb(a,b){return function(){var c=a||this;kb(c);try{var d=b.apply(c,arguments)}finally{lb(c)}return d}}function nb(a,b,c,d){a.curOp.changes.push({from:b,to:c,diff:d})}function ob(a){a.view.pollingFast||a.display.poll.set(a.options.pollInterval,function(){qb(a),a.view.focused&&ob(a)})}function pb(a){function c(){var d=qb(a);d||b?(a.display.pollingFast=!1,ob(a)):(b=!0,a.display.poll.set(60,c))}var b=!1;a.display.pollingFast=!0,a.display.poll.set(20,c)}function qb(a){var b=a.display.input,c=a.display.prevInput,d=a.view,e=d.sel;if(!d.focused||ke(b)||tb(a))return!1;var f=b.value;if(f==c&&bc(e.from,e.to))return!1;kb(a),d.sel.shift=!1;for(var g=0,h=Math.min(c.length,f.length);h>g&&c[g]==f[g];)++g;var i=e.from,j=e.to;c.length>g?i={line:i.line,ch:i.ch-(c.length-g)}:d.overwrite&&bc(i,j)&&!a.display.pasteIncoming&&(j={line:j.line,ch:Math.min(rd(a.view.doc,j.line).text.length,j.ch+(f.length-g))});var k=a.curOp.updateInput;return Yb(a,i,j,je(f.slice(g)),"end",a.display.pasteIncoming?"paste":"input",{from:i,to:j}),a.curOp.updateInput=k,f.length>1e3?b.value=a.display.prevInput="":a.display.prevInput=f,lb(a),a.display.pasteIncoming=!1,!0}function rb(a,b){var d,e,c=a.view;bc(c.sel.from,c.sel.to)?b&&(a.display.prevInput=a.display.input.value=""):(a.display.prevInput="",d=le&&(c.sel.to.line-c.sel.from.line>100||(e=a.getSelection()).length>1e3),a.display.input.value=d?"-":e||a.getSelection(),c.focused&&Td(a.display.input)),a.display.inaccurateSelection=d}function sb(a){"nocursor"==a.options.readOnly||!b&&document.activeElement==a.display.input||a.display.input.focus()}function tb(a){return a.options.readOnly||a.view.cantEdit}function ub(b){function d(){b.view.focused&&setTimeout(Wd(sb,b),0)}function f(a){b.options.onDragEvent&&b.options.onDragEvent(b,Ad(a))||Dd(a)}function g(){c.inaccurateSelection&&(c.prevInput="",c.inaccurateSelection=!1,c.input.value=b.getSelection(),Td(c.input))}var c=b.display;Hd(c.scroller,"mousedown",mb(b,zb)),Hd(c.scroller,"dblclick",mb(b,Bd)),Hd(c.lineSpace,"selectstart",function(a){vb(c,a)||Bd(a)}),a||Hd(c.scroller,"contextmenu",function(a){Xb(b,a)}),Hd(c.scroller,"scroll",function(){Db(b,c.scroller.scrollTop),Eb(b,c.scroller.scrollLeft,!0),Jd(b,"scroll",b)}),Hd(c.scrollbarV,"scroll",function(){Db(b,c.scrollbarV.scrollTop)}),Hd(c.scrollbarH,"scroll",function(){Eb(b,c.scrollbarH.scrollLeft)}),Hd(c.scroller,"mousewheel",function(a){Lb(b,a)}),Hd(c.scroller,"DOMMouseScroll",function(a){Lb(b,a)}),Hd(c.scrollbarH,"mousedown",d),Hd(c.scrollbarV,"mousedown",d),Hd(c.wrapper,"scroll",function(){c.wrapper.scrollTop=c.wrapper.scrollLeft=0}),Hd(window,"resize",function e(){c.cachedCharWidth=c.cachedTextHeight=null,bb(b),c.wrapper.parentNode?K(b,!0):Id(window,"resize",e)}),Hd(c.input,"keyup",mb(b,function(a){b.options.onKeyEvent&&b.options.onKeyEvent(b,Ad(a))||16==Gd(a,"keyCode")&&(b.view.sel.shift=!1)})),Hd(c.input,"input",Wd(pb,b)),Hd(c.input,"keydown",mb(b,Sb)),Hd(c.input,"keypress",mb(b,Tb)),Hd(c.input,"focus",Wd(Ub,b)),Hd(c.input,"blur",Wd(Vb,b)),b.options.dragDrop&&(Hd(c.scroller,"dragstart",function(a){Cb(b,a)}),Hd(c.scroller,"dragenter",f),Hd(c.scroller,"dragover",f),Hd(c.scroller,"drop",mb(b,Ab))),Hd(c.scroller,"paste",function(){sb(b),pb(b)}),Hd(c.input,"paste",function(){c.pasteIncoming=!0,pb(b)}),Hd(c.input,"cut",g),Hd(c.input,"copy",g),j&&Hd(c.sizer,"mouseup",function(){document.activeElement==c.input&&c.input.blur(),sb(b)})}function vb(a,b){for(var c=Ed(b);c!=a.wrapper;c=c.parentNode)if(/\bCodeMirror-(?:line)?widget\b/.test(c.className)||c.parentNode==a.sizer&&c!=a.mover)return!0}function wb(a,b,c){var d=a.display;if(!c){var e=Ed(b);if(e==d.scrollbarH||e==d.scrollbarH.firstChild||e==d.scrollbarV||e==d.scrollbarV.firstChild||e==d.scrollbarFiller)return null}var f,g,h=d.lineSpace.getBoundingClientRect();try{f=b.clientX,g=b.clientY}catch(b){return null}return fb(a,f-h.left,g-h.top)}function zb(c){function r(a){if("single"==l)return hc(d,fc(i,j),a),void 0;if(p=fc(i,p),q=fc(i,q),"double"==l){var b=sc(rd(i,a.line).text,a);cc(a,p)?hc(d,b.from,q):hc(d,p,b.to)}else"triple"==l&&(cc(a,p)?hc(d,q,fc(i,{line:a.line,ch:0})):hc(d,p,fc(i,{line:a.line+1,ch:0})))}function u(a){var b=++t,c=wb(d,a,!0);if(c)if(bc(c,n)){var h=a.clientY<s.top?-20:a.clientY>s.bottom?20:0;h&&setTimeout(mb(d,function(){t==b&&(f.scroller.scrollTop+=h,u(a))}),50)}else{g.focused||Ub(d),n=c,r(c);var e=F(f,i);(c.line>=e.to||c.line<e.from)&&setTimeout(mb(d,function(){t==b&&u(a)}),150)}}function v(a){t=1/0;var b=wb(d,a);b&&r(b),Bd(a),sb(d),Id(document,"mousemove",w),Id(document,"mouseup",x)}var d=this,f=d.display,g=d.view,h=g.sel,i=g.doc;if(h.shift=Gd(c,"shiftKey"),vb(f,c))return e||(f.scroller.draggable=!1,setTimeout(function(){f.scroller.draggable=!0},100)),void 0;if(!Bb(d,c)){var j=wb(d,c);switch(Fd(c)){case 3:return a&&Xb.call(d,d,c),void 0;case 2:return j&&hc(d,j),setTimeout(Wd(sb,d),20),Bd(c),void 0}if(!j)return Ed(c)==f.scroller&&Bd(c),void 0;g.focused||Ub(d);var k=+new Date,l="single";if(yb&&yb.time>k-400&&bc(yb.pos,j))l="triple",Bd(c),setTimeout(Wd(sb,d),20),tc(d,j.line);else if(xb&&xb.time>k-400&&bc(xb.pos,j)){l="double",yb={time:k,pos:j},Bd(c);var m=sc(rd(i,j.line).text,j);hc(d,m.from,m.to)}else xb={time:k,pos:j};var n=j;if(d.options.dragDrop&&de&&!tb(d)&&!bc(h.from,h.to)&&!cc(j,h.from)&&!cc(h.to,j)&&"single"==l){var o=mb(d,function(a){e&&(f.scroller.draggable=!1),g.draggingText=!1,Id(document,"mouseup",o),Id(f.scroller,"drop",o),10>Math.abs(c.clientX-a.clientX)+Math.abs(c.clientY-a.clientY)&&(Bd(a),hc(d,j),sb(d))});return e&&(f.scroller.draggable=!0),g.draggingText=o,f.scroller.dragDrop&&f.scroller.dragDrop(),Hd(document,"mouseup",o),Hd(f.scroller,"drop",o),void 0}Bd(c),"single"==l&&hc(d,fc(i,j));var p=h.from,q=h.to,s=f.wrapper.getBoundingClientRect(),t=0,w=mb(d,function(a){b||Fd(a)?u(a):v(a)}),x=mb(d,v);Hd(document,"mousemove",w),Hd(document,"mouseup",x)}}function Ab(a){var c=this;if(!c.options.onDragEvent||!c.options.onDragEvent(c,Ad(a))){Bd(a);var d=wb(c,a,!0),e=a.dataTransfer.files;if(d&&!tb(c))if(e&&e.length&&window.FileReader&&window.File)for(var f=e.length,g=Array(f),h=0,i=function(a,b){var e=new FileReader;e.onload=function(){g[b]=e.result,++h==f&&(d=fc(c.view.doc,d),mb(c,function(){var a=ac(c,g.join(""),d,d,"paste");ic(c,d,a)})())},e.readAsText(a)},j=0;f>j;++j)i(e[j],j);else{if(c.view.draggingText&&!cc(d,c.view.sel.from)&&!cc(c.view.sel.to,d))return c.view.draggingText(a),b&&setTimeout(Wd(sb,c),50),void 0;try{var g=a.dataTransfer.getData("Text");if(g){var k=c.view.sel.from,l=c.view.sel.to;ic(c,d,d),c.view.draggingText&&ac(c,"",k,l,"paste"),c.replaceSelection(g,null,"paste"),sb(c),Ub(c)}}catch(a){}}}}function Bb(a,b){var c=a.display;try{var d=b.clientX,e=b.clientY}catch(b){return!1}if(d>=Math.floor(c.gutters.getBoundingClientRect().right))return!1;if(Bd(b),!Ld(a,"gutterClick"))return!0;var f=c.lineDiv.getBoundingClientRect();if(e>f.bottom)return!0;e-=f.top-c.viewOffset;for(var g=0;a.options.gutters.length>g;++g){var h=c.gutters.childNodes[g];if(h&&h.getBoundingClientRect().right>=d){var i=ud(a.view.doc,e),j=a.options.gutters[g];Kd(a,a,"gutterClick",a,i,j,b);break}}return!0}function Cb(a,b){var c=a.getSelection();b.dataTransfer.setData("Text",c),b.dataTransfer.setDragImage&&!i&&b.dataTransfer.setDragImage(_d("img"),0,0)}function Db(b,c){2>Math.abs(b.view.scrollTop-c)||(b.view.scrollTop=c,a||K(b,[],c),b.display.scroller.scrollTop!=c&&(b.display.scroller.scrollTop=c),b.display.scrollbarV.scrollTop!=c&&(b.display.scrollbarV.scrollTop=c),a&&K(b,[]))}function Eb(a,b,c){(c?b==a.view.scrollLeft:2>Math.abs(a.view.scrollLeft-b))||(a.view.scrollLeft=b,G(a),a.display.scroller.scrollLeft!=b&&(a.display.scroller.scrollLeft=b),a.display.scrollbarH.scrollLeft!=b&&(a.display.scrollbarH.scrollLeft=b))}function Lb(b,c){var d=c.wheelDeltaX,f=c.wheelDeltaY;if(null==d&&c.detail&&c.axis==c.HORIZONTAL_AXIS&&(d=c.detail),null==f&&c.detail&&c.axis==c.VERTICAL_AXIS?f=c.detail:null==f&&(f=c.wheelDelta),f&&p&&e)for(var g=c.target;g!=i;g=g.parentNode)if(g.lineObj){b.display.currentWheelTarget=g;break}var i=b.display.scroller;if(d&&!a&&!h&&null!=Kb)return f&&Db(b,Math.max(0,Math.min(i.scrollTop+f*Kb,i.scrollHeight-i.clientHeight))),Eb(b,Math.max(0,Math.min(i.scrollLeft+d*Kb,i.scrollWidth-i.clientWidth))),Bd(c),Ib=null,void 0;if(f&&null!=Kb){var j=f*Kb,k=b.view.scrollTop,l=k+b.display.wrapper.clientHeight;0>j?k=Math.max(0,k+j-50):l=Math.min(b.view.doc.height,l+j+50),K(b,[],{top:k,bottom:l})}20>Fb&&(null==Ib?(Ib=i.scrollLeft,Jb=i.scrollTop,Gb=d,Hb=f,setTimeout(function(){if(null!=Ib){var a=i.scrollLeft-Ib,b=i.scrollTop-Jb,c=b&&Hb&&b/Hb||a&&Gb&&a/Gb;Ib=Jb=null,c&&(Kb=(Kb*Fb+c)/(Fb+1),++Fb)}},200)):(Gb+=d,Hb+=f))}function Mb(a,b,c){if("string"==typeof b&&(b=Ec[b],!b))return!1;a.display.pollingFast&&qb(a)&&(a.display.pollingFast=!1);var d=a.view,e=d.sel.shift;try{tb(a)&&(d.suppressEdits=!0),c&&(d.sel.shift=!1),b(a)}catch(f){if(f!=Nd)throw f;return!1}finally{d.sel.shift=e,d.suppressEdits=!1}return!0}function Nb(a){var b=a.view.keyMaps.slice(0);return b.push(a.options.keyMap),a.options.extraKeys&&b.unshift(a.options.extraKeys),b}function Pb(a,b){function l(){k=!0}var c=Gc(a.options.keyMap),e=c.auto;clearTimeout(Ob),e&&!Ic(b)&&(Ob=setTimeout(function(){Gc(a.options.keyMap)==c&&(a.options.keyMap=e.call?e.call(null,a):e)},50));var g=me[Gd(b,"keyCode")],i=!1,j=p&&(h||f);if(null==g||b.altGraphKey)return!1;Gd(b,"altKey")&&(g="Alt-"+g),Gd(b,j?"metaKey":"ctrlKey")&&(g="Ctrl-"+g),Gd(b,j?"ctrlKey":"metaKey")&&(g="Cmd-"+g);var k=!1,m=Nb(a);return i=Gd(b,"shiftKey")?Hc("Shift-"+g,m,function(b){return Mb(a,b,!0)},l)||Hc(g,m,function(b){return"string"==typeof b&&/^go[A-Z]/.test(b)?Mb(a,b):void 0},l):Hc(g,m,function(b){return Mb(a,b)},l),k&&(i=!1),i&&(Bd(b),T(a),d&&(b.oldKeyCode=b.keyCode,b.keyCode=0)),i}function Qb(a,b,c){var d=Hc("'"+c+"'",Nb(a),function(b){return Mb(a,b,!0)});return d&&(Bd(b),T(a)),d}function Sb(a){var c=this;if(c.view.focused||Ub(c),b&&27==a.keyCode&&(a.returnValue=!1),!c.options.onKeyEvent||!c.options.onKeyEvent(c,Ad(a))){var d=Gd(a,"keyCode");c.view.sel.shift=16==d||Gd(a,"shiftKey");var e=Pb(c,a);h&&(Rb=e?d:null,e||88!=d||le||!Gd(a,p?"metaKey":"ctrlKey")||c.replaceSelection(""))}}function Tb(a){var b=this;if(!b.options.onKeyEvent||!b.options.onKeyEvent(b,Ad(a))){var c=Gd(a,"keyCode"),d=Gd(a,"charCode");if(h&&c==Rb)return Rb=null,Bd(a),void 0;if(!(h&&(!a.which||10>a.which)||j)||!Pb(b,a)){var e=String.fromCharCode(null==d?c:d);this.options.electricChars&&this.view.mode.electricChars&&this.options.smartIndent&&!tb(this)&&this.view.mode.electricChars.indexOf(e)>-1&&setTimeout(mb(b,function(){pc(b,b.view.sel.to.line,"smart")}),75),Qb(b,a,e)||pb(b)}}}function Ub(a){"nocursor"!=a.options.readOnly&&(a.view.focused||(Jd(a,"focus",a),a.view.focused=!0,-1==a.display.scroller.className.search(/\bCodeMirror-focused\b/)&&(a.display.scroller.className+=" CodeMirror-focused"),rb(a,!0)),ob(a),T(a))}function Vb(a){a.view.focused&&(Jd(a,"blur",a),a.view.focused=!1,a.display.scroller.className=a.display.scroller.className.replace(" CodeMirror-focused","")),clearInterval(a.display.blinker),setTimeout(function(){a.view.focused||(a.view.sel.shift=!1)},150)}function Xb(b,c){function k(){if(e.inputDiv.style.position="relative",e.input.style.cssText=j,d&&(e.scrollbarV.scrollTop=e.scroller.scrollTop=i),ob(b),null!=e.input.selectionStart){clearTimeout(Wb);
2
+ var a=e.input.value=" "+(bc(f.from,f.to)?"":e.input.value),c=0;e.prevInput=" ",e.input.selectionStart=1,e.input.selectionEnd=a.length,Wb=setTimeout(function g(){" "==e.prevInput&&0==e.input.selectionStart?mb(b,Ec.selectAll)(b):10>c++?Wb=setTimeout(g,500):rb(b)},200)}}var e=b.display,f=b.view.sel,g=wb(b,c),i=e.scroller.scrollTop;if(g&&!h){(bc(f.from,f.to)||cc(g,f.from)||!cc(g,f.to))&&mb(b,ic)(b,g,g);var j=e.input.style.cssText;e.inputDiv.style.position="absolute",e.input.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(c.clientY-5)+"px; left: "+(c.clientX-5)+"px; z-index: 1000; background: white; outline: none;"+"border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",sb(b),rb(b,!0),bc(f.from,f.to)&&(e.input.value=e.prevInput=" "),a?(Dd(c),Hd(window,"mouseup",function l(){Id(window,"mouseup",l),setTimeout(k,20)})):setTimeout(k,50)}}function Yb(a,b,c,d,e,f){var g=q&&Sc(a.view.doc,b,c);if(!g)return Zb(a,b,c,d,e,f);for(var h=g.length-1;h>=1;--h)Zb(a,g[h].from,g[h].to,[""],f);return g.length?Zb(a,g[0].from,g[0].to,d,e,f):void 0}function Zb(a,b,c,d,e,f){if(!a.view.suppressEdits){var g=a.view,h=g.doc,i=[];h.iter(b.line,c.line+1,function(a){i.push(_c(a.text,a.markedSpans))});var j=g.sel.from,k=g.sel.to,l=Rc($c(i[0]),$c(Sd(i)),b.ch,c.ch,d),m=_b(a,b,c,l,e,f);return g.history&&yd(a,b.line,d.length,i,f,j,k,g.sel.from,g.sel.to),m}}function $b(a,b){var c=a.view.doc,d=a.view.history,e=("undo"==b?d.done:d.undone).pop();if(e){for(var f={events:[],fromBefore:e.fromAfter,toBefore:e.toAfter,fromAfter:e.fromBefore,toAfter:e.toBefore},g=e.events.length-1;g>=0;g-=1){d.dirtyCounter+="undo"==b?-1:1;var h=e.events[g],i=[],j=h.start+h.added;c.iter(h.start,j,function(a){i.push(_c(a.text,a.markedSpans))}),f.events.push({start:h.start,added:h.old.length,old:i});var k=g?null:{from:e.fromBefore,to:e.toBefore};_b(a,{line:h.start,ch:0},{line:j-1,ch:rd(c,j-1).text.length},h.old,k,b)}("undo"==b?d.undone:d.done).push(f)}}function _b(a,b,c,d,e,f){var g=a.view,h=g.doc,i=a.display;if(!g.suppressEdits){var j=c.line-b.line,k=rd(h,b.line),l=rd(h,c.line),m=!1,n=b.line;a.options.lineWrapping||(n=td(Wc(h,k)),h.iter(n,c.line+1,function(a){return B(h,a)==g.maxLineLength?(m=!0,!0):void 0}));var o=Sd(d),p=ib(i);if(0==b.ch&&0==c.ch&&""==Zc(o)){for(var q=[],r=0,s=d.length-1;s>r;++r)q.push(cd(Zc(d[r]),$c(d[r]),p));dd(a,l,l.text,$c(o)),j&&h.remove(b.line,j,a),q.length&&h.insert(b.line,q)}else if(k==l)if(1==d.length)dd(a,k,k.text.slice(0,b.ch)+Zc(d[0])+k.text.slice(c.ch),$c(d[0]));else{for(var q=[],r=1,s=d.length-1;s>r;++r)q.push(cd(Zc(d[r]),$c(d[r]),p));q.push(cd(Zc(o)+k.text.slice(c.ch),$c(o),p)),dd(a,k,k.text.slice(0,b.ch)+Zc(d[0]),$c(d[0])),h.insert(b.line+1,q)}else if(1==d.length)dd(a,k,k.text.slice(0,b.ch)+Zc(d[0])+l.text.slice(c.ch),$c(d[0])),h.remove(b.line+1,j,a);else{var q=[];dd(a,k,k.text.slice(0,b.ch)+Zc(d[0]),$c(d[0])),dd(a,l,Zc(o)+l.text.slice(c.ch),$c(o));for(var r=1,s=d.length-1;s>r;++r)q.push(cd(Zc(d[r]),$c(d[r]),p));j>1&&h.remove(b.line+1,j-1,a),h.insert(b.line+1,q)}if(a.options.lineWrapping){var t=Math.max(5,i.scroller.clientWidth/jb(i)-3);h.iter(b.line,b.line+d.length,function(a){if(0!=a.height){var b=(Math.ceil(a.text.length/t)||1)*p;b!=a.height&&sd(a,b)}})}else h.iter(n,b.line+d.length,function(a){var b=B(h,a);b>g.maxLineLength&&(g.maxLine=a,g.maxLineLength=b,g.maxLineChanged=!0,m=!1)}),m&&(a.curOp.updateMaxLine=!0);g.frontier=Math.min(g.frontier,b.line),U(a,400);var u=d.length-j-1;if(nb(a,b.line,c.line+1,u),Ld(a,"change")){for(var r=0;d.length>r;++r)"string"!=typeof d[r]&&(d[r]=d[r].text);var v={from:b,to:c,text:d,origin:f};if(a.curOp.textChanged){for(var w=a.curOp.textChanged;w.next;w=w.next);w.next=v}else a.curOp.textChanged=v}var x,y,z={line:b.line+d.length-1,ch:Zc(o).length+(1==d.length?b.ch:0)};if(e&&"string"!=typeof e)e.from?(x=e.from,y=e.to):x=y=e;else if("end"==e)x=y=z;else if("start"==e)x=y=b;else if("around"==e)x=b,y=z;else{var A=function(a){if(cc(a,b))return a;if(!cc(c,a))return z;var d=a.line+u,e=a.ch;return a.line==c.line&&(e+=Zc(o).length-(c.ch-(c.line==b.line?b.ch:0))),{line:d,ch:e}};x=A(g.sel.from),y=A(g.sel.to)}return ic(a,x,y,null,!0),z}}function ac(a,b,c,d,e){if(d||(d=c),cc(d,c)){var f=d;d=c,c=f}return Yb(a,c,d,je(b),null,e)}function bc(a,b){return a.line==b.line&&a.ch==b.ch}function cc(a,b){return a.line<b.line||a.line==b.line&&a.ch<b.ch}function dc(a){return{line:a.line,ch:a.ch}}function ec(a,b){return Math.max(0,Math.min(b,a.size-1))}function fc(a,b){if(0>b.line)return{line:0,ch:0};if(b.line>=a.size)return{line:a.size-1,ch:rd(a,a.size-1).text.length};var c=b.ch,d=rd(a,b.line).text.length;return null==c||c>d?{line:b.line,ch:d}:0>c?{line:b.line,ch:0}:b}function gc(a,b){return b>=0&&a.size>b}function hc(a,b,c,d){var e=a.view.sel;if(e.shift||e.extend){var f=e.anchor;if(c){var g=cc(b,f);g!=cc(c,f)?(f=b,b=c):g!=cc(b,c)&&(b=c)}ic(a,f,b,d)}else ic(a,b,c||b,d);a.curOp.userSelChange=!0}function ic(a,b,c,d,e){a.view.goalColumn=null;var f=a.view.sel;if((e||!bc(b,f.anchor))&&(b=kc(a,b,d,"push"!=e)),(e||!bc(c,f.head))&&(c=kc(a,c,d,"push"!=e)),!bc(f.anchor,b)||!bc(f.head,c)){f.anchor=b,f.head=c;var g=cc(c,b);f.from=g?c:b,f.to=g?b:c,a.curOp.updateInput=!0,a.curOp.selectionChanged=!0}}function jc(a){ic(a,a.view.sel.from,a.view.sel.to,null,"push")}function kc(a,b,c,d){var e=a.view.doc,f=!1,g=b,h=c||1;a.view.cantEdit=!1;a:for(;;){var j,i=rd(e,g.line);if(i.markedSpans){for(var k=0;i.markedSpans.length>k;++k){var l=i.markedSpans[k],m=l.marker;if((null==l.from||(m.inclusiveLeft?l.from<=g.ch:l.from<g.ch))&&(null==l.to||(m.inclusiveRight?l.to>=g.ch:l.to>g.ch))){if(d&&m.clearOnEnter){(j||(j=[])).push(m);continue}if(!m.atomic)continue;var n=m.find()[0>h?"from":"to"];if(bc(n,g)&&(n.ch+=h,0>n.ch?n=n.line?fc(e,{line:n.line-1}):null:n.ch>i.text.length&&(n=n.line<e.size-1?{line:n.line+1,ch:0}:null),!n)){if(f)return d?(a.view.cantEdit=!0,{line:0,ch:0}):kc(a,b,c,!0);f=!0,n=b,h=-h}g=n;continue a}}if(j)for(var k=0;j.length>k;++k)j[k].clear()}return g}}function lc(a){var b=a.view,c=mc(a,b.sel.head);if(b.focused){var d=a.display,e=d.sizer.getBoundingClientRect(),f=null;if(0>c.top+e.top?f=!0:c.bottom+e.top>(window.innerHeight||document.documentElement.clientHeight)&&(f=!1),null!=f&&!m){var g="none"==d.cursor.style.display;g&&(d.cursor.style.display="",d.cursor.style.left=c.left+"px",d.cursor.style.top=c.top-d.viewOffset+"px"),d.cursor.scrollIntoView(f),g&&(d.cursor.style.display="none")}}}function mc(a,b){for(;;){var c=!1,d=eb(a,b),e=oc(a,d.left,d.top,d.left,d.bottom),f=a.view.scrollTop,g=a.view.scrollLeft;if(null!=e.scrollTop&&(Db(a,e.scrollTop),Math.abs(a.view.scrollTop-f)>1&&(c=!0)),null!=e.scrollLeft&&(Eb(a,e.scrollLeft),Math.abs(a.view.scrollLeft-g)>1&&(c=!0)),!c)return d}}function nc(a,b,c,d,e){var f=oc(a,b,c,d,e);null!=f.scrollTop&&Db(a,f.scrollTop),null!=f.scrollLeft&&Eb(a,f.scrollLeft)}function oc(a,b,c,d,e){var f=a.display,g=Y(f);c+=g,e+=g;var h=f.scroller.clientHeight-Md,i=f.scroller.scrollTop,j={},k=a.view.doc.height+2*g,l=g+10>c,m=e+g>k-10;i>c?j.scrollTop=l?0:Math.max(0,c):e>i+h&&(j.scrollTop=(m?k:e)-h);var n=f.scroller.clientWidth-Md,o=f.scroller.scrollLeft;b+=f.gutters.offsetWidth,d+=f.gutters.offsetWidth;var p=f.gutters.offsetWidth,q=p+10>b;return o+p>b||q?(q&&(b=0),j.scrollLeft=Math.max(0,b-10-p)):d>n+o-3&&(j.scrollLeft=d+10-n),j}function pc(a,b,c,d){var e=a.view.doc;if(c||(c="add"),"smart"==c)if(a.view.mode.indent)var f=X(a,b);else c="prev";var k,g=a.options.tabSize,h=rd(e,b),i=Pd(h.text,null,g),j=h.text.match(/^\s*/)[0];if("smart"==c&&(k=a.view.mode.indent(f,h.text.slice(j.length),h.text),k==Nd)){if(!d)return;c="prev"}"prev"==c?k=b?Pd(rd(e,b-1).text,null,g):0:"add"==c?k=i+a.options.indentUnit:"subtract"==c&&(k=i-a.options.indentUnit),k=Math.max(0,k);var l="",m=0;if(a.options.indentWithTabs)for(var n=Math.floor(k/g);n;--n)m+=g,l+=" ";k>m&&(l+=Rd(k-m)),l!=j&&ac(a,l,{line:b,ch:0},{line:b,ch:j.length},"input"),h.stateAfter=null}function qc(a,b,c){var d=b,e=b,f=a.view.doc;return"number"==typeof b?e=rd(f,ec(f,b)):d=td(b),null==d?null:c(e,d)?(nb(a,d,d+1),e):null}function rc(a,b,c,d){function j(){var a=g+b;return 0>a||a==e.size?!1:(g=a,i=rd(e,a))}function k(a){var c=(d?ue:ve)(i,h,b,!0);if(null==c){if(a||!j())return!1;h=d?(0>b?re:qe)(i):0>b?i.text.length:0}else h=c;return!0}var e=a.view.doc,f=a.view.sel.head,g=f.line,h=f.ch,i=rd(e,g);if("char"==c)k();else if("column"==c)k(!0);else if("word"==c)for(var l=!1;!(0>b)||k();){if(Yd(i.text.charAt(h)))l=!0;else if(l){0>b&&(b=1,k());break}if(b>0&&!k())break}return kc(a,{line:g,ch:h},b,!0)}function sc(a,b){var c=b.ch,d=b.ch;if(a){b.after===!1||d==a.length?--c:++d;for(var e=a.charAt(c),f=Yd(e)?Yd:/\s/.test(e)?function(a){return/\s/.test(a)}:function(a){return!/\s/.test(a)&&!Yd(a)};c>0&&f(a.charAt(c-1));)--c;for(;a.length>d&&f(a.charAt(d));)++d}return{from:{line:b.line,ch:c},to:{line:b.line,ch:d}}}function tc(a,b){hc(a,{line:b,ch:0},fc(a.view.doc,{line:b+1,ch:0}))}function wc(a,b,c,d){s.defaults[a]=b,c&&(uc[a]=d?function(a,b,d){d!=xc&&c(a,b,d)}:c)}function Cc(a,b){if(b===!0)return b;if(a.copyState)return a.copyState(b);var c={};for(var d in b){var e=b[d];e instanceof Array&&(e=e.concat([])),c[d]=e}return c}function Dc(a,b,c){return a.startState?a.startState(b,c):!0}function Gc(a){return"string"==typeof a?Fc[a]:a}function Hc(a,b,c,d){function e(b){b=Gc(b);var f=b[a];if(f===!1)return d&&d(),!0;if(null!=f&&c(f))return!0;if(b.nofallthrough)return d&&d(),!0;var g=b.fallthrough;if(null==g)return!1;if("[object Array]"!=Object.prototype.toString.call(g))return e(g);for(var h=0,i=g.length;i>h;++h)if(e(g[h]))return!0;return!1}for(var f=0;b.length>f;++f)if(e(b[f]))return!0}function Ic(a){var b=me[Gd(a,"keyCode")];return"Ctrl"==b||"Alt"==b||"Shift"==b||"Mod"==b}function Jc(a,b){this.pos=this.start=0,this.string=a,this.tabSize=b||8}function Kc(a,b){this.lines=[],this.type=b,this.cm=a}function Lc(a,b,c,d,e){var f=a.view.doc,g=new Kc(a,e);if("range"==e&&!cc(b,c))return g;if(d)for(var h in d)d.hasOwnProperty(h)&&(g[h]=d[h]);g.replacedWith&&(g.collapsed=!0,g.replacedWith=_d("span",[g.replacedWith],"CodeMirror-widget")),g.collapsed&&(r=!0);var k,l,i=b.line,j=0;if(f.iter(i,c.line+1,function(a){var d={from:null,to:null,marker:g};j+=a.text.length,i==b.line&&(d.from=b.ch,j-=b.ch),i==c.line&&(d.to=c.ch,j-=a.text.length-c.ch),g.collapsed&&(i==c.line&&(l=Tc(a,c.ch)),i==b.line?k=Tc(a,b.ch):sd(a,0)),Oc(a,d),g.collapsed&&i==b.line&&Xc(a)&&sd(a,0),++i}),g.readOnly&&(q=!0,(a.view.history.done.length||a.view.history.undone.length)&&a.clearHistory()),g.collapsed){if(k!=l)throw Error("Inserting collapsed marker overlapping an existing one");g.size=j,g.atomic=!0}return(g.className||g.startStyle||g.endStyle||g.collapsed)&&nb(a,b.line,c.line+1),g.atomic&&jc(a),g}function Mc(a,b){if(a)for(var c=0;a.length>c;++c){var d=a[c];if(d.marker==b)return d}}function Nc(a,b){for(var c,d=0;a.length>d;++d)a[d]!=b&&(c||(c=[])).push(a[d]);return c}function Oc(a,b){a.markedSpans=a.markedSpans?a.markedSpans.concat([b]):[b],b.marker.lines.push(a)}function Pc(a,b){if(a)for(var d,c=0;a.length>c;++c){var e=a[c],f=e.marker,g=null==e.from||(f.inclusiveLeft?b>=e.from:b>e.from);if(g||"bookmark"==f.type&&e.from==b){var h=null==e.to||(f.inclusiveRight?e.to>=b:e.to>b);(d||(d=[])).push({from:e.from,to:h?null:e.to,marker:f})}}return d}function Qc(a,b,c){if(a)for(var e,d=0;a.length>d;++d){var f=a[d],g=f.marker,h=null==f.to||(g.inclusiveRight?f.to>=c:f.to>c);if(h||"bookmark"==g.type&&f.from==c&&f.from!=b){var i=null==f.from||(g.inclusiveLeft?c>=f.from:c>f.from);(e||(e=[])).push({from:i?null:f.from-c,to:null==f.to?null:f.to-c,marker:g})}}return e}function Rc(a,b,c,d,e){if(!a&&!b)return e;var f=Pc(a,c),g=Qc(b,c,d),h=1==e.length,i=Sd(e).length+(h?c:0);if(f)for(var j=0;f.length>j;++j){var k=f[j];if(null==k.to){var l=Mc(g,k.marker);l?h&&(k.to=null==l.to?null:l.to+i):k.to=c}}if(g)for(var j=0;g.length>j;++j){var k=g[j];if(null!=k.to&&(k.to+=i),null==k.from){var l=Mc(f,k.marker);l||(k.from=i,h&&(f||(f=[])).push(k))}else k.from+=i,h&&(f||(f=[])).push(k)}var m=[_c(e[0],f)];if(!h){var o,n=e.length-2;if(n>0&&f)for(var j=0;f.length>j;++j)null==f[j].to&&(o||(o=[])).push({from:null,to:null,marker:f[j].marker});for(var j=0;n>j;++j)m.push(_c(e[j+1],o));m.push(_c(Sd(e),g))}return m}function Sc(a,b,c){var d=null;if(a.iter(b.line,c.line+1,function(a){if(a.markedSpans)for(var b=0;a.markedSpans.length>b;++b){var c=a.markedSpans[b].marker;!c.readOnly||d&&-1!=Ud(d,c)||(d||(d=[])).push(c)}}),!d)return null;for(var e=[{from:b,to:c}],f=0;d.length>f;++f)for(var g=d[f].find(),h=0;e.length>h;++h){var i=e[h];if(cc(g.from,i.to)&&!cc(g.to,i.from)){var j=[h,1];cc(i.from,g.from)&&j.push({from:i.from,to:g.from}),cc(g.to,i.to)&&j.push({from:g.to,to:i.to}),e.splice.apply(e,j),h+=j.length-1}}return e}function Tc(a,b){var d,c=r&&a.markedSpans;if(c)for(var e,f=0;c.length>f;++f)e=c[f],e.marker.collapsed&&(null==e.from||b>e.from)&&(null==e.to||e.to>b)&&(!d||d.width<e.marker.width)&&(d=e.marker);return d}function Uc(a){return Tc(a,-1)}function Vc(a){return Tc(a,a.text.length+1)}function Wc(a,b){for(var c;c=Uc(b);)b=rd(a,c.find().from.line);return b}function Xc(a){var b=r&&a.markedSpans;if(b)for(var c,d=0;b.length>d;++d)if(c=b[d],c.marker.collapsed){if(null==c.from)return!0;if(0==c.from&&c.marker.inclusiveLeft&&Yc(a,c))return!0}}function Yc(a,b){if(null==b.to||b.marker.inclusiveRight&&b.to==a.text.length)return!0;for(var c,d=0;a.markedSpans.length>d;++d)if(c=a.markedSpans[d],c.marker.collapsed&&c.from==b.to&&(c.marker.inclusiveLeft||b.marker.inclusiveRight)&&Yc(a,c))return!0}function Zc(a){return"string"==typeof a?a:a.text}function $c(a){if("string"==typeof a)return null;for(var b=a.markedSpans,c=null,d=0;b.length>d;++d)b[d].marker.explicitlyCleared?c||(c=b.slice(0,d)):c&&c.push(b[d]);return c?c.length?c:null:b}function _c(a,b){return b?{text:a,markedSpans:b}:a}function ad(a){var b=a.markedSpans;if(b){for(var c=0;b.length>c;++c){var d=b[c].marker.lines,e=Ud(d,a);d.splice(e,1)}a.markedSpans=null}}function bd(a,b){if(b){for(var c=0;b.length>c;++c)b[c].marker.lines.push(a);a.markedSpans=b}}function cd(a,b,c){var d={text:a,height:c};return bd(d,b),Xc(d)&&(d.height=0),d}function dd(a,b,c,d){b.text=c,b.stateAfter=b.styles=null,null!=b.order&&(b.order=null),ad(b),bd(b,d),Xc(b)?b.height=0:b.height||(b.height=ib(a.display)),Kd(a,b,"change")}function ed(a){a.parent=null,ad(a)}function fd(a,b,c){var d=a.view.mode,e=a.options.flattenSpans,f=!b.styles,g=0,h="",i=null,j=new Jc(b.text,a.options.tabSize),k=b.styles||(b.styles=[]);for(""==b.text&&d.blankLine&&d.blankLine(c);!j.eol();){var l=d.token(j,c),m=j.current();if(j.start=j.pos,e&&i==l?h+=m:(h&&(f=f||g>=k.length||h!=k[g]||i!=k[g+1],k[g++]=h,k[g++]=i),h=m,i=l),j.pos>5e3)break}return h&&(f=f||g>=k.length||h!=k[g]||i!=k[g+1],k[g++]=h,k[g++]=i),j.pos>5e3&&(k[g++]=b.text.slice(j.pos),k[g++]=null),g!=k.length&&(k.length=g,f=!0),f}function gd(a,b,c){var d=a.view.mode,e=new Jc(b.text,a.options.tabSize);for(""==b.text&&d.blankLine&&d.blankLine(c);!e.eol()&&5e3>=e.pos;)d.token(e,c),e.start=e.pos}function id(a){return a?hd[a]||(hd[a]="cm-"+a.replace(/ +/g," cm-")):null}function jd(a,b,c){for(var d,f,g,e=b,h=!0;d=Uc(e);)h=!1,e=rd(a.view.doc,d.find().from.line),f||(f=e);var i={pre:_d("pre"),col:0,pos:0,display:!c,measure:null,addedOne:!1,cm:a};e.textClass&&(i.pre.className=e.textClass);do{e.styles||fd(a,e,e.stateAfter=X(a,td(e))),i.measure=e==b&&c,i.pos=0,i.addToken=i.measure?md:ld,c&&g&&e!=b&&!i.addedOne&&(c[0]=i.pre.appendChild(ie(a.display.measure)),i.addedOne=!0);var j=od(e,i);g=e==f,j&&(e=rd(a.view.doc,j.to.line),h=!1)}while(j);return c&&!i.addedOne&&(c[0]=i.pre.appendChild(h?_d("span","\u00a0"):ie(a.display.measure))),i.pre.firstChild||Xc(b)||i.pre.appendChild(document.createTextNode("\u00a0")),i.pre}function ld(a,b,c,d,e){if(b){if(kd.test(b))for(var f=document.createDocumentFragment(),g=0;;){kd.lastIndex=g;var h=kd.exec(b),i=h?h.index-g:b.length-g;if(i&&(f.appendChild(document.createTextNode(b.slice(g,g+i))),a.col+=i),!h)break;if(g+=i+1," "==h[0]){var j=a.cm.options.tabSize,k=j-a.col%j;f.appendChild(_d("span",Rd(k),"cm-tab")),a.col+=k}else{var l=_d("span","\u2022","cm-invalidchar");l.title="\\u"+h[0].charCodeAt(0).toString(16),f.appendChild(l),a.col+=1}}else{a.col+=b.length;var f=document.createTextNode(b)}if(c||d||e||a.measure){var m=c||"";return d&&(m+=d),e&&(m+=e),a.pre.appendChild(_d("span",[f],m))}a.pre.appendChild(f)}}function md(a,b,c,d,e){for(var f=0;b.length>f;++f)f&&b.length-1>f&&a.cm.options.lineWrapping&&ee.test(b.slice(f-1,f+1))&&a.pre.appendChild(_d("wbr")),a.measure[a.pos++]=ld(a,b.charAt(f),c,0==f&&d,f==b.length-1&&e);b.length&&(a.addedOne=!0)}function nd(a,b,c){c&&(a.display||(c=c.cloneNode(!0)),a.pre.appendChild(c),a.measure&&b&&(a.measure[a.pos]=c,a.addedOne=!0)),a.pos+=b}function od(a,b){var c=a.styles,d=a.markedSpans;if(d)for(var j,l,m,n,o,f=a.text,g=f.length,h=0,e=0,i="",k=0;;){if(k==h){l=m=n="",o=null,k=1/0;for(var p=null,q=0;d.length>q;++q){var r=d[q],s=r.marker;h>=r.from&&(null==r.to||r.to>h)?(null!=r.to&&k>r.to&&(k=r.to,m=""),s.className&&(l+=" "+s.className),s.startStyle&&r.from==h&&(n+=" "+s.startStyle),s.endStyle&&r.to==k&&(m+=" "+s.endStyle),s.collapsed&&(!o||o.marker.width<s.width)&&(o=r)):r.from>h&&k>r.from&&(k=r.from),"bookmark"==s.type&&r.from==h&&s.replacedWith&&(p=s.replacedWith)}if(o&&(o.from||0)==h&&(nd(b,(null==o.to?g:o.to)-h,null!=o.from&&o.marker.replacedWith),null==o.to))return o.marker.find();p&&!o&&nd(b,0,p)}if(h>=g)break;for(var t=Math.min(g,k);;){if(i){var u=h+i.length;if(!o){var v=u>t?i.slice(0,t-h):i;b.addToken(b,v,j+l,n,h+v.length==k?m:"")}if(u>=t){i=i.slice(t-h),h=t;break}h=u,n=""}i=c[e++],j=id(c[e++])}}else for(var e=0;c.length>e;e+=2)b.addToken(b,c[e],id(c[e+1]))}function pd(a){this.lines=a,this.parent=null;for(var b=0,c=a.length,d=0;c>b;++b)a[b].parent=this,d+=a[b].height;this.height=d}function qd(a){this.children=a;for(var b=0,c=0,d=0,e=a.length;e>d;++d){var f=a[d];b+=f.chunkSize(),c+=f.height,f.parent=this}this.size=b,this.height=c,this.parent=null}function rd(a,b){for(;!a.lines;)for(var c=0;;++c){var d=a.children[c],e=d.chunkSize();if(e>b){a=d;break}b-=e}return a.lines[b]}function sd(a,b){for(var c=b-a.height,d=a;d;d=d.parent)d.height+=c}function td(a){if(null==a.parent)return null;for(var b=a.parent,c=Ud(b.lines,a),d=b.parent;d;b=d,d=d.parent)for(var e=0;d.children[e]!=b;++e)c+=d.children[e].chunkSize();return c}function ud(a,b){var c=0;a:do{for(var d=0,e=a.children.length;e>d;++d){var f=a.children[d],g=f.height;if(g>b){a=f;continue a}b-=g,c+=f.chunkSize()}return c}while(!a.lines);for(var d=0,e=a.lines.length;e>d;++d){var h=a.lines[d],i=h.height;if(i>b)break;b-=i}return c+d}function vd(a,b){b=Wc(a.view.doc,b);for(var c=0,d=b.parent,e=0;d.lines.length>e;++e){var f=d.lines[e];if(f==b)break;c+=f.height}for(var g=d.parent;g;d=g,g=d.parent)for(var e=0;g.children.length>e;++e){var h=g.children[e];if(h==d)break;c+=h.height}return c}function wd(a){var b=a.order;return null==b&&(b=a.order=we(a.text)),b}function xd(){return{done:[],undone:[],lastTime:0,lastOp:null,lastOrigin:null,dirtyCounter:0}}function yd(a,b,c,d,e,f,g,h,i){var j=a.view.history;j.undone.length=0;var k=+new Date,l=Sd(j.done);if(l&&(j.lastOp==a.curOp.id||j.lastOrigin==e&&("input"==e||"delete"==e)&&j.lastTime>k-600)){var m=Sd(l.events);if(m.start>b+d.length||b>m.start+m.added)l.events.push({start:b,added:c,old:d});else{for(var n=Math.max(0,m.start-b),o=Math.max(0,b+d.length-(m.start+m.added)),p=n;p>0;--p)m.old.unshift(d[p-1]);for(var p=o;p>0;--p)m.old.push(d[d.length-p]);n&&(m.start=b),m.added+=c-(d.length-n-o)}l.fromAfter=h,l.toAfter=i}else{for(l={events:[{start:b,added:c,old:d}],fromBefore:f,toBefore:g,fromAfter:h,toAfter:i},j.done.push(l);j.done.length>a.options.undoDepth;)j.done.shift();0>j.dirtyCounter?j.dirtyCounter=0/0:j.dirtyCounter++}j.lastTime=k,j.lastOp=a.curOp.id,j.lastOrigin=e}function zd(){Dd(this)}function Ad(a){return a.stop||(a.stop=zd),a}function Bd(a){a.preventDefault?a.preventDefault():a.returnValue=!1}function Cd(a){a.stopPropagation?a.stopPropagation():a.cancelBubble=!0}function Dd(a){Bd(a),Cd(a)}function Ed(a){return a.target||a.srcElement}function Fd(a){var b=a.which;return null==b&&(1&a.button?b=1:2&a.button?b=3:4&a.button&&(b=2)),p&&a.ctrlKey&&1==b&&(b=3),b}function Gd(a,b){var c=a.override&&a.override.hasOwnProperty(b);return c?a.override[b]:a[b]}function Hd(a,b,c){if(a.addEventListener)a.addEventListener(b,c,!1);else if(a.attachEvent)a.attachEvent("on"+b,c);else{var d=a._handlers||(a._handlers={}),e=d[b]||(d[b]=[]);e.push(c)}}function Id(a,b,c){if(a.removeEventListener)a.removeEventListener(b,c,!1);else if(a.detachEvent)a.detachEvent("on"+b,c);else{var d=a._handlers&&a._handlers[b];if(!d)return;for(var e=0;d.length>e;++e)if(d[e]==c){d.splice(e,1);break}}}function Jd(a,b){var c=a._handlers&&a._handlers[b];if(c)for(var d=Array.prototype.slice.call(arguments,2),e=0;c.length>e;++e)c[e].apply(null,d)}function Kd(a,b,c){function g(a){return function(){a.apply(null,e)}}var d=b._handlers&&b._handlers[c];if(d)for(var e=Array.prototype.slice.call(arguments,3),f=a.curOp&&a.curOp.delayedCallbacks,h=0;d.length>h;++h)f?f.push(g(d[h])):d[h].apply(null,e)}function Ld(a,b){var c=a._handlers&&a._handlers[b];return c&&c.length>0}function Od(){this.id=null}function Pd(a,b,c){null==b&&(b=a.search(/[^\s\u00a0]/),-1==b&&(b=a.length));for(var d=0,e=0;b>d;++d)" "==a.charAt(d)?e+=c-e%c:++e;return e}function Rd(a){for(;a>=Qd.length;)Qd.push(Sd(Qd)+" ");return Qd[a]}function Sd(a){return a[a.length-1]}function Td(a){n?(a.selectionStart=0,a.selectionEnd=a.value.length):a.select()}function Ud(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;d>c;++c)if(a[c]==b)return c;return-1}function Vd(a){for(var b=[],c=0;a>c;++c)b.push(void 0);return b}function Wd(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b)}}function Yd(a){return/\w/.test(a)||a>"\u0080"&&(a.toUpperCase()!=a.toLowerCase()||Xd.test(a))}function Zd(a){var b=0;for(var c in a)a.hasOwnProperty(c)&&a[c]&&++b;return!b}function _d(a,b,c,d){var e=document.createElement(a);if(c&&(e.className=c),d&&(e.style.cssText=d),"string"==typeof b)ce(e,b);else if(b)for(var f=0;b.length>f;++f)e.appendChild(b[f]);return e}function ae(a){return a.innerHTML="",a}function be(a,b){return ae(a).appendChild(b)}function ce(a,b){d?(a.innerHTML="",a.appendChild(document.createTextNode(b))):a.textContent=b}function ge(a){if(null!=fe)return fe;var b=_d("div",null,null,"width: 50px; height: 50px; overflow-x: scroll");return be(a,b),b.offsetWidth&&(fe=b.offsetHeight-b.clientHeight),fe||0}function ie(a){if(null==he){var b=_d("span","\u200b");be(a,_d("span",[b,document.createTextNode("x")])),0!=a.firstChild.offsetHeight&&(he=1>=b.offsetWidth&&b.offsetHeight>2&&!c)}return he?_d("span","\u200b"):_d("span","\u00a0",null,"display: inline-block; width: 1px; margin-right: -1px")}function ne(a,b,c,d){if(!a)return d(b,c,"ltr");for(var e=0;a.length>e;++e){var f=a[e];c>f.from&&f.to>b&&d(Math.max(f.from,b),Math.min(f.to,c),1==f.level?"rtl":"ltr")}}function oe(a){return a.level%2?a.to:a.from}function pe(a){return a.level%2?a.from:a.to}function qe(a){var b=wd(a);return b?oe(b[0]):0}function re(a){var b=wd(a);return b?pe(Sd(b)):a.text.length}function se(a,b){var c=rd(a.view.doc,b),d=Wc(a.view.doc,c);d!=c&&(b=td(d));var e=wd(d),f=e?e[0].level%2?re(d):qe(d):0;return{line:b,ch:f}}function te(a,b){for(var c,d;c=Vc(d=rd(a.view.doc,b));)b=c.find().to.line;var e=wd(d),f=e?e[0].level%2?qe(d):re(d):d.text.length;return{line:b,ch:f}}function ue(a,b,c,d){var e=wd(a);if(!e)return ve(a,b,c,d);for(var f=d?function(b,c){do b+=c;while(b>0&&$d.test(a.text.charAt(b)));return b}:function(a,b){return a+b},g=e[0].level,h=0;e.length>h;++h){var i=e[h],j=i.level%2==g;if(b>i.from&&i.to>b||j&&(i.from==b||i.to==b))break}for(var k=f(b,i.level%2?-c:c);null!=k;)if(i.level%2==g){if(!(i.from>k||k>i.to))break;i=e[h+=c],k=i&&(c>0==i.level%2?f(i.to,-1):f(i.from,1))}else if(k==oe(i))i=e[--h],k=i&&pe(i);else{if(k!=pe(i))break;i=e[++h],k=i&&oe(i)}return 0>k||k>a.text.length?null:k}function ve(a,b,c,d){var e=b+c;if(d)for(;e>0&&$d.test(a.text.charAt(e));)e+=c;return 0>e||e>a.text.length?null:e}var hb,xb,yb,Gb,Hb,Ib,Jb,a=/gecko\/\d/i.test(navigator.userAgent),b=/MSIE \d/.test(navigator.userAgent),c=/MSIE [1-7]\b/.test(navigator.userAgent),d=/MSIE [1-8]\b/.test(navigator.userAgent),e=/WebKit\//.test(navigator.userAgent),f=e&&/Qt\/\d+\.\d+/.test(navigator.userAgent),g=/Chrome\//.test(navigator.userAgent),h=/Opera\//.test(navigator.userAgent),i=/Apple Computer/.test(navigator.vendor),j=/KHTML\//.test(navigator.userAgent),k=/Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent),l=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),m=/PhantomJS/.test(navigator.userAgent),n=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),o=n||/Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent),p=n||/Mac/.test(navigator.platform),q=!1,r=!1,Fb=0,Kb=null;b?Kb=-.53:a?Kb=15:g?Kb=-.7:i&&(Kb=-1/3);var Ob,Wb,Rb=null;s.prototype={getValue:function(a){var b=[],c=this.view.doc;return c.iter(0,c.size,function(a){b.push(a.text)}),b.join(a||"\n")},setValue:mb(null,function(a){var b=this.view.doc,c={line:0,ch:0},d=rd(b,b.size-1).text.length;Zb(this,c,{line:b.size-1,ch:d},je(a),c,c,"setValue")}),getSelection:function(a){return this.getRange(this.view.sel.from,this.view.sel.to,a)},replaceSelection:mb(null,function(a,b,c){var d=this.view.sel;Yb(this,d.from,d.to,je(a),b||"around",c)}),focus:function(){window.focus(),sb(this),Ub(this),pb(this)},setOption:function(a,b){var c=this.options,d=c[a];(c[a]!=b||"mode"==a)&&(c[a]=b,uc.hasOwnProperty(a)&&mb(this,uc[a])(this,b,d))},getOption:function(a){return this.options[a]},getMode:function(){return this.view.mode},addKeyMap:function(a){this.view.keyMaps.push(a)},removeKeyMap:function(a){for(var b=this.view.keyMaps,c=0;b.length>c;++c)if(("string"==typeof a?b[c].name:b[c])==a)return b.splice(c,1),!0},undo:mb(null,function(){$b(this,"undo")}),redo:mb(null,function(){$b(this,"redo")}),indentLine:mb(null,function(a,b,c){"string"!=typeof b&&(b=null==b?this.options.smartIndent?"smart":"prev":b?"add":"subtract"),gc(this.view.doc,a)&&pc(this,a,b,c)}),indentSelection:mb(null,function(a){var b=this.view.sel;if(bc(b.from,b.to))return pc(this,b.from.line,a);for(var c=b.to.line-(b.to.ch?0:1),d=b.from.line;c>=d;++d)pc(this,d,a)}),historySize:function(){var a=this.view.history;return{undo:a.done.length,redo:a.undone.length}},clearHistory:function(){this.view.history=xd()},markClean:function(){this.view.history.dirtyCounter=0,this.view.history.lastOp=this.view.history.lastOrigin=null},isClean:function(){return 0==this.view.history.dirtyCounter},getHistory:function(){function b(a){for(var d,b=0,c=[];a.length>b;++b){var e=a[b];c.push({events:d=[],fromBefore:e.fromBefore,toBefore:e.toBefore,fromAfter:e.fromAfter,toAfter:e.toAfter});for(var f=0,g=e.events;g.length>f;++f){var h=[],i=g[f];d.push({start:i.start,added:i.added,old:h});for(var j=0;i.old.length>j;++j)h.push(Zc(i.old[j]))}}return c}var a=this.view.history;return{done:b(a.done),undone:b(a.undone)}},setHistory:function(a){var b=this.view.history=xd();b.done=a.done,b.undone=a.undone},getTokenAt:function(a){var b=this.view.doc;a=fc(b,a);for(var c=X(this,a.line),d=this.view.mode,e=rd(b,a.line),f=new Jc(e.text,this.options.tabSize);f.pos<a.ch&&!f.eol();){f.start=f.pos;var g=d.token(f,c)}return{start:f.start,end:f.pos,string:f.current(),className:g||null,type:g||null,state:c}},getStateAfter:function(a){var b=this.view.doc;return a=ec(b,null==a?b.size-1:a),X(this,a+1)},cursorCoords:function(a,b){var c,d=this.view.sel;return c=null==a?d.head:"object"==typeof a?fc(this.view.doc,a):a?d.from:d.to,eb(this,c,b||"page")},charCoords:function(a,b){return db(this,fc(this.view.doc,a),b||"page")},coordsChar:function(a){var b=this.display.lineSpace.getBoundingClientRect();return fb(this,a.left-b.left,a.top-b.top)},defaultTextHeight:function(){return ib(this.display)},markText:mb(null,function(a,b,c){return Lc(this,fc(this.view.doc,a),fc(this.view.doc,b),c,"range")}),setBookmark:mb(null,function(a,b){return a=fc(this.view.doc,a),Lc(this,a,a,b?{replacedWith:b}:{},"bookmark")}),findMarksAt:function(a){var b=this.view.doc;a=fc(b,a);var c=[],d=rd(b,a.line).markedSpans;if(d)for(var e=0;d.length>e;++e){var f=d[e];(null==f.from||f.from<=a.ch)&&(null==f.to||f.to>=a.ch)&&c.push(f.marker)}return c},setGutterMarker:mb(null,function(a,b,c){return qc(this,a,function(a){var d=a.gutterMarkers||(a.gutterMarkers={});return d[b]=c,!c&&Zd(d)&&(a.gutterMarkers=null),!0})}),clearGutter:mb(null,function(a){var b=0,c=this,d=c.view.doc;d.iter(0,d.size,function(d){d.gutterMarkers&&d.gutterMarkers[a]&&(d.gutterMarkers[a]=null,nb(c,b,b+1),Zd(d.gutterMarkers)&&(d.gutterMarkers=null)),++b})}),addLineClass:mb(null,function(a,b,c){return qc(this,a,function(a){var d="text"==b?"textClass":"background"==b?"bgClass":"wrapClass";if(a[d]){if(RegExp("\\b"+c+"\\b").test(a[d]))return!1;a[d]+=" "+c}else a[d]=c;return!0})}),removeLineClass:mb(null,function(a,b,c){return qc(this,a,function(a){var d="text"==b?"textClass":"background"==b?"bgClass":"wrapClass",e=a[d];if(!e)return!1;if(null==c)a[d]=null;else{var f=e.replace(RegExp("^"+c+"\\b\\s*|\\s*\\b"+c+"\\b"),"");if(f==e)return!1;a[d]=f||null}return!0})}),addLineWidget:mb(null,function(a,b,c){var d=c||{};return d.node=b,d.noHScroll&&(this.display.alignWidgets=!0),qc(this,a,function(a){return(a.widgets||(a.widgets=[])).push(d),d.line=a,!0}),d}),removeLineWidget:mb(null,function(a){var b=a.line.widgets,c=td(a.line);if(null!=c){for(var d=0;b.length>d;++d)b[d]==a&&b.splice(d--,1);nb(this,c,c+1)}}),lineInfo:function(a){if("number"==typeof a){if(!gc(this.view.doc,a))return null;var b=a;if(a=rd(this.view.doc,a),!a)return null}else{var b=td(a);if(null==b)return null}return{line:b,handle:a,text:a.text,gutterMarkers:a.gutterMarkers,textClass:a.textClass,bgClass:a.bgClass,wrapClass:a.wrapClass,widgets:a.widgets}},getViewport:function(){return{from:this.display.showingFrom,to:this.display.showingTo}},addWidget:function(a,b,c,d,e){var f=this.display;a=eb(this,fc(this.view.doc,a));var g=a.top,h=a.left;if(b.style.position="absolute",f.sizer.appendChild(b),"over"==d)g=a.top;else if("near"==d){var i=Math.max(f.wrapper.clientHeight,this.view.doc.height),j=Math.max(f.sizer.clientWidth,f.lineSpace.clientWidth);a.bottom+b.offsetHeight>i&&a.top>b.offsetHeight&&(g=a.top-b.offsetHeight),h+b.offsetWidth>j&&(h=j-b.offsetWidth)}b.style.top=g+Y(f)+"px",b.style.left=b.style.right="","right"==e?(h=f.sizer.clientWidth-b.offsetWidth,b.style.right="0px"):("left"==e?h=0:"middle"==e&&(h=(f.sizer.clientWidth-b.offsetWidth)/2),b.style.left=h+"px"),c&&nc(this,h,g,h+b.offsetWidth,g+b.offsetHeight)},lineCount:function(){return this.view.doc.size},clipPos:function(a){return fc(this.view.doc,a)},getCursor:function(a){var c,b=this.view.sel;return c=null==a||"head"==a?b.head:"anchor"==a?b.anchor:"end"==a||a===!1?b.to:b.from,dc(c)},somethingSelected:function(){return!bc(this.view.sel.from,this.view.sel.to)},setCursor:mb(null,function(a,b,c){var d=fc(this.view.doc,"number"==typeof a?{line:a,ch:b||0}:a);c?hc(this,d):ic(this,d,d)}),setSelection:mb(null,function(a,b){var c=this.view.doc;ic(this,fc(c,a),fc(c,b||a))}),extendSelection:mb(null,function(a,b){var c=this.view.doc;hc(this,fc(c,a),b&&fc(c,b))}),setExtending:function(a){this.view.sel.extend=a},getLine:function(a){var b=this.getLineHandle(a);return b&&b.text},getLineHandle:function(a){var b=this.view.doc;return gc(b,a)?rd(b,a):void 0},getLineNumber:function(a){return td(a)},setLine:mb(null,function(a,b){gc(this.view.doc,a)&&ac(this,b,{line:a,ch:0},{line:a,ch:rd(this.view.doc,a).text.length})}),removeLine:mb(null,function(a){gc(this.view.doc,a)&&ac(this,"",{line:a,ch:0},fc(this.view.doc,{line:a+1,ch:0}))}),replaceRange:mb(null,function(a,b,c){var d=this.view.doc;return b=fc(d,b),c=c?fc(d,c):b,ac(this,a,b,c)}),getRange:function(a,b,c){var d=this.view.doc;a=fc(d,a),b=fc(d,b);var e=a.line,f=b.line;if(e==f)return rd(d,e).text.slice(a.ch,b.ch);var g=[rd(d,e).text.slice(a.ch)];return d.iter(e+1,f,function(a){g.push(a.text)
3
+ }),g.push(rd(d,f).text.slice(0,b.ch)),g.join(c||"\n")},triggerOnKeyDown:mb(null,Sb),execCommand:function(a){return Ec[a](this)},moveH:mb(null,function(a,b){var c=this.view.sel,d=0>a?c.from:c.to;(c.shift||c.extend||bc(c.from,c.to))&&(d=rc(this,a,b,!0)),hc(this,d,d,a)}),deleteH:mb(null,function(a,b){var c=this.view.sel;bc(c.from,c.to)?ac(this,"",c.from,rc(this,a,b,!1),"delete"):ac(this,"",c.from,c.to,"delete"),this.curOp.userSelChange=!0}),moveV:mb(null,function(a,b){var i,c=this.view,d=c.doc,e=this.display,f=c.sel.head,g=eb(this,f,"div"),h=g.left;if(null!=c.goalColumn&&(h=c.goalColumn),"page"==b){var j=Math.min(e.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);i=g.top+a*j}else"line"==b&&(i=a>0?g.bottom+3:g.top-3);do{var k=fb(this,h,i);i+=5*a}while(k.outside&&(0>a?i>0:d.height>i));"page"==b&&(e.scrollbarV.scrollTop+=db(this,k,"div").top-g.top),hc(this,k,k,a),c.goalColumn=h}),toggleOverwrite:function(){(this.view.overwrite=!this.view.overwrite)?this.display.cursor.className+=" CodeMirror-overwrite":this.display.cursor.className=this.display.cursor.className.replace(" CodeMirror-overwrite","")},posFromIndex:function(a){var c,b=0,d=this.view.doc;return d.iter(0,d.size,function(d){var e=d.text.length+1;return e>a?(c=a,!0):(a-=e,++b,void 0)}),fc(d,{line:b,ch:c})},indexFromPos:function(a){if(0>a.line||0>a.ch)return 0;var b=a.ch;return this.view.doc.iter(0,a.line,function(a){b+=a.text.length+1}),b},scrollTo:function(a,b){null!=a&&(this.display.scrollbarH.scrollLeft=this.display.scroller.scrollLeft=a),null!=b&&(this.display.scrollbarV.scrollTop=this.display.scroller.scrollTop=b),K(this,[])},getScrollInfo:function(){var a=this.display.scroller,b=Md;return{left:a.scrollLeft,top:a.scrollTop,height:a.scrollHeight-b,width:a.scrollWidth-b,clientHeight:a.clientHeight-b,clientWidth:a.clientWidth-b}},scrollIntoView:function(a){"number"==typeof a&&(a={line:a,ch:0}),a=a?fc(this.view.doc,a):this.view.sel.head,mc(this,a)},setSize:function(a,b){function c(a){return"number"==typeof a||/^\d+$/.test(a+"")?a+"px":a}null!=a&&(this.display.wrapper.style.width=c(a)),null!=b&&(this.display.wrapper.style.height=c(b)),this.refresh()},on:function(a,b){Hd(this,a,b)},off:function(a,b){Id(this,a,b)},operation:function(a){return mb(this,a)()},refresh:function(){bb(this),this.display.scroller.scrollHeight>this.view.scrollTop&&(this.display.scrollbarV.scrollTop=this.display.scroller.scrollTop=this.view.scrollTop),K(this,!0)},getInputField:function(){return this.display.input},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}};var uc=s.optionHandlers={},vc=s.defaults={},xc=s.Init={toString:function(){return"CodeMirror.Init"}};wc("value","",function(a,b){a.setValue(b)},!0),wc("mode",null,v,!0),wc("indentUnit",2,v,!0),wc("indentWithTabs",!1),wc("smartIndent",!0),wc("tabSize",4,function(a){v(a),bb(a),K(a,!0)},!0),wc("electricChars",!0),wc("theme","default",function(a){y(a),z(a)},!0),wc("keyMap","default",x),wc("extraKeys",null),wc("onKeyEvent",null),wc("onDragEvent",null),wc("lineWrapping",!1,w,!0),wc("gutters",[],function(a){D(a.options),z(a)},!0),wc("lineNumbers",!1,function(a){D(a.options),z(a)},!0),wc("firstLineNumber",1,z,!0),wc("lineNumberFormatter",function(a){return a},z,!0),wc("showCursorWhenSelecting",!1,Q,!0),wc("readOnly",!1,function(a,b){"nocursor"==b?(Vb(a),a.display.input.blur()):b||rb(a,!0)}),wc("dragDrop",!0),wc("cursorBlinkRate",530),wc("cursorHeight",1),wc("workTime",100),wc("workDelay",100),wc("flattenSpans",!0),wc("pollInterval",100),wc("undoDepth",40),wc("viewportMargin",10,function(a){a.refresh()},!0),wc("tabindex",null,function(a,b){a.display.input.tabIndex=b||""}),wc("autofocus",null);var yc=s.modes={},zc=s.mimeModes={};s.defineMode=function(a,b){if(s.defaults.mode||"null"==a||(s.defaults.mode=a),arguments.length>2){b.dependencies=[];for(var c=2;arguments.length>c;++c)b.dependencies.push(arguments[c])}yc[a]=b},s.defineMIME=function(a,b){zc[a]=b},s.resolveMode=function(a){if("string"==typeof a&&zc.hasOwnProperty(a))a=zc[a];else if("string"==typeof a&&/^[\w\-]+\/[\w\-]+\+xml$/.test(a))return s.resolveMode("application/xml");return"string"==typeof a?{name:a}:a||{name:"null"}},s.getMode=function(a,b){var b=s.resolveMode(b),c=yc[b.name];if(!c)return s.getMode(a,"text/plain");var d=c(a,b);if(Ac.hasOwnProperty(b.name)){var e=Ac[b.name];for(var f in e)e.hasOwnProperty(f)&&(d.hasOwnProperty(f)&&(d["_"+f]=d[f]),d[f]=e[f])}return d.name=b.name,d},s.defineMode("null",function(){return{token:function(a){a.skipToEnd()}}}),s.defineMIME("text/plain","null");var Ac=s.modeExtensions={};s.extendMode=function(a,b){var c=Ac.hasOwnProperty(a)?Ac[a]:Ac[a]={};for(var d in b)b.hasOwnProperty(d)&&(c[d]=b[d])},s.defineExtension=function(a,b){s.prototype[a]=b},s.defineOption=wc;var Bc=[];s.defineInitHook=function(a){Bc.push(a)},s.copyState=Cc,s.startState=Dc,s.innerMode=function(a,b){for(;a.innerMode;){var c=a.innerMode(b);b=c.state,a=c.mode}return c||{mode:a,state:b}};var Ec=s.commands={selectAll:function(a){a.setSelection({line:0,ch:0},{line:a.lineCount()-1})},killLine:function(a){var b=a.getCursor(!0),c=a.getCursor(!1),d=!bc(b,c);d||a.getLine(b.line).length!=b.ch?a.replaceRange("",b,d?c:{line:b.line},"delete"):a.replaceRange("",b,{line:b.line+1,ch:0},"delete")},deleteLine:function(a){var b=a.getCursor().line;a.replaceRange("",{line:b,ch:0},{line:b},"delete")},undo:function(a){a.undo()},redo:function(a){a.redo()},goDocStart:function(a){a.extendSelection({line:0,ch:0})},goDocEnd:function(a){a.extendSelection({line:a.lineCount()-1})},goLineStart:function(a){a.extendSelection(se(a,a.getCursor().line))},goLineStartSmart:function(a){var b=a.getCursor(),c=se(a,b.line),d=a.getLineHandle(c.line),e=wd(d);if(e&&0!=e[0].level)a.extendSelection(c);else{var f=Math.max(0,d.text.search(/\S/)),g=b.line==c.line&&f>=b.ch&&b.ch;a.extendSelection({line:c.line,ch:g?0:f})}},goLineEnd:function(a){a.extendSelection(te(a,a.getCursor().line))},goLineUp:function(a){a.moveV(-1,"line")},goLineDown:function(a){a.moveV(1,"line")},goPageUp:function(a){a.moveV(-1,"page")},goPageDown:function(a){a.moveV(1,"page")},goCharLeft:function(a){a.moveH(-1,"char")},goCharRight:function(a){a.moveH(1,"char")},goColumnLeft:function(a){a.moveH(-1,"column")},goColumnRight:function(a){a.moveH(1,"column")},goWordLeft:function(a){a.moveH(-1,"word")},goWordRight:function(a){a.moveH(1,"word")},delCharBefore:function(a){a.deleteH(-1,"char")},delCharAfter:function(a){a.deleteH(1,"char")},delWordBefore:function(a){a.deleteH(-1,"word")},delWordAfter:function(a){a.deleteH(1,"word")},indentAuto:function(a){a.indentSelection("smart")},indentMore:function(a){a.indentSelection("add")},indentLess:function(a){a.indentSelection("subtract")},insertTab:function(a){a.replaceSelection(" ","end","input")},defaultTab:function(a){a.somethingSelected()?a.indentSelection("add"):a.replaceSelection(" ","end","input")},transposeChars:function(a){var b=a.getCursor(),c=a.getLine(b.line);b.ch>0&&b.ch<c.length-1&&a.replaceRange(c.charAt(b.ch)+c.charAt(b.ch-1),{line:b.line,ch:b.ch-1},{line:b.line,ch:b.ch+1})},newlineAndIndent:function(a){mb(a,function(){a.replaceSelection("\n","end","input"),a.indentLine(a.getCursor().line,null,!0)})()},toggleOverwrite:function(a){a.toggleOverwrite()}},Fc=s.keyMap={};Fc.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite"},Fc.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Alt-Up":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Down":"goDocEnd","Ctrl-Left":"goWordLeft","Ctrl-Right":"goWordRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delWordBefore","Ctrl-Delete":"delWordAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore",fallthrough:"basic"},Fc.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goWordLeft","Alt-Right":"goWordRight","Cmd-Left":"goLineStart","Cmd-Right":"goLineEnd","Alt-Backspace":"delWordBefore","Ctrl-Alt-Backspace":"delWordAfter","Alt-Delete":"delWordAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore",fallthrough:["basic","emacsy"]},Fc["default"]=p?Fc.macDefault:Fc.pcDefault,Fc.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars"},s.isModifierKey=Ic,s.fromTextArea=function(a,b){function e(){a.value=i.getValue()}if(b||(b={}),b.value=a.value,!b.tabindex&&a.tabindex&&(b.tabindex=a.tabindex),null==b.autofocus){var c=document.body;try{c=document.activeElement}catch(d){}b.autofocus=c==a||null!=a.getAttribute("autofocus")&&c==document.body}if(a.form){Hd(a.form,"submit",e);var f=a.form,g=f.submit;try{f.submit=function h(){e(),f.submit=g,f.submit(),f.submit=h}}catch(d){}}a.style.display="none";var i=s(function(b){a.parentNode.insertBefore(b,a.nextSibling)},b);return i.save=e,i.getTextArea=function(){return a},i.toTextArea=function(){e(),a.parentNode.removeChild(i.getWrapperElement()),a.style.display="",a.form&&(Id(a.form,"submit",e),"function"==typeof a.form.submit&&(a.form.submit=g))},i},Jc.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return 0==this.pos},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){return this.pos<this.string.length?this.string.charAt(this.pos++):void 0},eat:function(a){var b=this.string.charAt(this.pos);if("string"==typeof a)var c=b==a;else var c=b&&(a.test?a.test(b):a(b));return c?(++this.pos,b):void 0},eatWhile:function(a){for(var b=this.pos;this.eat(a););return this.pos>b},eatSpace:function(){for(var a=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>a},skipToEnd:function(){this.pos=this.string.length},skipTo:function(a){var b=this.string.indexOf(a,this.pos);return b>-1?(this.pos=b,!0):void 0},backUp:function(a){this.pos-=a},column:function(){return Pd(this.string,this.start,this.tabSize)},indentation:function(){return Pd(this.string,null,this.tabSize)},match:function(a,b,c){if("string"!=typeof a){var e=this.string.slice(this.pos).match(a);return e&&e.index>0?null:(e&&b!==!1&&(this.pos+=e[0].length),e)}var d=function(a){return c?a.toLowerCase():a};return d(this.string).indexOf(d(a),this.pos)==this.pos?(b!==!1&&(this.pos+=a.length),!0):void 0},current:function(){return this.string.slice(this.start,this.pos)}},s.StringStream=Jc,Kc.prototype.clear=function(){if(!this.explicitlyCleared){kb(this.cm);for(var a=null,b=null,c=0;this.lines.length>c;++c){var d=this.lines[c],e=Mc(d.markedSpans,this);null!=e.to&&(b=td(d)),d.markedSpans=Nc(d.markedSpans,e),null!=e.from?a=td(d):this.collapsed&&!Xc(d)&&sd(d,ib(this.cm.display))}null!=a&&nb(this.cm,a,b+1),this.lines.length=0,this.explicitlyCleared=!0,this.collapsed&&this.cm.view.cantEdit&&(this.cm.view.cantEdit=!1,jc(this.cm)),lb(this.cm),Kd(this.cm,this,"clear")}},Kc.prototype.find=function(){for(var a,b,c=0;this.lines.length>c;++c){var d=this.lines[c],e=Mc(d.markedSpans,this);if(null!=e.from||null!=e.to){var f=td(d);null!=e.from&&(a={line:f,ch:e.from}),null!=e.to&&(b={line:f,ch:e.to})}}return"bookmark"==this.type?a:a&&{from:a,to:b}},window.lineIsHidden=Xc;var hd={},kd=/[\t\u0000-\u0019\u200b\u2028\u2029\uFEFF]/g;pd.prototype={chunkSize:function(){return this.lines.length},remove:function(a,b,c){for(var d=a,e=a+b;e>d;++d){var f=this.lines[d];this.height-=f.height,ed(f),Kd(c,f,"delete")}this.lines.splice(a,b)},collapse:function(a){a.splice.apply(a,[a.length,0].concat(this.lines))},insertHeight:function(a,b,c){this.height+=c,this.lines=this.lines.slice(0,a).concat(b).concat(this.lines.slice(a));for(var d=0,e=b.length;e>d;++d)b[d].parent=this},iterN:function(a,b,c){for(var d=a+b;d>a;++a)if(c(this.lines[a]))return!0}},qd.prototype={chunkSize:function(){return this.size},remove:function(a,b,c){this.size-=b;for(var d=0;this.children.length>d;++d){var e=this.children[d],f=e.chunkSize();if(f>a){var g=Math.min(b,f-a),h=e.height;if(e.remove(a,g,c),this.height-=h-e.height,f==g&&(this.children.splice(d--,1),e.parent=null),0==(b-=g))break;a=0}else a-=f}if(25>this.size-b){var i=[];this.collapse(i),this.children=[new pd(i)],this.children[0].parent=this}},collapse:function(a){for(var b=0,c=this.children.length;c>b;++b)this.children[b].collapse(a)},insert:function(a,b){for(var c=0,d=0,e=b.length;e>d;++d)c+=b[d].height;this.insertHeight(a,b,c)},insertHeight:function(a,b,c){this.size+=b.length,this.height+=c;for(var d=0,e=this.children.length;e>d;++d){var f=this.children[d],g=f.chunkSize();if(g>=a){if(f.insertHeight(a,b,c),f.lines&&f.lines.length>50){for(;f.lines.length>50;){var h=f.lines.splice(f.lines.length-25,25),i=new pd(h);f.height-=i.height,this.children.splice(d+1,0,i),i.parent=this}this.maybeSpill()}break}a-=g}},maybeSpill:function(){if(!(10>=this.children.length)){var a=this;do{var b=a.children.splice(a.children.length-5,5),c=new qd(b);if(a.parent){a.size-=c.size,a.height-=c.height;var e=Ud(a.parent.children,a);a.parent.children.splice(e+1,0,c)}else{var d=new qd(a.children);d.parent=a,a.children=[d,c],a=d}c.parent=a.parent}while(a.children.length>10);a.parent.maybeSpill()}},iter:function(a,b,c){this.iterN(a,b-a,c)},iterN:function(a,b,c){for(var d=0,e=this.children.length;e>d;++d){var f=this.children[d],g=f.chunkSize();if(g>a){var h=Math.min(b,g-a);if(f.iterN(a,h,c))return!0;if(0==(b-=h))break;a=0}else a-=g}}},s.e_stop=Dd,s.e_preventDefault=Bd,s.e_stopPropagation=Cd,s.on=Hd,s.off=Id,s.signal=Jd;var Md=30,Nd=s.Pass={toString:function(){return"CodeMirror.Pass"}};Od.prototype={set:function(a,b){clearTimeout(this.id),this.id=setTimeout(b,a)}},s.countColumn=Pd;var Qd=[""],Xd=/[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc]/,$d=/[\u0300-\u036F\u0483-\u0487\u0488-\u0489\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\uA66F\uA670-\uA672\uA674-\uA67D\uA69F]/,de=function(){if(d)return!1;var a=_d("div");return"draggable"in a||"dragDrop"in a}(),ee=/^$/;a?ee=/$'/:i?ee=/\-[^ \-?]|\?[^ !'\"\),.\-\/:;\?\]\}]/:g&&(ee=/\-[^ \-\.?]|\?[^ \-\.?\]\}:;!'\"\),\/]|[\.!\"#&%\)*+,:;=>\]|\}~][\(\{\[<]|\$'/);var fe,he,je=3!="\n\nb".split(/\n/).length?function(a){for(var b=0,c=[],d=a.length;d>=b;){var e=a.indexOf("\n",b);-1==e&&(e=a.length);var f=a.slice(b,"\r"==a.charAt(e-1)?e-1:e),g=f.indexOf("\r");-1!=g?(c.push(f.slice(0,g)),b+=g+1):(c.push(f),b=e+1)}return c}:function(a){return a.split(/\r\n?|\n/)};s.splitLines=je;var ke=window.getSelection?function(a){try{return a.selectionStart!=a.selectionEnd}catch(b){return!1}}:function(a){try{var b=a.ownerDocument.selection.createRange()}catch(c){}return b&&b.parentElement()==a?0!=b.compareEndPoints("StartToEnd",b):!1},le=function(){var a=_d("div");return"oncopy"in a?!0:(a.setAttribute("oncopy","return;"),"function"==typeof a.oncopy)}(),me={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",91:"Mod",92:"Mod",93:"Mod",109:"-",107:"=",127:"Delete",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63276:"PageUp",63277:"PageDown",63275:"End",63273:"Home",63234:"Left",63232:"Up",63235:"Right",63233:"Down",63302:"Insert",63272:"Delete"};s.keyNames=me,function(){for(var a=0;10>a;a++)me[a+48]=a+"";for(var a=65;90>=a;a++)me[a]=String.fromCharCode(a);for(var a=1;12>=a;a++)me[a+111]=me[a+63235]="F"+a}();var we=function(){function c(c){return 255>=c?a.charAt(c):c>=1424&&1524>=c?"R":c>=1536&&1791>=c?b.charAt(c-1536):c>=1792&&2220>=c?"r":"L"}var a="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL",b="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr",d=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,e=/[stwN]/,f=/[LRr]/,g=/[Lb1n]/,h=/[1n]/;return function(a){if(!d.test(a))return!1;for(var l,b=a.length,i=[],j=null,k=0;b>k;++k)i.push(l=c(a.charCodeAt(k))),null==j&&("L"==l?j="L":("R"==l||"r"==l)&&(j="R"));null==j&&(j="L");for(var k=0,m=j;b>k;++k){var l=i[k];"m"==l?i[k]=m:m=l}for(var k=0,n=j;b>k;++k){var l=i[k];"1"==l&&"r"==n?i[k]="n":f.test(l)&&(n=l,"r"==l&&(i[k]="R"))}for(var k=1,m=i[0];b-1>k;++k){var l=i[k];"+"==l&&"1"==m&&"1"==i[k+1]?i[k]="1":","!=l||m!=i[k+1]||"1"!=m&&"n"!=m||(i[k]=m),m=l}for(var k=0;b>k;++k){var l=i[k];if(","==l)i[k]="N";else if("%"==l){for(var o=k+1;b>o&&"%"==i[o];++o);for(var p=k&&"!"==i[k-1]||b-1>o&&"1"==i[o]?"1":"N",q=k;o>q;++q)i[q]=p;k=o-1}}for(var k=0,n=j;b>k;++k){var l=i[k];"L"==n&&"1"==l?i[k]="L":f.test(l)&&(n=l)}for(var k=0;b>k;++k)if(e.test(i[k])){for(var o=k+1;b>o&&e.test(i[o]);++o);for(var r="L"==(k?i[k-1]:j),s="L"==(b-1>o?i[o]:j),p=r||s?"L":"R",q=k;o>q;++q)i[q]=p;k=o-1}for(var u,t=[],k=0;b>k;)if(g.test(i[k])){var v=k;for(++k;b>k&&g.test(i[k]);++k);t.push({from:v,to:k,level:0})}else{var w=k,x=t.length;for(++k;b>k&&"L"!=i[k];++k);for(var q=w;k>q;)if(h.test(i[q])){q>w&&t.splice(x,0,{from:w,to:q,level:1});var y=q;for(++q;k>q&&h.test(i[q]);++q);t.splice(x,0,{from:y,to:q,level:2}),w=q}else++q;k>w&&t.splice(x,0,{from:w,to:k,level:1})}return 1==t[0].level&&(u=a.match(/^\s+/))&&(t[0].from=u[0].length,t.unshift({from:0,to:u[0].length,level:0})),1==Sd(t).level&&(u=a.match(/\s+$/))&&(Sd(t).to-=u[0].length,t.push({from:b-u[0].length,to:b,level:0})),t[0].level!=Sd(t).level&&t.push({from:b,to:b,level:t[0].level}),t}}();return s.version="3.0",s}(),CodeMirror.defineMode("javascript",function(a,b){function h(a,b,c){return b.tokenize=c,c(a,b)}function i(a,b){for(var d,c=!1;null!=(d=a.next());){if(d==b&&!c)return!1;c=!c&&"\\"==d}return c}function l(a,b,c){return j=a,k=c,b}function m(a,b){var c=a.next();if('"'==c||"'"==c)return h(a,b,n(c));if(/[\[\]{}\(\),;\:\.]/.test(c))return l(c);if("0"==c&&a.eat(/x/i))return a.eatWhile(/[\da-f]/i),l("number","number");if(/\d/.test(c)||"-"==c&&a.eat(/\d/))return a.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/),l("number","number");if("/"==c)return a.eat("*")?h(a,b,o):a.eat("/")?(a.skipToEnd(),l("comment","comment")):"operator"==b.lastType||"keyword c"==b.lastType||/^[\[{}\(,;:]$/.test(b.lastType)?(i(a,"/"),a.eatWhile(/[gimy]/),l("regexp","string-2")):(a.eatWhile(g),l("operator",null,a.current()));if("#"==c)return a.skipToEnd(),l("error","error");if(g.test(c))return a.eatWhile(g),l("operator",null,a.current());a.eatWhile(/[\w\$_]/);var d=a.current(),e=f.propertyIsEnumerable(d)&&f[d];return e&&"."!=b.lastType?l(e.type,e.style,d):l("variable","variable",d)}function n(a){return function(b,c){return i(b,a)||(c.tokenize=m),l("string","string")}}function o(a,b){for(var d,c=!1;d=a.next();){if("/"==d&&c){b.tokenize=m;break}c="*"==d}return l("comment","comment")}function q(a,b,c,d,e,f){this.indented=a,this.column=b,this.type=c,this.prev=e,this.info=f,null!=d&&(this.align=d)}function r(a,b){for(var c=a.localVars;c;c=c.next)if(c.name==b)return!0}function s(a,b,c,e,f){var g=a.cc;for(t.state=a,t.stream=f,t.marked=null,t.cc=g,a.lexical.hasOwnProperty("align")||(a.lexical.align=!0);;){var h=g.length?g.pop():d?E:D;if(h(c,e)){for(;g.length&&g[g.length-1].lex;)g.pop()();return t.marked?t.marked:"variable"==c&&r(a,e)?"variable-2":b}}}function u(){for(var a=arguments.length-1;a>=0;a--)t.cc.push(arguments[a])}function v(){return u.apply(null,arguments),!0}function w(a){var b=t.state;if(b.context){t.marked="def";for(var c=b.localVars;c;c=c.next)if(c.name==a)return;b.localVars={name:a,next:b.localVars}}}function y(){t.state.context={prev:t.state.context,vars:t.state.localVars},t.state.localVars=x}function z(){t.state.localVars=t.state.context.vars,t.state.context=t.state.context.prev}function A(a,b){var c=function(){var c=t.state;c.lexical=new q(c.indented,t.stream.column(),a,null,c.lexical,b)};return c.lex=!0,c}function B(){var a=t.state;a.lexical.prev&&(")"==a.lexical.type&&(a.indented=a.lexical.indented),a.lexical=a.lexical.prev)}function C(a){return function(b){return b==a?v():";"==a?u():v(arguments.callee)}}function D(a){return"var"==a?v(A("vardef"),O,C(";"),B):"keyword a"==a?v(A("form"),E,D,B):"keyword b"==a?v(A("form"),D,B):"{"==a?v(A("}"),L,B):";"==a?v():"function"==a?v(U):"for"==a?v(A("form"),C("("),A(")"),Q,C(")"),B,D,B):"variable"==a?v(A("stat"),H):"switch"==a?v(A("form"),E,A("}","switch"),C("{"),L,B,B):"case"==a?v(E,C(":")):"default"==a?v(C(":")):"catch"==a?v(A("form"),y,C("("),V,C(")"),D,B,z):u(A("stat"),E,C(";"),B)}function E(a){return p.hasOwnProperty(a)?v(G):"function"==a?v(U):"keyword c"==a?v(F):"("==a?v(A(")"),F,C(")"),B,G):"operator"==a?v(E):"["==a?v(A("]"),K(E,"]"),B,G):"{"==a?v(A("}"),K(J,"}"),B,G):v()}function F(a){return a.match(/[;\}\)\],]/)?u():u(E)}function G(a,b){if("operator"==a&&/\+\+|--/.test(b))return v(G);if("operator"==a&&"?"==b)return v(E,C(":"),E);if(";"!=a)return"("==a?v(A(")"),K(E,")"),B,G):"."==a?v(I,G):"["==a?v(A("]"),E,C("]"),B,G):void 0}function H(a){return":"==a?v(B,D):u(G,C(";"),B)}function I(a){return"variable"==a?(t.marked="property",v()):void 0}function J(a){return"variable"==a&&(t.marked="property"),p.hasOwnProperty(a)?v(C(":"),E):void 0}function K(a,b){function c(d){return","==d?v(a,c):d==b?v():v(C(b))}return function(d){return d==b?v():u(a,c)}}function L(a){return"}"==a?v():u(D,L)}function M(a){return":"==a?v(N):u()}function N(a){return"variable"==a?(t.marked="variable-3",v()):u()}function O(a,b){return"variable"==a?(w(b),e?v(M,P):v(P)):u()}function P(a,b){return"="==b?v(E,P):","==a?v(O):void 0}function Q(a){return"var"==a?v(O,C(";"),S):";"==a?v(S):"variable"==a?v(R):v(S)}function R(a,b){return"in"==b?v(E):v(G,S)}function S(a,b){return";"==a?v(T):"in"==b?v(E):v(E,C(";"),T)}function T(a){")"!=a&&v(E)}function U(a,b){return"variable"==a?(w(b),v(U)):"("==a?v(A(")"),y,K(V,")"),B,D,z):void 0}function V(a,b){return"variable"==a?(w(b),e?v(M):v()):void 0}var j,k,c=a.indentUnit,d=b.json,e=b.typescript,f=function(){function a(a){return{type:a,style:"keyword"}}var b=a("keyword a"),c=a("keyword b"),d=a("keyword c"),f=a("operator"),g={type:"atom",style:"atom"},h={"if":b,"while":b,"with":b,"else":c,"do":c,"try":c,"finally":c,"return":d,"break":d,"continue":d,"new":d,"delete":d,"throw":d,"var":a("var"),"const":a("var"),let:a("var"),"function":a("function"),"catch":a("catch"),"for":a("for"),"switch":a("switch"),"case":a("case"),"default":a("default"),"in":f,"typeof":f,"instanceof":f,"true":g,"false":g,"null":g,undefined:g,NaN:g,Infinity:g};if(e){var i={type:"variable",style:"variable-3"},j={"interface":a("interface"),"class":a("class"),"extends":a("extends"),constructor:a("constructor"),"public":a("public"),"private":a("private"),"protected":a("protected"),"static":a("static"),"super":a("super"),string:i,number:i,bool:i,any:i};for(var k in j)h[k]=j[k]}return h}(),g=/[+\-*&%=<>!?|]/,p={atom:!0,number:!0,variable:!0,string:!0,regexp:!0},t={state:null,column:null,marked:null,cc:null},x={name:"this",next:{name:"arguments"}};return B.lex=!0,{startState:function(a){return{tokenize:m,lastType:null,cc:[],lexical:new q((a||0)-c,0,"block",!1),localVars:b.localVars,context:b.localVars&&{vars:b.localVars},indented:0}},token:function(a,b){if(a.sol()&&(b.lexical.hasOwnProperty("align")||(b.lexical.align=!1),b.indented=a.indentation()),a.eatSpace())return null;var c=b.tokenize(a,b);return"comment"==j?c:(b.lastType=j,s(b,c,j,k,a))},indent:function(a,b){if(a.tokenize==o)return CodeMirror.Pass;if(a.tokenize!=m)return 0;var d=b&&b.charAt(0),e=a.lexical;"stat"==e.type&&"}"==d&&(e=e.prev);var f=e.type,g=d==f;return"vardef"==f?e.indented+("operator"==a.lastType||","==a.lastType?4:0):"form"==f&&"{"==d?e.indented:"form"==f?e.indented+c:"stat"==f?e.indented+("operator"==a.lastType||","==a.lastType?c:0):"switch"!=e.info||g?e.align?e.column+(g?0:1):e.indented+(g?0:c):e.indented+(/^(?:case|default)\b/.test(b)?c:2*c)},electricChars:":{}",jsonMode:d}}),CodeMirror.defineMIME("text/javascript","javascript"),CodeMirror.defineMIME("application/json",{name:"javascript",json:!0}),CodeMirror.defineMIME("text/typescript",{name:"javascript",typescript:!0}),CodeMirror.defineMIME("application/typescript",{name:"javascript",typescript:!0}),CodeMirror.defineMode("python",function(a,b){function d(a){return RegExp("^(("+a.join(")|(")+"))\\b")}function t(a,b){if(a.sol()){var d=b.scopes[0].offset;if(a.eatSpace()){var l=a.indentation();return l>d?s="indent":d>l&&(s="dedent"),null}d>0&&w(a,b)}if(a.eatSpace())return null;var m=a.peek();if("#"===m)return a.skipToEnd(),"comment";if(a.match(/^[0-9\.]/,!1)){var n=!1;if(a.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)&&(n=!0),a.match(/^\d+\.\d*/)&&(n=!0),a.match(/^\.\d+/)&&(n=!0),n)return a.eat(/J/i),"number";var o=!1;if(a.match(/^0x[0-9a-f]+/i)&&(o=!0),a.match(/^0b[01]+/i)&&(o=!0),a.match(/^0o[0-7]+/i)&&(o=!0),a.match(/^[1-9]\d*(e[\+\-]?\d+)?/)&&(a.eat(/J/i),o=!0),a.match(/^0(?![\dx])/i)&&(o=!0),o)return a.eat(/L/i),"number"}return a.match(p)?(b.tokenize=u(a.current()),b.tokenize(a,b)):a.match(i)||a.match(h)?null:a.match(g)||a.match(e)||a.match(k)?"operator":a.match(f)?null:a.match(q)?"keyword":a.match(r)?"builtin":a.match(j)?"variable":(a.next(),c)}function u(a){function f(f,g){for(;!f.eol();)if(f.eatWhile(/[^'"\\]/),f.eat("\\")){if(f.next(),d&&f.eol())return e}else{if(f.match(a))return g.tokenize=t,e;f.eat(/['"]/)}if(d){if(b.singleLineStringErrors)return c;g.tokenize=t}return e}for(;"rub".indexOf(a.charAt(0).toLowerCase())>=0;)a=a.substr(1);var d=1==a.length,e="string";return f.isString=!0,f}function v(b,c,d){d=d||"py";var e=0;if("py"===d){if("py"!==c.scopes[0].type)return c.scopes[0].offset=b.indentation(),void 0;for(var f=0;c.scopes.length>f;++f)if("py"===c.scopes[f].type){e=c.scopes[f].offset+a.indentUnit;break}}else e=b.column()+b.current().length;c.scopes.unshift({offset:e,type:d})}function w(a,b,c){if(c=c||"py",1!=b.scopes.length){if("py"===b.scopes[0].type){for(var d=a.indentation(),e=-1,f=0;b.scopes.length>f;++f)if(d===b.scopes[f].offset){e=f;break}if(-1===e)return!0;for(;b.scopes[0].offset!==d;)b.scopes.shift();return!1}return"py"===c?(b.scopes[0].offset=a.indentation(),!1):b.scopes[0].type!=c?!0:(b.scopes.shift(),!1)}}function x(a,b){s=null;var d=b.tokenize(a,b),e=a.current();if("."===e)return d=a.match(j,!1)?null:c,null===d&&"meta"===b.lastToken&&(d="meta"),d;if("@"===e)return a.match(j,!1)?"meta":c;"variable"!==d&&"builtin"!==d||"meta"!==b.lastToken||(d="meta"),("pass"===e||"return"===e)&&(b.dedent+=1),"lambda"===e&&(b.lambda=!0),(":"===e&&!b.lambda&&"py"==b.scopes[0].type||"indent"===s)&&v(a,b);var f="[({".indexOf(e);return-1!==f&&v(a,b,"])}".slice(f,f+1)),"dedent"===s&&w(a,b)?c:(f="])}".indexOf(e),-1!==f&&w(a,b,e)?c:(b.dedent>0&&a.eol()&&"py"==b.scopes[0].type&&(b.scopes.length>1&&b.scopes.shift(),b.dedent-=1),d))}var c="error",e=RegExp("^[\\+\\-\\*/%&|\\^~<>!]"),f=RegExp("^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]"),g=RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"),h=RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"),i=RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))"),j=RegExp("^[_A-Za-z][_A-Za-z0-9]*"),k=d(["and","or","not","is","in"]),l=["as","assert","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","lambda","pass","raise","return","try","while","with","yield"],m=["abs","all","any","bin","bool","bytearray","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip","__import__","NotImplemented","Ellipsis","__debug__"],n={builtins:["apply","basestring","buffer","cmp","coerce","execfile","file","intern","long","raw_input","reduce","reload","unichr","unicode","xrange","False","True","None"],keywords:["exec","print"]},o={builtins:["ascii","bytes","exec","print"],keywords:["nonlocal","False","True","None"]};if(b.version&&3===parseInt(b.version,10)){l=l.concat(o.keywords),m=m.concat(o.builtins);var p=RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))","i")}else{l=l.concat(n.keywords),m=m.concat(n.builtins);var p=RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))","i")}var q=d(l),r=d(m),s=null,y={startState:function(a){return{tokenize:t,scopes:[{offset:a||0,type:"py"}],lastToken:null,lambda:!1,dedent:0}},token:function(a,b){var c=x(a,b);return b.lastToken=c,a.eol()&&a.lambda&&(b.lambda=!1),c},indent:function(a){return a.tokenize!=t?a.tokenize.isString?CodeMirror.Pass:0:a.scopes[0].offset}};return y}),CodeMirror.defineMIME("text/x-python","python"),CodeMirror.defineMode("r",function(a){function b(a){for(var b=a.split(" "),c={},d=0;b.length>d;++d)c[b[d]]=!0;return c}function i(a,b){h=null;var i=a.next();if("#"==i)return a.skipToEnd(),"comment";if("0"==i&&a.eat("x"))return a.eatWhile(/[\da-f]/i),"number";if("."==i&&a.eat(/\d/))return a.match(/\d*(?:e[+\-]?\d+)?/),"number";if(/\d/.test(i))return a.match(/\d*(?:\.\d+)?(?:e[+\-]\d+)?L?/),"number";if("'"==i||'"'==i)return b.tokenize=j(i),"string";if("."==i&&a.match(/.[.\d]+/))return"keyword";if(/[\w\.]/.test(i)&&"_"!=i){a.eatWhile(/[\w\.]/);var k=a.current();return c.propertyIsEnumerable(k)?"atom":e.propertyIsEnumerable(k)?(f.propertyIsEnumerable(k)&&(h="block"),"keyword"):d.propertyIsEnumerable(k)?"builtin":"variable"}return"%"==i?(a.skipTo("%")&&a.next(),"variable-2"):"<"==i&&a.eat("-")?"arrow":"="==i&&b.ctx.argList?"arg-is":g.test(i)?"$"==i?"dollar":(a.eatWhile(g),"operator"):/[\(\){}\[\];]/.test(i)?(h=i,";"==i?"semi":null):null}function j(a){return function(b,c){if(b.eat("\\")){var d=b.next();return"x"==d?b.match(/^[a-f0-9]{2}/i):("u"==d||"U"==d)&&b.eat("{")&&b.skipTo("}")?b.next():"u"==d?b.match(/^[a-f0-9]{4}/i):"U"==d?b.match(/^[a-f0-9]{8}/i):/[0-7]/.test(d)&&b.match(/^[0-7]{1,2}/),"string-2"}for(var e;null!=(e=b.next());){if(e==a){c.tokenize=i;break}if("\\"==e){b.backUp(1);break}}return"string"}}function k(a,b,c){a.ctx={type:b,indent:a.indent,align:null,column:c.column(),prev:a.ctx}}function l(a){a.indent=a.ctx.indent,a.ctx=a.ctx.prev}var h,c=b("NULL NA Inf NaN NA_integer_ NA_real_ NA_complex_ NA_character_"),d=b("list quote bquote eval return call parse deparse"),e=b("if else repeat while function for in next break"),f=b("if else repeat while function for"),g=/[+\-*\/^<>=!&|~$:]/;return{startState:function(){return{tokenize:i,ctx:{type:"top",indent:-a.indentUnit,align:!1},indent:0,afterIdent:!1}},token:function(a,b){if(a.sol()&&(null==b.ctx.align&&(b.ctx.align=!1),b.indent=a.indentation()),a.eatSpace())return null;var c=b.tokenize(a,b);"comment"!=c&&null==b.ctx.align&&(b.ctx.align=!0);var d=b.ctx.type;return";"!=h&&"{"!=h&&"}"!=h||"block"!=d||l(b),"{"==h?k(b,"}",a):"("==h?(k(b,")",a),b.afterIdent&&(b.ctx.argList=!0)):"["==h?k(b,"]",a):"block"==h?k(b,"block",a):h==d&&l(b),b.afterIdent="variable"==c||"keyword"==c,c
4
+ },indent:function(b,c){if(b.tokenize!=i)return 0;var d=c&&c.charAt(0),e=b.ctx,f=d==e.type;return"block"==e.type?e.indent+("{"==d?0:a.indentUnit):e.align?e.column+(f?0:1):e.indent+(f?0:a.indentUnit)}}}),CodeMirror.defineMIME("text/x-rsrc","r"),CodeMirror.defineMode("ruby",function(a){function b(a){for(var b={},c=0,d=a.length;d>c;++c)b[a[c]]=!0;return b}function h(a,b,c){return c.tokenize.push(a),a(b,c)}function i(a,b){if(g=null,a.sol()&&a.match("=begin")&&a.eol())return b.tokenize.push(m),"comment";if(a.eatSpace())return null;var d,c=a.next();if("`"==c||"'"==c||'"'==c||"/"==c&&!a.eol()&&" "!=a.peek())return h(k(c,"string",'"'==c||"`"==c),a,b);if("%"==c){var e,i=!1;a.eat("s")?e="atom":a.eat(/[WQ]/)?(e="string",i=!0):a.eat(/[wxqr]/)&&(e="string");var j=a.eat(/[^\w\s]/);return j?(f.propertyIsEnumerable(j)&&(j=f[j]),h(k(j,e,i,!0),a,b)):"operator"}if("#"==c)return a.skipToEnd(),"comment";if("<"==c&&(d=a.match(/^<-?[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/)))return h(l(d[1]),a,b);if("0"==c)return a.eat("x")?a.eatWhile(/[\da-fA-F]/):a.eat("b")?a.eatWhile(/[01]/):a.eatWhile(/[0-7]/),"number";if(/\d/.test(c))return a.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/),"number";if("?"==c){for(;a.match(/^\\[CM]-/););return a.eat("\\")?a.eatWhile(/\w/):a.next(),"string"}return":"==c?a.eat("'")?h(k("'","atom",!1),a,b):a.eat('"')?h(k('"',"atom",!0),a,b):(a.eatWhile(/[\w\?]/),"atom"):"@"==c?(a.eat("@"),a.eatWhile(/[\w\?]/),"variable-2"):"$"==c?(a.next(),a.eatWhile(/[\w\?]/),"variable-3"):/\w/.test(c)?(a.eatWhile(/[\w\?]/),a.eat(":")?"atom":"ident"):"|"!=c||!b.varList&&"{"!=b.lastTok&&"do"!=b.lastTok?/[\(\)\[\]{}\\;]/.test(c)?(g=c,null):"-"==c&&a.eat(">")?"arrow":/[=+\-\/*:\.^%<>~|]/.test(c)?(a.eatWhile(/[=+\-\/*:\.^%<>~|]/),"operator"):null:(g="|",null)}function j(){var a=1;return function(b,c){if("}"==b.peek()){if(a--,0==a)return c.tokenize.pop(),c.tokenize[c.tokenize.length-1](b,c)}else"{"==b.peek()&&a++;return i(b,c)}}function k(a,b,c,d){return function(e,f){for(var h,g=!1;null!=(h=e.next());){if(h==a&&(d||!g)){f.tokenize.pop();break}if(c&&"#"==h&&!g&&e.eat("{")){f.tokenize.push(j(arguments.callee));break}g=!g&&"\\"==h}return b}}function l(a){return function(b,c){return b.match(a)?c.tokenize.pop():b.skipToEnd(),"string"}}function m(a,b){return a.sol()&&a.match("=end")&&a.eol()&&b.tokenize.pop(),a.skipToEnd(),"comment"}var g,c=b(["alias","and","BEGIN","begin","break","case","class","def","defined?","do","else","elsif","END","end","ensure","false","for","if","in","module","next","not","or","redo","rescue","retry","return","self","super","then","true","undef","unless","until","when","while","yield","nil","raise","throw","catch","fail","loop","callcc","caller","lambda","proc","public","protected","private","require","load","require_relative","extend","autoload"]),d=b(["def","class","case","for","while","do","module","then","catch","loop","proc","begin"]),e=b(["end","until"]),f={"[":"]","{":"}","(":")"};return{startState:function(){return{tokenize:[i],indented:0,context:{type:"top",indented:-a.indentUnit},continuedLine:!1,lastTok:null,varList:!1}},token:function(a,b){a.sol()&&(b.indented=a.indentation());var h,f=b.tokenize[b.tokenize.length-1](a,b);if("ident"==f){var i=a.current();f=c.propertyIsEnumerable(a.current())?"keyword":/^[A-Z]/.test(i)?"tag":"def"==b.lastTok||"class"==b.lastTok||b.varList?"def":"variable",d.propertyIsEnumerable(i)?h="indent":e.propertyIsEnumerable(i)?h="dedent":"if"!=i&&"unless"!=i||a.column()!=a.indentation()||(h="indent")}return(g||f&&"comment"!=f)&&(b.lastTok=i||g||f),"|"==g&&(b.varList=!b.varList),"indent"==h||/[\(\[\{]/.test(g)?b.context={prev:b.context,type:g||f,indented:b.indented}:("dedent"==h||/[\)\]\}]/.test(g))&&b.context.prev&&(b.context=b.context.prev),a.eol()&&(b.continuedLine="\\"==g||"operator"==f),f},indent:function(b,c){if(b.tokenize[b.tokenize.length-1]!=i)return 0;var d=c&&c.charAt(0),e=b.context,g=e.type==f[d]||"keyword"==e.type&&/^(?:end|until|else|elsif|when|rescue)\b/.test(c);return e.indented+(g?0:a.indentUnit)+(b.continuedLine?a.indentUnit:0)},electricChars:"}de"}}),CodeMirror.defineMIME("text/x-ruby","ruby"),CodeMirror.defineMode("xml",function(a,b){function h(a,b){function c(c){return b.tokenize=c,c(a,b)}var d=a.next();if("<"==d){if(a.eat("!"))return a.eat("[")?a.match("CDATA[")?c(k("atom","]]>")):null:a.match("--")?c(k("comment","-->")):a.match("DOCTYPE",!0,!0)?(a.eatWhile(/[\w\._\-]/),c(l(1))):null;if(a.eat("?"))return a.eatWhile(/[\w\._\-]/),b.tokenize=k("meta","?>"),"meta";var e=a.eat("/");f="";for(var h;h=a.eat(/[^\s\u00a0=<>\"\'\/?]/);)f+=h;return f?(g=e?"closeTag":"openTag",b.tokenize=i,"tag"):"error"}if("&"==d){var j;return j=a.eat("#")?a.eat("x")?a.eatWhile(/[a-fA-F\d]/)&&a.eat(";"):a.eatWhile(/[\d]/)&&a.eat(";"):a.eatWhile(/[\w\.\-:]/)&&a.eat(";"),j?"atom":"error"}return a.eatWhile(/[^&<]/),null}function i(a,b){var c=a.next();return">"==c||"/"==c&&a.eat(">")?(b.tokenize=h,g=">"==c?"endTag":"selfcloseTag","tag"):"="==c?(g="equals",null):/[\'\"]/.test(c)?(b.tokenize=j(c),b.tokenize(a,b)):(a.eatWhile(/[^\s\u00a0=<>\"\']/),"word")}function j(a){return function(b,c){for(;!b.eol();)if(b.next()==a){c.tokenize=i;break}return"string"}}function k(a,b){return function(c,d){for(;!c.eol();){if(c.match(b)){d.tokenize=h;break}c.next()}return a}}function l(a){return function(b,c){for(var d;null!=(d=b.next());){if("<"==d)return c.tokenize=l(a+1),c.tokenize(b,c);if(">"==d){if(1==a){c.tokenize=h;break}return c.tokenize=l(a-1),c.tokenize(b,c)}}return"meta"}}function o(){for(var a=arguments.length-1;a>=0;a--)m.cc.push(arguments[a])}function p(){return o.apply(null,arguments),!0}function q(a,b){var c=d.doNotIndent.hasOwnProperty(a)||m.context&&m.context.noIndent;m.context={prev:m.context,tagName:a,indent:m.indented,startOfLine:b,noIndent:c}}function r(){m.context&&(m.context=m.context.prev)}function s(a){if("openTag"==a)return m.tagName=f,p(w,t(m.startOfLine));if("closeTag"==a){var b=!1;return m.context?m.context.tagName!=f&&(d.implicitlyClosed.hasOwnProperty(m.context.tagName.toLowerCase())&&r(),b=!m.context||m.context.tagName!=f):b=!0,b&&(n="error"),p(u(b))}return p()}function t(a){return function(b){var c=m.tagName;return m.tagName=null,"selfcloseTag"==b||"endTag"==b&&d.autoSelfClosers.hasOwnProperty(c.toLowerCase())?(v(c.toLowerCase()),p()):"endTag"==b?(v(c.toLowerCase()),q(c,a),p()):p()}}function u(a){return function(b){return a&&(n="error"),"endTag"==b?(r(),p()):(n="error",p(arguments.callee))}}function v(a){for(var b;;){if(!m.context)return;if(b=m.context.tagName.toLowerCase(),!d.contextGrabbers.hasOwnProperty(b)||!d.contextGrabbers[b].hasOwnProperty(a))return;r()}}function w(a){return"word"==a?(n="attribute",p(x,w)):"endTag"==a||"selfcloseTag"==a?o():(n="error",p(w))}function x(a){return"equals"==a?p(y,w):(d.allowMissing?"word"==a&&(n="attribute"):n="error","endTag"==a||"selfcloseTag"==a?o():p())}function y(a){return"string"==a?p(z):"word"==a&&d.allowUnquoted?(n="string",p()):(n="error","endTag"==a||"selfCloseTag"==a?o():p())}function z(a){return"string"==a?p(z):o()}var f,g,m,n,c=a.indentUnit,d=b.htmlMode?{autoSelfClosers:{area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},implicitlyClosed:{dd:!0,li:!0,optgroup:!0,option:!0,p:!0,rp:!0,rt:!0,tbody:!0,td:!0,tfoot:!0,th:!0,tr:!0},contextGrabbers:{dd:{dd:!0,dt:!0},dt:{dd:!0,dt:!0},li:{li:!0},option:{option:!0,optgroup:!0},optgroup:{optgroup:!0},p:{address:!0,article:!0,aside:!0,blockquote:!0,dir:!0,div:!0,dl:!0,fieldset:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,menu:!0,nav:!0,ol:!0,p:!0,pre:!0,section:!0,table:!0,ul:!0},rp:{rp:!0,rt:!0},rt:{rp:!0,rt:!0},tbody:{tbody:!0,tfoot:!0},td:{td:!0,th:!0},tfoot:{tbody:!0},th:{td:!0,th:!0},thead:{tbody:!0,tfoot:!0},tr:{tr:!0}},doNotIndent:{pre:!0},allowUnquoted:!0,allowMissing:!0}:{autoSelfClosers:{},implicitlyClosed:{},contextGrabbers:{},doNotIndent:{},allowUnquoted:!1,allowMissing:!1},e=b.alignCDATA;return{startState:function(){return{tokenize:h,cc:[],indented:0,startOfLine:!0,tagName:null,context:null}},token:function(a,b){if(a.sol()&&(b.startOfLine=!0,b.indented=a.indentation()),a.eatSpace())return null;n=g=f=null;var c=b.tokenize(a,b);if(b.type=g,(c||g)&&"comment"!=c)for(m=b;;){var d=b.cc.pop()||s;if(d(g||c))break}return b.startOfLine=!1,n||c},indent:function(a,b,d){var f=a.context;if(a.tokenize!=i&&a.tokenize!=h||f&&f.noIndent)return d?d.match(/^(\s*)/)[0].length:0;if(e&&/<!\[CDATA\[/.test(b))return 0;for(f&&/^<\//.test(b)&&(f=f.prev);f&&!f.startOfLine;)f=f.prev;return f?f.indent+c:0},electricChars:"/",configuration:b.htmlMode?"html":"xml"}}),CodeMirror.defineMIME("text/xml","xml"),CodeMirror.defineMIME("application/xml","xml"),CodeMirror.mimeModes.hasOwnProperty("text/html")||CodeMirror.defineMIME("text/html",{name:"xml",htmlMode:!0}),function(){function b(b){a.push(b),a.length>50&&a.shift()}function c(){return a[a.length-1]||""}function d(){return a.length>1&&a.pop(),c()}var a=[];CodeMirror.keyMap.emacs={"Ctrl-X":function(a){a.setOption("keyMap","emacs-Ctrl-X")},"Ctrl-W":function(a){b(a.getSelection()),a.replaceSelection("")},"Ctrl-Alt-W":function(a){b(a.getSelection()),a.replaceSelection("")},"Alt-W":function(a){b(a.getSelection())},"Ctrl-Y":function(a){a.replaceSelection(c())},"Alt-Y":function(a){a.replaceSelection(d())},"Ctrl-/":"undo","Shift-Ctrl--":"undo","Shift-Alt-,":"goDocStart","Shift-Alt-.":"goDocEnd","Ctrl-S":"findNext","Ctrl-R":"findPrev","Ctrl-G":"clearSearch","Shift-Alt-5":"replace","Ctrl-Z":"undo","Cmd-Z":"undo","Alt-/":"autocomplete","Alt-V":"goPageUp","Ctrl-J":"newlineAndIndent",Enter:!1,Tab:"indentAuto",fallthrough:["basic","emacsy"]},CodeMirror.keyMap["emacs-Ctrl-X"]={"Ctrl-S":"save","Ctrl-W":"save",S:"saveAll",F:"open",U:"undo",K:"close",auto:"emacs",nofallthrough:!0}}(),function(){"use strict";var a=[{keys:["Left"],type:"keyToKey",toKeys:["h"]},{keys:["Right"],type:"keyToKey",toKeys:["l"]},{keys:["Up"],type:"keyToKey",toKeys:["k"]},{keys:["Down"],type:"keyToKey",toKeys:["j"]},{keys:["Space"],type:"keyToKey",toKeys:["l"]},{keys:["Backspace"],type:"keyToKey",toKeys:["h"]},{keys:["Ctrl-Space"],type:"keyToKey",toKeys:["W"]},{keys:["Ctrl-Backspace"],type:"keyToKey",toKeys:["B"]},{keys:["Shift-Space"],type:"keyToKey",toKeys:["w"]},{keys:["Shift-Backspace"],type:"keyToKey",toKeys:["b"]},{keys:["Ctrl-n"],type:"keyToKey",toKeys:["j"]},{keys:["Ctrl-p"],type:"keyToKey",toKeys:["k"]},{keys:["Ctrl-["],type:"keyToKey",toKeys:["Esc"]},{keys:["Ctrl-c"],type:"keyToKey",toKeys:["Esc"]},{keys:["s"],type:"keyToKey",toKeys:["c","l"]},{keys:["S"],type:"keyToKey",toKeys:["c","c"]},{keys:["Home"],type:"keyToKey",toKeys:["0"]},{keys:["End"],type:"keyToKey",toKeys:["$"]},{keys:["PageUp"],type:"keyToKey",toKeys:["Ctrl-b"]},{keys:["PageDown"],type:"keyToKey",toKeys:["Ctrl-f"]},{keys:["h"],type:"motion",motion:"moveByCharacters",motionArgs:{forward:!1}},{keys:["l"],type:"motion",motion:"moveByCharacters",motionArgs:{forward:!0}},{keys:["j"],type:"motion",motion:"moveByLines",motionArgs:{forward:!0,linewise:!0}},{keys:["k"],type:"motion",motion:"moveByLines",motionArgs:{forward:!1,linewise:!0}},{keys:["w"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1}},{keys:["W"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1,bigWord:!0}},{keys:["e"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,inclusive:!0}},{keys:["E"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:["b"],type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1}},{keys:["B"],type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1,bigWord:!0}},{keys:["g","e"],type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,inclusive:!0}},{keys:["g","E"],type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:["Ctrl-f"],type:"motion",motion:"moveByPage",motionArgs:{forward:!0}},{keys:["Ctrl-b"],type:"motion",motion:"moveByPage",motionArgs:{forward:!1}},{keys:["g","g"],type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0}},{keys:["G"],type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!0,explicitRepeat:!0,linewise:!0}},{keys:["0"],type:"motion",motion:"moveToStartOfLine"},{keys:["^"],type:"motion",motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:["$"],type:"motion",motion:"moveToEol",motionArgs:{inclusive:!0}},{keys:["%"],type:"motion",motion:"moveToMatchedSymbol",motionArgs:{inclusive:!0}},{keys:["f","character"],type:"motion",motion:"moveToCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:["F","character"],type:"motion",motion:"moveToCharacter",motionArgs:{forward:!1}},{keys:["t","character"],type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:["T","character"],type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!1}},{keys:["'","character"],type:"motion",motion:"goToMark"},{keys:["`","character"],type:"motion",motion:"goToMark"},{keys:["|"],type:"motion",motion:"moveToColumn",motionArgs:{}},{keys:["d"],type:"operator",operator:"delete"},{keys:["y"],type:"operator",operator:"yank"},{keys:["c"],type:"operator",operator:"change",operatorArgs:{enterInsertMode:!0}},{keys:[">"],type:"operator",operator:"indent",operatorArgs:{indentRight:!0}},{keys:["<"],type:"operator",operator:"indent",operatorArgs:{indentRight:!1}},{keys:["g","~"],type:"operator",operator:"swapcase"},{keys:["n"],type:"motion",motion:"findNext"},{keys:["N"],type:"motion",motion:"findPrev"},{keys:["x"],type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!0},operatorMotionArgs:{visualLine:!1}},{keys:["X"],type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!1},operatorMotionArgs:{visualLine:!0}},{keys:["D"],type:"operatorMotion",operator:"delete",motion:"moveToEol",motionArgs:{inclusive:!0},operatorMotionArgs:{visualLine:!0}},{keys:["Y"],type:"operatorMotion",operator:"yank",motion:"moveToEol",motionArgs:{inclusive:!0},operatorMotionArgs:{visualLine:!0}},{keys:["C"],type:"operatorMotion",operator:"change",operatorArgs:{enterInsertMode:!0},motion:"moveToEol",motionArgs:{inclusive:!0},operatorMotionArgs:{visualLine:!0}},{keys:["~"],type:"operatorMotion",operator:"swapcase",motion:"moveByCharacters",motionArgs:{forward:!0}},{keys:["a"],type:"action",action:"enterInsertMode",actionArgs:{insertAt:"charAfter"}},{keys:["A"],type:"action",action:"enterInsertMode",actionArgs:{insertAt:"eol"}},{keys:["i"],type:"action",action:"enterInsertMode"},{keys:["I"],type:"action",action:"enterInsertMode",motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:["o"],type:"action",action:"newLineAndEnterInsertMode",actionArgs:{after:!0}},{keys:["O"],type:"action",action:"newLineAndEnterInsertMode",actionArgs:{after:!1}},{keys:["v"],type:"action",action:"toggleVisualMode"},{keys:["V"],type:"action",action:"toggleVisualMode",actionArgs:{linewise:!0}},{keys:["J"],type:"action",action:"joinLines"},{keys:["p"],type:"action",action:"paste",actionArgs:{after:!0}},{keys:["P"],type:"action",action:"paste",actionArgs:{after:!1}},{keys:["r","character"],type:"action",action:"replace"},{keys:["u"],type:"action",action:"undo"},{keys:["Ctrl-r"],type:"action",action:"redo"},{keys:["m","character"],type:"action",action:"setMark"},{keys:['"',"character"],type:"action",action:"setRegister"},{keys:[",","/"],type:"action",action:"clearSearchHighlight"},{keys:["a","character"],type:"motion",motion:"textObjectManipulation"},{keys:["i","character"],type:"motion",motion:"textObjectManipulation",motionArgs:{textObjectInner:!0}},{keys:["/"],type:"search",searchArgs:{forward:!0,querySrc:"prompt"}},{keys:["?"],type:"search",searchArgs:{forward:!1,querySrc:"prompt"}},{keys:["*"],type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor"}},{keys:["#"],type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor"}},{keys:[":"],type:"ex"}],b=function(){function h(a,b){for(var c=[],d=a;a+b>d;d++)c.push(String.fromCharCode(d));return c}function r(a,b){return b>=0&&a.lineCount()>b}function t(a){return-1!="()[]{}".indexOf(a)}function u(a){return d.test(a)}function v(a){return/^[A-Z]$/.test(a)}function y(a){return/^\s*$/.test(a)}function z(a,b,c){return a>=b&&c>=a}function A(a,b){for(var c=0;b.length>c;c++)if(b[c]==a)return!0;return!1}function C(){return B||(B={searchQuery:null,searchIsReversed:!1,registerController:new H({})}),B}function D(a){return a.vimState||(a.vimState={inputState:new F,lastHPos:-1,lastMotion:null,marks:{},visualMode:!1,visualLine:!1}),a.vimState}function F(){this.reset()}function G(a,b){this.clear(),a&&this.set(a,b)}function H(a){this.registers=a,this.unamedRegister=a['"']=new G}function N(a,b,c){var d=Math.min(Math.max(0,b.line),a.lineCount()-1),e=Y(a,d)-1;e=c?e+1:e;var f=Math.min(Math.max(0,b.ch),e);return{line:d,ch:f}}function P(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function Q(a,b,c){return{line:a.line+b,ch:a.ch+c}}function S(a,b){for(var c=0;a.length>c;c++)if(a[c]!=b[c]&&"character"!=b[c])return!1;return!0}function U(a,b,c){return function(){for(var d=0;c>d;d++)b(a)}}function V(a){return{line:a.line,ch:a.ch}}function W(a,b){return a.ch==b.ch&&a.line==b.line}function X(a,b){return a.line<b.line?!0:a.line==b.line&&a.ch<b.ch?!0:!1}function Y(a,b){return a.getLine(b).length}function Z(a){return a.split("").reverse().join("")}function $(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function _(a){return a.replace(/([.?*+$\[\]\/\\(){}|\-])/g,"\\$1")}function ab(a,b){b.visualMode=!1,b.visualLine=!1;var c=a.getCursor("anchor"),d=a.getCursor("head");W(c,d)||a.setCursor(N(a,d))}function bb(a,b,c){var d=a.getRange(b,c),e=d.split("\n");e.length>1&&y(e.pop())&&(c.line--,c.ch=Y(a,c.line))}function cb(a,b,c){b.ch=0,c.ch=0,c.line++}function db(a){if(!a)return 0;var b=a.search(/\S/);return-1==b?a.length:b}function eb(a,b,c,d,e){var j,f=a.getCursor(),g=a.getLine(f.line),h=f.ch,i=g.substring(h);if(j=e?i.search(/\w/):i.search(/\S/),-1==j)return null;h+=j,i=g.substring(h);var l,k=g.substring(0,h);l=d?/^\S+/:/\w/.test(g.charAt(h))?/^\w+/:/^[^\w\s]+/;var m=l.exec(i),n=h,o=h+m[0].length-1,p=l.exec(Z(k));return p&&(n-=p[0].length),b&&o++,{start:{line:f.line,ch:n},end:{line:f.line,ch:o}}}function fb(a,b,c,d){for(var e=b.line,h=b.ch,i=a.getLine(e),j=c?1:-1,k=d?g:f;;){for(var l=j>0?i.length:-1,m=l,n=l;h!=l;){for(var o=!1,p=0;k.length>p&&!o;++p)if(k[p].test(i.charAt(h))){for(m=h;h!=l&&k[p].test(i.charAt(h));)h+=j;if(n=h,o=m!=n,m==b.ch&&e==b.line&&n==m+j)continue;return{from:Math.min(m,n+1),to:Math.max(m,n),line:e}}o||(h+=j)}if(e+=j,!r(a,e))return null;i=a.getLine(e),h=j>0?0:i.length}throw"The impossible happened."}function gb(a,b,c,d,e){for(var f=a.getCursor(),g=0;b>g;g++)for(var j,i=(f.ch,f.line),k=!1;!k;){if(j=fb(a,f,c,e),k=!0,!j)return c?{line:f.line,ch:Y(a,f.line)}:{line:f.line,ch:0};f.line=j.line,c&&d?f.ch=j.to-1:c&&!d?z(f.ch,j.from,j.to)&&j.line==i?(k=!1,f.ch=j.to-1):f.ch=j.from:!c&&d?z(f.ch,j.from,j.to)&&j.line==i?(k=!1,f.ch=j.from):f.ch=j.to:c||d||(f.ch=j.from)}return f}function hb(a,b,c,d){for(var g,e=a.getCursor(),f=e.ch,h=0;b>h;h++){var i=a.getLine(e.line);if(g=jb(f,i,d,c,!0),-1==g)return e;f=g}return{line:a.getCursor().line,ch:g}}function ib(a,b){var c=a.getCursor().line;return N(a,{line:c,ch:b-1})}function jb(a,b,c,d,e){var f;return d?(f=b.indexOf(c,a+1),-1==f||e||(f-=1)):(f=b.lastIndexOf(c,a-1),-1==f||e||(f+=1)),f}function kb(a,b,c){var d=b.line;c=c?c:a.getLine(d).charAt(b.ch),A(c,["(","[","{"]);var f={"(":")",")":"(","[":"]","]":"[","{":"}","}":"{"}[c];if(!f)return b;for(var g={"(":1,"{":1,"[":1}[c]||-1,h=1,i=c,j=b.ch,k=a.getLine(d);i&&h>0;)j+=g,i=k.charAt(j),i||(d+=g,j=0,k=a.getLine(d)||"",i=k.charAt(j)),i===c?h++:i===f&&h--;return i?{line:d,ch:j}:b}function lb(a,b,c){var d=a.getCursor(),e=kb(a,d,b),f=kb(a,e);return f.ch+=c?1:0,e.ch+=c?0:1,{start:f,end:e}}function nb(a,b,c){var g,h,i,j,d=a.getCursor(),e=a.getLine(d.line),f=e.split(""),k=f.indexOf(b);if(k>d.ch?d.ch=k:d.ch>k&&f[d.ch]==b&&(h=d.ch,--d.ch),f[d.ch]!=b||h)for(i=d.ch;i>-1&&!g;i--)f[i]==b&&(g=i+1);else g=d.ch+1;if(g&&!h)for(i=g,j=f.length;j>i&&!h;i++)f[i]==b&&(h=i);return g&&h?(c&&(--g,++h),{start:{line:d.line,ch:g},end:{line:d.line,ch:h}}):{start:d,end:d}}function ob(){this.marked=null}function pb(a){var b=D(a);return b.searchState_||(b.searchState_=new ob)}function qb(a,b,c,d){a.openDialog?a.openDialog(b,d,{bottom:!0}):d(prompt(c,""))}function rb(a){for(var b=!1,c=[],d=0;a.length>d;d++){var e=a.charAt(d);b||"/"!=e||c.push(d),b="\\"==e}return c}function sb(a,b,c,d){var f,g,e=rb(b);if(e.length){f=b.substring(0,e[0]);var h=b.substring(e[0]);g=-1!=h.indexOf("i")}else f=b;if(!f)return null;d&&(c=/^[^A-Z]*$/.test(f));try{var i=RegExp(f,c||g?"i":void 0);return i}catch(j){tb(a,"Invalid regex: "+f)}}function tb(a,b){a.openConfirm?a.openConfirm('<span style="color: red">'+b+'</span> <button type="button">OK</button>',function(){},{bottom:!0}):alert(b)}function ub(a,b){var c="";return a&&(c+='<span style="font-family: monospace">'+a+"</span>"),c+='<input type="text"/> <span style="color: #888">',b&&(c+='<span style="color: #888">',c+=b,c+="</span>"),c}function wb(a,b,c,d){var e=(c||"")+" "+(d||"");qb(a,ub(c,d),e,b)}function xb(a,b){if(a instanceof RegExp&&b instanceof RegExp){for(var c=["global","multiline","ignoreCase","source"],d=0;c.length>d;d++){var e=c[d];if(a[e]!==b[e])return!1}return!0}return!1}function yb(a,b,c,d){a.operation(function(){var e=pb(a);if(b){var f=sb(a,b,!!c,!!d);f&&(xb(f,e.getQuery())||(Bb(a),zb(a,f),e.setQuery(f)))}})}function zb(a,b){if(2e3>a.lineCount()){for(var c=[],d=a.getSearchCursor(b);d.findNext();)c.push(a.markText(d.from(),d.to(),{className:"CodeMirror-searching"}));pb(a).setMarked(c)}}function Ab(a,b,c){return a.operation(function(){var d=pb(a),e=d.getQuery();if(e){d.getMarked()||zb(a,e);var f=a.getCursor();b=d.isReversed()?!b:b,b||(f.ch+=1);for(var g=a.getSearchCursor(e,f),h=0;c>h;h++)if(!g.find(b)&&(g=a.getSearchCursor(e,b?{line:a.lineCount()-1}:{line:0,ch:0}),!g.find(b)))return;return g.from()}})}function Bb(a){a.operation(function(){var b=pb(a);if(b.getQuery()){var c=b.getMarked();if(c){for(var d=0;c.length>d;++d)c[d].clear();b.setMarked(null)}}})}function Eb(a){for(var b=0,c=[];a.length>b;)if("<"==a.charAt(b)){for(var d=++b;">"!=a.charAt(b++););var e=a.substring(d,b-1),f=/^C-(.+)$/.exec(e);if(f){var g;switch(f[1]){case"BS":g="Backspace";break;case"CR":g="Enter";break;case"Del":g="Delete";break;default:g=f[1]}c.push("Ctrl-"+g)}}else c.push(a.charAt(b)),b++;return c}function Hb(){function a(a,b,d){v(b)&&("Shift"==d?d=null:b=b.toLowerCase()),d&&(b=d+"-"+b),c.handleKey(a,b)}function b(b,c){return function(d){a(d,b,c)}}function f(a,c){for(var d=0;a.length>d;d++){var f=a[d];!c&&A(f,m)&&(f="'"+f+"'"),c?e[c+"-"+f]=b(a[d],c):e[f]=b(a[d])}}var e={nofallthrough:!0,style:"fat-cursor"};return f(i),f(i,"Shift"),f(i,"Ctrl"),f(m),f(m,"Ctrl"),f(k),f(k,"Ctrl"),f(n),f(n,"Ctrl"),e}function Ib(a){a.setCursor(a.getCursor().line,a.getCursor().ch-1,!0),a.setOption("keyMap","vim")}var B,d=/[\d]/,f=[/\w/,/[^\w\s]/],g=[/\S/],i=h(65,26),j=h(97,26),k=h(48,10),l="~`!@#$%^&*()_-+=[{}]\\|/?.,<>:;\"'",m=l.split(""),n=["Left","Right","Up","Down","Space","Backspace","Esc","Home","End","PageUp","PageDown"],o=i.concat(j).concat(k),p=i.concat(j).concat(k).concat('-"'.split("")),E={buildKeyMap:function(){},getRegisterController:function(){return C().registerController},clearVimGlobalState_:function(){B=null},map:function(a,b){Gb.map(a,b)},maybeInitState:function(a){D(a)},handleKey:function(b,c){var d,e=D(b);if("Esc"==c)return e.inputState.reset(),e.visualMode&&ab(b,e),void 0;if(e.visualMode&&W(b.getCursor("head"),b.getCursor("anchor"))&&ab(b,e),e.visualMode||W(b.getCursor("head"),b.getCursor("anchor"))||(e.visualMode=!0,e.visualLine=!1),("0"!=c||"0"==c&&0===e.inputState.getRepeat())&&(d=I.matchCommand(c,a,e)),!d)return u(c)&&e.inputState.pushRepeatDigit(c),void 0;if("keyToKey"==d.type)for(var f=0;d.toKeys.length>f;f++)this.handleKey(b,d.toKeys[f]);else I.processCommand(b,e,d)}};F.prototype.reset=function(){this.prefixRepeat=[],this.motionRepeat=[],this.operator=null,this.operatorArgs=null,this.motion=null,this.motionArgs=null,this.keyBuffer=[],this.registerName=null},F.prototype.pushRepeatDigit=function(a){this.operator?this.motionRepeat=this.motionRepeat.concat(a):this.prefixRepeat=this.prefixRepeat.concat(a)},F.prototype.getRepeat=function(){var a=0;return(this.prefixRepeat.length>0||this.motionRepeat.length>0)&&(a=1,this.prefixRepeat.length>0&&(a*=parseInt(this.prefixRepeat.join(""),10)),this.motionRepeat.length>0&&(a*=parseInt(this.motionRepeat.join(""),10))),a},G.prototype={set:function(a,b){this.text=a,this.linewise=!!b},append:function(a,b){b||this.linewise?(this.text+="\n"+a,this.linewise=!0):this.text+=a},clear:function(){this.text="",this.linewise=!1},toString:function(){return this.text}},H.prototype={pushText:function(a,b,c,d){var e=this.isValidRegister(a)?this.getRegister(a):null;if(!e){switch(b){case"yank":this.registers["0"]=new G(c,d);break;case"delete":case"change":-1==c.indexOf("\n")?this.registers["-"]=new G(c,d):(this.shiftNumericRegisters_(),this.registers["1"]=new G(c,d))}return this.unamedRegister.set(c,d),void 0}var f=v(a);f?(e.append(c,d),this.unamedRegister.append(c,d)):(e.set(c,d),this.unamedRegister.set(c,d))},getRegister:function(a){return this.isValidRegister(a)?(a=a.toLowerCase(),this.registers[a]||(this.registers[a]=new G),this.registers[a]):this.unamedRegister},isValidRegister:function(a){return a&&A(a,p)},shiftNumericRegisters_:function(){for(var a=9;a>=2;a--)this.registers[a]=this.getRegister(""+(a-1))}};var I={matchCommand:function(a,b,c){for(var d=c.inputState,e=d.keyBuffer.concat(a),f=0;b.length>f;f++){var g=b[f];if(S(e,g.keys)){if(e.length<g.keys.length)return d.keyBuffer.push(a),null;if(d.operator&&"action"==g.type)continue;return"character"==g.keys[e.length-1]&&(d.selectedCharacter=e[e.length-1]),d.keyBuffer=[],g}}return d.keyBuffer=[],null},processCommand:function(a,b,c){switch(c.type){case"motion":this.processMotion(a,b,c);break;case"operator":this.processOperator(a,b,c);break;case"operatorMotion":this.processOperatorMotion(a,b,c);break;case"action":this.processAction(a,b,c);break;case"search":this.processSearch(a,b,c);break;case"ex":case"keyToEx":this.processEx(a,b,c);break;default:}},processMotion:function(a,b,c){b.inputState.motion=c.motion,b.inputState.motionArgs=P(c.motionArgs),this.evalInput(a,b)},processOperator:function(a,b,c){var d=b.inputState;if(d.operator){if(d.operator==c.operator)return d.motion="expandToLine",d.motionArgs={linewise:!0},this.evalInput(a,b),void 0;d.reset()}d.operator=c.operator,d.operatorArgs=P(c.operatorArgs),b.visualMode&&this.evalInput(a,b)},processOperatorMotion:function(a,b,c){var d=b.visualMode,e=P(c.operatorMotionArgs);e&&d&&e.visualLine&&(b.visualLine=!0),this.processOperator(a,b,c),d||this.processMotion(a,b,c)},processAction:function(a,b,c){var d=b.inputState,e=d.getRepeat(),f=!!e,g=P(c.actionArgs)||{};d.selectedCharacter&&(g.selectedCharacter=d.selectedCharacter),c.operator&&this.processOperator(a,b,c),c.motion&&this.processMotion(a,b,c),(c.motion||c.operator)&&this.evalInput(a,b),g.repeat=e||1,g.repeatIsExplicit=f,g.registerName=d.registerName,d.reset(),b.lastMotion=null,L[c.action](a,g,b)},processSearch:function(a,b,c){function f(c,d,e){yb(a,c,d,e),I.processMotion(a,b,{type:"motion",motion:"findNext"})}function g(a){f(a,!0,!0)}if(a.getSearchCursor){var d=c.searchArgs.forward;pb(a).setReversed(!d);var e=d?"/":"?";switch(c.searchArgs.querySrc){case"prompt":wb(a,g,e,vb);break;case"wordUnderCursor":var h=eb(a,!1,!0,!1,!0),i=!0;if(h||(h=eb(a,!1,!0,!1,!1),i=!1),!h)return;var j=a.getLine(h.start.line).substring(h.start.ch,h.end.ch+1);j=i?"\\b"+j+"\\b":_(j),a.setCursor(h.start),f(j,!0,!1)}}},processEx:function(a,b,c){function d(b){Gb.processCommand(a,b)}"keyToEx"==c.type?Gb.processCommand(a,c.exArgs.input):wb(a,d,":")},evalInput:function(a,b){var m,n,c=b.inputState,d=c.motion,e=c.motionArgs||{},f=c.operator,g=c.operatorArgs||{},h=c.registerName,i=a.getCursor("head"),j=a.getCursor("anchor"),k=V(i),l=V(k);if(n=void 0!==e.repeat?c.motionArgs.repeat:c.getRepeat(),n>0&&e.explicitRepeat?e.repeatIsExplicit=!0:(e.noRepeat||!e.explicitRepeat&&0===n)&&(n=1,e.repeatIsExplicit=!1),c.selectedCharacter&&(e.selectedCharacter=g.selectedCharacter=c.selectedCharacter),e.repeat=n,c.reset(),d){var o=J[d](a,e,b);if(b.lastMotion=J[d],!o)return;o instanceof Array?(k=o[0],m=o[1]):m=o,m||(m={ch:k.ch,line:k.line}),b.visualMode?(X(j,i)&&(W(j,m)||X(m,j))?j.ch+=1:X(i,j)&&(W(j,m)||X(j,m))&&(j.ch-=1),i=m,b.visualLine&&(X(j,i)?(j.ch=0,i.ch=Y(a,i.line)):(i.ch=0,j.ch=Y(a,j.line))),a.setCursor(j),a.setSelection(j,i)):f||(m=N(a,m),a.setCursor(m.line,m.ch))}if(f){var p=!1;if(b.lastMotion=null,g.repeat=n,b.visualMode&&(k=j,m=i,e.inclusive=!0),X(m,k)){var q=k;k=m,m=q,p=!0}!e.inclusive||b.visualMode&&p||m.ch++;var r=e.linewise||b.visualMode&&b.visualLine;r?cb(a,k,m):e.forward&&bb(a,k,m),g.registerName=h,g.linewise=r,K[f](a,g,b,k,m,l),b.visualMode&&ab(a,b),g.enterInsertMode&&L.enterInsertMode(a)}}},J={expandToLine:function(a,b){var c=a.getCursor();return{line:c.line+b.repeat-1,ch:1/0}},findNext:function(a,b){return Ab(a,!1,b.repeat)},findPrev:function(a,b){return Ab(a,!0,b.repeat)},goToMark:function(a,b,c){var d=c.marks[b.selectedCharacter];return d?d.find():null},moveByCharacters:function(a,b){var c=a.getCursor(),d=b.repeat,e=b.forward?c.ch+d:c.ch-d;return{line:c.line,ch:e}},moveByLines:function(a,b,c){var d=a.getCursor().ch;switch(c.lastMotion){case this.moveByLines:case this.moveToColumn:case this.moveToEol:d=c.lastHPos;break;default:c.lastHPos=d}var e=a.getCursor(),f=b.repeat,g=b.forward?e.line+f:e.line-f;return 0>g||g>a.lineCount()-1?null:{line:g,ch:d}},moveByPage:function(a,b){var c=a.getCursor(),d=b.repeat;a.moveV(b.forward?d:-d,"page");var e=a.getCursor();return a.setCursor(c),e},moveByWords:function(a,b){return gb(a,b.repeat,!!b.forward,!!b.wordEnd,!!b.bigWord)},moveTillCharacter:function(a,b){var c=b.repeat,d=hb(a,c,b.forward,b.selectedCharacter),e=b.forward?-1:1;return d.ch+=e,d},moveToCharacter:function(a,b){var c=b.repeat;return hb(a,c,b.forward,b.selectedCharacter)},moveToColumn:function(a,b,c){var d=b.repeat;return c.lastHPos=d-1,ib(a,d)},moveToEol:function(a,b,c){var d=a.getCursor();return c.lastHPos=1/0,{line:d.line+b.repeat-1,ch:1/0}},moveToFirstNonWhiteSpaceCharacter:function(a){var b=a.getCursor();return a.getLine(b.line),{line:b.line,ch:db(a.getLine(b.line))}},moveToMatchedSymbol:function(a,b){var c=a.getCursor(),d=a.getLine(c.line).charAt(c.ch);return t(d)?kb(a,a.getCursor(),b.symbol):c},moveToStartOfLine:function(a){var b=a.getCursor();return{line:b.line,ch:0}},moveToLineOrEdgeOfDocument:function(a,b){var c=b.forward?a.lineCount()-1:0;return b.repeatIsExplicit&&(c=b.repeat-1),{line:c,ch:db(a.getLine(c))}},textObjectManipulation:function(a,b){var c=b.selectedCharacter,d=!b.textObjectInner;if(!M[c])return null;var e=M[c](a,d),f=e.start,g=e.end;return[f,g]}},K={change:function(a,b,c,d,e){C().registerController.pushText(b.registerName,"change",a.getRange(d,e),b.linewise),b.linewise?(d.ch=db(a.getLine(d.line)),a.replaceRange("\n",d,e)):a.replaceRange("",d,e),a.setCursor(d)},"delete":function(a,b,c,d,e){C().registerController.pushText(b.registerName,"delete",a.getRange(d,e),b.linewise),a.replaceRange("",d,e),b.linewise?a.setCursor(J.moveToFirstNonWhiteSpaceCharacter(a)):a.setCursor(d)},indent:function(a,b,c,d,e){var f=d.line,g=e.line,h=c.visualMode?b.repeat:1;b.linewise&&g--;for(var i=f;g>=i;i++)for(var j=0;h>j;j++)a.indentLine(i,b.indentRight);a.setCursor(d),a.setCursor(J.moveToFirstNonWhiteSpaceCharacter(a))},swapcase:function(a,b,c,d,e,f){for(var g=a.getRange(d,e),h="",i=0;g.length>i;i++){var j=g.charAt(i);h+=v(j)?j.toLowerCase():j.toUpperCase()}a.replaceRange(h,d,e),a.setCursor(f)},yank:function(a,b,c,d,e,f){C().registerController.pushText(b.registerName,"yank",a.getRange(d,e),b.linewise),a.setCursor(f)
5
+ }},L={clearSearchHighlight:Bb,enterInsertMode:function(a,b){var c=b?b.insertAt:null;if("eol"==c){var d=a.getCursor();d={line:d.line,ch:Y(a,d.line)},a.setCursor(d)}else"charAfter"==c&&a.setCursor(Q(a.getCursor(),0,1));a.setOption("keyMap","vim-insert")},toggleVisualMode:function(a,b,c){var f,d=b.repeat,e=a.getCursor();c.visualMode?!c.visualLine&&b.linewise?(c.visualLine=!0,e=a.getCursor("anchor"),f=a.getCursor("head"),e.ch=X(e,f)?0:Y(a,e.line),f.ch=X(e,f)?Y(a,f.line):0,a.setSelection(e,f)):ab(a,c):(c.visualMode=!0,c.visualLine=!!b.linewise,c.visualLine?(e.ch=0,f=N(a,{line:e.line+d-1,ch:Y(a,e.line)},!0)):f=N(a,{line:e.line,ch:e.ch+d},!0),b.repeatIsExplicit||c.visualLine?a.setSelection(e,f):(a.setCursor(f),a.setSelection(f,e)))},joinLines:function(a,b,c){var d,e;if(c.visualMode)d=a.getCursor("anchor"),e=a.getCursor("head"),e.ch=Y(a,e.line)-1;else{var f=Math.max(b.repeat,2);d=a.getCursor(),e=N(a,{line:d.line+f-1,ch:1/0})}var g=0;a.operation(function(){for(var b=d.line;e.line>b;b++){g=Y(a,d.line);var c={line:d.line+1,ch:Y(a,d.line+1)},f=a.getRange(d,c);f=f.replace(/\n\s*/g," "),a.replaceRange(f,d,c)}var h={line:d.line,ch:g};a.setCursor(h)})},newLineAndEnterInsertMode:function(a,b){var c=a.getCursor();if(0!==c.line||b.after){c.line=b.after?c.line:c.line-1,c.ch=Y(a,c.line),a.setCursor(c);var d=CodeMirror.commands.newlineAndIndentContinueComment||CodeMirror.commands.newlineAndIndent;d(a)}else a.replaceRange("\n",{line:0,ch:0}),a.setCursor(0,0);this.enterInsertMode(a)},paste:function(a,b){var d=a.getCursor(),e=C().registerController.getRegister(b.registerName);if(e.text){for(var f="",g=0;b.repeat>g;g++)f+=e.text;var h=e.linewise;h?b.after?(f="\n"+f.slice(0,f.length-1),d.ch=Y(a,d.line)):d.ch=0:d.ch+=b.after?1:0,a.replaceRange(f,d);var i,j;h&&b.after?i={line:d.line+1,ch:db(a.getLine(d.line+1))}:h&&!b.after?i={line:d.line,ch:db(a.getLine(d.line))}:!h&&b.after?(j=a.indexFromPos(d),i=a.posFromIndex(j+f.length-1)):(j=a.indexFromPos(d),i=a.posFromIndex(j+f.length)),a.setCursor(i)}},undo:function(a,b){U(a,CodeMirror.commands.undo,b.repeat)()},redo:function(a,b){U(a,CodeMirror.commands.redo,b.repeat)()},setRegister:function(a,b,c){c.inputState.registerName=b.selectedCharacter},setMark:function(a,b,c){var d=b.selectedCharacter;A(d,o)&&(c.marks[d]&&c.marks[d].clear(),c.marks[d]=a.setBookmark(a.getCursor()))},replace:function(a,b){var c=b.selectedCharacter,d=a.getCursor(),e=a.getLine(d.line),f=d.ch+b.repeat;if(!(f>e.length)){for(var g={line:d.line,ch:f},h="",i=0;g.ch-d.ch>i;i++)h+=c;a.replaceRange(h,d,g),a.setCursor(Q(g,0,-1))}}},M={w:function(a,b){return eb(a,b,!0,!1)},W:function(a,b){return eb(a,b,!0,!0)},"{":function(a,b){return lb(a,"}",b)},"(":function(a,b){return lb(a,")",b)},"[":function(a,b){return lb(a,"]",b)},"'":function(a,b){return nb(a,"'",b)},'"':function(a,b){return nb(a,'"',b)}};ob.prototype={getQuery:function(){return C().query},setQuery:function(a){C().query=a},getMarked:function(){return this.marked},setMarked:function(a){this.marked=a},isReversed:function(){return C().isReversed},setReversed:function(a){C().isReversed=a}};var vb="(Javascript regexp)",Cb=[{name:"map",type:"builtIn"},{name:"write",shortName:"w",type:"builtIn"},{name:"undo",shortName:"u",type:"builtIn"},{name:"redo",shortName:"red",type:"builtIn"}],Db=function(){this.buildCommandMap_()};Db.prototype={processCommand:function(a,b){var e,d=this.parseInput_(b);if(d.commandName){var f=this.matchCommand_(d.commandName);if(f){if(e=f.name,"exToKey"==f.type){for(var g=0;f.toKeys.length>g;g++)c.handleKey(a,f.toKeys[g]);return}if("exToEx"==f.type)return this.processCommand(a,f.toInput),void 0}}else void 0!==d.line&&(e="move");return e?(Fb[e](a,d),void 0):(tb(a,'Not an editor command ":'+b+'"'),void 0)},parseInput_:function(a){var b={};b.input=a;var c=0,d=/^:+/.exec(a);d&&(c+=d[0].length);var e=/^(\d+)/.exec(a.substring(c));e&&(b.line=parseInt(e[1],10),c+=e[0].length);var f=/^(\w+)/.exec(a.substring(c));f&&(b.commandName=f[1],c+=f[1].length);var g=$(a.substring(c)).split(/\s+/);return g.length&&g[0]&&(b.commandArgs=g),b},matchCommand_:function(a){for(var b=a.length;b>0;b--){var c=a.substring(0,b);if(this.commandMap_[c]){var d=this.commandMap_[c];if(0===d.name.indexOf(a))return d}}return null},buildCommandMap_:function(){this.commandMap_={};for(var a=0;Cb.length>a;a++){var b=Cb[a],c=b.shortName||b.name;this.commandMap_[c]=b}},map:function(b,c){if(":"==b.charAt(0)){var d=b.substring(1);this.commandMap_[d]=":"==c.charAt(0)?{name:d,type:"exToEx",toInput:c.substring(1)}:{name:d,type:"exToKey",toKeys:Eb(c)}}else":"==c.charAt(0)?a.unshift({keys:Eb(b),type:"keyToEx",exArgs:{input:c.substring(1)}}):a.unshift({keys:Eb(b),type:"keyToKey",toKeys:Eb(c)})}};var Fb={map:function(a,b){var c=b.commandArgs;return!c||2>c.length?(a&&tb(a,"Invalid mapping: "+b.input),void 0):(Gb.map(c[0],c[1],a),void 0)},move:function(a,b){I.processMotion(a,D(a),{motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0,repeat:b.line}})},redo:CodeMirror.commands.redo,undo:CodeMirror.commands.undo,write:function(a){CodeMirror.commands.save?CodeMirror.commands.save(a):a.save()}},Gb=new Db;return CodeMirror.keyMap.vim=Hb(),CodeMirror.keyMap["vim-insert"]={Esc:Ib,"Ctrl-[":Ib,"Ctrl-C":Ib,"Ctrl-N":"autocomplete","Ctrl-P":"autocomplete",Enter:function(a){var b=CodeMirror.commands.newlineAndIndentContinueComment||CodeMirror.commands.newlineAndIndent;b(a)},fallthrough:["default"]},E},c=b();CodeMirror.Vim=c}();
@@ -0,0 +1,30 @@
1
+ // TODO number prefixes
2
+ (function() {
3
+ // Really primitive kill-ring implementation.
4
+ var killRing = [];
5
+ function addToRing(str) {
6
+ killRing.push(str);
7
+ if (killRing.length > 50) killRing.shift();
8
+ }
9
+ function getFromRing() { return killRing[killRing.length - 1] || ""; }
10
+ function popFromRing() { if (killRing.length > 1) killRing.pop(); return getFromRing(); }
11
+
12
+ CodeMirror.keyMap.emacs = {
13
+ "Ctrl-X": function(cm) {cm.setOption("keyMap", "emacs-Ctrl-X");},
14
+ "Ctrl-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
15
+ "Ctrl-Alt-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
16
+ "Alt-W": function(cm) {addToRing(cm.getSelection());},
17
+ "Ctrl-Y": function(cm) {cm.replaceSelection(getFromRing());},
18
+ "Alt-Y": function(cm) {cm.replaceSelection(popFromRing());},
19
+ "Ctrl-/": "undo", "Shift-Ctrl--": "undo", "Shift-Alt-,": "goDocStart", "Shift-Alt-.": "goDocEnd",
20
+ "Ctrl-S": "findNext", "Ctrl-R": "findPrev", "Ctrl-G": "clearSearch", "Shift-Alt-5": "replace",
21
+ "Ctrl-Z": "undo", "Cmd-Z": "undo", "Alt-/": "autocomplete", "Alt-V": "goPageUp",
22
+ "Ctrl-J": "newlineAndIndent", "Enter": false, "Tab": "indentAuto",
23
+ fallthrough: ["basic", "emacsy"]
24
+ };
25
+
26
+ CodeMirror.keyMap["emacs-Ctrl-X"] = {
27
+ "Ctrl-S": "save", "Ctrl-W": "save", "S": "saveAll", "F": "open", "U": "undo", "K": "close",
28
+ auto: "emacs", nofallthrough: true
29
+ };
30
+ })();
@@ -0,0 +1,2298 @@
1
+ /**
2
+ * Supported keybindings:
3
+ *
4
+ * Motion:
5
+ * h, j, k, l
6
+ * e, E, w, W, b, B, ge, gE
7
+ * f<character>, F<character>, t<character>, T<character>
8
+ * $, ^, 0
9
+ * gg, G
10
+ * %
11
+ * '<character>, `<character>
12
+ *
13
+ * Operator:
14
+ * d, y, c
15
+ * dd, yy, cc
16
+ * g~, g~g~
17
+ * >, <, >>, <<
18
+ *
19
+ * Operator-Motion:
20
+ * x, X, D, Y, C, ~
21
+ *
22
+ * Action:
23
+ * a, i, s, A, I, S, o, O
24
+ * J
25
+ * u, Ctrl-r
26
+ * m<character>
27
+ * r<character>
28
+ *
29
+ * Modes:
30
+ * ESC - leave insert mode, visual mode, and clear input state.
31
+ * Ctrl-[, Ctrl-c - same as ESC.
32
+ *
33
+ * Registers: unamed, -, a-z, A-Z, 0-9
34
+ * (Does not respect the special case for number registers when delete
35
+ * operator is made with these commands: %, (, ), , /, ?, n, N, {, } )
36
+ * TODO: Implement the remaining registers.
37
+ * Marks: a-z, A-Z, and 0-9
38
+ * TODO: Implement the remaining special marks. They have more complex
39
+ * behavior.
40
+ *
41
+ * Code structure:
42
+ * 1. Default keymap
43
+ * 2. Variable declarations and short basic helpers
44
+ * 3. Instance (External API) implementation
45
+ * 4. Internal state tracking objects (input state, counter) implementation
46
+ * and instanstiation
47
+ * 5. Key handler (the main command dispatcher) implementation
48
+ * 6. Motion, operator, and action implementations
49
+ * 7. Helper functions for the key handler, motions, operators, and actions
50
+ * 8. Set up Vim to work as a keymap for CodeMirror.
51
+ */
52
+
53
+ (function() {
54
+ 'use strict';
55
+
56
+ var defaultKeymap = [
57
+ // Key to key mapping. This goes first to make it possible to override
58
+ // existing mappings.
59
+ { keys: ['Left'], type: 'keyToKey', toKeys: ['h'] },
60
+ { keys: ['Right'], type: 'keyToKey', toKeys: ['l'] },
61
+ { keys: ['Up'], type: 'keyToKey', toKeys: ['k'] },
62
+ { keys: ['Down'], type: 'keyToKey', toKeys: ['j'] },
63
+ { keys: ['Space'], type: 'keyToKey', toKeys: ['l'] },
64
+ { keys: ['Backspace'], type: 'keyToKey', toKeys: ['h'] },
65
+ { keys: ['Ctrl-Space'], type: 'keyToKey', toKeys: ['W'] },
66
+ { keys: ['Ctrl-Backspace'], type: 'keyToKey', toKeys: ['B'] },
67
+ { keys: ['Shift-Space'], type: 'keyToKey', toKeys: ['w'] },
68
+ { keys: ['Shift-Backspace'], type: 'keyToKey', toKeys: ['b'] },
69
+ { keys: ['Ctrl-n'], type: 'keyToKey', toKeys: ['j'] },
70
+ { keys: ['Ctrl-p'], type: 'keyToKey', toKeys: ['k'] },
71
+ { keys: ['Ctrl-['], type: 'keyToKey', toKeys: ['Esc'] },
72
+ { keys: ['Ctrl-c'], type: 'keyToKey', toKeys: ['Esc'] },
73
+ { keys: ['s'], type: 'keyToKey', toKeys: ['c', 'l'] },
74
+ { keys: ['S'], type: 'keyToKey', toKeys: ['c', 'c'] },
75
+ { keys: ['Home'], type: 'keyToKey', toKeys: ['0'] },
76
+ { keys: ['End'], type: 'keyToKey', toKeys: ['$'] },
77
+ { keys: ['PageUp'], type: 'keyToKey', toKeys: ['Ctrl-b'] },
78
+ { keys: ['PageDown'], type: 'keyToKey', toKeys: ['Ctrl-f'] },
79
+ // Motions
80
+ { keys: ['h'], type: 'motion',
81
+ motion: 'moveByCharacters',
82
+ motionArgs: { forward: false }},
83
+ { keys: ['l'], type: 'motion',
84
+ motion: 'moveByCharacters',
85
+ motionArgs: { forward: true }},
86
+ { keys: ['j'], type: 'motion',
87
+ motion: 'moveByLines',
88
+ motionArgs: { forward: true, linewise: true }},
89
+ { keys: ['k'], type: 'motion',
90
+ motion: 'moveByLines',
91
+ motionArgs: { forward: false, linewise: true }},
92
+ { keys: ['w'], type: 'motion',
93
+ motion: 'moveByWords',
94
+ motionArgs: { forward: true, wordEnd: false }},
95
+ { keys: ['W'], type: 'motion',
96
+ motion: 'moveByWords',
97
+ motionArgs: { forward: true, wordEnd: false, bigWord: true }},
98
+ { keys: ['e'], type: 'motion',
99
+ motion: 'moveByWords',
100
+ motionArgs: { forward: true, wordEnd: true, inclusive: true }},
101
+ { keys: ['E'], type: 'motion',
102
+ motion: 'moveByWords',
103
+ motionArgs: { forward: true, wordEnd: true, bigWord: true,
104
+ inclusive: true }},
105
+ { keys: ['b'], type: 'motion',
106
+ motion: 'moveByWords',
107
+ motionArgs: { forward: false, wordEnd: false }},
108
+ { keys: ['B'], type: 'motion',
109
+ motion: 'moveByWords',
110
+ motionArgs: { forward: false, wordEnd: false, bigWord: true }},
111
+ { keys: ['g', 'e'], type: 'motion',
112
+ motion: 'moveByWords',
113
+ motionArgs: { forward: false, wordEnd: true, inclusive: true }},
114
+ { keys: ['g', 'E'], type: 'motion',
115
+ motion: 'moveByWords',
116
+ motionArgs: { forward: false, wordEnd: true, bigWord: true,
117
+ inclusive: true }},
118
+ { keys: ['Ctrl-f'], type: 'motion',
119
+ motion: 'moveByPage', motionArgs: { forward: true }},
120
+ { keys: ['Ctrl-b'], type: 'motion',
121
+ motion: 'moveByPage', motionArgs: { forward: false }},
122
+ { keys: ['g', 'g'], type: 'motion',
123
+ motion: 'moveToLineOrEdgeOfDocument',
124
+ motionArgs: { forward: false, explicitRepeat: true, linewise: true }},
125
+ { keys: ['G'], type: 'motion',
126
+ motion: 'moveToLineOrEdgeOfDocument',
127
+ motionArgs: { forward: true, explicitRepeat: true, linewise: true }},
128
+ { keys: ['0'], type: 'motion', motion: 'moveToStartOfLine' },
129
+ { keys: ['^'], type: 'motion',
130
+ motion: 'moveToFirstNonWhiteSpaceCharacter' },
131
+ { keys: ['$'], type: 'motion',
132
+ motion: 'moveToEol',
133
+ motionArgs: { inclusive: true }},
134
+ { keys: ['%'], type: 'motion',
135
+ motion: 'moveToMatchedSymbol',
136
+ motionArgs: { inclusive: true }},
137
+ { keys: ['f', 'character'], type: 'motion',
138
+ motion: 'moveToCharacter',
139
+ motionArgs: { forward: true , inclusive: true }},
140
+ { keys: ['F', 'character'], type: 'motion',
141
+ motion: 'moveToCharacter',
142
+ motionArgs: { forward: false }},
143
+ { keys: ['t', 'character'], type: 'motion',
144
+ motion: 'moveTillCharacter',
145
+ motionArgs: { forward: true, inclusive: true }},
146
+ { keys: ['T', 'character'], type: 'motion',
147
+ motion: 'moveTillCharacter',
148
+ motionArgs: { forward: false }},
149
+ { keys: ['\'', 'character'], type: 'motion', motion: 'goToMark' },
150
+ { keys: ['`', 'character'], type: 'motion', motion: 'goToMark' },
151
+ { keys: ['|'], type: 'motion',
152
+ motion: 'moveToColumn',
153
+ motionArgs: { }},
154
+ // Operators
155
+ { keys: ['d'], type: 'operator', operator: 'delete' },
156
+ { keys: ['y'], type: 'operator', operator: 'yank' },
157
+ { keys: ['c'], type: 'operator', operator: 'change',
158
+ operatorArgs: { enterInsertMode: true } },
159
+ { keys: ['>'], type: 'operator', operator: 'indent',
160
+ operatorArgs: { indentRight: true }},
161
+ { keys: ['<'], type: 'operator', operator: 'indent',
162
+ operatorArgs: { indentRight: false }},
163
+ { keys: ['g', '~'], type: 'operator', operator: 'swapcase' },
164
+ { keys: ['n'], type: 'motion', motion: 'findNext' },
165
+ { keys: ['N'], type: 'motion', motion: 'findPrev' },
166
+ // Operator-Motion dual commands
167
+ { keys: ['x'], type: 'operatorMotion', operator: 'delete',
168
+ motion: 'moveByCharacters', motionArgs: { forward: true },
169
+ operatorMotionArgs: { visualLine: false }},
170
+ { keys: ['X'], type: 'operatorMotion', operator: 'delete',
171
+ motion: 'moveByCharacters', motionArgs: { forward: false },
172
+ operatorMotionArgs: { visualLine: true }},
173
+ { keys: ['D'], type: 'operatorMotion', operator: 'delete',
174
+ motion: 'moveToEol', motionArgs: { inclusive: true },
175
+ operatorMotionArgs: { visualLine: true }},
176
+ { keys: ['Y'], type: 'operatorMotion', operator: 'yank',
177
+ motion: 'moveToEol', motionArgs: { inclusive: true },
178
+ operatorMotionArgs: { visualLine: true }},
179
+ { keys: ['C'], type: 'operatorMotion',
180
+ operator: 'change', operatorArgs: { enterInsertMode: true },
181
+ motion: 'moveToEol', motionArgs: { inclusive: true },
182
+ operatorMotionArgs: { visualLine: true }},
183
+ { keys: ['~'], type: 'operatorMotion', operator: 'swapcase',
184
+ motion: 'moveByCharacters', motionArgs: { forward: true }},
185
+ // Actions
186
+ { keys: ['a'], type: 'action', action: 'enterInsertMode',
187
+ actionArgs: { insertAt: 'charAfter' }},
188
+ { keys: ['A'], type: 'action', action: 'enterInsertMode',
189
+ actionArgs: { insertAt: 'eol' }},
190
+ { keys: ['i'], type: 'action', action: 'enterInsertMode' },
191
+ { keys: ['I'], type: 'action', action: 'enterInsertMode',
192
+ motion: 'moveToFirstNonWhiteSpaceCharacter' },
193
+ { keys: ['o'], type: 'action', action: 'newLineAndEnterInsertMode',
194
+ actionArgs: { after: true }},
195
+ { keys: ['O'], type: 'action', action: 'newLineAndEnterInsertMode',
196
+ actionArgs: { after: false }},
197
+ { keys: ['v'], type: 'action', action: 'toggleVisualMode' },
198
+ { keys: ['V'], type: 'action', action: 'toggleVisualMode',
199
+ actionArgs: { linewise: true }},
200
+ { keys: ['J'], type: 'action', action: 'joinLines' },
201
+ { keys: ['p'], type: 'action', action: 'paste',
202
+ actionArgs: { after: true }},
203
+ { keys: ['P'], type: 'action', action: 'paste',
204
+ actionArgs: { after: false }},
205
+ { keys: ['r', 'character'], type: 'action', action: 'replace' },
206
+ { keys: ['u'], type: 'action', action: 'undo' },
207
+ { keys: ['Ctrl-r'], type: 'action', action: 'redo' },
208
+ { keys: ['m', 'character'], type: 'action', action: 'setMark' },
209
+ { keys: ['\"', 'character'], type: 'action', action: 'setRegister' },
210
+ { keys: [',', '/'], type: 'action', action: 'clearSearchHighlight' },
211
+ // Text object motions
212
+ { keys: ['a', 'character'], type: 'motion',
213
+ motion: 'textObjectManipulation' },
214
+ { keys: ['i', 'character'], type: 'motion',
215
+ motion: 'textObjectManipulation',
216
+ motionArgs: { textObjectInner: true }},
217
+ // Search
218
+ { keys: ['/'], type: 'search',
219
+ searchArgs: { forward: true, querySrc: 'prompt' }},
220
+ { keys: ['?'], type: 'search',
221
+ searchArgs: { forward: false, querySrc: 'prompt' }},
222
+ { keys: ['*'], type: 'search',
223
+ searchArgs: { forward: true, querySrc: 'wordUnderCursor' }},
224
+ { keys: ['#'], type: 'search',
225
+ searchArgs: { forward: false, querySrc: 'wordUnderCursor' }},
226
+ // Ex command
227
+ { keys: [':'], type: 'ex' }
228
+ ];
229
+
230
+ var Vim = function() {
231
+ var alphabetRegex = /[A-Za-z]/;
232
+ var numberRegex = /[\d]/;
233
+ var whiteSpaceRegex = /\s/;
234
+ var wordRegexp = [(/\w/), (/[^\w\s]/)], bigWordRegexp = [(/\S/)];
235
+ function makeKeyRange(start, size) {
236
+ var keys = [];
237
+ for (var i = start; i < start + size; i++) {
238
+ keys.push(String.fromCharCode(i));
239
+ }
240
+ return keys;
241
+ }
242
+ var upperCaseAlphabet = makeKeyRange(65, 26);
243
+ var lowerCaseAlphabet = makeKeyRange(97, 26);
244
+ var numbers = makeKeyRange(48, 10);
245
+ var SPECIAL_SYMBOLS = '~`!@#$%^&*()_-+=[{}]\\|/?.,<>:;\"\'';
246
+ var specialSymbols = SPECIAL_SYMBOLS.split('');
247
+ var specialKeys = ['Left', 'Right', 'Up', 'Down', 'Space', 'Backspace',
248
+ 'Esc', 'Home', 'End', 'PageUp', 'PageDown'];
249
+ var validMarks = upperCaseAlphabet.concat(lowerCaseAlphabet).concat(
250
+ numbers);
251
+ var validRegisters = upperCaseAlphabet.concat(lowerCaseAlphabet).concat(
252
+ numbers).concat('-\"'.split(''));
253
+
254
+ function isAlphabet(k) {
255
+ return alphabetRegex.test(k);
256
+ }
257
+ function isLine(cm, line) {
258
+ return line >= 0 && line < cm.lineCount();
259
+ }
260
+ function isLowerCase(k) {
261
+ return (/^[a-z]$/).test(k);
262
+ }
263
+ function isMatchableSymbol(k) {
264
+ return '()[]{}'.indexOf(k) != -1;
265
+ }
266
+ function isNumber(k) {
267
+ return numberRegex.test(k);
268
+ }
269
+ function isUpperCase(k) {
270
+ return (/^[A-Z]$/).test(k);
271
+ }
272
+ function isAlphanumeric(k) {
273
+ return (/^[\w]$/).test(k);
274
+ }
275
+ function isWhiteSpace(k) {
276
+ return whiteSpaceRegex.test(k);
277
+ }
278
+ function isWhiteSpaceString(k) {
279
+ return (/^\s*$/).test(k);
280
+ }
281
+ function inRangeInclusive(x, start, end) {
282
+ return x >= start && x <= end;
283
+ }
284
+ function inArray(val, arr) {
285
+ for (var i = 0; i < arr.length; i++) {
286
+ if (arr[i] == val) {
287
+ return true;
288
+ }
289
+ }
290
+ return false;
291
+ }
292
+
293
+ // Global Vim state. Call getVimGlobalState to get and initialize.
294
+ var vimGlobalState;
295
+ function getVimGlobalState() {
296
+ if (!vimGlobalState) {
297
+ vimGlobalState = {
298
+ // The current search query.
299
+ searchQuery: null,
300
+ // Whether we are searching backwards.
301
+ searchIsReversed: false,
302
+ registerController: new RegisterController({})
303
+ };
304
+ }
305
+ return vimGlobalState;
306
+ }
307
+ function getVimState(cm) {
308
+ if (!cm.vimState) {
309
+ // Store instance state in the CodeMirror object.
310
+ cm.vimState = {
311
+ inputState: new InputState(),
312
+ // When using jk for navigation, if you move from a longer line to a
313
+ // shorter line, the cursor may clip to the end of the shorter line.
314
+ // If j is pressed again and cursor goes to the next line, the
315
+ // cursor should go back to its horizontal position on the longer
316
+ // line if it can. This is to keep track of the horizontal position.
317
+ lastHPos: -1,
318
+ // The last motion command run. Cleared if a non-motion command gets
319
+ // executed in between.
320
+ lastMotion: null,
321
+ marks: {},
322
+ visualMode: false,
323
+ // If we are in visual line mode. No effect if visualMode is false.
324
+ visualLine: false
325
+ };
326
+ }
327
+ return cm.vimState;
328
+ }
329
+
330
+ var vimApi= {
331
+ buildKeyMap: function() {
332
+ // TODO: Convert keymap into dictionary format for fast lookup.
333
+ },
334
+ // Testing hook, though it might be useful to expose the register
335
+ // controller anyways.
336
+ getRegisterController: function() {
337
+ return getVimGlobalState().registerController;
338
+ },
339
+ // Testing hook.
340
+ clearVimGlobalState_: function() {
341
+ vimGlobalState = null;
342
+ },
343
+ map: function(lhs, rhs) {
344
+ // Add user defined key bindings.
345
+ exCommandDispatcher.map(lhs, rhs);
346
+ },
347
+ // Initializes vim state variable on the CodeMirror object. Should only be
348
+ // called lazily by handleKey or for testing.
349
+ maybeInitState: function(cm) {
350
+ getVimState(cm);
351
+ },
352
+ // This is the outermost function called by CodeMirror, after keys have
353
+ // been mapped to their Vim equivalents.
354
+ handleKey: function(cm, key) {
355
+ var command;
356
+ var vim = getVimState(cm);
357
+ if (key == 'Esc') {
358
+ // Clear input state and get back to normal mode.
359
+ vim.inputState.reset();
360
+ if (vim.visualMode) {
361
+ exitVisualMode(cm, vim);
362
+ }
363
+ return;
364
+ }
365
+ if (vim.visualMode &&
366
+ cursorEqual(cm.getCursor('head'), cm.getCursor('anchor'))) {
367
+ // The selection was cleared. Exit visual mode.
368
+ exitVisualMode(cm, vim);
369
+ }
370
+ if (!vim.visualMode &&
371
+ !cursorEqual(cm.getCursor('head'), cm.getCursor('anchor'))) {
372
+ vim.visualMode = true;
373
+ vim.visualLine = false;
374
+ }
375
+ if (key != '0' || (key == '0' && vim.inputState.getRepeat() === 0)) {
376
+ // Have to special case 0 since it's both a motion and a number.
377
+ command = commandDispatcher.matchCommand(key, defaultKeymap, vim);
378
+ }
379
+ if (!command) {
380
+ if (isNumber(key)) {
381
+ // Increment count unless count is 0 and key is 0.
382
+ vim.inputState.pushRepeatDigit(key);
383
+ }
384
+ return;
385
+ }
386
+ if (command.type == 'keyToKey') {
387
+ // TODO: prevent infinite recursion.
388
+ for (var i = 0; i < command.toKeys.length; i++) {
389
+ this.handleKey(cm, command.toKeys[i]);
390
+ }
391
+ } else {
392
+ commandDispatcher.processCommand(cm, vim, command);
393
+ }
394
+ }
395
+ };
396
+
397
+ // Represents the current input state.
398
+ function InputState() {
399
+ this.reset();
400
+ }
401
+ InputState.prototype.reset = function() {
402
+ this.prefixRepeat = [];
403
+ this.motionRepeat = [];
404
+
405
+ this.operator = null;
406
+ this.operatorArgs = null;
407
+ this.motion = null;
408
+ this.motionArgs = null;
409
+ this.keyBuffer = []; // For matching multi-key commands.
410
+ this.registerName = null; // Defaults to the unamed register.
411
+ };
412
+ InputState.prototype.pushRepeatDigit = function(n) {
413
+ if (!this.operator) {
414
+ this.prefixRepeat = this.prefixRepeat.concat(n);
415
+ } else {
416
+ this.motionRepeat = this.motionRepeat.concat(n);
417
+ }
418
+ };
419
+ InputState.prototype.getRepeat = function() {
420
+ var repeat = 0;
421
+ if (this.prefixRepeat.length > 0 || this.motionRepeat.length > 0) {
422
+ repeat = 1;
423
+ if (this.prefixRepeat.length > 0) {
424
+ repeat *= parseInt(this.prefixRepeat.join(''), 10);
425
+ }
426
+ if (this.motionRepeat.length > 0) {
427
+ repeat *= parseInt(this.motionRepeat.join(''), 10);
428
+ }
429
+ }
430
+ return repeat;
431
+ };
432
+
433
+ /*
434
+ * Register stores information about copy and paste registers. Besides
435
+ * text, a register must store whether it is linewise (i.e., when it is
436
+ * pasted, should it insert itself into a new line, or should the text be
437
+ * inserted at the cursor position.)
438
+ */
439
+ function Register(text, linewise) {
440
+ this.clear();
441
+ if (text) {
442
+ this.set(text, linewise);
443
+ }
444
+ }
445
+ Register.prototype = {
446
+ set: function(text, linewise) {
447
+ this.text = text;
448
+ this.linewise = !!linewise;
449
+ },
450
+ append: function(text, linewise) {
451
+ // if this register has ever been set to linewise, use linewise.
452
+ if (linewise || this.linewise) {
453
+ this.text += '\n' + text;
454
+ this.linewise = true;
455
+ } else {
456
+ this.text += text;
457
+ }
458
+ },
459
+ clear: function() {
460
+ this.text = '';
461
+ this.linewise = false;
462
+ },
463
+ toString: function() { return this.text; }
464
+ };
465
+
466
+ /*
467
+ * vim registers allow you to keep many independent copy and paste buffers.
468
+ * See http://usevim.com/2012/04/13/registers/ for an introduction.
469
+ *
470
+ * RegisterController keeps the state of all the registers. An initial
471
+ * state may be passed in. The unnamed register '"' will always be
472
+ * overridden.
473
+ */
474
+ function RegisterController(registers) {
475
+ this.registers = registers;
476
+ this.unamedRegister = registers['\"'] = new Register();
477
+ }
478
+ RegisterController.prototype = {
479
+ pushText: function(registerName, operator, text, linewise) {
480
+ // Lowercase and uppercase registers refer to the same register.
481
+ // Uppercase just means append.
482
+ var register = this.isValidRegister(registerName) ?
483
+ this.getRegister(registerName) : null;
484
+ // if no register/an invalid register was specified, things go to the
485
+ // default registers
486
+ if (!register) {
487
+ switch (operator) {
488
+ case 'yank':
489
+ // The 0 register contains the text from the most recent yank.
490
+ this.registers['0'] = new Register(text, linewise);
491
+ break;
492
+ case 'delete':
493
+ case 'change':
494
+ if (text.indexOf('\n') == -1) {
495
+ // Delete less than 1 line. Update the small delete register.
496
+ this.registers['-'] = new Register(text, linewise);
497
+ } else {
498
+ // Shift down the contents of the numbered registers and put the
499
+ // deleted text into register 1.
500
+ this.shiftNumericRegisters_();
501
+ this.registers['1'] = new Register(text, linewise);
502
+ }
503
+ break;
504
+ }
505
+ // Make sure the unnamed register is set to what just happened
506
+ this.unamedRegister.set(text, linewise);
507
+ return;
508
+ }
509
+
510
+ // If we've gotten to this point, we've actually specified a register
511
+ var append = isUpperCase(registerName);
512
+ if (append) {
513
+ register.append(text, linewise);
514
+ // The unamed register always has the same value as the last used
515
+ // register.
516
+ this.unamedRegister.append(text, linewise);
517
+ } else {
518
+ register.set(text, linewise);
519
+ this.unamedRegister.set(text, linewise);
520
+ }
521
+ },
522
+ // Gets the register named @name. If one of @name doesn't already exist,
523
+ // create it. If @name is invalid, return the unamedRegister.
524
+ getRegister: function(name) {
525
+ if (!this.isValidRegister(name)) {
526
+ return this.unamedRegister;
527
+ }
528
+ name = name.toLowerCase();
529
+ if (!this.registers[name]) {
530
+ this.registers[name] = new Register();
531
+ }
532
+ return this.registers[name];
533
+ },
534
+ isValidRegister: function(name) {
535
+ return name && inArray(name, validRegisters);
536
+ },
537
+ shiftNumericRegisters_: function() {
538
+ for (var i = 9; i >= 2; i--) {
539
+ this.registers[i] = this.getRegister('' + (i - 1));
540
+ }
541
+ }
542
+ };
543
+
544
+ var commandDispatcher = {
545
+ matchCommand: function(key, keyMap, vim) {
546
+ var inputState = vim.inputState;
547
+ var keys = inputState.keyBuffer.concat(key);
548
+ for (var i = 0; i < keyMap.length; i++) {
549
+ var command = keyMap[i];
550
+ if (matchKeysPartial(keys, command.keys)) {
551
+ if (keys.length < command.keys.length) {
552
+ // Matches part of a multi-key command. Buffer and wait for next
553
+ // stroke.
554
+ inputState.keyBuffer.push(key);
555
+ return null;
556
+ } else {
557
+ if (inputState.operator && command.type == 'action') {
558
+ // Ignore matched action commands after an operator. Operators
559
+ // only operate on motions. This check is really for text
560
+ // objects since aW, a[ etcs conflicts with a.
561
+ continue;
562
+ }
563
+ // Matches whole comand. Return the command.
564
+ if (command.keys[keys.length - 1] == 'character') {
565
+ inputState.selectedCharacter = keys[keys.length - 1];
566
+ }
567
+ inputState.keyBuffer = [];
568
+ return command;
569
+ }
570
+ }
571
+ }
572
+ // Clear the buffer since there are no partial matches.
573
+ inputState.keyBuffer = [];
574
+ return null;
575
+ },
576
+ processCommand: function(cm, vim, command) {
577
+ switch (command.type) {
578
+ case 'motion':
579
+ this.processMotion(cm, vim, command);
580
+ break;
581
+ case 'operator':
582
+ this.processOperator(cm, vim, command);
583
+ break;
584
+ case 'operatorMotion':
585
+ this.processOperatorMotion(cm, vim, command);
586
+ break;
587
+ case 'action':
588
+ this.processAction(cm, vim, command);
589
+ break;
590
+ case 'search':
591
+ this.processSearch(cm, vim, command);
592
+ break;
593
+ case 'ex':
594
+ case 'keyToEx':
595
+ this.processEx(cm, vim, command);
596
+ break;
597
+ default:
598
+ break;
599
+ }
600
+ },
601
+ processMotion: function(cm, vim, command) {
602
+ vim.inputState.motion = command.motion;
603
+ vim.inputState.motionArgs = copyArgs(command.motionArgs);
604
+ this.evalInput(cm, vim);
605
+ },
606
+ processOperator: function(cm, vim, command) {
607
+ var inputState = vim.inputState;
608
+ if (inputState.operator) {
609
+ if (inputState.operator == command.operator) {
610
+ // Typing an operator twice like 'dd' makes the operator operate
611
+ // linewise
612
+ inputState.motion = 'expandToLine';
613
+ inputState.motionArgs = { linewise: true };
614
+ this.evalInput(cm, vim);
615
+ return;
616
+ } else {
617
+ // 2 different operators in a row doesn't make sense.
618
+ inputState.reset();
619
+ }
620
+ }
621
+ inputState.operator = command.operator;
622
+ inputState.operatorArgs = copyArgs(command.operatorArgs);
623
+ if (vim.visualMode) {
624
+ // Operating on a selection in visual mode. We don't need a motion.
625
+ this.evalInput(cm, vim);
626
+ }
627
+ },
628
+ processOperatorMotion: function(cm, vim, command) {
629
+ var visualMode = vim.visualMode;
630
+ var operatorMotionArgs = copyArgs(command.operatorMotionArgs);
631
+ if (operatorMotionArgs) {
632
+ // Operator motions may have special behavior in visual mode.
633
+ if (visualMode && operatorMotionArgs.visualLine) {
634
+ vim.visualLine = true;
635
+ }
636
+ }
637
+ this.processOperator(cm, vim, command);
638
+ if (!visualMode) {
639
+ this.processMotion(cm, vim, command);
640
+ }
641
+ },
642
+ processAction: function(cm, vim, command) {
643
+ var inputState = vim.inputState;
644
+ var repeat = inputState.getRepeat();
645
+ var repeatIsExplicit = !!repeat;
646
+ var actionArgs = copyArgs(command.actionArgs) || {};
647
+ if (inputState.selectedCharacter) {
648
+ actionArgs.selectedCharacter = inputState.selectedCharacter;
649
+ }
650
+ // Actions may or may not have motions and operators. Do these first.
651
+ if (command.operator) {
652
+ this.processOperator(cm, vim, command);
653
+ }
654
+ if (command.motion) {
655
+ this.processMotion(cm, vim, command);
656
+ }
657
+ if (command.motion || command.operator) {
658
+ this.evalInput(cm, vim);
659
+ }
660
+ actionArgs.repeat = repeat || 1;
661
+ actionArgs.repeatIsExplicit = repeatIsExplicit;
662
+ actionArgs.registerName = inputState.registerName;
663
+ inputState.reset();
664
+ vim.lastMotion = null,
665
+ actions[command.action](cm, actionArgs, vim);
666
+ },
667
+ processSearch: function(cm, vim, command) {
668
+ if (!cm.getSearchCursor) {
669
+ // Search depends on SearchCursor.
670
+ return;
671
+ }
672
+ var forward = command.searchArgs.forward;
673
+ getSearchState(cm).setReversed(!forward);
674
+ var promptPrefix = (forward) ? '/' : '?';
675
+ function handleQuery(query, ignoreCase, smartCase) {
676
+ updateSearchQuery(cm, query, ignoreCase, smartCase);
677
+ commandDispatcher.processMotion(cm, vim, {
678
+ type: 'motion',
679
+ motion: 'findNext'
680
+ });
681
+ }
682
+ function onPromptClose(query) {
683
+ handleQuery(query, true /** ignoreCase */, true /** smartCase */);
684
+ }
685
+ switch (command.searchArgs.querySrc) {
686
+ case 'prompt':
687
+ showPrompt(cm, onPromptClose, promptPrefix, searchPromptDesc);
688
+ break;
689
+ case 'wordUnderCursor':
690
+ var word = expandWordUnderCursor(cm, false /** inclusive */,
691
+ true /** forward */, false /** bigWord */,
692
+ true /** noSymbol */);
693
+ var isKeyword = true;
694
+ if (!word) {
695
+ word = expandWordUnderCursor(cm, false /** inclusive */,
696
+ true /** forward */, false /** bigWord */,
697
+ false /** noSymbol */);
698
+ isKeyword = false;
699
+ }
700
+ if (!word) {
701
+ return;
702
+ }
703
+ var query = cm.getLine(word.start.line).substring(word.start.ch,
704
+ word.end.ch + 1);
705
+ if (isKeyword) {
706
+ query = '\\b' + query + '\\b';
707
+ } else {
708
+ query = escapeRegex(query);
709
+ }
710
+ cm.setCursor(word.start);
711
+ handleQuery(query, true /** ignoreCase */, false /** smartCase */);
712
+ break;
713
+ }
714
+ },
715
+ processEx: function(cm, vim, command) {
716
+ function onPromptClose(input) {
717
+ exCommandDispatcher.processCommand(cm, input);
718
+ }
719
+ if (command.type == 'keyToEx') {
720
+ // Handle user defined Ex to Ex mappings
721
+ exCommandDispatcher.processCommand(cm, command.exArgs.input);
722
+ } else {
723
+ showPrompt(cm, onPromptClose, ':');
724
+ }
725
+ },
726
+ evalInput: function(cm, vim) {
727
+ // If the motion comand is set, execute both the operator and motion.
728
+ // Otherwise return.
729
+ var inputState = vim.inputState;
730
+ var motion = inputState.motion;
731
+ var motionArgs = inputState.motionArgs || {};
732
+ var operator = inputState.operator;
733
+ var operatorArgs = inputState.operatorArgs || {};
734
+ var registerName = inputState.registerName;
735
+ var selectionEnd = cm.getCursor('head');
736
+ var selectionStart = cm.getCursor('anchor');
737
+ // The difference between cur and selection cursors are that cur is
738
+ // being operated on and ignores that there is a selection.
739
+ var curStart = copyCursor(selectionEnd);
740
+ var curOriginal = copyCursor(curStart);
741
+ var curEnd;
742
+ var repeat;
743
+ if (motionArgs.repeat !== undefined) {
744
+ // If motionArgs specifies a repeat, that takes precedence over the
745
+ // input state's repeat. Used by Ex mode and can be user defined.
746
+ repeat = inputState.motionArgs.repeat;
747
+ } else {
748
+ repeat = inputState.getRepeat();
749
+ }
750
+ if (repeat > 0 && motionArgs.explicitRepeat) {
751
+ motionArgs.repeatIsExplicit = true;
752
+ } else if (motionArgs.noRepeat ||
753
+ (!motionArgs.explicitRepeat && repeat === 0)) {
754
+ repeat = 1;
755
+ motionArgs.repeatIsExplicit = false;
756
+ }
757
+ if (inputState.selectedCharacter) {
758
+ // If there is a character input, stick it in all of the arg arrays.
759
+ motionArgs.selectedCharacter = operatorArgs.selectedCharacter =
760
+ inputState.selectedCharacter;
761
+ }
762
+ motionArgs.repeat = repeat;
763
+ inputState.reset();
764
+ if (motion) {
765
+ var motionResult = motions[motion](cm, motionArgs, vim);
766
+ vim.lastMotion = motions[motion];
767
+ if (!motionResult) {
768
+ return;
769
+ }
770
+ if (motionResult instanceof Array) {
771
+ curStart = motionResult[0];
772
+ curEnd = motionResult[1];
773
+ } else {
774
+ curEnd = motionResult;
775
+ }
776
+ // TODO: Handle null returns from motion commands better.
777
+ if (!curEnd) {
778
+ curEnd = { ch: curStart.ch, line: curStart.line };
779
+ }
780
+ if (vim.visualMode) {
781
+ // Check if the selection crossed over itself. Will need to shift
782
+ // the start point if that happened.
783
+ if (cursorIsBefore(selectionStart, selectionEnd) &&
784
+ (cursorEqual(selectionStart, curEnd) ||
785
+ cursorIsBefore(curEnd, selectionStart))) {
786
+ // The end of the selection has moved from after the start to
787
+ // before the start. We will shift the start right by 1.
788
+ selectionStart.ch += 1;
789
+ } else if (cursorIsBefore(selectionEnd, selectionStart) &&
790
+ (cursorEqual(selectionStart, curEnd) ||
791
+ cursorIsBefore(selectionStart, curEnd))) {
792
+ // The opposite happened. We will shift the start left by 1.
793
+ selectionStart.ch -= 1;
794
+ }
795
+ selectionEnd = curEnd;
796
+ if (vim.visualLine) {
797
+ if (cursorIsBefore(selectionStart, selectionEnd)) {
798
+ selectionStart.ch = 0;
799
+ selectionEnd.ch = lineLength(cm, selectionEnd.line);
800
+ } else {
801
+ selectionEnd.ch = 0;
802
+ selectionStart.ch = lineLength(cm, selectionStart.line);
803
+ }
804
+ }
805
+ // Need to set the cursor to clear the selection. Otherwise,
806
+ // CodeMirror can't figure out that we changed directions...
807
+ cm.setCursor(selectionStart);
808
+ cm.setSelection(selectionStart, selectionEnd);
809
+ } else if (!operator) {
810
+ curEnd = clipCursorToContent(cm, curEnd);
811
+ cm.setCursor(curEnd.line, curEnd.ch);
812
+ }
813
+ }
814
+
815
+ if (operator) {
816
+ var inverted = false;
817
+ vim.lastMotion = null;
818
+ operatorArgs.repeat = repeat; // Indent in visual mode needs this.
819
+ if (vim.visualMode) {
820
+ curStart = selectionStart;
821
+ curEnd = selectionEnd;
822
+ motionArgs.inclusive = true;
823
+ }
824
+ // Swap start and end if motion was backward.
825
+ if (cursorIsBefore(curEnd, curStart)) {
826
+ var tmp = curStart;
827
+ curStart = curEnd;
828
+ curEnd = tmp;
829
+ inverted = true;
830
+ }
831
+ if (motionArgs.inclusive && !(vim.visualMode && inverted)) {
832
+ // Move the selection end one to the right to include the last
833
+ // character.
834
+ curEnd.ch++;
835
+ }
836
+ var linewise = motionArgs.linewise ||
837
+ (vim.visualMode && vim.visualLine);
838
+ if (linewise) {
839
+ // Expand selection to entire line.
840
+ expandSelectionToLine(cm, curStart, curEnd);
841
+ } else if (motionArgs.forward) {
842
+ // Clip to trailing newlines only if we the motion goes forward.
843
+ clipToLine(cm, curStart, curEnd);
844
+ }
845
+ operatorArgs.registerName = registerName;
846
+ // Keep track of linewise as it affects how paste and change behave.
847
+ operatorArgs.linewise = linewise;
848
+ operators[operator](cm, operatorArgs, vim, curStart,
849
+ curEnd, curOriginal);
850
+ if (vim.visualMode) {
851
+ exitVisualMode(cm, vim);
852
+ }
853
+ if (operatorArgs.enterInsertMode) {
854
+ actions.enterInsertMode(cm);
855
+ }
856
+ }
857
+ }
858
+ };
859
+
860
+ /**
861
+ * typedef {Object{line:number,ch:number}} Cursor An object containing the
862
+ * position of the cursor.
863
+ */
864
+ // All of the functions below return Cursor objects.
865
+ var motions = {
866
+ expandToLine: function(cm, motionArgs) {
867
+ // Expands forward to end of line, and then to next line if repeat is
868
+ // >1. Does not handle backward motion!
869
+ var cur = cm.getCursor();
870
+ return { line: cur.line + motionArgs.repeat - 1, ch: Infinity };
871
+ },
872
+ findNext: function(cm, motionArgs, vim) {
873
+ return findNext(cm, false /** prev */, motionArgs.repeat);
874
+ },
875
+ findPrev: function(cm, motionArgs, vim) {
876
+ return findNext(cm, true /** prev */, motionArgs.repeat);
877
+ },
878
+ goToMark: function(cm, motionArgs, vim) {
879
+ var mark = vim.marks[motionArgs.selectedCharacter];
880
+ if (mark) {
881
+ return mark.find();
882
+ }
883
+ return null;
884
+ },
885
+ moveByCharacters: function(cm, motionArgs) {
886
+ var cur = cm.getCursor();
887
+ var repeat = motionArgs.repeat;
888
+ var ch = motionArgs.forward ? cur.ch + repeat : cur.ch - repeat;
889
+ return { line: cur.line, ch: ch };
890
+ },
891
+ moveByLines: function(cm, motionArgs, vim) {
892
+ var endCh = cm.getCursor().ch;
893
+ // Depending what our last motion was, we may want to do different
894
+ // things. If our last motion was moving vertically, we want to
895
+ // preserve the HPos from our last horizontal move. If our last motion
896
+ // was going to the end of a line, moving vertically we should go to
897
+ // the end of the line, etc.
898
+ switch (vim.lastMotion) {
899
+ case this.moveByLines:
900
+ case this.moveToColumn:
901
+ case this.moveToEol:
902
+ endCh = vim.lastHPos;
903
+ break;
904
+ default:
905
+ vim.lastHPos = endCh;
906
+ }
907
+ var cur = cm.getCursor();
908
+ var repeat = motionArgs.repeat;
909
+ var line = motionArgs.forward ? cur.line + repeat : cur.line - repeat;
910
+ if (line < 0 || line > cm.lineCount() - 1) {
911
+ return null;
912
+ }
913
+ return { line: line, ch: endCh };
914
+ },
915
+ moveByPage: function(cm, motionArgs) {
916
+ // CodeMirror only exposes functions that move the cursor page down, so
917
+ // doing this bad hack to move the cursor and move it back. evalInput
918
+ // will move the cursor to where it should be in the end.
919
+ var curStart = cm.getCursor();
920
+ var repeat = motionArgs.repeat;
921
+ cm.moveV((motionArgs.forward ? repeat : -repeat), 'page');
922
+ var curEnd = cm.getCursor();
923
+ cm.setCursor(curStart);
924
+ return curEnd;
925
+ },
926
+ moveByWords: function(cm, motionArgs) {
927
+ return moveToWord(cm, motionArgs.repeat, !!motionArgs.forward,
928
+ !!motionArgs.wordEnd, !!motionArgs.bigWord);
929
+ },
930
+ moveTillCharacter: function(cm, motionArgs) {
931
+ var repeat = motionArgs.repeat;
932
+ var curEnd = moveToCharacter(cm, repeat, motionArgs.forward,
933
+ motionArgs.selectedCharacter);
934
+ var increment = motionArgs.forward ? -1 : 1;
935
+ curEnd.ch += increment;
936
+ return curEnd;
937
+ },
938
+ moveToCharacter: function(cm, motionArgs) {
939
+ var repeat = motionArgs.repeat;
940
+ return moveToCharacter(cm, repeat, motionArgs.forward,
941
+ motionArgs.selectedCharacter);
942
+ },
943
+ moveToColumn: function(cm, motionArgs, vim) {
944
+ var repeat = motionArgs.repeat;
945
+ // repeat is equivalent to which column we want to move to!
946
+ vim.lastHPos = repeat - 1;
947
+ return moveToColumn(cm, repeat);
948
+ },
949
+ moveToEol: function(cm, motionArgs, vim) {
950
+ var cur = cm.getCursor();
951
+ vim.lastHPos = Infinity;
952
+ return { line: cur.line + motionArgs.repeat - 1, ch: Infinity };
953
+ },
954
+ moveToFirstNonWhiteSpaceCharacter: function(cm) {
955
+ // Go to the start of the line where the text begins, or the end for
956
+ // whitespace-only lines
957
+ var cursor = cm.getCursor();
958
+ var line = cm.getLine(cursor.line);
959
+ return { line: cursor.line,
960
+ ch: findFirstNonWhiteSpaceCharacter(cm.getLine(cursor.line)) };
961
+ },
962
+ moveToMatchedSymbol: function(cm, motionArgs) {
963
+ var cursor = cm.getCursor();
964
+ var symbol = cm.getLine(cursor.line).charAt(cursor.ch);
965
+ if (isMatchableSymbol(symbol)) {
966
+ return findMatchedSymbol(cm, cm.getCursor(), motionArgs.symbol);
967
+ } else {
968
+ return cursor;
969
+ }
970
+ },
971
+ moveToStartOfLine: function(cm) {
972
+ var cursor = cm.getCursor();
973
+ return { line: cursor.line, ch: 0 };
974
+ },
975
+ moveToLineOrEdgeOfDocument: function(cm, motionArgs) {
976
+ var lineNum = motionArgs.forward ? cm.lineCount() - 1 : 0;
977
+ if (motionArgs.repeatIsExplicit) {
978
+ lineNum = motionArgs.repeat - 1;
979
+ }
980
+ return { line: lineNum,
981
+ ch: findFirstNonWhiteSpaceCharacter(cm.getLine(lineNum)) };
982
+ },
983
+ textObjectManipulation: function(cm, motionArgs) {
984
+ var character = motionArgs.selectedCharacter;
985
+ // Inclusive is the difference between a and i
986
+ // TODO: Instead of using the additional text object map to perform text
987
+ // object operations, merge the map into the defaultKeyMap and use
988
+ // motionArgs to define behavior. Define separate entries for 'aw',
989
+ // 'iw', 'a[', 'i[', etc.
990
+ var inclusive = !motionArgs.textObjectInner;
991
+ if (!textObjects[character]) {
992
+ // No text object defined for this, don't move.
993
+ return null;
994
+ }
995
+ var tmp = textObjects[character](cm, inclusive);
996
+ var start = tmp.start;
997
+ var end = tmp.end;
998
+ return [start, end];
999
+ }
1000
+ };
1001
+
1002
+ var operators = {
1003
+ change: function(cm, operatorArgs, vim, curStart, curEnd) {
1004
+ getVimGlobalState().registerController.pushText(
1005
+ operatorArgs.registerName, 'change', cm.getRange(curStart, curEnd),
1006
+ operatorArgs.linewise);
1007
+ if (operatorArgs.linewise) {
1008
+ // Delete starting at the first nonwhitespace character of the first
1009
+ // line, instead of from the start of the first line. This way we get
1010
+ // an indent when we get into insert mode. This behavior isn't quite
1011
+ // correct because we should treat this as a completely new line, and
1012
+ // indent should be whatever codemirror thinks is the right indent.
1013
+ // But cm.indentLine doesn't seem work on empty lines.
1014
+ // TODO: Fix the above.
1015
+ curStart.ch =
1016
+ findFirstNonWhiteSpaceCharacter(cm.getLine(curStart.line));
1017
+ // Insert an additional newline so that insert mode can start there.
1018
+ // curEnd should be on the first character of the new line.
1019
+ cm.replaceRange('\n', curStart, curEnd);
1020
+ } else {
1021
+ cm.replaceRange('', curStart, curEnd);
1022
+ }
1023
+ cm.setCursor(curStart);
1024
+ },
1025
+ // delete is a javascript keyword.
1026
+ 'delete': function(cm, operatorArgs, vim, curStart, curEnd) {
1027
+ getVimGlobalState().registerController.pushText(
1028
+ operatorArgs.registerName, 'delete', cm.getRange(curStart, curEnd),
1029
+ operatorArgs.linewise);
1030
+ cm.replaceRange('', curStart, curEnd);
1031
+ if (operatorArgs.linewise) {
1032
+ cm.setCursor(motions.moveToFirstNonWhiteSpaceCharacter(cm));
1033
+ } else {
1034
+ cm.setCursor(curStart);
1035
+ }
1036
+ },
1037
+ indent: function(cm, operatorArgs, vim, curStart, curEnd) {
1038
+ var startLine = curStart.line;
1039
+ var endLine = curEnd.line;
1040
+ // In visual mode, n> shifts the selection right n times, instead of
1041
+ // shifting n lines right once.
1042
+ var repeat = (vim.visualMode) ? operatorArgs.repeat : 1;
1043
+ if (operatorArgs.linewise) {
1044
+ // The only way to delete a newline is to delete until the start of
1045
+ // the next line, so in linewise mode evalInput will include the next
1046
+ // line. We don't want this in indent, so we go back a line.
1047
+ endLine--;
1048
+ }
1049
+ for (var i = startLine; i <= endLine; i++) {
1050
+ for (var j = 0; j < repeat; j++) {
1051
+ cm.indentLine(i, operatorArgs.indentRight);
1052
+ }
1053
+ }
1054
+ cm.setCursor(curStart);
1055
+ cm.setCursor(motions.moveToFirstNonWhiteSpaceCharacter(cm));
1056
+ },
1057
+ swapcase: function(cm, operatorArgs, vim, curStart, curEnd, curOriginal) {
1058
+ var toSwap = cm.getRange(curStart, curEnd);
1059
+ var swapped = '';
1060
+ for (var i = 0; i < toSwap.length; i++) {
1061
+ var character = toSwap.charAt(i);
1062
+ swapped += isUpperCase(character) ? character.toLowerCase() :
1063
+ character.toUpperCase();
1064
+ }
1065
+ cm.replaceRange(swapped, curStart, curEnd);
1066
+ cm.setCursor(curOriginal);
1067
+ },
1068
+ yank: function(cm, operatorArgs, vim, curStart, curEnd, curOriginal) {
1069
+ getVimGlobalState().registerController.pushText(
1070
+ operatorArgs.registerName, 'yank',
1071
+ cm.getRange(curStart, curEnd), operatorArgs.linewise);
1072
+ cm.setCursor(curOriginal);
1073
+ }
1074
+ };
1075
+
1076
+ var actions = {
1077
+ clearSearchHighlight: clearSearchHighlight,
1078
+ enterInsertMode: function(cm, actionArgs) {
1079
+ var insertAt = (actionArgs) ? actionArgs.insertAt : null;
1080
+ if (insertAt == 'eol') {
1081
+ var cursor = cm.getCursor();
1082
+ cursor = { line: cursor.line, ch: lineLength(cm, cursor.line) };
1083
+ cm.setCursor(cursor);
1084
+ } else if (insertAt == 'charAfter') {
1085
+ cm.setCursor(offsetCursor(cm.getCursor(), 0, 1));
1086
+ }
1087
+ cm.setOption('keyMap', 'vim-insert');
1088
+ },
1089
+ toggleVisualMode: function(cm, actionArgs, vim) {
1090
+ var repeat = actionArgs.repeat;
1091
+ var curStart = cm.getCursor();
1092
+ var curEnd;
1093
+ // TODO: The repeat should actually select number of characters/lines
1094
+ // equal to the repeat times the size of the previous visual
1095
+ // operation.
1096
+ if (!vim.visualMode) {
1097
+ vim.visualMode = true;
1098
+ vim.visualLine = !!actionArgs.linewise;
1099
+ if (vim.visualLine) {
1100
+ curStart.ch = 0;
1101
+ curEnd = clipCursorToContent(cm, {
1102
+ line: curStart.line + repeat - 1,
1103
+ ch: lineLength(cm, curStart.line)
1104
+ }, true /** includeLineBreak */);
1105
+ } else {
1106
+ curEnd = clipCursorToContent(cm, {
1107
+ line: curStart.line,
1108
+ ch: curStart.ch + repeat
1109
+ }, true /** includeLineBreak */);
1110
+ }
1111
+ // Make the initial selection.
1112
+ if (!actionArgs.repeatIsExplicit && !vim.visualLine) {
1113
+ // This is a strange case. Here the implicit repeat is 1. The
1114
+ // following commands lets the cursor hover over the 1 character
1115
+ // selection.
1116
+ cm.setCursor(curEnd);
1117
+ cm.setSelection(curEnd, curStart);
1118
+ } else {
1119
+ cm.setSelection(curStart, curEnd);
1120
+ }
1121
+ } else {
1122
+ if (!vim.visualLine && actionArgs.linewise) {
1123
+ // Shift-V pressed in characterwise visual mode. Switch to linewise
1124
+ // visual mode instead of exiting visual mode.
1125
+ vim.visualLine = true;
1126
+ curStart = cm.getCursor('anchor');
1127
+ curEnd = cm.getCursor('head');
1128
+ curStart.ch = cursorIsBefore(curStart, curEnd) ? 0 :
1129
+ lineLength(cm, curStart.line);
1130
+ curEnd.ch = cursorIsBefore(curStart, curEnd) ?
1131
+ lineLength(cm, curEnd.line) : 0;
1132
+ cm.setSelection(curStart, curEnd);
1133
+ } else {
1134
+ exitVisualMode(cm, vim);
1135
+ }
1136
+ }
1137
+ },
1138
+ joinLines: function(cm, actionArgs, vim) {
1139
+ var curStart, curEnd;
1140
+ if (vim.visualMode) {
1141
+ curStart = cm.getCursor('anchor');
1142
+ curEnd = cm.getCursor('head');
1143
+ curEnd.ch = lineLength(cm, curEnd.line) - 1;
1144
+ } else {
1145
+ // Repeat is the number of lines to join. Minimum 2 lines.
1146
+ var repeat = Math.max(actionArgs.repeat, 2);
1147
+ curStart = cm.getCursor();
1148
+ curEnd = clipCursorToContent(cm, { line: curStart.line + repeat - 1,
1149
+ ch: Infinity });
1150
+ }
1151
+ var finalCh = 0;
1152
+ cm.operation(function() {
1153
+ for (var i = curStart.line; i < curEnd.line; i++) {
1154
+ finalCh = lineLength(cm, curStart.line);
1155
+ var tmp = { line: curStart.line + 1,
1156
+ ch: lineLength(cm, curStart.line + 1) };
1157
+ var text = cm.getRange(curStart, tmp);
1158
+ text = text.replace(/\n\s*/g, ' ');
1159
+ cm.replaceRange(text, curStart, tmp);
1160
+ }
1161
+ var curFinalPos = { line: curStart.line, ch: finalCh };
1162
+ cm.setCursor(curFinalPos);
1163
+ });
1164
+ },
1165
+ newLineAndEnterInsertMode: function(cm, actionArgs) {
1166
+ var insertAt = cm.getCursor();
1167
+ if (insertAt.line === 0 && !actionArgs.after) {
1168
+ // Special case for inserting newline before start of document.
1169
+ cm.replaceRange('\n', { line: 0, ch: 0 });
1170
+ cm.setCursor(0, 0);
1171
+ } else {
1172
+ insertAt.line = (actionArgs.after) ? insertAt.line :
1173
+ insertAt.line - 1;
1174
+ insertAt.ch = lineLength(cm, insertAt.line);
1175
+ cm.setCursor(insertAt);
1176
+ var newlineFn = CodeMirror.commands.newlineAndIndentContinueComment ||
1177
+ CodeMirror.commands.newlineAndIndent;
1178
+ newlineFn(cm);
1179
+ }
1180
+ this.enterInsertMode(cm);
1181
+ },
1182
+ paste: function(cm, actionArgs, vim) {
1183
+ var cur = cm.getCursor();
1184
+ var register = getVimGlobalState().registerController.getRegister(
1185
+ actionArgs.registerName);
1186
+ if (!register.text) {
1187
+ return;
1188
+ }
1189
+ for (var text = '', i = 0; i < actionArgs.repeat; i++) {
1190
+ text += register.text;
1191
+ }
1192
+ var linewise = register.linewise;
1193
+ if (linewise) {
1194
+ if (actionArgs.after) {
1195
+ // Move the newline at the end to the start instead, and paste just
1196
+ // before the newline character of the line we are on right now.
1197
+ text = '\n' + text.slice(0, text.length - 1);
1198
+ cur.ch = lineLength(cm, cur.line);
1199
+ } else {
1200
+ cur.ch = 0;
1201
+ }
1202
+ } else {
1203
+ cur.ch += actionArgs.after ? 1 : 0;
1204
+ }
1205
+ cm.replaceRange(text, cur);
1206
+ // Now fine tune the cursor to where we want it.
1207
+ var curPosFinal;
1208
+ var idx;
1209
+ if (linewise && actionArgs.after) {
1210
+ curPosFinal = { line: cur.line + 1,
1211
+ ch: findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)) };
1212
+ } else if (linewise && !actionArgs.after) {
1213
+ curPosFinal = { line: cur.line,
1214
+ ch: findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)) };
1215
+ } else if (!linewise && actionArgs.after) {
1216
+ idx = cm.indexFromPos(cur);
1217
+ curPosFinal = cm.posFromIndex(idx + text.length - 1);
1218
+ } else {
1219
+ idx = cm.indexFromPos(cur);
1220
+ curPosFinal = cm.posFromIndex(idx + text.length);
1221
+ }
1222
+ cm.setCursor(curPosFinal);
1223
+ },
1224
+ undo: function(cm, actionArgs) {
1225
+ repeatFn(cm, CodeMirror.commands.undo, actionArgs.repeat)();
1226
+ },
1227
+ redo: function(cm, actionArgs) {
1228
+ repeatFn(cm, CodeMirror.commands.redo, actionArgs.repeat)();
1229
+ },
1230
+ setRegister: function(cm, actionArgs, vim) {
1231
+ vim.inputState.registerName = actionArgs.selectedCharacter;
1232
+ },
1233
+ setMark: function(cm, actionArgs, vim) {
1234
+ var markName = actionArgs.selectedCharacter;
1235
+ if (!inArray(markName, validMarks)) {
1236
+ return;
1237
+ }
1238
+ if (vim.marks[markName]) {
1239
+ vim.marks[markName].clear();
1240
+ }
1241
+ vim.marks[markName] = cm.setBookmark(cm.getCursor());
1242
+ },
1243
+ replace: function(cm, actionArgs) {
1244
+ var replaceWith = actionArgs.selectedCharacter;
1245
+ var curStart = cm.getCursor();
1246
+ var line = cm.getLine(curStart.line);
1247
+ var replaceTo = curStart.ch + actionArgs.repeat;
1248
+ if (replaceTo > line.length) {
1249
+ return;
1250
+ }
1251
+ var curEnd = { line: curStart.line, ch: replaceTo };
1252
+ var replaceWithStr = '';
1253
+ for (var i = 0; i < curEnd.ch - curStart.ch; i++) {
1254
+ replaceWithStr += replaceWith;
1255
+ }
1256
+ cm.replaceRange(replaceWithStr, curStart, curEnd);
1257
+ cm.setCursor(offsetCursor(curEnd, 0, -1));
1258
+ }
1259
+ };
1260
+
1261
+ var textObjects = {
1262
+ // TODO: lots of possible exceptions that can be thrown here. Try da(
1263
+ // outside of a () block.
1264
+ // TODO: implement text objects for the reverse like }. Should just be
1265
+ // an additional mapping after moving to the defaultKeyMap.
1266
+ 'w': function(cm, inclusive) {
1267
+ return expandWordUnderCursor(cm, inclusive, true /** forward */,
1268
+ false /** bigWord */);
1269
+ },
1270
+ 'W': function(cm, inclusive) {
1271
+ return expandWordUnderCursor(cm, inclusive,
1272
+ true /** forward */, true /** bigWord */);
1273
+ },
1274
+ '{': function(cm, inclusive) {
1275
+ return selectCompanionObject(cm, '}', inclusive);
1276
+ },
1277
+ '(': function(cm, inclusive) {
1278
+ return selectCompanionObject(cm, ')', inclusive);
1279
+ },
1280
+ '[': function(cm, inclusive) {
1281
+ return selectCompanionObject(cm, ']', inclusive);
1282
+ },
1283
+ '\'': function(cm, inclusive) {
1284
+ return findBeginningAndEnd(cm, "'", inclusive);
1285
+ },
1286
+ '\"': function(cm, inclusive) {
1287
+ return findBeginningAndEnd(cm, '"', inclusive);
1288
+ }
1289
+ };
1290
+
1291
+ /*
1292
+ * Below are miscellaneous utility functions used by vim.js
1293
+ */
1294
+
1295
+ /**
1296
+ * Clips cursor to ensure that:
1297
+ * 0 <= cur.ch < lineLength
1298
+ * AND
1299
+ * 0 <= cur.line < lineCount
1300
+ * If includeLineBreak is true, then allow cur.ch == lineLength.
1301
+ */
1302
+ function clipCursorToContent(cm, cur, includeLineBreak) {
1303
+ var line = Math.min(Math.max(0, cur.line), cm.lineCount() - 1);
1304
+ var maxCh = lineLength(cm, line) - 1;
1305
+ maxCh = (includeLineBreak) ? maxCh + 1 : maxCh;
1306
+ var ch = Math.min(Math.max(0, cur.ch), maxCh);
1307
+ return { line: line, ch: ch };
1308
+ }
1309
+ // Merge arguments in place, for overriding arguments.
1310
+ function mergeArgs(to, from) {
1311
+ for (var prop in from) {
1312
+ if (from.hasOwnProperty(prop)) {
1313
+ to[prop] = from[prop];
1314
+ }
1315
+ }
1316
+ }
1317
+ function copyArgs(args) {
1318
+ var ret = {};
1319
+ for (var prop in args) {
1320
+ if (args.hasOwnProperty(prop)) {
1321
+ ret[prop] = args[prop];
1322
+ }
1323
+ }
1324
+ return ret;
1325
+ }
1326
+ function offsetCursor(cur, offsetLine, offsetCh) {
1327
+ return { line: cur.line + offsetLine, ch: cur.ch + offsetCh };
1328
+ }
1329
+ function arrayEq(a1, a2) {
1330
+ if (a1.length != a2.length) {
1331
+ return false;
1332
+ }
1333
+ for (var i = 0; i < a1.length; i++) {
1334
+ if (a1[i] != a2[i]) {
1335
+ return false;
1336
+ }
1337
+ }
1338
+ return true;
1339
+ }
1340
+ function matchKeysPartial(pressed, mapped) {
1341
+ for (var i = 0; i < pressed.length; i++) {
1342
+ // 'character' means any character. For mark, register commads, etc.
1343
+ if (pressed[i] != mapped[i] && mapped[i] != 'character') {
1344
+ return false;
1345
+ }
1346
+ }
1347
+ return true;
1348
+ }
1349
+ function arrayIsSubsetFromBeginning(small, big) {
1350
+ for (var i = 0; i < small.length; i++) {
1351
+ if (small[i] != big[i]) {
1352
+ return false;
1353
+ }
1354
+ }
1355
+ return true;
1356
+ }
1357
+ function repeatFn(cm, fn, repeat) {
1358
+ return function() {
1359
+ for (var i = 0; i < repeat; i++) {
1360
+ fn(cm);
1361
+ }
1362
+ };
1363
+ }
1364
+ function copyCursor(cur) {
1365
+ return { line: cur.line, ch: cur.ch };
1366
+ }
1367
+ function cursorEqual(cur1, cur2) {
1368
+ return cur1.ch == cur2.ch && cur1.line == cur2.line;
1369
+ }
1370
+ function cursorIsBefore(cur1, cur2) {
1371
+ if (cur1.line < cur2.line) {
1372
+ return true;
1373
+ } else if (cur1.line == cur2.line && cur1.ch < cur2.ch) {
1374
+ return true;
1375
+ }
1376
+ return false;
1377
+ }
1378
+ function lineLength(cm, lineNum) {
1379
+ return cm.getLine(lineNum).length;
1380
+ }
1381
+ function reverse(s){
1382
+ return s.split("").reverse().join("");
1383
+ }
1384
+ function trim(s) {
1385
+ if (s.trim) {
1386
+ return s.trim();
1387
+ } else {
1388
+ return s.replace(/^\s+|\s+$/g, '');
1389
+ }
1390
+ }
1391
+ function escapeRegex(s) {
1392
+ return s.replace(/([.?*+$\[\]\/\\(){}|\-])/g, "\\$1");
1393
+ }
1394
+
1395
+ function exitVisualMode(cm, vim) {
1396
+ vim.visualMode = false;
1397
+ vim.visualLine = false;
1398
+ var selectionStart = cm.getCursor('anchor');
1399
+ var selectionEnd = cm.getCursor('head');
1400
+ if (!cursorEqual(selectionStart, selectionEnd)) {
1401
+ // Clear the selection and set the cursor only if the selection has not
1402
+ // already been cleared. Otherwise we risk moving the cursor somewhere
1403
+ // it's not supposed to be.
1404
+ cm.setCursor(clipCursorToContent(cm, selectionEnd));
1405
+ }
1406
+ }
1407
+
1408
+ // Remove any trailing newlines from the selection. For
1409
+ // example, with the caret at the start of the last word on the line,
1410
+ // 'dw' should word, but not the newline, while 'w' should advance the
1411
+ // caret to the first character of the next line.
1412
+ function clipToLine(cm, curStart, curEnd) {
1413
+ var selection = cm.getRange(curStart, curEnd);
1414
+ var lines = selection.split('\n');
1415
+ if (lines.length > 1 && isWhiteSpaceString(lines.pop())) {
1416
+ curEnd.line--;
1417
+ curEnd.ch = lineLength(cm, curEnd.line);
1418
+ }
1419
+ }
1420
+
1421
+ // Expand the selection to line ends.
1422
+ function expandSelectionToLine(cm, curStart, curEnd) {
1423
+ curStart.ch = 0;
1424
+ curEnd.ch = 0;
1425
+ curEnd.line++;
1426
+ }
1427
+
1428
+ function findFirstNonWhiteSpaceCharacter(text) {
1429
+ if (!text) {
1430
+ return 0;
1431
+ }
1432
+ var firstNonWS = text.search(/\S/);
1433
+ return firstNonWS == -1 ? text.length : firstNonWS;
1434
+ }
1435
+
1436
+ function expandWordUnderCursor(cm, inclusive, forward, bigWord, noSymbol) {
1437
+ var cur = cm.getCursor();
1438
+ var line = cm.getLine(cur.line);
1439
+ var idx = cur.ch;
1440
+
1441
+ // Seek to first word or non-whitespace character, depending on if
1442
+ // noSymbol is true.
1443
+ var textAfterIdx = line.substring(idx);
1444
+ var firstMatchedChar;
1445
+ if (noSymbol) {
1446
+ firstMatchedChar = textAfterIdx.search(/\w/);
1447
+ } else {
1448
+ firstMatchedChar = textAfterIdx.search(/\S/);
1449
+ }
1450
+ if (firstMatchedChar == -1) {
1451
+ return null;
1452
+ }
1453
+ idx += firstMatchedChar;
1454
+ textAfterIdx = line.substring(idx);
1455
+ var textBeforeIdx = line.substring(0, idx);
1456
+
1457
+ var matchRegex;
1458
+ // Greedy matchers for the "word" we are trying to expand.
1459
+ if (bigWord) {
1460
+ matchRegex = /^\S+/;
1461
+ } else {
1462
+ if ((/\w/).test(line.charAt(idx))) {
1463
+ matchRegex = /^\w+/;
1464
+ } else {
1465
+ matchRegex = /^[^\w\s]+/;
1466
+ }
1467
+ }
1468
+
1469
+ var wordAfterRegex = matchRegex.exec(textAfterIdx);
1470
+ var wordStart = idx;
1471
+ var wordEnd = idx + wordAfterRegex[0].length - 1;
1472
+ // TODO: Find a better way to do this. It will be slow on very long lines.
1473
+ var wordBeforeRegex = matchRegex.exec(reverse(textBeforeIdx));
1474
+ if (wordBeforeRegex) {
1475
+ wordStart -= wordBeforeRegex[0].length;
1476
+ }
1477
+
1478
+ if (inclusive) {
1479
+ wordEnd++;
1480
+ }
1481
+
1482
+ return { start: { line: cur.line, ch: wordStart },
1483
+ end: { line: cur.line, ch: wordEnd }};
1484
+ }
1485
+
1486
+ /*
1487
+ * Returns the boundaries of the next word. If the cursor in the middle of
1488
+ * the word, then returns the boundaries of the current word, starting at
1489
+ * the cursor. If the cursor is at the start/end of a word, and we are going
1490
+ * forward/backward, respectively, find the boundaries of the next word.
1491
+ *
1492
+ * @param {CodeMirror} cm CodeMirror object.
1493
+ * @param {Cursor} cur The cursor position.
1494
+ * @param {boolean} forward True to search forward. False to search
1495
+ * backward.
1496
+ * @param {boolean} bigWord True if punctuation count as part of the word.
1497
+ * False if only [a-zA-Z0-9] characters count as part of the word.
1498
+ * @return {Object{from:number, to:number, line: number}} The boundaries of
1499
+ * the word, or null if there are no more words.
1500
+ */
1501
+ // TODO: Treat empty lines (with no whitespace) as words.
1502
+ function findWord(cm, cur, forward, bigWord) {
1503
+ var lineNum = cur.line;
1504
+ var pos = cur.ch;
1505
+ var line = cm.getLine(lineNum);
1506
+ var dir = forward ? 1 : -1;
1507
+ var regexps = bigWord ? bigWordRegexp : wordRegexp;
1508
+
1509
+ while (true) {
1510
+ var stop = (dir > 0) ? line.length : -1;
1511
+ var wordStart = stop, wordEnd = stop;
1512
+ // Find bounds of next word.
1513
+ while (pos != stop) {
1514
+ var foundWord = false;
1515
+ for (var i = 0; i < regexps.length && !foundWord; ++i) {
1516
+ if (regexps[i].test(line.charAt(pos))) {
1517
+ wordStart = pos;
1518
+ // Advance to end of word.
1519
+ while (pos != stop && regexps[i].test(line.charAt(pos))) {
1520
+ pos += dir;
1521
+ }
1522
+ wordEnd = pos;
1523
+ foundWord = wordStart != wordEnd;
1524
+ if (wordStart == cur.ch && lineNum == cur.line &&
1525
+ wordEnd == wordStart + dir) {
1526
+ // We started at the end of a word. Find the next one.
1527
+ continue;
1528
+ } else {
1529
+ return {
1530
+ from: Math.min(wordStart, wordEnd + 1),
1531
+ to: Math.max(wordStart, wordEnd),
1532
+ line: lineNum };
1533
+ }
1534
+ }
1535
+ }
1536
+ if (!foundWord) {
1537
+ pos += dir;
1538
+ }
1539
+ }
1540
+ // Advance to next/prev line.
1541
+ lineNum += dir;
1542
+ if (!isLine(cm, lineNum)) {
1543
+ return null;
1544
+ }
1545
+ line = cm.getLine(lineNum);
1546
+ pos = (dir > 0) ? 0 : line.length;
1547
+ }
1548
+ // Should never get here.
1549
+ throw 'The impossible happened.';
1550
+ }
1551
+
1552
+ /**
1553
+ * @param {CodeMirror} cm CodeMirror object.
1554
+ * @param {int} repeat Number of words to move past.
1555
+ * @param {boolean} forward True to search forward. False to search
1556
+ * backward.
1557
+ * @param {boolean} wordEnd True to move to end of word. False to move to
1558
+ * beginning of word.
1559
+ * @param {boolean} bigWord True if punctuation count as part of the word.
1560
+ * False if only alphabet characters count as part of the word.
1561
+ * @return {Cursor} The position the cursor should move to.
1562
+ */
1563
+ function moveToWord(cm, repeat, forward, wordEnd, bigWord) {
1564
+ var cur = cm.getCursor();
1565
+ for (var i = 0; i < repeat; i++) {
1566
+ var startCh = cur.ch, startLine = cur.line, word;
1567
+ var movedToNextWord = false;
1568
+ while (!movedToNextWord) {
1569
+ // Search and advance.
1570
+ word = findWord(cm, cur, forward, bigWord);
1571
+ movedToNextWord = true;
1572
+ if (word) {
1573
+ // Move to the word we just found. If by moving to the word we end
1574
+ // up in the same spot, then move an extra character and search
1575
+ // again.
1576
+ cur.line = word.line;
1577
+ if (forward && wordEnd) {
1578
+ // 'e'
1579
+ cur.ch = word.to - 1;
1580
+ } else if (forward && !wordEnd) {
1581
+ // 'w'
1582
+ if (inRangeInclusive(cur.ch, word.from, word.to) &&
1583
+ word.line == startLine) {
1584
+ // Still on the same word. Go to the next one.
1585
+ movedToNextWord = false;
1586
+ cur.ch = word.to - 1;
1587
+ } else {
1588
+ cur.ch = word.from;
1589
+ }
1590
+ } else if (!forward && wordEnd) {
1591
+ // 'ge'
1592
+ if (inRangeInclusive(cur.ch, word.from, word.to) &&
1593
+ word.line == startLine) {
1594
+ // still on the same word. Go to the next one.
1595
+ movedToNextWord = false;
1596
+ cur.ch = word.from;
1597
+ } else {
1598
+ cur.ch = word.to;
1599
+ }
1600
+ } else if (!forward && !wordEnd) {
1601
+ // 'b'
1602
+ cur.ch = word.from;
1603
+ }
1604
+ } else {
1605
+ // No more words to be found. Move to the end.
1606
+ if (forward) {
1607
+ return { line: cur.line, ch: lineLength(cm, cur.line) };
1608
+ } else {
1609
+ return { line: cur.line, ch: 0 };
1610
+ }
1611
+ }
1612
+ }
1613
+ }
1614
+ return cur;
1615
+ }
1616
+
1617
+ function moveToCharacter(cm, repeat, forward, character) {
1618
+ var cur = cm.getCursor();
1619
+ var start = cur.ch;
1620
+ var idx;
1621
+ for (var i = 0; i < repeat; i ++) {
1622
+ var line = cm.getLine(cur.line);
1623
+ idx = charIdxInLine(start, line, character, forward, true);
1624
+ if (idx == -1) {
1625
+ return cur;
1626
+ }
1627
+ start = idx;
1628
+ }
1629
+ return { line: cm.getCursor().line, ch: idx };
1630
+ }
1631
+
1632
+ function moveToColumn(cm, repeat) {
1633
+ // repeat is always >= 1, so repeat - 1 always corresponds
1634
+ // to the column we want to go to.
1635
+ var line = cm.getCursor().line;
1636
+ return clipCursorToContent(cm, { line: line, ch: repeat - 1 });
1637
+ }
1638
+
1639
+ function charIdxInLine(start, line, character, forward, includeChar) {
1640
+ // Search for char in line.
1641
+ // motion_options: {forward, includeChar}
1642
+ // If includeChar = true, include it too.
1643
+ // If forward = true, search forward, else search backwards.
1644
+ // If char is not found on this line, do nothing
1645
+ var idx;
1646
+ if (forward) {
1647
+ idx = line.indexOf(character, start + 1);
1648
+ if (idx != -1 && !includeChar) {
1649
+ idx -= 1;
1650
+ }
1651
+ } else {
1652
+ idx = line.lastIndexOf(character, start - 1);
1653
+ if (idx != -1 && !includeChar) {
1654
+ idx += 1;
1655
+ }
1656
+ }
1657
+ return idx;
1658
+ }
1659
+
1660
+ function findMatchedSymbol(cm, cur, symb) {
1661
+ var line = cur.line;
1662
+ symb = symb ? symb : cm.getLine(line).charAt(cur.ch);
1663
+
1664
+ // Are we at the opening or closing char
1665
+ var forwards = inArray(symb, ['(', '[', '{']);
1666
+
1667
+ var reverseSymb = ({
1668
+ '(': ')', ')': '(',
1669
+ '[': ']', ']': '[',
1670
+ '{': '}', '}': '{'})[symb];
1671
+
1672
+ // Couldn't find a matching symbol, abort
1673
+ if (!reverseSymb) {
1674
+ return cur;
1675
+ }
1676
+
1677
+ // set our increment to move forward (+1) or backwards (-1)
1678
+ // depending on which bracket we're matching
1679
+ var increment = ({'(': 1, '{': 1, '[': 1})[symb] || -1;
1680
+ var depth = 1, nextCh = symb, index = cur.ch, lineText = cm.getLine(line);
1681
+ // Simple search for closing paren--just count openings and closings till
1682
+ // we find our match
1683
+ // TODO: use info from CodeMirror to ignore closing brackets in comments
1684
+ // and quotes, etc.
1685
+ while (nextCh && depth > 0) {
1686
+ index += increment;
1687
+ nextCh = lineText.charAt(index);
1688
+ if (!nextCh) {
1689
+ line += increment;
1690
+ index = 0;
1691
+ lineText = cm.getLine(line) || '';
1692
+ nextCh = lineText.charAt(index);
1693
+ }
1694
+ if (nextCh === symb) {
1695
+ depth++;
1696
+ } else if (nextCh === reverseSymb) {
1697
+ depth--;
1698
+ }
1699
+ }
1700
+
1701
+ if (nextCh) {
1702
+ return { line: line, ch: index };
1703
+ }
1704
+ return cur;
1705
+ }
1706
+
1707
+ function selectCompanionObject(cm, revSymb, inclusive) {
1708
+ var cur = cm.getCursor();
1709
+
1710
+ var end = findMatchedSymbol(cm, cur, revSymb);
1711
+ var start = findMatchedSymbol(cm, end);
1712
+ start.ch += inclusive ? 1 : 0;
1713
+ end.ch += inclusive ? 0 : 1;
1714
+
1715
+ return { start: start, end: end };
1716
+ }
1717
+
1718
+ function regexLastIndexOf(string, pattern, startIndex) {
1719
+ for (var i = !startIndex ? string.length : startIndex;
1720
+ i >= 0; --i) {
1721
+ if (pattern.test(string.charAt(i))) {
1722
+ return i;
1723
+ }
1724
+ }
1725
+ return -1;
1726
+ }
1727
+
1728
+ // Takes in a symbol and a cursor and tries to simulate text objects that
1729
+ // have identical opening and closing symbols
1730
+ // TODO support across multiple lines
1731
+ function findBeginningAndEnd(cm, symb, inclusive) {
1732
+ var cur = cm.getCursor();
1733
+ var line = cm.getLine(cur.line);
1734
+ var chars = line.split('');
1735
+ var start, end, i, len;
1736
+ var firstIndex = chars.indexOf(symb);
1737
+
1738
+ // the decision tree is to always look backwards for the beginning first,
1739
+ // but if the cursor is in front of the first instance of the symb,
1740
+ // then move the cursor forward
1741
+ if (cur.ch < firstIndex) {
1742
+ cur.ch = firstIndex;
1743
+ // Why is this line even here???
1744
+ // cm.setCursor(cur.line, firstIndex+1);
1745
+ }
1746
+ // otherwise if the cursor is currently on the closing symbol
1747
+ else if (firstIndex < cur.ch && chars[cur.ch] == symb) {
1748
+ end = cur.ch; // assign end to the current cursor
1749
+ --cur.ch; // make sure to look backwards
1750
+ }
1751
+
1752
+ // if we're currently on the symbol, we've got a start
1753
+ if (chars[cur.ch] == symb && !end) {
1754
+ start = cur.ch + 1; // assign start to ahead of the cursor
1755
+ } else {
1756
+ // go backwards to find the start
1757
+ for (i = cur.ch; i > -1 && !start; i--) {
1758
+ if (chars[i] == symb) {
1759
+ start = i + 1;
1760
+ }
1761
+ }
1762
+ }
1763
+
1764
+ // look forwards for the end symbol
1765
+ if (start && !end) {
1766
+ for (i = start, len = chars.length; i < len && !end; i++) {
1767
+ if (chars[i] == symb) {
1768
+ end = i;
1769
+ }
1770
+ }
1771
+ }
1772
+
1773
+ // nothing found
1774
+ if (!start || !end) {
1775
+ return { start: cur, end: cur };
1776
+ }
1777
+
1778
+ // include the symbols
1779
+ if (inclusive) {
1780
+ --start; ++end;
1781
+ }
1782
+
1783
+ return {
1784
+ start: { line: cur.line, ch: start },
1785
+ end: { line: cur.line, ch: end }
1786
+ };
1787
+ }
1788
+
1789
+ // Search functions
1790
+ function SearchState() {
1791
+ // Highlighted text that match the query.
1792
+ this.marked = null;
1793
+ }
1794
+ SearchState.prototype = {
1795
+ getQuery: function() {
1796
+ return getVimGlobalState().query;
1797
+ },
1798
+ setQuery: function(query) {
1799
+ getVimGlobalState().query = query;
1800
+ },
1801
+ getMarked: function() {
1802
+ return this.marked;
1803
+ },
1804
+ setMarked: function(marked) {
1805
+ this.marked = marked;
1806
+ },
1807
+ isReversed: function() {
1808
+ return getVimGlobalState().isReversed;
1809
+ },
1810
+ setReversed: function(reversed) {
1811
+ getVimGlobalState().isReversed = reversed;
1812
+ }
1813
+ };
1814
+ function getSearchState(cm) {
1815
+ var vim = getVimState(cm);
1816
+ return vim.searchState_ || (vim.searchState_ = new SearchState());
1817
+ }
1818
+ function dialog(cm, text, shortText, callback) {
1819
+ if (cm.openDialog) {
1820
+ cm.openDialog(text, callback, {bottom: true});
1821
+ }
1822
+ else {
1823
+ callback(prompt(shortText, ""));
1824
+ }
1825
+ }
1826
+ function findUnescapedSlashes(str) {
1827
+ var escapeNextChar = false;
1828
+ var slashes = [];
1829
+ for (var i = 0; i < str.length; i++) {
1830
+ var c = str.charAt(i);
1831
+ if (!escapeNextChar && c == '/') {
1832
+ slashes.push(i);
1833
+ }
1834
+ escapeNextChar = (c == '\\');
1835
+ }
1836
+ return slashes;
1837
+ }
1838
+ /**
1839
+ * Extract the regular expression from the query and return a Regexp object.
1840
+ * Returns null if the query is blank.
1841
+ * If ignoreCase is passed in, the Regexp object will have the 'i' flag set.
1842
+ * If smartCase is passed in, and the query contains upper case letters,
1843
+ * then ignoreCase is overridden, and the 'i' flag will not be set.
1844
+ * If the query contains the /i in the flag part of the regular expression,
1845
+ * then both ignoreCase and smartCase are ignored, and 'i' will be passed
1846
+ * through to the Regex object.
1847
+ */
1848
+ function parseQuery(cm, query, ignoreCase, smartCase) {
1849
+ // First try to extract regex + flags from the input. If no flags found,
1850
+ // extract just the regex. IE does not accept flags directly defined in
1851
+ // the regex string in the form /regex/flags
1852
+ var slashes = findUnescapedSlashes(query);
1853
+ var regexPart;
1854
+ var forceIgnoreCase;
1855
+ if (!slashes.length) {
1856
+ // Query looks like 'regexp'
1857
+ regexPart = query;
1858
+ } else {
1859
+ // Query looks like 'regexp/...'
1860
+ regexPart = query.substring(0, slashes[0]);
1861
+ var flagsPart = query.substring(slashes[0]);
1862
+ forceIgnoreCase = (flagsPart.indexOf('i') != -1);
1863
+ }
1864
+ if (!regexPart) {
1865
+ return null;
1866
+ }
1867
+ if (smartCase) {
1868
+ ignoreCase = (/^[^A-Z]*$/).test(regexPart);
1869
+ }
1870
+ try {
1871
+ var regexp = new RegExp(regexPart,
1872
+ (ignoreCase || forceIgnoreCase) ? 'i' : undefined);
1873
+ return regexp;
1874
+ } catch (e) {
1875
+ showConfirm(cm, 'Invalid regex: ' + regexPart);
1876
+ }
1877
+ }
1878
+ function showConfirm(cm, text) {
1879
+ if (cm.openConfirm) {
1880
+ cm.openConfirm('<span style="color: red">' + text +
1881
+ '</span> <button type="button">OK</button>', function() {},
1882
+ {bottom: true});
1883
+ } else {
1884
+ alert(text);
1885
+ }
1886
+ }
1887
+ function makePrompt(prefix, desc) {
1888
+ var raw = '';
1889
+ if (prefix) {
1890
+ raw += '<span style="font-family: monospace">' + prefix + '</span>';
1891
+ }
1892
+ raw += '<input type="text"/> ' +
1893
+ '<span style="color: #888">';
1894
+ if (desc) {
1895
+ raw += '<span style="color: #888">';
1896
+ raw += desc;
1897
+ raw += '</span>';
1898
+ }
1899
+ return raw;
1900
+ }
1901
+ var searchPromptDesc = '(Javascript regexp)';
1902
+ function showPrompt(cm, onPromptClose, prefix, desc) {
1903
+ var shortText = (prefix || '') + ' ' + (desc || '');
1904
+ dialog(cm, makePrompt(prefix, desc), shortText, onPromptClose);
1905
+ }
1906
+ function regexEqual(r1, r2) {
1907
+ if (r1 instanceof RegExp && r2 instanceof RegExp) {
1908
+ var props = ["global", "multiline", "ignoreCase", "source"];
1909
+ for (var i = 0; i < props.length; i++) {
1910
+ var prop = props[i];
1911
+ if (r1[prop] !== r2[prop]) {
1912
+ return(false);
1913
+ }
1914
+ }
1915
+ return(true);
1916
+ }
1917
+ return(false);
1918
+ }
1919
+ function updateSearchQuery(cm, rawQuery, ignoreCase, smartCase) {
1920
+ cm.operation(function() {
1921
+ var state = getSearchState(cm);
1922
+ if (!rawQuery) {
1923
+ return;
1924
+ }
1925
+ var query = parseQuery(cm, rawQuery, !!ignoreCase, !!smartCase);
1926
+ if (!query) {
1927
+ return;
1928
+ }
1929
+ if (regexEqual(query, state.getQuery())) {
1930
+ return;
1931
+ }
1932
+ clearSearchHighlight(cm);
1933
+ highlightSearchMatches(cm, query);
1934
+ state.setQuery(query);
1935
+ });
1936
+ }
1937
+ function highlightSearchMatches(cm, query) {
1938
+ // TODO: Highlight only text inside the viewport. Highlighting everything
1939
+ // is inefficient and expensive.
1940
+ if (cm.lineCount() < 2000) { // This is too expensive on big documents.
1941
+ var marked = [];
1942
+ for (var cursor = cm.getSearchCursor(query);
1943
+ cursor.findNext();) {
1944
+ marked.push(cm.markText(cursor.from(), cursor.to(),
1945
+ { className: 'CodeMirror-searching' }));
1946
+ }
1947
+ getSearchState(cm).setMarked(marked);
1948
+ }
1949
+ }
1950
+ function findNext(cm, prev, repeat) {
1951
+ return cm.operation(function() {
1952
+ var state = getSearchState(cm);
1953
+ var query = state.getQuery();
1954
+ if (!query) {
1955
+ return;
1956
+ }
1957
+ if (!state.getMarked()) {
1958
+ highlightSearchMatches(cm, query);
1959
+ }
1960
+ var pos = cm.getCursor();
1961
+ // If search is initiated with ? instead of /, negate direction.
1962
+ prev = (state.isReversed()) ? !prev : prev;
1963
+ if (!prev) {
1964
+ pos.ch += 1;
1965
+ }
1966
+ var cursor = cm.getSearchCursor(query, pos);
1967
+ for (var i = 0; i < repeat; i++) {
1968
+ if (!cursor.find(prev)) {
1969
+ // SearchCursor may have returned null because it hit EOF, wrap
1970
+ // around and try again.
1971
+ cursor = cm.getSearchCursor(query,
1972
+ (prev) ? { line: cm.lineCount() - 1} : {line: 0, ch: 0} );
1973
+ if (!cursor.find(prev)) {
1974
+ return;
1975
+ }
1976
+ }
1977
+ }
1978
+ return cursor.from();
1979
+ });}
1980
+ function clearSearchHighlight(cm) {
1981
+ cm.operation(function() {
1982
+ var state = getSearchState(cm);
1983
+ if (!state.getQuery()) {
1984
+ return;
1985
+ }
1986
+ var marked = state.getMarked();
1987
+ if (!marked) {
1988
+ return;
1989
+ }
1990
+ for (var i = 0; i < marked.length; ++i) {
1991
+ marked[i].clear();
1992
+ }
1993
+ state.setMarked(null);
1994
+ });}
1995
+
1996
+ // Ex command handling
1997
+ // Care must be taken when adding to the default Ex command map. For any
1998
+ // pair of commands that have a shared prefix, at least one of their
1999
+ // shortNames must not match the prefix of the other command.
2000
+ var defaultExCommandMap = [
2001
+ { name: 'map', type: 'builtIn' },
2002
+ { name: 'write', shortName: 'w', type: 'builtIn' },
2003
+ { name: 'undo', shortName: 'u', type: 'builtIn' },
2004
+ { name: 'redo', shortName: 'red', type: 'builtIn' }
2005
+ ];
2006
+ var ExCommandDispatcher = function() {
2007
+ this.buildCommandMap_();
2008
+ };
2009
+ ExCommandDispatcher.prototype = {
2010
+ processCommand: function(cm, input) {
2011
+ var params = this.parseInput_(input);
2012
+ var commandName;
2013
+ if (!params.commandName) {
2014
+ // If only a line range is defined, move to the line.
2015
+ if (params.line !== undefined) {
2016
+ commandName = 'move';
2017
+ }
2018
+ } else {
2019
+ var command = this.matchCommand_(params.commandName);
2020
+ if (command) {
2021
+ commandName = command.name;
2022
+ if (command.type == 'exToKey') {
2023
+ // Handle Ex to Key mapping.
2024
+ for (var i = 0; i < command.toKeys.length; i++) {
2025
+ vim.handleKey(cm, command.toKeys[i]);
2026
+ }
2027
+ return;
2028
+ } else if (command.type == 'exToEx') {
2029
+ // Handle Ex to Ex mapping.
2030
+ this.processCommand(cm, command.toInput);
2031
+ return;
2032
+ }
2033
+ }
2034
+ }
2035
+ if (!commandName) {
2036
+ showConfirm(cm, 'Not an editor command ":' + input + '"');
2037
+ return;
2038
+ }
2039
+ exCommands[commandName](cm, params);
2040
+ },
2041
+ parseInput_: function(input) {
2042
+ var result = {};
2043
+ result.input = input;
2044
+ var idx = 0;
2045
+ // Trim preceding ':'.
2046
+ var colons = (/^:+/).exec(input);
2047
+ if (colons) {
2048
+ idx += colons[0].length;
2049
+ }
2050
+
2051
+ // Parse range.
2052
+ var numberMatch = (/^(\d+)/).exec(input.substring(idx));
2053
+ if (numberMatch) {
2054
+ result.line = parseInt(numberMatch[1], 10);
2055
+ idx += numberMatch[0].length;
2056
+ }
2057
+
2058
+ // Parse command name.
2059
+ var commandMatch = (/^(\w+)/).exec(input.substring(idx));
2060
+ if (commandMatch) {
2061
+ result.commandName = commandMatch[1];
2062
+ idx += commandMatch[1].length;
2063
+ }
2064
+
2065
+ // Parse command-line arguments
2066
+ var args = trim(input.substring(idx)).split(/\s+/);
2067
+ if (args.length && args[0]) {
2068
+ result.commandArgs = args;
2069
+ }
2070
+
2071
+ return result;
2072
+ },
2073
+ matchCommand_: function(commandName) {
2074
+ // Return the command in the command map that matches the shortest
2075
+ // prefix of the passed in command name. The match is guaranteed to be
2076
+ // unambiguous if the defaultExCommandMap's shortNames are set up
2077
+ // correctly. (see @code{defaultExCommandMap}).
2078
+ for (var i = commandName.length; i > 0; i--) {
2079
+ var prefix = commandName.substring(0, i);
2080
+ if (this.commandMap_[prefix]) {
2081
+ var command = this.commandMap_[prefix];
2082
+ if (command.name.indexOf(commandName) === 0) {
2083
+ return command;
2084
+ }
2085
+ }
2086
+ }
2087
+ return null;
2088
+ },
2089
+ buildCommandMap_: function() {
2090
+ this.commandMap_ = {};
2091
+ for (var i = 0; i < defaultExCommandMap.length; i++) {
2092
+ var command = defaultExCommandMap[i];
2093
+ var key = command.shortName || command.name;
2094
+ this.commandMap_[key] = command;
2095
+ }
2096
+ },
2097
+ map: function(lhs, rhs) {
2098
+ if (lhs.charAt(0) == ':') {
2099
+ var commandName = lhs.substring(1);
2100
+ if (rhs.charAt(0) == ':') {
2101
+ // Ex to Ex mapping
2102
+ this.commandMap_[commandName] = {
2103
+ name: commandName,
2104
+ type: 'exToEx',
2105
+ toInput: rhs.substring(1)
2106
+ };
2107
+ } else {
2108
+ // Ex to key mapping
2109
+ this.commandMap_[commandName] = {
2110
+ name: commandName,
2111
+ type: 'exToKey',
2112
+ toKeys: parseKeyString(rhs)
2113
+ };
2114
+ }
2115
+ } else {
2116
+ if (rhs.charAt(0) == ':') {
2117
+ // Key to Ex mapping.
2118
+ defaultKeymap.unshift({
2119
+ keys: parseKeyString(lhs),
2120
+ type: 'keyToEx',
2121
+ exArgs: { input: rhs.substring(1) }});
2122
+ } else {
2123
+ // Key to key mapping
2124
+ defaultKeymap.unshift({
2125
+ keys: parseKeyString(lhs),
2126
+ type: 'keyToKey',
2127
+ toKeys: parseKeyString(rhs)
2128
+ });
2129
+ }
2130
+ }
2131
+ }
2132
+ };
2133
+
2134
+ // Converts a key string sequence of the form a<C-w>bd<Left> into Vim's
2135
+ // keymap representation.
2136
+ function parseKeyString(str) {
2137
+ var idx = 0;
2138
+ var keys = [];
2139
+ while (idx < str.length) {
2140
+ if (str.charAt(idx) != '<') {
2141
+ keys.push(str.charAt(idx));
2142
+ idx++;
2143
+ continue;
2144
+ }
2145
+ // Vim key notation here means desktop Vim key-notation.
2146
+ // See :help key-notation in desktop Vim.
2147
+ var vimKeyNotationStart = ++idx;
2148
+ while (str.charAt(idx++) != '>') {}
2149
+ var vimKeyNotation = str.substring(vimKeyNotationStart, idx - 1);
2150
+ var match = (/^C-(.+)$/).exec(vimKeyNotation);
2151
+ if (match) {
2152
+ var key;
2153
+ switch (match[1]) {
2154
+ case 'BS':
2155
+ key = 'Backspace';
2156
+ break;
2157
+ case 'CR':
2158
+ key = 'Enter';
2159
+ break;
2160
+ case 'Del':
2161
+ key = 'Delete';
2162
+ break;
2163
+ default:
2164
+ key = match[1];
2165
+ break;
2166
+ }
2167
+ keys.push('Ctrl-' + key);
2168
+ }
2169
+ }
2170
+ return keys;
2171
+ }
2172
+
2173
+ var exCommands = {
2174
+ map: function(cm, params) {
2175
+ var mapArgs = params.commandArgs;
2176
+ if (!mapArgs || mapArgs.length < 2) {
2177
+ if (cm) {
2178
+ showConfirm(cm, 'Invalid mapping: ' + params.input);
2179
+ }
2180
+ return;
2181
+ }
2182
+ exCommandDispatcher.map(mapArgs[0], mapArgs[1], cm);
2183
+ },
2184
+ move: function(cm, params) {
2185
+ commandDispatcher.processMotion(cm, getVimState(cm), {
2186
+ motion: 'moveToLineOrEdgeOfDocument',
2187
+ motionArgs: { forward: false, explicitRepeat: true,
2188
+ linewise: true, repeat: params.line }});
2189
+ },
2190
+ redo: CodeMirror.commands.redo,
2191
+ undo: CodeMirror.commands.undo,
2192
+ write: function(cm) {
2193
+ if (CodeMirror.commands.save) {
2194
+ // If a save command is defined, call it.
2195
+ CodeMirror.commands.save(cm);
2196
+ } else {
2197
+ // Saves to text area if no save command is defined.
2198
+ cm.save();
2199
+ }
2200
+ }
2201
+ };
2202
+
2203
+ var exCommandDispatcher = new ExCommandDispatcher();
2204
+
2205
+ // Register Vim with CodeMirror
2206
+ function buildVimKeyMap() {
2207
+ /**
2208
+ * Handle the raw key event from CodeMirror. Translate the
2209
+ * Shift + key modifier to the resulting letter, while preserving other
2210
+ * modifers.
2211
+ */
2212
+ // TODO: Figure out a way to catch capslock.
2213
+ function handleKeyEvent_(cm, key, modifier) {
2214
+ if (isUpperCase(key)) {
2215
+ // Convert to lower case if shift is not the modifier since the key
2216
+ // we get from CodeMirror is always upper case.
2217
+ if (modifier == 'Shift') {
2218
+ modifier = null;
2219
+ }
2220
+ else {
2221
+ key = key.toLowerCase();
2222
+ }
2223
+ }
2224
+ if (modifier) {
2225
+ // Vim will parse modifier+key combination as a single key.
2226
+ key = modifier + '-' + key;
2227
+ }
2228
+ vim.handleKey(cm, key);
2229
+ }
2230
+
2231
+ // Closure to bind CodeMirror, key, modifier.
2232
+ function keyMapper(key, modifier) {
2233
+ return function(cm) {
2234
+ handleKeyEvent_(cm, key, modifier);
2235
+ };
2236
+ }
2237
+
2238
+ var modifiers = ['Shift', 'Ctrl'];
2239
+ var keyMap = {
2240
+ 'nofallthrough': true,
2241
+ 'style': 'fat-cursor'
2242
+ };
2243
+ function bindKeys(keys, modifier) {
2244
+ for (var i = 0; i < keys.length; i++) {
2245
+ var key = keys[i];
2246
+ if (!modifier && inArray(key, specialSymbols)) {
2247
+ // Wrap special symbols with '' because that's how CodeMirror binds
2248
+ // them.
2249
+ key = "'" + key + "'";
2250
+ }
2251
+ if (modifier) {
2252
+ keyMap[modifier + '-' + key] = keyMapper(keys[i], modifier);
2253
+ } else {
2254
+ keyMap[key] = keyMapper(keys[i]);
2255
+ }
2256
+ }
2257
+ }
2258
+ bindKeys(upperCaseAlphabet);
2259
+ bindKeys(upperCaseAlphabet, 'Shift');
2260
+ bindKeys(upperCaseAlphabet, 'Ctrl');
2261
+ bindKeys(specialSymbols);
2262
+ bindKeys(specialSymbols, 'Ctrl');
2263
+ bindKeys(numbers);
2264
+ bindKeys(numbers, 'Ctrl');
2265
+ bindKeys(specialKeys);
2266
+ bindKeys(specialKeys, 'Ctrl');
2267
+ return keyMap;
2268
+ }
2269
+ CodeMirror.keyMap.vim = buildVimKeyMap();
2270
+
2271
+ function exitInsertMode(cm) {
2272
+ cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1, true);
2273
+ cm.setOption('keyMap', 'vim');
2274
+ }
2275
+
2276
+ CodeMirror.keyMap['vim-insert'] = {
2277
+ // TODO: override navigation keys so that Esc will cancel automatic
2278
+ // indentation from o, O, i_<CR>
2279
+ 'Esc': exitInsertMode,
2280
+ 'Ctrl-[': exitInsertMode,
2281
+ 'Ctrl-C': exitInsertMode,
2282
+ 'Ctrl-N': 'autocomplete',
2283
+ 'Ctrl-P': 'autocomplete',
2284
+ 'Enter': function(cm) {
2285
+ var fn = CodeMirror.commands.newlineAndIndentContinueComment ||
2286
+ CodeMirror.commands.newlineAndIndent;
2287
+ fn(cm);
2288
+ },
2289
+ fallthrough: ['default']
2290
+ };
2291
+
2292
+ return vimApi;
2293
+ };
2294
+ // Initialize Vim and make it available as an API.
2295
+ var vim = Vim();
2296
+ CodeMirror.Vim = vim;
2297
+ }
2298
+ )();