lines-engine 0.6.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (572) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +10 -3
  6. data/Gemfile +1 -0
  7. data/Gemfile.lock +10 -6
  8. data/app/assets/images/favicon.ico +0 -0
  9. data/app/assets/images/gplus.svg +17 -0
  10. data/app/assets/javascripts/lines/admin/admin.js +299 -0
  11. data/app/assets/javascripts/lines/{autosize.min.js → admin/autosize.min.js} +0 -0
  12. data/app/assets/javascripts/lines/admin/navbar.js +51 -0
  13. data/app/assets/javascripts/lines/{pictures.js.coffee → admin/pictures.js.coffee} +2 -1
  14. data/app/assets/javascripts/lines/application.js +3 -0
  15. data/app/assets/javascripts/lines/articles.js.coffee +1 -0
  16. data/app/assets/javascripts/lines/viewer.js.coffee +3 -0
  17. data/app/assets/stylesheets/lines/admin/admin.scss +609 -0
  18. data/app/assets/stylesheets/lines/admin/variables_and_mixins.scss +36 -0
  19. data/app/assets/stylesheets/lines/application.scss +2 -13
  20. data/app/assets/stylesheets/lines/article.scss +165 -69
  21. data/app/assets/stylesheets/lines/fonts.scss +2 -2
  22. data/app/assets/stylesheets/lines/footer.scss +10 -56
  23. data/app/assets/stylesheets/lines/general.scss +18 -13
  24. data/app/assets/stylesheets/lines/media_queries.scss +5 -1
  25. data/app/assets/stylesheets/lines/messages.scss +28 -0
  26. data/app/assets/stylesheets/lines/navbar.scss +199 -122
  27. data/app/assets/stylesheets/lines/pagination.scss +8 -31
  28. data/app/assets/stylesheets/lines/pygments.css.erb +1 -2
  29. data/app/assets/stylesheets/lines/variables_and_mixins.scss +4 -0
  30. data/app/controllers/lines/admin/articles_controller.rb +8 -6
  31. data/app/controllers/lines/admin/authors_controller.rb +2 -2
  32. data/app/controllers/lines/admin/pictures_controller.rb +1 -1
  33. data/app/controllers/lines/application_controller.rb +1 -1
  34. data/app/controllers/lines/articles_controller.rb +3 -1
  35. data/app/controllers/lines/password_resets_controller.rb +4 -7
  36. data/app/controllers/lines/sessions_controller.rb +3 -3
  37. data/app/helpers/lines/application_helper.rb +25 -4
  38. data/app/mailers/lines/user_mailer.rb +1 -1
  39. data/app/models/lines/article.rb +13 -3
  40. data/app/models/lines/user.rb +2 -2
  41. data/app/uploaders/picture_uploader.rb +1 -1
  42. data/app/views/layouts/lines/_markdown_cheatsheet.html.erb +72 -0
  43. data/app/views/layouts/lines/admin.html.erb +15 -4
  44. data/app/views/layouts/lines/application.html.erb +16 -4
  45. data/app/views/layouts/lines/preview.html.erb +30 -2
  46. data/app/views/lines/admin/articles/_form.html.erb +50 -148
  47. data/app/views/lines/admin/articles/_picture_box.html.erb +37 -8
  48. data/app/views/lines/admin/articles/edit.html.erb +2 -12
  49. data/app/views/lines/admin/articles/index.html.erb +40 -28
  50. data/app/views/lines/admin/articles/new.html.erb +3 -10
  51. data/app/views/lines/admin/articles/show.html.erb +6 -4
  52. data/app/views/lines/admin/authors/_form.html.erb +12 -41
  53. data/app/views/lines/admin/authors/index.html.erb +18 -13
  54. data/app/views/lines/admin/authors/show.html.erb +19 -48
  55. data/app/views/lines/admin/pictures/_picture.html.erb +5 -4
  56. data/app/views/lines/admin/pictures/create.js.erb +1 -1
  57. data/app/views/lines/admin/pictures/destroy.js.erb +1 -1
  58. data/app/views/lines/articles/_article.html.erb +10 -6
  59. data/app/views/lines/articles/_article_collection.html.erb +1 -1
  60. data/app/views/lines/articles/_article_small.html.erb +9 -7
  61. data/app/views/lines/articles/index.atom.builder +10 -9
  62. data/app/views/lines/articles/index.html.erb +2 -2
  63. data/app/views/lines/articles/show.html.erb +5 -1
  64. data/app/views/lines/password_resets/edit.html.erb +25 -12
  65. data/app/views/lines/password_resets/new.html.erb +14 -8
  66. data/app/views/lines/sessions/new.html.erb +6 -10
  67. data/app/views/lines/shared/_flash.html.erb +1 -1
  68. data/app/views/lines/shared/_footer.html.erb +5 -28
  69. data/app/views/lines/user_mailer/password_reset.html.erb +6 -5
  70. data/app/views/lines/user_mailer/password_reset.text.erb +8 -4
  71. data/config/lines_config.yml +15 -14
  72. data/config/routes.rb +2 -2
  73. data/db/seeds.rb +5 -5
  74. data/lib/lines/engine.rb +1 -1
  75. data/lib/lines/version.rb +1 -1
  76. data/lines.gemspec +1 -1
  77. data/public/codemirror/.gitattributes +8 -0
  78. data/public/codemirror/.gitignore +8 -0
  79. data/public/codemirror/.npmignore +9 -0
  80. data/public/codemirror/.travis.yml +4 -0
  81. data/public/codemirror/AUTHORS +474 -0
  82. data/public/codemirror/CONTRIBUTING.md +88 -0
  83. data/public/codemirror/LICENSE +19 -0
  84. data/public/codemirror/README.md +27 -0
  85. data/public/codemirror/addon/comment/comment.js +183 -0
  86. data/public/codemirror/addon/comment/continuecomment.js +85 -0
  87. data/public/codemirror/addon/dialog/dialog.css +32 -0
  88. data/public/codemirror/addon/dialog/dialog.js +157 -0
  89. data/public/codemirror/addon/display/fullscreen.css +6 -0
  90. data/public/codemirror/addon/display/fullscreen.js +41 -0
  91. data/public/codemirror/addon/display/panel.js +112 -0
  92. data/public/codemirror/addon/display/placeholder.js +58 -0
  93. data/public/codemirror/addon/display/rulers.js +63 -0
  94. data/public/codemirror/addon/edit/closebrackets.js +185 -0
  95. data/public/codemirror/addon/edit/closetag.js +166 -0
  96. data/public/codemirror/addon/edit/continuelist.js +51 -0
  97. data/public/codemirror/addon/edit/matchbrackets.js +120 -0
  98. data/public/codemirror/addon/edit/matchtags.js +66 -0
  99. data/public/codemirror/addon/edit/trailingspace.js +27 -0
  100. data/public/codemirror/addon/fold/brace-fold.js +105 -0
  101. data/public/codemirror/addon/fold/comment-fold.js +57 -0
  102. data/public/codemirror/addon/fold/foldcode.js +149 -0
  103. data/public/codemirror/addon/fold/foldgutter.css +20 -0
  104. data/public/codemirror/addon/fold/foldgutter.js +146 -0
  105. data/public/codemirror/addon/fold/indent-fold.js +44 -0
  106. data/public/codemirror/addon/fold/markdown-fold.js +49 -0
  107. data/public/codemirror/addon/fold/xml-fold.js +182 -0
  108. data/public/codemirror/addon/hint/anyword-hint.js +41 -0
  109. data/public/codemirror/addon/hint/css-hint.js +60 -0
  110. data/public/codemirror/addon/hint/html-hint.js +348 -0
  111. data/public/codemirror/addon/hint/javascript-hint.js +146 -0
  112. data/public/codemirror/addon/hint/show-hint.css +38 -0
  113. data/public/codemirror/addon/hint/show-hint.js +386 -0
  114. data/public/codemirror/addon/hint/sql-hint.js +254 -0
  115. data/public/codemirror/addon/hint/xml-hint.js +110 -0
  116. data/public/codemirror/addon/lint/coffeescript-lint.js +41 -0
  117. data/public/codemirror/addon/lint/css-lint.js +35 -0
  118. data/public/codemirror/addon/lint/javascript-lint.js +136 -0
  119. data/public/codemirror/addon/lint/json-lint.js +31 -0
  120. data/public/codemirror/addon/lint/lint.css +73 -0
  121. data/public/codemirror/addon/lint/lint.js +207 -0
  122. data/public/codemirror/addon/lint/yaml-lint.js +28 -0
  123. data/public/codemirror/addon/merge/merge.css +112 -0
  124. data/public/codemirror/addon/merge/merge.js +775 -0
  125. data/public/codemirror/addon/mode/loadmode.js +64 -0
  126. data/public/codemirror/addon/mode/multiplex.js +123 -0
  127. data/public/codemirror/addon/mode/multiplex_test.js +33 -0
  128. data/public/codemirror/addon/mode/overlay.js +85 -0
  129. data/public/codemirror/addon/mode/simple.js +213 -0
  130. data/public/codemirror/addon/runmode/colorize.js +40 -0
  131. data/public/codemirror/addon/runmode/runmode-standalone.js +157 -0
  132. data/public/codemirror/addon/runmode/runmode.js +72 -0
  133. data/public/codemirror/addon/runmode/runmode.node.js +178 -0
  134. data/public/codemirror/addon/scroll/annotatescrollbar.js +115 -0
  135. data/public/codemirror/addon/scroll/scrollpastend.js +46 -0
  136. data/public/codemirror/addon/scroll/simplescrollbars.css +66 -0
  137. data/public/codemirror/addon/scroll/simplescrollbars.js +147 -0
  138. data/public/codemirror/addon/search/match-highlighter.js +128 -0
  139. data/public/codemirror/addon/search/matchesonscrollbar.css +8 -0
  140. data/public/codemirror/addon/search/matchesonscrollbar.js +97 -0
  141. data/public/codemirror/addon/search/search.js +202 -0
  142. data/public/codemirror/addon/search/searchcursor.js +189 -0
  143. data/public/codemirror/addon/selection/active-line.js +71 -0
  144. data/public/codemirror/addon/selection/mark-selection.js +118 -0
  145. data/public/codemirror/addon/selection/selection-pointer.js +98 -0
  146. data/public/codemirror/addon/tern/tern.css +87 -0
  147. data/public/codemirror/addon/tern/tern.js +699 -0
  148. data/public/codemirror/addon/tern/worker.js +44 -0
  149. data/public/codemirror/addon/wrap/hardwrap.js +139 -0
  150. data/public/codemirror/bin/authors.sh +6 -0
  151. data/public/codemirror/bin/compress +92 -0
  152. data/public/codemirror/bin/lint +3 -0
  153. data/public/codemirror/bin/release +45 -0
  154. data/public/codemirror/bin/source-highlight +51 -0
  155. data/public/codemirror/bower.json +17 -0
  156. data/public/codemirror/demo/activeline.html +78 -0
  157. data/public/codemirror/demo/anywordhint.html +79 -0
  158. data/public/codemirror/demo/bidi.html +74 -0
  159. data/public/codemirror/demo/btree.html +85 -0
  160. data/public/codemirror/demo/buffers.html +109 -0
  161. data/public/codemirror/demo/changemode.html +58 -0
  162. data/public/codemirror/demo/closebrackets.html +52 -0
  163. data/public/codemirror/demo/closetag.html +41 -0
  164. data/public/codemirror/demo/complete.html +79 -0
  165. data/public/codemirror/demo/emacs.html +75 -0
  166. data/public/codemirror/demo/folding.html +95 -0
  167. data/public/codemirror/demo/fullscreen.html +83 -0
  168. data/public/codemirror/demo/hardwrap.html +72 -0
  169. data/public/codemirror/demo/html5complete.html +56 -0
  170. data/public/codemirror/demo/indentwrap.html +59 -0
  171. data/public/codemirror/demo/lint.html +171 -0
  172. data/public/codemirror/demo/loadmode.html +72 -0
  173. data/public/codemirror/demo/marker.html +52 -0
  174. data/public/codemirror/demo/markselection.html +52 -0
  175. data/public/codemirror/demo/matchhighlighter.html +47 -0
  176. data/public/codemirror/demo/matchtags.html +48 -0
  177. data/public/codemirror/demo/merge.html +122 -0
  178. data/public/codemirror/demo/multiplex.html +75 -0
  179. data/public/codemirror/demo/mustache.html +69 -0
  180. data/public/codemirror/demo/panel.html +136 -0
  181. data/public/codemirror/demo/placeholder.html +45 -0
  182. data/public/codemirror/demo/preview.html +87 -0
  183. data/public/codemirror/demo/requirejs.html +70 -0
  184. data/public/codemirror/demo/resize.html +51 -0
  185. data/public/codemirror/demo/rulers.html +49 -0
  186. data/public/codemirror/demo/runmode.html +62 -0
  187. data/public/codemirror/demo/search.html +95 -0
  188. data/public/codemirror/demo/simplemode.html +186 -0
  189. data/public/codemirror/demo/simplescrollbars.html +82 -0
  190. data/public/codemirror/demo/spanaffectswrapping_shim.html +85 -0
  191. data/public/codemirror/demo/sublime.html +76 -0
  192. data/public/codemirror/demo/tern.html +133 -0
  193. data/public/codemirror/demo/theme.html +152 -0
  194. data/public/codemirror/demo/trailingspace.html +48 -0
  195. data/public/codemirror/demo/variableheight.html +67 -0
  196. data/public/codemirror/demo/vim.html +104 -0
  197. data/public/codemirror/demo/visibletabs.html +62 -0
  198. data/public/codemirror/demo/widget.html +85 -0
  199. data/public/codemirror/demo/xmlcomplete.html +119 -0
  200. data/public/codemirror/doc/activebookmark.js +57 -0
  201. data/public/codemirror/doc/compress.html +329 -0
  202. data/public/codemirror/doc/docs.css +271 -0
  203. data/public/codemirror/doc/internals.html +503 -0
  204. data/public/codemirror/doc/logo.png +0 -0
  205. data/public/codemirror/doc/logo.svg +181 -0
  206. data/public/codemirror/doc/manual.html +3327 -0
  207. data/public/codemirror/doc/realworld.html +174 -0
  208. data/public/codemirror/doc/releases.html +1116 -0
  209. data/public/codemirror/doc/reporting.html +61 -0
  210. data/public/codemirror/doc/upgrade_v2.2.html +96 -0
  211. data/public/codemirror/doc/upgrade_v3.html +230 -0
  212. data/public/codemirror/doc/upgrade_v4.html +144 -0
  213. data/public/codemirror/doc/yinyang.png +0 -0
  214. data/public/codemirror/index.html +199 -0
  215. data/public/codemirror/keymap/emacs.js +412 -0
  216. data/public/codemirror/keymap/sublime.js +555 -0
  217. data/public/codemirror/keymap/vim.js +5060 -0
  218. data/public/codemirror/lib/codemirror.css +332 -0
  219. data/public/codemirror/lib/codemirror.js +8788 -0
  220. data/public/codemirror/mode/apl/apl.js +174 -0
  221. data/public/codemirror/mode/apl/index.html +72 -0
  222. data/public/codemirror/mode/asciiarmor/asciiarmor.js +73 -0
  223. data/public/codemirror/mode/asciiarmor/index.html +46 -0
  224. data/public/codemirror/mode/asn.1/asn.1.js +204 -0
  225. data/public/codemirror/mode/asn.1/index.html +78 -0
  226. data/public/codemirror/mode/asterisk/asterisk.js +196 -0
  227. data/public/codemirror/mode/asterisk/index.html +154 -0
  228. data/public/codemirror/mode/brainfuck/brainfuck.js +85 -0
  229. data/public/codemirror/mode/brainfuck/index.html +85 -0
  230. data/public/codemirror/mode/clike/clike.js +604 -0
  231. data/public/codemirror/mode/clike/index.html +252 -0
  232. data/public/codemirror/mode/clike/scala.html +767 -0
  233. data/public/codemirror/mode/clike/test.js +33 -0
  234. data/public/codemirror/mode/clojure/clojure.js +244 -0
  235. data/public/codemirror/mode/clojure/index.html +88 -0
  236. data/public/codemirror/mode/cmake/cmake.js +97 -0
  237. data/public/codemirror/mode/cmake/index.html +129 -0
  238. data/public/codemirror/mode/cobol/cobol.js +255 -0
  239. data/public/codemirror/mode/cobol/index.html +210 -0
  240. data/public/codemirror/mode/coffeescript/coffeescript.js +369 -0
  241. data/public/codemirror/mode/coffeescript/index.html +740 -0
  242. data/public/codemirror/mode/commonlisp/commonlisp.js +123 -0
  243. data/public/codemirror/mode/commonlisp/index.html +177 -0
  244. data/public/codemirror/mode/css/css.js +756 -0
  245. data/public/codemirror/mode/css/index.html +75 -0
  246. data/public/codemirror/mode/css/less.html +152 -0
  247. data/public/codemirror/mode/css/less_test.js +54 -0
  248. data/public/codemirror/mode/css/scss.html +157 -0
  249. data/public/codemirror/mode/css/scss_test.js +110 -0
  250. data/public/codemirror/mode/css/test.js +188 -0
  251. data/public/codemirror/mode/cypher/cypher.js +146 -0
  252. data/public/codemirror/mode/cypher/index.html +63 -0
  253. data/public/codemirror/mode/d/d.js +218 -0
  254. data/public/codemirror/mode/d/index.html +273 -0
  255. data/public/codemirror/mode/dart/dart.js +50 -0
  256. data/public/codemirror/mode/dart/index.html +71 -0
  257. data/public/codemirror/mode/diff/diff.js +47 -0
  258. data/public/codemirror/mode/diff/index.html +117 -0
  259. data/public/codemirror/mode/django/django.js +350 -0
  260. data/public/codemirror/mode/django/index.html +73 -0
  261. data/public/codemirror/mode/dockerfile/dockerfile.js +76 -0
  262. data/public/codemirror/mode/dockerfile/index.html +73 -0
  263. data/public/codemirror/mode/dtd/dtd.js +142 -0
  264. data/public/codemirror/mode/dtd/index.html +89 -0
  265. data/public/codemirror/mode/dylan/dylan.js +291 -0
  266. data/public/codemirror/mode/dylan/index.html +407 -0
  267. data/public/codemirror/mode/ebnf/ebnf.js +195 -0
  268. data/public/codemirror/mode/ebnf/index.html +102 -0
  269. data/public/codemirror/mode/ecl/ecl.js +206 -0
  270. data/public/codemirror/mode/ecl/index.html +52 -0
  271. data/public/codemirror/mode/eiffel/eiffel.js +160 -0
  272. data/public/codemirror/mode/eiffel/index.html +429 -0
  273. data/public/codemirror/mode/elm/elm.js +205 -0
  274. data/public/codemirror/mode/elm/index.html +61 -0
  275. data/public/codemirror/mode/erlang/erlang.js +618 -0
  276. data/public/codemirror/mode/erlang/index.html +76 -0
  277. data/public/codemirror/mode/factor/factor.js +83 -0
  278. data/public/codemirror/mode/factor/index.html +77 -0
  279. data/public/codemirror/mode/forth/forth.js +180 -0
  280. data/public/codemirror/mode/forth/index.html +75 -0
  281. data/public/codemirror/mode/fortran/fortran.js +188 -0
  282. data/public/codemirror/mode/fortran/index.html +81 -0
  283. data/public/codemirror/mode/gas/gas.js +345 -0
  284. data/public/codemirror/mode/gas/index.html +68 -0
  285. data/public/codemirror/mode/gfm/gfm.js +124 -0
  286. data/public/codemirror/mode/gfm/index.html +93 -0
  287. data/public/codemirror/mode/gfm/test.js +213 -0
  288. data/public/codemirror/mode/gherkin/gherkin.js +178 -0
  289. data/public/codemirror/mode/gherkin/index.html +48 -0
  290. data/public/codemirror/mode/go/go.js +185 -0
  291. data/public/codemirror/mode/go/index.html +85 -0
  292. data/public/codemirror/mode/groovy/groovy.js +230 -0
  293. data/public/codemirror/mode/groovy/index.html +84 -0
  294. data/public/codemirror/mode/haml/haml.js +159 -0
  295. data/public/codemirror/mode/haml/index.html +79 -0
  296. data/public/codemirror/mode/haml/test.js +97 -0
  297. data/public/codemirror/mode/handlebars/handlebars.js +53 -0
  298. data/public/codemirror/mode/handlebars/index.html +83 -0
  299. data/public/codemirror/mode/haskell/haskell.js +267 -0
  300. data/public/codemirror/mode/haskell/index.html +73 -0
  301. data/public/codemirror/mode/haxe/haxe.js +518 -0
  302. data/public/codemirror/mode/haxe/index.html +124 -0
  303. data/public/codemirror/mode/htmlembedded/htmlembedded.js +28 -0
  304. data/public/codemirror/mode/htmlembedded/index.html +59 -0
  305. data/public/codemirror/mode/htmlmixed/htmlmixed.js +121 -0
  306. data/public/codemirror/mode/htmlmixed/index.html +89 -0
  307. data/public/codemirror/mode/http/http.js +113 -0
  308. data/public/codemirror/mode/http/index.html +45 -0
  309. data/public/codemirror/mode/idl/idl.js +290 -0
  310. data/public/codemirror/mode/idl/index.html +64 -0
  311. data/public/codemirror/mode/index.html +149 -0
  312. data/public/codemirror/mode/jade/index.html +70 -0
  313. data/public/codemirror/mode/jade/jade.js +590 -0
  314. data/public/codemirror/mode/javascript/index.html +114 -0
  315. data/public/codemirror/mode/javascript/javascript.js +704 -0
  316. data/public/codemirror/mode/javascript/json-ld.html +72 -0
  317. data/public/codemirror/mode/javascript/test.js +205 -0
  318. data/public/codemirror/mode/javascript/typescript.html +61 -0
  319. data/public/codemirror/mode/jinja2/index.html +54 -0
  320. data/public/codemirror/mode/jinja2/jinja2.js +142 -0
  321. data/public/codemirror/mode/julia/index.html +195 -0
  322. data/public/codemirror/mode/julia/julia.js +299 -0
  323. data/public/codemirror/mode/kotlin/index.html +89 -0
  324. data/public/codemirror/mode/kotlin/kotlin.js +284 -0
  325. data/public/codemirror/mode/livescript/index.html +459 -0
  326. data/public/codemirror/mode/livescript/livescript.js +280 -0
  327. data/public/codemirror/mode/lua/index.html +85 -0
  328. data/public/codemirror/mode/lua/lua.js +159 -0
  329. data/public/codemirror/mode/markdown/index.html +359 -0
  330. data/public/codemirror/mode/markdown/markdown.js +781 -0
  331. data/public/codemirror/mode/markdown/test.js +792 -0
  332. data/public/codemirror/mode/mathematica/index.html +72 -0
  333. data/public/codemirror/mode/mathematica/mathematica.js +175 -0
  334. data/public/codemirror/mode/meta.js +190 -0
  335. data/public/codemirror/mode/mirc/index.html +160 -0
  336. data/public/codemirror/mode/mirc/mirc.js +193 -0
  337. data/public/codemirror/mode/mllike/index.html +179 -0
  338. data/public/codemirror/mode/mllike/mllike.js +205 -0
  339. data/public/codemirror/mode/modelica/index.html +67 -0
  340. data/public/codemirror/mode/modelica/modelica.js +245 -0
  341. data/public/codemirror/mode/mumps/index.html +85 -0
  342. data/public/codemirror/mode/mumps/mumps.js +148 -0
  343. data/public/codemirror/mode/nginx/index.html +181 -0
  344. data/public/codemirror/mode/nginx/nginx.js +178 -0
  345. data/public/codemirror/mode/ntriples/index.html +45 -0
  346. data/public/codemirror/mode/ntriples/ntriples.js +186 -0
  347. data/public/codemirror/mode/octave/index.html +83 -0
  348. data/public/codemirror/mode/octave/octave.js +135 -0
  349. data/public/codemirror/mode/pascal/index.html +61 -0
  350. data/public/codemirror/mode/pascal/pascal.js +109 -0
  351. data/public/codemirror/mode/pegjs/index.html +66 -0
  352. data/public/codemirror/mode/pegjs/pegjs.js +114 -0
  353. data/public/codemirror/mode/perl/index.html +75 -0
  354. data/public/codemirror/mode/perl/perl.js +837 -0
  355. data/public/codemirror/mode/php/index.html +64 -0
  356. data/public/codemirror/mode/php/php.js +230 -0
  357. data/public/codemirror/mode/php/test.js +154 -0
  358. data/public/codemirror/mode/pig/index.html +55 -0
  359. data/public/codemirror/mode/pig/pig.js +178 -0
  360. data/public/codemirror/mode/properties/index.html +53 -0
  361. data/public/codemirror/mode/properties/properties.js +78 -0
  362. data/public/codemirror/mode/puppet/index.html +121 -0
  363. data/public/codemirror/mode/puppet/puppet.js +220 -0
  364. data/public/codemirror/mode/python/index.html +198 -0
  365. data/public/codemirror/mode/python/python.js +358 -0
  366. data/public/codemirror/mode/q/index.html +144 -0
  367. data/public/codemirror/mode/q/q.js +139 -0
  368. data/public/codemirror/mode/r/index.html +85 -0
  369. data/public/codemirror/mode/r/r.js +162 -0
  370. data/public/codemirror/mode/rpm/changes/index.html +66 -0
  371. data/public/codemirror/mode/rpm/index.html +149 -0
  372. data/public/codemirror/mode/rpm/rpm.js +101 -0
  373. data/public/codemirror/mode/rst/index.html +535 -0
  374. data/public/codemirror/mode/rst/rst.js +557 -0
  375. data/public/codemirror/mode/ruby/index.html +183 -0
  376. data/public/codemirror/mode/ruby/ruby.js +285 -0
  377. data/public/codemirror/mode/ruby/test.js +14 -0
  378. data/public/codemirror/mode/rust/index.html +60 -0
  379. data/public/codemirror/mode/rust/rust.js +451 -0
  380. data/public/codemirror/mode/sass/index.html +66 -0
  381. data/public/codemirror/mode/sass/sass.js +414 -0
  382. data/public/codemirror/mode/scheme/index.html +77 -0
  383. data/public/codemirror/mode/scheme/scheme.js +249 -0
  384. data/public/codemirror/mode/shell/index.html +66 -0
  385. data/public/codemirror/mode/shell/shell.js +139 -0
  386. data/public/codemirror/mode/shell/test.js +58 -0
  387. data/public/codemirror/mode/sieve/index.html +93 -0
  388. data/public/codemirror/mode/sieve/sieve.js +193 -0
  389. data/public/codemirror/mode/slim/index.html +96 -0
  390. data/public/codemirror/mode/slim/slim.js +575 -0
  391. data/public/codemirror/mode/slim/test.js +96 -0
  392. data/public/codemirror/mode/smalltalk/index.html +68 -0
  393. data/public/codemirror/mode/smalltalk/smalltalk.js +168 -0
  394. data/public/codemirror/mode/smarty/index.html +138 -0
  395. data/public/codemirror/mode/smarty/smarty.js +225 -0
  396. data/public/codemirror/mode/solr/index.html +57 -0
  397. data/public/codemirror/mode/solr/solr.js +104 -0
  398. data/public/codemirror/mode/soy/index.html +68 -0
  399. data/public/codemirror/mode/soy/soy.js +198 -0
  400. data/public/codemirror/mode/sparql/index.html +61 -0
  401. data/public/codemirror/mode/sparql/sparql.js +174 -0
  402. data/public/codemirror/mode/spreadsheet/index.html +42 -0
  403. data/public/codemirror/mode/spreadsheet/spreadsheet.js +109 -0
  404. data/public/codemirror/mode/sql/index.html +84 -0
  405. data/public/codemirror/mode/sql/sql.js +391 -0
  406. data/public/codemirror/mode/stex/index.html +110 -0
  407. data/public/codemirror/mode/stex/stex.js +251 -0
  408. data/public/codemirror/mode/stex/test.js +123 -0
  409. data/public/codemirror/mode/stylus/index.html +106 -0
  410. data/public/codemirror/mode/stylus/stylus.js +768 -0
  411. data/public/codemirror/mode/swift/index.html +88 -0
  412. data/public/codemirror/mode/swift/swift.js +203 -0
  413. data/public/codemirror/mode/tcl/index.html +142 -0
  414. data/public/codemirror/mode/tcl/tcl.js +147 -0
  415. data/public/codemirror/mode/textile/index.html +191 -0
  416. data/public/codemirror/mode/textile/test.js +417 -0
  417. data/public/codemirror/mode/textile/textile.js +469 -0
  418. data/public/codemirror/mode/tiddlywiki/index.html +154 -0
  419. data/public/codemirror/mode/tiddlywiki/tiddlywiki.css +14 -0
  420. data/public/codemirror/mode/tiddlywiki/tiddlywiki.js +358 -0
  421. data/public/codemirror/mode/tiki/index.html +95 -0
  422. data/public/codemirror/mode/tiki/tiki.css +26 -0
  423. data/public/codemirror/mode/tiki/tiki.js +312 -0
  424. data/public/codemirror/mode/toml/index.html +73 -0
  425. data/public/codemirror/mode/toml/toml.js +88 -0
  426. data/public/codemirror/mode/tornado/index.html +63 -0
  427. data/public/codemirror/mode/tornado/tornado.js +68 -0
  428. data/public/codemirror/mode/troff/index.html +146 -0
  429. data/public/codemirror/mode/troff/troff.js +82 -0
  430. data/public/codemirror/mode/ttcn-cfg/index.html +115 -0
  431. data/public/codemirror/mode/ttcn-cfg/ttcn-cfg.js +214 -0
  432. data/public/codemirror/mode/ttcn/index.html +118 -0
  433. data/public/codemirror/mode/ttcn/ttcn.js +283 -0
  434. data/public/codemirror/mode/turtle/index.html +50 -0
  435. data/public/codemirror/mode/turtle/turtle.js +162 -0
  436. data/public/codemirror/mode/twig/index.html +45 -0
  437. data/public/codemirror/mode/twig/twig.js +132 -0
  438. data/public/codemirror/mode/vb/index.html +102 -0
  439. data/public/codemirror/mode/vb/vb.js +276 -0
  440. data/public/codemirror/mode/vbscript/index.html +55 -0
  441. data/public/codemirror/mode/vbscript/vbscript.js +350 -0
  442. data/public/codemirror/mode/velocity/index.html +118 -0
  443. data/public/codemirror/mode/velocity/velocity.js +201 -0
  444. data/public/codemirror/mode/verilog/index.html +120 -0
  445. data/public/codemirror/mode/verilog/test.js +273 -0
  446. data/public/codemirror/mode/verilog/verilog.js +537 -0
  447. data/public/codemirror/mode/vhdl/index.html +95 -0
  448. data/public/codemirror/mode/vhdl/vhdl.js +189 -0
  449. data/public/codemirror/mode/xml/index.html +57 -0
  450. data/public/codemirror/mode/xml/test.js +51 -0
  451. data/public/codemirror/mode/xml/xml.js +385 -0
  452. data/public/codemirror/mode/xquery/index.html +210 -0
  453. data/public/codemirror/mode/xquery/test.js +67 -0
  454. data/public/codemirror/mode/xquery/xquery.js +437 -0
  455. data/public/codemirror/mode/yaml/index.html +80 -0
  456. data/public/codemirror/mode/yaml/yaml.js +117 -0
  457. data/public/codemirror/mode/z80/index.html +53 -0
  458. data/public/codemirror/mode/z80/z80.js +116 -0
  459. data/public/codemirror/package.json +20 -0
  460. data/public/codemirror/test/comment_test.js +100 -0
  461. data/public/codemirror/test/doc_test.js +371 -0
  462. data/public/codemirror/test/driver.js +138 -0
  463. data/public/codemirror/test/emacs_test.js +147 -0
  464. data/public/codemirror/test/index.html +241 -0
  465. data/public/codemirror/test/lint.js +11 -0
  466. data/public/codemirror/test/mode_test.css +23 -0
  467. data/public/codemirror/test/mode_test.js +192 -0
  468. data/public/codemirror/test/multi_test.js +285 -0
  469. data/public/codemirror/test/phantom_driver.js +31 -0
  470. data/public/codemirror/test/run.js +31 -0
  471. data/public/codemirror/test/scroll_test.js +115 -0
  472. data/public/codemirror/test/search_test.js +62 -0
  473. data/public/codemirror/test/sql-hint-test.js +189 -0
  474. data/public/codemirror/test/sublime_test.js +303 -0
  475. data/public/codemirror/test/test.js +2142 -0
  476. data/public/codemirror/test/vim_test.js +3955 -0
  477. data/public/codemirror/theme/3024-day.css +41 -0
  478. data/public/codemirror/theme/3024-night.css +39 -0
  479. data/public/codemirror/theme/ambiance-mobile.css +5 -0
  480. data/public/codemirror/theme/ambiance.css +76 -0
  481. data/public/codemirror/theme/base16-dark.css +38 -0
  482. data/public/codemirror/theme/base16-light.css +38 -0
  483. data/public/codemirror/theme/blackboard.css +32 -0
  484. data/public/codemirror/theme/cobalt.css +25 -0
  485. data/public/codemirror/theme/colorforth.css +33 -0
  486. data/public/codemirror/theme/dracula.css +87 -0
  487. data/public/codemirror/theme/eclipse.css +23 -0
  488. data/public/codemirror/theme/elegant.css +13 -0
  489. data/public/codemirror/theme/erlang-dark.css +34 -0
  490. data/public/codemirror/theme/icecoder.css +42 -0
  491. data/public/codemirror/theme/lesser-dark.css +47 -0
  492. data/public/codemirror/theme/lines.css +109 -0
  493. data/public/codemirror/theme/liquibyte.css +95 -0
  494. data/public/codemirror/theme/material.css +105 -0
  495. data/public/codemirror/theme/mbo.css +37 -0
  496. data/public/codemirror/theme/mdn-like.css +46 -0
  497. data/public/codemirror/theme/midnight.css +47 -0
  498. data/public/codemirror/theme/monokai.css +35 -0
  499. data/public/codemirror/theme/neat.css +12 -0
  500. data/public/codemirror/theme/neo.css +43 -0
  501. data/public/codemirror/theme/night.css +28 -0
  502. data/public/codemirror/theme/paraiso-dark.css +38 -0
  503. data/public/codemirror/theme/paraiso-light.css +38 -0
  504. data/public/codemirror/theme/pastel-on-dark.css +53 -0
  505. data/public/codemirror/theme/rubyblue.css +25 -0
  506. data/public/codemirror/theme/seti.css +88 -0
  507. data/public/codemirror/theme/solarized.css +165 -0
  508. data/public/codemirror/theme/the-matrix.css +30 -0
  509. data/public/codemirror/theme/tomorrow-night-bright.css +35 -0
  510. data/public/codemirror/theme/tomorrow-night-eighties.css +38 -0
  511. data/public/codemirror/theme/ttcn.css +65 -0
  512. data/public/codemirror/theme/twilight.css +32 -0
  513. data/public/codemirror/theme/vibrant-ink.css +34 -0
  514. data/public/codemirror/theme/xq-dark.css +53 -0
  515. data/public/codemirror/theme/xq-light.css +43 -0
  516. data/public/codemirror/theme/yeti.css +86 -0
  517. data/public/codemirror/theme/zenburn.css +37 -0
  518. data/public/fira-mono/FiraMono-Bold.eot +0 -0
  519. data/public/fira-mono/FiraMono-Bold.otf +0 -0
  520. data/public/fira-mono/FiraMono-Bold.ttf +0 -0
  521. data/public/fira-mono/FiraMono-Bold.woff +0 -0
  522. data/public/fira-mono/FiraMono-Medium.eot +0 -0
  523. data/public/fira-mono/FiraMono-Medium.otf +0 -0
  524. data/public/fira-mono/FiraMono-Medium.ttf +0 -0
  525. data/public/fira-mono/FiraMono-Medium.woff +0 -0
  526. data/public/fira-mono/FiraMono-Regular.eot +0 -0
  527. data/public/fira-mono/FiraMono-Regular.otf +0 -0
  528. data/public/fira-mono/FiraMono-Regular.ttf +0 -0
  529. data/public/fira-mono/FiraMono-Regular.woff +0 -0
  530. data/public/fira-mono/fira-mono.css +32 -0
  531. data/public/heroes/lines_default_01.png +0 -0
  532. data/public/heroes/lines_default_02.png +0 -0
  533. data/public/heroes/lines_default_03.png +0 -0
  534. data/public/iconfont/iconfont.css +48 -0
  535. data/public/iconfont/iconfont.eot +0 -0
  536. data/public/iconfont/iconfont.svg +18 -0
  537. data/public/iconfont/iconfont.ttf +0 -0
  538. data/public/iconfont/iconfont.woff +0 -0
  539. data/spec/dummy/config/environments/test.rb +3 -1
  540. data/spec/dummy/db/migrate/20140505122014_base_migration.rb +84 -0
  541. data/spec/dummy/db/migrate/20140702160602_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +31 -0
  542. data/spec/dummy/db/migrate/20140702160603_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
  543. data/spec/dummy/db/migrate/20140702160604_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
  544. data/spec/dummy/db/migrate/20141027143656_add_teaser_to_article.rb +5 -0
  545. data/spec/dummy/db/migrate/20150421093311_add_reset_password_fields_to_users.rb +6 -0
  546. data/spec/dummy/db/schema.rb +50 -50
  547. data/spec/dummy/db/seeds.rb +5 -5
  548. data/spec/factories/users.rb +1 -1
  549. data/spec/features/article_spec.rb +4 -4
  550. data/spec/features/password_reset_spec.rb +17 -17
  551. data/spec/features/user_logs_in_spec.rb +6 -8
  552. data/spec/mailers/lines/user_mailer_spec.rb +1 -1
  553. data/spec/models/article_spec.rb +6 -6
  554. data/spec/support/auth_macros.rb +2 -2
  555. metadata +492 -26
  556. metadata.gz.sig +0 -0
  557. data/app/assets/images/ic_gplus.png +0 -0
  558. data/app/assets/images/ic_gplus_hover.png +0 -0
  559. data/app/assets/images/logo.png +0 -0
  560. data/app/assets/images/logo_opoloo.png +0 -0
  561. data/app/assets/images/signet.png +0 -0
  562. data/app/assets/javascripts/lines/admin.js +0 -201
  563. data/app/assets/stylesheets/lines/admin.scss +0 -970
  564. data/app/views/layouts/lines/_messages.html.erb +0 -8
  565. data/app/views/lines/admin/articles/_formatting_guide.html.erb +0 -89
  566. data/public/heroes/001.jpg +0 -0
  567. data/public/heroes/001_dark.jpg +0 -0
  568. data/public/heroes/002.jpg +0 -0
  569. data/public/heroes/002_dark.jpg +0 -0
  570. data/public/heroes/003.jpg +0 -0
  571. data/public/heroes/003_dark.jpg +0 -0
  572. data/spec/dummy/config/lines_config.yml +0 -58
Binary file
@@ -0,0 +1,181 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+ <svg
5
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
6
+ xmlns:cc="http://creativecommons.org/ns#"
7
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
+ xmlns:svg="http://www.w3.org/2000/svg"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
11
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
12
+ id="svg2"
13
+ version="1.1"
14
+ inkscape:version="0.48.4 r9939"
15
+ width="640"
16
+ height="640"
17
+ xml:space="preserve"
18
+ sodipodi:docname="logo.svg"
19
+ inkscape:export-filename="/home/marijn/src/js/codemirror/doc/logo.png"
20
+ inkscape:export-xdpi="16.601332"
21
+ inkscape:export-ydpi="16.601332"><metadata
22
+ id="metadata8"><rdf:RDF><cc:Work
23
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
24
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
25
+ id="defs6"><clipPath
26
+ clipPathUnits="userSpaceOnUse"
27
+ id="clipPath16"><path
28
+ d="M 0,512 512,512 512,0 0,0 0,512 z"
29
+ id="path18" /></clipPath><clipPath
30
+ clipPathUnits="userSpaceOnUse"
31
+ id="clipPath40"><path
32
+ d="m 435.607,369.899 31.242,0 0,-64.782 -31.242,0 0,64.782 z"
33
+ id="path42" /></clipPath><clipPath
34
+ clipPathUnits="userSpaceOnUse"
35
+ id="clipPath56"><path
36
+ d="m 421.796,349.477 39.074,0 0,-88.423 -39.074,0 0,88.423 z"
37
+ id="path58" /></clipPath></defs><sodipodi:namedview
38
+ pagecolor="#ffffff"
39
+ bordercolor="#666666"
40
+ borderopacity="1"
41
+ objecttolerance="10"
42
+ gridtolerance="10"
43
+ guidetolerance="10"
44
+ inkscape:pageopacity="0"
45
+ inkscape:pageshadow="2"
46
+ inkscape:window-width="1600"
47
+ inkscape:window-height="875"
48
+ id="namedview4"
49
+ showgrid="false"
50
+ showguides="true"
51
+ inkscape:guide-bbox="true"
52
+ inkscape:zoom="0.52149125"
53
+ inkscape:cx="303.572"
54
+ inkscape:cy="574.48012"
55
+ inkscape:window-x="0"
56
+ inkscape:window-y="25"
57
+ inkscape:window-maximized="0"
58
+ inkscape:current-layer="g10" /><g
59
+ id="g10"
60
+ inkscape:groupmode="layer"
61
+ inkscape:label="2014-10_codeMirror_logo_vectors"
62
+ transform="matrix(1.25,0,0,-1.25,0,640)"><path
63
+ inkscape:connector-curvature="0"
64
+ id="path22"
65
+ style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
66
+ d="m 233.97976,469.37438 c 0,0 7.01353,-14.94848 -2.94916,-31.42373 -4.97925,-8.23417 -130.50847,-34.94915 -179.50847,-102.94915 -30,-47 -76,-183 71,-273 66,-34 94,-33 94,-33 0,0 -44,31 -16,52 28,21 69,31 80,60 13,-10 34,-31 54,-29 -2,13 -7,18 9,20 16,2 24,2 24,2 0,0 -15,12 -32,13 -17,1 -49,34 -48,48 21,12 48,32 64,26 16,-6 32,-16 35,-25 0,-6 -3,-16 10,-8 13,8 10,13 15,24 5,11 6,13 -5,22 -11,9 -37,30 -58,24 -21,-6 -65,-23 -87,-2 9,20 23,52 16,74 13,10 28,21 30,39 15,2 47,11 41,27 -6,16 -48.59322,87.16949 -113.59322,73.16949"
67
+ sodipodi:nodetypes="cscccsccscscscsssscccsc" /><path
68
+ inkscape:connector-curvature="0"
69
+ id="path26"
70
+ style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
71
+ d="m 441.52213,306.0015 c 11,29 29,78 12,80 -17,2 -36,-44 -41,-56 -5,-12 -25,-72 -14,-80 11,-8 43,56 43,56" /><path
72
+ inkscape:connector-curvature="0"
73
+ id="path30"
74
+ style="fill:#da687d;fill-opacity:1;fill-rule:nonzero;stroke:none"
75
+ d="m 348.52213,384.0015 c 3.13,4.919 5.82086,0.64508 -7.67914,-0.35492 -13.5,-1 -29.62196,-5.18461 -32.38899,-11.04836 -5.19174,-11.00208 -6.93187,-38.09672 -26.43187,-44.09672 -1,-7 0,-23 27.5,-26 27.5,-3 28.5,15 44.5,14.5 16,-0.5 14.5,5.5 9,10 -5.5,4.5 -24.5,35 -24.5,45 0,10 6.5,6.5 10,12"
76
+ sodipodi:nodetypes="csscssssc" /><path
77
+ inkscape:connector-curvature="0"
78
+ id="path34"
79
+ style="fill:#da687d;fill-opacity:1;fill-rule:nonzero;stroke:none"
80
+ d="m 103.02213,82.502 c 0,0 -8.5,22.5 16.5,34.5 25,12 47.5,2.5 52,-6 4.5,-8.5 -7.5,-42.5 -50.5,-43 -10.5,8.5 -18,14.5 -18,14.5" /><g
81
+ id="g38"
82
+ transform="translate(-21.47687,0)" /><g
83
+ id="g44"
84
+ transform="translate(-21.47687,0)"><g
85
+ style="opacity:0.69999701"
86
+ id="g46"
87
+ clip-path="url(#clipPath40)"><g
88
+ id="g48"
89
+ transform="translate(466.2583,369.8384)"><path
90
+ inkscape:connector-curvature="0"
91
+ id="path50"
92
+ style="fill:#da687d;fill-opacity:1;fill-rule:evenodd;stroke:none"
93
+ d="M 0,0 C 0.423,-1.569 0.298,-3.199 0.255,-4.838 0.213,-6.452 0.062,-8.15 -0.349,-9.801 c 0.106,-0.377 -0.082,-0.814 -0.018,-1.201 -0.41,-0.515 -0.194,-0.903 -0.284,-1.354 0.661,-0.674 1.522,-1.313 1.152,-2.162 -0.259,-0.596 -0.874,-0.706 -1.464,-0.995 -0.389,-1.403 -0.709,-3.099 -1.028,-4.649 -0.097,-0.476 -0.044,-1.051 -0.187,-1.485 -0.334,-1.01 -0.691,-1.978 -0.971,-3.09 -0.237,-0.945 0.034,-2.689 -1.063,-2.811 -0.423,-1.049 -0.663,-1.841 -1.165,-2.83 -0.286,-0.163 -0.452,0.106 -0.692,0.009 -0.305,-0.348 -0.294,-0.823 -0.577,-1.114 -0.222,-0.229 -0.503,-0.163 -0.665,-0.385 -0.363,-0.5 -0.266,-1.24 -0.523,-1.902 -0.468,-0.4 -0.862,-0.905 -1.147,-1.478 -0.588,-1.179 -0.698,-2.681 -1.591,-3.593 -0.28,-0.286 -0.761,-0.365 -1.011,-0.647 -0.238,-0.269 -0.455,-0.665 -0.689,-0.98 -0.338,-0.452 -0.669,-1.045 -0.972,-1.583 -1.004,-1.787 -2.383,-3.71 -3.301,-5.664 -0.173,-0.369 -0.199,-0.805 -0.364,-1.165 -0.381,-0.827 -0.943,-1.579 -1.257,-2.333 -0.516,-1.239 -1.31,-3.339 -2.538,-4.42 -0.149,-0.131 -0.473,-0.254 -0.606,-0.414 -0.179,-0.215 -0.136,-0.568 -0.32,-0.808 -0.086,-0.113 -0.4,-0.164 -0.537,-0.302 -0.208,-0.211 -0.306,-0.481 -0.479,-0.639 -0.426,-0.388 -1.015,-0.555 -1.381,-0.959 -0.277,-0.306 -0.397,-0.743 -0.692,-1.127 -0.318,-0.413 -0.761,-0.784 -1.09,-1.202 -0.994,-1.264 -1.38,-2.8 -2.702,-3.396 -0.393,-0.178 -0.88,-0.12 -1.291,-0.241 -0.374,0.344 -0.078,0.818 -0.163,1.164 -0.055,0.222 -0.285,0.382 -0.346,0.583 -0.143,0.474 -0.347,1.336 -0.34,1.878 0.007,0.538 0.305,0.971 0.375,1.612 0.061,0.549 -0.137,1.246 -0.177,1.856 -0.021,0.306 0.064,0.624 0.059,0.956 -0.008,0.533 -0.066,0.801 0.008,1.442 0.086,0.743 -0.074,1.462 -0.171,2.152 0.342,1.705 0.531,3.008 1.09,4.919 0.258,0.881 0.721,2.367 1.18,3.346 0.886,1.895 1.64,3.964 2.6,5.945 0.319,0.656 0.825,1.196 1.139,1.852 0.182,0.381 0.211,0.828 0.395,1.215 1.617,3.398 3.877,6.233 5.565,9.731 1.399,2.859 2.88,5.418 4.745,8.545 0.842,1.415 1.568,2.917 2.434,4.086 0.66,0.891 1.632,2.413 2.334,3.916 0.278,0.596 0.269,1.073 1.005,1.102 0.758,0.948 1.326,2.018 2.119,2.824 0.2,0.202 0.51,0.303 0.733,0.498 0.26,0.228 0.383,0.57 0.638,0.778 0.541,0.441 1.432,0.832 2.035,1.659 0.16,0.22 0.229,0.451 0.406,0.682 0.414,0.539 1.191,1.866 1.81,2.013 C -0.241,0.085 -0.126,0.061 0,0" /></g></g></g><g
94
+ id="g54"
95
+ transform="translate(-21.47687,0)" /><g
96
+ id="g60"
97
+ transform="translate(-21.47687,0)"><g
98
+ style="opacity:0.69999701"
99
+ id="g62"
100
+ clip-path="url(#clipPath56)"><g
101
+ id="g64"
102
+ transform="translate(459.8965,349.4487)"><path
103
+ inkscape:connector-curvature="0"
104
+ id="path66"
105
+ style="fill:#da687d;fill-opacity:1;fill-rule:evenodd;stroke:none"
106
+ d="m 0,0 c 0.688,-1.936 0.765,-4.106 0.935,-6.266 -0.019,-2.14 -0.168,-4.579 -0.715,-6.943 0.098,-0.492 -0.155,-1.108 -0.109,-1.623 -0.519,-0.752 -0.295,-1.25 -0.438,-1.876 0.718,-0.835 1.666,-1.609 1.155,-2.836 -0.37,-0.846 -1.118,-1.037 -1.845,-1.479 -0.64,-1.905 -1.226,-4.263 -1.846,-6.305 -0.187,-0.635 -0.212,-1.395 -0.447,-1.977 -0.547,-1.362 -1.111,-2.656 -1.597,-4.101 -0.416,-1.238 -0.356,-3.498 -1.652,-3.689 -0.61,-1.355 -0.978,-2.373 -1.674,-3.651 -0.35,-0.217 -0.512,0.119 -0.801,-0.013 -0.392,-0.456 -0.442,-1.063 -0.795,-1.445 -0.269,-0.298 -0.585,-0.226 -0.785,-0.514 -0.449,-0.651 -0.386,-1.58 -0.723,-2.425 -0.282,-0.266 -0.546,-0.564 -0.784,-0.888 -0.119,-0.162 -0.233,-0.33 -0.337,-0.505 l -0.153,-0.266 -0.072,-0.136 -0.034,-0.069 -0.003,-0.004 0,-10e-4 c 0.099,0.238 0.028,0.066 0.05,0.119 l -10e-4,-0.002 -0.001,-10e-4 -0.004,-0.01 -0.008,-0.019 -0.016,-0.037 c -0.697,-1.635 -0.851,-3.63 -1.895,-4.955 -0.335,-0.421 -0.872,-0.577 -1.142,-0.971 -0.259,-0.375 -0.491,-0.912 -0.746,-1.347 -0.366,-0.625 -0.722,-1.432 -1.046,-2.164 -1.085,-2.456 -2.571,-5.274 -3.572,-8.03 -0.188,-0.523 -0.205,-1.106 -0.385,-1.617 -0.422,-1.173 -1.022,-2.273 -1.394,-3.342 -0.626,-1.753 -1.474,-4.727 -3.01,-6.377 -0.182,-0.2 -0.567,-0.415 -0.732,-0.65 -0.22,-0.315 -0.191,-0.786 -0.42,-1.137 -0.106,-0.164 -0.475,-0.275 -0.642,-0.48 -0.254,-0.313 -0.383,-0.69 -0.594,-0.926 -0.503,-0.581 -1.23,-0.865 -1.714,-1.438 -0.365,-0.435 -0.562,-1.029 -0.958,-1.568 -0.426,-0.578 -0.991,-1.104 -1.428,-1.683 -0.65,-0.928 -1.251,-1.786 -1.828,-2.608 -0.592,-0.813 -1.215,-1.514 -2.047,-1.884 -0.495,-0.219 -1.042,-0.12 -1.539,-0.256 -0.353,0.473 0.086,1.071 0.061,1.524 -0.018,0.288 -0.25,0.504 -0.28,0.766 -0.07,0.615 -0.141,1.712 -0.035,2.387 0.099,0.676 0.548,1.191 0.712,2.005 0.125,0.708 -0.034,1.591 -0.025,2.359 0.004,0.387 0.13,0.791 0.153,1.206 0.038,0.668 -0.008,0.999 0.13,1.795 0.163,0.922 -0.034,1.854 -0.121,2.709 0.426,2.191 0.686,3.806 1.265,6.362 0.273,1.176 0.786,3.104 1.265,4.488 0.472,1.315 0.904,2.681 1.347,4.063 0.445,1.4 0.906,2.841 1.424,4.249 0.347,0.939 0.896,1.734 1.274,2.728 0.213,0.565 0.249,1.192 0.465,1.767 0.475,1.25 0.99,2.514 1.541,3.656 0.553,1.123 1.13,2.228 1.711,3.336 l 0.938,1.807 c 0.326,0.58 0.653,1.161 0.981,1.745 0.649,1.172 1.283,2.367 1.886,3.609 1.027,1.966 2.073,3.828 3.188,5.725 1.116,1.844 2.324,3.757 3.629,5.817 1.158,1.853 2.248,3.825 3.357,5.355 0.827,1.167 2.173,3.163 3.042,5.126 0.342,0.78 0.349,1.38 1.197,1.482 0.907,1.274 1.649,2.697 2.452,3.773 0.214,0.276 0.563,0.445 0.808,0.722 0.286,0.323 0.408,0.762 0.693,1.065 0.582,0.653 1.672,1.277 2.21,2.569 0.151,0.332 0.198,0.653 0.368,1.006 0.397,0.822 1.098,2.779 1.78,3.145 C -0.284,0.044 -0.151,0.044 0,0" /></g></g></g><path
107
+ inkscape:connector-curvature="0"
108
+ id="path70"
109
+ style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
110
+ d="m 416.68863,327.0015 c 0,0 -8,-30.667 -4.667,-56 0.667,8 4.667,56 4.667,56" /><path
111
+ inkscape:connector-curvature="0"
112
+ id="path74"
113
+ style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
114
+ d="m 426.18913,347.7256 c -0.61,2.147 -4.597,-59.478 -3.432,-61.636 1.166,-2.159 7.147,48.575 3.432,61.636" /><path
115
+ inkscape:connector-curvature="0"
116
+ id="path78"
117
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
118
+ d="m 235.24913,465.60369 c 0,0 4.667,-26.6198 -38.667,-40.6198 -43.333,-14 -103.0605,-25.98239 -147.0605,-78.64939 -44.0000004,-52.666 -52.0000004,-139.999 -22,-197.333 30,-57.333 103.333,-128.667 235.333,-128.667 132,0 236.85312,101.50582 236.85312,171.50582 0,36.667 -20.1469,28.4918 -27.11433,-5.90828 C 466.30468,154.88286 408.18863,39.0015 262.18863,39.0015 c -146,0 -220.667,88.667 -230,164.667 -9.334,76 11.898969,141.46925 88.56597,180.80225 76.667,39.334 125.32039,23.66435 114.65339,80.99735"
119
+ sodipodi:nodetypes="cssssssscsc" /><path
120
+ inkscape:connector-curvature="0"
121
+ id="path82"
122
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
123
+ d="m 198.85713,260.335 c 0,0 -8.667,-40.001 -50.667,-59.333 -42,-19.334 -60,-30 -66,-63.334 16,26.666 62.667,32 88.667,58 26,26 28,64.667 28,64.667" /><path
124
+ inkscape:connector-curvature="0"
125
+ id="path86"
126
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
127
+ d="m 210.19013,353.0015 c 0,0 36,-46.667 78.667,-24 42.666,22.667 20.667,75.333 20,78.667 -0.667,3.333 4.666,-58.667 -27.334,-69.334 -32,-10.666 -71.333,14.667 -71.333,14.667" /><path
128
+ inkscape:connector-curvature="0"
129
+ id="path90"
130
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
131
+ d="m 116.18913,74.3359 c 0,0 22.666,-1.334 39.333,17.332 16.667,18.668 7.334,48 34.667,58.668 27.333,10.666 46,4 46,4 0,0 -48.667,-6.668 -52.667,-34.668 -4,-28 -10.666,-40.666 -21.333,-49.332 -10.667,-8.668 -24.667,-10 -24.667,-10 l -21.333,14 z" /><path
132
+ inkscape:connector-curvature="0"
133
+ id="path94"
134
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
135
+ d="m 219.02213,219.502 c 0,0 40.523,6.783 59,48 15.167,33.833 5,63 5,63 l -20.5,-3 c 0,0 8.5,-24.5 2,-46.5 -6.5,-22 -21.5,-47.5 -45.5,-61.5" /><path
136
+ inkscape:connector-curvature="0"
137
+ id="path98"
138
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
139
+ d="m 437.13303,313.1621 c -14.461,-36.13 -35.773,-62.068 -38.265,-60.674 -4.494,2.513 -0.358,34.036 14.104,70.166 14.46,36.13 32.432,63.635 39.104,61.014 6.672,-2.621 -0.483,-34.376 -14.943,-70.506 m 20.999,72.506 c -16.442,8.934 -36.644,-24.449 -53.276,-63.334 -16.633,-38.885 -18.542,-70.229 -5.759,-75.836 17.092,-7.496 33.127,22.285 49.759,61.17 16.632,38.885 24,70 9.276,78" /><path
140
+ inkscape:connector-curvature="0"
141
+ id="path102"
142
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
143
+ d="m 159.52163,189.668 c 0,0 10.331,-31.037 62,-24.666 48.667,6 69.59,24.744 99.333,43.334 21.334,13.332 20,7.332 22.667,6.666 2.667,-0.666 14.667,-8 27.333,-6.666 0.667,-6.668 -5.999,-1.334 -8.666,-7.334 -1.333,-4 10.12,-22.824 26.666,-20 27.334,4.666 19.667,16 25.001,28.666 5.333,12.666 9,19.334 -17.667,37.334 -20.667,18.666 -32,13.999 -42,13.999 -10,0 -36,-13.999 -54,-10.666 -18,3.333 -29.334,10 -29.334,10 l -11.999,-13.333 c 0,0 21.999,-16.666 47.333,-10.666 25.333,6 44.001,25.332 66.001,15.332 22,-10 26.282,-16.701 32.999,-21.666 7.667,-5.668 8.333,-11.666 3,-17 -5.334,-5.334 0.001,-9.334 -3.332,-15.334 -3.334,-6 -20,-8.666 -20,-8.666 0,0 18.273,23.477 -4,25.332 -16,1.334 -26,22.668 -48.667,11.334 -32.55,-16.277 -78.668,-44 -110.668,-47.332 -31.193,-3.248 -42.667,6.666 -50.667,25.332 -9.333,-8 -11.333,-14 -11.333,-14" /><path
144
+ inkscape:connector-curvature="0"
145
+ id="path106"
146
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
147
+ d="m 274.18863,183.002 c 0,0 22.667,-12 16,-38 -6.667,-26 -36.667,-44 -56,-52.668 -19.333,-8.666 -33.743,-20.127 -19.333,-27.332 12,-6 18.667,9.334 36,12 17.333,2.666 32.667,-4 34,-14 -7.334,4 -12.667,4 -12.667,4 0,0 6,-4 6.667,-10.668 0.666,-6.666 -0.667,-3.332 -4.667,-3.332 -10,0 -11.333,8.666 -20,7.332 -22,-2 -23.333,-11.334 -35.333,-12.666 -12,-1.334 -32,5.334 -29.334,20.666 2.667,15.334 23.334,26 42.667,34 19.333,8 48.667,33.334 44.667,56 -4,22.668 -21.334,18 -21.334,18 l 18.667,6.668 z" /><path
148
+ inkscape:connector-curvature="0"
149
+ id="path110"
150
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
151
+ d="m 331.02213,371.7515 c 0,0 9.5,-4.75 15.5,-28.75 4,-8.667 9.333,-15.667 14,-17.667 4.667,-2 -2,-4 -5.333,-3.333 -3.334,0.667 -10.334,3.667 -15,-0.333 -4.667,-4 -16,-14.667 -32,-12 -16,2.666 -29.667,12.833 -29.667,12.833 0,0 6,-26.5 41.667,-24.833 24.721,1.155 19.333,14 36,16.666 16.666,2.667 14.893,11.089 11.333,18 -5.667,11 -23.333,13.667 -25.333,45.834 -2,3.333 -14.5,-0.417 -11.167,-6.417" /><path
152
+ inkscape:connector-curvature="0"
153
+ id="path114"
154
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
155
+ d="m 388.01383,204.4707 c 1.506,-1.477 -11.825,-31.469 -11.825,-31.469 0,0 -2.667,-7.334 -9.814,-4.75 -7.311,2.645 -5.413,7.948 -5.413,7.948 l 17.026,30.837 c 0,0 9.353,-1.906 10.026,-2.566" /><path
156
+ inkscape:connector-curvature="0"
157
+ id="path118"
158
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
159
+ d="m 406.74623,247.168 c -0.667,-2 -3.333,-10 -3.333,-10 l -10.891,8.334 2.891,6.332 11.333,-4.666 z" /><path
160
+ inkscape:connector-curvature="0"
161
+ id="path122"
162
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
163
+ d="m 284.85563,189.002 c -2,-7.334 23.333,-50.002 40.667,-47.334 17.333,2.666 19.999,-2.668 14.666,-6 -5.333,-3.334 -14.666,-4.668 -13.333,-9.334 1.333,-4.666 5,-9.334 -3.667,-8 -8.666,1.334 -26.333,10.668 -37,28.668 -3.333,-10.668 -4.666,-14 -4.666,-14 0,0 34,-35.334 68.666,-20.668 -6,4.668 -22.666,3.334 -8.666,11.334 14,8 24.666,10.666 31.333,-2 3.333,0.666 3.333,30 -40.667,28 -15.333,2 -36,32 -36,47.334 -4,-4 -9.333,-0.666 -11.333,-8" /><path
164
+ inkscape:connector-curvature="0"
165
+ id="path126"
166
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
167
+ d="m 420.44553,336.5015 c 0,0 -8.75,-26.286 -5.104,-48 0.729,6.857 5.104,48 5.104,48" /><path
168
+ inkscape:connector-curvature="0"
169
+ id="path130"
170
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
171
+ d="m 429.40543,352.0503 c -0.444,1.66 -4.07,-45.761 -3.203,-47.435 0.868,-1.673 5.909,37.339 3.203,47.435" /><path
172
+ inkscape:connector-curvature="0"
173
+ id="path134"
174
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
175
+ d="m 312.85513,378.335 c 0,0 37.667,3.333 31,18.333 -20.105,45.239 -58.333,71.667 -129,69 40,16 74.00021,14.00025 106.667,-14 16.33311,-13.99988 23.89324,-31.04069 29.74979,-44.08296 9.34044,-20.80074 6.58914,-22.74696 -3.74979,-28.58304 -12.56847,-7.0946 -34.191,-2.57 -34.667,-0.667"
176
+ sodipodi:nodetypes="cccsssc" /><path
177
+ inkscape:connector-curvature="0"
178
+ id="path138"
179
+ style="fill:#2d2b2c;fill-opacity:1;fill-rule:nonzero;stroke:none"
180
+ d="m 316.7084,372.58242 c 0,0 10.36415,-7.13802 18.50215,-1.32602 3.74086,3.84884 6.23323,5.95026 -4.37137,5.51213 l -12.90479,0.52875 c -8.94116,1.82452 -8.7647,-0.93753 -1.22599,-4.71486 z"
181
+ sodipodi:nodetypes="ccccc" /></g></svg>
@@ -0,0 +1,3327 @@
1
+ <!doctype html>
2
+
3
+ <title>CodeMirror: User Manual</title>
4
+ <meta charset="utf-8"/>
5
+ <link rel=stylesheet href="docs.css">
6
+ <script src="activebookmark.js"></script>
7
+
8
+ <script src="../lib/codemirror.js"></script>
9
+ <link rel="stylesheet" href="../lib/codemirror.css">
10
+ <script src="../addon/runmode/runmode.js"></script>
11
+ <script src="../addon/runmode/colorize.js"></script>
12
+ <script src="../mode/javascript/javascript.js"></script>
13
+ <script src="../mode/xml/xml.js"></script>
14
+ <script src="../mode/css/css.js"></script>
15
+ <script src="../mode/htmlmixed/htmlmixed.js"></script>
16
+ <style>
17
+ dt { text-indent: -2em; padding-left: 2em; margin-top: 1em; }
18
+ dd { margin-left: 1.5em; margin-bottom: 1em; }
19
+ dt {margin-top: 1em;}
20
+ dd dl, dd dt, dd dd, dd ul { margin-top: 0; margin-bottom: 0; }
21
+ dt + dt { margin-top: 0; }
22
+ dt.command { position: relative; }
23
+ span.keybinding { position: absolute; right: 0; font-size: 80%; color: #555; text-indent: 0; }
24
+ </style>
25
+
26
+ <div id=nav>
27
+ <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="logo.png"></a>
28
+ <ul>
29
+ <li><a href="../index.html">Home</a></li>
30
+ <li><a href="#overview" class=active data-default="true">Manual</a></li>
31
+ <li><a href="https://github.com/codemirror/codemirror">Code</a></li>
32
+ </ul>
33
+ <ul>
34
+ <li><a href="#usage">Basic Usage</a></li>
35
+ <li><a href="#config">Configuration</a></li>
36
+ <li><a href="#events">Events</a></li>
37
+ <li><a href="#keymaps">Key maps</a></li>
38
+ <li><a href="#commands">Commands</a></li>
39
+ <li><a href="#styling">Customized Styling</a></li>
40
+ <li><a href="#api">Programming API</a>
41
+ <ul>
42
+ <li><a href="#api_constructor">Constructor</a></li>
43
+ <li><a href="#api_content">Content manipulation</a></li>
44
+ <li><a href="#api_selection">Selection</a></li>
45
+ <li><a href="#api_configuration">Configuration</a></li>
46
+ <li><a href="#api_doc">Document management</a></li>
47
+ <li><a href="#api_history">History</a></li>
48
+ <li><a href="#api_marker">Text-marking</a></li>
49
+ <li><a href="#api_decoration">Widget, gutter, and decoration</a></li>
50
+ <li><a href="#api_sizing">Sizing, scrolling, and positioning</a></li>
51
+ <li><a href="#api_mode">Mode, state, and tokens</a></li>
52
+ <li><a href="#api_misc">Miscellaneous methods</a></li>
53
+ <li><a href="#api_static">Static properties</a></li>
54
+ </ul>
55
+ </li>
56
+ <li><a href="#addons">Addons</a></li>
57
+ <li><a href="#modeapi">Writing CodeMirror Modes</a></li>
58
+ <li><a href="#vimapi">Vim Mode API</a>
59
+ <ul>
60
+ <li><a href="#vimapi_configuration">Configuration</a></li>
61
+ <li><a href="#vimapi_extending">Extending VIM</a></li>
62
+ </ul>
63
+ </li>
64
+ </ul>
65
+ </div>
66
+
67
+ <article>
68
+
69
+ <section class=first id=overview>
70
+ <h2 style="position: relative">
71
+ User manual and reference guide
72
+ <span style="color: #888; font-size: 1rem; position: absolute; right: 0; bottom: 0">version 5.5.0</span>
73
+ </h2>
74
+
75
+ <p>CodeMirror is a code-editor component that can be embedded in
76
+ Web pages. The core library provides <em>only</em> the editor
77
+ component, no accompanying buttons, auto-completion, or other IDE
78
+ functionality. It does provide a rich API on top of which such
79
+ functionality can be straightforwardly implemented. See
80
+ the <a href="#addons">addons</a> included in the distribution,
81
+ and the <a href="https://github.com/codemirror/CodeMirror/wiki/CodeMirror-addons">list
82
+ of externally hosted addons</a>, for reusable
83
+ implementations of extra features.</p>
84
+
85
+ <p>CodeMirror works with language-specific modes. Modes are
86
+ JavaScript programs that help color (and optionally indent) text
87
+ written in a given language. The distribution comes with a number
88
+ of modes (see the <a href="../mode/"><code>mode/</code></a>
89
+ directory), and it isn't hard to <a href="#modeapi">write new
90
+ ones</a> for other languages.</p>
91
+ </section>
92
+
93
+ <section id=usage>
94
+ <h2>Basic Usage</h2>
95
+
96
+ <p>The easiest way to use CodeMirror is to simply load the script
97
+ and style sheet found under <code>lib/</code> in the distribution,
98
+ plus a mode script from one of the <code>mode/</code> directories.
99
+ (See <a href="compress.html">the compression helper</a> for an
100
+ easy way to combine scripts.) For example:</p>
101
+
102
+ <pre data-lang="text/html">&lt;script src="lib/codemirror.js">&lt;/script>
103
+ &lt;link rel="stylesheet" href="../lib/codemirror.css">
104
+ &lt;script src="mode/javascript/javascript.js">&lt;/script></pre>
105
+
106
+ <p>(Alternatively, use a module loader. <a href="#modloader">More
107
+ about that later.</a>)</p>
108
+
109
+ <p>Having done this, an editor instance can be created like
110
+ this:</p>
111
+
112
+ <pre data-lang="javascript">var myCodeMirror = CodeMirror(document.body);</pre>
113
+
114
+ <p>The editor will be appended to the document body, will start
115
+ empty, and will use the mode that we loaded. To have more control
116
+ over the new editor, a configuration object can be passed
117
+ to <a href="#CodeMirror"><code>CodeMirror</code></a> as a second
118
+ argument:</p>
119
+
120
+ <pre data-lang="javascript">var myCodeMirror = CodeMirror(document.body, {
121
+ value: "function myScript(){return 100;}\n",
122
+ mode: "javascript"
123
+ });</pre>
124
+
125
+ <p>This will initialize the editor with a piece of code already in
126
+ it, and explicitly tell it to use the JavaScript mode (which is
127
+ useful when multiple modes are loaded).
128
+ See <a href="#config">below</a> for a full discussion of the
129
+ configuration options that CodeMirror accepts.</p>
130
+
131
+ <p>In cases where you don't want to append the editor to an
132
+ element, and need more control over the way it is inserted, the
133
+ first argument to the <code>CodeMirror</code> function can also
134
+ be a function that, when given a DOM element, inserts it into the
135
+ document somewhere. This could be used to, for example, replace a
136
+ textarea with a real editor:</p>
137
+
138
+ <pre data-lang="javascript">var myCodeMirror = CodeMirror(function(elt) {
139
+ myTextArea.parentNode.replaceChild(elt, myTextArea);
140
+ }, {value: myTextArea.value});</pre>
141
+
142
+ <p>However, for this use case, which is a common way to use
143
+ CodeMirror, the library provides a much more powerful
144
+ shortcut:</p>
145
+
146
+ <pre data-lang="javascript">var myCodeMirror = CodeMirror.fromTextArea(myTextArea);</pre>
147
+
148
+ <p>This will, among other things, ensure that the textarea's value
149
+ is updated with the editor's contents when the form (if it is part
150
+ of a form) is submitted. See the <a href="#fromTextArea">API
151
+ reference</a> for a full description of this method.</p>
152
+
153
+ <h3 id=modloader>Module loaders</h3>
154
+
155
+ <p>The files in the CodeMirror distribution contain shims for
156
+ loading them (and their dependencies) in AMD or CommonJS
157
+ environments. If the variables <code>exports</code>
158
+ and <code>module</code> exist and have type object, CommonJS-style
159
+ require will be used. If not, but there is a
160
+ function <code>define</code> with an <code>amd</code> property
161
+ present, AMD-style (RequireJS) will be used.</p>
162
+
163
+ <p>It is possible to
164
+ use <a href="http://browserify.org/">Browserify</a> or similar
165
+ tools to statically build modules using CodeMirror. Alternatively,
166
+ use <a href="http://requirejs.org/">RequireJS</a> to dynamically
167
+ load dependencies at runtime. Both of these approaches have the
168
+ advantage that they don't use the global namespace and can, thus,
169
+ do things like load multiple versions of CodeMirror alongside each
170
+ other.</p>
171
+
172
+ <p>Here's a simple example of using RequireJS to load CodeMirror:</p>
173
+
174
+ <pre data-lang="javascript">require([
175
+ "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
176
+ ], function(CodeMirror) {
177
+ CodeMirror.fromTextArea(document.getElementById("code"), {
178
+ lineNumbers: true,
179
+ mode: "htmlmixed"
180
+ });
181
+ });</pre>
182
+
183
+ <p>It will automatically load the modes that the mixed HTML mode
184
+ depends on (XML, JavaScript, and CSS). Do <em>not</em> use
185
+ RequireJS' <code>paths</code> option to configure the path to
186
+ CodeMirror, since it will break loading submodules through
187
+ relative paths. Use
188
+ the <a href="http://requirejs.org/docs/api.html#packages"><code>packages</code></a>
189
+ configuration option instead, as in:</p>
190
+
191
+ <pre data-lang=javascript>require.config({
192
+ packages: [{
193
+ name: "codemirror",
194
+ location: "../path/to/codemirror",
195
+ main: "lib/codemirror"
196
+ }]
197
+ });</pre>
198
+
199
+ </section>
200
+
201
+ <section id=config>
202
+ <h2>Configuration</h2>
203
+
204
+ <p>Both the <a href="#CodeMirror"><code>CodeMirror</code></a>
205
+ function and its <code>fromTextArea</code> method take as second
206
+ (optional) argument an object containing configuration options.
207
+ Any option not supplied like this will be taken
208
+ from <a href="#defaults"><code>CodeMirror.defaults</code></a>, an
209
+ object containing the default options. You can update this object
210
+ to change the defaults on your page.</p>
211
+
212
+ <p>Options are not checked in any way, so setting bogus option
213
+ values is bound to lead to odd errors.</p>
214
+
215
+ <p>These are the supported options:</p>
216
+
217
+ <dl>
218
+ <dt id="option_value"><code><strong>value</strong>: string|CodeMirror.Doc</code></dt>
219
+ <dd>The starting value of the editor. Can be a string, or
220
+ a <a href="#api_doc">document object</a>.</dd>
221
+
222
+ <dt id="option_mode"><code><strong>mode</strong>: string|object</code></dt>
223
+ <dd>The mode to use. When not given, this will default to the
224
+ first mode that was loaded. It may be a string, which either
225
+ simply names the mode or is
226
+ a <a href="http://en.wikipedia.org/wiki/MIME">MIME</a> type
227
+ associated with the mode. Alternatively, it may be an object
228
+ containing configuration options for the mode, with
229
+ a <code>name</code> property that names the mode (for
230
+ example <code>{name: "javascript", json: true}</code>). The demo
231
+ pages for each mode contain information about what configuration
232
+ parameters the mode supports. You can ask CodeMirror which modes
233
+ and MIME types have been defined by inspecting
234
+ the <code>CodeMirror.modes</code>
235
+ and <code>CodeMirror.mimeModes</code> objects. The first maps
236
+ mode names to their constructors, and the second maps MIME types
237
+ to mode specs.</dd>
238
+
239
+ <dt id="option_lineSeparator"><code><strong>lineSeparator</strong>: string|null</code></dt>
240
+ <dd>Explicitly set the line separator for the editor. By default
241
+ (value <code>null</code>), the document will be split on CRLFs
242
+ as well as lone CRs and LFs, and a single LF will be used as
243
+ line separator in all output (such
244
+ as <a href="#getValue"><code>getValue</code></a>). When a
245
+ specific string is given, lines will only be split on that
246
+ string, and output will, by default, use that same
247
+ separator.</dd>
248
+
249
+ <dt id="option_theme"><code><strong>theme</strong>: string</code></dt>
250
+ <dd>The theme to style the editor with. You must make sure the
251
+ CSS file defining the corresponding <code>.cm-s-[name]</code>
252
+ styles is loaded (see
253
+ the <a href="../theme/"><code>theme</code></a> directory in the
254
+ distribution). The default is <code>"default"</code>, for which
255
+ colors are included in <code>codemirror.css</code>. It is
256
+ possible to use multiple theming classes at once—for
257
+ example <code>"foo bar"</code> will assign both
258
+ the <code>cm-s-foo</code> and the <code>cm-s-bar</code> classes
259
+ to the editor.</dd>
260
+
261
+ <dt id="option_indentUnit"><code><strong>indentUnit</strong>: integer</code></dt>
262
+ <dd>How many spaces a block (whatever that means in the edited
263
+ language) should be indented. The default is 2.</dd>
264
+
265
+ <dt id="option_smartIndent"><code><strong>smartIndent</strong>: boolean</code></dt>
266
+ <dd>Whether to use the context-sensitive indentation that the
267
+ mode provides (or just indent the same as the line before).
268
+ Defaults to true.</dd>
269
+
270
+ <dt id="option_tabSize"><code><strong>tabSize</strong>: integer</code></dt>
271
+ <dd>The width of a tab character. Defaults to 4.</dd>
272
+
273
+ <dt id="option_indentWithTabs"><code><strong>indentWithTabs</strong>: boolean</code></dt>
274
+ <dd>Whether, when indenting, the first N*<code>tabSize</code>
275
+ spaces should be replaced by N tabs. Default is false.</dd>
276
+
277
+ <dt id="option_electricChars"><code><strong>electricChars</strong>: boolean</code></dt>
278
+ <dd>Configures whether the editor should re-indent the current
279
+ line when a character is typed that might change its proper
280
+ indentation (only works if the mode supports indentation).
281
+ Default is true.</dd>
282
+
283
+ <dt id="option_specialChars"><code><strong>specialChars</strong>: RegExp</code></dt>
284
+ <dd>A regular expression used to determine which characters
285
+ should be replaced by a
286
+ special <a href="#option_specialCharPlaceholder">placeholder</a>.
287
+ Mostly useful for non-printing special characters. The default
288
+ is <code>/[\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/</code>.</dd>
289
+ <dt id="option_specialCharPlaceholder"><code><strong>specialCharPlaceholder</strong>: function(char) → Element</code></dt>
290
+ <dd>A function that, given a special character identified by
291
+ the <a href="#option_specialChars"><code>specialChars</code></a>
292
+ option, produces a DOM node that is used to represent the
293
+ character. By default, a red dot (<span style="color: red">•</span>)
294
+ is shown, with a title tooltip to indicate the character code.</dd>
295
+
296
+ <dt id="option_rtlMoveVisually"><code><strong>rtlMoveVisually</strong>: boolean</code></dt>
297
+ <dd>Determines whether horizontal cursor movement through
298
+ right-to-left (Arabic, Hebrew) text is visual (pressing the left
299
+ arrow moves the cursor left) or logical (pressing the left arrow
300
+ moves to the next lower index in the string, which is visually
301
+ right in right-to-left text). The default is <code>false</code>
302
+ on Windows, and <code>true</code> on other platforms.</dd>
303
+
304
+ <dt id="option_keyMap"><code><strong>keyMap</strong>: string</code></dt>
305
+ <dd>Configures the key map to use. The default
306
+ is <code>"default"</code>, which is the only key map defined
307
+ in <code>codemirror.js</code> itself. Extra key maps are found in
308
+ the <a href="../keymap/"><code>key map</code></a> directory. See
309
+ the <a href="#keymaps">section on key maps</a> for more
310
+ information.</dd>
311
+
312
+ <dt id="option_extraKeys"><code><strong>extraKeys</strong>: object</code></dt>
313
+ <dd>Can be used to specify extra key bindings for the editor,
314
+ alongside the ones defined
315
+ by <a href="#option_keyMap"><code>keyMap</code></a>. Should be
316
+ either null, or a valid <a href="#keymaps">key map</a> value.</dd>
317
+
318
+ <dt id="option_lineWrapping"><code><strong>lineWrapping</strong>: boolean</code></dt>
319
+ <dd>Whether CodeMirror should scroll or wrap for long lines.
320
+ Defaults to <code>false</code> (scroll).</dd>
321
+
322
+ <dt id="option_lineNumbers"><code><strong>lineNumbers</strong>: boolean</code></dt>
323
+ <dd>Whether to show line numbers to the left of the editor.</dd>
324
+
325
+ <dt id="option_firstLineNumber"><code><strong>firstLineNumber</strong>: integer</code></dt>
326
+ <dd>At which number to start counting lines. Default is 1.</dd>
327
+
328
+ <dt id="option_lineNumberFormatter"><code><strong>lineNumberFormatter</strong>: function(line: integer) → string</code></dt>
329
+ <dd>A function used to format line numbers. The function is
330
+ passed the line number, and should return a string that will be
331
+ shown in the gutter.</dd>
332
+
333
+ <dt id="option_gutters"><code><strong>gutters</strong>: array&lt;string&gt;</code></dt>
334
+ <dd>Can be used to add extra gutters (beyond or instead of the
335
+ line number gutter). Should be an array of CSS class names, each
336
+ of which defines a <code>width</code> (and optionally a
337
+ background), and which will be used to draw the background of
338
+ the gutters. <em>May</em> include
339
+ the <code>CodeMirror-linenumbers</code> class, in order to
340
+ explicitly set the position of the line number gutter (it will
341
+ default to be to the right of all other gutters). These class
342
+ names are the keys passed
343
+ to <a href="#setGutterMarker"><code>setGutterMarker</code></a>.</dd>
344
+
345
+ <dt id="option_fixedGutter"><code><strong>fixedGutter</strong>: boolean</code></dt>
346
+ <dd>Determines whether the gutter scrolls along with the content
347
+ horizontally (false) or whether it stays fixed during horizontal
348
+ scrolling (true, the default).</dd>
349
+
350
+ <dt id="option_scrollbarStyle"><code><strong>scrollbarStyle</strong>: string</code></dt>
351
+ <dd>Chooses a scrollbar implementation. The default
352
+ is <code>"native"</code>, showing native scrollbars. The core
353
+ library also provides the <code>"null"</code> style, which
354
+ completely hides the
355
+ scrollbars. <a href="#addon_simplescrollbars">Addons</a> can
356
+ implement additional scrollbar models.</dd>
357
+
358
+ <dt id="option_coverGutterNextToScrollbar"><code><strong>coverGutterNextToScrollbar</strong>: boolean</code></dt>
359
+ <dd>When <a href="#option_fixedGutter"><code>fixedGutter</code></a>
360
+ is on, and there is a horizontal scrollbar, by default the
361
+ gutter will be visible to the left of this scrollbar. If this
362
+ option is set to true, it will be covered by an element with
363
+ class <code>CodeMirror-gutter-filler</code>.</dd>
364
+
365
+ <dt id="option_inputStyle"><code><strong>inputStyle</strong>: string</code></dt>
366
+ <dd>Selects the way CodeMirror handles input and focus. The core
367
+ library defines the <code>"textarea"</code>
368
+ and <code>"contenteditable"</code> input models. On mobile
369
+ browsers, the default is <code>"contenteditable"</code>. On
370
+ desktop browsers, the default is <code>"textarea"</code>.
371
+ Support for IME and screen readers is better in
372
+ the <code>"contenteditable"</code> model. The intention is to
373
+ make it the default on modern desktop browsers in the
374
+ future.</dd>
375
+
376
+ <dt id="option_readOnly"><code><strong>readOnly</strong>: boolean|string</code></dt>
377
+ <dd>This disables editing of the editor content by the user. If
378
+ the special value <code>"nocursor"</code> is given (instead of
379
+ simply <code>true</code>), focusing of the editor is also
380
+ disallowed.</dd>
381
+
382
+ <dt id="option_showCursorWhenSelecting"><code><strong>showCursorWhenSelecting</strong>: boolean</code></dt>
383
+ <dd>Whether the cursor should be drawn when a selection is
384
+ active. Defaults to false.</dd>
385
+
386
+ <dt id="option_lineWiseCopyCut"><code><strong>lineWiseCopyCut</strong>: boolean</code></dt>
387
+ <dd>When enabled, which is the default, doing copy or cut when
388
+ there is no selection will copy or cut the whole lines that have
389
+ cursors on them.</dd>
390
+
391
+ <dt id="option_undoDepth"><code><strong>undoDepth</strong>: integer</code></dt>
392
+ <dd>The maximum number of undo levels that the editor stores.
393
+ Note that this includes selection change events. Defaults to
394
+ 200.</dd>
395
+
396
+ <dt id="option_historyEventDelay"><code><strong>historyEventDelay</strong>: integer</code></dt>
397
+ <dd>The period of inactivity (in milliseconds) that will cause a
398
+ new history event to be started when typing or deleting.
399
+ Defaults to 1250.</dd>
400
+
401
+ <dt id="option_tabindex"><code><strong>tabindex</strong>: integer</code></dt>
402
+ <dd>The <a href="http://www.w3.org/TR/html401/interact/forms.html#adef-tabindex">tab
403
+ index</a> to assign to the editor. If not given, no tab index
404
+ will be assigned.</dd>
405
+
406
+ <dt id="option_autofocus"><code><strong>autofocus</strong>: boolean</code></dt>
407
+ <dd>Can be used to make CodeMirror focus itself on
408
+ initialization. Defaults to off.
409
+ When <a href="#fromTextArea"><code>fromTextArea</code></a> is
410
+ used, and no explicit value is given for this option, it will be
411
+ set to true when either the source textarea is focused, or it
412
+ has an <code>autofocus</code> attribute and no other element is
413
+ focused.</dd>
414
+ </dl>
415
+
416
+ <p>Below this a few more specialized, low-level options are
417
+ listed. These are only useful in very specific situations, you
418
+ might want to skip them the first time you read this manual.</p>
419
+
420
+ <dl>
421
+ <dt id="option_dragDrop"><code><strong>dragDrop</strong>: boolean</code></dt>
422
+ <dd>Controls whether drag-and-drop is enabled. On by default.</dd>
423
+
424
+ <dt id="option_cursorBlinkRate"><code><strong>cursorBlinkRate</strong>: number</code></dt>
425
+ <dd>Half-period in milliseconds used for cursor blinking. The default blink
426
+ rate is 530ms. By setting this to zero, blinking can be disabled. A
427
+ negative value hides the cursor entirely.</dd>
428
+
429
+ <dt id="option_cursorScrollMargin"><code><strong>cursorScrollMargin</strong>: number</code></dt>
430
+ <dd>How much extra space to always keep above and below the
431
+ cursor when approaching the top or bottom of the visible view in
432
+ a scrollable document. Default is 0.</dd>
433
+
434
+ <dt id="option_cursorHeight"><code><strong>cursorHeight</strong>: number</code></dt>
435
+ <dd>Determines the height of the cursor. Default is 1, meaning
436
+ it spans the whole height of the line. For some fonts (and by
437
+ some tastes) a smaller height (for example <code>0.85</code>),
438
+ which causes the cursor to not reach all the way to the bottom
439
+ of the line, looks better</dd>
440
+
441
+ <dt id="option_resetSelectionOnContextMenu"><code><strong>resetSelectionOnContextMenu</strong>: boolean</code></dt>
442
+ <dd>Controls whether, when the context menu is opened with a
443
+ click outside of the current selection, the cursor is moved to
444
+ the point of the click. Defaults to <code>true</code>.</dd>
445
+
446
+ <dt id="option_workTime"><code id="option_wordkDelay"><strong>workTime</strong>, <strong>workDelay</strong>: number</code></dt>
447
+ <dd>Highlighting is done by a pseudo background-thread that will
448
+ work for <code>workTime</code> milliseconds, and then use
449
+ timeout to sleep for <code>workDelay</code> milliseconds. The
450
+ defaults are 200 and 300, you can change these options to make
451
+ the highlighting more or less aggressive.</dd>
452
+
453
+ <dt id="option_pollInterval"><code><strong>pollInterval</strong>: number</code></dt>
454
+ <dd>Indicates how quickly CodeMirror should poll its input
455
+ textarea for changes (when focused). Most input is captured by
456
+ events, but some things, like IME input on some browsers, don't
457
+ generate events that allow CodeMirror to properly detect it.
458
+ Thus, it polls. Default is 100 milliseconds.</dd>
459
+
460
+ <dt id="option_flattenSpans"><code><strong>flattenSpans</strong>: boolean</code></dt>
461
+ <dd>By default, CodeMirror will combine adjacent tokens into a
462
+ single span if they have the same class. This will result in a
463
+ simpler DOM tree, and thus perform better. With some kinds of
464
+ styling (such as rounded corners), this will change the way the
465
+ document looks. You can set this option to false to disable this
466
+ behavior.</dd>
467
+
468
+ <dt id="option_addModeClass"><code><strong>addModeClass</strong>: boolean</code></dt>
469
+ <dd>When enabled (off by default), an extra CSS class will be
470
+ added to each token, indicating the
471
+ (<a href="#innerMode">inner</a>) mode that produced it, prefixed
472
+ with <code>"cm-m-"</code>. For example, tokens from the XML mode
473
+ will get the <code>cm-m-xml</code> class.</dd>
474
+
475
+ <dt id="option_maxHighlightLength"><code><strong>maxHighlightLength</strong>: number</code></dt>
476
+ <dd>When highlighting long lines, in order to stay responsive,
477
+ the editor will give up and simply style the rest of the line as
478
+ plain text when it reaches a certain position. The default is
479
+ 10 000. You can set this to <code>Infinity</code> to turn off
480
+ this behavior.</dd>
481
+
482
+ <dt id="option_viewportMargin"><code><strong>viewportMargin</strong>: integer</code></dt>
483
+ <dd>Specifies the amount of lines that are rendered above and
484
+ below the part of the document that's currently scrolled into
485
+ view. This affects the amount of updates needed when scrolling,
486
+ and the amount of work that such an update does. You should
487
+ usually leave it at its default, 10. Can be set
488
+ to <code>Infinity</code> to make sure the whole document is
489
+ always rendered, and thus the browser's text search works on it.
490
+ This <em>will</em> have bad effects on performance of big
491
+ documents.</dd>
492
+ </dl>
493
+ </section>
494
+
495
+ <section id=events>
496
+ <h2>Events</h2>
497
+
498
+ <p>Various CodeMirror-related objects emit events, which allow
499
+ client code to react to various situations. Handlers for such
500
+ events can be registered with the <a href="#on"><code>on</code></a>
501
+ and <a href="#off"><code>off</code></a> methods on the objects
502
+ that the event fires on. To fire your own events,
503
+ use <code>CodeMirror.signal(target, name, args...)</code>,
504
+ where <code>target</code> is a non-DOM-node object.</p>
505
+
506
+ <p>An editor instance fires the following events.
507
+ The <code>instance</code> argument always refers to the editor
508
+ itself.</p>
509
+
510
+ <dl>
511
+ <dt id="event_change"><code><strong>"change"</strong> (instance: CodeMirror, changeObj: object)</code></dt>
512
+ <dd>Fires every time the content of the editor is changed.
513
+ The <code>changeObj</code> is a <code>{from, to, text, removed,
514
+ origin}</code> object containing information about the changes
515
+ that occurred as second argument. <code>from</code>
516
+ and <code>to</code> are the positions (in the pre-change
517
+ coordinate system) where the change started and ended (for
518
+ example, it might be <code>{ch:0, line:18}</code> if the
519
+ position is at the beginning of line #19). <code>text</code> is
520
+ an array of strings representing the text that replaced the
521
+ changed range (split by line). <code>removed</code> is the text
522
+ that used to be between <code>from</code> and <code>to</code>,
523
+ which is overwritten by this change. This event is
524
+ fired <em>before</em> the end of
525
+ an <a href="#operation">operation</a>, before the DOM updates
526
+ happen.</dd>
527
+
528
+ <dt id="event_changes"><code><strong>"changes"</strong> (instance: CodeMirror, changes: array&lt;object&gt;)</code></dt>
529
+ <dd>Like the <a href="#event_change"><code>"change"</code></a>
530
+ event, but batched per <a href="#operation">operation</a>,
531
+ passing an array containing all the changes that happened in the
532
+ operation. This event is fired after the operation finished, and
533
+ display changes it makes will trigger a new operation.</dd>
534
+
535
+ <dt id="event_beforeChange"><code><strong>"beforeChange"</strong> (instance: CodeMirror, changeObj: object)</code></dt>
536
+ <dd>This event is fired before a change is applied, and its
537
+ handler may choose to modify or cancel the change.
538
+ The <code>changeObj</code> object
539
+ has <code>from</code>, <code>to</code>, and <code>text</code>
540
+ properties, as with
541
+ the <a href="#event_change"><code>"change"</code></a> event. It
542
+ also has a <code>cancel()</code> method, which can be called to
543
+ cancel the change, and, <strong>if</strong> the change isn't
544
+ coming from an undo or redo event, an <code>update(from, to,
545
+ text)</code> method, which may be used to modify the change.
546
+ Undo or redo changes can't be modified, because they hold some
547
+ metainformation for restoring old marked ranges that is only
548
+ valid for that specific change. All three arguments
549
+ to <code>update</code> are optional, and can be left off to
550
+ leave the existing value for that field
551
+ intact. <strong>Note:</strong> you may not do anything from
552
+ a <code>"beforeChange"</code> handler that would cause changes
553
+ to the document or its visualization. Doing so will, since this
554
+ handler is called directly from the bowels of the CodeMirror
555
+ implementation, probably cause the editor to become
556
+ corrupted.</dd>
557
+
558
+ <dt id="event_cursorActivity"><code><strong>"cursorActivity"</strong> (instance: CodeMirror)</code></dt>
559
+ <dd>Will be fired when the cursor or selection moves, or any
560
+ change is made to the editor content.</dd>
561
+
562
+ <dt id="event_keyHandled"><code><strong>"keyHandled"</strong> (instance: CodeMirror, name: string, event: Event)</code></dt>
563
+ <dd>Fired after a key is handled through a
564
+ key map. <code>name</code> is the name of the handled key (for
565
+ example <code>"Ctrl-X"</code> or <code>"'q'"</code>),
566
+ and <code>event</code> is the DOM <code>keydown</code>
567
+ or <code>keypress</code> event.</dd>
568
+
569
+ <dt id="event_inputRead"><code><strong>"inputRead"</strong> (instance: CodeMirror, changeObj: object)</code></dt>
570
+ <dd>Fired whenever new input is read from the hidden textarea
571
+ (typed or pasted by the user).</dd>
572
+
573
+ <dt id="event_electricInput"><code><strong>"electrictInput"</strong> (instance: CodeMirror, line: integer)</code></dt>
574
+ <dd>Fired if text input matched the
575
+ mode's <a href="#option_electricChars">electric</a> patterns,
576
+ and this caused the line's indentation to change.</dd>
577
+
578
+ <dt id="event_beforeSelectionChange"><code><strong>"beforeSelectionChange"</strong> (instance: CodeMirror, obj: {ranges, update})</code></dt>
579
+ <dd>This event is fired before the selection is moved. Its
580
+ handler may inspect the set of selection ranges, present as an
581
+ array of <code>{anchor, head}</code> objects in
582
+ the <code>ranges</code> property of the <code>obj</code>
583
+ argument, and optionally change them by calling
584
+ the <code>update</code> method on this object, passing an array
585
+ of ranges in the same format. Handlers for this event have the
586
+ same restriction
587
+ as <a href="#event_beforeChange"><code>"beforeChange"</code></a>
588
+ handlers — they should not do anything to directly update the
589
+ state of the editor.</dd>
590
+
591
+ <dt id="event_viewportChange"><code><strong>"viewportChange"</strong> (instance: CodeMirror, from: number, to: number)</code></dt>
592
+ <dd>Fires whenever the <a href="#getViewport">view port</a> of
593
+ the editor changes (due to scrolling, editing, or any other
594
+ factor). The <code>from</code> and <code>to</code> arguments
595
+ give the new start and end of the viewport.</dd>
596
+
597
+ <dt id="event_swapDoc"><code><strong>"swapDoc"</strong> (instance: CodeMirror, oldDoc: Doc)</code></dt>
598
+ <dd>This is signalled when the editor's document is replaced
599
+ using the <a href="#swapDoc"><code>swapDoc</code></a>
600
+ method.</dd>
601
+
602
+ <dt id="event_gutterClick"><code><strong>"gutterClick"</strong> (instance: CodeMirror, line: integer, gutter: string, clickEvent: Event)</code></dt>
603
+ <dd>Fires when the editor gutter (the line-number area) is
604
+ clicked. Will pass the editor instance as first argument, the
605
+ (zero-based) number of the line that was clicked as second
606
+ argument, the CSS class of the gutter that was clicked as third
607
+ argument, and the raw <code>mousedown</code> event object as
608
+ fourth argument.</dd>
609
+
610
+ <dt id="event_gutterContextMenu"><code><strong>"gutterContextMenu"</strong> (instance: CodeMirror, line: integer, gutter: string, contextMenu: Event: Event)</code></dt>
611
+ <dd>Fires when the editor gutter (the line-number area)
612
+ receives a <code>contextmenu</code> event. Will pass the editor
613
+ instance as first argument, the (zero-based) number of the line
614
+ that was clicked as second argument, the CSS class of the
615
+ gutter that was clicked as third argument, and the raw
616
+ <code>contextmenu</code> mouse event object as fourth argument.
617
+ You can <code>preventDefault</code> the event, to signal that
618
+ CodeMirror should do no further handling.</dd>
619
+
620
+ <dt id="event_focus"><code><strong>"focus"</strong> (instance: CodeMirror)</code></dt>
621
+ <dd>Fires whenever the editor is focused.</dd>
622
+
623
+ <dt id="event_blur"><code><strong>"blur"</strong> (instance: CodeMirror)</code></dt>
624
+ <dd>Fires whenever the editor is unfocused.</dd>
625
+
626
+ <dt id="event_scroll"><code><strong>"scroll"</strong> (instance: CodeMirror)</code></dt>
627
+ <dd>Fires when the editor is scrolled.</dd>
628
+
629
+ <dt id="event_scrollCursorIntoView"><code><strong>"scrollCursorIntoView"</strong> (instance: CodeMirror, event: Event)</code></dt>
630
+ <dd>Fires when the editor tries to scroll its cursor into view.
631
+ Can be hooked into to take care of additional scrollable
632
+ containers around the editor. When the event object has
633
+ its <code>preventDefault</code> method called, CodeMirror will
634
+ not itself try to scroll the window.</dd>
635
+
636
+ <dt id="event_update"><code><strong>"update"</strong> (instance: CodeMirror)</code></dt>
637
+ <dd>Will be fired whenever CodeMirror updates its DOM display.</dd>
638
+
639
+ <dt id="event_renderLine"><code><strong>"renderLine"</strong> (instance: CodeMirror, line: LineHandle, element: Element)</code></dt>
640
+ <dd>Fired whenever a line is (re-)rendered to the DOM. Fired
641
+ right after the DOM element is built, <em>before</em> it is
642
+ added to the document. The handler may mess with the style of
643
+ the resulting element, or add event handlers, but
644
+ should <em>not</em> try to change the state of the editor.</dd>
645
+
646
+ <dt id="event_dom"><code><strong>"mousedown"</strong>,
647
+ <strong>"dblclick"</strong>, <strong>"contextmenu"</strong>, <strong>"keydown"</strong>, <strong>"keypress"</strong>,
648
+ <strong>"keyup"</strong>, <strong>"dragstart"</strong>, <strong>"dragenter"</strong>,
649
+ <strong>"dragover"</strong>, <strong>"drop"</strong>
650
+ (instance: CodeMirror, event: Event)</code></dt>
651
+ <dd>Fired when CodeMirror is handling a DOM event of this type.
652
+ You can <code>preventDefault</code> the event, or give it a
653
+ truthy <code>codemirrorIgnore</code> property, to signal that
654
+ CodeMirror should do no further handling.</dd>
655
+ </dl>
656
+
657
+ <p>Document objects (instances
658
+ of <a href="#Doc"><code>CodeMirror.Doc</code></a>) emit the
659
+ following events:</p>
660
+
661
+ <dl>
662
+ <dt id="event_doc_change"><code><strong>"change"</strong> (doc: CodeMirror.Doc, changeObj: object)</code></dt>
663
+ <dd>Fired whenever a change occurs to the
664
+ document. <code>changeObj</code> has a similar type as the
665
+ object passed to the
666
+ editor's <a href="#event_change"><code>"change"</code></a>
667
+ event.</dd>
668
+
669
+ <dt id="event_doc_beforeChange"><code><strong>"beforeChange"</strong> (doc: CodeMirror.Doc, change: object)</code></dt>
670
+ <dd>See the <a href="#event_beforeChange">description of the
671
+ same event</a> on editor instances.</dd>
672
+
673
+ <dt id="event_doc_cursorActivity"><code><strong>"cursorActivity"</strong> (doc: CodeMirror.Doc)</code></dt>
674
+ <dd>Fired whenever the cursor or selection in this document
675
+ changes.</dd>
676
+
677
+ <dt id="event_doc_beforeSelectionChange"><code><strong>"beforeSelectionChange"</strong> (doc: CodeMirror.Doc, selection: {head, anchor})</code></dt>
678
+ <dd>Equivalent to
679
+ the <a href="#event_beforeSelectionChange">event by the same
680
+ name</a> as fired on editor instances.</dd>
681
+ </dl>
682
+
683
+ <p>Line handles (as returned by, for
684
+ example, <a href="#getLineHandle"><code>getLineHandle</code></a>)
685
+ support these events:</p>
686
+
687
+ <dl>
688
+ <dt id="event_delete"><code><strong>"delete"</strong> ()</code></dt>
689
+ <dd>Will be fired when the line object is deleted. A line object
690
+ is associated with the <em>start</em> of the line. Mostly useful
691
+ when you need to find out when your <a href="#setGutterMarker">gutter
692
+ markers</a> on a given line are removed.</dd>
693
+ <dt id="event_line_change"><code><strong>"change"</strong> (line: LineHandle, changeObj: object)</code></dt>
694
+ <dd>Fires when the line's text content is changed in any way
695
+ (but the line is not deleted outright). The <code>change</code>
696
+ object is similar to the one passed
697
+ to <a href="#event_change">change event</a> on the editor
698
+ object.</dd>
699
+ </dl>
700
+
701
+ <p>Marked range handles (<code>CodeMirror.TextMarker</code>), as returned
702
+ by <a href="#markText"><code>markText</code></a>
703
+ and <a href="#setBookmark"><code>setBookmark</code></a>, emit the
704
+ following events:</p>
705
+
706
+ <dl>
707
+ <dt id="event_beforeCursorEnter"><code><strong>"beforeCursorEnter"</strong> ()</code></dt>
708
+ <dd>Fired when the cursor enters the marked range. From this
709
+ event handler, the editor state may be inspected
710
+ but <em>not</em> modified, with the exception that the range on
711
+ which the event fires may be cleared.</dd>
712
+ <dt id="event_clear"><code><strong>"clear"</strong> (from: {line, ch}, to: {line, ch})</code></dt>
713
+ <dd>Fired when the range is cleared, either through cursor
714
+ movement in combination
715
+ with <a href="#mark_clearOnEnter"><code>clearOnEnter</code></a>
716
+ or through a call to its <code>clear()</code> method. Will only
717
+ be fired once per handle. Note that deleting the range through
718
+ text editing does not fire this event, because an undo action
719
+ might bring the range back into existence. <code>from</code>
720
+ and <code>to</code> give the part of the document that the range
721
+ spanned when it was cleared.</dd>
722
+ <dt id="event_hide"><code><strong>"hide"</strong> ()</code></dt>
723
+ <dd>Fired when the last part of the marker is removed from the
724
+ document by editing operations.</dd>
725
+ <dt id="event_unhide"><code><strong>"unhide"</strong> ()</code></dt>
726
+ <dd>Fired when, after the marker was removed by editing, a undo
727
+ operation brought the marker back.</dd>
728
+ </dl>
729
+
730
+ <p>Line widgets (<code>CodeMirror.LineWidget</code>), returned
731
+ by <a href="#addLineWidget"><code>addLineWidget</code></a>, fire
732
+ these events:</p>
733
+
734
+ <dl>
735
+ <dt id="event_redraw"><code><strong>"redraw"</strong> ()</code></dt>
736
+ <dd>Fired whenever the editor re-adds the widget to the DOM.
737
+ This will happen once right after the widget is added (if it is
738
+ scrolled into view), and then again whenever it is scrolled out
739
+ of view and back in again, or when changes to the editor options
740
+ or the line the widget is on require the widget to be
741
+ redrawn.</dd>
742
+ </dl>
743
+ </section>
744
+
745
+ <section id=keymaps>
746
+ <h2>Key Maps</h2>
747
+
748
+ <p>Key maps are ways to associate keys with functionality. A key map
749
+ is an object mapping strings that identify the keys to functions
750
+ that implement their functionality.</p>
751
+
752
+ <p>The CodeMirror distributions comes
753
+ with <a href="../demo/emacs.html">Emacs</a>, <a href="../demo/vim.html">Vim</a>,
754
+ and <a href="../demo/sublime.html">Sublime Text</a>-style keymaps.</p>
755
+
756
+ <p>Keys are identified either by name or by character.
757
+ The <code>CodeMirror.keyNames</code> object defines names for
758
+ common keys and associates them with their key codes. Examples of
759
+ names defined here are <code>Enter</code>, <code>F5</code>,
760
+ and <code>Q</code>. These can be prefixed
761
+ with <code>Shift-</code>, <code>Cmd-</code>, <code>Ctrl-</code>,
762
+ and <code>Alt-</code> to specify a modifier. So for
763
+ example, <code>Shift-Ctrl-Space</code> would be a valid key
764
+ identifier.</p>
765
+
766
+ <p>Common example: map the Tab key to insert spaces instead of a tab
767
+ character.</p>
768
+
769
+ <pre data-lang="javascript">
770
+ editor.setOption("extraKeys", {
771
+ Tab: function(cm) {
772
+ var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
773
+ cm.replaceSelection(spaces);
774
+ }
775
+ });</pre>
776
+
777
+ <p>Alternatively, a character can be specified directly by
778
+ surrounding it in single quotes, for example <code>'$'</code>
779
+ or <code>'q'</code>. Due to limitations in the way browsers fire
780
+ key events, these may not be prefixed with modifiers.</p>
781
+
782
+ <p id="normalizeKeyMap">Multi-stroke key bindings can be specified
783
+ by separating the key names by spaces in the property name, for
784
+ example <code>Ctrl-X Ctrl-V</code>. When a map contains
785
+ multi-stoke bindings or keys with modifiers that are not specified
786
+ in the default order (<code>Shift-Cmd-Ctrl-Alt</code>), you must
787
+ call <code>CodeMirror.normalizeKeyMap</code> on it before it can
788
+ be used. This function takes a keymap and modifies it to normalize
789
+ modifier order and properly recognize multi-stroke bindings. It
790
+ will return the keymap itself.</p>
791
+
792
+ <p>The <code>CodeMirror.keyMap</code> object associates key maps
793
+ with names. User code and key map definitions can assign extra
794
+ properties to this object. Anywhere where a key map is expected, a
795
+ string can be given, which will be looked up in this object. It
796
+ also contains the <code>"default"</code> key map holding the
797
+ default bindings.</p>
798
+
799
+ <p>The values of properties in key maps can be either functions of
800
+ a single argument (the CodeMirror instance), strings, or
801
+ <code>false</code>. Strings refer
802
+ to <a href="#commands">commands</a>, which are described below. If
803
+ the property is set to <code>false</code>, CodeMirror leaves
804
+ handling of the key up to the browser. A key handler function may
805
+ return <code>CodeMirror.Pass</code> to indicate that it has
806
+ decided not to handle the key, and other handlers (or the default
807
+ behavior) should be given a turn.</p>
808
+
809
+ <p>Keys mapped to command names that start with the
810
+ characters <code>"go"</code> or to functions that have a
811
+ truthy <code>motion</code> property (which should be used for
812
+ cursor-movement actions) will be fired even when an
813
+ extra <code>Shift</code> modifier is present (i.e. <code>"Up":
814
+ "goLineUp"</code> matches both up and shift-up). This is used to
815
+ easily implement shift-selection.</p>
816
+
817
+ <p>Key maps can defer to each other by defining
818
+ a <code>fallthrough</code> property. This indicates that when a
819
+ key is not found in the map itself, one or more other maps should
820
+ be searched. It can hold either a single key map or an array of
821
+ key maps.</p>
822
+
823
+ <p>When a key map needs to set something up when it becomes
824
+ active, or tear something down when deactivated, it can
825
+ contain <code>attach</code> and/or <code>detach</code> properties,
826
+ which should hold functions that take the editor instance and the
827
+ next or previous keymap. Note that this only works for the
828
+ <a href="#option_keyMap">top-level keymap</a>, not for fallthrough
829
+ maps or maps added
830
+ with <a href="#option_extraKeys"><code>extraKeys</code></a>
831
+ or <a href="#addKeyMap"><code>addKeyMap</code></a>.</p>
832
+ </section>
833
+
834
+ <section id=commands>
835
+ <h2>Commands</h2>
836
+
837
+ <p>Commands are parameter-less actions that can be performed on an
838
+ editor. Their main use is for key bindings. Commands are defined by
839
+ adding properties to the <code>CodeMirror.commands</code> object.
840
+ A number of common commands are defined by the library itself,
841
+ most of them used by the default key bindings. The value of a
842
+ command property must be a function of one argument (an editor
843
+ instance).</p>
844
+
845
+ <p>Some of the commands below are referenced in the default
846
+ key map, but not defined by the core library. These are intended to
847
+ be defined by user code or addons.</p>
848
+
849
+ <p>Commands can also be run with
850
+ the <a href="#execCommand"><code>execCommand</code></a>
851
+ method.</p>
852
+
853
+ <dl>
854
+ <dt class=command id=command_selectAll><code><strong>selectAll</strong></code><span class=keybinding>Ctrl-A (PC), Cmd-A (Mac)</span></dt>
855
+ <dd>Select the whole content of the editor.</dd>
856
+
857
+ <dt class=command id=command_singleSelection><code><strong>singleSelection</strong></code><span class=keybinding>Esc</span></dt>
858
+ <dd>When multiple selections are present, this deselects all but
859
+ the primary selection.</dd>
860
+
861
+ <dt class=command id=command_killLine><code><strong>killLine</strong></code><span class=keybinding>Ctrl-K (Mac)</span></dt>
862
+ <dd>Emacs-style line killing. Deletes the part of the line after
863
+ the cursor. If that consists only of whitespace, the newline at
864
+ the end of the line is also deleted.</dd>
865
+
866
+ <dt class=command id=command_deleteLine><code><strong>deleteLine</strong></code><span class=keybinding>Ctrl-D (PC), Cmd-D (Mac)</span></dt>
867
+ <dd>Deletes the whole line under the cursor, including newline at the end.</dd>
868
+
869
+ <dt class=command id=command_delLineLeft><code><strong>delLineLeft</strong></code></dt>
870
+ <dd>Delete the part of the line before the cursor.</dd>
871
+
872
+ <dt class=command id=command_delWrappedLineLeft><code><strong>delWrappedLineLeft</strong></code><span class=keybinding>Cmd-Backspace (Mac)</span></dt>
873
+ <dd>Delete the part of the line from the left side of the visual line the cursor is on to the cursor.</dd>
874
+
875
+ <dt class=command id=command_delWrappedLineRight><code><strong>delWrappedLineRight</strong></code><span class=keybinding>Cmd-Delete (Mac)</span></dt>
876
+ <dd>Delete the part of the line from the cursor to the right side of the visual line the cursor is on.</dd>
877
+
878
+ <dt class=command id=command_undo><code><strong>undo</strong></code><span class=keybinding>Ctrl-Z (PC), Cmd-Z (Mac)</span></dt>
879
+ <dd>Undo the last change.</dd>
880
+
881
+ <dt class=command id=command_redo><code><strong>redo</strong></code><span class=keybinding>Ctrl-Y (PC), Shift-Cmd-Z (Mac), Cmd-Y (Mac)</span></dt>
882
+ <dd>Redo the last undone change.</dd>
883
+
884
+ <dt class=command id=command_undoSelection><code><strong>undoSelection</strong></code><span class=keybinding>Ctrl-U (PC), Cmd-U (Mac)</span></dt>
885
+ <dd>Undo the last change to the selection, or if there are no
886
+ selection-only changes at the top of the history, undo the last
887
+ change.</dd>
888
+
889
+ <dt class=command id=command_redoSelection><code><strong>redoSelection</strong></code><span class=keybinding>Alt-U (PC), Shift-Cmd-U (Mac)</span></dt>
890
+ <dd>Redo the last change to the selection, or the last text change if
891
+ no selection changes remain.</dd>
892
+
893
+ <dt class=command id=command_goDocStart><code><strong>goDocStart</strong></code><span class=keybinding>Ctrl-Home (PC), Cmd-Up (Mac), Cmd-Home (Mac)</span></dt>
894
+ <dd>Move the cursor to the start of the document.</dd>
895
+
896
+ <dt class=command id=command_goDocEnd><code><strong>goDocEnd</strong></code><span class=keybinding>Ctrl-End (PC), Cmd-End (Mac), Cmd-Down (Mac)</span></dt>
897
+ <dd>Move the cursor to the end of the document.</dd>
898
+
899
+ <dt class=command id=command_goLineStart><code><strong>goLineStart</strong></code><span class=keybinding>Alt-Left (PC), Ctrl-A (Mac)</span></dt>
900
+ <dd>Move the cursor to the start of the line.</dd>
901
+
902
+ <dt class=command id=command_goLineStartSmart><code><strong>goLineStartSmart</strong></code><span class=keybinding>Home</span></dt>
903
+ <dd>Move to the start of the text on the line, or if we are
904
+ already there, to the actual start of the line (including
905
+ whitespace).</dd>
906
+
907
+ <dt class=command id=command_goLineEnd><code><strong>goLineEnd</strong></code><span class=keybinding>Alt-Right (PC), Ctrl-E (Mac)</span></dt>
908
+ <dd>Move the cursor to the end of the line.</dd>
909
+
910
+ <dt class=command id=command_goLineRight><code><strong>goLineRight</strong></code><span class=keybinding>Cmd-Right (Mac)</span></dt>
911
+ <dd>Move the cursor to the right side of the visual line it is on.</dd>
912
+
913
+ <dt class=command id=command_goLineLeft><code><strong>goLineLeft</strong></code><span class=keybinding>Cmd-Left (Mac)</span></dt>
914
+ <dd>Move the cursor to the left side of the visual line it is on. If
915
+ this line is wrapped, that may not be the start of the line.</dd>
916
+
917
+ <dt class=command id=command_goLineLeftSmart><code><strong>goLineLeftSmart</strong></code></dt>
918
+ <dd>Move the cursor to the left side of the visual line it is
919
+ on. If that takes it to the start of the line, behave
920
+ like <a href="#command_goLineStartSmart"><code>goLineStartSmart</code></a>.</dd>
921
+
922
+ <dt class=command id=command_goLineUp><code><strong>goLineUp</strong></code><span class=keybinding>Up, Ctrl-P (Mac)</span></dt>
923
+ <dd>Move the cursor up one line.</dd>
924
+
925
+ <dt class=command id=command_goLineDown><code><strong>goLineDown</strong></code><span class=keybinding>Down, Ctrl-N (Mac)</span></dt>
926
+ <dd>Move down one line.</dd>
927
+
928
+ <dt class=command id=command_goPageUp><code><strong>goPageUp</strong></code><span class=keybinding>PageUp, Shift-Ctrl-V (Mac)</span></dt>
929
+ <dd>Move the cursor up one screen, and scroll up by the same distance.</dd>
930
+
931
+ <dt class=command id=command_goPageDown><code><strong>goPageDown</strong></code><span class=keybinding>PageDown, Ctrl-V (Mac)</span></dt>
932
+ <dd>Move the cursor down one screen, and scroll down by the same distance.</dd>
933
+
934
+ <dt class=command id=command_goCharLeft><code><strong>goCharLeft</strong></code><span class=keybinding>Left, Ctrl-B (Mac)</span></dt>
935
+ <dd>Move the cursor one character left, going to the previous line
936
+ when hitting the start of line.</dd>
937
+
938
+ <dt class=command id=command_goCharRight><code><strong>goCharRight</strong></code><span class=keybinding>Right, Ctrl-F (Mac)</span></dt>
939
+ <dd>Move the cursor one character right, going to the next line
940
+ when hitting the end of line.</dd>
941
+
942
+ <dt class=command id=command_goColumnLeft><code><strong>goColumnLeft</strong></code></dt>
943
+ <dd>Move the cursor one character left, but don't cross line boundaries.</dd>
944
+
945
+ <dt class=command id=command_goColumnRight><code><strong>goColumnRight</strong></code></dt>
946
+ <dd>Move the cursor one character right, don't cross line boundaries.</dd>
947
+
948
+ <dt class=command id=command_goWordLeft><code><strong>goWordLeft</strong></code><span class=keybinding>Alt-B (Mac)</span></dt>
949
+ <dd>Move the cursor to the start of the previous word.</dd>
950
+
951
+ <dt class=command id=command_goWordRight><code><strong>goWordRight</strong></code><span class=keybinding>Alt-F (Mac)</span></dt>
952
+ <dd>Move the cursor to the end of the next word.</dd>
953
+
954
+ <dt class=command id=command_goGroupLeft><code><strong>goGroupLeft</strong></code><span class=keybinding>Ctrl-Left (PC), Alt-Left (Mac)</span></dt>
955
+ <dd>Move to the left of the group before the cursor. A group is
956
+ a stretch of word characters, a stretch of punctuation
957
+ characters, a newline, or a stretch of <em>more than one</em>
958
+ whitespace character.</dd>
959
+
960
+ <dt class=command id=command_goGroupRight><code><strong>goGroupRight</strong></code><span class=keybinding>Ctrl-Right (PC), Alt-Right (Mac)</span></dt>
961
+ <dd>Move to the right of the group after the cursor
962
+ (see <a href="#command_goGroupLeft">above</a>).</dd>
963
+
964
+ <dt class=command id=command_delCharBefore><code><strong>delCharBefore</strong></code><span class=keybinding>Shift-Backspace, Ctrl-H (Mac)</span></dt>
965
+ <dd>Delete the character before the cursor.</dd>
966
+
967
+ <dt class=command id=command_delCharAfter><code><strong>delCharAfter</strong></code><span class=keybinding>Delete, Ctrl-D (Mac)</span></dt>
968
+ <dd>Delete the character after the cursor.</dd>
969
+
970
+ <dt class=command id=command_delWordBefore><code><strong>delWordBefore</strong></code><span class=keybinding>Alt-Backspace (Mac)</span></dt>
971
+ <dd>Delete up to the start of the word before the cursor.</dd>
972
+
973
+ <dt class=command id=command_delWordAfter><code><strong>delWordAfter</strong></code><span class=keybinding>Alt-D (Mac)</span></dt>
974
+ <dd>Delete up to the end of the word after the cursor.</dd>
975
+
976
+ <dt class=command id=command_delGroupBefore><code><strong>delGroupBefore</strong></code><span class=keybinding>Ctrl-Backspace (PC), Alt-Backspace (Mac)</span></dt>
977
+ <dd>Delete to the left of the <a href="#command_goGroupLeft">group</a> before the cursor.</dd>
978
+
979
+ <dt class=command id=command_delGroupAfter><code><strong>delGroupAfter</strong></code><span class=keybinding>Ctrl-Delete (PC), Ctrl-Alt-Backspace (Mac), Alt-Delete (Mac)</span></dt>
980
+ <dd>Delete to the start of the <a href="#command_goGroupLeft">group</a> after the cursor.</dd>
981
+
982
+ <dt class=command id=command_indentAuto><code><strong>indentAuto</strong></code><span class=keybinding>Shift-Tab</span></dt>
983
+ <dd>Auto-indent the current line or selection.</dd>
984
+
985
+ <dt class=command id=command_indentMore><code><strong>indentMore</strong></code><span class=keybinding>Ctrl-] (PC), Cmd-] (Mac)</span></dt>
986
+ <dd>Indent the current line or selection by one <a href="#option_indentUnit">indent unit</a>.</dd>
987
+
988
+ <dt class=command id=command_indentLess><code><strong>indentLess</strong></code><span class=keybinding>Ctrl-[ (PC), Cmd-[ (Mac)</span></dt>
989
+ <dd>Dedent the current line or selection by one <a href="#option_indentUnit">indent unit</a>.</dd>
990
+
991
+ <dt class=command id=command_insertTab><code><strong>insertTab</strong></code></dt>
992
+ <dd>Insert a tab character at the cursor.</dd>
993
+
994
+ <dt class=command id=command_insertSoftTab><code><strong>insertSoftTab</strong></code></dt>
995
+ <dd>Insert the amount of spaces that match the width a tab at
996
+ the cursor position would have.</dd>
997
+
998
+ <dt class=command id=command_defaultTab><code><strong>defaultTab</strong></code><span class=keybinding>Tab</span></dt>
999
+ <dd>If something is selected, indent it by
1000
+ one <a href="#option_indentUnit">indent unit</a>. If nothing is
1001
+ selected, insert a tab character.</dd>
1002
+
1003
+ <dt class=command id=command_transposeChars><code><strong>transposeChars</strong></code><span class=keybinding>Ctrl-T (Mac)</span></dt>
1004
+ <dd>Swap the characters before and after the cursor.</dd>
1005
+
1006
+ <dt class=command id=command_newlineAndIndent><code><strong>newlineAndIndent</strong></code><span class=keybinding>Enter</span></dt>
1007
+ <dd>Insert a newline and auto-indent the new line.</dd>
1008
+
1009
+ <dt class=command id=command_toggleOverwrite><code><strong>toggleOverwrite</strong></code><span class=keybinding>Insert</span></dt>
1010
+ <dd>Flip the <a href="#toggleOverwrite">overwrite</a> flag.</dd>
1011
+
1012
+ <dt class=command id=command_save><code><strong>save</strong></code><span class=keybinding>Ctrl-S (PC), Cmd-S (Mac)</span></dt>
1013
+ <dd>Not defined by the core library, only referred to in
1014
+ key maps. Intended to provide an easy way for user code to define
1015
+ a save command.</dd>
1016
+
1017
+ <dt class=command id=command_find><code><strong>find</strong></code><span class=keybinding>Ctrl-F (PC), Cmd-F (Mac)</span></dt>
1018
+ <dt class=command id=command_findNext><code><strong>findNext</strong></code><span class=keybinding>Ctrl-G (PC), Cmd-G (Mac)</span></dt>
1019
+ <dt class=command id=command_findPrev><code><strong>findPrev</strong></code><span class=keybinding>Shift-Ctrl-G (PC), Shift-Cmd-G (Mac)</span></dt>
1020
+ <dt class=command id=command_replace><code><strong>replace</strong></code><span class=keybinding>Shift-Ctrl-F (PC), Cmd-Alt-F (Mac)</span></dt>
1021
+ <dt class=command id=command_replaceAll><code><strong>replaceAll</strong></code><span class=keybinding>Shift-Ctrl-R (PC), Shift-Cmd-Alt-F (Mac)</span></dt>
1022
+ <dd>Not defined by the core library, but defined in
1023
+ the <a href="#addon_search">search addon</a> (or custom client
1024
+ addons).</dd>
1025
+
1026
+ </dl>
1027
+
1028
+ </section>
1029
+
1030
+ <section id=styling>
1031
+ <h2>Customized Styling</h2>
1032
+
1033
+ <p>Up to a certain extent, CodeMirror's look can be changed by
1034
+ modifying style sheet files. The style sheets supplied by modes
1035
+ simply provide the colors for that mode, and can be adapted in a
1036
+ very straightforward way. To style the editor itself, it is
1037
+ possible to alter or override the styles defined
1038
+ in <a href="../lib/codemirror.css"><code>codemirror.css</code></a>.</p>
1039
+
1040
+ <p>Some care must be taken there, since a lot of the rules in this
1041
+ file are necessary to have CodeMirror function properly. Adjusting
1042
+ colors should be safe, of course, and with some care a lot of
1043
+ other things can be changed as well. The CSS classes defined in
1044
+ this file serve the following roles:</p>
1045
+
1046
+ <dl>
1047
+ <dt id="class_CodeMirror"><code><strong>CodeMirror</strong></code></dt>
1048
+ <dd>The outer element of the editor. This should be used for the
1049
+ editor width, height, borders and positioning. Can also be used
1050
+ to set styles that should hold for everything inside the editor
1051
+ (such as font and font size), or to set a background. Setting
1052
+ this class' <code>height</code> style to <code>auto</code> will
1053
+ make the editor <a href="../demo/resize.html">resize to fit its
1054
+ content</a> (it is recommended to also set
1055
+ the <a href="#option_viewportMargin"><code>viewportMargin</code>
1056
+ option</a> to <code>Infinity</code> when doing this.</dd>
1057
+
1058
+ <dt id="class_CodeMirror_focused"><code><strong>CodeMirror-focused</strong></code></dt>
1059
+ <dd>Whenever the editor is focused, the top element gets this
1060
+ class. This is used to hide the cursor and give the selection a
1061
+ different color when the editor is not focused.</dd>
1062
+
1063
+ <dt id="class_CodeMirror_gutters"><code><strong>CodeMirror-gutters</strong></code></dt>
1064
+ <dd>This is the backdrop for all gutters. Use it to set the
1065
+ default gutter background color, and optionally add a border on
1066
+ the right of the gutters.</dd>
1067
+
1068
+ <dt id="class_CodeMirror_linenumbers"><code><strong>CodeMirror-linenumbers</strong></code></dt>
1069
+ <dd>Use this for giving a background or width to the line number
1070
+ gutter.</dd>
1071
+
1072
+ <dt id="class_CodeMirror_linenumber"><code><strong>CodeMirror-linenumber</strong></code></dt>
1073
+ <dd>Used to style the actual individual line numbers. These
1074
+ won't be children of the <code>CodeMirror-linenumbers</code>
1075
+ (plural) element, but rather will be absolutely positioned to
1076
+ overlay it. Use this to set alignment and text properties for
1077
+ the line numbers.</dd>
1078
+
1079
+ <dt id="class_CodeMirror_lines"><code><strong>CodeMirror-lines</strong></code></dt>
1080
+ <dd>The visible lines. This is where you specify vertical
1081
+ padding for the editor content.</dd>
1082
+
1083
+ <dt id="class_CodeMirror_cursor"><code><strong>CodeMirror-cursor</strong></code></dt>
1084
+ <dd>The cursor is a block element that is absolutely positioned.
1085
+ You can make it look whichever way you want.</dd>
1086
+
1087
+ <dt id="class_CodeMirror_selected"><code><strong>CodeMirror-selected</strong></code></dt>
1088
+ <dd>The selection is represented by <code>span</code> elements
1089
+ with this class.</dd>
1090
+
1091
+ <dt id="class_CodeMirror_matchingbracket"><code><strong>CodeMirror-matchingbracket</strong></code>,
1092
+ <code><strong>CodeMirror-nonmatchingbracket</strong></code></dt>
1093
+ <dd>These are used to style matched (or unmatched) brackets.</dd>
1094
+ </dl>
1095
+
1096
+ <p>If your page's style sheets do funky things to
1097
+ all <code>div</code> or <code>pre</code> elements (you probably
1098
+ shouldn't do that), you'll have to define rules to cancel these
1099
+ effects out again for elements under the <code>CodeMirror</code>
1100
+ class.</p>
1101
+
1102
+ <p>Themes are also simply CSS files, which define colors for
1103
+ various syntactic elements. See the files in
1104
+ the <a href="../theme/"><code>theme</code></a> directory.</p>
1105
+ </section>
1106
+
1107
+ <section id=api>
1108
+ <h2>Programming API</h2>
1109
+
1110
+ <p>A lot of CodeMirror features are only available through its
1111
+ API. Thus, you need to write code (or
1112
+ use <a href="#addons">addons</a>) if you want to expose them to
1113
+ your users.</p>
1114
+
1115
+ <p>Whenever points in the document are represented, the API uses
1116
+ objects with <code>line</code> and <code>ch</code> properties.
1117
+ Both are zero-based. CodeMirror makes sure to 'clip' any positions
1118
+ passed by client code so that they fit inside the document, so you
1119
+ shouldn't worry too much about sanitizing your coordinates. If you
1120
+ give <code>ch</code> a value of <code>null</code>, or don't
1121
+ specify it, it will be replaced with the length of the specified
1122
+ line.</p>
1123
+
1124
+ <p>Methods prefixed with <code>doc.</code> can, unless otherwise
1125
+ specified, be called both on <code>CodeMirror</code> (editor)
1126
+ instances and <code>CodeMirror.Doc</code> instances. Methods
1127
+ prefixed with <code>cm.</code> are <em>only</em> available
1128
+ on <code>CodeMirror</code> instances.</p>
1129
+
1130
+ <h3 id="api_constructor">Constructor</h3>
1131
+
1132
+ <p id="CodeMirror">Constructing an editor instance is done with
1133
+ the <code><strong>CodeMirror</strong>(place: Element|fn(Element),
1134
+ ?option: object)</code> constructor. If the <code>place</code>
1135
+ argument is a DOM element, the editor will be appended to it. If
1136
+ it is a function, it will be called, and is expected to place the
1137
+ editor into the document. <code>options</code> may be an element
1138
+ mapping <a href="#config">option names</a> to values. The options
1139
+ that it doesn't explicitly specify (or all options, if it is not
1140
+ passed) will be taken
1141
+ from <a href="#defaults"><code>CodeMirror.defaults</code></a>.</p>
1142
+
1143
+ <p>Note that the options object passed to the constructor will be
1144
+ mutated when the instance's options
1145
+ are <a href="#setOption">changed</a>, so you shouldn't share such
1146
+ objects between instances.</p>
1147
+
1148
+ <p>See <a href="#fromTextArea"><code>CodeMirror.fromTextArea</code></a>
1149
+ for another way to construct an editor instance.</p>
1150
+
1151
+ <h3 id="api_content">Content manipulation methods</h3>
1152
+
1153
+ <dl>
1154
+ <dt id="getValue"><code><strong>doc.getValue</strong>(?separator: string) → string</code></dt>
1155
+ <dd>Get the current editor content. You can pass it an optional
1156
+ argument to specify the string to be used to separate lines
1157
+ (defaults to <code>"\n"</code>).</dd>
1158
+ <dt id="setValue"><code><strong>doc.setValue</strong>(content: string)</code></dt>
1159
+ <dd>Set the editor content.</dd>
1160
+
1161
+ <dt id="getRange"><code><strong>doc.getRange</strong>(from: {line, ch}, to: {line, ch}, ?separator: string) → string</code></dt>
1162
+ <dd>Get the text between the given points in the editor, which
1163
+ should be <code>{line, ch}</code> objects. An optional third
1164
+ argument can be given to indicate the line separator string to
1165
+ use (defaults to <code>"\n"</code>).</dd>
1166
+ <dt id="replaceRange"><code><strong>doc.replaceRange</strong>(replacement: string, from: {line, ch}, to: {line, ch}, ?origin: string)</code></dt>
1167
+ <dd>Replace the part of the document between <code>from</code>
1168
+ and <code>to</code> with the given string. <code>from</code>
1169
+ and <code>to</code> must be <code>{line, ch}</code>
1170
+ objects. <code>to</code> can be left off to simply insert the
1171
+ string at position <code>from</code>. When <code>origin</code>
1172
+ is given, it will be passed on
1173
+ to <a href="#event_change"><code>"change"</code> events</a>, and
1174
+ its first letter will be used to determine whether this change
1175
+ can be merged with previous history events, in the way described
1176
+ for <a href="#selection_origin">selection origins</a>.</dd>
1177
+
1178
+ <dt id="getLine"><code><strong>doc.getLine</strong>(n: integer) → string</code></dt>
1179
+ <dd>Get the content of line <code>n</code>.</dd>
1180
+
1181
+ <dt id="lineCount"><code><strong>doc.lineCount</strong>() → integer</code></dt>
1182
+ <dd>Get the number of lines in the editor.</dd>
1183
+ <dt id="firstLine"><code><strong>doc.firstLine</strong>() → integer</code></dt>
1184
+ <dd>Get the first line of the editor. This will
1185
+ usually be zero but for <a href="#linkedDoc_from">linked sub-views</a>,
1186
+ or <a href="#api_doc">documents</a> instantiated with a non-zero
1187
+ first line, it might return other values.</dd>
1188
+ <dt id="lastLine"><code><strong>doc.lastLine</strong>() → integer</code></dt>
1189
+ <dd>Get the last line of the editor. This will
1190
+ usually be <code>doc.lineCount() - 1</code>,
1191
+ but for <a href="#linkedDoc_from">linked sub-views</a>,
1192
+ it might return other values.</dd>
1193
+
1194
+ <dt id="getLineHandle"><code><strong>doc.getLineHandle</strong>(num: integer) → LineHandle</code></dt>
1195
+ <dd>Fetches the line handle for the given line number.</dd>
1196
+ <dt id="getLineNumber"><code><strong>doc.getLineNumber</strong>(handle: LineHandle) → integer</code></dt>
1197
+ <dd>Given a line handle, returns the current position of that
1198
+ line (or <code>null</code> when it is no longer in the
1199
+ document).</dd>
1200
+ <dt id="eachLine"><code><strong>doc.eachLine</strong>(f: (line: LineHandle))</code></dt>
1201
+ <dt><code><strong>doc.eachLine</strong>(start: integer, end: integer, f: (line: LineHandle))</code></dt>
1202
+ <dd>Iterate over the whole document, or if <code>start</code>
1203
+ and <code>end</code> line numbers are given, the range
1204
+ from <code>start</code> up to (not including) <code>end</code>,
1205
+ and call <code>f</code> for each line, passing the line handle.
1206
+ This is a faster way to visit a range of line handlers than
1207
+ calling <a href="#getLineHandle"><code>getLineHandle</code></a>
1208
+ for each of them. Note that line handles have
1209
+ a <code>text</code> property containing the line's content (as a
1210
+ string).</dd>
1211
+
1212
+ <dt id="markClean"><code><strong>doc.markClean</strong>()</code></dt>
1213
+ <dd>Set the editor content as 'clean', a flag that it will
1214
+ retain until it is edited, and which will be set again when such
1215
+ an edit is undone again. Useful to track whether the content
1216
+ needs to be saved. This function is deprecated in favor
1217
+ of <a href="#changeGeneration"><code>changeGeneration</code></a>,
1218
+ which allows multiple subsystems to track different notions of
1219
+ cleanness without interfering.</dd>
1220
+ <dt id="changeGeneration"><code><strong>doc.changeGeneration</strong>(?closeEvent: boolean) → integer</code></dt>
1221
+ <dd>Returns a number that can later be passed
1222
+ to <a href="#isClean"><code>isClean</code></a> to test whether
1223
+ any edits were made (and not undone) in the meantime.
1224
+ If <code>closeEvent</code> is true, the current history event
1225
+ will be ‘closed’, meaning it can't be combined with further
1226
+ changes (rapid typing or deleting events are typically
1227
+ combined).</dd>
1228
+ <dt id="isClean"><code><strong>doc.isClean</strong>(?generation: integer) → boolean</code></dt>
1229
+ <dd>Returns whether the document is currently clean — not
1230
+ modified since initialization or the last call
1231
+ to <a href="#markClean"><code>markClean</code></a> if no
1232
+ argument is passed, or since the matching call
1233
+ to <a href="#changeGeneration"><code>changeGeneration</code></a>
1234
+ if a generation value is given.</dd>
1235
+ </dl>
1236
+
1237
+ <h3 id="api_selection">Cursor and selection methods</h3>
1238
+
1239
+ <dl>
1240
+ <dt id="getSelection"><code><strong>doc.getSelection</strong>(?lineSep: string) → string</code></dt>
1241
+ <dd>Get the currently selected code. Optionally pass a line
1242
+ separator to put between the lines in the output. When multiple
1243
+ selections are present, they are concatenated with instances
1244
+ of <code>lineSep</code> in between.</dd>
1245
+ <dt id="getSelections"><code><strong>doc.getSelections</strong>(?lineSep: string) → string</code></dt>
1246
+ <dd>Returns an array containing a string for each selection,
1247
+ representing the content of the selections.</dd>
1248
+
1249
+ <dt id="replaceSelection"><code><strong>doc.replaceSelection</strong>(replacement: string, ?select: string)</code></dt>
1250
+ <dd>Replace the selection(s) with the given string. By default,
1251
+ the new selection ends up after the inserted text. The
1252
+ optional <code>select</code> argument can be used to change
1253
+ this—passing <code>"around"</code> will cause the new text to be
1254
+ selected, passing <code>"start"</code> will collapse the
1255
+ selection to the start of the inserted text.</dd>
1256
+ <dt id="replaceSelections"><code><strong>doc.replaceSelections</strong>(replacements: array&lt;string&gt;, ?select: string)</code></dt>
1257
+ <dd>The length of the given array should be the same as the
1258
+ number of active selections. Replaces the content of the
1259
+ selections with the strings in the array.
1260
+ The <code>select</code> argument works the same as
1261
+ in <a href="#replaceSelection"><code>replaceSelection</code></a>.</dd>
1262
+
1263
+ <dt id="getCursor"><code><strong>doc.getCursor</strong>(?start: string) → {line, ch}</code></dt>
1264
+ <dd>Retrieve one end of the <em>primary</em>
1265
+ selection. <code>start</code> is a an optional string indicating
1266
+ which end of the selection to return. It may
1267
+ be <code>"from"</code>, <code>"to"</code>, <code>"head"</code>
1268
+ (the side of the selection that moves when you press
1269
+ shift+arrow), or <code>"anchor"</code> (the fixed side of the
1270
+ selection). Omitting the argument is the same as
1271
+ passing <code>"head"</code>. A <code>{line, ch}</code> object
1272
+ will be returned.</dd>
1273
+ <dt id="listSelections"><code><strong>doc.listSelections</strong>() → array&lt;{anchor, head}&gt;</code></dt>
1274
+ <dd>Retrieves a list of all current selections. These will
1275
+ always be sorted, and never overlap (overlapping selections are
1276
+ merged). Each object in the array contains <code>anchor</code>
1277
+ and <code>head</code> properties referring to <code>{line,
1278
+ ch}</code> objects.</dd>
1279
+
1280
+ <dt id="somethingSelected"><code><strong>doc.somethingSelected</strong>() → boolean</code></dt>
1281
+ <dd>Return true if any text is selected.</dd>
1282
+ <dt id="setCursor"><code><strong>doc.setCursor</strong>(pos: {line, ch}|number, ?ch: number, ?options: object)</code></dt>
1283
+ <dd>Set the cursor position. You can either pass a
1284
+ single <code>{line, ch}</code> object, or the line and the
1285
+ character as two separate parameters. Will replace all
1286
+ selections with a single, empty selection at the given position.
1287
+ The supported options are the same as for <a href="#setSelection"><code>setSelection</code></a>.</dd>
1288
+
1289
+ <dt id="setSelection"><code><strong>doc.setSelection</strong>(anchor: {line, ch}, ?head: {line, ch}, ?options: object)</code></dt>
1290
+ <dd>Set a single selection range. <code>anchor</code>
1291
+ and <code>head</code> should be <code>{line, ch}</code>
1292
+ objects. <code>head</code> defaults to <code>anchor</code> when
1293
+ not given. These options are supported:
1294
+ <dl>
1295
+ <dt id="selection_scroll"><code><strong>scroll</strong>: boolean</code></dt>
1296
+ <dd>Determines whether the selection head should be scrolled
1297
+ into view. Defaults to true.</dd>
1298
+ <dt id="selection_origin"><code><strong>origin</strong>: string</code></dt>
1299
+ <dd>Detemines whether the selection history event may be
1300
+ merged with the previous one. When an origin starts with the
1301
+ character <code>+</code>, and the last recorded selection had
1302
+ the same origin and was similar (close
1303
+ in <a href="#option_historyEventDelay">time</a>, both
1304
+ collapsed or both non-collapsed), the new one will replace the
1305
+ old one. When it starts with <code>*</code>, it will always
1306
+ replace the previous event (if that had the same origin).
1307
+ Built-in motion uses the <code>"+move"</code> origin.</dd>
1308
+ <dt id="selection_bias"><code><strong>bias</strong>: number</code></dt>
1309
+ <dd>Determine the direction into which the selection endpoints
1310
+ should be adjusted when they fall inside
1311
+ an <a href="#mark_atomic">atomic</a> range. Can be either -1
1312
+ (backward) or 1 (forward). When not given, the bias will be
1313
+ based on the relative position of the old selection—the editor
1314
+ will try to move further away from that, to prevent getting
1315
+ stuck.</dd>
1316
+ </dl></dd>
1317
+
1318
+ <dt id="setSelections"><code><strong>doc.setSelections</strong>(ranges: array&lt;{anchor, head}&gt;, ?primary: integer, ?options: object)</code></dt>
1319
+ <dd>Sets a new set of selections. There must be at least one
1320
+ selection in the given array. When <code>primary</code> is a
1321
+ number, it determines which selection is the primary one. When
1322
+ it is not given, the primary index is taken from the previous
1323
+ selection, or set to the last range if the previous selection
1324
+ had less ranges than the new one. Supports the same options
1325
+ as <a href="#setSelection"><code>setSelection</code></a>.</dd>
1326
+ <dt id="addSelection"><code><strong>doc.addSelection</strong>(anchor: {line, ch}, ?head: {line, ch})</code></dt>
1327
+ <dd>Adds a new selection to the existing set of selections, and
1328
+ makes it the primary selection.</dd>
1329
+
1330
+ <dt id="extendSelection"><code><strong>doc.extendSelection</strong>(from: {line, ch}, ?to: {line, ch}, ?options: object)</code></dt>
1331
+ <dd>Similar
1332
+ to <a href="#setSelection"><code>setSelection</code></a>, but
1333
+ will, if shift is held or
1334
+ the <a href="#setExtending">extending</a> flag is set, move the
1335
+ head of the selection while leaving the anchor at its current
1336
+ place. <code>to</code> is optional, and can be passed to ensure
1337
+ a region (for example a word or paragraph) will end up selected
1338
+ (in addition to whatever lies between that region and the
1339
+ current anchor). When multiple selections are present, all but
1340
+ the primary selection will be dropped by this method.
1341
+ Supports the same options as <a href="#setSelection"><code>setSelection</code></a>.</dd>
1342
+ <dt id="extendSelections"><code><strong>doc.extendSelections</strong>(heads: array&lt;{line, ch}&gt;, ?options: object)</code></dt>
1343
+ <dd>An equivalent
1344
+ of <a href="#extendSelection"><code>extendSelection</code></a>
1345
+ that acts on all selections at once.</dd>
1346
+ <dt id="extendSelectionsBy"><code><strong>doc.extendSelectionsBy</strong>(f: function(range: {anchor, head}) → {anchor, head}), ?options: object)</code></dt>
1347
+ <dd>Applies the given function to all existing selections, and
1348
+ calls <a href="#extendSelections"><code>extendSelections</code></a>
1349
+ on the result.</dd>
1350
+ <dt id="setExtending"><code><strong>doc.setExtending</strong>(value: boolean)</code></dt>
1351
+ <dd>Sets or clears the 'extending' flag, which acts similar to
1352
+ the shift key, in that it will cause cursor movement and calls
1353
+ to <a href="#extendSelection"><code>extendSelection</code></a>
1354
+ to leave the selection anchor in place.</dd>
1355
+ <dt id="getExtending"><code><strong>doc.getExtending</strong>() → boolean</code></dt>
1356
+ <dd>Get the value of the 'extending' flag.</dd>
1357
+
1358
+ <dt id="hasFocus"><code><strong>cm.hasFocus</strong>() → boolean</code></dt>
1359
+ <dd>Tells you whether the editor currently has focus.</dd>
1360
+
1361
+ <dt id="findPosH"><code><strong>cm.findPosH</strong>(start: {line, ch}, amount: integer, unit: string, visually: boolean) → {line, ch, ?hitSide: boolean}</code></dt>
1362
+ <dd>Used to find the target position for horizontal cursor
1363
+ motion. <code>start</code> is a <code>{line, ch}</code>
1364
+ object, <code>amount</code> an integer (may be negative),
1365
+ and <code>unit</code> one of the
1366
+ string <code>"char"</code>, <code>"column"</code>,
1367
+ or <code>"word"</code>. Will return a position that is produced
1368
+ by moving <code>amount</code> times the distance specified
1369
+ by <code>unit</code>. When <code>visually</code> is true, motion
1370
+ in right-to-left text will be visual rather than logical. When
1371
+ the motion was clipped by hitting the end or start of the
1372
+ document, the returned value will have a <code>hitSide</code>
1373
+ property set to true.</dd>
1374
+ <dt id="findPosV"><code><strong>cm.findPosV</strong>(start: {line, ch}, amount: integer, unit: string) → {line, ch, ?hitSide: boolean}</code></dt>
1375
+ <dd>Similar to <a href="#findPosH"><code>findPosH</code></a>,
1376
+ but used for vertical motion. <code>unit</code> may
1377
+ be <code>"line"</code> or <code>"page"</code>. The other
1378
+ arguments and the returned value have the same interpretation as
1379
+ they have in <code>findPosH</code>.</dd>
1380
+
1381
+ <dt id="findWordAt"><code><strong>cm.findWordAt</strong>(pos: {line, ch}) → {anchor: {line, ch}, head: {line, ch}}</code></dt>
1382
+ <dd>Returns the start and end of the 'word' (the stretch of
1383
+ letters, whitespace, or punctuation) at the given position.</dd>
1384
+ </dl>
1385
+
1386
+ <h3 id="api_configuration">Configuration methods</h3>
1387
+
1388
+ <dl>
1389
+ <dt id="setOption"><code><strong>cm.setOption</strong>(option: string, value: any)</code></dt>
1390
+ <dd>Change the configuration of the editor. <code>option</code>
1391
+ should the name of an <a href="#config">option</a>,
1392
+ and <code>value</code> should be a valid value for that
1393
+ option.</dd>
1394
+ <dt id="getOption"><code><strong>cm.getOption</strong>(option: string) → any</code></dt>
1395
+ <dd>Retrieves the current value of the given option for this
1396
+ editor instance.</dd>
1397
+
1398
+ <dt id="addKeyMap"><code><strong>cm.addKeyMap</strong>(map: object, bottom: boolean)</code></dt>
1399
+ <dd>Attach an additional <a href="#keymaps">key map</a> to the
1400
+ editor. This is mostly useful for addons that need to register
1401
+ some key handlers without trampling on
1402
+ the <a href="#option_extraKeys"><code>extraKeys</code></a>
1403
+ option. Maps added in this way have a higher precedence than
1404
+ the <code>extraKeys</code>
1405
+ and <a href="#option_keyMap"><code>keyMap</code></a> options,
1406
+ and between them, the maps added earlier have a lower precedence
1407
+ than those added later, unless the <code>bottom</code> argument
1408
+ was passed, in which case they end up below other key maps added
1409
+ with this method.</dd>
1410
+ <dt id="removeKeyMap"><code><strong>cm.removeKeyMap</strong>(map: object)</code></dt>
1411
+ <dd>Disable a keymap added
1412
+ with <a href="#addKeyMap"><code>addKeyMap</code></a>. Either
1413
+ pass in the key map object itself, or a string, which will be
1414
+ compared against the <code>name</code> property of the active
1415
+ key maps.</dd>
1416
+
1417
+ <dt id="addOverlay"><code><strong>cm.addOverlay</strong>(mode: string|object, ?options: object)</code></dt>
1418
+ <dd>Enable a highlighting overlay. This is a stateless mini-mode
1419
+ that can be used to add extra highlighting. For example,
1420
+ the <a href="../demo/search.html">search addon</a> uses it to
1421
+ highlight the term that's currently being
1422
+ searched. <code>mode</code> can be a <a href="#option_mode">mode
1423
+ spec</a> or a mode object (an object with
1424
+ a <a href="#token"><code>token</code></a> method).
1425
+ The <code>options</code> parameter is optional. If given, it
1426
+ should be an object. Currently, only the <code>opaque</code>
1427
+ option is recognized. This defaults to off, but can be given to
1428
+ allow the overlay styling, when not <code>null</code>, to
1429
+ override the styling of the base mode entirely, instead of the
1430
+ two being applied together.</dd>
1431
+ <dt id="removeOverlay"><code><strong>cm.removeOverlay</strong>(mode: string|object)</code></dt>
1432
+ <dd>Pass this the exact value passed for the <code>mode</code>
1433
+ parameter to <a href="#addOverlay"><code>addOverlay</code></a>,
1434
+ or a string that corresponds to the <code>name</code> propery of
1435
+ that value, to remove an overlay again.</dd>
1436
+
1437
+ <dt id="on"><code><strong>cm.on</strong>(type: string, func: (...args))</code></dt>
1438
+ <dd>Register an event handler for the given event type (a
1439
+ string) on the editor instance. There is also
1440
+ a <code>CodeMirror.on(object, type, func)</code> version
1441
+ that allows registering of events on any object.</dd>
1442
+ <dt id="off"><code><strong>cm.off</strong>(type: string, func: (...args))</code></dt>
1443
+ <dd>Remove an event handler on the editor instance. An
1444
+ equivalent <code>CodeMirror.off(object, type,
1445
+ func)</code> also exists.</dd>
1446
+ </dl>
1447
+
1448
+ <h3 id="api_doc">Document management methods</h3>
1449
+
1450
+ <p id="Doc">Each editor is associated with an instance
1451
+ of <code>CodeMirror.Doc</code>, its document. A document
1452
+ represents the editor content, plus a selection, an undo history,
1453
+ and a <a href="#option_mode">mode</a>. A document can only be
1454
+ associated with a single editor at a time. You can create new
1455
+ documents by calling the <code>CodeMirror.Doc(text, mode,
1456
+ firstLineNumber)</code> constructor. The last two arguments are
1457
+ optional and can be used to set a mode for the document and make
1458
+ it start at a line number other than 0, respectively.</p>
1459
+
1460
+ <dl>
1461
+ <dt id="getDoc"><code><strong>cm.getDoc</strong>() → Doc</code></dt>
1462
+ <dd>Retrieve the currently active document from an editor.</dd>
1463
+ <dt id="getEditor"><code><strong>doc.getEditor</strong>() → CodeMirror</code></dt>
1464
+ <dd>Retrieve the editor associated with a document. May
1465
+ return <code>null</code>.</dd>
1466
+
1467
+ <dt id="swapDoc"><code><strong>cm.swapDoc</strong>(doc: CodeMirror.Doc) → Doc</code></dt>
1468
+ <dd>Attach a new document to the editor. Returns the old
1469
+ document, which is now no longer associated with an editor.</dd>
1470
+
1471
+ <dt id="copy"><code><strong>doc.copy</strong>(copyHistory: boolean) → Doc</code></dt>
1472
+ <dd>Create an identical copy of the given doc.
1473
+ When <code>copyHistory</code> is true, the history will also be
1474
+ copied. Can not be called directly on an editor.</dd>
1475
+
1476
+ <dt id="linkedDoc"><code><strong>doc.linkedDoc</strong>(options: object) → Doc</code></dt>
1477
+ <dd>Create a new document that's linked to the target document.
1478
+ Linked documents will stay in sync (changes to one are also
1479
+ applied to the other) until <a href="#unlinkDoc">unlinked</a>.
1480
+ These are the options that are supported:
1481
+ <dl>
1482
+ <dt id="linkedDoc_sharedHist"><code><strong>sharedHist</strong>: boolean</code></dt>
1483
+ <dd>When turned on, the linked copy will share an undo
1484
+ history with the original. Thus, something done in one of
1485
+ the two can be undone in the other, and vice versa.</dd>
1486
+ <dt id="linkedDoc_from"><code><strong>from</strong>: integer</code></dt>
1487
+ <dt id="linkedDoc_to"><code><strong>to</strong>: integer</code></dt>
1488
+ <dd>Can be given to make the new document a subview of the
1489
+ original. Subviews only show a given range of lines. Note
1490
+ that line coordinates inside the subview will be consistent
1491
+ with those of the parent, so that for example a subview
1492
+ starting at line 10 will refer to its first line as line 10,
1493
+ not 0.</dd>
1494
+ <dt id="linkedDoc_mode"><code><strong>mode</strong>: string|object</code></dt>
1495
+ <dd>By default, the new document inherits the mode of the
1496
+ parent. This option can be set to
1497
+ a <a href="#option_mode">mode spec</a> to give it a
1498
+ different mode.</dd>
1499
+ </dl></dd>
1500
+ <dt id="unlinkDoc"><code><strong>doc.unlinkDoc</strong>(doc: CodeMirror.Doc)</code></dt>
1501
+ <dd>Break the link between two documents. After calling this,
1502
+ changes will no longer propagate between the documents, and, if
1503
+ they had a shared history, the history will become
1504
+ separate.</dd>
1505
+ <dt id="iterLinkedDocs"><code><strong>doc.iterLinkedDocs</strong>(function: (doc: CodeMirror.Doc, sharedHist: boolean))</code></dt>
1506
+ <dd>Will call the given function for all documents linked to the
1507
+ target document. It will be passed two arguments, the linked document
1508
+ and a boolean indicating whether that document shares history
1509
+ with the target.</dd>
1510
+ </dl>
1511
+
1512
+ <h3 id="api_history">History-related methods</h3>
1513
+
1514
+ <dl>
1515
+ <dt id="undo"><code><strong>doc.undo</strong>()</code></dt>
1516
+ <dd>Undo one edit (if any undo events are stored).</dd>
1517
+ <dt id="redo"><code><strong>doc.redo</strong>()</code></dt>
1518
+ <dd>Redo one undone edit.</dd>
1519
+
1520
+ <dt id="undoSelection"><code><strong>doc.undoSelection</strong>()</code></dt>
1521
+ <dd>Undo one edit or selection change.</dd>
1522
+ <dt id="redoSelection"><code><strong>doc.redoSelection</strong>()</code></dt>
1523
+ <dd>Redo one undone edit or selection change.</dd>
1524
+
1525
+ <dt id="historySize"><code><strong>doc.historySize</strong>() → {undo: integer, redo: integer}</code></dt>
1526
+ <dd>Returns an object with <code>{undo, redo}</code> properties,
1527
+ both of which hold integers, indicating the amount of stored
1528
+ undo and redo operations.</dd>
1529
+ <dt id="clearHistory"><code><strong>doc.clearHistory</strong>()</code></dt>
1530
+ <dd>Clears the editor's undo history.</dd>
1531
+ <dt id="getHistory"><code><strong>doc.getHistory</strong>() → object</code></dt>
1532
+ <dd>Get a (JSON-serializeable) representation of the undo history.</dd>
1533
+ <dt id="setHistory"><code><strong>doc.setHistory</strong>(history: object)</code></dt>
1534
+ <dd>Replace the editor's undo history with the one provided,
1535
+ which must be a value as returned
1536
+ by <a href="#getHistory"><code>getHistory</code></a>. Note that
1537
+ this will have entirely undefined results if the editor content
1538
+ isn't also the same as it was when <code>getHistory</code> was
1539
+ called.</dd>
1540
+ </dl>
1541
+
1542
+ <h3 id="api_marker">Text-marking methods</h3>
1543
+
1544
+ <dl>
1545
+ <dt id="markText"><code><strong>doc.markText</strong>(from: {line, ch}, to: {line, ch}, ?options: object) → TextMarker</code></dt>
1546
+ <dd>Can be used to mark a range of text with a specific CSS
1547
+ class name. <code>from</code> and <code>to</code> should
1548
+ be <code>{line, ch}</code> objects. The <code>options</code>
1549
+ parameter is optional. When given, it should be an object that
1550
+ may contain the following configuration options:
1551
+ <dl>
1552
+ <dt id="mark_className"><code><strong>className</strong>: string</code></dt>
1553
+ <dd>Assigns a CSS class to the marked stretch of text.</dd>
1554
+ <dt id="mark_inclusiveLeft"><code><strong>inclusiveLeft</strong>: boolean</code></dt>
1555
+ <dd>Determines whether
1556
+ text inserted on the left of the marker will end up inside
1557
+ or outside of it.</dd>
1558
+ <dt id="mark_inclusiveRight"><code><strong>inclusiveRight</strong>: boolean</code></dt>
1559
+ <dd>Like <code>inclusiveLeft</code>,
1560
+ but for the right side.</dd>
1561
+ <dt id="mark_atomic"><code><strong>atomic</strong>: boolean</code></dt>
1562
+ <dd>Atomic ranges act as a single unit when cursor movement is
1563
+ concerned—i.e. it is impossible to place the cursor inside of
1564
+ them. In atomic ranges, <code>inclusiveLeft</code>
1565
+ and <code>inclusiveRight</code> have a different meaning—they
1566
+ will prevent the cursor from being placed respectively
1567
+ directly before and directly after the range.</dd>
1568
+ <dt id="mark_collapsed"><code><strong>collapsed</strong>: boolean</code></dt>
1569
+ <dd>Collapsed ranges do not show up in the display. Setting a
1570
+ range to be collapsed will automatically make it atomic.</dd>
1571
+ <dt id="mark_clearOnEnter"><code><strong>clearOnEnter</strong>: boolean</code></dt>
1572
+ <dd>When enabled, will cause the mark to clear itself whenever
1573
+ the cursor enters its range. This is mostly useful for
1574
+ text-replacement widgets that need to 'snap open' when the
1575
+ user tries to edit them. The
1576
+ <a href="#event_clear"><code>"clear"</code></a> event
1577
+ fired on the range handle can be used to be notified when this
1578
+ happens.</dd>
1579
+ <dt id="mark_clearWhenEmpty"><code><strong>clearWhenEmpty</strong>: boolean</code></dt>
1580
+ <dd>Determines whether the mark is automatically cleared when
1581
+ it becomes empty. Default is true.</dd>
1582
+ <dt id="mark_replacedWith"><code><strong>replacedWith</strong>: Element</code></dt>
1583
+ <dd>Use a given node to display this range. Implies both
1584
+ collapsed and atomic. The given DOM node <em>must</em> be an
1585
+ inline element (as opposed to a block element).</dd>
1586
+ <dt><code><strong>handleMouseEvents</strong>: boolean</code></dt>
1587
+ <dd>When <code>replacedWith</code> is given, this determines
1588
+ whether the editor will capture mouse and drag events
1589
+ occurring in this widget. Default is false—the events will be
1590
+ left alone for the default browser handler, or specific
1591
+ handlers on the widget, to capture.</dd>
1592
+ <dt id="mark_readOnly"><code><strong>readOnly</strong>: boolean</code></dt>
1593
+ <dd>A read-only span can, as long as it is not cleared, not be
1594
+ modified except by
1595
+ calling <a href="#setValue"><code>setValue</code></a> to reset
1596
+ the whole document. <em>Note:</em> adding a read-only span
1597
+ currently clears the undo history of the editor, because
1598
+ existing undo events being partially nullified by read-only
1599
+ spans would corrupt the history (in the current
1600
+ implementation).</dd>
1601
+ <dt id="mark_addToHistory"><code><strong>addToHistory</strong>: boolean</code></dt>
1602
+ <dd>When set to true (default is false), adding this marker
1603
+ will create an event in the undo history that can be
1604
+ individually undone (clearing the marker).</dd>
1605
+ <dt id="mark_startStyle"><code><strong>startStyle</strong>: string</code></dt><dd>Can be used to specify
1606
+ an extra CSS class to be applied to the leftmost span that
1607
+ is part of the marker.</dd>
1608
+ <dt id="mark_endStyle"><code><strong>endStyle</strong>: string</code></dt><dd>Equivalent
1609
+ to <code>startStyle</code>, but for the rightmost span.</dd>
1610
+ <dt id="mark_css"><code><strong>css</strong>: string</code></dt>
1611
+ <dd>A string of CSS to be applied to the covered text. For example <code>"color: #fe3"</code>.</dd>
1612
+ <dt id="mark_title"><code><strong>title</strong>:
1613
+ string</code></dt><dd>When given, will give the nodes created
1614
+ for this span a HTML <code>title</code> attribute with the
1615
+ given value.</dd>
1616
+ <dt id="mark_shared"><code><strong>shared</strong>: boolean</code></dt><dd>When the
1617
+ target document is <a href="#linkedDoc">linked</a> to other
1618
+ documents, you can set <code>shared</code> to true to make the
1619
+ marker appear in all documents. By default, a marker appears
1620
+ only in its target document.</dd>
1621
+ </dl>
1622
+ The method will return an object that represents the marker
1623
+ (with constructor <code>CodeMirror.TextMarker</code>), which
1624
+ exposes three methods:
1625
+ <code><strong>clear</strong>()</code>, to remove the mark,
1626
+ <code><strong>find</strong>()</code>, which returns
1627
+ a <code>{from, to}</code> object (both holding document
1628
+ positions), indicating the current position of the marked range,
1629
+ or <code>undefined</code> if the marker is no longer in the
1630
+ document, and finally <code><strong>changed</strong>()</code>,
1631
+ which you can call if you've done something that might change
1632
+ the size of the marker (for example changing the content of
1633
+ a <a href="#mark_replacedWith"><code>replacedWith</code></a>
1634
+ node), and want to cheaply update the display.</dd>
1635
+
1636
+ <dt id="setBookmark"><code><strong>doc.setBookmark</strong>(pos: {line, ch}, ?options: object) → TextMarker</code></dt>
1637
+ <dd>Inserts a bookmark, a handle that follows the text around it
1638
+ as it is being edited, at the given position. A bookmark has two
1639
+ methods <code>find()</code> and <code>clear()</code>. The first
1640
+ returns the current position of the bookmark, if it is still in
1641
+ the document, and the second explicitly removes the bookmark.
1642
+ The options argument is optional. If given, the following
1643
+ properties are recognized:
1644
+ <dl>
1645
+ <dt><code><strong>widget</strong>: Element</code></dt><dd>Can be used to display a DOM
1646
+ node at the current location of the bookmark (analogous to
1647
+ the <a href="#mark_replacedWith"><code>replacedWith</code></a>
1648
+ option to <a href="#markText"><code>markText</code></a>).</dd>
1649
+ <dt><code><strong>insertLeft</strong>: boolean</code></dt><dd>By default, text typed
1650
+ when the cursor is on top of the bookmark will end up to the
1651
+ right of the bookmark. Set this option to true to make it go
1652
+ to the left instead.</dd>
1653
+ <dt><code><strong>shared</strong>: boolean</code></dt><dd>See
1654
+ the corresponding <a href="#mark_shared">option</a>
1655
+ to <code>markText</code>.</dd>
1656
+ <dt><code><strong>handleMouseEvents</strong>: boolean</code></dt>
1657
+ <dd>As with <a href="#markText"><code>markText</code></a>,
1658
+ this determines whether mouse events on the widget inserted
1659
+ for this bookmark are handled by CodeMirror. The default is
1660
+ false.</dd>
1661
+ </dl></dd>
1662
+
1663
+ <dt id="findMarks"><code><strong>doc.findMarks</strong>(from: {line, ch}, to: {line, ch}) → array&lt;TextMarker&gt;</code></dt>
1664
+ <dd>Returns an array of all the bookmarks and marked ranges
1665
+ found between the given positions.</dd>
1666
+ <dt id="findMarksAt"><code><strong>doc.findMarksAt</strong>(pos: {line, ch}) → array&lt;TextMarker&gt;</code></dt>
1667
+ <dd>Returns an array of all the bookmarks and marked ranges
1668
+ present at the given position.</dd>
1669
+ <dt id="getAllMarks"><code><strong>doc.getAllMarks</strong>() → array&lt;TextMarker&gt;</code></dt>
1670
+ <dd>Returns an array containing all marked ranges in the document.</dd>
1671
+ </dl>
1672
+
1673
+ <h3 id="api_decoration">Widget, gutter, and decoration methods</h3>
1674
+
1675
+ <dl>
1676
+ <dt id="setGutterMarker"><code><strong>cm.setGutterMarker</strong>(line: integer|LineHandle, gutterID: string, value: Element) → LineHandle</code></dt>
1677
+ <dd>Sets the gutter marker for the given gutter (identified by
1678
+ its CSS class, see
1679
+ the <a href="#option_gutters"><code>gutters</code></a> option)
1680
+ to the given value. Value can be either <code>null</code>, to
1681
+ clear the marker, or a DOM element, to set it. The DOM element
1682
+ will be shown in the specified gutter next to the specified
1683
+ line.</dd>
1684
+
1685
+ <dt id="clearGutter"><code><strong>cm.clearGutter</strong>(gutterID: string)</code></dt>
1686
+ <dd>Remove all gutter markers in
1687
+ the <a href="#option_gutters">gutter</a> with the given ID.</dd>
1688
+
1689
+ <dt id="addLineClass"><code><strong>doc.addLineClass</strong>(line: integer|LineHandle, where: string, class: string) → LineHandle</code></dt>
1690
+ <dd>Set a CSS class name for the given line. <code>line</code>
1691
+ can be a number or a line handle. <code>where</code> determines
1692
+ to which element this class should be applied, can can be one
1693
+ of <code>"text"</code> (the text element, which lies in front of
1694
+ the selection), <code>"background"</code> (a background element
1695
+ that will be behind the selection), <code>"gutter"</code> (the
1696
+ line's gutter space), or <code>"wrap"</code> (the wrapper node
1697
+ that wraps all of the line's elements, including gutter
1698
+ elements). <code>class</code> should be the name of the class to
1699
+ apply.</dd>
1700
+
1701
+ <dt id="removeLineClass"><code><strong>doc.removeLineClass</strong>(line: integer|LineHandle, where: string, class: string) → LineHandle</code></dt>
1702
+ <dd>Remove a CSS class from a line. <code>line</code> can be a
1703
+ line handle or number. <code>where</code> should be one
1704
+ of <code>"text"</code>, <code>"background"</code>,
1705
+ or <code>"wrap"</code>
1706
+ (see <a href="#addLineClass"><code>addLineClass</code></a>). <code>class</code>
1707
+ can be left off to remove all classes for the specified node, or
1708
+ be a string to remove only a specific class.</dd>
1709
+
1710
+ <dt id="lineInfo"><code><strong>cm.lineInfo</strong>(line: integer|LineHandle) → object</code></dt>
1711
+ <dd>Returns the line number, text content, and marker status of
1712
+ the given line, which can be either a number or a line handle.
1713
+ The returned object has the structure <code>{line, handle, text,
1714
+ gutterMarkers, textClass, bgClass, wrapClass, widgets}</code>,
1715
+ where <code>gutterMarkers</code> is an object mapping gutter IDs
1716
+ to marker elements, and <code>widgets</code> is an array
1717
+ of <a href="#addLineWidget">line widgets</a> attached to this
1718
+ line, and the various class properties refer to classes added
1719
+ with <a href="#addLineClass"><code>addLineClass</code></a>.</dd>
1720
+
1721
+ <dt id="addWidget"><code><strong>cm.addWidget</strong>(pos: {line, ch}, node: Element, scrollIntoView: boolean)</code></dt>
1722
+ <dd>Puts <code>node</code>, which should be an absolutely
1723
+ positioned DOM node, into the editor, positioned right below the
1724
+ given <code>{line, ch}</code> position.
1725
+ When <code>scrollIntoView</code> is true, the editor will ensure
1726
+ that the entire node is visible (if possible). To remove the
1727
+ widget again, simply use DOM methods (move it somewhere else, or
1728
+ call <code>removeChild</code> on its parent).</dd>
1729
+
1730
+ <dt id="addLineWidget"><code><strong>doc.addLineWidget</strong>(line: integer|LineHandle, node: Element, ?options: object) → LineWidget</code></dt>
1731
+ <dd>Adds a line widget, an element shown below a line, spanning
1732
+ the whole of the editor's width, and moving the lines below it
1733
+ downwards. <code>line</code> should be either an integer or a
1734
+ line handle, and <code>node</code> should be a DOM node, which
1735
+ will be displayed below the given line. <code>options</code>,
1736
+ when given, should be an object that configures the behavior of
1737
+ the widget. The following options are supported (all default to
1738
+ false):
1739
+ <dl>
1740
+ <dt><code><strong>coverGutter</strong>: boolean</code></dt>
1741
+ <dd>Whether the widget should cover the gutter.</dd>
1742
+ <dt><code><strong>noHScroll</strong>: boolean</code></dt>
1743
+ <dd>Whether the widget should stay fixed in the face of
1744
+ horizontal scrolling.</dd>
1745
+ <dt><code><strong>above</strong>: boolean</code></dt>
1746
+ <dd>Causes the widget to be placed above instead of below
1747
+ the text of the line.</dd>
1748
+ <dt><code><strong>handleMouseEvents</strong>: boolean</code></dt>
1749
+ <dd>Determines whether the editor will capture mouse and
1750
+ drag events occurring in this widget. Default is false—the
1751
+ events will be left alone for the default browser handler,
1752
+ or specific handlers on the widget, to capture.</dd>
1753
+ <dt><code><strong>insertAt</strong>: integer</code></dt>
1754
+ <dd>By default, the widget is added below other widgets for
1755
+ the line. This option can be used to place it at a different
1756
+ position (zero for the top, N to put it after the Nth other
1757
+ widget). Note that this only has effect once, when the
1758
+ widget is created.
1759
+ </dl>
1760
+ Note that the widget node will become a descendant of nodes with
1761
+ CodeMirror-specific CSS classes, and those classes might in some
1762
+ cases affect it. This method returns an object that represents
1763
+ the widget placement. It'll have a <code>line</code> property
1764
+ pointing at the line handle that it is associated with, and the following methods:
1765
+ <dl>
1766
+ <dt id="widget_clear"><code><strong>clear</strong>()</code></dt><dd>Removes the widget.</dd>
1767
+ <dt id="widget_changed"><code><strong>changed</strong>()</code></dt><dd>Call
1768
+ this if you made some change to the widget's DOM node that
1769
+ might affect its height. It'll force CodeMirror to update
1770
+ the height of the line that contains the widget.</dd>
1771
+ </dl>
1772
+ </dd>
1773
+ </dl>
1774
+
1775
+ <h3 id="api_sizing">Sizing, scrolling and positioning methods</h3>
1776
+
1777
+ <dl>
1778
+ <dt id="setSize"><code><strong>cm.setSize</strong>(width: number|string, height: number|string)</code></dt>
1779
+ <dd>Programatically set the size of the editor (overriding the
1780
+ applicable <a href="#css-resize">CSS
1781
+ rules</a>). <code>width</code> and <code>height</code>
1782
+ can be either numbers (interpreted as pixels) or CSS units
1783
+ (<code>"100%"</code>, for example). You can
1784
+ pass <code>null</code> for either of them to indicate that that
1785
+ dimension should not be changed.</dd>
1786
+
1787
+ <dt id="scrollTo"><code><strong>cm.scrollTo</strong>(x: number, y: number)</code></dt>
1788
+ <dd>Scroll the editor to a given (pixel) position. Both
1789
+ arguments may be left as <code>null</code>
1790
+ or <code>undefined</code> to have no effect.</dd>
1791
+ <dt id="getScrollInfo"><code><strong>cm.getScrollInfo</strong>() → {left, top, width, height, clientWidth, clientHeight}</code></dt>
1792
+ <dd>Get an <code>{left, top, width, height, clientWidth,
1793
+ clientHeight}</code> object that represents the current scroll
1794
+ position, the size of the scrollable area, and the size of the
1795
+ visible area (minus scrollbars).</dd>
1796
+ <dt id="scrollIntoView"><code><strong>cm.scrollIntoView</strong>(what: {line, ch}|{left, top, right, bottom}|{from, to}|null, ?margin: number)</code></dt>
1797
+ <dd>Scrolls the given position into view. <code>what</code> may
1798
+ be <code>null</code> to scroll the cursor into view,
1799
+ a <code>{line, ch}</code> position to scroll a character into
1800
+ view, a <code>{left, top, right, bottom}</code> pixel range (in
1801
+ editor-local coordinates), or a range <code>{from, to}</code>
1802
+ containing either two character positions or two pixel squares.
1803
+ The <code>margin</code> parameter is optional. When given, it
1804
+ indicates the amount of vertical pixels around the given area
1805
+ that should be made visible as well.</dd>
1806
+
1807
+ <dt id="cursorCoords"><code><strong>cm.cursorCoords</strong>(where: boolean|{line, ch}, mode: string) → {left, top, bottom}</code></dt>
1808
+ <dd>Returns an <code>{left, top, bottom}</code> object
1809
+ containing the coordinates of the cursor position.
1810
+ If <code>mode</code> is <code>"local"</code>, they will be
1811
+ relative to the top-left corner of the editable document. If it
1812
+ is <code>"page"</code> or not given, they are relative to the
1813
+ top-left corner of the page. If <code>mode</code>
1814
+ is <code>"window"</code>, the coordinates are relative to the
1815
+ top-left corner of the currently visible (scrolled)
1816
+ window. <code>where</code> can be a boolean indicating whether
1817
+ you want the start (<code>true</code>) or the end
1818
+ (<code>false</code>) of the selection, or, if a <code>{line,
1819
+ ch}</code> object is given, it specifies the precise position at
1820
+ which you want to measure.</dd>
1821
+ <dt id="charCoords"><code><strong>cm.charCoords</strong>(pos: {line, ch}, ?mode: string) → {left, right, top, bottom}</code></dt>
1822
+ <dd>Returns the position and dimensions of an arbitrary
1823
+ character. <code>pos</code> should be a <code>{line, ch}</code>
1824
+ object. This differs from <code>cursorCoords</code> in that
1825
+ it'll give the size of the whole character, rather than just the
1826
+ position that the cursor would have when it would sit at that
1827
+ position.</dd>
1828
+ <dt id="coordsChar"><code><strong>cm.coordsChar</strong>(object: {left, top}, ?mode: string) → {line, ch}</code></dt>
1829
+ <dd>Given an <code>{left, top}</code> object, returns
1830
+ the <code>{line, ch}</code> position that corresponds to it. The
1831
+ optional <code>mode</code> parameter determines relative to what
1832
+ the coordinates are interpreted. It may
1833
+ be <code>"window"</code>, <code>"page"</code> (the default),
1834
+ or <code>"local"</code>.</dd>
1835
+ <dt id="lineAtHeight"><code><strong>cm.lineAtHeight</strong>(height: number, ?mode: string) → number</code></dt>
1836
+ <dd>Computes the line at the given pixel
1837
+ height. <code>mode</code> can be one of the same strings
1838
+ that <a href="#coordsChar"><code>coordsChar</code></a>
1839
+ accepts.</dd>
1840
+ <dt id="heightAtLine"><code><strong>cm.heightAtLine</strong>(line: integer|LineHandle, ?mode: string) → number</code></dt>
1841
+ <dd>Computes the height of the top of a line, in the coordinate
1842
+ system specified by <code>mode</code>
1843
+ (see <a href="#coordsChar"><code>coordsChar</code></a>), which
1844
+ defaults to <code>"page"</code>. When a line below the bottom of
1845
+ the document is specified, the returned value is the bottom of
1846
+ the last line in the document.</dd>
1847
+ <dt id="defaultTextHeight"><code><strong>cm.defaultTextHeight</strong>() → number</code></dt>
1848
+ <dd>Returns the line height of the default font for the editor.</dd>
1849
+ <dt id="defaultCharWidth"><code><strong>cm.defaultCharWidth</strong>() → number</code></dt>
1850
+ <dd>Returns the pixel width of an 'x' in the default font for
1851
+ the editor. (Note that for non-monospace fonts, this is mostly
1852
+ useless, and even for monospace fonts, non-ascii characters
1853
+ might have a different width).</dd>
1854
+
1855
+ <dt id="getViewport"><code><strong>cm.getViewport</strong>() → {from: number, to: number}</code></dt>
1856
+ <dd>Returns a <code>{from, to}</code> object indicating the
1857
+ start (inclusive) and end (exclusive) of the currently rendered
1858
+ part of the document. In big documents, when most content is
1859
+ scrolled out of view, CodeMirror will only render the visible
1860
+ part, and a margin around it. See also
1861
+ the <a href="#event_viewportChange"><code>viewportChange</code></a>
1862
+ event.</dd>
1863
+
1864
+ <dt id="refresh"><code><strong>cm.refresh</strong>()</code></dt>
1865
+ <dd>If your code does something to change the size of the editor
1866
+ element (window resizes are already listened for), or unhides
1867
+ it, you should probably follow up by calling this method to
1868
+ ensure CodeMirror is still looking as intended.</dd>
1869
+ </dl>
1870
+
1871
+ <h3 id="api_mode">Mode, state, and token-related methods</h3>
1872
+
1873
+ <p>When writing language-aware functionality, it can often be
1874
+ useful to hook into the knowledge that the CodeMirror language
1875
+ mode has. See <a href="#modeapi">the section on modes</a> for a
1876
+ more detailed description of how these work.</p>
1877
+
1878
+ <dl>
1879
+ <dt id="getMode"><code><strong>doc.getMode</strong>() → object</code></dt>
1880
+ <dd>Gets the (outer) mode object for the editor. Note that this
1881
+ is distinct from <code>getOption("mode")</code>, which gives you
1882
+ the mode specification, rather than the resolved, instantiated
1883
+ <a href="#defineMode">mode object</a>.</dd>
1884
+
1885
+ <dt id="getModeAt"><code><strong>cm.getModeAt</strong>(pos: {line, ch}) → object</code></dt>
1886
+ <dd>Gets the inner mode at a given position. This will return
1887
+ the same as <a href="#getMode"><code>getMode</code></a> for
1888
+ simple modes, but will return an inner mode for nesting modes
1889
+ (such as <code>htmlmixed</code>).</dd>
1890
+
1891
+ <dt id="getTokenAt"><code><strong>cm.getTokenAt</strong>(pos: {line, ch}, ?precise: boolean) → object</code></dt>
1892
+ <dd>Retrieves information about the token the current mode found
1893
+ before the given position (a <code>{line, ch}</code> object). The
1894
+ returned object has the following properties:
1895
+ <dl>
1896
+ <dt><code><strong>start</strong></code></dt><dd>The character (on the given line) at which the token starts.</dd>
1897
+ <dt><code><strong>end</strong></code></dt><dd>The character at which the token ends.</dd>
1898
+ <dt><code><strong>string</strong></code></dt><dd>The token's string.</dd>
1899
+ <dt><code><strong>type</strong></code></dt><dd>The token type the mode assigned
1900
+ to the token, such as <code>"keyword"</code>
1901
+ or <code>"comment"</code> (may also be null).</dd>
1902
+ <dt><code><strong>state</strong></code></dt><dd>The mode's state at the end of this token.</dd>
1903
+ </dl>
1904
+ If <code>precise</code> is true, the token will be guaranteed to be accurate based on recent edits. If false or
1905
+ not specified, the token will use cached state information, which will be faster but might not be accurate if
1906
+ edits were recently made and highlighting has not yet completed.
1907
+ </dd>
1908
+
1909
+ <dt id="getLineTokens"><code><strong>cm.getLineTokens</strong>(line: integer, ?precise: boolean) → array&lt;{start, end, string, type, state}&gt;</code></dt>
1910
+ <dd>This is similar
1911
+ to <a href="#getTokenAt"><code>getTokenAt</code></a>, but
1912
+ collects all tokens for a given line into an array. It is much
1913
+ cheaper than repeatedly calling <code>getTokenAt</code>, which
1914
+ re-parses the part of the line before the token for every call.</dd>
1915
+
1916
+ <dt id="getTokenTypeAt"><code><strong>cm.getTokenTypeAt</strong>(pos: {line, ch}) → string</code></dt>
1917
+ <dd>This is a (much) cheaper version
1918
+ of <a href="#getTokenAt"><code>getTokenAt</code></a> useful for
1919
+ when you just need the type of the token at a given position,
1920
+ and no other information. Will return <code>null</code> for
1921
+ unstyled tokens, and a string, potentially containing multiple
1922
+ space-separated style names, otherwise.</dd>
1923
+
1924
+ <dt id="getHelpers"><code><strong>cm.getHelpers</strong>(pos: {line, ch}, type: string) → array&lt;helper&gt;</code></dt>
1925
+ <dd>Fetch the set of applicable helper values for the given
1926
+ position. Helpers provide a way to look up functionality
1927
+ appropriate for a mode. The <code>type</code> argument provides
1928
+ the helper namespace (see
1929
+ <a href="#registerHelper"><code>registerHelper</code></a>), in
1930
+ which the values will be looked up. When the mode itself has a
1931
+ property that corresponds to the <code>type</code>, that
1932
+ directly determines the keys that are used to look up the helper
1933
+ values (it may be either a single string, or an array of
1934
+ strings). Failing that, the mode's <code>helperType</code>
1935
+ property and finally the mode's name are used.</dd>
1936
+ <dd>For example, the JavaScript mode has a
1937
+ property <code>fold</code> containing <code>"brace"</code>. When
1938
+ the <code>brace-fold</code> addon is loaded, that defines a
1939
+ helper named <code>brace</code> in the <code>fold</code>
1940
+ namespace. This is then used by
1941
+ the <a href="#addon_foldcode"><code>foldcode</code></a> addon to
1942
+ figure out that it can use that folding function to fold
1943
+ JavaScript code.</dd>
1944
+ <dd>When any <a href="#registerGlobalHelper">'global'</a>
1945
+ helpers are defined for the given namespace, their predicates
1946
+ are called on the current mode and editor, and all those that
1947
+ declare they are applicable will also be added to the array that
1948
+ is returned.</dd>
1949
+
1950
+ <dt id="getHelper"><code><strong>cm.getHelper</strong>(pos: {line, ch}, type: string) → helper</code></dt>
1951
+ <dd>Returns the first applicable helper value.
1952
+ See <a href="#getHelpers"><code>getHelpers</code></a>.</dd>
1953
+
1954
+ <dt id="getStateAfter"><code><strong>cm.getStateAfter</strong>(?line: integer, ?precise: boolean) → object</code></dt>
1955
+ <dd>Returns the mode's parser state, if any, at the end of the
1956
+ given line number. If no line number is given, the state at the
1957
+ end of the document is returned. This can be useful for storing
1958
+ parsing errors in the state, or getting other kinds of
1959
+ contextual information for a line. <code>precise</code> is defined
1960
+ as in <code>getTokenAt()</code>.</dd>
1961
+ </dl>
1962
+
1963
+ <h3 id="api_misc">Miscellaneous methods</h3>
1964
+
1965
+ <dl>
1966
+ <dt id="operation"><code><strong>cm.operation</strong>(func: () → any) → any</code></dt>
1967
+ <dd>CodeMirror internally buffers changes and only updates its
1968
+ DOM structure after it has finished performing some operation.
1969
+ If you need to perform a lot of operations on a CodeMirror
1970
+ instance, you can call this method with a function argument. It
1971
+ will call the function, buffering up all changes, and only doing
1972
+ the expensive update after the function returns. This can be a
1973
+ lot faster. The return value from this method will be the return
1974
+ value of your function.</dd>
1975
+
1976
+ <dt id="indentLine"><code><strong>cm.indentLine</strong>(line: integer, ?dir: string|integer)</code></dt>
1977
+ <dd>Adjust the indentation of the given line. The second
1978
+ argument (which defaults to <code>"smart"</code>) may be one of:
1979
+ <dl>
1980
+ <dt><code><strong>"prev"</strong></code></dt>
1981
+ <dd>Base indentation on the indentation of the previous line.</dd>
1982
+ <dt><code><strong>"smart"</strong></code></dt>
1983
+ <dd>Use the mode's smart indentation if available, behave
1984
+ like <code>"prev"</code> otherwise.</dd>
1985
+ <dt><code><strong>"add"</strong></code></dt>
1986
+ <dd>Increase the indentation of the line by
1987
+ one <a href="#option_indentUnit">indent unit</a>.</dd>
1988
+ <dt><code><strong>"subtract"</strong></code></dt>
1989
+ <dd>Reduce the indentation of the line.</dd>
1990
+ <dt><code><strong>&lt;integer></strong></code></dt>
1991
+ <dd>Add (positive number) or reduce (negative number) the
1992
+ indentation by the given amount of spaces.</dd>
1993
+ </dl></dd>
1994
+
1995
+ <dt id="toggleOverwrite"><code><strong>cm.toggleOverwrite</strong>(?value: bool)</code></dt>
1996
+ <dd>Switches between overwrite and normal insert mode (when not
1997
+ given an argument), or sets the overwrite mode to a specific
1998
+ state (when given an argument).</dd>
1999
+
2000
+ <dt id="lineSeparator"><code><strong>doc.lineSeparator</strong>()</code></dt>
2001
+ <dd>Returns the preferred line separator string for this
2002
+ document, as per the <a href="#option_lineSeparator">option</a>
2003
+ by the same name. When that option is <code>null</code>, the
2004
+ string <code>"\n"</code> is returned.</dd>
2005
+
2006
+ <dt id="execCommand"><code><strong>cm.execCommand</strong>(name: string)</code></dt>
2007
+ <dd>Runs the <a href="#commands">command</a> with the given name on the editor.</dd>
2008
+
2009
+ <dt id="posFromIndex"><code><strong>doc.posFromIndex</strong>(index: integer) → {line, ch}</code></dt>
2010
+ <dd>Calculates and returns a <code>{line, ch}</code> object for a
2011
+ zero-based <code>index</code> who's value is relative to the start of the
2012
+ editor's text. If the <code>index</code> is out of range of the text then
2013
+ the returned object is clipped to start or end of the text
2014
+ respectively.</dd>
2015
+ <dt id="indexFromPos"><code><strong>doc.indexFromPos</strong>(object: {line, ch}) → integer</code></dt>
2016
+ <dd>The reverse of <a href="#posFromIndex"><code>posFromIndex</code></a>.</dd>
2017
+
2018
+ <dt id="focus"><code><strong>cm.focus</strong>()</code></dt>
2019
+ <dd>Give the editor focus.</dd>
2020
+
2021
+ <dt id="getInputField"><code><strong>cm.getInputField</strong>() → Element</code></dt>
2022
+ <dd>Returns the input field for the editor. Will be a textarea
2023
+ or an editable div, depending on the value of
2024
+ the <a href="#option_inputStyle"><code>inputStyle</code></a>
2025
+ option.</dd>
2026
+ <dt id="getWrapperElement"><code><strong>cm.getWrapperElement</strong>() → Element</code></dt>
2027
+ <dd>Returns the DOM node that represents the editor, and
2028
+ controls its size. Remove this from your tree to delete an
2029
+ editor instance.</dd>
2030
+ <dt id="getScrollerElement"><code><strong>cm.getScrollerElement</strong>() → Element</code></dt>
2031
+ <dd>Returns the DOM node that is responsible for the scrolling
2032
+ of the editor.</dd>
2033
+ <dt id="getGutterElement"><code><strong>cm.getGutterElement</strong>() → Element</code></dt>
2034
+ <dd>Fetches the DOM node that contains the editor gutters.</dd>
2035
+ </dl>
2036
+
2037
+ <h3 id="api_static">Static properties</h3>
2038
+ <p>The <code>CodeMirror</code> object itself provides
2039
+ several useful properties.</p>
2040
+
2041
+ <dl>
2042
+ <dt id="version"><code><strong>CodeMirror.version</strong>: string</code></dt>
2043
+ <dd>It contains a string that indicates the version of the
2044
+ library. This is a triple of
2045
+ integers <code>"major.minor.patch"</code>,
2046
+ where <code>patch</code> is zero for releases, and something
2047
+ else (usually one) for dev snapshots.</dd>
2048
+
2049
+ <dt id="fromTextArea"><code><strong>CodeMirror.fromTextArea</strong>(textArea: TextAreaElement, ?config: object)</code></dt>
2050
+ <dd>
2051
+ The method provides another way to initialize an editor. It
2052
+ takes a textarea DOM node as first argument and an optional
2053
+ configuration object as second. It will replace the textarea
2054
+ with a CodeMirror instance, and wire up the form of that
2055
+ textarea (if any) to make sure the editor contents are put
2056
+ into the textarea when the form is submitted. The text in the
2057
+ textarea will provide the content for the editor. A CodeMirror
2058
+ instance created this way has three additional methods:
2059
+ <dl>
2060
+ <dt id="save"><code><strong>cm.save</strong>()</code></dt>
2061
+ <dd>Copy the content of the editor into the textarea.</dd>
2062
+
2063
+ <dt id="toTextArea"><code><strong>cm.toTextArea</strong>()</code></dt>
2064
+ <dd>Remove the editor, and restore the original textarea (with
2065
+ the editor's current content).</dd>
2066
+
2067
+ <dt id="getTextArea"><code><strong>cm.getTextArea</strong>() → TextAreaElement</code></dt>
2068
+ <dd>Returns the textarea that the instance was based on.</dd>
2069
+ </dl>
2070
+ </dd>
2071
+
2072
+ <dt id="defaults"><code><strong>CodeMirror.defaults</strong>: object</code></dt>
2073
+ <dd>An object containing default values for
2074
+ all <a href="#config">options</a>. You can assign to its
2075
+ properties to modify defaults (though this won't affect editors
2076
+ that have already been created).</dd>
2077
+
2078
+ <dt id="defineExtension"><code><strong>CodeMirror.defineExtension</strong>(name: string, value: any)</code></dt>
2079
+ <dd>If you want to define extra methods in terms of the
2080
+ CodeMirror API, it is possible to
2081
+ use <code>defineExtension</code>. This will cause the given
2082
+ value (usually a method) to be added to all CodeMirror instances
2083
+ created from then on.</dd>
2084
+
2085
+ <dt id="defineDocExtension"><code><strong>CodeMirror.defineDocExtension</strong>(name: string, value: any)</code></dt>
2086
+ <dd>Like <a href="#defineExtenstion"><code>defineExtension</code></a>,
2087
+ but the method will be added to the interface
2088
+ for <a href="#Doc"><code>Doc</code></a> objects instead.</dd>
2089
+
2090
+ <dt id="defineOption"><code><strong>CodeMirror.defineOption</strong>(name: string,
2091
+ default: any, updateFunc: function)</code></dt>
2092
+ <dd>Similarly, <code>defineOption</code> can be used to define new options for
2093
+ CodeMirror. The <code>updateFunc</code> will be called with the
2094
+ editor instance and the new value when an editor is initialized,
2095
+ and whenever the option is modified
2096
+ through <a href="#setOption"><code>setOption</code></a>.</dd>
2097
+
2098
+ <dt id="defineInitHook"><code><strong>CodeMirror.defineInitHook</strong>(func: function)</code></dt>
2099
+ <dd>If your extention just needs to run some
2100
+ code whenever a CodeMirror instance is initialized,
2101
+ use <code>CodeMirror.defineInitHook</code>. Give it a function as
2102
+ its only argument, and from then on, that function will be called
2103
+ (with the instance as argument) whenever a new CodeMirror instance
2104
+ is initialized.</dd>
2105
+
2106
+ <dt id="registerHelper"><code><strong>CodeMirror.registerHelper</strong>(type: string, name: string, value: helper)</code></dt>
2107
+ <dd>Registers a helper value with the given <code>name</code> in
2108
+ the given namespace (<code>type</code>). This is used to define
2109
+ functionality that may be looked up by mode. Will create (if it
2110
+ doesn't already exist) a property on the <code>CodeMirror</code>
2111
+ object for the given <code>type</code>, pointing to an object
2112
+ that maps names to values. I.e. after
2113
+ doing <code>CodeMirror.registerHelper("hint", "foo",
2114
+ myFoo)</code>, the value <code>CodeMirror.hint.foo</code> will
2115
+ point to <code>myFoo</code>.</dd>
2116
+
2117
+ <dt id="registerGlobalHelper"><code><strong>CodeMirror.registerGlobalHelper</strong>(type: string, name: string, predicate: fn(mode, CodeMirror), value: helper)</code></dt>
2118
+ <dd>Acts
2119
+ like <a href="#registerHelper"><code>registerHelper</code></a>,
2120
+ but also registers this helper as 'global', meaning that it will
2121
+ be included by <a href="#getHelpers"><code>getHelpers</code></a>
2122
+ whenever the given <code>predicate</code> returns true when
2123
+ called with the local mode and editor.</dd>
2124
+
2125
+ <dt id="Pos"><code><strong>CodeMirror.Pos</strong>(line: integer, ?ch: integer)</code></dt>
2126
+ <dd>A constructor for the <code>{line, ch}</code> objects that
2127
+ are used to represent positions in editor documents.</dd>
2128
+
2129
+ <dt id="changeEnd"><code><strong>CodeMirror.changeEnd</strong>(change: object) → {line, ch}</code></dt>
2130
+ <dd>Utility function that computes an end position from a change
2131
+ (an object with <code>from</code>, <code>to</code>,
2132
+ and <code>text</code> properties, as passed to
2133
+ various <a href="#event_change">event handlers</a>). The
2134
+ returned position will be the end of the changed
2135
+ range, <em>after</em> the change is applied.</dd>
2136
+ </dl>
2137
+ </section>
2138
+
2139
+ <section id=addons>
2140
+ <h2 id="addons">Addons</h2>
2141
+
2142
+ <p>The <code>addon</code> directory in the distribution contains a
2143
+ number of reusable components that implement extra editor
2144
+ functionality (on top of extension functions
2145
+ like <a href="#defineOption"><code>defineOption</code></a>, <a href="#defineExtension"><code>defineExtension</code></a>,
2146
+ and <a href="#registerHelper"><code>registerHelper</code></a>). In
2147
+ brief, they are:</p>
2148
+
2149
+ <dl>
2150
+ <dt id="addon_dialog"><a href="../addon/dialog/dialog.js"><code>dialog/dialog.js</code></a></dt>
2151
+ <dd>Provides a very simple way to query users for text input.
2152
+ Adds the <strong><code>openDialog(template, callback, options) →
2153
+ closeFunction</code></strong> method to CodeMirror instances,
2154
+ which can be called with an HTML fragment or a detached DOM
2155
+ node that provides the prompt (should include an <code>input</code>
2156
+ or <code>button</code> tag), and a callback function that is called
2157
+ when the user presses enter. It returns a function <code>closeFunction</code>
2158
+ which, if called, will close the dialog immediately.
2159
+ <strong><code>openDialog</code></strong> takes the following options:
2160
+ <dl>
2161
+ <dt><code><strong>closeOnEnter</strong></code>:</dt>
2162
+ <dd>If true, the dialog will be closed when the user presses
2163
+ enter in the input. Defaults to <code>true</code>.</dd>
2164
+ <dt><code><strong>onKeyDown</strong></code>:</dt>
2165
+ <dd>An event handler of the signature <code>(event, value, closeFunction)</code>
2166
+ that will be called whenever <code>keydown</code> fires in the
2167
+ dialog's input. If your callback returns <code>true</code>,
2168
+ the dialog will not do any further processing of the event.</dd>
2169
+ <dt><code><strong>onKeyUp</strong></code>:</dt>
2170
+ <dd>Same as <code>onKeyDown</code> but for the
2171
+ <code>keyup</code> event.</dd>
2172
+ <dt><code><strong>onInput</strong></code>:</dt>
2173
+ <dd>Same as <code>onKeyDown</code> but for the
2174
+ <code>input</code> event.</dd>
2175
+ <dt><code><strong>onClose</strong></code>:</dt>
2176
+ <dd>A callback of the signature <code>(dialogInstance)</code>
2177
+ that will be called after the dialog has been closed and
2178
+ removed from the DOM. No return value.</dd>
2179
+ </dl>
2180
+
2181
+ <p>Also adds an <strong><code>openNotification(template, options) →
2182
+ closeFunction</code></strong> function that simply shows an HTML
2183
+ fragment as a notification at the top of the editor. It takes a
2184
+ single option: <code>duration</code>, the amount of time after
2185
+ which the notification will be automatically closed. If <code>
2186
+ duration</code> is zero, the dialog will not be closed automatically.</p>
2187
+
2188
+ <p>Depends on <code>addon/dialog/dialog.css</code>.</p></dd>
2189
+
2190
+ <dt id="addon_searchcursor"><a href="../addon/search/searchcursor.js"><code>search/searchcursor.js</code></a></dt>
2191
+ <dd>Adds the <code>getSearchCursor(query, start, caseFold) →
2192
+ cursor</code> method to CodeMirror instances, which can be used
2193
+ to implement search/replace functionality. <code>query</code>
2194
+ can be a regular expression or a string (only strings will match
2195
+ across lines—if they contain newlines). <code>start</code>
2196
+ provides the starting position of the search. It can be
2197
+ a <code>{line, ch}</code> object, or can be left off to default
2198
+ to the start of the document. <code>caseFold</code> is only
2199
+ relevant when matching a string. It will cause the search to be
2200
+ case-insensitive. A search cursor has the following methods:
2201
+ <dl>
2202
+ <dt><code><strong>findNext</strong>() → boolean</code></dt>
2203
+ <dt><code><strong>findPrevious</strong>() → boolean</code></dt>
2204
+ <dd>Search forward or backward from the current position.
2205
+ The return value indicates whether a match was found. If
2206
+ matching a regular expression, the return value will be the
2207
+ array returned by the <code>match</code> method, in case you
2208
+ want to extract matched groups.</dd>
2209
+ <dt><code><strong>from</strong>() → {line, ch}</code></dt>
2210
+ <dt><code><strong>to</strong>() → {line, ch}</code></dt>
2211
+ <dd>These are only valid when the last call
2212
+ to <code>findNext</code> or <code>findPrevious</code> did
2213
+ not return false. They will return <code>{line, ch}</code>
2214
+ objects pointing at the start and end of the match.</dd>
2215
+ <dt><code><strong>replace</strong>(text: string, ?origin: string)</code></dt>
2216
+ <dd>Replaces the currently found match with the given text
2217
+ and adjusts the cursor position to reflect the
2218
+ replacement.</dd>
2219
+ </dl></dd>
2220
+
2221
+ <dt id="addon_search"><a href="../addon/search/search.js"><code>search/search.js</code></a></dt>
2222
+ <dd>Implements the search commands. CodeMirror has keys bound to
2223
+ these by default, but will not do anything with them unless an
2224
+ implementation is provided. Depends
2225
+ on <code>searchcursor.js</code>, and will make use
2226
+ of <a href="#addon_dialog"><code>openDialog</code></a> when
2227
+ available to make prompting for search queries less ugly.</dd>
2228
+
2229
+ <dt id="addon_matchesonscrollbar"><a href="../addon/search/matchesonscrollbar.js"><code>search/matchesonscrollbar.js</code></a></dt>
2230
+ <dd>Adds a <code>showMatchesOnScrollbar</code> method to editor
2231
+ instances, which should be given a query (string or regular
2232
+ expression), optionally a case-fold flag (only applicable for
2233
+ strings), and optionally a class name (defaults
2234
+ to <code>CodeMirror-search-match</code>) as arguments. When
2235
+ called, matches of the given query will be displayed on the
2236
+ editor's vertical scrollbar. The method returns an object with
2237
+ a <code>clear</code> method that can be called to remove the
2238
+ matches. Depends on
2239
+ the <a href="#addon_annotatescrollbar"><code>annotatescrollbar</code></a>
2240
+ addon, and
2241
+ the <a href="../addon/search/matchesonscrollbar.css"><code>matchesonscrollbar.css</code></a>
2242
+ file provides a default (transparent yellowish) definition of
2243
+ the CSS class applied to the matches. Note that the matches are
2244
+ only perfectly aligned if your scrollbar does not have buttons
2245
+ at the top and bottom. You can use
2246
+ the <a href="#addon_simplescrollbars"><code>simplescrollbar</code></a>
2247
+ addon to make sure of this. If this addon is loaded,
2248
+ the <a href="#addon_search"><code>search</code></a> addon will
2249
+ automatically use it.</dd>
2250
+
2251
+ <dt id="addon_matchbrackets"><a href="../addon/edit/matchbrackets.js"><code>edit/matchbrackets.js</code></a></dt>
2252
+ <dd>Defines an option <code>matchBrackets</code> which, when set
2253
+ to true, causes matching brackets to be highlighted whenever the
2254
+ cursor is next to them. It also adds a
2255
+ method <code>matchBrackets</code> that forces this to happen
2256
+ once, and a method <code>findMatchingBracket</code> that can be
2257
+ used to run the bracket-finding algorithm that this uses
2258
+ internally.</dd>
2259
+
2260
+ <dt id="addon_closebrackets"><a href="../addon/edit/closebrackets.js"><code>edit/closebrackets.js</code></a></dt>
2261
+ <dd>Defines an option <code>autoCloseBrackets</code> that will
2262
+ auto-close brackets and quotes when typed. By default, it'll
2263
+ auto-close <code>()[]{}''""</code>, but you can pass it a string
2264
+ similar to that (containing pairs of matching characters), or an
2265
+ object with <code>pairs</code> and
2266
+ optionally <code>explode</code> properties to customize
2267
+ it. <code>explode</code> should be a similar string that gives
2268
+ the pairs of characters that, when enter is pressed between
2269
+ them, should have the second character also moved to its own
2270
+ line. <a href="../demo/closebrackets.html">Demo here</a>.</dd>
2271
+
2272
+ <dt id="addon_matchtags"><a href="../addon/edit/matchtags.js"><code>edit/matchtags.js</code></a></dt>
2273
+ <dd>Defines an option <code>matchTags</code> that, when enabled,
2274
+ will cause the tags around the cursor to be highlighted (using
2275
+ the <code>CodeMirror-matchingtag</code> class). Also
2276
+ defines
2277
+ a <a href="#commands">command</a> <code>toMatchingTag</code>,
2278
+ which you can bind a key to in order to jump to the tag mathing
2279
+ the one under the cursor. Depends on
2280
+ the <code>addon/fold/xml-fold.js</code>
2281
+ addon. <a href="../demo/matchtags.html">Demo here.</a></dd>
2282
+
2283
+ <dt id="addon_trailingspace"><a href="../addon/edit/trailingspace.js"><code>edit/trailingspace.js</code></a></dt>
2284
+ <dd>Adds an option <code>showTrailingSpace</code> which, when
2285
+ enabled, adds the CSS class <code>cm-trailingspace</code> to
2286
+ stretches of whitespace at the end of lines.
2287
+ The <a href="../demo/trailingspace.html">demo</a> has a nice
2288
+ squiggly underline style for this class.</dd>
2289
+
2290
+ <dt id="addon_closetag"><a href="../addon/edit/closetag.js"><code>edit/closetag.js</code></a></dt>
2291
+ <dd>Defines an <code>autoCloseTags</code> option that will
2292
+ auto-close XML tags when '<code>&gt;</code>' or '<code>/</code>'
2293
+ is typed, and
2294
+ a <code>closeTag</code> <a href="#commands">command</a> that
2295
+ closes the nearest open tag. Depends on
2296
+ the <code>fold/xml-fold.js</code> addon. See
2297
+ the <a href="../demo/closetag.html">demo</a>.</dd>
2298
+
2299
+ <dt id="addon_continuelist"><a href="../addon/edit/continuelist.js"><code>edit/continuelist.js</code></a></dt>
2300
+ <dd>Markdown specific. Defines
2301
+ a <code>"newlineAndIndentContinueMarkdownList"</code> <a href="#commands">command</a>
2302
+ command that can be bound to <code>enter</code> to automatically
2303
+ insert the leading characters for continuing a list. See
2304
+ the <a href="../mode/markdown/index.html">Markdown mode
2305
+ demo</a>.</dd>
2306
+
2307
+ <dt id="addon_comment"><a href="../addon/comment/comment.js"><code>comment/comment.js</code></a></dt>
2308
+ <dd>Addon for commenting and uncommenting code. Adds three
2309
+ methods to CodeMirror instances:
2310
+ <dl>
2311
+ <dt id="lineComment"><code><strong>lineComment</strong>(from: {line, ch}, to: {line, ch}, ?options: object)</code></dt>
2312
+ <dd>Set the lines in the given range to be line comments. Will
2313
+ fall back to <code>blockComment</code> when no line comment
2314
+ style is defined for the mode.</dd>
2315
+ <dt id="blockComment"><code><strong>blockComment</strong>(from: {line, ch}, to: {line, ch}, ?options: object)</code></dt>
2316
+ <dd>Wrap the code in the given range in a block comment. Will
2317
+ fall back to <code>lineComment</code> when no block comment
2318
+ style is defined for the mode.</dd>
2319
+ <dt id="uncomment"><code><strong>uncomment</strong>(from: {line, ch}, to: {line, ch}, ?options: object) → boolean</code></dt>
2320
+ <dd>Try to uncomment the given range.
2321
+ Returns <code>true</code> if a comment range was found and
2322
+ removed, <code>false</code> otherwise.</dd>
2323
+ </dl>
2324
+ The <code>options</code> object accepted by these methods may
2325
+ have the following properties:
2326
+ <dl>
2327
+ <dt><code>blockCommentStart, blockCommentEnd, blockCommentLead, lineComment: string</code></dt>
2328
+ <dd>Override the <a href="#mode_comment">comment string
2329
+ properties</a> of the mode with custom comment strings.</dd>
2330
+ <dt><code><strong>padding</strong>: string</code></dt>
2331
+ <dd>A string that will be inserted after opening and leading
2332
+ markers, and before closing comment markers. Defaults to a
2333
+ single space.</dd>
2334
+ <dt><code><strong>commentBlankLines</strong>: boolean</code></dt>
2335
+ <dd>Whether, when adding line comments, to also comment lines
2336
+ that contain only whitespace.</dd>
2337
+ <dt><code><strong>indent</strong>: boolean</code></dt>
2338
+ <dd>When adding line comments and this is turned on, it will
2339
+ align the comment block to the current indentation of the
2340
+ first line of the block.</dd>
2341
+ <dt><code><strong>fullLines</strong>: boolean</code></dt>
2342
+ <dd>When block commenting, this controls whether the whole
2343
+ lines are indented, or only the precise range that is given.
2344
+ Defaults to <code>true</code>.</dd>
2345
+ </dl>
2346
+ The addon also defines
2347
+ a <code>toggleComment</code> <a href="#commands">command</a>,
2348
+ which will try to uncomment the current selection, and if that
2349
+ fails, line-comments it.</dd>
2350
+
2351
+ <dt id="addon_foldcode"><a href="../addon/fold/foldcode.js"><code>fold/foldcode.js</code></a></dt>
2352
+ <dd>Helps with code folding. Adds a <code>foldCode</code> method
2353
+ to editor instances, which will try to do a code fold starting
2354
+ at the given line, or unfold the fold that is already present.
2355
+ The method takes as first argument the position that should be
2356
+ folded (may be a line number or
2357
+ a <a href="#Pos"><code>Pos</code></a>), and as second optional
2358
+ argument either a range-finder function, or an options object,
2359
+ supporting the following properties:
2360
+ <dl>
2361
+ <dt><code><strong>rangeFinder</strong>: fn(CodeMirror, Pos)</code></dt>
2362
+ <dd id="helper_fold_auto">The function that is used to find
2363
+ foldable ranges. If this is not directly passed, it will
2364
+ default to <code>CodeMirror.fold.auto</code>, which
2365
+ uses <a href="#getHelpers"><code>getHelpers</code></a> with
2366
+ a <code>"fold"</code> type to find folding functions
2367
+ appropriate for the local mode. There are files in
2368
+ the <a href="../addon/fold/"><code>addon/fold/</code></a>
2369
+ directory providing <code>CodeMirror.fold.brace</code>, which
2370
+ finds blocks in brace languages (JavaScript, C, Java,
2371
+ etc), <code>CodeMirror.fold.indent</code>, for languages where
2372
+ indentation determines block structure (Python, Haskell),
2373
+ and <code>CodeMirror.fold.xml</code>, for XML-style languages,
2374
+ and <code>CodeMirror.fold.comment</code>, for folding comment
2375
+ blocks.</dd>
2376
+ <dt><code><strong>widget</strong>: string|Element</code></dt>
2377
+ <dd>The widget to show for folded ranges. Can be either a
2378
+ string, in which case it'll become a span with
2379
+ class <code>CodeMirror-foldmarker</code>, or a DOM node.</dd>
2380
+ <dt><code><strong>scanUp</strong>: boolean</code></dt>
2381
+ <dd>When true (default is false), the addon will try to find
2382
+ foldable ranges on the lines above the current one if there
2383
+ isn't an eligible one on the given line.</dd>
2384
+ <dt><code><strong>minFoldSize</strong>: integer</code></dt>
2385
+ <dd>The minimum amount of lines that a fold should span to be
2386
+ accepted. Defaults to 0, which also allows single-line
2387
+ folds.</dd>
2388
+ </dl>
2389
+ See <a href="../demo/folding.html">the demo</a> for an
2390
+ example.</dd>
2391
+
2392
+ <dt id="addon_foldgutter"><a href="../addon/fold/foldgutter.js"><code>fold/foldgutter.js</code></a></dt>
2393
+ <dd>Provides an option <code>foldGutter</code>, which can be
2394
+ used to create a gutter with markers indicating the blocks that
2395
+ can be folded. Create a gutter using
2396
+ the <a href="#option_gutters"><code>gutters</code></a> option,
2397
+ giving it the class <code>CodeMirror-foldgutter</code> or
2398
+ something else if you configure the addon to use a different
2399
+ class, and this addon will show markers next to folded and
2400
+ foldable blocks, and handle clicks in this gutter. Note that
2401
+ CSS styles should be applied to make the gutter, and the fold
2402
+ markers within it, visible. A default set of CSS styles are
2403
+ available in:
2404
+ <a href="../addon/fold/foldgutter.css">
2405
+ <code>addon/fold/foldgutter.css</code>
2406
+ </a>.
2407
+ The option
2408
+ can be either set to <code>true</code>, or an object containing
2409
+ the following optional option fields:
2410
+ <dl>
2411
+ <dt><code><strong>gutter</strong>: string</code></dt>
2412
+ <dd>The CSS class of the gutter. Defaults
2413
+ to <code>"CodeMirror-foldgutter"</code>. You will have to
2414
+ style this yourself to give it a width (and possibly a
2415
+ background). See the default gutter style rules above.</dd>
2416
+ <dt><code><strong>indicatorOpen</strong>: string | Element</code></dt>
2417
+ <dd>A CSS class or DOM element to be used as the marker for
2418
+ open, foldable blocks. Defaults
2419
+ to <code>"CodeMirror-foldgutter-open"</code>.</dd>
2420
+ <dt><code><strong>indicatorFolded</strong>: string | Element</code></dt>
2421
+ <dd>A CSS class or DOM element to be used as the marker for
2422
+ folded blocks. Defaults to <code>"CodeMirror-foldgutter-folded"</code>.</dd>
2423
+ <dt><code><strong>rangeFinder</strong>: fn(CodeMirror, Pos)</code></dt>
2424
+ <dd>The range-finder function to use when determining whether
2425
+ something can be folded. When not
2426
+ given, <a href="#helper_fold_auto"><code>CodeMirror.fold.auto</code></a>
2427
+ will be used as default.</dd>
2428
+ </dl>
2429
+ The <code>foldOptions</code> editor option can be set to an
2430
+ object to provide an editor-wide default configuration.
2431
+ Demo <a href="../demo/folding.html">here</a>.</dd>
2432
+
2433
+ <dt id="addon_runmode"><a href="../addon/runmode/runmode.js"><code>runmode/runmode.js</code></a></dt>
2434
+ <dd>Can be used to run a CodeMirror mode over text without
2435
+ actually opening an editor instance.
2436
+ See <a href="../demo/runmode.html">the demo</a> for an example.
2437
+ There are alternate versions of the file avaible for
2438
+ running <a href="../addon/runmode/runmode-standalone.js">stand-alone</a>
2439
+ (without including all of CodeMirror) and
2440
+ for <a href="../addon/runmode/runmode.node.js">running under
2441
+ node.js</a>.</dd>
2442
+
2443
+ <dt id="addon_colorize"><a href="../addon/runmode/colorize.js"><code>runmode/colorize.js</code></a></dt>
2444
+ <dd>Provides a convenient way to syntax-highlight code snippets
2445
+ in a webpage. Depends on
2446
+ the <a href="#addon_runmode"><code>runmode</code></a> addon (or
2447
+ its standalone variant). Provides
2448
+ a <code>CodeMirror.colorize</code> function that can be called
2449
+ with an array (or other array-ish collection) of DOM nodes that
2450
+ represent the code snippets. By default, it'll get
2451
+ all <code>pre</code> tags. Will read the <code>data-lang</code>
2452
+ attribute of these nodes to figure out their language, and
2453
+ syntax-color their content using the relevant CodeMirror mode
2454
+ (you'll have to load the scripts for the relevant modes
2455
+ yourself). A second argument may be provided to give a default
2456
+ mode, used when no language attribute is found for a node. Used
2457
+ in this manual to highlight example code.</dd>
2458
+
2459
+ <dt id="addon_overlay"><a href="../addon/mode/overlay.js"><code>mode/overlay.js</code></a></dt>
2460
+ <dd>Mode combinator that can be used to extend a mode with an
2461
+ 'overlay' — a secondary mode is run over the stream, along with
2462
+ the base mode, and can color specific pieces of text without
2463
+ interfering with the base mode.
2464
+ Defines <code>CodeMirror.overlayMode</code>, which is used to
2465
+ create such a mode. See <a href="../demo/mustache.html">this
2466
+ demo</a> for a detailed example.</dd>
2467
+
2468
+ <dt id="addon_multiplex"><a href="../addon/mode/multiplex.js"><code>mode/multiplex.js</code></a></dt>
2469
+ <dd>Mode combinator that can be used to easily 'multiplex'
2470
+ between several modes.
2471
+ Defines <code>CodeMirror.multiplexingMode</code> which, when
2472
+ given as first argument a mode object, and as other arguments
2473
+ any number of <code>{open, close, mode [, delimStyle, innerStyle, parseDelimiters]}</code>
2474
+ objects, will return a mode object that starts parsing using the
2475
+ mode passed as first argument, but will switch to another mode
2476
+ as soon as it encounters a string that occurs in one of
2477
+ the <code>open</code> fields of the passed objects. When in a
2478
+ sub-mode, it will go back to the top mode again when
2479
+ the <code>close</code> string is encountered.
2480
+ Pass <code>"\n"</code> for <code>open</code> or <code>close</code>
2481
+ if you want to switch on a blank line.
2482
+ <ul><li>When <code>delimStyle</code> is specified, it will be the token
2483
+ style returned for the delimiter tokens.</li>
2484
+ <li>When <code>innerStyle</code> is specified, it will be the token
2485
+ style added for each inner mode token.</li>
2486
+ <li>When <code>parseDelimiters</code> is true, the content of
2487
+ the delimiters will also be passed to the inner mode.
2488
+ (And <code>delimStyle</code> is ignored.)</li></ul> The outer
2489
+ mode will not see the content between the delimiters.
2490
+ See <a href="../demo/multiplex.html">this demo</a> for an
2491
+ example.</dd>
2492
+
2493
+ <dt id="addon_show-hint"><a href="../addon/hint/show-hint.js"><code>hint/show-hint.js</code></a></dt>
2494
+ <dd>Provides a framework for showing autocompletion hints.
2495
+ Defines <code>editor.showHint</code>, which takes an optional
2496
+ options object, and pops up a widget that allows the user to
2497
+ select a completion. Finding hints is done with a hinting
2498
+ functions (the <code>hint</code> option), which is a function
2499
+ that take an editor instance and options object, and return
2500
+ a <code>{list, from, to}</code> object, where <code>list</code>
2501
+ is an array of strings or objects (the completions),
2502
+ and <code>from</code> and <code>to</code> give the start and end
2503
+ of the token that is being completed as <code>{line, ch}</code>
2504
+ objects. An optional <code>selectedHint</code> property (an
2505
+ integer) can be added to the completion object to control the
2506
+ initially selected hint.</dd>
2507
+ <dd>If no hinting function is given, the addon will
2508
+ use <code>CodeMirror.hint.auto</code>, which
2509
+ calls <a href="#getHelpers"><code>getHelpers</code></a> with
2510
+ the <code>"hint"</code> type to find applicable hinting
2511
+ functions, and tries them one by one. If that fails, it looks
2512
+ for a <code>"hintWords"</code> helper to fetch a list of
2513
+ completable words for the mode, and
2514
+ uses <code>CodeMirror.hint.fromList</code> to complete from
2515
+ those.</dd>
2516
+ <dd>When completions aren't simple strings, they should be
2517
+ objects with the following properties:
2518
+ <dl>
2519
+ <dt><code><strong>text</strong>: string</code></dt>
2520
+ <dd>The completion text. This is the only required
2521
+ property.</dd>
2522
+ <dt><code><strong>displayText</strong>: string</code></dt>
2523
+ <dd>The text that should be displayed in the menu.</dd>
2524
+ <dt><code><strong>className</strong>: string</code></dt>
2525
+ <dd>A CSS class name to apply to the completion's line in the
2526
+ menu.</dd>
2527
+ <dt><code><strong>render</strong>: fn(Element, self, data)</code></dt>
2528
+ <dd>A method used to create the DOM structure for showing the
2529
+ completion by appending it to its first argument.</dd>
2530
+ <dt><code><strong>hint</strong>: fn(CodeMirror, self, data)</code></dt>
2531
+ <dd>A method used to actually apply the completion, instead of
2532
+ the default behavior.</dd>
2533
+ <dt><code><strong>from</strong>: {line, ch}</code></dt>
2534
+ <dd>Optional <code>from</code> position that will be used by <code>pick()</code> instead
2535
+ of the global one passed with the full list of completions.</dd>
2536
+ <dt><code><strong>to</strong>: {line, ch}</code></dt>
2537
+ <dd>Optional <code>to</code> position that will be used by <code>pick()</code> instead
2538
+ of the global one passed with the full list of completions.</dd>
2539
+ </dl>
2540
+ The plugin understands the following options (the options object
2541
+ will also be passed along to the hinting function, which may
2542
+ understand additional options):
2543
+ <dl>
2544
+ <dt><code><strong>hint</strong>: function</code></dt>
2545
+ <dd>A hinting function, as specified above. It is possible to
2546
+ set the <code>async</code> property on a hinting function to
2547
+ true, in which case it will be called with
2548
+ arguments <code>(cm, callback, ?options)</code>, and the
2549
+ completion interface will only be popped up when the hinting
2550
+ function calls the callback, passing it the object holding the
2551
+ completions.</dd>
2552
+ <dt><code><strong>completeSingle</strong>: boolean</code></dt>
2553
+ <dd>Determines whether, when only a single completion is
2554
+ available, it is completed without showing the dialog.
2555
+ Defaults to true.</dd>
2556
+ <dt><code><strong>alignWithWord</strong>: boolean</code></dt>
2557
+ <dd>Whether the pop-up should be horizontally aligned with the
2558
+ start of the word (true, default), or with the cursor (false).</dd>
2559
+ <dt><code><strong>closeOnUnfocus</strong>: boolean</code></dt>
2560
+ <dd>When enabled (which is the default), the pop-up will close
2561
+ when the editor is unfocused.</dd>
2562
+ <dt><code><strong>customKeys</strong>: keymap</code></dt>
2563
+ <dd>Allows you to provide a custom key map of keys to be active
2564
+ when the pop-up is active. The handlers will be called with an
2565
+ extra argument, a handle to the completion menu, which
2566
+ has <code>moveFocus(n)</code>, <code>setFocus(n)</code>, <code>pick()</code>,
2567
+ and <code>close()</code> methods (see the source for details),
2568
+ that can be used to change the focused element, pick the
2569
+ current element or close the menu. Additionnaly <code>menuSize()</code>
2570
+ can give you access to the size of the current dropdown menu,
2571
+ <code>length</code> give you the number of availlable completions, and
2572
+ <code>data</code> give you full access to the completion returned by the
2573
+ hinting function.</dd>
2574
+ <dt><code><strong>extraKeys</strong>: keymap</code></dt>
2575
+ <dd>Like <code>customKeys</code> above, but the bindings will
2576
+ be added to the set of default bindings, instead of replacing
2577
+ them.</dd>
2578
+ </dl>
2579
+ The following events will be fired on the completions object
2580
+ during completion:
2581
+ <dl>
2582
+ <dt><code><strong>"shown"</strong> ()</code></dt>
2583
+ <dd>Fired when the pop-up is shown.</dd>
2584
+ <dt><code><strong>"select"</strong> (completion, Element)</code></dt>
2585
+ <dd>Fired when a completion is selected. Passed the completion
2586
+ value (string or object) and the DOM node that represents it
2587
+ in the menu.</dd>
2588
+ <dt><code><strong>"pick"</strong> (completion)</code></dt>
2589
+ <dd>Fired when a completion is picked. Passed the completion value
2590
+ (string or object).</dd>
2591
+ <dt><code><strong>"close"</strong> ()</code></dt>
2592
+ <dd>Fired when the completion is finished.</dd>
2593
+ </dl>
2594
+ This addon depends on styles
2595
+ from <code>addon/hint/show-hint.css</code>. Check
2596
+ out <a href="../demo/complete.html">the demo</a> for an
2597
+ example.</dd>
2598
+
2599
+ <dt id="addon_javascript-hint"><a href="../addon/hint/javascript-hint.js"><code>hint/javascript-hint.js</code></a></dt>
2600
+ <dd>Defines a simple hinting function for JavaScript
2601
+ (<code>CodeMirror.hint.javascript</code>) and CoffeeScript
2602
+ (<code>CodeMirror.hint.coffeescript</code>) code. This will
2603
+ simply use the JavaScript environment that the editor runs in as
2604
+ a source of information about objects and their properties.</dd>
2605
+
2606
+ <dt id="addon_xml-hint"><a href="../addon/hint/xml-hint.js"><code>hint/xml-hint.js</code></a></dt>
2607
+ <dd>Defines <code>CodeMirror.hint.xml</code>, which produces
2608
+ hints for XML tagnames, attribute names, and attribute values,
2609
+ guided by a <code>schemaInfo</code> option (a property of the
2610
+ second argument passed to the hinting function, or the third
2611
+ argument passed to <code>CodeMirror.showHint</code>).<br>The
2612
+ schema info should be an object mapping tag names to information
2613
+ about these tags, with optionally a <code>"!top"</code> property
2614
+ containing a list of the names of valid top-level tags. The
2615
+ values of the properties should be objects with optional
2616
+ properties <code>children</code> (an array of valid child
2617
+ element names, omit to simply allow all tags to appear)
2618
+ and <code>attrs</code> (an object mapping attribute names
2619
+ to <code>null</code> for free-form attributes, and an array of
2620
+ valid values for restricted
2621
+ attributes). <a href="../demo/xmlcomplete.html">Demo
2622
+ here.</a></dd>
2623
+
2624
+ <dt id="addon_html-hint"><a href="../addon/hint/html-hint.js"><code>hint/html-hint.js</code></a></dt>
2625
+ <dd>Provides schema info to
2626
+ the <a href="#addon_xml-hint">xml-hint</a> addon for HTML
2627
+ documents. Defines a schema
2628
+ object <code>CodeMirror.htmlSchema</code> that you can pass to
2629
+ as a <code>schemaInfo</code> option, and
2630
+ a <code>CodeMirror.hint.html</code> hinting function that
2631
+ automatically calls <code>CodeMirror.hint.xml</code> with this
2632
+ schema data. See
2633
+ the <a href="../demo/html5complete.html">demo</a>.</dd>
2634
+
2635
+ <dt id="addon_css-hint"><a href="../addon/hint/css-hint.js"><code>hint/css-hint.js</code></a></dt>
2636
+ <dd>A hinting function for CSS, SCSS, or LESS code.
2637
+ Defines <code>CodeMirror.hint.css</code>.</dd>
2638
+
2639
+ <dt id="addon_anyword-hint"><a href="../addon/hint/anyword-hint.js"><code>hint/anyword-hint.js</code></a></dt>
2640
+ <dd>A very simple hinting function
2641
+ (<code>CodeMirror.hint.anyword</code>) that simply looks for
2642
+ words in the nearby code and completes to those. Takes two
2643
+ optional options, <code>word</code>, a regular expression that
2644
+ matches words (sequences of one or more character),
2645
+ and <code>range</code>, which defines how many lines the addon
2646
+ should scan when completing (defaults to 500).</dd>
2647
+
2648
+ <dt id="addon_sql-hint"><a href="../addon/hint/sql-hint.js"><code>hint/sql-hint.js</code></a></dt>
2649
+ <dd>A simple SQL hinter. Defines <code>CodeMirror.hint.sql</code>.
2650
+ Takes two optional options, <code>tables</code>, a object with
2651
+ table names as keys and array of respective column names as values,
2652
+ and <code>defaultTable</code>, a string corresponding to a
2653
+ table name in <code>tables</code> for autocompletion.</dd>
2654
+
2655
+ <dt id="addon_match-highlighter"><a href="../addon/search/match-highlighter.js"><code>search/match-highlighter.js</code></a></dt>
2656
+ <dd>Adds a <code>highlightSelectionMatches</code> option that
2657
+ can be enabled to highlight all instances of a currently
2658
+ selected word. Can be set either to true or to an object
2659
+ containing the following options: <code>minChars</code>, for the
2660
+ minimum amount of selected characters that triggers a highlight
2661
+ (default 2), <code>style</code>, for the style to be used to
2662
+ highlight the matches (default <code>"matchhighlight"</code>,
2663
+ which will correspond to CSS
2664
+ class <code>cm-matchhighlight</code>),
2665
+ and <code>showToken</code> which can be set to <code>true</code>
2666
+ or to a regexp matching the characters that make up a word. When
2667
+ enabled, it causes the current word to be highlighted when
2668
+ nothing is selected (defaults to off).
2669
+ Demo <a href="../demo/matchhighlighter.html">here</a>.</dd>
2670
+
2671
+ <dt id="addon_lint"><a href="../addon/lint/lint.js"><code>lint/lint.js</code></a></dt>
2672
+ <dd>Defines an interface component for showing linting warnings,
2673
+ with pluggable warning sources
2674
+ (see <a href="../addon/lint/json-lint.js"><code>json-lint.js</code></a>,
2675
+ <a href="../addon/lint/javascript-lint.js"><code>javascript-lint.js</code></a>,
2676
+ <a href="../addon/lint/coffeescript-lint.js"><code>coffeescript-lint.js</code></a>,
2677
+ and <a href="../addon/lint/css-lint.js"><code>css-lint.js</code></a>
2678
+ in the same directory). Defines a <code>lint</code> option that
2679
+ can be set to a warning source (for
2680
+ example <code>CodeMirror.lint.javascript</code>), or
2681
+ to <code>true</code>, in which
2682
+ case <a href="#getHelper"><code>getHelper</code></a> with
2683
+ type <code>"lint"</code> is used to determined a validator
2684
+ function. Such a function should, when given a document string,
2685
+ an options object, and an editor instance, return an array of <code>{message,
2686
+ severity, from, to}</code> objects representing problems. When
2687
+ the function has an <code>async</code> property with a truthy
2688
+ value, it will be called with an additional second argument,
2689
+ which is a callback to pass the array to. Depends
2690
+ on <code>addon/lint/lint.css</code>. A demo can be
2691
+ found <a href="../demo/lint.html">here</a>.</dd>
2692
+
2693
+ <dt id="addon_mark-selection"><a href="../addon/selection/mark-selection.js"><code>selection/mark-selection.js</code></a></dt>
2694
+ <dd>Causes the selected text to be marked with the CSS class
2695
+ <code>CodeMirror-selectedtext</code> when the <code>styleSelectedText</code> option
2696
+ is enabled. Useful to change the colour of the selection (in addition to the background),
2697
+ like in <a href="../demo/markselection.html">this demo</a>.</dd>
2698
+
2699
+ <dt id="addon_active-line"><a href="../addon/selection/active-line.js"><code>selection/active-line.js</code></a></dt>
2700
+ <dd>Defines a <code>styleActiveLine</code> option that, when enabled,
2701
+ gives the wrapper of the active line the class <code>CodeMirror-activeline</code>,
2702
+ and adds a background with the class <code>CodeMirror-activeline-background</code>.
2703
+ is enabled. See the <a href="../demo/activeline.html">demo</a>.</dd>
2704
+
2705
+ <dt id="addon_selection-pointer"><a href="../addon/selection/selection-pointer.js"><code>selection/selection-pointer.js</code></a></dt>
2706
+ <dd>Defines a <code>selectionPointer</code> option which you can
2707
+ use to control the mouse cursor appearance when hovering over
2708
+ the selection. It can be set to a string,
2709
+ like <code>"pointer"</code>, or to true, in which case
2710
+ the <code>"default"</code> (arrow) cursor will be used. You can
2711
+ see a demo <a href="../mode/htmlmixed/index.html">here</a>.</dd>
2712
+
2713
+ <dt id="addon_loadmode"><a href="../addon/mode/loadmode.js"><code>mode/loadmode.js</code></a></dt>
2714
+ <dd>Defines a <code>CodeMirror.requireMode(modename,
2715
+ callback)</code> function that will try to load a given mode and
2716
+ call the callback when it succeeded. You'll have to
2717
+ set <code>CodeMirror.modeURL</code> to a string that mode paths
2718
+ can be constructed from, for
2719
+ example <code>"mode/%N/%N.js"</code>—the <code>%N</code>'s will
2720
+ be replaced with the mode name. Also
2721
+ defines <code>CodeMirror.autoLoadMode(instance, mode)</code>,
2722
+ which will ensure the given mode is loaded and cause the given
2723
+ editor instance to refresh its mode when the loading
2724
+ succeeded. See the <a href="../demo/loadmode.html">demo</a>.</dd>
2725
+
2726
+ <dt id="addon_meta"><a href="../mode/meta.js"><code>mode/meta.js</code></a></dt>
2727
+ <dd>Provides meta-information about all the modes in the
2728
+ distribution in a single file.
2729
+ Defines <code>CodeMirror.modeInfo</code>, an array of objects
2730
+ with <code>{name, mime, mode}</code> properties,
2731
+ where <code>name</code> is the human-readable
2732
+ name, <code>mime</code> the MIME type, and <code>mode</code> the
2733
+ name of the mode file that defines this MIME. There are optional
2734
+ properties <code>mimes</code>, which holds an array of MIME
2735
+ types for modes with multiple MIMEs associated,
2736
+ and <code>ext</code>, which holds an array of file extensions
2737
+ associated with this mode. Four convenience
2738
+ functions, <code>CodeMirror.findModeByMIME</code>,
2739
+ <code>CodeMirror.findModeByExtension</code>,
2740
+ <code>CodeMirror.findModeByFileName</code>
2741
+ and <code>CodeMirror.findModeByName</code> are provided, which
2742
+ return such an object given a MIME, extension, file name or mode name
2743
+ string. Note that, for historical reasons, this file resides in the
2744
+ top-level <code>mode</code> directory, not
2745
+ under <code>addon</code>. <a href="../demo/loadmode.html">Demo</a>.</dd>
2746
+
2747
+ <dt id="addon_continuecomment"><a href="../addon/comment/continuecomment.js"><code>comment/continuecomment.js</code></a></dt>
2748
+ <dd>Adds a <code>continueComments</code> option, which sets whether the
2749
+ editor will make the next line continue a comment when you press Enter
2750
+ inside a comment block. Can be set to a boolean to enable/disable this
2751
+ functionality. Set to a string, it will continue comments using a custom
2752
+ shortcut. Set to an object, it will use the <code>key</code> property for
2753
+ a custom shortcut and the boolean <code>continueLineComment</code>
2754
+ property to determine whether single-line comments should be continued
2755
+ (defaulting to <code>true</code>).</dd>
2756
+
2757
+ <dt id="addon_placeholder"><a href="../addon/display/placeholder.js"><code>display/placeholder.js</code></a></dt>
2758
+ <dd>Adds a <code>placeholder</code> option that can be used to
2759
+ make text appear in the editor when it is empty and not focused.
2760
+ Also gives the editor a <code>CodeMirror-empty</code> CSS class
2761
+ whenever it doesn't contain any text.
2762
+ See <a href="../demo/placeholder.html">the demo</a>.</dd>
2763
+
2764
+ <dt id="addon_fullscreen"><a href="../addon/display/fullscreen.js"><code>display/fullscreen.js</code></a></dt>
2765
+ <dd>Defines an option <code>fullScreen</code> that, when set
2766
+ to <code>true</code>, will make the editor full-screen (as in,
2767
+ taking up the whole browser window). Depends
2768
+ on <a href="../addon/display/fullscreen.css"><code>fullscreen.css</code></a>. <a href="../demo/fullscreen.html">Demo
2769
+ here</a>.</dd>
2770
+
2771
+ <dt id="addon_simplescrollbars"><a href="../addon/scroll/simplescrollbars.js"><code>scroll/simplescrollbars.js</code></a></dt>
2772
+ <dd>Defines two additional scrollbar
2773
+ models, <code>"simple"</code> and <code>"overlay"</code>
2774
+ (see <a href="../demo/simplescrollbars.html">demo</a>) that can
2775
+ be selected with
2776
+ the <a href="#option_scrollbarStyle"><code>scrollbarStyle</code></a>
2777
+ option. Depends
2778
+ on <a href="../addon/scroll/simplescrollbars.css"><code>simplescrollbars.css</code></a>,
2779
+ which can be further overridden to style your own
2780
+ scrollbars.</dd>
2781
+
2782
+ <dt id="addon_annotatescrollbar"><a href="../addon/scroll/annotatescrollbar.js"><code>scroll/annotatescrollbar.js</code></a></dt>
2783
+ <dd>Provides functionality for showing markers on the scrollbar
2784
+ to call out certain parts of the document. Adds a
2785
+ method <code>annotateScrollbar</code> to editor instances that
2786
+ can be called, with a CSS class name as argument, to create a
2787
+ set of annotations. The method returns an object
2788
+ whose <code>update</code> method can be called with an array
2789
+ of <code>{from: Pos, to: Pos}</code> objects marking the ranges
2790
+ to be higlighed. To detach the annotations, call the
2791
+ object's <code>clear</code> method.</dd>
2792
+
2793
+ <dt id="addon_rulers"><a href="../addon/display/rulers.js"><code>display/rulers.js</code></a></dt>
2794
+ <dd>Adds a <code>rulers</code> option, which can be used to show
2795
+ one or more vertical rulers in the editor. The option, if
2796
+ defined, should be given an array of <code>{column [, className,
2797
+ color, lineStyle, width]}</code> objects or numbers (wich
2798
+ indicate a column). The ruler will be displayed at the column
2799
+ indicated by the number or the <code>column</code> property.
2800
+ The <code>className</code> property can be used to assign a
2801
+ custom style to a ruler. <a href="../demo/rulers.html">Demo
2802
+ here</a>.</dd>
2803
+
2804
+ <dt id="addon_panel"><a href="../addon/display/panel.js"><code>display/panel.js</code></a></dt>
2805
+ <dd>Defines an <code>addPanel</code> method for CodeMirror
2806
+ instances, which places a DOM node above or below an editor, and
2807
+ shrinks the editor to make room for the node. The method takes
2808
+ as first argument as DOM node, and as second an optional options
2809
+ object. The <code>Panel</code> object returned by this method
2810
+ has a <code>clear</code> method that is used to remove the
2811
+ panel, and a <code>changed</code> method that can be used to
2812
+ notify the addon when the size of the panel's DOM node has
2813
+ changed.<br/>
2814
+ The method accepts the following options:
2815
+ <dl>
2816
+ <dt><code><strong>position</strong> : string</code></dt>
2817
+ <dd>Controls the position of the newly added panel. The
2818
+ following values are recognized:
2819
+ <dl>
2820
+ <dt><code><strong>top</strong> (default)</code></dt>
2821
+ <dd>Adds the panel at the very top.</dd>
2822
+ <dt><code><strong>after-top</strong></code></dt>
2823
+ <dd>Adds the panel at the bottom of the top panels.</dd>
2824
+ <dt><code><strong>bottom</strong></code></dt>
2825
+ <dd>Adds the panel at the very bottom.</dd>
2826
+ <dt><code><strong>before-bottom</strong></code></dt>
2827
+ <dd>Adds the panel at the top of the bottom panels.</dd>
2828
+ </dl>
2829
+ </dd>
2830
+ <dt><code><strong>before</strong> : Panel</code></dt>
2831
+ <dd>The new panel will be added before the given panel.</dd>
2832
+ <dt><code><strong>after</strong> : Panel</code></dt>
2833
+ <dd>The new panel will be added after the given panel.</dd>
2834
+ <dt><code><strong>replace</strong> : Panel</code></dt>
2835
+ <dd>The new panel will replace the given panel.</dd>
2836
+ </dl>
2837
+ When using the <code>after</code>, <code>before</code> or <code>replace</code> options,
2838
+ if the panel doesn't exists or has been removed,
2839
+ the value of the <code>position</code> option will be used as a fallback.
2840
+ <br>
2841
+ A demo of the addon is available <a href="../demo/panel.html">here</a>.
2842
+ </dd>
2843
+
2844
+ <dt id="addon_hardwrap"><a href="../addon/wrap/hardwrap.js"><code>wrap/hardwrap.js</code></a></dt>
2845
+ <dd>Addon to perform hard line wrapping/breaking for paragraphs
2846
+ of text. Adds these methods to editor instances:
2847
+ <dl>
2848
+ <dt><code><strong>wrapParagraph</strong>(?pos: {line, ch}, ?options: object)</code></dt>
2849
+ <dd>Wraps the paragraph at the given position.
2850
+ If <code>pos</code> is not given, it defaults to the cursor
2851
+ position.</dd>
2852
+ <dt><code><strong>wrapRange</strong>(from: {line, ch}, to: {line, ch}, ?options: object)</code></dt>
2853
+ <dd>Wraps the given range as one big paragraph.</dd>
2854
+ <dt><code><strong>wrapParagraphsInRange</strong>(from: {line, ch}, to: {line, ch}, ?options: object)</code></dt>
2855
+ <dd>Wrapps the paragraphs in (and overlapping with) the
2856
+ given range individually.</dd>
2857
+ </dl>
2858
+ The following options are recognized:
2859
+ <dl>
2860
+ <dt><code><strong>paragraphStart</strong>, <strong>paragraphEnd</strong>: RegExp</code></dt>
2861
+ <dd>Blank lines are always considered paragraph boundaries.
2862
+ These options can be used to specify a pattern that causes
2863
+ lines to be considered the start or end of a paragraph.</dd>
2864
+ <dt><code><strong>column</strong>: number</code></dt>
2865
+ <dd>The column to wrap at. Defaults to 80.</dd>
2866
+ <dt><code><strong>wrapOn</strong>: RegExp</code></dt>
2867
+ <dd>A regular expression that matches only those
2868
+ two-character strings that allow wrapping. By default, the
2869
+ addon wraps on whitespace and after dash characters.</dd>
2870
+ <dt><code><strong>killTrailingSpace</strong>: boolean</code></dt>
2871
+ <dd>Whether trailing space caused by wrapping should be
2872
+ preserved, or deleted. Defaults to true.</dd>
2873
+ </dl>
2874
+ A demo of the addon is available <a href="../demo/hardwrap.html">here</a>.
2875
+ </dd>
2876
+
2877
+ <dt id="addon_merge"><a href="../addon/merge/merge.js"><code>merge/merge.js</code></a></dt>
2878
+ <dd>Implements an interface for merging changes, using either a
2879
+ 2-way or a 3-way view. The <code>CodeMirror.MergeView</code>
2880
+ constructor takes arguments similar to
2881
+ the <a href="#CodeMirror"><code>CodeMirror</code></a>
2882
+ constructor, first a node to append the interface to, and then
2883
+ an options object. Options are passed through to the editors
2884
+ inside the view. These extra options are recognized:
2885
+ <dl>
2886
+ <dt><code><strong>origLeft</strong></code> and <code><strong>origRight</strong>: string</code></dt>
2887
+ <dd>If given these provide original versions of the
2888
+ document, which will be shown to the left and right of the
2889
+ editor in non-editable CodeMirror instances. The merge
2890
+ interface will highlight changes between the editable
2891
+ document and the original(s). To create a 2-way (as opposed
2892
+ to 3-way) merge view, provide only one of them.</dd>
2893
+ <dt><code><strong>revertButtons</strong>: boolean</code></dt>
2894
+ <dd>Determines whether buttons that allow the user to revert
2895
+ changes are shown. Defaults to true.</dd>
2896
+ <dt><code><strong>connect</strong>: string</code></dt>
2897
+ <dd>Sets the style used to connect changed chunks of code.
2898
+ By default, connectors are drawn. When this is set
2899
+ to <code>"align"</code>, the smaller chunk is padded to
2900
+ align with the bigger chunk instead.</dd>
2901
+ <dt><code><strong>collapseIdentical</strong>: boolean|number</code></dt>
2902
+ <dd>When true (default is false), stretches of unchanged
2903
+ text will be collapsed. When a number is given, this
2904
+ indicates the amount of lines to leave visible around such
2905
+ stretches (which defaults to 2).</dd>
2906
+ <dt><code><strong>allowEditingOriginals</strong>: boolean</code></dt>
2907
+ <dd>Determines whether the original editor allows editing.
2908
+ Defaults to false.</dd>
2909
+ <dt><code><strong>showDifferences</strong>: boolean</code></dt>
2910
+ <dd>When true (the default), changed pieces of text are
2911
+ highlighted.</dd>
2912
+ </dl>
2913
+ The addon also defines commands <code>"goNextDiff"</code>
2914
+ and <code>"goPrevDiff"</code> to quickly jump to the next
2915
+ changed chunk. <a href="../demo/merge.html">Demo
2916
+ here</a>.</dd>
2917
+
2918
+ <dt id="addon_tern"><a href="../addon/tern/tern.js"><code>tern/tern.js</code></a></dt>
2919
+ <dd>Provides integration with
2920
+ the <a href="http://ternjs.net">Tern</a> JavaScript analysis
2921
+ engine, for completion, definition finding, and minor
2922
+ refactoring help. See the <a href="../demo/tern.html">demo</a>
2923
+ for a very simple integration. For more involved scenarios, see
2924
+ the comments at the top of
2925
+ the <a href="../addon/tern/tern.js">addon</a> and the
2926
+ implementation of the
2927
+ (multi-file) <a href="http://ternjs.net/doc/demo.html">demonstration
2928
+ on the Tern website</a>.</dd>
2929
+ </dl>
2930
+ </section>
2931
+
2932
+ <section id=modeapi>
2933
+ <h2>Writing CodeMirror Modes</h2>
2934
+
2935
+ <p>Modes typically consist of a single JavaScript file. This file
2936
+ defines, in the simplest case, a lexer (tokenizer) for your
2937
+ language—a function that takes a character stream as input,
2938
+ advances it past a token, and returns a style for that token. More
2939
+ advanced modes can also handle indentation for the language.</p>
2940
+
2941
+ <p>This section describes the low-level mode interface. Many modes
2942
+ are written directly against this, since it offers a lot of
2943
+ control, but for a quick mode definition, you might want to use
2944
+ the <a href="../demo/simplemode.html">simple mode addon</a>.</p>
2945
+
2946
+ <p id="defineMode">The mode script should
2947
+ call <code><strong>CodeMirror.defineMode</strong></code> to
2948
+ register itself with CodeMirror. This function takes two
2949
+ arguments. The first should be the name of the mode, for which you
2950
+ should use a lowercase string, preferably one that is also the
2951
+ name of the files that define the mode (i.e. <code>"xml"</code> is
2952
+ defined in <code>xml.js</code>). The second argument should be a
2953
+ function that, given a CodeMirror configuration object (the thing
2954
+ passed to the <code>CodeMirror</code> function) and an optional
2955
+ mode configuration object (as in
2956
+ the <a href="#option_mode"><code>mode</code></a> option), returns
2957
+ a mode object.</p>
2958
+
2959
+ <p>Typically, you should use this second argument
2960
+ to <code>defineMode</code> as your module scope function (modes
2961
+ should not leak anything into the global scope!), i.e. write your
2962
+ whole mode inside this function.</p>
2963
+
2964
+ <p>The main responsibility of a mode script is <em>parsing</em>
2965
+ the content of the editor. Depending on the language and the
2966
+ amount of functionality desired, this can be done in really easy
2967
+ or extremely complicated ways. Some parsers can be stateless,
2968
+ meaning that they look at one element (<em>token</em>) of the code
2969
+ at a time, with no memory of what came before. Most, however, will
2970
+ need to remember something. This is done by using a <em>state
2971
+ object</em>, which is an object that is always passed when
2972
+ reading a token, and which can be mutated by the tokenizer.</p>
2973
+
2974
+ <p id="startState">Modes that use a state must define
2975
+ a <code><strong>startState</strong></code> method on their mode
2976
+ object. This is a function of no arguments that produces a state
2977
+ object to be used at the start of a document.</p>
2978
+
2979
+ <p id="token">The most important part of a mode object is
2980
+ its <code><strong>token</strong>(stream, state)</code> method. All
2981
+ modes must define this method. It should read one token from the
2982
+ stream it is given as an argument, optionally update its state,
2983
+ and return a style string, or <code>null</code> for tokens that do
2984
+ not have to be styled. For your styles, you are encouraged to use
2985
+ the 'standard' names defined in the themes (without
2986
+ the <code>cm-</code> prefix). If that fails, it is also possible
2987
+ to come up with your own and write your own CSS theme file.<p>
2988
+
2989
+ <p id="token_style_line">A typical token string would
2990
+ be <code>"variable"</code> or <code>"comment"</code>. Multiple
2991
+ styles can be returned (separated by spaces), for
2992
+ example <code>"string error"</code> for a thing that looks like a
2993
+ string but is invalid somehow (say, missing its closing quote).
2994
+ When a style is prefixed by <code>"line-"</code>
2995
+ or <code>"line-background-"</code>, the style will be applied to
2996
+ the whole line, analogous to what
2997
+ the <a href="#addLineClass"><code>addLineClass</code></a> method
2998
+ does—styling the <code>"text"</code> in the simple case, and
2999
+ the <code>"background"</code> element
3000
+ when <code>"line-background-"</code> is prefixed.</p>
3001
+
3002
+ <p id="StringStream">The stream object that's passed
3003
+ to <code>token</code> encapsulates a line of code (tokens may
3004
+ never span lines) and our current position in that line. It has
3005
+ the following API:</p>
3006
+
3007
+ <dl>
3008
+ <dt><code><strong>eol</strong>() → boolean</code></dt>
3009
+ <dd>Returns true only if the stream is at the end of the
3010
+ line.</dd>
3011
+ <dt><code><strong>sol</strong>() → boolean</code></dt>
3012
+ <dd>Returns true only if the stream is at the start of the
3013
+ line.</dd>
3014
+
3015
+ <dt><code><strong>peek</strong>() → string</code></dt>
3016
+ <dd>Returns the next character in the stream without advancing
3017
+ it. Will return an <code>null</code> at the end of the
3018
+ line.</dd>
3019
+ <dt><code><strong>next</strong>() → string</code></dt>
3020
+ <dd>Returns the next character in the stream and advances it.
3021
+ Also returns <code>null</code> when no more characters are
3022
+ available.</dd>
3023
+
3024
+ <dt><code><strong>eat</strong>(match: string|regexp|function(char: string) → boolean) → string</code></dt>
3025
+ <dd><code>match</code> can be a character, a regular expression,
3026
+ or a function that takes a character and returns a boolean. If
3027
+ the next character in the stream 'matches' the given argument,
3028
+ it is consumed and returned. Otherwise, <code>undefined</code>
3029
+ is returned.</dd>
3030
+ <dt><code><strong>eatWhile</strong>(match: string|regexp|function(char: string) → boolean) → boolean</code></dt>
3031
+ <dd>Repeatedly calls <code>eat</code> with the given argument,
3032
+ until it fails. Returns true if any characters were eaten.</dd>
3033
+ <dt><code><strong>eatSpace</strong>() → boolean</code></dt>
3034
+ <dd>Shortcut for <code>eatWhile</code> when matching
3035
+ white-space.</dd>
3036
+ <dt><code><strong>skipToEnd</strong>()</code></dt>
3037
+ <dd>Moves the position to the end of the line.</dd>
3038
+ <dt><code><strong>skipTo</strong>(ch: string) → boolean</code></dt>
3039
+ <dd>Skips to the next occurrence of the given character, if
3040
+ found on the current line (doesn't advance the stream if the
3041
+ character does not occur on the line). Returns true if the
3042
+ character was found.</dd>
3043
+ <dt><code><strong>match</strong>(pattern: string, ?consume: boolean, ?caseFold: boolean) → boolean</code></dt>
3044
+ <dt><code><strong>match</strong>(pattern: regexp, ?consume: boolean) → array&lt;string&gt;</code></dt>
3045
+ <dd>Act like a
3046
+ multi-character <code>eat</code>—if <code>consume</code> is true
3047
+ or not given—or a look-ahead that doesn't update the stream
3048
+ position—if it is false. <code>pattern</code> can be either a
3049
+ string or a regular expression starting with <code>^</code>.
3050
+ When it is a string, <code>caseFold</code> can be set to true to
3051
+ make the match case-insensitive. When successfully matching a
3052
+ regular expression, the returned value will be the array
3053
+ returned by <code>match</code>, in case you need to extract
3054
+ matched groups.</dd>
3055
+
3056
+ <dt><code><strong>backUp</strong>(n: integer)</code></dt>
3057
+ <dd>Backs up the stream <code>n</code> characters. Backing it up
3058
+ further than the start of the current token will cause things to
3059
+ break, so be careful.</dd>
3060
+ <dt><code><strong>column</strong>() → integer</code></dt>
3061
+ <dd>Returns the column (taking into account tabs) at which the
3062
+ current token starts.</dd>
3063
+ <dt><code><strong>indentation</strong>() → integer</code></dt>
3064
+ <dd>Tells you how far the current line has been indented, in
3065
+ spaces. Corrects for tab characters.</dd>
3066
+
3067
+ <dt><code><strong>current</strong>() → string</code></dt>
3068
+ <dd>Get the string between the start of the current token and
3069
+ the current stream position.</dd>
3070
+ </dl>
3071
+
3072
+ <p id="blankLine">By default, blank lines are simply skipped when
3073
+ tokenizing a document. For languages that have significant blank
3074
+ lines, you can define
3075
+ a <code><strong>blankLine</strong>(state)</code> method on your
3076
+ mode that will get called whenever a blank line is passed over, so
3077
+ that it can update the parser state.</p>
3078
+
3079
+ <p id="copyState">Because state object are mutated, and CodeMirror
3080
+ needs to keep valid versions of a state around so that it can
3081
+ restart a parse at any line, copies must be made of state objects.
3082
+ The default algorithm used is that a new state object is created,
3083
+ which gets all the properties of the old object. Any properties
3084
+ which hold arrays get a copy of these arrays (since arrays tend to
3085
+ be used as mutable stacks). When this is not correct, for example
3086
+ because a mode mutates non-array properties of its state object, a
3087
+ mode object should define
3088
+ a <code><strong>copyState</strong></code> method, which is given a
3089
+ state and should return a safe copy of that state.</p>
3090
+
3091
+ <p id="indent">If you want your mode to provide smart indentation
3092
+ (through the <a href="#indentLine"><code>indentLine</code></a>
3093
+ method and the <code>indentAuto</code>
3094
+ and <code>newlineAndIndent</code> commands, to which keys can be
3095
+ <a href="#option_extraKeys">bound</a>), you must define
3096
+ an <code><strong>indent</strong>(state, textAfter)</code> method
3097
+ on your mode object.</p>
3098
+
3099
+ <p>The indentation method should inspect the given state object,
3100
+ and optionally the <code>textAfter</code> string, which contains
3101
+ the text on the line that is being indented, and return an
3102
+ integer, the amount of spaces to indent. It should usually take
3103
+ the <a href="#option_indentUnit"><code>indentUnit</code></a>
3104
+ option into account. An indentation method may
3105
+ return <code>CodeMirror.Pass</code> to indicate that it
3106
+ could not come up with a precise indentation.</p>
3107
+
3108
+ <p id="mode_comment">To work well with
3109
+ the <a href="#addon_comment">commenting addon</a>, a mode may
3110
+ define <code><strong>lineComment</strong></code> (string that
3111
+ starts a line
3112
+ comment), <code><strong>blockCommentStart</strong></code>, <code><strong>blockCommentEnd</strong></code>
3113
+ (strings that start and end block comments),
3114
+ and <code>blockCommentLead</code> (a string to put at the start of
3115
+ continued lines in a block comment). All of these are
3116
+ optional.</p>
3117
+
3118
+ <p id="electricChars">Finally, a mode may define either
3119
+ an <code>electricChars</code> or an <code>electricInput</code>
3120
+ property, which are used to automatically reindent the line when
3121
+ certain patterns are typed and
3122
+ the <a href="#option_electricChars"><code>electricChars</code></a>
3123
+ option is enabled. <code>electricChars</code> may be a string, and
3124
+ will trigger a reindent whenever one of the characters in that
3125
+ string are typed. Often, it is more appropriate to
3126
+ use <code>electricInput</code>, which should hold a regular
3127
+ expression, and will trigger indentation when the part of the
3128
+ line <em>before</em> the cursor matches the expression. It should
3129
+ usually end with a <code>$</code> character, so that it only
3130
+ matches when the indentation-changing pattern was just typed, not when something was
3131
+ typed after the pattern.</p>
3132
+
3133
+ <p>So, to summarize, a mode <em>must</em> provide
3134
+ a <code>token</code> method, and it <em>may</em>
3135
+ provide <code>startState</code>, <code>copyState</code>,
3136
+ and <code>indent</code> methods. For an example of a trivial mode,
3137
+ see the <a href="../mode/diff/diff.js">diff mode</a>, for a more
3138
+ involved example, see the <a href="../mode/clike/clike.js">C-like
3139
+ mode</a>.</p>
3140
+
3141
+ <p>Sometimes, it is useful for modes to <em>nest</em>—to have one
3142
+ mode delegate work to another mode. An example of this kind of
3143
+ mode is the <a href="../mode/htmlmixed/htmlmixed.js">mixed-mode HTML
3144
+ mode</a>. To implement such nesting, it is usually necessary to
3145
+ create mode objects and copy states yourself. To create a mode
3146
+ object, there are <code>CodeMirror.getMode(options,
3147
+ parserConfig)</code>, where the first argument is a configuration
3148
+ object as passed to the mode constructor function, and the second
3149
+ argument is a mode specification as in
3150
+ the <a href="#option_mode"><code>mode</code></a> option. To copy a
3151
+ state object, call <code>CodeMirror.copyState(mode, state)</code>,
3152
+ where <code>mode</code> is the mode that created the given
3153
+ state.</p>
3154
+
3155
+ <p id="innerMode">In a nested mode, it is recommended to add an
3156
+ extra method, <code><strong>innerMode</strong></code> which, given
3157
+ a state object, returns a <code>{state, mode}</code> object with
3158
+ the inner mode and its state for the current position. These are
3159
+ used by utility scripts such as the <a href="#addon_closetag">tag
3160
+ closer</a> to get context information. Use
3161
+ the <code>CodeMirror.innerMode</code> helper function to, starting
3162
+ from a mode and a state, recursively walk down to the innermost
3163
+ mode and state.</p>
3164
+
3165
+ <p>To make indentation work properly in a nested parser, it is
3166
+ advisable to give the <code>startState</code> method of modes that
3167
+ are intended to be nested an optional argument that provides the
3168
+ base indentation for the block of code. The JavaScript and CSS
3169
+ parser do this, for example, to allow JavaScript and CSS code
3170
+ inside the mixed-mode HTML mode to be properly indented.</p>
3171
+
3172
+ <p id="defineMIME">It is possible, and encouraged, to associate
3173
+ your mode, or a certain configuration of your mode, with
3174
+ a <a href="http://en.wikipedia.org/wiki/MIME">MIME</a> type. For
3175
+ example, the JavaScript mode associates itself
3176
+ with <code>text/javascript</code>, and its JSON variant
3177
+ with <code>application/json</code>. To do this,
3178
+ call <code><strong>CodeMirror.defineMIME</strong>(mime,
3179
+ modeSpec)</code>, where <code>modeSpec</code> can be a string or
3180
+ object specifying a mode, as in
3181
+ the <a href="#option_mode"><code>mode</code></a> option.</p>
3182
+
3183
+ <p>If a mode specification wants to add some properties to the
3184
+ resulting mode object, typically for use
3185
+ with <a href="#getHelpers"><code>getHelpers</code></a>, it may
3186
+ contain a <code>modeProps</code> property, which holds an object.
3187
+ This object's properties will be copied to the actual mode
3188
+ object.</p>
3189
+
3190
+ <p id="extendMode">Sometimes, it is useful to add or override mode
3191
+ object properties from external code.
3192
+ The <code><strong>CodeMirror.extendMode</strong></code> function
3193
+ can be used to add properties to mode objects produced for a
3194
+ specific mode. Its first argument is the name of the mode, its
3195
+ second an object that specifies the properties that should be
3196
+ added. This is mostly useful to add utilities that can later be
3197
+ looked up through <a href="#getMode"><code>getMode</code></a>.</p>
3198
+ </section>
3199
+
3200
+ <section id="vimapi">
3201
+ <h2>VIM Mode API</h2>
3202
+
3203
+ <p>CodeMirror has a robust VIM mode that attempts to faithfully
3204
+ emulate VIM's most useful features. It can be enabled by
3205
+ including <a href="../keymap/vim.js"><code>keymap/vim.js</code>
3206
+ </a> and setting the <code>keymap</code> option to
3207
+ <code>vim</code>.</p>
3208
+
3209
+ <h3 id="vimapi_configuration">Configuration</h3>
3210
+
3211
+ <p>VIM mode accepts configuration options for customizing
3212
+ behavior at run time. These methods can be called at any time
3213
+ and will affect all existing CodeMirror instances unless
3214
+ specified otherwise. The methods are exposed on the
3215
+ <code><strong>CodeMirror.Vim</strong></code> object.</p>
3216
+
3217
+ <dl>
3218
+ <dt id="vimapi_setOption"><code><strong>setOption(name: string, value: any, ?cm: CodeMirror, ?cfg: object)</strong></code></dt>
3219
+ <dd>Sets the value of a VIM option. <code>name</code> should
3220
+ be the name of an option. If <code>cfg.scope</code> is not set
3221
+ and <code>cm</code> is provided, then sets the global and
3222
+ instance values of the option. Otherwise, sets either the
3223
+ global or instance value of the option depending on whether
3224
+ <code>cfg.scope</code> is <code>global</code> or
3225
+ <code>local</code>.</dd>
3226
+ <dt id="vimapi_getOption"><code><strong>getOption(name: string, ?cm: CodeMirror: ?cfg: object)</strong></code></dt>
3227
+ <dd>Gets the current value of a VIM option. If
3228
+ <code>cfg.scope</code> is not set and <code>cm</code> is
3229
+ provided, then gets the instance value of the option, falling
3230
+ back to the global value if not set. If <code>cfg.scope</code> is provided, then gets the <code>global</code> or
3231
+ <code>local</code> value without checking the other.</dd>
3232
+
3233
+ <dt id="vimapi_map"><code><strong>map(lhs: string, rhs: string, ?context: string)</strong></code></dt>
3234
+ <dd>Maps a key sequence to another key sequence. Implements
3235
+ VIM's <code>:map</code> command. To map ; to : in VIM would be
3236
+ <code><strong>:map ; :</strong></code>. That would translate to
3237
+ <code><strong>CodeMirror.Vim.map(';', ':');</strong></code>.
3238
+ The <code>context</code> can be <code>normal</code>,
3239
+ <code>visual</code>, or <code>insert</code>, which correspond
3240
+ to <code>:nmap</code>, <code>:vmap</code>, and
3241
+ <code>:imap</code>
3242
+ respectively.</dd>
3243
+
3244
+ <dt id="vimapi_mapCommand"><code><strong>mapCommand(keys: string, type: string, name: string, ?args: object, ?extra: object)</strong></code></dt>
3245
+ <dd>Maps a key sequence to a <code>motion</code>,
3246
+ <code>operator</code>, or <code>action</code> type command.
3247
+ The args object is passed through to the command when it is
3248
+ invoked by the provided key sequence.
3249
+ <code>extras.context</code> can be <code>normal</code>,
3250
+ <code>visual</code>, or <code>insert</code>, to map the key
3251
+ sequence only in the corresponding mode.
3252
+ <code>extras.isEdit</code> is applicable only to actions,
3253
+ determining whether it is recorded for replay for the
3254
+ <code>.</code> single-repeat command.
3255
+ </dl>
3256
+
3257
+ <h3 id="vimapi_extending">Extending VIM</h3>
3258
+
3259
+ <p>CodeMirror's VIM mode implements a large subset of VIM's core
3260
+ editing functionality. But since there's always more to be
3261
+ desired, there is a set of APIs for extending VIM's
3262
+ functionality. As with the configuration API, the methods are
3263
+ exposed on <code><strong>CodeMirror.Vim</strong></code> and may
3264
+ be called at any time.</p>
3265
+
3266
+ <dl>
3267
+ <dt id="vimapi_defineOption"><code><strong>defineOption(name: string, default: any, type: string, ?aliases: array&lt;string&gt;, ?callback: function (?value: any, ?cm: CodeMirror) → ?any)</strong></code></dt>
3268
+ <dd>Defines a VIM style option and makes it available to the
3269
+ <code>:set</code> command. Type can be <code>boolean</code> or
3270
+ <code>string</code>, used for validation and by
3271
+ <code>:set</code> to determine which syntax to accept. If a
3272
+ <code>callback</code> is passed in, VIM does not store the value of the
3273
+ option itself, but instead uses the callback as a setter/getter. If the
3274
+ first argument to the callback is <code>undefined</code>, then the
3275
+ callback should return the value of the option. Otherwise, it should set
3276
+ instead. Since VIM options have global and instance values, whether a
3277
+ <code>CodeMirror</code> instance is passed in denotes whether the global
3278
+ or local value should be used. Consequently, it's possible for the
3279
+ callback to be called twice for a single <code>setOption</code> or
3280
+ <code>getOption</code> call. Note that right now, VIM does not support
3281
+ defining buffer-local options that do not have global values. If an
3282
+ option should not have a global value, either always ignore the
3283
+ <code>cm</code> parameter in the callback, or always pass in a
3284
+ <code>cfg.scope</code> to <code>setOption</code> and
3285
+ <code>getOption</code>.</dd>
3286
+
3287
+ <dt id="vimapi_defineMotion"><code><strong>defineMotion(name: string, fn: function(cm: CodeMirror, head: {line, ch}, ?motionArgs: object}) → {line, ch})</strong></code></dt>
3288
+ <dd>Defines a motion command for VIM. The motion should return
3289
+ the desired result position of the cursor. <code>head</code>
3290
+ is the current position of the cursor. It can differ from
3291
+ <code>cm.getCursor('head')</code> if VIM is in visual mode.
3292
+ <code>motionArgs</code> is the object passed into
3293
+ <strong><code>mapCommand()</code></strong>.</dd>
3294
+
3295
+ <dt id="vimapi_defineOperator"><strong><code>defineOperator(name: string, fn: function(cm: CodeMirror, ?operatorArgs: object, ranges: array&lt;{anchor, head}&gt;) → ?{line, ch})</code></strong></dt>
3296
+ <dd>Defines an operator command, similar to <strong><code>
3297
+ defineMotion</code></strong>. <code>ranges</code> is the range
3298
+ of text the operator should operate on. If the cursor should
3299
+ be set to a certain position after the operation finishes, it
3300
+ can return a cursor object.</dd>
3301
+
3302
+ <dt id="vimapi_defineActon"><strong><code>defineAction(name: string, fn: function(cm: CodeMirror, ?actionArgs: object))</strong></code></dt>
3303
+ <dd>Defines an action command, similar to
3304
+ <strong><code>defineMotion</code></strong>. Action commands
3305
+ can have arbitrary behavior, making them more flexible than
3306
+ motions and operators, at the loss of orthogonality.</dd>
3307
+
3308
+ <dt id="vimapi_defineEx"><strong><code>defineEx(name: string, ?prefix: string, fn: function(cm: CodeMirror, ?params: object))</code></strong></dt>
3309
+ <dd>Defines an Ex command, and maps it to <code>:name</code>.
3310
+ If a prefix is provided, it, and any prefixed substring of the
3311
+ <code>name</code> beginning with the <code>prefix</code> can
3312
+ be used to invoke the command. If the <code>prefix</code> is
3313
+ falsy, then <code>name</code> is used as the prefix. <code>
3314
+ params.argString</code> contains the part of the prompted
3315
+ string after the command name. <code>params.args</code> is
3316
+ <code>params.argString</code> split by whitespace. If the
3317
+ command was prefixed with a
3318
+ <code><strong><a href="http://vimdoc.sourceforge.net/htmldoc/cmdline.html#cmdline-ranges">line range</a></strong></code>,
3319
+ <code>params.line</code> and <code>params.lineEnd</code> will
3320
+ be set.
3321
+ </dl>
3322
+
3323
+ </section>
3324
+
3325
+ </article>
3326
+
3327
+ <script>setTimeout(function(){CodeMirror.colorize();}, 20);</script>